Skip to content

Commit 7054e52

Browse files
authored
[SEMA] Don't emit an error for sizeof an enum. (#7449)
Fixes #7416
1 parent 2421964 commit 7054e52

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

tools/clang/lib/AST/HlslTypes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ bool IsHLSLNumericOrAggregateOfNumericType(clang::QualType type) {
9595
} else if (type->isArrayType()) {
9696
return IsHLSLNumericOrAggregateOfNumericType(
9797
QualType(type->getArrayElementTypeNoTypeQual(), 0));
98+
} else if (type->isEnumeralType()) {
99+
return true;
98100
}
99101

100102
// Chars can only appear as part of strings, which we don't consider numeric.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
enum E1 : uint64_t
4+
{
5+
v1 = 0,
6+
};
7+
8+
enum E2 : uint32_t
9+
{
10+
v2 = 0,
11+
};
12+
13+
struct S {
14+
E1 e1;
15+
E2 e2;
16+
};
17+
18+
RWBuffer<int> b;
19+
20+
[numthreads(128, 1, 1)]
21+
void main()
22+
{
23+
// CHECK: OpImageWrite {{%.*}} %uint_0 %int_8 None
24+
b[0] = sizeof(E1);
25+
26+
// CHECK: OpImageWrite {{%.*}} %uint_1 %int_4 None
27+
b[1] = sizeof(E2);
28+
29+
// CHECK: OpImageWrite {{%.*}} %uint_2 %int_16 None
30+
b[2] = sizeof(S);
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %dxc -T cs_6_9 -E main %s -ast-dump-implicit | FileCheck %s --check-prefix AST
2+
3+
enum E1 : uint64_t
4+
{
5+
v1 = 0,
6+
};
7+
8+
enum E2 : uint32_t
9+
{
10+
v2 = 0,
11+
};
12+
13+
struct S {
14+
E1 e1;
15+
E2 e2;
16+
};
17+
18+
RWBuffer<int> b;
19+
20+
[numthreads(128, 1, 1)]
21+
void main()
22+
{
23+
// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'E1'
24+
b[0] = sizeof(E1);
25+
26+
// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'E2'
27+
b[1] = sizeof(E2);
28+
29+
// AST: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'S'
30+
b[2] = sizeof(S);
31+
}

0 commit comments

Comments
 (0)