Skip to content

Commit 3508cdc

Browse files
authored
[SPIR-V] Lower templated enums correctly. (microsoft#6768)
Templated enums lowering was not supported. This commit fixes those cases. Fixes microsoft#6753 Signed-off-by: Nathan Gauër <[email protected]>
1 parent e0c83a8 commit 3508cdc

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,14 @@ const SpirvType *LowerTypeVisitor::lowerType(QualType type,
619619
return spvContext.getSIntType(32);
620620
}
621621

622+
// Templated types.
623+
if (const auto *spec = type->getAs<TemplateSpecializationType>()) {
624+
return lowerType(spec->desugar(), rule, isRowMajor, srcLoc);
625+
}
626+
if (const auto *spec = type->getAs<SubstTemplateTypeParmType>()) {
627+
return lowerType(spec->desugar(), rule, isRowMajor, srcLoc);
628+
}
629+
622630
emitError("lower type %0 unimplemented", srcLoc) << type->getTypeClassName();
623631
type->dump();
624632
return 0;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %dxc -T cs_6_6 -E main -spirv %s -fcgl | FileCheck %s
2+
3+
template<typename T>
4+
void templated_func() {
5+
T tmp;
6+
}
7+
8+
template<typename T>
9+
void templated_func_deduced(T tmp) {
10+
}
11+
12+
enum MyEnum { };
13+
14+
template<typename T>
15+
using TemplatedType = MyEnum;
16+
17+
[numthreads(1, 1, 1)]
18+
void main() {
19+
// CHECK: %a = OpVariable %_ptr_Function_int Function
20+
TemplatedType<MyEnum> a;
21+
22+
// CHECK: OpFunctionCall %void %templated_func
23+
templated_func<MyEnum>();
24+
25+
// CHECK: [[a:%[0-9]+]] = OpLoad %int %a
26+
// CHECK: OpStore %param_var_tmp [[a]]
27+
// CHECK: OpFunctionCall %void %templated_func_deduced %param_var_tmp
28+
templated_func_deduced(a);
29+
}

0 commit comments

Comments
 (0)