92 lines · plain
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -Wconversion -verify -o - %s2// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -Wno-conversion -DNO_ERR -ast-dump %s | FileCheck %s3 4void test() {5 6 // CHECK: VarDecl {{.*}} used f3 'vector<float, 3>' cinit7 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 3>' <VectorSplat>8 // CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+009 vector<float,3> f3 = 1.0; // No warning for splatting to a vector from a literal.10 11 12 // CHECK: VarDecl {{.*}} used d4 'vector<double, 4>' cinit13 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <FloatingCast>14 // CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector<float, 4>' xyzx15 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<float, 3>' lvalue Var {{.*}} 'f3' 'vector<float, 3>'16 vector<double,4> d4 = f3.xyzx; // No warnings for promotion or explicit extension.17 18 // CHECK: VarDecl {{.*}} used f2 'vector<float, 2>' cinit19 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <HLSLVectorTruncation>20 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 3>' <LValueToRValue>21 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<float, 3>' lvalue Var {{.*}} 'f3' 'vector<float, 3>'22 // expected-warning@#f2{{implicit conversion truncates vector: 'vector<float, 3>' (vector of 3 'float' values) to 'vector<float, 2>' (vector of 2 'float' values)}}23 vector<float,2> f2 = f3; // #f224 25 // CHECK: VarDecl {{.*}} f2_2 'vector<float, 2>' cinit26 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <HLSLVectorTruncation>27 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <FloatingCast>28 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <LValueToRValue>29 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<double, 4>' lvalue Var {{.*}} 'd4' 'vector<double, 4>'30 // expected-warning@#f2_2{{implicit conversion truncates vector: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<float, 2>' (vector of 2 'float' values)}}31 // expected-warning@#f2_2{{implicit conversion loses floating-point precision: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<float, 2>' (vector of 2 'float' values)}}32 vector<float,2> f2_2 = d4; // #f2_233 34 // CHECK: VarDecl {{.*}} i2 'vector<int, 2>' cinit35 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 2>' <FloatingToIntegral>36 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 2>' <LValueToRValue>37 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<float, 2>' lvalue Var {{.*}} 'f2' 'vector<float, 2>'38 // expected-warning@#i2{{mplicit conversion turns floating-point number into integer: 'vector<float, 2>' (vector of 2 'float' values) to 'vector<int, 2>' (vector of 2 'int' values)}}39 vector<int,2> i2 = f2; // #i240 41 // CHECK: VarDecl {{.*}} i2_2 'vector<int, 2>' cinit42 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 2>' <HLSLVectorTruncation>43 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <FloatingToIntegral>44 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <LValueToRValue>45 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<double, 4>' lvalue Var {{.*}} 'd4' 'vector<double, 4>'46 // expected-warning@#i2_2{{implicit conversion truncates vector: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<int, 2>' (vector of 2 'int' values)}}47 // expected-warning@#i2_2{{implicit conversion turns floating-point number into integer: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<int, 2>' (vector of 2 'int' values)}}48 vector<int,2> i2_2 = d4; // #i2_249 50 51 // CHECK: VarDecl {{.*}} used i64_4 'vector<long, 4>' cinit52 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<long, 4>' <FloatingToIntegral>53 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <LValueToRValue>54 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<double, 4>' lvalue Var {{.*}} 'd4' 'vector<double, 4>'55 // expected-warning@#i64_4{{implicit conversion turns floating-point number into integer: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<long, 4>' (vector of 4 'long' values)}}56 vector<long,4> i64_4 = d4; // #i64_457 58 // CHECK: VarDecl {{.*}} used i2_3 'vector<int, 2>' cinit59 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 2>' <HLSLVectorTruncation>60 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <IntegralCast>61 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<long, 4>' <LValueToRValue>62 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<long, 4>' lvalue Var {{.*}} 'i64_4' 'vector<long, 4>'63 // expected-warning@#i2_3{{implicit conversion loses integer precision: 'vector<long, 4>' (vector of 4 'long' values) to 'vector<int, 2>' (vector of 2 'int' values)}}64 // expected-warning@#i2_3{{implicit conversion truncates vector: 'vector<long, 4>' (vector of 4 'long' values) to 'vector<int, 2>' (vector of 2 'int' values)}}65 vector<int,2> i2_3 = i64_4; // #i2_366 67 //CHECK: VarDecl {{.*}} b2 'vector<bool, 2>' cinit68 //CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<bool, 2>' <IntegralToBoolean>69 //CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 2>' <LValueToRValue>70 //CHECK-NEXT: DeclRefExpr {{.*}} 'vector<int, 2>' lvalue Var {{.*}} 'i2_3' 'vector<int, 2>'71 vector<bool, 2> b2 = i2_3; // No warning for integer to bool conversion.72 73 // CHECK: VarDecl {{.*}} b2_2 'vector<bool, 2>' cinit74 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<bool, 2>' <HLSLVectorTruncation>75 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<bool, 4>' <FloatingToBoolean>76 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <LValueToRValue>77 // CHECK-NEXT: DeclRefExpr {{.*}} 'vector<double, 4>' lvalue Var {{.*}} 'd4' 'vector<double, 4>'78 // expected-warning@#b2_2{{implicit conversion truncates vector: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<bool, 2>' (vector of 2 'bool' values)}}79 // expected-warning@#b2_2{{implicit conversion turns floating-point number into integer: 'vector<double, 4>' (vector of 4 'double' values) to 'vector<bool, 2>' (vector of 2 'bool' values)}}80 vector<bool, 2> b2_2 = d4; // #b2_281}82 83#ifndef NO_ERR84 85void illegal() {86 // vector extension is illegal87 vector<float,3> f3 = 1.0;88 vector<float,4> f4 = f3; // expected-error{{cannot initialize a variable of type 'vector<[...], 4>' with an lvalue of type 'vector<[...], 3>'}}89}90 91#endif92