This is an archive of the discontinued LLVM Phabricator instance.

Fix for Itanium mangler issue with templates (bug: 31405)
ClosedPublic

Authored by Serge_Preis on Apr 24 2017, 5:15 AM.

Details

Summary

This fixes problem described as bug:31405

https://bugs.llvm.org//show_bug.cgi?id=31405
Itanium ABI: debug assertion in template mangling with declype return

The problem is that FunctionTypeDepthState is not properly managed in templated decltype() construct mangling resulting in assertion inside mangler
mangler: /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:3976: void (anonymous namespace)::CXXNameMangler::mangleFunctionParam(const clang::ParmVarDecl *): Assertion `parmDepth < FunctionTypeDepth.getDepth()' failed.
Aborted (core dumped)

for code as simple as template <typename T> auto foo(T x) -> const decltype(x);

The fix is to properly save/restore FunctionTypeDepthState before/after mangling of type in decltype. This exactly same way FunctionTypeDepthState treated in other similar places in a mangler.

While in normal operation mangling of non-instantiated templates is not needed, some tools like source code indexers and others may need this. Also in most cases mangling of template functions does work, so described assertion looks like a flaw rather than actual guard.

See issue description above for more details including stack trace of the issue, reproducer example and simple mangling matcher exhibiting the issue.

Diff Detail

Repository
rL LLVM

Event Timeline

Serge_Preis created this revision.Apr 24 2017, 5:15 AM

David, could you please take a look to this patch. It fixes potential issue and should have no side effects. If you have no objections, I'll commit it for Serge.

Would you please take a look into proposed minor changes to avoid mangler assertion in some template cases.

This revision is now accepted and ready to land.Jun 13 2017, 9:43 AM
This revision was automatically updated to reflect the committed changes.