[libcxx-commits] [PATCH] D124010: [llvm-cxxfilt] Unable to demangle a template argument which happens to be a null pointer
Owen Reynolds via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Apr 26 09:17:39 PDT 2022
gbreynoo added a comment.
Apologies for the delay in response and thank you for your input @dblaikie and @urnathan.
In D124010#3459710 <https://reviews.llvm.org/D124010#3459710>, @dblaikie wrote:
> Should Clang be changing to not use this mangling, so it uses a mangling that matches GCC?
> And the demangle AST you're creating here is for an enum, and a cast from 0 to nullptr - but I'm not sure that's portable (even if it is inconsistent between producers) - nullptr_t isn't necessarily an enum, and I don't think C++ requires that you can cast 0 to nullptr_t?
I'm not sure what you mean regarding clang's use of this mangling. From my understanding this is legal in the specification and so should be handled appropriately as input?
Comment at: llvm/include/llvm/Demangle/ItaniumDemangle.h:4357-4360
+ // 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");
> Why demangle this differently to just 'nullptr'? I notice GNU's demangler does that:
> zathras:11>c++filt _Z1fIDnLDn0EEvv
> void f<decltype(nullptr), (decltype(nullptr))0>()
> It would seem
> if (consumeIf("Dn") && (consumeIf ('0'), consumeIf ('E'))
> return make<NameType>("nullptr");
> return nullptr;
> would suffice?
This would output nullptr rather than decltype(nullptr) or nullptr_t. Looking at the spec "a template argument which happens to be a null pointer should mangled as if it were a literal 0 of the appropriate pointer type" which in the case of LDn0E is nullptr_t.
Comment at: llvm/test/tools/llvm-cxxfilt/null-pointer-template-arg.test: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>()
> demangler tests are in libcxxabi/test/test_demangle.pass.cpp you'll see there's a massive array of tuples.
Thanks @urnathan the LPi0E and LDnE cases were already present so I have added the LDn0E case.
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
More information about the libcxx-commits