microsoft / microsoft/DirectXShaderCompiler

Compilation fails with an internal error when calling a function on a static variable that is of a templated type

Open
#7,133 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
Compilation fails with an internal error when calling a function on a static variable that is of a templated type. Only seems to happen with optimizations disabled and lib_* targets.

Steps to Reproduce
Compile the shader with -T lib_6_6 -E Main -O0

template<typename T>
struct Wrapper {
    void Foo(uint index, T value) {}
};

static Wrapper<float4> WrappedResource;

void Bar(uint index, float4 value) {
    WrappedResource.Foo(index, value);
}

[shader("raygeneration")]
void Main() {
}

https://godbolt.org/z/MeenE7fdW

Actual Behavior
Compilation fails with the message Internal compiler error: Terminal Error 0x80000003.
Stacktrace when running from within VisualStudio:

dxcompiler.dll!`anonymous namespace'::SROA_Helper::RewriteCall(llvm::CallInst * CI) Line 2804	C++
dxcompiler.dll!`anonymous namespace'::SROA_Helper::RewriteForScalarRepl(llvm::Value * V, llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1>> & Builder) Line 2897	C++
dxcompiler.dll!`anonymous namespace'::SROA_Helper::DoScalarReplacement(llvm::GlobalVariable * GV, std::vector<llvm::Value *,std::allocator<llvm::Value *>> & Elts, llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1>> & Builder, bool bFlatVector, bool hasPrecise, hlsl::DxilTypeSystem & typeSys, const llvm::DataLayout & DL, llvm::SmallVector<llvm::Value *,32> & DeadInsts, llvm::DominatorTree * DT) Line 3275	C++
dxcompiler.dll!`anonymous namespace'::SROAGlobalAndAllocas(hlsl::HLModule & HLM, bool bHasDbgInfo) Line 1983	C++
dxcompiler.dll!`anonymous namespace'::SROA_Parameter_HLSL::runOnModule(llvm::Module & M) Line 4375	C++
dxcompiler.dll!`anonymous namespace'::MPPassManager::runOnModule(llvm::Module & M) Line 1669	C++
dxcompiler.dll!llvm::legacy::PassManagerImpl::run(llvm::Module & M) Line 1771	C++
dxcompiler.dll!llvm::legacy::PassManager::run(llvm::Module & M) Line 1815	C++
dxcompiler.dll!`anonymous namespace'::EmitAssemblyHelper::EmitAssembly(clang::BackendAction Action, llvm::raw_pwrite_stream * OS) Line 760	C++
dxcompiler.dll!clang::EmitBackendOutput(clang::DiagnosticsEngine & Diags, const clang::CodeGenOptions & CGOpts, const clang::TargetOptions & TOpts, const clang::LangOptions & LOpts, llvm::StringRef TDesc, llvm::Module * M, clang::BackendAction Action, llvm::raw_pwrite_stream * OS) Line 783	C++
dxcompiler.dll!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 196	C++
dxcompiler.dll!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 166	C++
dxcompiler.dll!clang::ASTFrontendAction::ExecuteAction() Line 556	C++
dxcompiler.dll!clang::CodeGenAction::ExecuteAction() Line 809	C++
dxcompiler.dll!clang::FrontendAction::Execute() Line 468	C++
dxcompiler.dll!DxcCompiler::Compile(const DxcBuffer * pSource, const wchar_t * * pArguments, unsigned int argCount, IDxcIncludeHandler * pIncludeHandler, const _GUID & riid, void * * ppResult) Line 975	C++
dxcompiler.dll!hlsl::DxcCompilerAdapter::WrapCompile(int bPreprocess, IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult, wchar_t * * ppDebugBlobName, IDxcBlob * * ppDebugBlob) Line 1851	C++
dxcompiler.dll!hlsl::DxcCompilerAdapter::CompileWithDebug(IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult, wchar_t * * ppDebugBlobName, IDxcBlob * * ppDebugBlob) Line 1757	C++
dxcompiler.dll!hlsl::DxcCompilerAdapter::Compile(IDxcBlob * pSource, const wchar_t * pSourceName, const wchar_t * pEntryPoint, const wchar_t * pTargetProfile, const wchar_t * * pArguments, unsigned int argCount, const DxcDefine * pDefines, unsigned int defineCount, IDxcIncludeHandler * pIncludeHandler, IDxcOperationResult * * ppResult) Line 78	C++
dxc.exe!DxcContext::Compile() Line 874	C++
dxc.exe!dxc::main(int argc, const wchar_t * * argv_) Line 1502	C++
dxc.exe!wmain(int argc, const wchar_t * * argv_) Line 21	C++
dxc.exe!invoke_main() Line 91	C++
dxc.exe!__scrt_common_main_seh() Line 288	C++
dxc.exe!__scrt_common_main() Line 331	C++
dxc.exe!wmainCRTStartup(void * __formal) Line 17	C++
kernel32.dll!00007ffc69ec259d()	Unknown
ntdll.dll!00007ffc6b2eaf38()	Unknown

Which points to DXASSERT(0, "should done at inline");.

Environment

  • DXC version: 1.9 - 1.8.0.14785 (main, e4636f063)
  • Host Operating System Windows 11 23H2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Godbolt example with dxc using -T lib_6_6 -E Main -O0, then inspect the SROA_Helper::RewriteCall path and SROA_Parameter_HLSL::runOnModule named in the stack trace. Trace how the templated static variable call reaches the DXASSERT. Done means the shader compiles without the internal error while preserving the reported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.