[PATCH] D32428: Fix for Itanium mangler issue with templates (bug: 31405)

Serge Preis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 05:15:53 PDT 2017


Serge_Preis created this revision.
Herald added subscribers: rengolin, aemerson.

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.


https://reviews.llvm.org/D32428

Files:
  lib/AST/ItaniumMangle.cpp


Index: lib/AST/ItaniumMangle.cpp
===================================================================
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -4539,9 +4539,11 @@
 
   const FunctionProtoType *Proto =
       cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>());
+  FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
   TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
   TrackReturnTypeTags.mangleType(Proto->getReturnType());
   TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
+  TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
 
   return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32428.96380.patch
Type: text/x-patch
Size: 681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170424/1a357d5f/attachment.bin>


More information about the cfe-commits mailing list