103 lines · plain
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -fsyntax-only -Wconversion %s -DERROR=1 -verify2// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -ast-dump %s | FileCheck %s3 4// Case 1: Prefer conversion over exact match truncation.5 6void Half4Float2(float2 D);7void Half4Float2(half4 D);8 9void 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)}}14}15 16// Case 2: Prefer promotions over conversions when truncating.17void Half2Double2(double2 D);18void Half2Double2(half2 H);19 20void 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)}}25}26 27// Case 3: Allow truncation down to vector<T,1> or T.28void Half(half H);29void Float(float F);30void Double(double D);31 32void Half1(half1 H);33void Float1(float1 F);34void Double1(double1 D);35 36void 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'}}40 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'}}44 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'}}48 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)}}52 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)}}56 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)}}60}61 62 63#if ERROR64// Case 3: Two promotions or two conversions are ambiguous.65void Float2Double2(double2 D); // expected-note{{candidate function}}66void Float2Double2(float2 D); // expected-note{{candidate function}}67 68void Half2Float2(float2 D); // expected-note{{candidate function}}69void Half2Float2(half2 D); // expected-note{{candidate function}}70 71void Half2Half3(half3 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}72void Half2Half3(half2 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}73 74void Double2Double3(double3 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}75void Double2Double3(double2 D); // expected-note{{candidate function}} expected-note{{candidate function}} expected-note{{candidate function}}76 77void Half4Float4Double2(double2 D);78void Half4Float4Double2(float4 D); // expected-note{{candidate function}}79void Half4Float4Double2(half4 D); // expected-note{{candidate function}}80 81void Case1(half4 H, float4 F, double4 D) {82 Half4Float4Double2(D); // expected-error {{call to 'Half4Float4Double2' is ambiguous}}83 84 Float2Double2(H); // expected-error {{call to 'Float2Double2' is ambiguous}}85 86 Half2Float2(D); // expected-error {{call to 'Half2Float2' is ambiguous}}87 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}}91 Half2Half3(H.xyz);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)}}94 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);101}102#endif103