1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -fsyntax-only -Wconversion %s -DERROR=1 -verify
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -ast-dump %s | FileCheck %s
4 // Case 1: Prefer conversion over exact match truncation.
6 void Half4Float2(float2 D);
7 void Half4Float2(half4 D);
9 void Case1(float4 F, double4 D) {
10 // CHECK: CallExpr {{.*}} 'void'
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)}}
16 // Case 2: Prefer promotions over conversions when truncating.
17 void Half2Double2(double2 D);
18 void Half2Double2(half2 H);
20 void Case2(float4 F) {
21 // CHECK: CallExpr {{.*}} 'void'
22 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(double2)' <FunctionToPointerDecay>
23 // CHECK-NEXT: DeclRefExpr {{.*}} 'void (double2)' lvalue Function {{.*}} 'Half2Double2' 'void (double2)'
24 Half2Double2(F); // expected-warning{{implicit conversion truncates vector: 'float4' (aka 'vector<float, 4>') to 'vector<double, 2>' (vector of 2 'double' values)}}
27 // Case 3: Allow truncation down to vector<T,1> or T.
30 void Double(double D);
33 void Float1(float1 F);
34 void Double1(double1 D);
36 void Case3(half3 H, float3 F, double3 D) {
37 Half(H); // expected-warning{{implicit conversion turns vector to scalar: 'half3' (aka 'vector<half, 3>') to 'half'}}
38 Half(F); // expected-warning{{implicit conversion turns vector to scalar: 'float3' (aka 'vector<float, 3>') to 'half'}}
39 Half(D); // expected-warning{{implicit conversion turns vector to scalar: 'double3' (aka 'vector<double, 3>') to 'half'}}
41 Float(H); // expected-warning{{implicit conversion turns vector to scalar: 'half3' (aka 'vector<half, 3>') to 'float'}}
42 Float(F); // expected-warning{{implicit conversion turns vector to scalar: 'float3' (aka 'vector<float, 3>') to 'float'}}
43 Float(D); // expected-warning{{implicit conversion turns vector to scalar: 'double3' (aka 'vector<double, 3>') to 'float'}}
45 Double(H); // expected-warning{{implicit conversion turns vector to scalar: 'half3' (aka 'vector<half, 3>') to 'double'}}
46 Double(F); // expected-warning{{implicit conversion turns vector to scalar: 'float3' (aka 'vector<float, 3>') to 'double'}}
47 Double(D); // expected-warning{{implicit conversion turns vector to scalar: 'double3' (aka 'vector<double, 3>') to 'double'}}
49 Half1(H); // expected-warning{{implicit conversion truncates vector: 'half3' (aka 'vector<half, 3>') to 'vector<half, 1>' (vector of 1 'half' value)}}
50 Half1(F); // expected-warning{{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<half, 1>' (vector of 1 'half' value)}} expected-warning{{implicit conversion loses floating-point precision: 'float3' (aka 'vector<float, 3>') to 'vector<half, 1>' (vector of 1 'half' value)}}
51 Half1(D); // expected-warning{{implicit conversion truncates vector: 'double3' (aka 'vector<double, 3>') to 'vector<half, 1>' (vector of 1 'half' value)}} expected-warning{{implicit conversion loses floating-point precision: 'double3' (aka 'vector<double, 3>') to 'vector<half, 1>' (vector of 1 'half' value)}}
53 Float1(H); // expected-warning{{implicit conversion truncates vector: 'half3' (aka 'vector<half, 3>') to 'vector<float, 1>' (vector of 1 'float' value)}}
54 Float1(F); // expected-warning{{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 1>' (vector of 1 'float' value)}}
55 Float1(D); // expected-warning{{implicit conversion truncates vector: 'double3' (aka 'vector<double, 3>') to 'vector<float, 1>' (vector of 1 'float' value)}} expected-warning{{implicit conversion loses floating-point precision: 'double3' (aka 'vector<double, 3>') to 'vector<float, 1>' (vector of 1 'float' value)}}
57 Double1(H); // expected-warning{{implicit conversion truncates vector: 'half3' (aka 'vector<half, 3>') to 'vector<double, 1>' (vector of 1 'double' value)}}
58 Double1(F); // expected-warning{{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<double, 1>' (vector of 1 'double' value)}}
59 Double1(D); // expected-warning{{implicit conversion truncates vector: 'double3' (aka 'vector<double, 3>') to 'vector<double, 1>' (vector of 1 'double' value)}}
64 // Case 3: Two promotions or two conversions are ambiguous.
65 void Float2Double2(double2 D); // expected-note{{candidate function}}
66 void Float2Double2(float2 D); // expected-note{{candidate function}}
68 void Half2Float2(float2 D); // expected-note{{candidate function}}
69 void Half2Float2(half2 D); // expected-note{{candidate function}}
71 void Half2Half3(half3 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
72 void Half2Half3(half2 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
74 void Double2Double3(double3 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
75 void Double2Double3(double2 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}
77 void Half4Float4Double2(double2 D);
78 void Half4Float4Double2(float4 D); // expected-note{{candidate function}}
79 void Half4Float4Double2(half4 D); // expected-note{{candidate function}}
81 void Case1(half4 H, float4 F, double4 D) {
82 Half4Float4Double2(D); // expected-error {{call to 'Half4Float4Double2' is ambiguous}}
84 Float2Double2(H); // expected-error {{call to 'Float2Double2' is ambiguous}}
86 Half2Float2(D); // expected-error {{call to 'Half2Float2' is ambiguous}}
88 Half2Half3(H); // expected-error {{call to 'Half2Half3' is ambiguous}}
89 Half2Half3(F); // expected-error {{call to 'Half2Half3' is ambiguous}}
90 Half2Half3(D); // expected-error {{call to 'Half2Half3' is ambiguous}}
92 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)}}
93 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)}}
95 Double2Double3(H); // expected-error {{call to 'Double2Double3' is ambiguous}}
96 Double2Double3(F); // expected-error {{call to 'Double2Double3' is ambiguous}}
97 Double2Double3(D); // expected-error {{call to 'Double2Double3' is ambiguous}}
98 Double2Double3(D.xyz);
99 Double2Double3(F.xyz);
100 Double2Double3(H.xyz);