microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Segfault when emitting NonSemantic.Shader.DebugInfo.100 for uninstantiated/incomplete type template parameter
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
Compiling the snippet below with -T cs_6_9 -spirv -fspv-debug=vulkan causes a segfault.
template<typename T>
struct A {};
template<typename T>
struct B {};
[numthreads(1, 1, 1)]
void main() {
A<B<int> > a;
}
Steps to Reproduce
Option 1: uninstantiated template specialization
https://godbolt.org/z/c6sP977oe
Option 2: incomplete type
https://godbolt.org/z/T6zc4Yarn
Actual Behavior
Program terminated with signal: SIGSEGV
Compiler returned: 139
Environment
- DXC version 1.8.2505
Analysis
The segfault occurs when trying to lower a type that has no definition, B<int> in my example.
For a composite type like B<int>, LowerTypeVisitor::lowerType calls LowerTypeVisitor::lowerStructFields, which accesses the type's definition. B<int> is uninstantiated and so it has no definition because it is not used in a context that requires a complete type.
Now, the reason that the type B<int> is being lowered to a SPIR-V type at all is that debug type information is generated for the type of the variable a, i.e. for A<B<int>>. This is done in the parameter handling of DebugTypeVisitor::lowerDebugTypeTemplate and is, as far as I can tell, where the real logical problem is.
Ideally, you would want to generate a debug type that represents this incomplete type. Unfortunately, the extension has no way to represent that, afaik. Maybe the best solution would be to just generate a debug composite type with no members and size zero to represent B. In this case, trying to lower it to a concrete, non-debug SPIR-V type would best be avoided.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash with the provided HLSL template snippets using -T cs_6_9 -spirv -fspv-debug=vulkan. Start with LowerTypeVisitor::lowerType and lowerStructFields, then inspect DebugTypeVisitor::lowerDebugTypeTemplate to trace how the incomplete B type is lowered. Done means both reproduction cases complete without a segmentation fault while preserving valid debug type handling.
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
- 35/100