Skip to content

[LLVM][Demangle] Fix MS Demangler to be stricter about wide string literals #134483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Changes to LLVM infrastructure

* Removed support for target intrinsics being defined in the target directories
themselves (i.e., the `TargetIntrinsicInfo` class).
* Fix Microsoft demangling of string literals to be stricter
(#GH129970))

Changes to building LLVM
------------------------
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Demangle/MicrosoftDemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,11 @@ Demangler::demangleStringLiteral(std::string_view &MangledName) {
Result->IsTruncated = true;

while (!consumeFront(MangledName, '@')) {
// For a wide string StringByteSize has to have an even length.
if (StringByteSize % 2 != 0)
goto StringLiteralError;
if (StringByteSize == 0)
goto StringLiteralError;
if (MangledName.size() < 2)
goto StringLiteralError;
wchar_t W = demangleWcharLiteral(MangledName);
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/Demangle/invalid-manglings.test
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,27 @@
; CHECK-EMPTY:
; CHECK-NEXT: .?AUBase@@@8
; CHECK-NEXT: error: Invalid mangled name

; Begin GH129970

??_C@_12EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_12EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-NEXT: error: Invalid mangled name

??_C@_16EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_16EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-NEXT: error: Invalid mangled name

??_C@_18EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_18EEHFKJGG@?$AAt?$AAe?$AAx@
; CHECK-NEXT: error: Invalid mangled name

??_C@_15EEHFKJGG@?$AAt?$AAe?$AAx?$AAx@
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_15EEHFKJGG@?$AAt?$AAe?$AAx?$AAx@
; CHECK-NEXT: error: Invalid mangled name

; End GH129970