Skip to content

clang-20 crash when compiling HIP device code for gfx1200 (ROCm 7.0.2), and uninitialized-memory use in CodeGen detected by valgrind #168431

@Brian-Cook-rk

Description

@Brian-Cook-rk

Summary
Using clang from ROCm 7.0.2 to compile a HIP device file for amdgcn-amd-amdhsa (gfx1200), we observe:

A clang crash during CodeGen when building rocPRIM test sources.
The crash appears in the build log at line 631 and following.

Use of uninitialized memory inside clang/LLVM CodeGen, detected via valgrind when re-running the same clang invocation in isolation.

The crash occurs during a parallel build.
However, the standalone invocation (provided below) does not itself crash, but it does consistently expose uninitialized-memory use under valgrind.

All required materials (crash log, preprocessed input, run script) are attached.

Environment
AMD clang version 20.0.0git
(https://github.com/RadeonOpenCompute/llvm-project roc-7.0.2 ...)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/rocm-7.0.2/lib/llvm/bin
Host triple: x86_64-unknown-linux-gnu

Device triple: amdgcn-amd-amdhsa

Target GPU: gfx1200

Crash observed in build log
During a build of rocPRIM tests, clang crashes during device-code emission.
The first failing entry in our log appears at:

build.log line 631

Complete build.log is attached.

Standalone reproduction setup

  1. Preprocessed source file
    The exact input given to clang is included:

➡️ test_linking_lib-hip-amdgcn-amd-amdhsa-gfx1200.hipi

  1. Run script (standalone clang invocation)
    The exact clang -cc1 command extracted from the build is contained in:

➡️ rpl

Running this script standalone:

does not reproduce the crash,

but is used for instrumentation and valgrind analysis described below.

Example excerpt of the invocation (truncated for readability):

/opt/rocm-7.0.2/lib/llvm/bin/clang-20 -cc1
-triple amdgcn-amd-amdhsa
-aux-triple x86_64-unknown-linux-gnu
-emit-llvm-bc -emit-llvm-uselists -save-temps=cwd
-disable-free -clear-ast-before-backend
-disable-llvm-verifier
-main-file-name test_linking_lib.cpp
-mrelocation-model pic -pic-level 2
-aux-target-cpu x86-64
-fcuda-is-device
-fno-threadsafe-statics
-target-cpu gfx1200
-debug-info-kind=constructor -dwarf-version=5
-std=c++17
-cuid=6366e6513e2eabac
-o test_linking_lib-hip-amdgcn-amd-amdhsa-gfx1200.bc
-x hip-cpp-output
test_linking_lib-hip-amdgcn-amd-amdhsa-gfx1200.hipi
Valgrind analysis of the standalone invocation
Even though the standalone invocation does not crash, running it under valgrind consistently reports uninitialized-memory usage inside clang/LLVM:

Conditional jump or move depends on uninitialised value(s)
at clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition
by clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition
by clang::CodeGen::CodeGenModule::EmitGlobalDefinition
...
Uninitialised value was created by a stack allocation
at llvm::Module::setDataLayout
Additional trace:
clang::CodeGen::CodeGenModule::codegenCXXStructor
clang::CodeGen::ItaniumCXXABI::emitCXXStructor

llvm-hip-gfx1200-repro.tar.gz

Full diagnostics: valgrind.txt

Metadata

Metadata

Labels

clang:codegenIR generation bugs: mangling, exceptions, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions