Skip to content

Commit 0ff2c71

Browse files
committed
[HLSL] Fix casting asserts
There are two issues here. first ICK_Floating_Integral were always defaulting to CK_FloatingToIntegral for vectors regardless of direction of cast. Check was scalar only so added a vec float check to the conditional. Second issue was float to int casts were resolving to ICK_Integral_Promotion when they need to be resolving to CK_FloatingToIntegral. This was fixed by changing the ordering of conversion checks. This fixes #82826
1 parent 24e7be4 commit 0ff2c71

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4843,7 +4843,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
48434843
.get();
48444844
break;
48454845
case ICK_Floating_Integral:
4846-
if (ToType->isRealFloatingType())
4846+
if (ToType->hasFloatingRepresentation())
48474847
From =
48484848
ImpCastExprToType(From, ToType, CK_IntegralToFloating, VK_PRValue,
48494849
/*BasePath=*/nullptr, CCK)

clang/lib/Sema/SemaOverload.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,13 @@ static bool IsVectorElementConversion(Sema &S, QualType FromType,
18841884
return true;
18851885
}
18861886

1887+
if ((FromType->isRealFloatingType() && ToType->isIntegralType(S.Context)) ||
1888+
(FromType->isIntegralOrUnscopedEnumerationType() &&
1889+
ToType->isRealFloatingType())) {
1890+
ICK = ICK_Floating_Integral;
1891+
return true;
1892+
}
1893+
18871894
if (S.IsIntegralPromotion(From, FromType, ToType)) {
18881895
ICK = ICK_Integral_Promotion;
18891896
return true;
@@ -1895,13 +1902,6 @@ static bool IsVectorElementConversion(Sema &S, QualType FromType,
18951902
return true;
18961903
}
18971904

1898-
if ((FromType->isRealFloatingType() && ToType->isIntegralType(S.Context)) ||
1899-
(FromType->isIntegralOrUnscopedEnumerationType() &&
1900-
ToType->isRealFloatingType())) {
1901-
ICK = ICK_Floating_Integral;
1902-
return true;
1903-
}
1904-
19051905
return false;
19061906
}
19071907

clang/test/SemaHLSL/VectorOverloadResolution.hlsl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -triple dxil-unknown-shadermodel6.6-library -S -fnative-half-type -finclude-default-header -o - -ast-dump %s | FileCheck %s
2+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s --check-prefixes=CHECKIR
23
void Fn(double2 D);
34
void Fn(half2 H);
45

@@ -28,3 +29,43 @@ void Fn2(int16_t2 S);
2829
void Call2(int2 I) {
2930
Fn2(I);
3031
}
32+
33+
void Fn3( int64_t2 p0);
34+
35+
// CHECK: FunctionDecl {{.*}} Call3 'void (half2)'
36+
// CHECK: CallExpr {{.*}} 'void'
37+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(int64_t2)' <FunctionToPointerDecay>
38+
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (int64_t2)' lvalue Function {{.*}} 'Fn3' 'void (int64_t2)'
39+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t2':'long __attribute__((ext_vector_type(2)))' <FloatingToIntegral>
40+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'half2':'half __attribute__((ext_vector_type(2)))' <LValueToRValue>
41+
// CHECK-NEXT: DeclRefExpr {{.*}} 'half2':'half __attribute__((ext_vector_type(2)))' lvalue ParmVar {{.*}} 'p0' 'half2':'half __attribute__((ext_vector_type(2)))'
42+
// CHECKIR: %conv = fptosi <2 x half> %0 to <2 x i64>
43+
void Call3(half2 p0) {
44+
Fn3(p0);
45+
}
46+
47+
// CHECK: FunctionDecl {{.*}} Call4 'void (float2)'
48+
// CHECK: CallExpr {{.*}} 'void'
49+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(int64_t2)' <FunctionToPointerDecay>
50+
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (int64_t2)' lvalue Function {{.*}} 'Fn3' 'void (int64_t2)'
51+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t2':'long __attribute__((ext_vector_type(2)))' <FloatingToIntegral>
52+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float2':'float __attribute__((ext_vector_type(2)))' <LValueToRValue>
53+
// CHECK-NEXT: DeclRefExpr {{.*}} 'float2':'float __attribute__((ext_vector_type(2)))' lvalue ParmVar {{.*}} 'p0' 'float2':'float __attribute__((ext_vector_type(2)))'
54+
// CHECKIR: %conv = fptosi <2 x float> %0 to <2 x i64>
55+
void Call4(float2 p0) {
56+
Fn3(p0);
57+
}
58+
59+
void Fn4( float2 p0);
60+
61+
// CHECK: FunctionDecl {{.*}} Call5 'void (int64_t2)'
62+
// CHECK: CallExpr {{.*}} 'void'
63+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(float2)' <FunctionToPointerDecay>
64+
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (float2)' lvalue Function {{.*}} 'Fn4' 'void (float2)'
65+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float2':'float __attribute__((ext_vector_type(2)))' <IntegralToFloating>
66+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t2':'long __attribute__((ext_vector_type(2)))' <LValueToRValue>
67+
// CHECK-NEXT: DeclRefExpr {{.*}} 'int64_t2':'long __attribute__((ext_vector_type(2)))' lvalue ParmVar {{.*}} 'p0' 'int64_t2':'long __attribute__((ext_vector_type(2)))'
68+
// CHECKIR: %conv = sitofp <2 x i64> %0 to <2 x float>
69+
void Call5(int64_t2 p0) {
70+
Fn4(p0);
71+
}

0 commit comments

Comments
 (0)