https://llvm.org/bugs/show_bug.cgi?id=31405
Bug ID: 31405 Summary: Itanium ABI: debug assertion in template mangling with declype return Product: clang Version: 3.9 Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: C++14 Assignee: unassignedclangb...@nondot.org Reporter: spr...@yandex-team.ru CC: llvm-bugs@lists.llvm.org Classification: Unclassified I develop in-house source code indexer and met the following issue. The simple declaration cannot be mangled - Itanium mangler fails with assert if clang is built in debug mode: >> cat test.cpp template <typename T> auto foo(T x) -> const decltype(x); >> indexer -std=c++14 test.cpp indexer: /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) The problem is that both parts of comparison are '0'. This is due to the fact that in this case CXXNameMangler::mangleFunctionParam() is called transitively from CXXNameMangler::makeFunctionReturnTypeTags() (see stack trace below) and for TrackReturnTypeTags mangler the FunctionTypeDepth is never increased in this case. I believe this is incorrect: makeFunctionReturnTypeTags is called in context of return value, so its FunctionTypeDepth should be 1 at minimum (though I am not 100% sure: I am still new to clang). The patch below fixes the issue for me: ~/LLVM/llvm/tools/clang/lib/AST$ svn diff Index: ItaniumMangle.cpp =================================================================== --- ItaniumMangle.cpp (revision 289930) +++ ItaniumMangle.cpp (working copy) @@ -4418,9 +4418,12 @@ 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(); } Unfortunately I cannot provide full reproducer. I may try to create skeleton visitor as reduced test case at later days. But maybe some C++ mangler capable of handling this case already exists (c-index-test tool's mangling doesn't work for function templates) - it should crash on debug CLANG with the declaration above. ---- The stack trace: ------------------- >> gdb --args indexer -std=c++14 test.cpp [...] (gdb) run indexer: /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:3976: void (anonymous namespace)::CXXNameMangler::mangleFunctionParam(const clang::ParmVarDecl *): Assertion `parmDepth < FunctionTypeDepth.getDepth()' failed. (gdb) bt Program received signal SIGABRT, Aborted. 0x00007ffff69b8c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt #0 0x00007ffff69b8c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00007ffff69bc028 in __GI_abort () at abort.c:89 #2 0x00007ffff69b1bf6 in __assert_fail_base () at assert.c:92 #3 0x00007ffff69b1ca2 in __GI___assert_fail () at assert.c:101 #4 0x0000000000e3600d in (anonymous namespace)::CXXNameMangler::mangleFunctionParam () at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:3976 #5 0x0000000000e2c9a2 in mangleType () at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:3028 #6 (anonymous namespace)::CXXNameMangler::mangleType () at /home/spreis/LLVM/llvm/tools/clang/include/clang/AST/TypeNodes.def:88 #7 0x0000000000e2bf95 in (anonymous namespace)::CXXNameMangler::mangleType () at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:2252 #8 0x0000000000e2aa0f in makeFunctionReturnTypeTags () <<<<<<!!!!!!!!! at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:4424 #9 (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding () at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:652 #10 0x0000000000e28901 in (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXName () at /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:4476 #11 0x000000000058fff0 in Collector::getMangledName () at /home/spreis/work/indexer/collector.cpp:914 #12 0x000000000058d2f0 in Collector::registerFunctionDecl () at /home/spreis/work/indexer/collector.cpp:640 #13 0x00000000005853c8 in BrowserASTVisitor::VisitFunctionDecl () at /home/spreis/work/indexer/browserastvisitor.h:125 #14 0x0000000000573754 in WalkUpFromFunctionDecl () at /home/spreis/include/clang/AST/DeclNodes.inc:371 #15 TraverseFunctionDecl (D=0x1c8acd0, this=<optimized out>) at /home/spreis/LLVM/build/include/clang/AST/RecursiveASTVisitor.h:1883 #16 clang::RecursiveASTVisitor<BrowserASTVisitor>::TraverseDecl () at /place/home/spreis/LLVM/build/include/clang/AST/DeclNodes.inc:371 #17 0x00000000005736e2 in BrowserASTVisitor::TraverseDecl () at at /home/spreis/work/indexer/browserastvisitor.h:324 #18 0x0000000000574d5b in clang::RecursiveASTVisitor<BrowserASTVisitor>::TraverseFunctionTemplateDecl () at /home/spreis/LLVM/build/include/clang/AST/RecursiveASTVisitor.h:1637 .... -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs