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
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.
Description
Compiling the snippet below with
-T cs_6_9 -spirv -fspv-debug=vulkancauses a segfault.Steps to Reproduce
Option 1: uninstantiated template specialization
https://godbolt.org/z/c6sP977oe
Option 2: incomplete type
https://godbolt.org/z/T6zc4Yarn
Actual Behavior
Environment
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::lowerTypecallsLowerTypeVisitor::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 variablea, i.e. forA<B<int>>. This is done in the parameter handling ofDebugTypeVisitor::lowerDebugTypeTemplateand 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.