180 Commits

Author SHA1 Message Date
Richard Smith
5764a8f942 Synchronize LLVM's copy of libc++abi's demangler with the libc++abi
version after r371273.

Also fix a minor issue in r371273 that only surfaced after template
instantiation from LLVM's use of the demangler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371274 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-07 00:11:53 +00:00
Nico Weber
ac1cfa0a87 llvm-undname: Correctly demangle vararg parameters
FunctionSignatureNode already had an IsVariadic field,
but it wasn't used anywhere yet. Set it and use it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362541 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 19:10:08 +00:00
Nico Weber
eef66d3ad4 llvm-undname: More coverage-related cleanups
- 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362540 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 18:49:05 +00:00
Nico Weber
8b3a59a1a3 llvm-undname: Add test coverage for demangleInitFiniStub()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362536 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 18:06:28 +00:00
Nico Weber
e03e3b716f llvm-undname: Yet more coverage for error paths
- 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362520 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 16:25:28 +00:00
Nico Weber
26bb87bf78 llvm-undname: More no-op changes to increase test coverage
- Add test coverage around invalid anon namespaces and
  for error paths in demanglePrimitiveType() and in
  demangleFullyQualifiedTypeName()

- Use DEMANGLE_UNREACHABLE in two more unreachable places

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362514 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 15:38:00 +00:00
Nico Weber
a94891b42d llvm-undname: Several behavior-preserving changes to increase coverage
- 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362506 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-04 15:13:30 +00:00
Nico Weber
1f9ff83b6d llvm-undname; Add more test coverage for demangleFunctionClass()
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.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362344 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-02 23:26:57 +00:00
Nico Weber
9b5b20a5ea Remove code path that's dead after r358835
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362333 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-02 17:41:07 +00:00
Nico Weber
31c9ebef19 llvm-undname: Support demangling char8_t
Ports clang's mangling support added in r354633 to llvm-undname.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361839 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-28 15:30:04 +00:00
Nico Weber
03087fa7e6 llvm-undname: Add support for local static thread guards
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361835 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-28 14:54:49 +00:00
Nico Weber
58d1481aed llvm-undname: Remove unreachable statement
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361786 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-28 01:20:36 +00:00
Nico Weber
b650beba4e llvm-undname: Extract demangleMD5Name() method; no behavior change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361783 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-27 23:10:42 +00:00
Nico Weber
e5bd1bfa35 llvm-undname: Make demangling of MD5 names more robust
Demangler::parse() for MD5 names would:

1. Put all remaining text into the MD5 name sight unseen
2. Not modify MangledName

This meant that if the demangler recursively called parse() (e.g. in
demangleLocallyScopedNamePiece()), every recursive call that started on
an MD5 name would add all remaining bytes to the output buffer but
only advance the input by a byte.  For valid inputs, MD5 types are
never (well, see comments for 2 exceptions) nested, but for invalid
input this could cause memory use quadratic in the input size.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361744 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-27 00:48:59 +00:00
Nico Weber
c53aaaaaac llvm-undname: Fix an assert-on-invalid, found by oss-fuzz
If a template parameter refers to a pointer to member, but the mangling
of that was a string literal instead of a real symbol, llvm-undname used
to crash instead of rejecting the input.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361402 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-22 15:53:23 +00:00
Nico Weber
aae1f9f35a llvm-undname: Fix assert-on->4GiB-string-literal, found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359109 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 16:09:38 +00:00
Nico Weber
29a5944cbf llvm-undname: Support demangling the spaceship operator
Also add a test for demanling the co_await operator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359007 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-23 16:20:27 +00:00
Nico Weber
6de91b31ce llvm-undname: Fix an assert-on-invalid, found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358891 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-22 15:05:18 +00:00
Nico Weber
ecefdcd2b9 llvm-undname: Fix hex escapes in wchar_t, char16_t, char32_t strings
llvm-undname used to put '\x' in front of every pair of nibbles, but
u"\xD7\xFF" produces a string with 6 bytes: \xD7 \0 \xFF \0 (and \0\0). Correct
for a single character (plus terminating \0) is u\xD7FF instead.
Now, wchar_t, char16_t, and char32_t strings roundtrip from source to
clang-cl (and cl.exe) and then llvm-undname.

(...at least as long as it's not a string like L"\xD7FF" L"foo" which
gets demangled as L"\xD7FFfoo", where the compiler then considers the
"f" as part of the hex escape. That seems ok.)

