Open ioannco opened 2 months ago
@llvm/issue-subscribers-tools-llvm-cxxfilt
Author: Ivan Cheremisenov (ioannco)
@llvm/issue-subscribers-clang-frontend
Author: Ivan Cheremisenov (ioannco)
This fails to demangle when we parse the Sa
special substitution in parseType
and encounter the template argument IcE
while TryParseTemplateArguments == false
, as you point out. I suspect this was an untested codepath because with libc++ all types live in an inline namespace (most commonly std::__1
), so Clang is never allowed to produce those special substitutions. But with libstdc++ apparently only std::basic_string lives in the __cxx11
namespace, but not std::allocator. So hence we compressed std::allocator
but not std::__cxx11::basic_string
. See godbolt.
Slightly more self-contained reproducer would be:
namespace std {
template <typename T>
struct allocator {};
}
template<typename T>
struct Bar {};
struct Foo {
operator Bar<std::allocator<char>>() { return {}; }
};
int main() {
Foo f;
(Bar<std::allocator<char>>)f;
return 0;
}
AFAICT, the reason why TryToParseTemplateArgs
exists, is to support cases where we have conversion operators whose result-type contains forward template references. So if you allow parsing template arguments like you propose, I suspect there are cases where we would get confused about which template the forward reference referred to. E.g., (taken from one of the test failures) for _ZN5OuterI4MarpEcvT_I4MerpEEv
, we would now demangle to:
Outer<Marp>::operator Marp<Merp>()
instead of:
Outer<Marp>::operator Merp<Merp>()
Nonetheless, this is a bug with the demangler.
Issue description
LLVM demangler fails to decode Itanium mangled name
_ZN3foocvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEv
which encodesfoo::operator std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>()
while other demanglers (i.ec++filt
) do not fail.Possible causes
It seems that in
llvm/Include/llvm/Demangle/ItaniumDemangle.h:3346
parser has been explicitly told not to try to parse template arguments in the names encoding C-style casts. I did not find any reason why this is illegal in the itanium C++ ABIPossible patch provided in this pull request
How to reproduce
example.cpp
:output:
demangle of line
00000000000011e0 W _ZN3foocvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEv
has failed.