llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU] Segmentation fault in `CGNVCUDARuntime::finalizeModule()` during IR generation

Open ElliotBLabs opened this issue 6 months ago • 5 comments

Compiling the attached HIP program causes a segmentation fault in the Clang frontend.

Test File: HIPProg.hip

How to reproduce:

clang++ -x hip HIPProg.hip --offload-arch=native
Stack dump:
0.      Program arguments: ... clang-23 -cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -O3 ...
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
 #0 0x0000742d80c5e41b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
 ...
 #4 0x0000742d80ce15a8 llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true>, llvm::ilist_parent<llvm::BasicBlock>>::addNodeToList(llvm::Instruction*)
 #5 0x0000742d80e04f32 llvm::Instruction::Instruction(llvm::Type*, unsigned int, llvm::User::AllocInfo, llvm::InsertPosition)
 #6 0x0000742d80e10021 llvm::LoadInst::LoadInst(llvm::Type*, llvm::Value*, llvm::Twine const&, bool, llvm::Align, llvm::InsertPosition)
 #7 0x0000742d89af882b (anonymous namespace)::CGNVCUDARuntime::finalizeModule() CGCUDANV.cpp:0:0
 #8 0x0000742d89f00166 clang::CodeGen::CodeGenModule::Release() 
 #9 0x0000742d89f8dcfd (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#10 0x0000742d89e89495 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) 
 ...
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed with exit code -2 (use -v to see invocation)

ElliotBLabs avatar May 16 '26 09:05 ElliotBLabs

tagging @mgcarrasco who is working on it

ElliotBLabs avatar May 16 '26 09:05 ElliotBLabs

@llvm/issue-subscribers-backend-amdgpu

Author: ElliotBLabs

Compiling the attached HIP program causes a segmentation fault in the Clang frontend.

Test File: HIPProg.hip

How to reproduce:

clang++ -x hip HIPProg.hip --offload-arch=native
Stack dump:
0.      Program arguments: ... clang-23 -cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -O3 ...
1.      &lt;eof&gt; parser at end of file
2.      Per-file LLVM IR generation
 #<!-- -->0 0x0000742d80c5e41b llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) 
 ...
 #<!-- -->4 0x0000742d80ce15a8 llvm::SymbolTableListTraits&lt;llvm::Instruction, llvm::ilist_iterator_bits&lt;true&gt;, llvm::ilist_parent&lt;llvm::BasicBlock&gt;&gt;::addNodeToList(llvm::Instruction*)
 #<!-- -->5 0x0000742d80e04f32 llvm::Instruction::Instruction(llvm::Type*, unsigned int, llvm::User::AllocInfo, llvm::InsertPosition)
 #<!-- -->6 0x0000742d80e10021 llvm::LoadInst::LoadInst(llvm::Type*, llvm::Value*, llvm::Twine const&amp;, bool, llvm::Align, llvm::InsertPosition)
 #<!-- -->7 0x0000742d89af882b (anonymous namespace)::CGNVCUDARuntime::finalizeModule() CGCUDANV.cpp:0:0
 #<!-- -->8 0x0000742d89f00166 clang::CodeGen::CodeGenModule::Release() 
 #<!-- -->9 0x0000742d89f8dcfd (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) ModuleBuilder.cpp:0:0
#<!-- -->10 0x0000742d89e89495 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) 
 ...
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed with exit code -2 (use -v to see invocation)
</details>

I can confirm the issue and crash with commit 3e20d3d3964a3a6ac5f882842c7716e2682d622f.

mgcarrasco avatar May 18 '26 14:05 mgcarrasco

Just to add on this. The following version doesn't crash:

void hipsmith_kernel() { 
  //S0 c_1938{&hip_managed_2}; 
  S0 c_1938;
  c_1938.g_1690 = &hip_managed_2;
}

mgcarrasco avatar May 18 '26 14:05 mgcarrasco

@llvm/issue-subscribers-clang-frontend

Author: ElliotBLabs

Compiling the attached HIP program causes a segmentation fault in the Clang frontend.

Test File: HIPProg.hip

How to reproduce:

clang++ -x hip HIPProg.hip --offload-arch=native
Stack dump:
0.      Program arguments: ... clang-23 -cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -O3 ...
1.      &lt;eof&gt; parser at end of file
2.      Per-file LLVM IR generation
 #<!-- -->0 0x0000742d80c5e41b llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) 
 ...
 #<!-- -->4 0x0000742d80ce15a8 llvm::SymbolTableListTraits&lt;llvm::Instruction, llvm::ilist_iterator_bits&lt;true&gt;, llvm::ilist_parent&lt;llvm::BasicBlock&gt;&gt;::addNodeToList(llvm::Instruction*)
 #<!-- -->5 0x0000742d80e04f32 llvm::Instruction::Instruction(llvm::Type*, unsigned int, llvm::User::AllocInfo, llvm::InsertPosition)
 #<!-- -->6 0x0000742d80e10021 llvm::LoadInst::LoadInst(llvm::Type*, llvm::Value*, llvm::Twine const&amp;, bool, llvm::Align, llvm::InsertPosition)
 #<!-- -->7 0x0000742d89af882b (anonymous namespace)::CGNVCUDARuntime::finalizeModule() CGCUDANV.cpp:0:0
 #<!-- -->8 0x0000742d89f00166 clang::CodeGen::CodeGenModule::Release() 
 #<!-- -->9 0x0000742d89f8dcfd (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) ModuleBuilder.cpp:0:0
#<!-- -->10 0x0000742d89e89495 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) 
 ...
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed with exit code -2 (use -v to see invocation)
</details>