aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/ItaniumDemangle.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-04-25[lldb][Mangled] Retrieve and cache demangled name info (#131836)Michael Buch1-3/+14
Uses the `TrackingOutputBuffer` to populate the new member `Mangled::m_demangled_info`. `m_demangled_info` is lazily popluated by `GetDemangledInfo`. To ensure `m_demangled` and `m_demangled_info` are in-sync we clear `m_demangled_info` anytime `m_demangled` is set/cleared. https://github.com/llvm/llvm-project/pull/131836
2024-01-04[llvm-cxxfilt] Added the option --no-params (#75348)Dmitry Vasilyev1-2/+2
Added -p / --no-params flag to skip demangling function parameters similar to how it is supported by GNU c++filt tool. There are cases when users want to demangle a large number of symbols in bulk, for example, at startup, and do not care about function parameters and overloads at that time. Skipping the demangling of parameter types led to a measurable improvement in performance. Our users reported about 15% speed up with GNU c++filt and we expect similar results with llvm-cxxfilt with this patch.
2024-01-02Revert "[llvm-cxxfilt] Added the option --no-params (#75348)"Arthur Eubanks1-2/+2
This reverts commit 71f8ea3062a6b0a190835853ee77e58469763b9e. Test doesn't pass on mac. See comments on https://github.com/llvm/llvm-project/pull/75348.
2024-01-02[llvm-cxxfilt] Added the option --no-params (#75348)Dmitry Vasilyev1-2/+2
Added -p / --no-params flag to skip demangling function parameters similar to how it is supported by GNU c++filt tool. There are cases when users want to demangle a large number of symbols in bulk, for example, at startup, and do not care about function parameters and overloads at that time. Skipping the demangling of parameter types led to a measurable improvement in performance. Our users reported about 15% speed up with GNU c++filt and we expect similar results with llvm-cxxfilt with this patch.
2023-07-18[Demangle] Include <exception> for IWYUFangrui Song1-0/+1
The called std::terminate currently gets the declaration transitively through llvm/Demangle/Utility.h, removing <exception> from Utility.h would break ItaniumDemangle.cpp.
2023-07-13[Demangle] use std::string_view::data rather than &*std::string_view::beginNick Desaulniers1-1/+1
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-06-02[Demangle] convert itaniumDemangle and nonMicrosoftDemangle to use ↵Nick Desaulniers1-3/+4
std::string_view D149104 converted llvm::demangle to use std::string_view. Enabling "expensive checks" (via -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON) causes lld/test/wasm/why-extract.s to fail. The reason for this is obscure: Reason #10007 why std::string_view is dangerous: Consider the following pattern: std::string_view s = ...; const char *c = s.data(); std::strlen(c); Is c a NUL-terminated C style string? It depends; but if it's not then it's not safe to call std::strlen on the std::string_view::data(). std::string_view::length() should be used instead. Fixing this fixes the one lone test that caught this. microsoftDemangle, rustDemangle, and dlangDemangle should get this same treatment, too. I will do that next. Reviewed By: MaskRay, efriedma Differential Revision: https://reviews.llvm.org/D149675
2023-05-03[Demangle] remove unused status param of itaniumDemangleNick Desaulniers1-20/+9
No call sites interpreted this value meaningfully. Simplify this interface. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D149707
2023-05-03[Demangle] remove unused params of itaniumDemangleNick Desaulniers1-6/+4
No call sites use these parameters, so drop them. Equivalent to D148940. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D149703
2023-04-20Reland: [Demangle] replace use of llvm::StringView w/ std::string_viewNick Desaulniers1-2/+2
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 Song1-2/+2
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 Desaulniers1-1/+1
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 Desaulniers1-1/+1
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
2022-10-17[demangler] Simplify OutputBuffer initializationNathan Sidwell1-16/+5
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-04-26Revert "[demangler] Simplify OutputBuffer initialization"Kirill Stoimenov1-5/+16
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 Sidwell1-16/+5
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-04-06[demangler] Node precision dumperNathan Sidwell1-3/+43
Add contents to the demangler node dumper's print(Prec) functions. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D122740
2022-03-28ItaniumDemangler: Update BinaryExpr::match to match the ctorDavid Blaikie1-0/+4
Not sure if this could use more testing, but hopefully this is adequate.
2022-03-22[demangler] Add support for C++20 modulesNathan Sidwell1-0/+9
Add support for module name demangling. We have two new demangler nodes -- ModuleName and ModuleEntity. The former represents a module name in a hierarchical fashion. The latter is the combination of a (name) node and a module name. Because module names and entity identities use the same substitution encoding, we have to adjust the flow of how substitutions are handled, and examine the substituted node to know how to deal with it. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D119933
2022-02-07[demangler] Remove StdQualifiedNameNathan Sidwell1-9/+0
The StdQualifiedName node class is used for names exactly in the std namespace. It is not used for nested names that descend further -- those use a NestedName with NameType("std") as the scope. Representing the compression scheme in the node graph is layer breaking. We can use the same structure for those exactly in std too, and reduce code size a bit. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D118249
2022-01-21[llvm] Remove unused headers in LLVMDemangleserge-sans-paille1-2/+0
As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Demangle/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 208053 lines after: 203965 lines
2021-10-21[Demangle] Rename OutputStream to OutputStringLuís Ferreira1-35/+35
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
2020-02-11Use std::foo_t rather than std::foo in LLVM.Justin Lebar1-4/+2
Summary: C++14 migration. No functional change. Reviewers: bkramer, JDevlieghere, lebedev.ri Subscribers: MatzeB, hiraditya, jkorous, dexonsmith, arphaman, kadircet, lebedev.ri, usaxena95, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D74384
2019-11-04[demangle] NFC: get rid of NodeOrStringErik Pilkington1-8/+0
This class was a bit overengineered, and was triggering some PVS warnings. Instead, put strings into a NameType and let clients unconditionally treat it as a Node.
2019-09-07Synchronize LLVM's copy of libc++abi's demangler with the libc++abiRichard Smith1-0/+10
version after r371273. Also fix a minor issue in r371273 that only surfaced after template instantiation from LLVM's use of the demangler. llvm-svn: 371274
2019-01-19Update more file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
2018-11-27[Demangle] remove itaniumFindTypesInMangledNamePavel Labath1-9/+0
Summary: This (very specialized) function was added to enable an LLDB use case. Now that a more generic interface (overriding of parser functions - D52992) is available, and LLDB has been converted to use that (D54074), the function is unused and can be removed. Reviewers: erik.pilkington, sgraenitz, rsmith Subscribers: mgorny, hiraditya, christof, libcxx-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D54893 llvm-svn: 347670
2018-11-11Make initializeOutputStream() return false on error and true on success.Nico Weber1-5/+5
As discussed in https://reviews.llvm.org/D52104 Differential Revision: https://reviews.llvm.org/D52143 llvm-svn: 346606
2018-10-17Port libcxxabi r344607 into llvmPavel Labath1-1/+1
Summary: The original commit message was: This uses CRTP (for performance reasons) to allow a user the override demangler functions to implement custom parsing logic. The motivation for this is LLDB, which needs to occasionaly modify the mangled names. One such instance is already implemented via the TypeCallback member, but this is very specific functionality which does not help with any other use case. Currently we have a use case for modifying the constructor flavours, which would require adding another callback. This approach does not scale. With CRTP, the user (LLDB) can override any function it needs without any special support from the demangler library. After LLDB is ported to use this instead of the TypeCallback mechanism, the callback can be removed. The only difference here is the addition of a unit test which exercises the CRTP mechanism to override a function in the parser. Reviewers: erik.pilkington, rsmith, EricWF Subscribers: mgorny, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D53300 llvm-svn: 344703
2018-10-15NFC: Fix a -Wsign-conversion warningErik Pilkington1-5/+11
llvm-svn: 344564
2018-09-15Update microsoftDemangle() to work more like itaniumDemangle().Nico Weber1-15/+0
* Use same method of initializing the output stream and its buffer * Allow a nullptr Status pointer * Don't print the mangled name on demangling error * Write to N (if it is non-nullptr) Differential Revision: https://reviews.llvm.org/D52104 llvm-svn: 342330
2018-08-20Add missing include (<functional> for std::ref)David Blaikie1-0/+1
llvm-svn: 340205
2018-08-20Move Itanium demangler implementation into a header file and add visitation ↵Richard Smith1-4857/+206
support. Summary: This transforms the Itanium demangler into a generic reusable library that can be used to build, traverse, and transform Itanium mangled name trees. This is in preparation for adding a canonicalizing demangler, which cannot live in the Demangle library for layering reasons. In order to keep the diffs simpler, this patch moves more code to the new header than is strictly necessary: in particular, all of the printLeft / printRight implementations can be moved to the implementation file. (And indeed we could make them non-virtual now if we wished, and remove the vptr from Node.) All nodes are now included in the Kind enumeration, rather than omitting some of the Expr nodes, and the three different floating-point literal node types now have distinct Kind values. As a proof of concept for the visitation / matching mechanism, this patch implements a Node dumping facility on top of it, replacing the prior mechanism that produced the pretty-printed output rather than a tree dump. Sample dump output: FunctionEncoding( NameType("int"), NameWithTemplateArgs( NestedName( NameWithTemplateArgs( NameType("A"), TemplateArgs( {NameType("B")})), NameType("f")), TemplateArgs( {NameType("int")})), {}, <null>, QualConst, FunctionRefQual::FrefQualLValue) As a next step, it would make sense to move the LLVM high-level interface to the demangler (the itaniumDemangler function and ItaniumPartialDemangler class) into the Support library, and implement them in terms of the Demangle library. This would allow the libc++abi demangler implementation to be an identical copy of the llvm Demangle library, and would allow the LLVM implementation to reuse LLVM components such as llvm::BumpPtrAllocator, but we'll need to decide how to coordinate that with the MS ABI demangler, so I'm not doing that in this patch. No functionality change intended other than the behavior of dump(). Reviewers: erik.pilkington, zturner, chandlerc, dlj Subscribers: aheejin, llvm-commits Differential Revision: https://reviews.llvm.org/D50930 llvm-svn: 340203
2018-08-16Factor Node creation out of the demangler. No functionality changeRichard Smith1-77/+99
intended. llvm-svn: 339944
2018-08-13[itanium demangler] Add llvm::itaniumFindTypesInMangledName()Erik Pilkington1-1/+15
This function calls a callback whenever a <type> is parsed. This is necessary to implement FindAlternateFunctionManglings in LLDB, which uses a similar hack in FastDemangle. Once that function has been updated to use this version, FastDemangle can finally be removed. Differential revision: https://reviews.llvm.org/D50586 llvm-svn: 339580
2018-08-02[itanium demangler] Support dot suffixes on block invocation functionsErik Pilkington1-0/+2
rdar://32378759 llvm-svn: 338747
2018-07-28[demangler] Fix an oss-fuzz bug from r338138Erik Pilkington1-0/+8
Stack overflow on invalid. While collapsing references, we were skipping over a cycle check in ForwardTemplateReference leading to a stack overflow. This commit fixes the problem by duplicating the cycle check in ReferenceType. llvm-svn: 338190
2018-07-27[demangler] Support for reference collapsingErik Pilkington1-46/+56
llvm.org/PR38323 llvm-svn: 338138
2018-07-23[demangler] call terminate() if allocation failedErik Pilkington1-4/+13
We really should set *status to memory_alloc_failure, but we need to refactor the demangler a bit to properly propagate the failure up the stack. Until then, its better to explicitly terminate then rely on a null dereference crash. rdar://31240372 llvm-svn: 337759
2018-07-17Add some helper functions to the demangle utility classes.Zachary Turner1-13/+5
These are all methods that, while not currently used in the Itanium demangler, are generally useful enough that it's likely the itanium demangler could find a use for them. More importantly, they are all necessary for the Microsoft demangler which is up and coming in a subsequent patch. Rather than combine these into a single monolithic patch, I think it makes sense to commit this utility code first since it is very simple, this way it won't detract from the substance of the MS demangler patch. llvm-svn: 337316
2018-07-16[LLVMDemangle] Move some utility classes to header files.Zachary Turner1-198/+5
In a followup I'm looking to add a Microsoft demangler. Doing so needs a lot of the same utility classes and feature test macros which are already implemented in ItaniumDemangle.cpp. So move all of these things into header files so that they can be re-used by a new demangler. Differential Revision: https://reviews.llvm.org/D49399 llvm-svn: 337217
2018-07-05[demangler] Avoid alignment warningSerge Pavlov1-1/+1
The alignment specified by a constant for the field `BumpPointerAllocator::InitialBuffer` exceeded the alignment guaranteed by `malloc` and `new` on Windows. This change set the alignment value to that of `long double`, which is defined by the used platform. It fixes https://bugs.llvm.org/show_bug.cgi?id=37944. Differential Revision: https://reviews.llvm.org/D48889 llvm-svn: 336311
2018-07-03Revert r336159, r336157. Some bots failed on qualified std::max_align_t, and ↵Erik Pilkington1-2/+1
other on unqualified max_align_t. I'll take another stab at this tomorrow. Any ideas for fixing this would be appreciated! http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/23071/steps/build_Lld/logs/stdio http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/11185/steps/build-stage1-compiler/logs/stdio llvm-svn: 336162
2018-07-03Some buildbots were choking on std::max_align_t, try using the global alias.Erik Pilkington1-1/+1
llvm-svn: 336159
2018-07-03[demangler] Fix a MSVC alignment warning.Erik Pilkington1-1/+2
This should fix llvm.org/PR37944 llvm-svn: 336157
2018-06-26Fix spelling mistakes in comments. NFCI.Simon Pilgrim1-4/+4
llvm-svn: 335603
2018-06-04Move Compiler.h from Demangle back to SupportDavid Blaikie1-2/+70
Code review feedback from r328123 prefers copying the few feature test macros used by Demangle into there, rather than sinking the header into an odd corner like Demangle. llvm-svn: 333965
2018-05-29Reverted commits 333390, 333391 and 333394Serge Pavlov1-5/+5
Build of shared library LLVMDemangle.so fails due to dependency problem. llvm-svn: 333395
2018-05-29Use uniform mechanism for OOM errors handlingSerge Pavlov1-5/+5
In r325551 many calls of malloc/calloc/realloc were replaces with calls of their safe counterparts defined in the namespace llvm. There functions generate crash if memory cannot be allocated, such behavior facilitates handling of out of memory errors on Windows. If the result of *alloc function were checked for success, the function was not replaced with the safe variant. In these cases the calling function made the error handling, like: T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); if (NewElts == nullptr) report_bad_alloc_error("Allocation of SmallVector element failed."); Actually knowledge about the function where OOM occurred is useless. Moreover having a single entry point for OOM handling is convenient for investigation of memory problems. This change removes custom OOM errors handling and replaces them with calls to functions `llvm::safe_*alloc`. Declarations of `safe_*alloc` are moved to a separate include file, to avoid cyclic dependency in SmallVector.h Differential Revision: https://reviews.llvm.org/D47440 llvm-svn: 333390
2018-05-24[demangler] Add ItaniumPartialDemangler::isCtorOrDtorFangrui Song1-0/+32
Reviewers: erik.pilkington, ruiu, echristo, pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47248 llvm-svn: 333159