Also add a comment saying that the "almost-valid" char32_t string I
added in my last commit is actually produced by compilers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358857 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 17:19:27 +00:00
Nico Weber
f6b23dfdd4 llvm-undname: Fix stack overflow on almost-valid
If a unsigned with all 4 bytes non-0 was passed to outputHex(), there
were two off-by-ones in it:

- Both MaxPos and Pos left space for the final \0, which left the buffer
  one byte to small. Set MaxPos to 16 instead of 15 to fix.

- The `assert(Pos >= 0);` was after a `Pos--`, move it up one line.

Since valid Unicode codepoints are <= 0x10ffff, this could never really
happen in practice.

Found by oss-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358856 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 16:58:25 +00:00
Nico Weber
2f10db760a llvm-undname: Fix stack overflow on invalid found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358852 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 14:25:07 +00:00
Nico Weber
594fc0d116 llvm-undname: Improve string literal demangling with embedded \0 chars
- Don't assert when a string looks like a u32 string to the heuristic
  but doesn't have a length that's 0 mod 4.  Instead, classify those
  as u16 with embedded \0 chars. Found by oss-fuzz.
- Print embedded nul bytes as \0 instead of \x00.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358835 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 23:59:06 +00:00
Nico Weber
6a946515b8 llvm-undname: Attempt to fix leak-on-invalid found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358760 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-19 14:13:11 +00:00
Nico Weber
a329ade88f llvm-undname: Fix two more asserts-on-invalid, found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358708 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-18 19:52:32 +00:00
Nico Weber
61c38154e1 llvm-undname: Fix two asserts-on-invalid
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358707 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-18 19:30:21 +00:00
Nico Weber
14a17d2dd5 llvm-undname: Consistently use "return nullptr" in functions returning pointers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358492 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-16 14:24:42 +00:00
Nico Weber
1d7046374b llvm-undname: Fix nullptr deref on invalid structor names in template args
Similar to r358421: A StructorIndentifierNode has a Class field which
is read when printing it, but if the StructorIndentifierNode appears in
a template argument then demangleFullyQualifiedSymbolName() which sets
Class isn't called. Since StructorIndentifierNodes are always leaf
names, we can just reject them as well.

Found by oss-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358491 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-16 14:10:34 +00:00
Nico Weber
6900134167 llvm-undname: Fix nullptr deref on invalid conversion operator names in template args
A ConversionOperatorIdentifierNode has a TargetType which is read when
printing it, but if the ConversionOperatorIdentifierNode appears in a
template argument there's nothing that can provide the TargetType.
Normally the COIN is a symbol (leaf) name and takes its TargetType from the
symbol's type, but in a template argument context the COIN can only be
either a non-leaf name piece or a type, and must hence be invalid.

Similar to the COIN check in demangleDeclarator().

Found by oss-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358421 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 16:42:44 +00:00
Nico Weber
9fe9eec3d8 llvm-undname: Fix oss-fuzz-foudn crash-on-invalid with incomplete special table nodes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358367 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-14 23:32:37 +00:00
Nico Weber
eaedc0223b llvm-undname: Fix another crash-on-invalid found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358363 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-14 23:08:12 +00:00
Nico Weber
42f5049fce llvm-undname: Use UNREACHABLE after exhaustive switch returning everywhere
No behavior change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358241 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 23:23:00 +00:00
Nico Weber
0c94d6f746 llvm-undname: Name a bool param, no behavior change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358240 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 23:20:18 +00:00
Nico Weber
4b4fd781e2 llvm-undname: Fix out-of-bounds read on invalid intrinsic function code
Found by inspection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358239 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 23:11:33 +00:00
Nico Weber
54ee04c709 llvm-undname: Don't crash on incomplete enum tag manglings
Found by inspection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358238 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 22:59:25 +00:00
Nico Weber
65c0092a7b llvm-undname: Fix crash on incomplete virtual this adjusts
Found by oss-fuzz.

Also remove an else-after-return, this part has no behavior change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358237 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 22:47:18 +00:00
Nico Weber
0907e8aafa llvm-undname: Fix crash on invalid name in a template parameter pointer to member arg
Found by oss-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358234 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-11 22:23:35 +00:00
Nico Weber
12041c1bc8 llvm-undname: Fix another crash-on-invalid
This fixes a regression from https://reviews.llvm.org/D60354. We used to

  SymbolNode *Symbol = demangleEncodedSymbol(MangledName, QN);
  if (Symbol) {
    Symbol->Name = QN;
  }

