<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136813>136813</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crashes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangtz0607
</td>
</tr>
</table>
<pre>
## Example
```cpp
template <typename, typename>
class C {
public:
template <typename>
class C2 {
public:
C2(C &) {}
};
void f() {
C2(*this);
}
};
int main() {
C<int, int>().f();
return 0;
}
```
```sh
clang++ -std=c++20 example.cpp
```
## Actual Behavior
```
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-trunk/bin/clang++ -gdwarf-4 -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 -std=c++20 <source>
1. <eof> parser at end of file
2. <source>:10:10: instantiating function definition 'C<int, int>::f'
#0 0x0000000003bdfdb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3bdfdb8)
#1 0x0000000003bddefc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3bddefc)
#2 0x0000000003b2e7f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000071aeece42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00000000076ce50f clang::TemplateArgument::getNonTypeTemplateArgumentType() const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x76ce50f)
#5 0x0000000006c43df8 checkDeducedTemplateArguments(clang::ASTContext&, clang::DeducedTemplateArgument const&, clang::DeducedTemplateArgument const&, bool) (.part.0) SemaTemplateDeduction.cpp:0:0
#6 0x0000000006c85fc5 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#7 0x0000000006c89553 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, clang::TemplateArgument const&, clang::TemplateArgument, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool*) SemaTemplateDeduction.cpp:0:0
#8 0x0000000006c89c46 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, llvm::ArrayRef<clang::TemplateArgument>, llvm::ArrayRef<clang::TemplateArgument>, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool, bool, PackFold, bool*) SemaTemplateDeduction.cpp:0:0
#9 0x0000000006c8b53f DeduceTemplateSpecArguments(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool*) SemaTemplateDeduction.cpp:0:0
#10 0x0000000006c867e6 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#11 0x0000000006c91b1a DeduceTemplateArgumentsFromCallArgument(clang::Sema&, clang::TemplateParameterList*, unsigned int, clang::QualType, clang::QualType, clang::Expr::Classification, clang::Expr*, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg>&, bool, unsigned int, unsigned int, clang::TemplateSpecCandidateSet*) SemaTemplateDeduction.cpp:0:0
#12 0x0000000006c969e4 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6c969e4)
#13 0x0000000006a9c46a AddTemplateOverloadCandidateImmediately(clang::Sema&, clang::OverloadCandidateSet&, clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) SemaOverload.cpp:0:0
#14 0x0000000006a9cdbf clang::OverloadCandidateSet::InjectNonDeducedTemplateCandidates(clang::Sema&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6a9cdbf)
#15 0x0000000006a9ce17 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6a9ce17)
#16 0x0000000006868301 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>)::'lambda0'(bool)::operator()(bool) const SemaInit.cpp:0:0
#17 0x0000000006868c1a clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6868c1a)
#18 0x00000000067476eb clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x67476eb)
#19 0x0000000006d218be clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXUnresolvedConstructExpr(clang::CXXUnresolvedConstructExpr*) SemaTemplateInstantiate.cpp:0:0
#20 0x0000000006d01408 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#21 0x0000000006d3bea9 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#22 0x0000000006d3c685 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#23 0x0000000006d4335b clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d4335b)
#24 0x0000000006d99e67 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d99e67)
#25 0x0000000006d97f88 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d97f88)
#26 0x00000000062f5709 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#27 0x00000000062f5e9d clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62f5e9d)
#28 0x000000000615ae83 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x615ae83)
#29 0x000000000614920a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x614920a)
#30 0x000000000451a5ed clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x451a5ed)
#31 0x0000000004828c2a clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4828c2a)
#32 0x00000000047a535b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47a535b)
#33 0x0000000004918a43 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4918a43)
#34 0x0000000000db1801 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdb1801)
#35 0x0000000000da9f5d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#36 0x000000000458c189 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#37 0x0000000003b2ec13 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b2ec13)
#38 0x000000000458c3a9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#39 0x000000000454f7fd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x454f7fd)
#40 0x00000000045507c1 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x45507c1)
#41 0x000000000455ab0c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x455ab0c)
#42 0x0000000000dae531 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdae531)
#43 0x0000000000c301d4 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc301d4)
#44 0x000071aeece29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#45 0x000071aeece29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#46 0x0000000000da99f5 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xda99f5)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
https://godbolt.org/z/faxEK476f
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW1F346az_zTKC8c5EpIs6SEPihP3brt7k1unPfuWgwDZdCXQBZRN-un_B5AsS7azTuq0D_3vycaOgJnf_GYGBoyRUmzNKb3y4msvvrlArd4IefUd8bX-05_7yUUhyMuVB0MPhuD2GdVNRT0_Nz9z3_3gpvH8XNO6qZCmwAsX-qWhHNXUgwuwfR_een6OK6QUWAAvufb8vGmLimEvNOLAQQF2EAAAdANhN9I8Go3u_i2gB9MF8ODcg5ntm9yYZvMSXjvgpt-TYASUHkz7bhMRHsz1hikPZm6YaXCidiUxrkGNGB_LWXjhgnFtjDcv4a1rvuzUDQIl1a3kwO_kOfE9qxOS1caxx9cevPbgNZgpTbzwBrs_oQ-oc86lc8dUjnNgjnWLKnBNN-iJCTnR4fn5_efbfHULVFvUTAMEinYNJG2E1EALsNG6UYZwuPTgcs30pi0usag9uKyqp_5l1kjxB8Xag0umVEuVB5cAcQIYx1VLKNAbCrBEagMKhL9pibCNlEbSRgpMlaIEKNFK99iMREoJzJCmBMiWA4Ula_Sl5-crjfA3QNq6cXHgX3p-di_FWqIaILlua8q1gQw8uBSNwYRF3bCKyhl9biohqTTPDLEzLVv-zYPLwnh0OSJ7Tb4jWc4iMFuDmTDCUNMYka1uWn2pwKw2poPZ7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