Commit Graph

250 Commits

Author SHA1 Message Date
Nathan Sidwell 201c4b9cc4 [demangler] Rust demangler buffer return
The rust demangler has some odd buffer handling code, which will copy
the demangled string into the provided buffer, if it will fit.
Otherwise it uses the allocated buffer it made.  But the length of the
incoming buffer will have come from a previous call, which was the
length of the demangled string -- not the buffer size.  And of course,
we're unconditionally allocating a temporary buffer in the first
place.  So we don't actually get buffer reuse, and we get a memcpy in
somecases.

However, nothing in LLVM ever passes in a non-null pointer.  Neither
does anything pass in a status pointer that is then made use of.  The
only exercise these have is in the test suite.

So let's just make the rust demangler have the same API as the dlang
demangler.

Reviewed By: tmiasko

Differential Revision: https://reviews.llvm.org/D123420
2022-04-13 08:50:04 -07:00
Nathan Sidwell 4a4d0985d4 [demangler] Node precision dumper
Add contents to the demangler node dumper's print(Prec) functions.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D122740
2022-04-06 14:04:15 -07:00
Nathan Sidwell 51f6caf2fb [demangler][NFC] Rename SwapAndRestore to ScopedOverride
The demangler has a utility class 'SwapAndRestore'. That name is
confusing. It's not swapping anything, and the restore part happens at
the object's destruction. What it's actually doing is allowing a
override of some value that is dynamically accessible within the
lifetime of a lexical scope. Thus rename it to ScopedOverride, and
tweak it's member variable names.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D122606
2022-04-06 12:55:35 -07:00
David Blaikie 1d1cf9b6c4 ItaniumDemangler: Update BinaryExpr::match to match the ctor
Not sure if this could use more testing, but hopefully this is adequate.
2022-03-28 21:51:27 +00:00
Nathan Sidwell 1066e397fa [demangler] Add StringView conversion operator
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 11:19:55 -07:00
Nathan Sidwell d1587c38e6 [llvm] Fix string copy confusion
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
2022-03-28 09:37:36 -07:00
Nathan Sidwell c354167ae2 [demangler] Add support for C++20 modules
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-03-22 09:42:52 -07:00
Nathan Sidwell 704b21cb4f [demangler] Remove StdQualifiedName
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-02-07 07:49:30 -08:00
serge-sans-paille a2f6921ef2 [llvm] Remove unused headers in LLVMDemangle
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
2022-01-21 10:18:32 +01:00
Luís Ferreira 6983968e83 [Demangle] Pass Ret parameter from decodeNumber by reference
Since Ret parameter is never meant to be nullptr, let's pass it by reference instead of a raw pointer.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D117046
2022-01-12 21:57:31 +00:00
Luís Ferreira b21ea1c270 [Demangle] Add support for D types back referencing
This patch adds support for type back referencing, allowing demangling of
    compressed mangled symbols with repetitive types.

    Signed-off-by: Luís Ferreira <contact@lsferreira.net>

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D111419
2022-01-12 21:57:31 +00:00
Luís Ferreira bec08795db [Demangle] Add support for D symbols back referencing
This patch adds support for identifier back referencing allowing compressed
    mangled names by avoiding repetitiveness.

    Signed-off-by: Luís Ferreira <contact@lsferreira.net>

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D111417
2022-01-12 21:57:31 +00:00
Luís Ferreira 669bfcf036 [Demangle] Add minimal support for D simple basic types
This patch implements simple demangling of two basic types to add minimal type functionality. This will be later used in function type parsing. After that being implemented we can add the rest of the types and test the result of the type name.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D111416
2022-01-12 21:57:30 +00:00
Luís Ferreira 83087c096a [Demangle] Add support for D function-local parent symbols
Internally `__Sddd` function-local parent symbols are used to solve ambiguities on symbols in
    the same scope with the same mangled name.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D114309
