summaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/MicrosoftDemangle.cpp
AgeCommit message (Collapse)Author
2025-11-09Remove unused <array> and <list> inclusion (#167116)serge-sans-paille
2025-11-05[MsDemangle] Use NodeList over SmallVector for target names (#166586)nerix
Using `SmallVector` would introduce a dependency cycle (see https://github.com/llvm/llvm-project/pull/155630#discussion_r2495268497), so this uses a NodeList.
2025-11-05[MsDemangle] Read entire chain of target names in special tables (#155630)nerix
When there's a deep inheritance hierarchy of multiple C++ classes (see below), then the mangled name of a VFTable can include multiple key nodes in the target name. For example, in the following code, MSVC will generate mangled names for the VFTables that have up to three key classes in the context. <details><summary>Code</summary> ```cpp class Base1 { virtual void a() {}; }; class Base2 { virtual void b() {} }; class Ind1 : public Base1 {}; class Ind2 : public Base1 {}; class A : public Ind1, public Ind2 {}; class Ind3 : public A {}; class Ind4 : public A {}; class B : public Ind3, public Ind4 {}; class Ind5 : public B {}; class Ind6 : public B {}; class C : public Ind5, public Ind6 {}; int main() { auto i = new C; } ``` </details> This will include `??_7C@@6BInd1@@Ind4@@Ind5@@@` (and every other combination). Microsoft's undname will demangle this to "const C::\`vftable'{for \`Ind1's \`Ind4's \`Ind5'}". Previously, LLVM would demangle this to "const C::\`vftable'{for \`Ind1'}". With this PR, the output of LLVM's undname will be identical to Microsoft's version. This changes `SpecialTableSymbolNode::TargetName` to a node array which contains each key from the name. Unlike namespaces, these keys are not in reverse order - they are in the same order as in the mangled name.
2025-04-15[PAC] Add support for __ptrauth type qualifier (#100830)Akira Hatanaka
The qualifier allows programmer to directly control how pointers are signed when they are stored in a particular variable. The qualifier takes three arguments: the signing key, a flag specifying whether address discrimination should be used, and a non-negative integer that is used for additional discrimination. ``` typedef void (*my_callback)(const void*); my_callback __ptrauth(ptrauth_key_process_dependent_code, 1, 0xe27a) callback; ``` Co-Authored-By: John McCall rjmccall@apple.com
2025-04-07[LLVM][Demangle] Fix MS Demangler to be stricter about wide string literals ↵Shafik Yaghmour
(#134483) Static analysis detected that Demangler::demangleStringLiteral had a potential overflow if not checking StringByteSize properly. Added check to ensure that for wide string it is always even and that there were the byte count did not mismatch the actual size of the literal. Fixes: https://github.com/llvm/llvm-project/issues/129970
2024-11-13[llvm][aarch64] Fix Arm64EC name mangling algorithm (#115567)Daniel Paoliello
Arm64EC uses a special name mangling mode that adds `$$h` between the symbol name and its type. In MSVC's name mangling `@` is used to separate the name and type BUT it is also used for other purposes, such as the separator between paths in a fully qualified name. The original algorithm was quite fragile and made assumptions that didn't hold true for all MSVC mangled symbols, so instead of trying to improve this algorithm we are now using the demangler to indicate where the insertion point should be (i.e., to parse the fully-qualified name and return the current string offset). Also fixed `isArm64ECMangledFunctionName` to search for `@$$h` since the `$$h` must always be after a `@`. Fixes #115231
2024-09-17[llvm] [Demangle] Fix MSVC demangling for placeholder return types (#106178)Max Winkler
Properly demangle `_T` and `_P` return type manglings for MSVC 1920+. Also added a unit test for `@` return type that is used when mangling non-template auto placeholder return type function. Tested the output against the undname shipped with MSVC 19.40.
2024-07-04Fix MSVC 1920+ auto NTTP mangling for pointers to members (#97007)Max Winkler
Fixes https://github.com/llvm/llvm-project/issues/70899. This is a continuation of https://github.com/llvm/llvm-project/pull/92477 for pointers to member data and pointers to member functions. The mangled name must be prefixed with `$M <mangled-type>` for the deduced type of the nttp parameter.
2024-06-26Fix MSVC Demangling with auto NTTP mangled names for function pointer, ↵Max Winkler
pointer to data and integral types (#96590) As cited here, https://github.com/llvm/llvm-project/pull/92477, undname needs updating to support the new auto NTTP name mangling. In short the deduced type of the auto NTTP parameter is mangled as `$M <type> <nttp-param>`. However the deduced type is not printed for the undecorated name so the `$M <type>` is parsed but simply ignored when stringifying the generated AST.
2023-07-13[Demangle] use std::string_view::data rather than &*std::string_view::beginNick Desaulniers
To fix expensive check builds that were failing when using MSVC's std::string_view::iterator::operator*, I added a few expressions like &*std::string_view::begin. @nico pointed out that this is literally the same thing and more clearly expressed as std::string_view::data. Link: https://github.com/llvm/llvm-project/issues/63740 Reviewed By: #libc_abi, ldionne, philnik, MaskRay Differential Revision: https://reviews.llvm.org/D154876
2023-07-11[MicrosoftDemangle] fix warn-trailing false positiveNick Desaulniers
A follow up to commit 6bad76c7ae93 ("[Demangle] fix windows tests") based on @thakis' report. Fixes: #63740 Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D154875
2023-06-05[Demangle] convert microsoftDemangle to take a std::string_viewNick Desaulniers
This should be last of the "bottom-up conversions" of various demanglers to accept std::string_view. After this, D149104 may be revisited. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D152176
2023-04-21[Demangle] remove unused params of microsoftDemangleNick Desaulniers
No call sites use these parameters, so drop them. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148940
2023-04-20[Demangle] fix windows testsNick Desaulniers
My reland of https://reviews.llvm.org/D148546 has caused a few windows demangler tests to fail when run with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON on windows. I have a sneaking suspicion that MSVC's std::string_view::iterator::operator* may be missing a nullptr check. Link: https://lab.llvm.org/buildbot/#/builders/42/builds/9723/steps/7/logs/stdio Reviewed By: ayzhao Differential Revision: https://reviews.llvm.org/D148852
2023-04-20Reland: [Demangle] replace use of llvm::StringView w/ std::string_viewNick Desaulniers
This reverts commit d81cdb49d74064e88843733e7da92db865943509. This refactoring was waiting on converting LLVM to C++17. Leave StringView.h and cleanup around for subsequent cleanup. Additional fixes for missing std::string_view conversions for MSVC. Reviewed By: MaskRay, DavidSpickett, ayzhao Differential Revision: https://reviews.llvm.org/D148546
2023-04-14Revert D148384 "[Demangle] replace use of llvm::StringView w/ std::string_view"Fangrui Song
This reverts commit 3e559509b426b6aae735a7f57dbdaed1041d2622 and e0c4ffa796b553fa78c638a9584c05ac21fe07d5. This still breaks Windows builds. In addition, `#include <llvm/ADT/StringViewExtras.h>` in llvm/include/llvm/Demangle/ItaniumDemangle.h is a library layering violation (LLVMDemangle is the lowest LLVM library and cannot depend on LLVMSupport).
2023-04-14[Demangle] fix windows buildNick Desaulniers
Fixes diagnostics reported against https://reviews.llvm.org/D148384 https://lab.llvm.org/buildbot/#/builders/127/builds/46749/steps/4/logs/stdio Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148392
2023-04-14[Demangle] replace use of llvm::StringView w/ std::string_viewNick Desaulniers
This refactoring was waiting on converting LLVM to C++17. Leave StringView.h and cleanup around for subsequent cleanup. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148384
2023-04-14[StringView] remove consumeFrontNick Desaulniers
Towards converting our use of llvm::StringView to std::string_view, remove a method that std::string_view doesn't have. This could be moved to the nascent llvm/ADT/StringViewExtras.h, but the use is highly localized to one TU. Move this to be a static function there. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148375
2023-04-14[StringView] remove popFrontNick Desaulniers
Towards converting our use of llvm::StringView to std::string_view, remove a method that std::string_view doesn't have. llvm::StringView::popFront is similar to std::string_view::remove_prefix but with a reference to std::string_view::front taken first. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148363
2023-04-14[StringView] remove ctor incompatible with std::string_viewNick Desaulniers
Towards replacing llvm::StringView with std::string_view, remove ctor that std::string_view doesn't have an analog for. Reviewed By: erichkeane, MaskRay Differential Revision: https://reviews.llvm.org/D148353
2023-04-14[StringView] remove dropFrontNick Desaulniers
Towards converting our use of llvm::StringView to std::string_view, remove a method that std::string_view doesn't have. llvm::StringView::dropFront is semantically similar to std::string_view::substr but with the input clamped to the size. No code was relying on clamping other than the rust demangler, which I fixed in https://reviews.llvm.org/D148272. Removing this method makes it easier to switch over code later. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148348
2023-04-13[Demangle] Remove uses of ↵Fangrui Song
llvm::itanium_demangle::StringView::{dropBack,dropFront}. NFC Make it easier to migrate StringView to std::string_view.
2022-10-17[demangler] Simplify OutputBuffer initializationNathan Sidwell
Every non-testcase use of OutputBuffer contains code to allocate an initial buffer (using either 128 or 1024 as initial guesses). There's now no need to do that, given recent changes to the buffer extension heuristics -- it allocates a 1k(ish) buffer on first need. Just pass in a buffer (if any) to the constructor. Thus the OutputBuffer's ownership of the buffer starts at its own lifetime start. We can reduce the lifetime of this object in several cases. That new constructor takes a 'size_t *' for the size argument, as all uses with a non-null buffer are passing through a malloc'd buffer from their own caller in this manner. The buffer reset member function is never used, and is deleted. Some adjustment to a couple of uses is needed, due to the lazy buffer creation of this patch. a) the Microsoft demangler can demangle empty strings to nothing, which it then memoizes. We need to avoid the UB of passing nullptr to memcpy. b) a unit test checks insertion of no characters into an empty buffer. We need to avoid UB when converting that to std::string. The original buffer initialization code would return a failure code if that first malloc failed. Existing code either ignored that, called std::terminate with a FIXME, or returned an error code. But that's not foolproof anyway, as a subsequent buffer extension failure ends up calling std::terminate. I am working on addressing that unfortunate failure mode in a manner more consistent with the C++ ABI design. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D122604
2022-06-08[MicrosoftDemangle] Set error to true when returning nullptr.Zequan Wu
2022-04-26Revert "[demangler] Simplify OutputBuffer initialization"Kirill Stoimenov
Reverting due to a bot failure: https://lab.llvm.org/buildbot/#/builders/5/builds/22738 This reverts commit 5b3ca24a35e91bf9c19af856e7f92c69b17f989e.
2022-04-26[demangler] Simplify OutputBuffer initializationNathan Sidwell
Every non-testcase use of OutputBuffer contains code to allocate an initial buffer (using either 128 or 1024 as initial guesses). There's now no need to do that, given recent changes to the buffer extension heuristics -- it allocates a 1k(ish) buffer on first need. Just pass in a buffer (if any) to the constructor. Thus the OutputBuffer's ownership of the buffer starts at its own lifetime start. We can reduce the lifetime of this object in several cases. That new constructor takes a 'size_t *' for the size argument, as all uses with a non-null buffer are passing through a malloc'd buffer from their own caller in this manner. The buffer reset member function is never used, and is deleted. The original buffer initialization code would return a failure code if that first malloc failed. Existing code either ignored that, called std::terminate with a FIXME, or returned an error code. But that's not foolproof anyway, as a subsequent buffer extension failure ends up calling std::terminate. I am working on addressing that unfortunate failure mode in a manner more consistent with the C++ ABI design. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D122604
2022-03-28[demangler] Add StringView conversion operatorNathan Sidwell
The OutputBuffer class tries to present a NUL-terminated string API to consumers. But several of them would prefer a StringView. In particular the Microsoft demangler, juggles between NUL-terminated and StringView, which is confusing. This adds a StringView conversion, and adjusts the Demanglers that can benefit from that. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D120990
2022-03-28[llvm] Fix string copy confusionNathan Sidwell
The microsoft demangler makes copies of the demangled strings, but has some confusion between StringView representation (sans NUL), and C-strings (with NUL). Here we also have a use of strcpy, which happens to work because the incoming string view happens to have a trailing NUL. But a simple memcpy excluding the NUL is sufficient. Reviewed By: dblaikie, erichkeane Differential Revision: https://reviews.llvm.org/D122391
2021-10-21[Demangle] Rename OutputStream to OutputStringLuís Ferreira
This patch is a refactor to implement prepend afterwards. Since this changes a lot of files and to conform with guidelines, I will separate this from the implementation of prepend. Related to the discussion in https://reviews.llvm.org/D111414 , so please read it for more context. Reviewed By: #libc_abi, dblaikie, ldionne Differential Revision: https://reviews.llvm.org/D111947
2021-10-19[lldb] change name demangling to be consistent between windows and linxLasse Folger
When printing names in lldb on windows these names contain the full type information while on linux only the name is contained. This change introduces a flag in the Microsoft demangler to control if the type information should be included. With the flag enabled demangled name contains only the qualified name, e.g: without flag -> with flag int (*array2d)[10] -> array2d int (*abc::array2d)[10] -> abc::array2d const int *x -> x For globals there is a second inconsistency which is not yet addressed by this change. On linux globals (in global namespace) are prefixed with :: while on windows they are not. Reviewed By: teemperor, rnk Differential Revision: https://reviews.llvm.org/D111715
2021-07-14Demangle: correct swift_async demangling for Microsoft schemeSaleem Abdulrasool
The emission was corrected for the swift_async calling convention but the demangling support was not. This repairs the demangling support as well.
2021-07-09[Clang] Introduce Swift async calling convention.Varun Gandhi
This change is intended as initial setup. The plan is to add more semantic checks later. I plan to update the documentation as more semantic checks are added (instead of documenting the details up front). Most of the code closely mirrors that for the Swift calling convention. Three places are marked as [FIXME: swiftasynccc]; those will be addressed once the corresponding convention is introduced in LLVM. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D95561
2021-01-27[Demangle] Support demangling Swift calling convention in MS demangler.Varun Gandhi
Previously, Clang was able to mangle the Swift calling convention but 'MicrosoftDemangle.cpp' was not able to demangle it. Reviewed By: compnerd, rnk Differential Revision: https://reviews.llvm.org/D95053
2020-05-20Give microsoftDemangle() an outparam for how many input bytes were consumed.Nico Weber
Demangling Itanium symbols either consumes the whole input or fails, but Microsoft symbols can be successfully demangled with just some of the input. Add an outparam that enables clients to know how much of the input was consumed, and use this flag to give llvm-undname an opt-in warning on partially consumed symbols. Differential Revision: https://reviews.llvm.org/D80173
2019-12-04Revert "Add some missing includes to MicrosoftDemangle.cpp (PR44217)"David Blaikie
This reverts commit 9b962d83ece841e43fd2823375dc6ddc94c1b178. This didn't address the underlying issue (in MicrosoftDemangleNodes.h) that was fixed 6 months ago anyway.
2019-12-04Add some missing includes to MicrosoftDemangle.cpp (PR44217)David Blaikie
2019-10-15[Demangle] Add a few more options to the microsoft demanglerMartin Storsjo
This corresponds to commonly used options to UnDecorateSymbolName within llvm. Add them as hidden options in llvm-undname. MS undname.exe takes numeric flags, corresponding to the UNDNAME_* constants, but instead of hardcoding in mappings for those numbers, just add textual options instead, as it the use of them here is primarily intended for testing. Differential Revision: https://reviews.llvm.org/D68917 llvm-svn: 374865
2019-10-02Fix uninitialized variable warning. NFCI.Simon Pilgrim
llvm-svn: 373450
2019-09-23llvm-undname: Add support for demangling typeinfo namesNico Weber
typeinfo names aren't symbols but string constant contents stored in compiler-generated typeinfo objects, but llvm-cxxfilt can demangle these for Itanium names. In the MSVC ABI, these are just a '.' followed by a mangled type -- this means they don't start with '?' like all MS-mangled symbols do. Differential Revision: https://reviews.llvm.org/D67851 llvm-svn: 372602
2019-06-04llvm-undname: Correctly demangle vararg parametersNico Weber
FunctionSignatureNode already had an IsVariadic field, but it wasn't used anywhere yet. Set it and use it. llvm-svn: 362541
2019-06-04llvm-undname: More coverage-related cleanupsNico Weber
- The loop in demangleFunctionParameterList() only exits on Error, @, and Z. All 3 cases were handled, so the rest of the function is DEMANGLE_UNREACHABLE. - The loop in demangleTemplateParameterList() always returns on Error, so there's no need to check for that in the loop header and after the loop. - Add test cases for invalid function parameter manglings. - Add a (redundant) test case for a simple template parameter list mangling. - Add a test case pointing out that varargs functions aren't demangled correctly. llvm-svn: 362540
2019-06-04llvm-undname: Add test coverage for demangleInitFiniStub()Nico Weber
llvm-svn: 362536
2019-06-04llvm-undname: Yet more coverage for error pathsNico Weber
- For error returns in demangleSpecialTableNode(), demangleLocalStaticGuard(), RTTITypeDescriptor, demangleRttiBaseClassDescriptorNode(), demangleUnsigned(), demangleUntypedVariable() (via RttiBaseClassArray) - For ?_A and ?_P which are handled at early levels of the demangler but are not implemented in a later stage; this is now more obvious - Replace a "default:" with an explicit list of cases, to get -Wswitch check we list all cases llvm-svn: 362520
2019-06-04llvm-undname: More no-op changes to increase test coverageNico Weber
- Add test coverage around invalid anon namespaces and for error paths in demanglePrimitiveType() and in demangleFullyQualifiedTypeName() - Use DEMANGLE_UNREACHABLE in two more unreachable places llvm-svn: 362514
2019-06-04llvm-undname: Several behavior-preserving changes to increase coverageNico Weber
- Replace `Error = true` in a few branches that are truly unreachable with DEMANGLE_UNREACHABLE - Remove early return early in startsWithLocalScopePattern() because it's redundant with the next two early returns - Remove unreachable `case '0'` (it's handled in the branch below) - Remove an unused bool return - Add test coverage for several early error returns, mostly in array type parsing llvm-svn: 362506
2019-06-02llvm-undname; Add more test coverage for demangleFunctionClass()Nico Weber
Also add two FC_Far that seem to be missing, by symmetry from the public and protected cases. (But FC_Far isn't really a thing anymore, so this doesn't really have an observable effect.) llvm-svn: 362344
2019-06-02Remove code path that's dead after r358835Nico Weber
llvm-svn: 362333
2019-05-28llvm-undname: Support demangling char8_tNico Weber
Ports clang's mangling support added in r354633 to llvm-undname. llvm-svn: 361839
2019-05-28llvm-undname: Add support for local static thread guardsNico Weber
llvm-svn: 361835