Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-cxxfilt] Add --quote option to quote demangled function names #111871

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

keryell
Copy link
Contributor

@keryell keryell commented Oct 10, 2024

This is useful when looking at LLVM/MLIR assembly produced from C++ sources. For example
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$0EEvOT(%2, %7) :
will be translated to
cir.call @"void aie::tile<1, 4>::programmain::$_0(main::$_0&&)"(%2, %7) : which can be parsed as valid MLIR by the right mlir-lsp-server.

If a symbol is already quoted, do not quote it more.

This is useful when looking at LLVM/MLIR assembly produced from C++ sources.
For example
 cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$_0EEvOT_(%2, %7) :
will be translated to
cir.call @"void aie::tile<1, 4>::program<main::$_0>(main::$_0&&)"(%2, %7) :
which can be parsed as valid MLIR by the right mlir-lsp-server.

If a symbol is already quoted, do not quote it more.
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 10, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Ronan Keryell (keryell)

Changes

This is useful when looking at LLVM/MLIR assembly produced from C++ sources. For example
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$0EEvOT(%2, %7) :
will be translated to
cir.call @"void aie::tile<1, 4>::program<main::$_0>(main::$_0&&)"(%2, %7) : which can be parsed as valid MLIR by the right mlir-lsp-server.

If a symbol is already quoted, do not quote it more.


Full diff: https://github.com/llvm/llvm-project/pull/111871.diff

4 Files Affected:

  • (modified) llvm/docs/CommandGuide/llvm-cxxfilt.rst (+5)
  • (added) llvm/test/tools/llvm-cxxfilt/quote.test (+12)
  • (modified) llvm/tools/llvm-cxxfilt/Opts.td (+2)
  • (modified) llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp (+19-5)
diff --git a/llvm/docs/CommandGuide/llvm-cxxfilt.rst b/llvm/docs/CommandGuide/llvm-cxxfilt.rst
index 0933f0b5bed878..ea90a05bcd4338 100644
--- a/llvm/docs/CommandGuide/llvm-cxxfilt.rst
+++ b/llvm/docs/CommandGuide/llvm-cxxfilt.rst
@@ -52,6 +52,11 @@ OPTIONS
 
   Do not demangle function parameters or return types.
 
+.. option:: --quote, -q
+
+  Add `"` `"` around demangled function symbols, typically to keep LLVM/MLIR
+  assembly files with `@<symbols>` valid. Do not quote already quoted symbols.
+
 .. option:: --no-strip-underscore, -n
 
   Do not strip a leading underscore. This is the default for all platforms
diff --git a/llvm/test/tools/llvm-cxxfilt/quote.test b/llvm/test/tools/llvm-cxxfilt/quote.test
new file mode 100644
index 00000000000000..1420c14efbbfbc
--- /dev/null
+++ b/llvm/test/tools/llvm-cxxfilt/quote.test
@@ -0,0 +1,12 @@
+// Show that llvm-cxxfilt --quote can emit quoted demangled symbols but not
+// without double-quoting in the case they are already quoted
+
+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]>]]}
diff --git a/llvm/tools/llvm-cxxfilt/Opts.td b/llvm/tools/llvm-cxxfilt/Opts.td
index 034cb267aab800..e69082ba05e3a4 100644
--- a/llvm/tools/llvm-cxxfilt/Opts.td
+++ b/llvm/tools/llvm-cxxfilt/Opts.td
@@ -15,6 +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">;
 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">;
@@ -27,4 +28,5 @@ 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>;
diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
index f90adb6cacb990..f3f11e488d2c3d 100644
--- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -20,6 +20,7 @@
 #include "llvm/TargetParser/Triple.h"
 #include <cstdlib>
 #include <iostream>
+#include <string>
 
 using namespace llvm;
 
@@ -54,6 +55,7 @@ class CxxfiltOptTable : public opt::GenericOptTable {
 } // namespace
 
 static bool ParseParams;
+static bool Quote;
 static bool StripUnderscore;
 static bool Types;
 
@@ -64,7 +66,15 @@ static void error(const Twine &Message) {
   exit(1);
 }
 