2021-12-07 01:46:13 +00:00
Luís Ferreira 8a7ddf9e22 [Demangle] Add support for D special identifiers
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D114308
2021-12-07 01:46:08 +00:00
David Blaikie bd4c6a476f Add missing header 2021-11-29 16:29:37 -08:00
Luís Ferreira b779f02a1c [Demangle] Add support for D anonymous symbols
Anonymous symbols are represented by 0 in the mangled symbol. We should skip
    them in order to represent the demangled name correctly, otherwise demangled
    names like `demangle..anon` can happen.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D114307
2021-11-29 16:05:48 -08:00
David Blaikie 6e08abdc25 [Demangle] Add support for multiple identifiers in D qualified names
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D114305
2021-11-29 16:05:33 -08:00
David Blaikie e63c799a76 [Demangle] Add support for D simple single qualified names
This patch adds support for simple single qualified names that includes
    internal mangled names and normal symbol names.

Differential Revision: https://reviews.llvm.org/D111415
2021-11-29 16:05:32 -08:00
David Blaikie 1bed03b5e3 Fix memory leak in D demangler 2021-11-09 16:08:14 -08:00
Luís Ferreira 22a1aa5a43 [Demangle] Add minimal support for D programming language
This patch adds minimal support for D programming language demangling on LLVM
core based on the D name mangling spec. This will allow easier integration on a
future LLDB plugin for D either in the upstream tree or outside of it.

Minimal support includes recognizing D demangling encoding and at least one
mangling name, which in this case is `_Dmain` mangle.

Reviewed By: jhenderson, lattner

Differential Revision: https://reviews.llvm.org/D111414
2021-11-09 09:29:13 -08:00
Luís Ferreira 2e97236aac [Demangle] Rename OutputStream to OutputString
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-21 17:34:57 -07:00
Lasse Folger 134e1817f6 [lldb] change name demangling to be consistent between windows and linx
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-10-19 12:04:37 +02:00
Tomasz Miąsko 41a6fc8438 [Demangle] Extract nonMicrosoftDemangle from llvm::demangle
Introduce a new demangling function that supports symbols using Itanium
mangling and Rust v0 mangling, and is expected in the near future to
include support for D mangling as well.

Unlike llvm::demangle, the function does not accept extra underscore
decoration. The callers generally know exactly when symbols should
include the extra decoration and so they should be responsible for
stripping it.

Functionally the only intended change is to allow demangling Rust
symbols with an extra underscore decoration through llvm::demangle,
which matches the existing behaviour for Itanium symbols.

Reviewed By: dblaikie, jhenderson

Part of https://reviews.llvm.org/D110664
2021-10-16 13:32:16 +02:00
Tomasz Miąsko c8c2b4629f [Demangle][Rust] Parse non-ASCII identifiers
Rust allows use of non-ASCII identifiers, which in Rust mangling scheme
are encoded using Punycode.

The encoding deviates from the standard by using an underscore as the
separator between ASCII part and a base-36 encoding of non-ASCII
characters (avoiding hypen-minus in the symbol name). Other than that,
the encoding follows the standard, and the decoder implemented here in
turn follows the one given in RFC 3492.

To avoid an extra intermediate memory allocation while decoding
Punycode, the interface of OutputStream is extended with an insert
method.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D104366
2021-10-01 22:08:32 +02:00
Saleem Abdulrasool 9c2de23821 Demangle: correct swift_async demangling for Microsoft scheme
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-14 11:43:44 -07:00
Varun Gandhi 92dcb1d2db [Clang] Introduce Swift async calling convention.
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-07-09 11:50:10 -07:00
Tomasz Miąsko 6cc6ada143 [Demangle][Rust] Hide implementation details NFC
Move content of the "public" header into the implementation file.

This also renames two enumerations that were previously used through
`rust_demangle::` scope, to avoid breaking a build bot with older
version of GCC that rejects uses of enumerator through `E::A` if there
is a variable with the same name as enumeration `E` in the scope.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D104362
2021-06-23 18:28:16 +02:00
Tomasz Miąsko 2a5bb9c877 [Demangle][Rust] Parse dot suffix
Allow mangled names to include an arbitrary dot suffix, akin to vendor
specific suffix in Itanium mangling.

