diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 4b4f26983b..ba0801dd52 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -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; diff --git a/tools/clang/test/CodeGenSPIRV/type.enum.cast.hlsl b/tools/clang/test/CodeGenSPIRV/type.enum.cast.hlsl new file mode 100644 index 0000000000..c150cb4e16 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/type.enum.cast.hlsl @@ -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; +} diff --git a/tools/clang/test/CodeGenSPIRV/type.enum.hlsl b/tools/clang/test/CodeGenSPIRV/type.enum.hlsl index 38baa4d73c..ae24412f1d 100644 --- a/tools/clang/test/CodeGenSPIRV/type.enum.hlsl +++ b/tools/clang/test/CodeGenSPIRV/type.enum.hlsl @@ -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);