<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78048>78048</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] calling convention attribute in lambda in templated function crashes clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
a2flo
</td>
</tr>
</table>
<pre>
Putting a calling convention attribute on a lambda inside a template function and then instantiating that function crashes clang.
E.g. with System V ABI:
```
template <typename T>
void dummy(T val) {
[]() __attribute__((sysv_abi)) {};
}
void dummy_instantiate() {
dummy(1);
}
```
Similarly with PCS:
```
template <typename T>
void dummy(T val) {
[]() __attribute__((pcs("aapcs"))) {};
}
void dummy_instantiate() {
dummy(1);
}
```
Compiler explorer link: https://compiler-explorer.com/z/9b348a5x1
Happens on clang 17.0.1 and goes as far back as clang 3.5.
Stacktrace:
```
clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = clang::FunctionType; From = clang::Type]: Assertion `Val && "isa<> used on a null pointer"' 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-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++14 <source>
1. <eof> parser at end of file
2. <source>:2:6: instantiating function definition 'dummy<int>'
#0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558)
#1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc)
#2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f9c6b442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f9c6b4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f9c6b442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f9c6b4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007f9c6b42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007f9c6b439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x000000000691722b clang::QualType clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformFunctionProtoType<clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*)::'lambda0'(clang::FunctionProtoType::ExceptionSpecInfo&, bool&)>(clang::TypeLocBuilder&, clang::FunctionProtoTypeLoc, clang::CXXRecordDecl*, clang::Qualifiers, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*)::'lambda0'(clang::FunctionProtoType::ExceptionSpecInfo&, bool&)) (.constprop.0) SemaTemplateInstantiate.cpp:0:0
#10 0x00000000068e8d65 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) SemaTemplateInstantiate.cpp:0:0
#11 0x00000000068eae14 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#12 0x0000000006920ccf clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#13 0x0000000006921ee8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#14 0x000000000692512a clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x692512a)
#15 0x00000000069740fb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x69740fb)
#16 0x00000000069724df clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x69724df)
#17 0x0000000005f5f4c9 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#18 0x0000000005f5fca2 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5f5fca2)
#19 0x0000000005df75f3 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df75f3)
#20 0x0000000005deb76a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb76a)
#21 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258)
#22 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09)
#23 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce)
#24 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6)
#25 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb)
#26 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000000003f83419 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
#28 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4)
#29 0x0000000003f83a0f 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
#30 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275)
#31 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd)
#32 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d)
#33 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87)
#34 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61)
#35 0x00007f9c6b429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x00007f9c6b429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9z47YR_zT0C0YaEiAp8sEPsmQll17m3MjJ5E0DgqCMHgiwAOjI_fQdAJRE0PI1zlhJp81c7ij82f3tD4vdBQmsNdsLSm-j7C7K1je4N09S3WLYcHlTyfrl9qE3hok9wIBgzu0TkeKZCsOkANgYxareUGB_AI7bqsaACc1qCjAwtO04NhQ0vSB-gqiBeaLCjjFYGIadcPOEzXkQUVg_UQ0Ix2I_j-J1FC_93_fz_Rz8xswT2L5oQ1vwC1jefYrQ0B3l8fDH_Typj9DKvHRU4JaCxwjd--5nyWpQ9237EsHiETxjHsESRIs73w0AAJ6VCBa2Z7c7mbvbubZCv-jnHa5YBMvj3MU6QoME-zwCf9a3O1tPB-FntUdEiRX6WlRoov97y1rGseIvnpuH1favo6Qj2j1AjN0j9Nz8lfSsZNsxThWgh45LRRXgTHyN0BI8GdNpyxXcRHBDhnGz47g5kW0EN_-K4KasUFrg7JB4kd_jrqNCW7d3XgqSxTyeJ86_95JqgDVosAIVJl_tsx-E5lngzluDyVejMKFvrZebF8E7-wctQQQ3SkoTwQ3nz-2sU_IflBx_RnDDBOF9Tc8N277rpLIjVljbrTZ_itAyiUsrTRtsGAGVlBy48WgZoSXTeMfaju8Ij9DqUUZwZbe8NmCjLB1L6y1uZC2ZiWARdtrFyu6cHz5KEKG1t93P2Axb_PGloxG6c5OmY1xftrYAl1pT5UJClMe_YA4imEcwBxGETOMIrSJ0D3pNax9-RM856CQThirneAvQYMZpPZD-8Pl-ub0Huq9aZgAGVb8Hilp-gJETX9gz89RXgwMMZE44Z1r3VEdw41Z9oN5GNx_A3Nr7xYUr0CnaKUmotmi17JVvtjOx1pJYX6-B6gXQRLHOzEceYn2-O3lIPI_i8kHJvcItwGrft1QYPXiH7MwlR7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