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(); }
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(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits