286 Commits

Author SHA1 Message Date
Dmitry Vasilyev
569ec185f5 [llvm-cxxfilt] Added the option --no-params (#75348)
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-04 20:42:51 +04:00
Arthur Eubanks
c91fab5041 Revert "[llvm-cxxfilt] Added the option --no-params (#75348)"
This reverts commit 71f8ea3062a6b0a190835853ee77e58469763b9e.

Test doesn't pass on mac. See comments on
https://github.com/llvm/llvm-project/pull/75348.
2024-01-02 20:27:01 +00:00
Dmitry Vasilyev
71f8ea3062
[llvm-cxxfilt] Added the option --no-params (#75348)
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-02 22:04:43 +04:00
zhijian
1ff958c350 [llvm-cxxfilt] Do not consider the prefix dot as part of the demangled symbol name.
Summary:

In AIX OS, function entry label are begin with '.', it can not be decoded currently.
we support to decode the name in this patch for all OS.

Reviewers: Fangrui Song, James Henderson,
Differential Revision: https://reviews.llvm.org/D139864
2023-09-26 11:07:59 -04:00
Fangrui Song
1d133d9e88 [Demangle] Include <exception> for IWYU
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-18 22:10:58 -07:00
Nick Desaulniers
8bb9414f14 [Demangle] use std::string_view::data rather than &*std::string_view::begin
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-07-13 10:20:09 -07:00
Nick Desaulniers
6641d2b7df [MicrosoftDemangle] fix warn-trailing false positive
A follow up to commit 6bad76c7ae93 ("[Demangle] fix windows tests")
based on @thakis' report.

Fixes: #63740

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D154875
2023-07-11 09:25:52 -07:00
Nick Desaulniers
8abbc17ff3 reland: [Demangle] make llvm::demangle take std::string_view rather than const std::string&
As suggested by @erichkeane in
https://reviews.llvm.org/D141451#inline-1429549

There's potential for a lot more cleanups around these APIs. This is
just a start.

Callers need to be more careful about sub-expressions producing strings
that don't outlast the expression using `llvm::demangle`. Add a
release note.

Differential Revision: https://reviews.llvm.org/D149104
2023-06-06 10:18:06 -07:00
Nick Desaulniers
86b6ac5d54 [Demangle] refactor DLangDemangle to use std::string_view
Many existing methods of the D Language Demangler take a C style string
and return an adjusted pointer to the same object as the input string is
consumed.

Make it more obvious by changing the signatures to accept
std::string_view& when the input is modified vs a copy of a
std::string_view when the input is not.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D152177
2023-06-05 14:38:07 -07:00
Nick Desaulniers
db98ac0827 [Demangle] convert microsoftDemangle to take a std::string_view
This should be last of the "bottom-up conversions" of various demanglers
to accept std::string_view.  After this, D149104 may be revisited.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D152176
2023-06-05 13:00:20 -07:00
Nick Desaulniers
936dcc89da [Demangle] convert is*Encoding to use std::string_view
This was originally a part of D149104 which was backed out. This change
is uncontroversial though, so split it out and reland it.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D152042
2023-06-05 09:33:49 -07:00
Nick Desaulniers
f5371eb3d3 [Damangle] convert dlangDemangle to use std::string_view
I was doing this API conversion to use std::string_view top-down in
D149104, but this exposed issues in individual demanglers that needed to
get fixed first. There's no issue with the conversion for the D language
demangler, so convert it.

I have a more aggressive refactoring of the entire D language demangler
to use std::string_view more extensively, but the interface with
llvm::nonMicrosoftDemangle is the more interesting one.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D151003
2023-06-02 15:19:41 -07:00
Nick Desaulniers
12d967c95f [Damangle] convert rustDemangle to use std::string_view
I was doing this API conversion to use std::string_view top-down in
D149104, but this exposed issues in individual demanglers that needed to
get fixed first. There's no issue with the conversion for the Rust
demangler, so convert it first.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149784
2023-06-02 15:08:14 -07:00
Nick Desaulniers
61e1c3d80d [Demangle] convert itaniumDemangle and nonMicrosoftDemangle to use 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-06-02 14:53:49 -07:00
Nick Desaulniers
3b01fa264c [Demangle] remove unused status param of itaniumDemangle
No call sites interpreted this value meaningfully. Simplify this
interface.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149707
2023-05-03 11:51:35 -07:00
Nick Desaulniers
7277a72b90 [Demangle] remove unused params of itaniumDemangle
No call sites use these parameters, so drop them.
Equivalent to D148940.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D149703
2023-05-03 09:57:41 -07:00
Nick Desaulniers
3e3c6f24ff Revert "[Demangle] make llvm::demangle take std::string_view rather than const std::string&"
This reverts commit c117c2c8ba4afd45a006043ec6dd858652b2ffcc.

itaniumDemangle calls std::strlen with the results of
std::string_view::data() which may not be NUL-terminated. This causes
lld/test/wasm/why-extract.s  to fail when "expensive checks" are enabled
via -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON. See D149675 for further
discussion. Back this out until the individual demanglers are converted
to use std::string_view.
2023-05-02 15:54:09 -07:00
Nick Desaulniers
c117c2c8ba [Demangle] make llvm::demangle take std::string_view rather than const std::string&
As suggested by @erichkeane in
https://reviews.llvm.org/D141451#inline-1429549

There's potential for a lot more cleanups around these APIs. This is
just a start.

Callers need to be more careful about sub-expressions producing strings
that don't outlast the expression using ``llvm::demangle``. Add a
release note.

Reviewed By: MaskRay, #lld-macho

Differential Revision: https://reviews.llvm.org/D149104
2023-05-02 11:20:15 -07:00
Nick Desaulniers
c2709fcb0a [Demangle] remove unused params of microsoftDemangle
No call sites use these parameters, so drop them.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148940
2023-04-21 15:37:00 -07:00
Nick Desaulniers
6bad76c7ae [Demangle] fix windows tests
My reland of https://reviews.llvm.org/D148546 has caused a few windows
demangler tests to fail when run with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON
on windows.

I have a sneaking suspicion that MSVC's
std::string_view::iterator::operator* may be missing a nullptr check.

Link: https://lab.llvm.org/buildbot/#/builders/42/builds/9723/steps/7/logs/stdio

Reviewed By: ayzhao

Differential Revision: https://reviews.llvm.org/D148852
2023-04-20 16:41:09 -07:00
Nick Desaulniers
7c59e8001a Reland: [Demangle] replace use of llvm::StringView w/ std::string_view
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-20 11:22:20 -07:00
Fangrui Song
d81cdb49d7 Revert D148384 "[Demangle] replace use of llvm::StringView w/ std::string_view"
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 18:42:11 -07:00
Nick Desaulniers
e0c4ffa796 [Demangle] fix windows build
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 16:25:14 -07:00
Nick Desaulniers
3e559509b4 [Demangle] replace use of llvm::StringView w/ std::string_view
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
2023-04-14 15:48:38 -07:00
Nick Desaulniers
5e53e1bbc3 [StringView] remove consumeFront
Towards converting our use of llvm::StringView to std::string_view,
remove a method that std::string_view doesn't have.

This could be moved to the nascent llvm/ADT/StringViewExtras.h, but the
use is highly localized to one TU. Move this to be a static function
there.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148375
2023-04-14 15:34:24 -07:00
Nick Desaulniers
ee6abfc5ea [StringView] remove popFront
Towards converting our use of llvm::StringView to std::string_view,
remove a method that std::string_view doesn't have.

llvm::StringView::popFront is similar to std::string_view::remove_prefix
but with a reference to std::string_view::front taken first.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148363
2023-04-14 13:13:46 -07:00
Nick Desaulniers
0f9f03afca [StringView] remove ctor incompatible with std::string_view
Towards replacing llvm::StringView with std::string_view, remove ctor
that std::string_view doesn't have an analog for.

Reviewed By: erichkeane, MaskRay

Differential Revision: https://reviews.llvm.org/D148353
2023-04-14 11:16:11 -07:00
Nick Desaulniers
f198e0b594 [StringView] remove dropFront
Towards converting our use of llvm::StringView to std::string_view,
remove a method that std::string_view doesn't have.
llvm::StringView::dropFront is semantically similar to
std::string_view::substr but with the input clamped to the size. No code
was relying on clamping other than the rust demangler, which I fixed in
https://reviews.llvm.org/D148272.  Removing this method makes it easier
to switch over code later.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148348
2023-04-14 10:24:10 -07:00
Nick Desaulniers
c8144eea9e [RustDemangle] remove StringView::dropFront
Toward the goal of replacing llvm::StringView with std::string_view,
first replacing users of llvm::StringView::dropFront, this case in the
Rust demangling scheme seemed worth its own commit+review.

Reviewed By: erichkeane, MaskRay

Differential Revision: https://reviews.llvm.org/D148272
2023-04-14 09:18:07 -07:00
Fangrui Song
3ece37b3fa [Demangle] Remove uses of llvm::itanium_demangle::StringView::{dropBack,dropFront}. NFC
Make it easier to migrate StringView to std::string_view.
2023-04-13 15:09:25 -07:00
Nathan Sidwell
d3b10150b6 [demangler] Simplify OutputBuffer initialization
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-10-17 04:23:16 -07:00
Benjamin Kramer
982779230f
Make demangler independent of LLVM again
The demangler is not supposed to include bits of LLVM, so it can't use STLExtras.

This undoes part of 6d9cd9199a6fdeab0412117bcefc28f625510b61
2022-08-15 11:44:28 +02:00
Kazu Hirata
6d9cd9199a Use llvm::all_of (NFC) 2022-08-14 16:25:36 -07:00
Zequan Wu
bf1e96d620 [MicrosoftDemangle] Set error to true when returning nullptr. 2022-06-08 17:18:09 -07:00
Kirill Stoimenov
aabeb5eb7f Revert "[demangler] Simplify OutputBuffer initialization"
Reverting due to a bot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/22738

This reverts commit 5b3ca24a35e91bf9c19af856e7f92c69b17f989e.
2022-04-26 20:24:06 +00:00
Nathan Sidwell
5b3ca24a35 [demangler] Simplify OutputBuffer initialization
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-26 04:23:12 -07:00
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