aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/ItaniumDemangle.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2018-04-12[demangler] Add a partial demangling API for LLDB.Erik Pilkington1-0/+191
This parses a mangled name into an AST (typically an intermediate stage in itaniumDemangle) and provides some functions to query certain properties or print certain parts of the demangled name. Differential revision: https://reviews.llvm.org/D44668 llvm-svn: 329951
2018-04-12[demangler] NFC: Some refactoring to support partial demangling.Erik Pilkington1-42/+97
I'm committing this to libcxxabi too so that the two demanglers remain as simular as possible. llvm-svn: 329950
2018-04-09[demangler] Support for fold expressions.Erik Pilkington1-3/+126
llvm-svn: 329601
2018-04-09[demangler] Support for <data-member-prefix>.Erik Pilkington1-0/+9
llvm-svn: 329600
2018-04-09[demangler] Support for partially substituted sizeof....Erik Pilkington1-1/+24
llvm-svn: 329599
2018-03-26[demangler] Fix a bug in r328464 found by oss-fuzz.Erik Pilkington1-2/+27
llvm-svn: 328507
2018-03-25[demangler] Use a back-patching scheme to resolve forward references.Erik Pilkington1-40/+79
Strictly in a conversion operator's type, a <template-param> refers to a <template-arg> that is further ahead in the mangled name. Instead of doing a second parse to resolve these, introduce a ForwardTemplateReference Node and back-patch the referenced <template-arg> when we're in the right context. This is also a correctness fix, previously we would only do a second parse if the <template-param> was out of bounds in the current set of <template-args>. This lead to misdemangles (gasp!) when the conversion operator was a member of a templated struct, for instance. llvm-svn: 328464
2018-03-25[demangler] Tweak how parameter pack sizes are determined.Erik Pilkington1-210/+105
Rather than eagerly propagating up parameter pack sizes in Node ctors, find the parameter pack size during printing. This is being done to support back-patching forward referencing <template-param>s. llvm-svn: 328463
2018-03-25[demangler] Support for clang's enable_if attribute.Erik Pilkington1-6/+35
Fixes PR33569. llvm-svn: 328462
2018-03-21Reapply Support layering fixes.David Blaikie1-4/+6
Compiler.h is used by Demangle (which Support depends on) - so sink it into Demangle to avoid a circular dependency DataTypes.h is used by llvm-c (which Support depends on) - so sink it into llvm-c. DataTypes.h could probably be fixed the other way - making llvm-c depend on Support instead of Support depending on llvm-c - if anyone feels that's the better option, happy to work with them on that. I /think/ this'll address the layering issues that previous attempts to commit this have triggered in the Modules buildbot, but I haven't been able to reproduce that build so can't say for sure. If anyone's having trouble with this - it might be worth taking a look to see if there's a quick fix/something small I missed rather than revert, but no worries. llvm-svn: 328123
2018-03-21Revert layering changesJonas Devlieghere1-6/+4
This reverts: r328072 "Move Compiler.h from Support to Demangler to fix layering." r328073 "Fix the actual user of DataTypes.h in llvm-c to avoid the circular dependency" Failing bots: http://green.lab.llvm.org/green/job/clang-stage2-coverage-R/ http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/ llvm-svn: 328085
2018-03-21Move Compiler.h from Support to Demangler to fix layering.David Blaikie1-4/+6
Support depends on Demangle (Support/Unix/Signals.inc), so Demangle including Support/Compiler.h created a circular dependency. Leave a forwarding shim of Compiler.h because it makes more sense for users (a deeper fix might involve splitting Support into lower and upper Support - but that also sounds a bit weird/awkward) than thinking about the dependency on the Demangler. llvm-svn: 328072
2018-03-19[demangler] Recopy the demangler from libcxxabi.Erik Pilkington1-3943/+4521
Some significant work has gone into libcxxabi's copy of this file: - Uses an AST to represent mangled names. - Support/bugfixes for many C++ features. - Uses LLVM coding style. llvm-svn: 327859
2017-12-19Silence a bunch of implicit fallthrough warningsAdrian Prantl1-1/+2
llvm-svn: 321114
2017-05-28[ItaniumDemangle] Fix a exponential string copying bugErik Pilkington1-0/+3
This is a port of libcxxabi's r304113. llvm-svn: 304114
2017-05-27[Demangler] copy changes made in libcxxabi's r303718 to ItaniumDemangleErik Pilkington1-21/+28
llvm-svn: 304053
2017-05-24Demangler: Fix constructor cv qualifier handlingTamas Berghammer1-0/+2
Previously if we parsed a constructor then we set parsed_ctor_dtor_cv to true and never reseted it. This causes issue when a template argument references a constructor (e.g. type of lambda defined inside a constructor) as we will have the parsed_ctor_dtor_cv flag set what will cause issues when parsing later arguments. Differential Revision: https://reviews.llvm.org/D33385 libcxxabi change: https://reviews.llvm.org/rL303737 llvm-svn: 303738
2017-05-18Revert r303375 "LLVM_FALLTHROUGH instead of fall-through comment."Rui Ueyama1-1/+1
This reverts commit r303375 since it didn't compile. llvm-svn: 303377
2017-05-18LLVM_FALLTHROUGH instead of fall-through comment.Galina Kistanova1-1/+1
llvm-svn: 303375
2017-05-18Reduce gcc-7 warnings by fall-through comments.Galina Kistanova1-1/+1
llvm-svn: 303365
2017-01-31Add support for demangling C++11 thread_local variables. David Bozier1-0/+23
In clang, the grammar for mangling for these names are "<special-name> ::= TW <object name>" for wrapper variables or "<special-name> ::= TH <object name>" for initialization variables. Initial change was made in libccxxabi r293638 llvm-svn: 293643
2017-01-27Fix ASAN failure in cxa_demangleMehdi Amini1-1/+2
Found with ASAN + libFuzzer by Kostya Serebryany <kcc@google.com> llvm-svn: 293330
2017-01-24Demangle: correct demangling for CV-qualified functionsSaleem Abdulrasool1-6/+9
When demangling a CV-qualified function type with a final reference type parameter, we would treat the reference type parameter as a r-value ref accidentally. This would result in the improper decoration of the function type itself. Resolves PR31741! llvm-svn: 292976
2017-01-24Demangle: use named values for CV qualifiersSaleem Abdulrasool1-12/+18
Rather than hard-coding magic values of 1, 2, 4 (bit-field), use an enum to name the values. NFC. llvm-svn: 292975
2017-01-24Demangle: avoid butchering parameter typeSaleem Abdulrasool1-2/+2
When demangling a CV-qualified function type with a final parameter with a reference type, we would insert the CV qualification on the parameter rather than the function, and in the process adjust the insertion point by one extra, splitting the type name. This avoids doing so, even though the attribution is still incorrect. llvm-svn: 292965