but changed that to
  SymbolNode *Symbol = demangleEncodedSymbol(MangledName, QN);
  if (Error)
    return nullptr;
  Symbol->Name = QN;

and one branch somewhere returned a nullptr without setting Error.

Looking at the code changed in r340083 and r340710 that branch looks
like a remnant from an earlier attempt to demangle RTTI descriptors
that has since been rewritten -- so just remove this branch. It
shouldn't change behavior for correctly mangled symbols.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358112 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-10 17:31:34 +00:00
Nico Weber
5388309387 llvm-undname: Fix more crashes and asserts on invalid inputs
For functions whose callers don't check that enough input is present,
add checks at the start of the function that enough input is there and
set Error otherwise.

For functions that return AST objects, return nullptr instead of
incomplete AST objects with nullptr fields if an error occurred during
the function.

Introduce a new function demangleDeclarator() for the sequence
demangleFullyQualifiedSymbolName(); demangleEncodedSymbol() and
use it in the two places that had this sequence. Let this new function
check that ConversionOperatorIdentifiers have a valid TargetType.

Some of the bad inputs found by oss-fuzz, others by inspection.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357936 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-08 19:46:53 +00:00
Nico Weber
21c63d584f llvm-undname: Name a pair. No behavior change.
Differential Revision: https://reviews.llvm.org/D60210

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357653 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 23:29:05 +00:00
Nico Weber
c8d28c5350 llvm-undname: Fix a crash-on-invalid
Found by oss-fuzz, fixes issue 13260 on oss-fuzz.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357649 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 23:27:18 +00:00
Nico Weber
79f7028ca6 llvm-undame: Fix an assert-on-invalid
Found by oss-fuzz, fixes issue 12432 on os-fuzz.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357648 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 23:23:32 +00:00
Nico Weber
d05c59d5f9 llvm-undname: Fix an assert-on-invalid
Found by oss-fuzz, fixes issues 12428 and 12429 on oss-fuzz.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357647 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 23:19:39 +00:00
Nico Weber
61d2657ecc llvm-undname: Fix a crash-on-invalid
Found by oss-fuzz, fixes issues 12435 and 12438 on oss-fuzz.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357646 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 23:15:56 +00:00
Konstantin Zhuravlyov
8f914744dc Add missing include (cstdlib) to Demangle.h
Differential Revision: https://reviews.llvm.org/D57035


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351861 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-22 19:18:18 +00:00
Chandler Carruth
438784aaf3 Update more file headers across all of the LLVM projects in the monorepo
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351648 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 10:56:40 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
James Henderson
c020a4b755 Add __[_[_]]Z demangling to new common demangle function
This is a follow-up to r351448. It adds support for other _*Z extensions
of the Itanium demanling, to the newly available demangle function
heuristic.

Reviewed by: erik.pilkington, rupprecht, grimar

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351551 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 13:58:41 +00:00
Erik Pilkington
cc6eedfcf3 NFC: Make the copies of the demangler byte-for-byte identical
With this patch, the copies of the files ItaniumDemangle.h,
StringView.h, and Utility.h are kept byte-for-byte in sync between
libcxxabi and llvm. All differences (namespaces, fallthrough, and
unreachable macros) are defined in each copies' DemanglerConfig.h.

This patch also adds a script to copy changes from libcxxabi
(cp-to-llvm.sh), and a README.txt explaining the situation.

Differential revision: https://reviews.llvm.org/D53538

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351474 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-17 20:37:51 +00:00
James Henderson
bc34da10fa Move demangling function from llvm-objdump to Demangle library
This allows it to be used in an upcoming llvm-readobj change.

A small change in internal behaviour of the function is to always call
the microsoftDemangle function if the string does not have an itanium
encoding prefix, rather than only if it starts with '?'. This is
harmless because the microsoftDemangle function does the same check
already.

Reviewed by: grimar, erik.pilkington

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351448 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-17 15:18:44 +00:00
Zachary Turner
f4448ba208 [llvm-undname] Add support for demangling msvc's noexcept types.
Starting in C++17, MSVC introduced a new mangling for function
parameters that are themselves noexcept functions.  This patch
makes llvm-undname properly demangle them.

Patch by Zachary Henkel
Differential Revision: https://reviews.llvm.org/D55769

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350656 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-08 21:05:51 +00:00