| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -Wconversion -verify -o - %s |
| 2 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -Wno-conversion -DNO_ERR -ast-dump %s | FileCheck %s |
| 3 |
|
| 4 |
void test() { |
| 5 |
|
| 6 |
// CHECK: VarDecl {{.*}} used f3 'vector<float, 3>' cinit |
| 7 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 3>' <VectorSplat> |
| 8 |
// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00 |
| 9 |
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>' cinit |
| 13 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<double, 4>' <FloatingCast> |
| 14 |
// CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector<float, 4>' xyzx |
| 15 |
// 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>' cinit |
| 19 |
// 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; // #f2 |
| 24 |
|
| 25 |
// CHECK: VarDecl {{.*}} f2_2 'vector<float, 2>' cinit |
| 26 |
// 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_2 |
| 33 |
|
| 34 |
// CHECK: VarDecl {{.*}} i2 'vector<int, 2>' cinit |
| 35 |
// 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; // #i2 |
| 40 |
|
| 41 |
// CHECK: VarDecl {{.*}} i2_2 'vector<int, 2>' cinit |
| 42 |
// 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_2 |
| 49 |
|
| 50 |
|
| 51 |
// CHECK: VarDecl {{.*}} used i64_4 'vector<long, 4>' cinit |
| 52 |
// 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_4 |
| 57 |
|
| 58 |
// CHECK: VarDecl {{.*}} used i2_3 'vector<int, 2>' cinit |
| 59 |
// 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_3 |
| 66 |
|
| 67 |
//CHECK: VarDecl {{.*}} b2 'vector<bool, 2>' cinit |
| 68 |
//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>' cinit |
| 74 |
// 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_2 |
| 81 |
} |
| 82 |
|
| 83 |
#ifndef NO_ERR |
| 84 |
|
| 85 |
void illegal() { |
| 86 |
// vector extension is illegal |
| 87 |
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 |
#endif |