54 Commits

Author SHA1 Message Date
Martin Storsjo
bc0cffa673 Remove a superfluous semicolon
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337599 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 18:43:42 +00:00
Zachary Turner
3dd57df1d1 [Demangler] Correctly factor in assignment when allocating.
Incidentally all allocations that we currently perform were
properly aligned, but this was only an accident.

Thanks to Erik Pilkington for catching this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337596 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 18:35:06 +00:00
Benjamin Kramer
70215f556f [Demangler] Add missing overrides
-Winconsistent-missing-override complains about this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337592 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 18:22:12 +00:00
Zachary Turner
aeb65f137a Fix a few warnings and style issues in MS demangler.
Also remove a broken test case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337591 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 18:07:33 +00:00
Zachary Turner
42e40ea33e Add a Microsoft Demangler.
This adds initial support for a demangling library (LLVMDemangle)
and tool (llvm-undname) for demangling Microsoft names.  This
doesn't cover 100% of cases and there are some known limitations
which I intend to address in followup patches, at least until such
time that we have (near) 100% test coverage matching up with all
of the test cases in clang/test/CodeGenCXX/mangle-ms-*.

Differential Revision: https://reviews.llvm.org/D49552

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337584 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 17:27:48 +00:00
Fangrui Song
cf121a0f05 [Demangle] Add missing header files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337318 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-17 19:50:41 +00:00
Zachary Turner
08ea6f8319 Add missing include.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337317 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-17 19:48:46 +00:00
Zachary Turner
dc84f3b6c1 Add some helper functions to the demangle utility classes.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337316 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-17 19:42:29 +00:00
Zachary Turner
d554de1ec8 Add missing includes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337218 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-16 21:34:25 +00:00
Zachary Turner
937d2c0dee [LLVMDemangle] Move some utility classes to header files.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337217 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-16 21:24:03 +00:00
Serge Pavlov
c7bc4c373c [demangler] Avoid alignment warning
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336311 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-05 06:22:39 +00:00
Erik Pilkington
7b549ea6b6 Revert r336159, r336157. Some bots failed on qualified std::max_align_t, and 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336162 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-03 01:30:53 +00:00
Erik Pilkington
3369ac0dd8 Some buildbots were choking on std::max_align_t, try using the global alias.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336159 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-03 00:48:27 +00:00
Erik Pilkington
22e1f60570 [demangler] Fix a MSVC alignment warning.
This should fix llvm.org/PR37944

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336157 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-03 00:23:18 +00:00
Simon Pilgrim
799df9565b Fix spelling mistakes in comments. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335603 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-26 14:06:23 +00:00
David Blaikie
475e530121 Move Compiler.h from Demangle back to Support
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333965 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-04 22:53:38 +00:00
Serge Pavlov
d3b4e81711 Reverted commits 333390, 333391 and 333394
Build of shared library LLVMDemangle.so fails due to dependency problem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333395 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-29 07:05:41 +00:00
Serge Pavlov
79428ba469 Added library LLVMSupport to dependencies of LLVMDemangle
After r333390 build of LLVMDemangle.so fails due to unresolved
reference `llvm::report_bad_alloc_error`.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333394 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-29 06:48:57 +00:00
Serge Pavlov
5c9fd60f9f Use uniform mechanism for OOM errors handling
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333390 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-29 05:39:08 +00:00
Fangrui Song
109abe0d9a [demangler] Add ItaniumPartialDemangler::isCtorOrDtor
Reviewers: erik.pilkington, ruiu, echristo, pcc

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D47248

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333159 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-24 06:57:57 +00:00
Erik Pilkington
d0381b68b8 [demangler] Add a partial demangling API for LLDB.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329951 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-12 20:41:38 +00:00
Erik Pilkington
87bdde82ce [demangler] NFC: Some refactoring to support partial demangling.
I'm committing this to libcxxabi too so that the two demanglers remain as
simular as possible.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329950 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-12 20:41:06 +00:00
Erik Pilkington
650fe38f58 [demangler] Support for fold expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329601 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 18:33:01 +00:00
Erik Pilkington
6b669f18f0 [demangler] Support for <data-member-prefix>.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329600 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 18:32:25 +00:00
Erik Pilkington
526e92a9cf [demangler] Support for partially substituted sizeof....
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329599 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 18:31:50 +00:00
Erik Pilkington
a76b7566a8 [demangler] Fix a bug in r328464 found by oss-fuzz.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328507 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-26 15:34:36 +00:00
Erik Pilkington
21f282660d [demangler] Use a back-patching scheme to resolve forward references.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328464 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-25 22:50:33 +00:00
Erik Pilkington
4990859072 [demangler] Tweak how parameter pack sizes are determined.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328463 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-25 22:49:57 +00:00
Erik Pilkington
e7042cfa9c [demangler] Support for clang's enable_if attribute.
Fixes PR33569.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328462 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-25 22:49:16 +00:00
David Blaikie
1c62040a5c Reapply Support layering fixes.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328123 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 17:31:49 +00:00
Jonas Devlieghere
74473fc50b Revert layering changes
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/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328085 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 10:35:09 +00:00
David Blaikie
ab9186d500 Move Compiler.h from Support to Demangler to fix layering.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328072 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 04:07:05 +00:00
Erik Pilkington
d767d0a7b4 [demangler] Recopy the demangler from libcxxabi.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327859 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-19 15:18:23 +00:00
Adrian Prantl
c0ade050e0 Silence a bunch of implicit fallthrough warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321114 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-19 22:05:25 +00:00
Erik Pilkington
1e9ed47d14 [ItaniumDemangle] Fix a exponential string copying bug
This is a port of libcxxabi's r304113.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304114 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-28 23:24:52 +00:00
Erik Pilkington
bf14f47c78 [Demangler] copy changes made in libcxxabi's r303718 to ItaniumDemangle
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304053 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-27 01:48:34 +00:00
Tamas Berghammer
b762e5bdbc Demangler: Fix constructor cv qualifier handling
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303738 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24 11:29:02 +00:00
Rui Ueyama
54d256ca56 Revert r303375 "LLVM_FALLTHROUGH instead of fall-through comment."
This reverts commit r303375 since it didn't compile.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303377 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-18 20:18:24 +00:00
Galina Kistanova
f73a055bca LLVM_FALLTHROUGH instead of fall-through comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303375 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-18 20:01:52 +00:00
Galina Kistanova
8762436dd0 Reduce gcc-7 warnings by fall-through comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303365 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-18 17:53:47 +00:00
David Bozier
34d37a4707 Add support for demangling C++11 thread_local variables.
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293643 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31 15:56:36 +00:00
Mehdi Amini
e1698550ad Fix ASAN failure in cxa_demangle
Found with ASAN + libFuzzer by Kostya Serebryany <kcc@google.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293330 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 20:32:16 +00:00
Saleem Abdulrasool
815bff1cc4 Demangle: correct demangling for CV-qualified functions
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!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292976 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 20:04:58 +00:00
Saleem Abdulrasool
ed1b025f1b Demangle: use named values for CV qualifiers
Rather than hard-coding magic values of 1, 2, 4 (bit-field), use an enum
to name the values.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292975 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 20:04:56 +00:00
Saleem Abdulrasool
60b4e66e58 Demangle: avoid butchering parameter type
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292965 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 18:52:19 +00:00
Saleem Abdulrasool
f2a3664b8a Revert "Demangle: only demangle mangled symbols"
This reverts SVN r286795.  This was incorrect the demangler is expected
to be able to demangle types as well as functions.  This makes the
behaviour of itaniumDemangle similar to __cxa_demangle once more.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292573 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 03:54:04 +00:00
Saleem Abdulrasool
902878bb3f Demangle: remove references to allocator for default allocator
The demangler had stopped using a custom allocator but had not been updated to
remove the use of the explicit allocator passing.  This removes that as we do
not need to do anything special here anymore.  This just makes the code more
compact.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287472 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-20 00:20:27 +00:00
Saleem Abdulrasool
21918ee4aa Demangle: remove unnecessary typedef for std::vector
We could create a local typedef for std::vector called Vector.  Inline the use
of std::vector rather than use the typedef.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287471 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-20 00:20:25 +00:00
Saleem Abdulrasool
e17a816352 Demangle: replace custom typedef for std::string with std::string
We created a local typedef for `std::basic_string<char, std::char_traits<char>>`
which is just `std::string`.  Remove the local typedef and propagate the type
information through the rest of the demangler.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287470 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-20 00:20:23 +00:00
Saleem Abdulrasool
7f90f9e9a9 Demangle: use direct member initialization (NFC)
Prefer direct member initialization over the explicit out-of-line initialization
for the construction of the local type.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287469 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-20 00:20:20 +00:00