1 // RUN: %clang_cc1 %s -fenable-matrix -pedantic -verify -triple=x86_64-apple-darwin9
2 
3 typedef float sx5x10_t __attribute__((matrix_type(5, 10)));
4 typedef int ix3x2_t __attribute__((matrix_type(3, 2)));
5 typedef double dx3x3 __attribute__((matrix_type(3, 3)));
6 typedef unsigned ix3x3 __attribute__((matrix_type(3, 3)));
7 
transpose(sx5x10_t a,ix3x2_t b,dx3x3 c,int * d,int e)8 void transpose(sx5x10_t a, ix3x2_t b, dx3x3 c, int *d, int e) {
9   a = __builtin_matrix_transpose(b);
10   // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
11   b = __builtin_matrix_transpose(b);
12   // expected-error@-1 {{assigning to 'ix3x2_t' (aka 'int __attribute__((matrix_type(3, 2)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
13   __builtin_matrix_transpose(d);
14   // expected-error@-1 {{1st argument must be a matrix}}
15   __builtin_matrix_transpose(e);
16   // expected-error@-1 {{1st argument must be a matrix}}
17   __builtin_matrix_transpose("test");
18   // expected-error@-1 {{1st argument must be a matrix}}
19 
20   ix3x3 m = __builtin_matrix_transpose(c);
21   // expected-error@-1 {{initializing 'ix3x3' (aka 'unsigned int __attribute__((matrix_type(3, 3)))') with an expression of incompatible type 'double __attribute__((matrix_type(3, 3)))'}}
22 }
23 
24 struct Foo {
25   unsigned x;
26 };
27 
column_major_load(float * p1,int * p2,_Bool * p3,struct Foo * p4)28 void column_major_load(float *p1, int *p2, _Bool *p3, struct Foo *p4) {
29   sx5x10_t a1 = __builtin_matrix_column_major_load(p1, 5, 11, 5);
30   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'float __attribute__((matrix_type(5, 11)))'}}
31   sx5x10_t a2 = __builtin_matrix_column_major_load(p1, 5, 9, 5);
32   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'float __attribute__((matrix_type(5, 9)))'}}
33   sx5x10_t a3 = __builtin_matrix_column_major_load(p1, 6, 10, 6);
34   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'float __attribute__((matrix_type(6, 10)))'}}
35   sx5x10_t a4 = __builtin_matrix_column_major_load(p1, 4, 10, 4);
36   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'float __attribute__((matrix_type(4, 10)))'}}
37   sx5x10_t a5 = __builtin_matrix_column_major_load(p1, 6, 9, 6);
38   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'float __attribute__((matrix_type(6, 9)))'}}
39   sx5x10_t a6 = __builtin_matrix_column_major_load(p2, 5, 10, 6);
40   // expected-error@-1 {{initializing 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') with an expression of incompatible type 'int __attribute__((matrix_type(5, 10)))'}}
41 
42   sx5x10_t a7 = __builtin_matrix_column_major_load(p1, 5, 10, 3);
43   // expected-error@-1 {{stride must be greater or equal to the number of rows}}
44 
45   sx5x10_t a8 = __builtin_matrix_column_major_load(p3, 5, 10, 6);
46   // expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
47 
48   sx5x10_t a9 = __builtin_matrix_column_major_load(p4, 5, 10, 6);
49   // expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
50 
51   sx5x10_t a10 = __builtin_matrix_column_major_load(p1, 1ull << 21, 10, 6);
52   // expected-error@-1 {{row dimension is outside the allowed range [1, 1048575}}
53   sx5x10_t a11 = __builtin_matrix_column_major_load(p1, 10, 1ull << 21, 10);
54   // expected-error@-1 {{column dimension is outside the allowed range [1, 1048575}}
55 
56   sx5x10_t a12 = __builtin_matrix_column_major_load(
57       10,         // expected-error {{1st argument must be a pointer to a valid matrix element type}}
58       1ull << 21, // expected-error {{row dimension is outside the allowed range [1, 1048575]}}
59       1ull << 21, // expected-error {{column dimension is outside the allowed range [1, 1048575]}}
60       "");        // expected-warning {{incompatible pointer to integer conversion casting 'char [1]' to type 'unsigned long'}}
61 
62   sx5x10_t a13 = __builtin_matrix_column_major_load(
63       10,  // expected-error {{1st argument must be a pointer to a valid matrix element type}}
64       *p4, // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
65       "",  // expected-error {{column argument must be a constant unsigned integer expression}}
66            // expected-warning@-1 {{incompatible pointer to integer conversion casting 'char [1]' to type 'unsigned long'}}
67       10);
68 }
69 
column_major_store(sx5x10_t * m1,ix3x2_t * m2,float * p1,int * p2,struct Foo * p3,const float * p4)70 void column_major_store(sx5x10_t *m1, ix3x2_t *m2, float *p1, int *p2, struct Foo *p3, const float *p4) {
71   __builtin_matrix_column_major_store(*m1, p1, 1);
72   // expected-error@-1 {{stride must be greater or equal to the number of rows}}
73   __builtin_matrix_column_major_store(*m1, p1, 0);
74   // expected-error@-1 {{stride must be greater or equal to the number of rows}}
75   __builtin_matrix_column_major_store(*m1, p2, 10);
76   // expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('int' != 'float')}}
77   __builtin_matrix_column_major_store(p1, p2, 10);
78   // expected-error@-1 {{1st argument must be a matrix}}
79 
80   __builtin_matrix_column_major_store(
81       "",   // expected-error {{1st argument must be a matrix}}
82       10,   // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
83       *p3); // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
84 
85   __builtin_matrix_column_major_store(
86       *m1,
87       10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
88       10);
89 
90   *m1 = __builtin_matrix_column_major_store(*m1, p1, 10);
91   // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'void'}}
92 
93   int x = __builtin_matrix_column_major_store(*m1, p1, 10);
94   // expected-error@-1 {{initializing 'int' with an expression of incompatible type 'void'}}
95 
96   __builtin_matrix_column_major_store(*m1, p4, 20);
97   // expected-error@-1 {{cannot store matrix to read-only pointer}}
98 }
99