[llvm] [llvm][aarch64] Fix Arm64EC name mangling algorithm (PR #115567)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 10:56:28 PST 2024


================
@@ -302,14 +302,23 @@ std::optional<std::string> llvm::getArm64ECMangledFunctionName(StringRef Name) {
   // Insert the ARM64EC "$$h" tag after the mangled function name.
   if (Name.contains("$$h"))
     return std::nullopt;
-  size_t InsertIdx = Name.find("@@");
-  size_t ThreeAtSignsIdx = Name.find("@@@");
-  if (InsertIdx != std::string::npos && InsertIdx != ThreeAtSignsIdx) {
+
+  // The last 4 characters of the symbol type may contain a `@@` if the symbol
+  // is returning a qualified type. We don't want to insert `$$h` at that point.
+  auto TrimmedName = Name.drop_back(4);
+
+  // The last `@@` is the separation between the qualified name of the symbol
+  // and its type, which is where we want to insert `$$h`.
----------------
efriedma-quic wrote:

Right.

I'd guess parsing forward from the front is easier than parsing backwards, because that's the way mangling naturally works.  And I'm not sure there are any good shortcuts here.  Not sure how much code a "mini-demangler" that knows enough to parse the name of the function without actually printing the demangled name would be, vs. just pulling in the real demangler.

https://github.com/llvm/llvm-project/pull/115567


More information about the llvm-commits mailing list