Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/docs/CommandGuide/llvm-cxxfilt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ OPTIONS

Do not demangle function parameters or return types.

.. option:: --quote, -q
.. option:: --quote
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This should appear after --no-strip-underscore to maintain alphabetical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.


Add `"` `"` around demangled function symbols, typically to keep LLVM/MLIR
assembly files with `@<symbols>` valid. Do not quote already quoted symbols.
Add `"` `"` around demangled function symbols.
Do not quote already quoted symbols.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: word wrapping seems premature.


.. option:: --no-strip-underscore, -n

Expand Down
31 changes: 20 additions & 11 deletions llvm/test/tools/llvm-cxxfilt/quote.test
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// Show that llvm-cxxfilt --quote can emit quoted demangled symbols but not
// without double-quoting in the case they are already quoted
// Show that llvm-cxxfilt --quote can emit quoted demangled symbols (even at the
// end of a line) but not without double-quoting in the case they are already
// quoted.
RUN: echo _Z3barv '"_Z3barv"' > %t
RUN: echo '"_Z3barv"' _Z3barv >> %t
// This is not mangled, thus it should not be quoted
RUN: echo 'log()' >> %t
// Check that an "import thunk for" prefix can be quoted along the demangled name
RUN: echo __imp__ZSt6futureIvE >> %t
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use echo, I'd recommend the more modern split-file approach. In essence, you add a marker later in the file, then write the intended contents of the input file below that marker. In place of the echo lines, you simply add RUN: split-file %s .... See various existing examples for correct usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

RUN: llvm-cxxfilt --quote < %t | FileCheck --match-full-lines --check-prefix=CHECK-FILE %s
CHECK-FILE: "bar()" "bar()"
CHECK-FILE-NEXT: "bar()" "bar()"
CHECK-FILE-NEXT: log()
CHECK-FILE-NEXT: "import thunk for std::future<void>"

RUN: llvm-cxxfilt --quote < %s | FileCheck %s
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$_0EEvOT_(%2, %7) : (!cir.ptr<!ty_aie3A3Atile3C12C_43E>, !cir.ptr<!ty_anon2E0_>) -> () loc(#loc74)
cir.func lambda internal private @_ZZ4mainENK3$_1clEv(%arg0: !cir.ptr<!ty_anon2E1_> loc("example.cpp":31:26)) extra(#fn_attr) {
module @"example.cpp" attributes {cir.global_annotations = #cir<global_annotations [["_ZN3aie6deviceILNS_3$_0E42EE4tileILi1ELi4EEENS_4tileIXT_EXT0_EEEv", #cir.annotation<name = "aie.device.tile", args = [1 : i32, 4 : i32, 42 : i8, 42 : i8]>]]}

CHECK: cir.call @"void aie::tile<1, 4>::program<main::$_0>(main::$_0&&)"(%2, %7)
CHECK-NEXT: cir.func lambda internal private @"main::$_1::operator()() const"(%arg0: !cir.ptr<!ty_anon2E1_>
// \todo Is there a simpler way to escape these [[ leading to "error: invalid variable name" otherwise?
CHECK-NEXT: module @"example.cpp" attributes {cir.global_annotations = #cir<global_annotations {{[[]}}["aie::tile<1, 4> aie::device<(aie::$_0)42>::tile<1, 4>()", #cir.annotation<name = "aie.device.tile", args = [1 : i32, 4 : i32, 42 : i8, 42 : i8]>]]}
// Check it works with cli symbols too. Since a quoted mangled name is not a
// mangled name, it should be unchanged
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// mangled name, it should be unchanged
// mangled name, it should be unchanged.

Nit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not addressed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I messed up in conflict resolution when I rebased my commit on top of the one I made on GitHub UI with your suggestions.

RUN: llvm-cxxfilt --quote _Z3firv '"_Z3barv"' 'saw()' | FileCheck --match-full-lines --check-prefix=CHECK-CLI %s
CHECK-CLI: "fir()"
CHECK-CLI: "_Z3barv"
CHECK-CLI: saw()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-NEXT prefixes?

3 changes: 1 addition & 2 deletions llvm/tools/llvm-cxxfilt/Opts.td
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ multiclass Eq<string name, string help> {
}

def help : FF<"help", "Display this help">;
def quote : FF<"quote", "Quote demangled function names with \" \" if not already quoted. Useful for symbols appearing after an @ in MLIR/LLVM assembly">;
def quote : FF<"quote", "Quote demangled function names with \" \" if not already quoted">;
defm strip_underscore : BB<"strip-underscore", "Strip the leading underscore", "Don't strip the leading underscore">;
def types : FF<"types", "Attempt to demangle types as well as function names">;
def no_params : FF<"no-params", "Skip function parameters and return types">;
Expand All @@ -28,5 +28,4 @@ def : F<"_", "Alias for --strip-underscore">, Alias<strip_underscore>;
def : F<"h", "Alias for --help">, Alias<help>;
def : F<"n", "Alias for --no-strip-underscore">, Alias<no_strip_underscore>;
def : F<"p", "Alias for --no-params">, Alias<no_params>;
def : F<"q", "Alias for --quote">, Alias<quote>;
def : F<"t", "Alias for --types">, Alias<types>;
5 changes: 2 additions & 3 deletions llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "llvm/TargetParser/Triple.h"
#include <cstdlib>
#include <iostream>
#include <string>

using namespace llvm;

Expand Down Expand Up @@ -67,7 +66,7 @@ static void error(const Twine &Message) {
}

// Quote Undecorated with "" if asked for and not already followed by a '"'
static std::string optionalQuote(std::string Undecorated,
static std::string optionalQuote(const std::string &Undecorated,
StringRef Delimiters) {
if (Quote && (Delimiters.empty() || Delimiters[0] != '"'))
return '"' + Undecorated + '"';
Expand Down Expand Up @@ -100,7 +99,7 @@ static std::string demangle(const std::string &Mangled, StringRef Delimiters) {
}

Result =
Undecorated ? Prefix + optionalQuote(Undecorated, Delimiters) : Mangled;
Undecorated ? optionalQuote(Prefix + Undecorated, Delimiters) : Mangled;
free(Undecorated);
return Result;
}
Expand Down
Loading