[Clang] Assertion `OldTInfo && "substituting function without type source info"` failed since clang 6.0
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
***Generated by fuzzer.***
Clang trunk crashed and goes back to 6.0.
Compiler Explorer: https://godbolt.org/z/fE9aaq6hG
## Program
```cpp
class InterfaceBase {
public:
virtual ~InterfaceBase() = default;
};
template class InterfaceWrapper : public InterfaceBase;
template struct bad {
template {};
}>
static void f(T);
}
int main() {
bad<0>::f(0);
}
```
## Stack Dump
```bash
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5094: clang::TypeSourceInfo* clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl&): Assertion `OldTInfo && "substituting function without type source info"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics
1. :17:29: current parser token ')'
2. :17:16: parsing function body 'main'
3. :17:16: in compound statement ('{}')
4. :11:37: instantiating class definition 'TestClass_x3b04'
#0 0x0000000004309158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4309158)
#1 0x0000000004306584 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4306584)
#2 0x00000000042492d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000078b345a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000078b345a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000078b345a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000078b345a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000078b345a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000078b345a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x000000000762224a clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x762224a)
#10 0x00000000076855aa clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, clang::TemplateDeclInstantiator::RewriteKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76855aa)
#11 0x00000000075ab22b clang::Sema::InstantiateClassImpl(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75ab22b)
#12 0x00000000075abedd clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75abedd)
#13 0x0000000007677b5f clang::TemplateDeclInstantiator::VisitCXXRecordDecl(clang::CXXRecordDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7677b5f)
#14 0x0000000007687634 void llvm::function_ref::callback_fn(long) SemaTemplateInstantiateDecl.cpp:0:0
#15 0x0000000008537151 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8537151)
#16 0x000000000762198a clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x762198a)
#17 0x000000000758bcaa clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDeclStmt(clang::DeclStmt*) SemaTemplateInstantiate.cpp:0:0
#18 0x00000000075d39c5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#19 0x00000000075958e5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) SemaTemplateInstantiate.cpp:0:0
#20 0x0000000007596819 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#21 0x00000000075ad3a7 (anonymous namespace)::TemplateInstantiator::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#22 0x00000000075ad947 clang::Sema::SubstTemplateArgument(clang::TemplateArgumentLoc const&, clang::MultiLevelTemplateArgumentList const&, clang::TemplateArgumentLoc&, clang::SourceLocation, clang::DeclarationName const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75ad947)
#23 0x0000000007442e53 clang::Sema::SubstDefaultTemplateArgumentIfAvailable(clang::TemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::Decl*, llvm::ArrayRef, llvm::ArrayRef, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7442e53)
#24 0x00000000074d2cd7 ConvertDeducedTemplateArguments(clang::Sema&, clang::NamedDecl*, clang::TemplateParameterList*, bool, llvm::SmallVectorImpl&, clang::sema::TemplateDeductionInfo&, clang::Sema::CheckTemplateArgumentInfo&, clang::LocalInstantiationScope*, unsigned int, bool*) SemaTemplateDeduction.cpp:0:0
#25 0x000000000752a3bd clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl const*, bool, bool, bool, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x752a3bd)
#26 0x000000000752bc8a void llvm::function_ref::callback_fn, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref, bool)>)::'lambda1'()>(long) SemaTemplateDeduction.cpp:0:0
#27 0x0000000008537151 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8537151)
#28 0x000000000750a6b0 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref, bool)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x750a6b0)
#29 0x0000000007358e3b AddTemplateOverloadCandidateImmediately(clang::Sema&, clang::OverloadCandidateSet&, clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) SemaOverload.cpp:0:0
#30 0x000000000735992f clang::OverloadCandidateSet::InjectNonDeducedTemplateCandidates(clang::Sema&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x735992f)
#31 0x0000000007359b03 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7359b03)
#32 0x0000000007372ceb clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7372ceb)
#33 0x0000000006fd0e6a clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fd0e6a)
#34 0x0000000006fd637c clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fd637c)
#35 0x0000000006ad4037 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ad4037)
#36 0x0000000006accf4a clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6accf4a)
#37 0x0000000006acf1a7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6acf1a7)
#38 0x0000000006acf239 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6acf239)
#39 0x0000000006ad3819 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ad3819)
#40 0x0000000006b590e9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b590e9)
#41 0x0000000006b50594 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b50594)
#42 0x0000000006b50f76 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b50f76)
#43 0x0000000006b598be clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b598be)
#44 0x0000000006b5a10a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5a10a)
#45 0x0000000006a6055b clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a6055b)
#46 0x0000000006a969cd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a969cd)
#47 0x0000000006a536bb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a536bb)
#48 0x0000000006a53eaf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a53eaf)
#49 0x0000000006a5bcda clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a5bcda)
#50 0x0000000006a5cc75 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a5cc75)
#51 0x0000000006a3dcfa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a3dcfa)
#52 0x0000000004c6c068 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c6c068)
#53 0x0000000004f65455 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f65455)
#54 0x0000000004ee528e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ee528e)
#55 0x000000000505fafd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x505fafd)
#56 0x0000000000de89de cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde89de)
#57 0x0000000000ddf3aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#58 0x0000000000ddf52d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#59 0x0000000004cdf0a9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#60 0x0000000004249774 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4249774)
#61 0x0000000004cdf6bf clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#62 0x0000000004ca0052 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca0052)
#63 0x0000000004ca0ffe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca0ffe)
#64 0x0000000004ca8455 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca8455)
#65 0x0000000000de4d51 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde4d51)
#66 0x0000000000c8f044 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8f044)
#67 0x000078b345a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#68 0x000078b345a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#69 0x0000000000ddee45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddee45)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the crash with the provided C++ program and Clang invocation, then inspect clang/lib/Sema/SemaTemplateInstantiateDecl.cpp around TemplateDeclInstantiator::SubstFunctionType, where the assertion fires. Trace the instantiation path shown in the stack dump and verify that the reproducer no longer aborts while preserving the intended diagnostic or compilation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100