| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify -Wdouble-promotion -Wconversion %s |
| 2 |
|
| 3 |
struct TwoFloats { |
| 4 |
float X, Y; |
| 5 |
}; |
| 6 |
|
| 7 |
struct TwoInts { |
| 8 |
int Z, W; |
| 9 |
}; |
| 10 |
|
| 11 |
struct Doggo { |
| 12 |
int4 LegState; |
| 13 |
int TailState; |
| 14 |
float HairCount; |
| 15 |
float4 EarDirection[2]; |
| 16 |
}; |
| 17 |
|
| 18 |
struct AnimalBits { |
| 19 |
int Legs[4]; |
| 20 |
uint State; |
| 21 |
int64_t Counter; |
| 22 |
float4 LeftDir; |
| 23 |
float4 RightDir; |
| 24 |
}; |
| 25 |
|
| 26 |
struct Kitteh { |
| 27 |
int4 Legs; |
| 28 |
int TailState; |
| 29 |
float HairCount; |
| 30 |
float4 Claws[2]; |
| 31 |
}; |
| 32 |
|
| 33 |
struct Zoo { |
| 34 |
Doggo Dogs[2]; |
| 35 |
Kitteh Cats[4]; |
| 36 |
}; |
| 37 |
|
| 38 |
struct FourFloats : TwoFloats { |
| 39 |
float Z, W; |
| 40 |
}; |
| 41 |
|
| 42 |
struct SlicyBits { |
| 43 |
int Z : 8; |
| 44 |
int W : 8; |
| 45 |
}; |
| 46 |
|
| 47 |
struct ContainsResource { // #ContainsResource |
| 48 |
int X; |
| 49 |
RWBuffer<float4> B; |
| 50 |
}; |
| 51 |
|
| 52 |
struct ContainsResourceInverted { |
| 53 |
RWBuffer<float4> B; |
| 54 |
int X; |
| 55 |
}; |
| 56 |
|
| 57 |
void fn() { |
| 58 |
TwoFloats TF1 = {{{1.0, 2}}}; |
| 59 |
TwoFloats TF2 = {1,2}; |
| 60 |
int Val = 1; |
| 61 |
TwoFloats TF3 = {Val, 2}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} |
| 62 |
int2 TwoVals = 1.xx; |
| 63 |
int2 Something = 1.xxx; // expected-warning{{implicit conversion truncates vector: 'vector<int, 3>' (vector of 3 'int' values) to 'vector<int, 2>' (vector of 2 'int' values)}} |
| 64 |
TwoFloats TF4 = {TwoVals}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} |
| 65 |
|
| 66 |
TwoInts TI1 = {TwoVals}; |
| 67 |
TwoInts TI2 = {TF4}; // expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'int'}} expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'int'}} |
| 68 |
|
| 69 |
Doggo D1 = {TI1, TI2, {Val, Val}, {{TF1, TF2}, {TF3, TF4}}}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} |
| 70 |
AnimalBits A1 = {D1}; // expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'long'}} expected-warning{{implicit conversion changes signedness: 'int' to 'unsigned int'}} |
| 71 |
|
| 72 |
Zoo Z1 = {D1, A1, D1, A1, D1, A1}; // #insanity |
| 73 |
|
| 74 |
// expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} |
| 75 |
// expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} |
| 76 |
// expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} |
| 77 |
// expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} |
| 78 |
// expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} |
| 79 |
// expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} |
| 80 |
} |
| 81 |
|
| 82 |
void fn2() { |
| 83 |
TwoFloats TF2 = {1,2}; |
| 84 |
FourFloats FF1 = {TF2, TF2}; |
| 85 |
FourFloats FF2 = {1,2,3,4}; |
| 86 |
FourFloats FF3 = {1.xxx, 2}; |
| 87 |
|
| 88 |
SlicyBits SB1 = {1,2}; |
| 89 |
TwoInts TI1 = {SB1}; |
| 90 |
SlicyBits SB2 = {TI1}; |
| 91 |
} |
| 92 |
|
| 93 |
void Errs() { |
| 94 |
TwoFloats F1 = {}; // expected-error{{too few initializers in list for type 'TwoFloats' (expected 2 but found 0)}} |
| 95 |
TwoFloats F2 = {1}; // expected-error{{too few initializers in list for type 'TwoFloats' (expected 2 but found 1)}} |
| 96 |
TwoFloats F3 = {1,2,3}; // expected-error{{too many initializers in list for type 'TwoFloats' (expected 2 but found 3)}} |
| 97 |
|
| 98 |
int2 Something = {1.xxx}; // expected-error{{too many initializers in list for type 'int2' (aka 'vector<int, 2>') (expected 2 but found 3)}} |
| 99 |
} |
| 100 |
|
| 101 |
struct R { |
| 102 |
int A; |
| 103 |
union { // #anon |
| 104 |
float F; |
| 105 |
int4 G; |
| 106 |
}; |
| 107 |
}; |
| 108 |
|
| 109 |
// expected-note@#anon{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to}} |
| 110 |
// expected-note@#anon{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to}} |
| 111 |
|
| 112 |
void Err2(RWBuffer<float4> B) { |
| 113 |
ContainsResource RS1 = {1, B}; |
| 114 |
ContainsResource RS2 = (1.xx); // expected-error{{no viable conversion from 'vector<int, 2>' (vector of 2 'int' values) to 'ContainsResource'}} |
| 115 |
ContainsResource RS3 = {B, 1}; // expected-error{{no viable conversion from 'RWBuffer<float4>' (aka 'RWBuffer<vector<float, 4>>') to 'int'}} |
| 116 |
ContainsResourceInverted IR = {RS1}; // expected-error{{no viable conversion from 'int' to 'hlsl::RWBuffer<vector<float, 4>>'}} |
| 117 |
|
| 118 |
R r = {1,2}; // expected-error{{no viable conversion from 'int' to 'R::(anonymous union at}} |
| 119 |
} |
| 120 |
|
| 121 |
// expected-note@#ContainsResource{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'vector<int, 2>' (vector of 2 'int' values) to 'const ContainsResource &' for 1st argument}} |
| 122 |
// expected-note@#ContainsResource{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'vector<int, 2>' (vector of 2 'int' values) to 'ContainsResource &&' for 1st argument}} |
| 123 |
|
| 124 |
// This note refers to the RWBuffer copy constructor that do not have a source locations |
| 125 |
// expected-note@*{{candidate constructor not viable}} |