diff --git a/tools/clang/lib/AST/HlslTypes.cpp b/tools/clang/lib/AST/HlslTypes.cpp index 5b19e064a3..fda45d0b1d 100644 --- a/tools/clang/lib/AST/HlslTypes.cpp +++ b/tools/clang/lib/AST/HlslTypes.cpp @@ -95,6 +95,8 @@ bool IsHLSLNumericOrAggregateOfNumericType(clang::QualType type) { } else if (type->isArrayType()) { return IsHLSLNumericOrAggregateOfNumericType( QualType(type->getArrayElementTypeNoTypeQual(), 0)); + } else if (type->isEnumeralType()) { + return true; } // Chars can only appear as part of strings, which we don't consider numeric. diff --git a/tools/clang/test/CodeGenSPIRV/enum_sizeof.hlsl b/tools/clang/test/CodeGenSPIRV/enum_sizeof.hlsl new file mode 100644 index 0000000000..f596a2db50 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/enum_sizeof.hlsl @@ -0,0 +1,31 @@ +// RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s + +enum E1 : uint64_t +{ + v1 = 0, +}; + +enum E2 : uint32_t +{ + v2 = 0, +}; + +struct S { + E1 e1; + E2 e2; +}; + +RWBuffer b; + +[numthreads(128, 1, 1)] +void main() +{ +// CHECK: OpImageWrite {{%.*}} %uint_0 %int_8 None + b[0] = sizeof(E1); + +// CHECK: OpImageWrite {{%.*}} %uint_1 %int_4 None + b[1] = sizeof(E2); + +// CHECK: OpImageWrite {{%.*}} %uint_2 %int_16 None + b[2] = sizeof(S); +} diff --git a/tools/clang/test/SemaHLSL/enum_sizeof.hlsl b/tools/clang/test/SemaHLSL/enum_sizeof.hlsl new file mode 100644 index 0000000000..71723976a9 --- /dev/null +++ b/tools/clang/test/SemaHLSL/enum_sizeof.hlsl @@ -0,0 +1,31 @@ +// RUN: %dxc -T cs_6_9 -E main %s -ast-dump-implicit | FileCheck %s --check-prefix AST + +enum E1 : uint64_t +{ + v1 = 0, +}; + +enum E2 : uint32_t +{ + v2 = 0, +}; + +struct S { + E1 e1; + E2 e2; +}; + +RWBuffer b; + +[numthreads(128, 1, 1)] +void main() +{ +// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'E1' + b[0] = sizeof(E1); + +// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'E2' + b[1] = sizeof(E2); + +// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'S' + b[2] = sizeof(S); +}