Skip to content

Commit eb1223e

Browse files
authored
sema: fix int enum implicit cast to float. (microsoft#6977)
An implicit cast from int enum to a float should be a Floating_Integral cast, not an Integral_Conversion. Fixes microsoft#6884 --------- Signed-off-by: Nathan Gauër <[email protected]>
1 parent 848b7c4 commit eb1223e

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9102,7 +9102,10 @@ static bool ConvertComponent(ArTypeInfo TargetInfo, ArTypeInfo SourceInfo,
91029102
return false;
91039103
} else if (IS_BASIC_ENUM(SourceInfo.EltKind)) {
91049104
// enum -> int/float
9105-
ComponentConversion = ICK_Integral_Conversion;
9105+
if (IS_BASIC_FLOAT(TargetInfo.EltKind))
9106+
ComponentConversion = ICK_Floating_Integral;
9107+
else
9108+
ComponentConversion = ICK_Integral_Conversion;
91069109
} else if (TargetInfo.EltKind == AR_OBJECT_STRING) {
91079110
if (SourceInfo.EltKind == AR_OBJECT_STRING_LITERAL) {
91089111
ComponentConversion = ICK_Array_To_Pointer;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %dxc -T vs_6_5 %s | FileCheck %s
2+
3+
enum UE : uint {
4+
UA = 1
5+
};
6+
7+
enum SE : int {
8+
SA = 3
9+
};
10+
11+
struct Output {
12+
float u;
13+
float s;
14+
};
15+
16+
Output main(UE u : A, SE s : B) : C {
17+
// CHECK-DAG: %[[U:.+]] = call i32 @dx.op.loadInput.i32(i32 4, i32 0, i32 0, i8 0, i32 undef)
18+
// CHECK-DAG: %[[S:.+]] = call i32 @dx.op.loadInput.i32(i32 4, i32 1, i32 0, i8 0, i32 undef)
19+
20+
Output o;
21+
22+
o.u = u;
23+
// CHECK-DAG: %[[FU:.+]] = uitofp i32 %[[U]] to float
24+
// CHECK-DAG: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float %[[FU]])
25+
26+
o.s = s;
27+
// CHECK-DAG: %[[FS:.+]] = sitofp i32 %[[S]] to float
28+
// CHECK-DAG: call void @dx.op.storeOutput.f32(i32 5, i32 1, i32 0, i8 0, float %[[FS]])
29+
30+
return o;
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %dxc -T cs_6_6 -fspv-target-env=vulkan1.3 -E main %s -spirv -fcgl | FileCheck %s
2+
3+
enum : uint {
4+
UA = 1
5+
};
6+
7+
enum : int {
8+
SA = 3
9+
};
10+
11+
static float p;
12+
13+
[numthreads(1, 1, 1)]
14+
void main() {
15+
//CHECK: OpStore %foo %float_1
16+
float foo = UA;
17+
18+
//CHECK: OpStore %bar %float_3
19+
float bar = SA;
20+
}

tools/clang/test/CodeGenSPIRV/type.enum.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void main() {
101101
testParamTypeCast(Second);
102102

103103
//CHECK: [[a_2:%[0-9]+]] = OpLoad %int %a
104-
//CHECK-NEXT: [[a_3:%[0-9]+]] = OpBitcast %float [[a_2]]
104+
//CHECK-NEXT: [[a_3:%[0-9]+]] = OpConvertSToF %float [[a_2]]
105105
//CHECK-NEXT: [[sin:%[0-9]+]] = OpExtInst %float {{%[0-9]+}} Sin [[a_3]]
106106
//CHECK-NEXT: OpStore %bar [[sin]]
107107
float bar = sin(a);

0 commit comments

Comments
 (0)