-static std::string demangle(const std::string &Mangled) {
+// Quote Undecorated with "" if asked for and not already followed by a '"'
+static std::string optionalQuote(std::string Undecorated,
+                                 StringRef Delimiters) {
+  if (Quote && (Delimiters.empty() || Delimiters[0] != '"'))
+    return '"' + Undecorated + '"';
+  return Undecorated;
+}
+
+static std::string demangle(const std::string &Mangled, StringRef Delimiters) {
   using llvm::itanium_demangle::starts_with;
   std::string_view DecoratedStr = Mangled;
   bool CanHaveLeadingDot = true;
@@ -76,7 +86,7 @@ static std::string demangle(const std::string &Mangled) {
   std::string Result;
   if (nonMicrosoftDemangle(DecoratedStr, Result, CanHaveLeadingDot,
                            ParseParams))
-    return Result;
+    return optionalQuote(Result, Delimiters);
 
   std::string Prefix;
   char *Undecorated = nullptr;
@@ -89,7 +99,8 @@ static std::string demangle(const std::string &Mangled) {
     Undecorated = itaniumDemangle(DecoratedStr.substr(6), ParseParams);
   }
 
-  Result = Undecorated ? Prefix + Undecorated : Mangled;
+  Result =
+      Undecorated ? Prefix + optionalQuote(Undecorated, Delimiters) : Mangled;
   free(Undecorated);
   return Result;
 }
@@ -137,9 +148,10 @@ static void demangleLine(llvm::raw_ostream &OS, StringRef Mangled, bool Split) {
     SmallVector<std::pair<StringRef, StringRef>, 16> Words;
     SplitStringDelims(Mangled, Words, IsLegalItaniumChar);
     for (const auto &Word : Words)
-      Result += ::demangle(std::string(Word.first)) + Word.second.str();
+      Result +=
+          ::demangle(std::string(Word.first), Word.second) + Word.second.str();
   } else
-    Result = ::demangle(std::string(Mangled));
+    Result = ::demangle(std::string(Mangled), "");
   OS << Result << '\n';
   OS.flush();
 }
@@ -172,6 +184,8 @@ int llvm_cxxfilt_main(int argc, char **argv, const llvm::ToolContext &) {
 
   Types = Args.hasArg(OPT_types);
 
+  Quote = Args.hasArg(OPT_quote);
+
   std::vector<std::string> Decorated = Args.getAllArgValues(OPT_INPUT);
   if (Decorated.empty())
     for (std::string Mangled; std::getline(std::cin, Mangled);)

@keryell
Copy link
Contributor Author

keryell commented Oct 10, 2024

This is a follow-up of llvm/clangir#824 suggested by @bcardosolopes.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

Thanks for this: the core of it looks fine. Just some testing could be simplified and improved, in my opinion, and there are a few other minor bits and pieces.

@@ -64,7 +66,15 @@ static void error(const Twine &Message) {
exit(1);
}

static std::string demangle(const std::string &Mangled) {
// Quote Undecorated with "" if asked for and not already followed by a '"'
static std::string optionalQuote(std::string Undecorated,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should Undecorated be a const std::string & or StringRef?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this to have the compiler able to move the string from the callee to the caller in the case it is not to be quoted, which is, I guess, the common case. But I might be wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's likely this function call will get optimized away, so it's somewhat moot, and we should just do what requires less mental logistics by readers of the code (which typically would not expect a string to be passed by value).

Comment on lines 1 to 2
// Show that llvm-cxxfilt --quote can emit quoted demangled symbols but not
// without double-quoting in the case they are already quoted
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
// 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 but not
// without double-quoting in the case they are already quoted.

Nit.

@@ -20,6 +20,7 @@
#include "llvm/TargetParser/Triple.h"
#include <cstdlib>
#include <iostream>
#include <string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: std::string is already used by this file, so adding this seems unnecessary by my reading of the include rules in the style guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is added automatically by clangd LSP server using the project configuration, so I guess it is cleaner according to the official coding style but I can remove it.

// without double-quoting in the case they are already quoted

RUN: llvm-cxxfilt --quote < %s | FileCheck %s
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$_0EEvOT_(%2, %7) : (!cir.ptr<!ty_aie3A3Atile3C12C_43E>, !cir.ptr<!ty_anon2E0_>) -> () loc(#loc74)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks to me like this test is overly complicated for what actually needs testing. If I understand it correctly, an input of something like the following would be sufficient to test the case with and without a quote:

_Z3barv "_Z3barv"

which I believe would turn into:

"bar()" "bar()"

(or if there was a bug, it might become `"bar()" ""bar()"", for example)

I'd also add two additional test cases:

  1. A case that doesn't result in demangling (to show that only successfully demangled names are quoted)
  2. A case that shows the behaviour if --quote is specified with the mangled name as one of the command-line arguments (e.g. llvm-cxxfilt --quote _Z3barv). I don't think quotes can appear in mangled names, so I don't think we need to show the "no double-quoting" behaviour in this case.
  3. A case that exercises the behaviour when an "import thunk for" prefix is added. Aside: I wonder if this case should be always quoted with --quote?

Finally, it may make the test cleaner to not use < %s and instead redirect the stdin cases from a separate file, possibly created via split-file. This would prevent things like the RUN and CHECK lines themselves from being fed into llvm-cxxfilt. This would also allow you to add --match-full-lines or similar, to make sure there's no unexpected quotes being added, since CHECK: bar() doesn't prevent quotes from existing.

Copy link
Contributor Author

@keryell keryell Oct 12, 2024

Choose a reason for hiding this comment

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

--match-full-lines sounds like a good idea if the tested lines are simplified as you propose.

I don't think quotes can appear in mangled names, so I don't think we need to show the "no double-quoting" behaviour in this case.

I have added it anyway for completude.
I am unfamiliar with the "import thunk for". Is this something we expect to show up in LLVM or MLIR dialect assembly file?
The goal is to produce a clearer self-content LLVM/MLIR file but not something which can be linked into something sensible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am unfamiliar with the "import thunk for". Is this something we expect to show up in LLVM or MLIR dialec assembly filet?

I don't know, but possibly? I don't think it really matters where it can appear though, since its behaviour can be impacted by the new option (see the code around line 102 in llvm-cxxfilt.cpp in this PR, where you've modified it - in particular, I'm interested in testing the behaviour of Prefix in combination with the quoting).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this is more comprehensive to have this case to work too.

Comment on lines 57 to 58
Add `"` `"` around demangled function symbols, typically to keep LLVM/MLIR
assembly files with `@<symbols>` valid. 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.

I can imagine other cases where the quoting behaviour might be useful, so I'd be inclined to drop the "typically to keep ..." part of this sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it would be more inclusive and compassionate to give a use case 😃 but I can remove it.

@@ -15,6 +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">;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comment to above, let's drop the "Useful for" bit of this.

@@ -27,4 +28,5 @@ 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>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't add single-character aliases for options that don't exist in the GNU version of the tool (c++filt), as it becomes a problem if they add their own -q option (we aim for compatibility with the GNU binutils). That is unless you are proposing to the binutils list to add it too...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not know this.

Copy link
Contributor Author

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed feedback!

Comment on lines 57 to 58
Add `"` `"` around demangled function symbols, typically to keep LLVM/MLIR
assembly files with `@<symbols>` valid. Do not quote already quoted symbols.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it would be more inclusive and compassionate to give a use case 😃 but I can remove it.

@@ -27,4 +28,5 @@ 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>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not know this.

// without double-quoting in the case they are already quoted

RUN: llvm-cxxfilt --quote < %s | FileCheck %s
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$_0EEvOT_(%2, %7) : (!cir.ptr<!ty_aie3A3Atile3C12C_43E>, !cir.ptr<!ty_anon2E0_>) -> () loc(#loc74)
Copy link
Contributor Author

@keryell keryell Oct 12, 2024

Choose a reason for hiding this comment

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

--match-full-lines sounds like a good idea if the tested lines are simplified as you propose.

I don't think quotes can appear in mangled names, so I don't think we need to show the "no double-quoting" behaviour in this case.

I have added it anyway for completude.
I am unfamiliar with the "import thunk for". Is this something we expect to show up in LLVM or MLIR dialect assembly file?
The goal is to produce a clearer self-content LLVM/MLIR file but not something which can be linked into something sensible.

@@ -64,7 +66,15 @@ static void error(const Twine &Message) {
exit(1);
}

static std::string demangle(const std::string &Mangled) {
// Quote Undecorated with "" if asked for and not already followed by a '"'
static std::string optionalQuote(std::string Undecorated,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this to have the compiler able to move the string from the callee to the caller in the case it is not to be quoted, which is, I guess, the common case. But I might be wrong.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

@keryell, for some reason your follow-up commit (keryell/clangir@d3553f3) isn't showing up in the PR, so I can't review it. Please push the commit to the branch used for this PR.

// without double-quoting in the case they are already quoted

RUN: llvm-cxxfilt --quote < %s | FileCheck %s
cir.call @_ZN3aie4tileILi1ELi4EE7programIZ4mainE3$_0EEvOT_(%2, %7) : (!cir.ptr<!ty_aie3A3Atile3C12C_43E>, !cir.ptr<!ty_anon2E0_>) -> () loc(#loc74)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am unfamiliar with the "import thunk for". Is this something we expect to show up in LLVM or MLIR dialec assembly filet?

I don't know, but possibly? I don't think it really matters where it can appear though, since its behaviour can be impacted by the new option (see the code around line 102 in llvm-cxxfilt.cpp in this PR, where you've modified it - in particular, I'm interested in testing the behaviour of Prefix in combination with the quoting).

@@ -64,7 +66,15 @@ static void error(const Twine &Message) {
exit(1);
}

static std::string demangle(const std::string &Mangled) {
// Quote Undecorated with "" if asked for and not already followed by a '"'
static std::string optionalQuote(std::string Undecorated,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's likely this function call will get optimized away, so it's somewhat moot, and we should just do what requires less mental logistics by readers of the code (which typically would not expect a string to be passed by value).

@keryell
Copy link
Contributor Author

keryell commented Oct 15, 2024

@keryell, for some reason your follow-up commit (keryell/clangir@d3553f3) isn't showing up in the PR, so I can't review it. Please push the commit to the branch used for this PR.

Sorry about that. I have pushed on the wrong remote I have on this worktree.

Comment on lines 57 to 58
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.

llvm/test/tools/llvm-cxxfilt/quote.test Outdated Show resolved Hide resolved
Comment on lines 4 to 9
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!

// \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.

Comment on lines 20 to 21
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?

llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp Show resolved Hide resolved
keryell and others added 2 commits October 16, 2024 11:58
Co-authored-by: James Henderson <46713263+jh7370@users.noreply.github.com>
Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

Looks good, barring the remaining nits. I'll give it one more once-over once you've addressed those to make sure I haven't missed anything, before formally approving.

// Check that an "import thunk for" prefix can be quoted along the demangled name
RUN: echo __imp__ZSt6futureIvE >> %t
RUN: llvm-cxxfilt --quote < %t | FileCheck --match-full-lines --check-prefix=CHECK-FILE %s
// Show that llvm-cxxfilt --quote adds quotes around demangled symbols, unless the symbol is already quoted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: sorry, thought I said this, but please reflow comments to approximately 80 characters, just like in regular code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my usual coding style actually, so I love this.

// \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.

Not addressed?

//--- symbols-in-file.test
_Z3barv "_Z3barv"
"_Z3barv" _Z3barv
// This is not mangled, thus it should not be quoted
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also missing "." here and below - comments should always end with one, just like in regular code.

Copy link
Contributor Author

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Thanks for all the review feedback!

// \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
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.

// Check that an "import thunk for" prefix can be quoted along the demangled name
RUN: echo __imp__ZSt6futureIvE >> %t
RUN: llvm-cxxfilt --quote < %t | FileCheck --match-full-lines --check-prefix=CHECK-FILE %s
// Show that llvm-cxxfilt --quote adds quotes around demangled symbols, unless the symbol is already quoted.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my usual coding style actually, so I love this.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

LGTM, with one exception - please reorder the documentation entry to be in alphabetical order.

@@ -52,6 +52,11 @@ OPTIONS

Do not demangle function parameters or return types.

.. 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.

Copy link
Contributor Author

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Please feel free to merge this as I do not have write access to the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants