<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136585>136585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIRV][HLSL] Crash when calling exported function and targeting SPIRV
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:SPIR-V
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
https://hlsl.godbolt.org/z/ojzoYh4bb
Version of LLVM discovered: b95ec24ff08c6ffc300bd85c8b0e53dfda4bceef
Crash only happens when targeting SPIRV.
## Code that causes crash
```hlsl
export int blah() {
return 0;
}
[numthreads(1,1,1)]
void main() {
blah();
return;
}
```
## crash stack
```gdb
#5 0x0000000003f2438f clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::CallBase**, clang::CodeGen::CGFunctionInfo const**) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f2438f)
#6 0x0000000003f250d6 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f250d6)
#7 0x0000000003f92819 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#8 0x0000000003f8813b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#9 0x0000000003f8d442 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f8d442)
#10 0x0000000003f0771e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f0771e)
#11 0x0000000003f0be60 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f0be60)
#12 0x0000000004088977 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4088977)
#13 0x000000000408fe29 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk/bin/clang+0x408fe29)
#14 0x00000000040f0097 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x40f0097)
#15 0x0000000004103ed1 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4103ed1)
#16 0x000000000415ec4b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x415ec4b)
#17 0x000000000415a5e4 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x415a5e4)
#18 0x000000000415b108 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk/bin/clang+0x415b108)
#19 0x00000000041649ff clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#20 0x000000000451f92e (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#21 0x00000000045097a9 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk/bin/clang+0x45097a9)
#22 0x0000000006141dc4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x6141dc4)
#23 0x000000000451cf4d clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x451cf4d)
#24 0x000000000482b58a clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x482b58a)
#25 0x00000000047a7cdb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x47a7cdb)
#26 0x000000000491b3a3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x491b3a3)
#27 0x0000000000db1501 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xdb1501)
#28 0x0000000000da9c5d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x000000000458e989 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
#30 0x0000000003b31663 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b31663)
#31 0x000000000458eba9 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
#32 0x000000000455215d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x455215d)
#33 0x0000000004553121 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+0x4553121)
#34 0x000000000455d46c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x455d46c)
#35 0x0000000000dae231 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xdae231)
#36 0x0000000000c2ff24 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xc2ff24)
#37 0x0000742795629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x0000742795629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000da96f5 _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xda96f5)
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWVtv5CgW_jXkBaWE8f0hD06lK5NWRurttLLapxIGXOVpCiyMM5X-9SuMKzbOpZNU7WqlHU26O1wO3_edY84BSNvWG8n5BYgvQXx1RjqzVfqiIvqXkuKsVOzxYmtM04KwAHgF8GorWrHYKFYqYRZKbwBe_QJ4pf76pf61jcoSoAKg4p7rtlYSqgre3t7_CVndUvXANWcgLGCZx5ziqKpQRpOqoiFCJctimpWIxyGrGIlKynnlbC01abdQSfEIt6RpuGzh31suoSF6w00tN_Du2833-4UbDXAIcAiXinFotsRASrqWt5BaK7Y_Qe5_SwSggu8bpQ2spYGlIFuAM4BzCNJLgAoIIdTcdFpCBELbAtIr-2d8Kbud2WpOWAtwFgC8HH5yENsRD6pmcEdq6dsbV3DmxgU88weII50ePWwNoT-nAzasdGNiiPbo8F9Y4SjMKkgFkRvruLCwclxz6f2y6iQ1tRoav-xqsyRCAJxN5v2jI-LHY8MBXr5u7trO4xxSJVsDcDIfTIT4sm_0ob94y9j3Xo17Ijp-J5SxQ4V42LnOvnkwMLZa-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