Skip to content

Commit 6cc0138

Browse files
authored
Fix implicit conversion rank ordering (#106811)
DXC prefers dimension-preserving conversions over precision-losing conversions. This means a double4 -> float4 conversion is preferred over a double4 -> double3 or double4 -> double conversion.
1 parent cd8229b commit 6cc0138

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

clang/include/clang/Sema/Overload.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ class Sema;
225225
/// HLSL Scalar Widening with promotion
226226
ICR_HLSL_Scalar_Widening_Promotion,
227227

228-
/// HLSL Matching Dimension Reduction
229-
ICR_HLSL_Dimension_Reduction,
230-
231228
/// Conversion
232229
ICR_Conversion,
233230

@@ -250,6 +247,9 @@ class Sema;
250247
/// extension anyway.
251248
ICR_C_Conversion_Extension,
252249

250+
/// HLSL Matching Dimension Reduction
251+
ICR_HLSL_Dimension_Reduction,
252+
253253
/// HLSL Dimension reduction with promotion
254254
ICR_HLSL_Dimension_Reduction_Promotion,
255255

clang/test/SemaHLSL/TruncationOverloadResolution.hlsl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -fsyntax-only %s -DERROR=1 -verify
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -fsyntax-only -Wconversion %s -DERROR=1 -verify
22
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -ast-dump %s | FileCheck %s
33

4-
// Case 1: Prefer exact-match truncation over conversion.
5-
void Half4Float4Double2(double2 D);
6-
void Half4Float4Double2(float4 D);
7-
void Half4Float4Double2(half4 D);
4+
// Case 1: Prefer conversion over exact match truncation.
85

96
void Half4Float2(float2 D);
107
void Half4Float2(half4 D);
118

129
void Case1(float4 F, double4 D) {
1310
// CHECK: CallExpr {{.*}} 'void'
14-
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(double2)' <FunctionToPointerDecay>
15-
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (double2)' lvalue Function {{.*}} 'Half4Float4Double2' 'void (double2)'
16-
Half4Float4Double2(D); // expected-warning{{implicit conversion truncates vector: 'double4' (aka 'vector<double, 4>') to 'vector<double, 2>' (vector of 2 'double' values)}}
17-
18-
// CHECK: CallExpr {{.*}} 'void'
19-
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(float2)' <FunctionToPointerDecay>
20-
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (float2)' lvalue Function {{.*}} 'Half4Float2' 'void (float2)'
21-
Half4Float2(F); // expected-warning{{implicit conversion truncates vector: 'float4' (aka 'vector<float, 4>') to 'vector<float, 2>' (vector of 2 'float' values)}}
11+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(half4)' <FunctionToPointerDecay>
12+
// CHECK-NEXT: DeclRefExpr {{.*}} 'void (half4)' lvalue Function {{.*}} 'Half4Float2' 'void (half4)'
13+
Half4Float2(F); // expected-warning{{implicit conversion loses floating-point precision: 'float4' (aka 'vector<float, 4>') to 'vector<half, 4>' (vector of 4 'half' values)}}
2214
}
2315

2416
// Case 2: Prefer promotions over conversions when truncating.
@@ -46,7 +38,13 @@ void Half2Half3(half2 D); // expected-note{{candidate function}} expected-note{{
4638
void Double2Double3(double3 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
4739
void Double2Double3(double2 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
4840

41+
void Half4Float4Double2(double2 D);
42+
void Half4Float4Double2(float4 D); // expected-note{{candidate function}}
43+
void Half4Float4Double2(half4 D); // expected-note{{candidate function}}
44+
4945
void Case1(half4 H, float4 F, double4 D) {
46+
Half4Float4Double2(D); // expected-error {{call to 'Half4Float4Double2' is ambiguous}}
47+
5048
Float2Double2(H); // expected-error {{call to 'Float2Double2' is ambiguous}}
5149

5250
Half2Float2(D); // expected-error {{call to 'Half2Float2' is ambiguous}}
@@ -55,8 +53,8 @@ void Case1(half4 H, float4 F, double4 D) {
5553
Half2Half3(F); // expected-error {{call to 'Half2Half3' is ambiguous}}
5654
Half2Half3(D); // expected-error {{call to 'Half2Half3' is ambiguous}}
5755
Half2Half3(H.xyz);
58-
Half2Half3(F.xyz);
59-
Half2Half3(D.xyz);
56+
Half2Half3(F.xyz); // expected-warning {{implicit conversion loses floating-point precision: 'vector<float, 3>' (vector of 3 'float' values) to 'vector<half, 3>' (vector of 3 'half' values)}}
57+
Half2Half3(D.xyz); // expected-warning {{implicit conversion loses floating-point precision: 'vector<double, 3>' (vector of 3 'double' values) to 'vector<half, 3>' (vector of 3 'half' values)}}
6058

6159
Double2Double3(H); // expected-error {{call to 'Double2Double3' is ambiguous}}
6260
Double2Double3(F); // expected-error {{call to 'Double2Double3' is ambiguous}}

0 commit comments

Comments
 (0)