Skip to content

Commit

Permalink
sema: fix int enum implicit cast to float.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Keenuts committed Oct 21, 2024
1 parent db90a46 commit c5b1c54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9102,7 +9102,10 @@ static bool ConvertComponent(ArTypeInfo TargetInfo, ArTypeInfo SourceInfo,
return false;
} else if (IS_BASIC_ENUM(SourceInfo.EltKind)) {
// enum -> int/float
ComponentConversion = ICK_Integral_Conversion;
if (IS_BASIC_FLOAT(TargetInfo.EltKind))
ComponentConversion = ICK_Floating_Integral;
else
ComponentConversion = ICK_Integral_Conversion;
} else if (TargetInfo.EltKind == AR_OBJECT_STRING) {
if (SourceInfo.EltKind == AR_OBJECT_STRING_LITERAL) {
ComponentConversion = ICK_Array_To_Pointer;
Expand Down
20 changes: 20 additions & 0 deletions tools/clang/test/CodeGenSPIRV/type.enum.cast.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %dxc -T cs_6_6 -fspv-target-env=vulkan1.3 -E main %s -spirv -fcgl | FileCheck %s

enum : uint {
UA = 1
};

enum : int {
SA = 3
};

static float p;

[numthreads(1, 1, 1)]
void main() {
//CHECK: OpStore %foo %float_1
float foo = UA;

//CHECK: OpStore %bar %float_3
float bar = SA;
}
2 changes: 1 addition & 1 deletion tools/clang/test/CodeGenSPIRV/type.enum.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void main() {
testParamTypeCast(Second);

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

0 comments on commit c5b1c54

Please sign in to comment.