[PATCH] D124010: [llvm-cxxfilt] Unable to demangle a template argument which happens to be a null pointer

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 09:05:17 PDT 2022


gbreynoo created this revision.
gbreynoo added reviewers: jhenderson, steven_wu, MaskRay, dblaikie, urnathan.
Herald added a subscriber: StephenFan.
Herald added a project: All.
gbreynoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As seen in https://github.com/llvm/llvm-project/issues/51854 llvm-cxxfilt was having trouble demangling the case below:

> When attempting to demangle "_Z1fIDnLDn0EEvv" llvm-cxxfilt does not demangle the input. According to GCC we should see similar to "void f<decltype(nullptr), (decltype(nullptr))0>()"

After investigating the issue I discovered the following in the Itanium C++ ABI demangling section:

> The pointer literal expression nullptr is encoded as "LDnE". In contrast, a template argument which happens to be a null pointer (an extension made standard in C++11) is mangled as if it were a literal 0 of the appropriate pointer type; for example, "LPi0E" or "LDn0E". This inconsistency is an unfortunate accident.

We handle the "LDNE" case and "LPi0E" but not "LDn0E". This change adds that handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124010

Files:
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/test/tools/llvm-cxxfilt/null-pointer-template-arg.test


Index: llvm/test/tools/llvm-cxxfilt/null-pointer-template-arg.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cxxfilt/null-pointer-template-arg.test
@@ -0,0 +1,12 @@
+# As stated in the Itanium C++ ABI mangling section:A template argument
+# which happens to be a null pointer is mangled as if it were a literal
+# 0 of the appropriate pointer type; for example, "LPi0E" or "LDn0E".
+
+# RUN: llvm-cxxfilt _Z1fIDnLDnEEvv | FileCheck %s --check-prefix=NULLPTR
+# NULLPTR: void f<std::nullptr_t, nullptr>()
+
+# RUN: llvm-cxxfilt _Z1fIDnLDn0EEvv | FileCheck %s --check-prefix=TEMPARG1
+# TEMPARG1: void f<std::nullptr_t, (std::nullptr_t)0>()
+
+# RUN: llvm-cxxfilt _Z1fIPiLPi0EEvv | FileCheck %s --check-prefix=TEMPARG2
+# TEMPARG2: void f<int*, (int*)0>()
Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -4354,6 +4354,10 @@
   case 'D':
     if (consumeIf("DnE"))
       return make<NameType>("nullptr");
+    // A template argument which happens to be a null pointer is mangled as if
+    // it were a literal 0 of the appropriate pointer type.
+    if (consumeIf("Dn0E"))
+      return make<EnumLiteral>(make<NameType>("std::nullptr_t"), "0");
     return nullptr;
   case 'T':
     // Invalid mangled name per


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124010.423642.patch
Type: text/x-patch
Size: 1461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220419/9ba6847d/attachment.bin>


More information about the llvm-commits mailing list