Primary motivation is a support for symbols renamed during ThinLTO
import / promotion (ThinLTO is the default configuration for optimized
builds in rustc).

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D104358
2021-06-18 09:29:45 +02:00
Tomasz Miąsko 9b1085604e [Demangle] Support Rust v0 mangling scheme in llvm::demangle
The llvm::demangle is currently used by llvm-objdump and llvm-readobj,
so this effectively adds support for Rust v0 mangling to those
applications.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D104340
2021-06-17 10:37:26 +02:00
Tomasz Miąsko f9a79356f2 [Demangle][Rust] Parse const backreferences
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103848
2021-06-08 10:01:50 +02:00
Tomasz Miąsko 44d63c57c1 [Demangle][Rust] Parse type backreferences
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103847
2021-06-08 10:01:49 +02:00
Tomasz Miąsko 82b7e822d0 [Demangle][Rust] Parse path backreferences
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103459
2021-06-08 10:01:49 +02:00
Tomasz Miąsko 43929ccc12 [Demangle][Rust] Parse instantiating crate
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103460
2021-06-07 19:16:11 +02:00
Tomasz Miąsko 619a65e5e4 [Demangle][Rust] Parse dyn-trait-assoc-binding
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103364
2021-06-07 18:18:31 +02:00
Tomasz Miąsko 1499afa09b [Demangle][Rust] Parse dyn-trait
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103361
2021-06-07 18:18:31 +02:00
Tomasz Miąsko 89615a5e92 [Demangle][Rust] Parse dyn-bounds
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103151
2021-06-07 18:18:30 +02:00
Tomasz Miąsko a67a234ec7 [Demangle][Rust] Parse binders
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102729
2021-06-02 10:36:45 +02:00
Tomasz Miąsko 75cc1cf018 [Demangle][Rust] Parse function signatures
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102581
2021-05-22 11:49:08 +02:00
Tomasz Miąsko e4fa6c95ac [Demangle][Rust] Parse references
Reviewed By: dblaikie

Part of https://reviews.llvm.org/D102580
2021-05-22 11:49:08 +02:00
Tomasz Miąsko 6aac56336d [Demangle][Rust] Parse raw pointers
Reviewed By: dblaikie

Part of https://reviews.llvm.org/D102580
2021-05-22 11:49:08 +02:00
Tomasz Miąsko 57f408861d [Demangle][Rust] Speculative fix for bot build failure
> error: ‘InType’ is not a class, namespace, or enumeration
2021-05-19 00:40:24 +02:00
Tomasz Miąsko 774de7a09b [Demangle][Rust] Parse tuples
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102579
2021-05-19 00:04:42 +02:00
Tomasz Miąsko a84c65c204 [Demangle][Rust] Parse slice type
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102578
2021-05-19 00:04:41 +02:00
Tomasz Miąsko b42400ccf3 [Demangle][Rust] Parse array type
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102573
2021-05-19 00:04:41 +02:00
Tomasz Miąsko 068332978c [Demangle][Rust] Parse named types
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102571
2021-05-19 00:04:41 +02:00
Tomasz Miąsko f933f7fbd0 [Demangle][Rust] Parse trait definitions
Part of https://reviews.llvm.org/D102549
2021-05-15 23:52:25 +02:00
Tomasz Miąsko 9fa138009f [Demangle][Rust] Parse trait implementations
Part of https://reviews.llvm.org/D102549
2021-05-15 23:52:25 +02:00
Tomasz Miąsko f0f2a8b21c [Demangle][Rust] Parse inherent implementations
Part of https://reviews.llvm.org/D102549
2021-05-15 23:52:25 +02:00
Tomasz Miąsko 2ba49f6ae6 [Demangle][Rust] Parse char constants
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102524
2021-05-15 10:48:27 +02:00