llvm / llvm/llvm-project

[HLSL] Assertion crash when initializing a static local resource

Open
#205,169 1 comment 0 reactions 0 assignees View on GitHub
crash HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider this HLSL:
```hlsl

RWByteAddressBuffer gBuf0 : register(u0);

uint Pass_StaticLocal(uint idx) {
static RWByteAddressBuffer buf = gBuf0;
buf.Store(idx * 4, 1);

return 1;
}

[numthreads(1,1,1)]
void main(uint3 tid : SV_DispatchThreadID) {
Pass_StaticLocal(tid.x);
}
```

It produces the below stack trace when compiled with -T cs_6_0:

```
# RUN: at line 58
/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin/split-file /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/OffloadTest/test/Feature/LocalResources/local_resource_static_local.test /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp
# executed command: /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin/split-file /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/OffloadTest/test/Feature/LocalResources/local_resource_static_local.test /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp
# RUN: at line 59
/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin/clang-dxc --dxv-path=/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/DXC/build/bin -T cs_6_0 -Fo /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp.o /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp/source.hlsl
# executed command: /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin/clang-dxc --dxv-path=/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/DXC/build/bin -T cs_6_0 -Fo /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp.o /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp/source.hlsl
# .---command stderr------------
# | Assertion failed: (Ty->hasProperty(TargetExtType::HasZeroInit) && "Target extension type not allowed to have a zeroinitializer"), function get, file Constants.cpp, line 1997.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
# | Stack dump:
# | 0. Program arguments: /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin/clang-23 -cc1 -triple dxilv1.0-unknown-shadermodel6.0-compute -O3 -Wconversion -Wvector-conversion -Wmatrix-conversion -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name source.hlsl -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -debugger-tuning=gdb -fdebug-compilation-dir=/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources -target-linker-version 1230.1 -fcoverage-compilation-dir=/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources -resource-dir /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/lib/clang/23 -ferror-limit 19 -O3 -finclude-default-header -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -o /var/folders/9v/g7k79jss47nfbjfnb9fvj_2w0000gn/T/lit-tmp-smeanvz6/source-279e4f.obj -x hlsl /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp/source.hlsl
# | 1. parser at end of file
# | 2. Optimizer
# | 3. Running pass "globalopt" on module "/Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/tools/OffloadTest/test/clang-mtl/Feature/LocalResources/Output/local_resource_static_local.test.tmp/source.hlsl"
# | Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
# | 0 clang-23 0x000000010220961c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
# | 1 clang-23 0x0000000102207360 llvm::sys::RunSignalHandlers() + 204
# | 2 clang-23 0x000000010220a120 SignalHandler(int, __siginfo*, void*) + 300
# | 3 clang-23 0x0000000102209fb8 SignalHandlerTerminate(int, __siginfo*, void*) + 20
# | 4 libsystem_platform.dylib 0x00000001976d3744 _sigtramp + 56
# | 5 libsystem_pthread.dylib 0x00000001976c9888 pthread_kill + 296
# | 6 libsystem_c.dylib 0x00000001975ce850 abort + 124
# | 7 libsystem_c.dylib 0x00000001975cda84 err + 0
# | 8 clang-23 0x0000000104c841a0 llvm::ConstantInt::get(llvm::LLVMContext&, llvm::APInt const&) (.cold.1) + 0
# | 9 clang-23 0x000000010189a2c8 llvm::ConstantTargetNone::get(llvm::TargetExtType*) + 296
# | 10 clang-23 0x0000000101143774 llvm::ConstantFoldLoadThroughBitcast(llvm::Constant*, llvm::Type*, llvm::DataLayout const&) + 172
# | 11 clang-23 0x0000000101144b84 llvm::ConstantFoldLoadFromConst(llvm::Constant*, llvm::Type*, llvm::APInt const&, llvm::DataLayout const&) + 148
# | 12 clang-23 0x0000000101adb9b8 processInternalGlobal(llvm::GlobalVariable*, llvm::GlobalStatus const&, llvm::function_ref, llvm::function_ref, llvm::function_ref) + 4672
# | 13 clang-23 0x0000000101ada314 processGlobal(llvm::GlobalValue&, llvm::function_ref, llvm::function_ref, llvm::function_ref) + 276
# | 14 clang-23 0x0000000101ad78d0 optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout const&, llvm::function_ref, llvm::function_ref, llvm::function_ref, llvm::function_ref, llvm::function_ref, llvm::function_ref) + 4664
# | 15 clang-23 0x0000000101ad650c llvm::GlobalOptPass::run(llvm::Module&, llvm::AnalysisManager&) + 296
# | 16 clang-23 0x000000010199d114 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) + 408
# | 17 clang-23 0x00000001026b19f4 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::__1::unique_ptr>&, std::__1::unique_ptr>&, clang::BackendConsumer*) + 10592
# | 18 clang-23 0x00000001026ab248 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::__1::unique_ptr>, clang::BackendConsumer*) + 1876
# | 19 clang-23 0x00000001029282a0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1308
# | 20 clang-23 0x000000010380e0f0 clang::ParseAST(clang::Sema&, bool, bool) + 544
# | 21 clang-23 0x0000000102cf6b14 clang::HLSLFrontendAction::ExecuteAction() + 392
# | 22 clang-23 0x0000000102cdcd64 clang::FrontendAction::Execute() + 48
# | 23 clang-23 0x0000000102c752c4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1104
# | 24 clang-23 0x0000000102d5e51c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 468
# | 25 clang-23 0x0000000100c5983c cc1_main(llvm::ArrayRef, char const*, void*) + 1420
# | 26 clang-23 0x0000000100c57b14 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) + 1000
# | 27 clang-23 0x0000000100c57424 clang_main(int, char**, llvm::ToolContext const&) + 5868
# | 28 clang-23 0x0000000100c62e24 main + 92
# | 29 dyld 0x0000000197301d54 start + 7184
# | clang-dxc: error: unable to execute command: Abort trap: 6
# | clang-dxc: error: clang frontend command failed with exit code -2 (use -v to see invocation)
# | clang version 23.0.0git (https://github.com/llvm/llvm-project a40055caee3c372675da0190dcce1e7b14831485)
# | Target: dxilv1.0-unknown-shadermodel6.0-compute
# | Thread model: posix
# | InstalledDir: /Users/admin/actions-runner/_work/offload-test-suite/offload-test-suite/llvm-project/build/bin
# | Build config: +assertions
# | clang-dxc: note: diagnostic msg:
# | ********************
# |
# | PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
# | clang-dxc: note: diagnostic msg: /var/folders/9v/g7k79jss47nfbjfnb9fvj_2w0000gn/T/lit-tmp-smeanvz6/source-6184b4.hlsl
# | clang-dxc: note: diagnostic msg: /var/folders/9v/g7k79jss47nfbjfnb9fvj_2w0000gn/T/lit-tmp-smeanvz6/source-6184b4.sh
# | clang-dxc: note: diagnostic msg: Crash backtrace is located in
# | clang-dxc: note: diagnostic msg: /Users/admin/Library/Logs/DiagnosticReports/clang-23__.crash
# | clang-dxc: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
# | clang-dxc: note: diagnostic msg:
# |
# | ********************
# `-----------------------------
# error: command failed with exit status: -6
```
We do not see any error diagnostics disallowing static local resources, instead an assertion triggers, causing a failure.
We should emit an error diagnostic and gracefully exit, and not crash on an assert.

Contributor guide

Open the contributing guide

Research direction

Start with OffloadTest/test/Feature/LocalResources/local_resource_static_local.test and reproduce the clang-dxc command using the static local HLSL resource. Trace the GlobalOpt failure through Constants.cpp around the reported assertion and inspect nearby HLSL resource tests. Done means the reproducer emits an error diagnostic and exits without triggering an assertion.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.