Debian Codegraph @

clang/test/SemaHLSL/BuiltIns/matrix-constructors-errors.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify %s
2
3 typedef float float2x1 __attribute__((matrix_type(2,1)));
4 typedef float float2x2 __attribute__((matrix_type(2,2)));
5 typedef float float2 __attribute__((ext_vector_type(2)));
6
7 struct S { float f; };
8 struct S2 { float2 f;};
9
10 [numthreads(1,1,1)]
11 void entry() {
12 float2x1 LilMat = float2x1(1.0, 2.0);
13 float2x1 BrokenMat = float2x1(1.0, 2.0, 3.0); // expected-error{{too many initializers in list for type 'float2x1' (aka 'matrix<float, 2, 1>') (expected 2 but found 3)}}
14 float2x2 NormieMat = float2x2(LilMat, 3.0, 4.0, 5.0); // expected-error{{too many initializers in list for type 'float2x2' (aka 'matrix<float, 2, 2>') (expected 4 but found 5)}}
15 float2x2 BrokenNormie = float2x2(3.0, 4.0); // expected-error{{too few initializers in list for type 'float2x2' (aka 'matrix<float, 2, 2>') (expected 4 but found 2)}}
16 float2x1 OverwhemledNormie = float2x1(3.0, 4.0, 5.0, 6.0); // expected-error{{too many initializers in list for type 'float2x1' (aka 'matrix<float, 2, 1>') (expected 2 but found 4)}}
17
18 // These should work in HLSL and not error
19 S s;
20 float2x1 GettingStrange = float2x1(s, s);
21
22 S2 s2;
23 float2x2 GettingStrange2 = float2x2(s2, s2);
24
25 // HLSL does not yet allow user-defined conversions.
26 struct T {
27 operator float() const { return 1.0f; }
28 } t;
29 // TODO: Should this work? Today HLSL doesn't resolve user-defined conversions here, but we maybe should...
30 float2x1 foo5 = float2x1(t, t); // expected-error{{too few initializers in list for type 'float2x1' (aka 'matrix<float, 2, 1>') (expected 2 but found 0)}}
31 }