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 float sx10x5_t __attribute__((matrix_type(10, 5)));
5 typedef float sx10x10_t __attribute__((matrix_type(10, 10)));
6 
add(sx10x10_t a,sx5x10_t b,sx10x5_t c)7 void add(sx10x10_t a, sx5x10_t b, sx10x5_t c) {
8   a = b + c;
9   // expected-error@-1 {{invalid operands to binary expression ('sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') and 'sx10x5_t' (aka 'float __attribute__((matrix_type(10, 5)))'))}}
10 
11   a = b + b; // expected-error {{assigning to 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') from incompatible type 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))')}}
12 
13   a = 10 + b;
14   // expected-error@-1 {{assigning to 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') from incompatible type 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))')}}
15 
16   a = b + &c;
17   // expected-error@-1 {{invalid operands to binary expression ('sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') and 'sx10x5_t *' (aka 'float  __attribute__((matrix_type(10, 5)))*'))}}
18   // expected-error@-2 {{casting 'sx10x5_t *' (aka 'float  __attribute__((matrix_type(10, 5)))*') to incompatible type 'float'}}
19 }
20 
sub(sx10x10_t a,sx5x10_t b,sx10x5_t c)21 void sub(sx10x10_t a, sx5x10_t b, sx10x5_t c) {
22   a = b - c;
23   // expected-error@-1 {{invalid operands to binary expression ('sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') and 'sx10x5_t' (aka 'float __attribute__((matrix_type(10, 5)))'))}}
24 
25   a = b - b; // expected-error {{assigning to 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') from incompatible type 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))')}}
26 
27   a = 10 - b;
28   // expected-error@-1 {{assigning to 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') from incompatible type 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))')}}
29 
30   a = b - &c;
31   // expected-error@-1 {{invalid operands to binary expression ('sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') and 'sx10x5_t *' (aka 'float  __attribute__((matrix_type(10, 5)))*'))}}
32   // expected-error@-2 {{casting 'sx10x5_t *' (aka 'float  __attribute__((matrix_type(10, 5)))*') to incompatible type 'float'}}
33 }
34 
35 typedef int ix10x5_t __attribute__((matrix_type(10, 5)));
36 typedef int ix10x10_t __attribute__((matrix_type(10, 10)));
37 
matrix_matrix_multiply(sx10x10_t a,sx5x10_t b,ix10x5_t c,ix10x10_t d,float sf,char * p)38 void matrix_matrix_multiply(sx10x10_t a, sx5x10_t b, ix10x5_t c, ix10x10_t d, float sf, char *p) {
39   // Check dimension mismatches.
40   a = a * b;
41   // expected-error@-1 {{invalid operands to binary expression ('sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') and 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))'))}}
42   b = a * a;
43   // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'float __attribute__((matrix_type(10, 10)))'}}
44 
45   // Check element type mismatches.
46   a = b * c;
47   // expected-error@-1 {{invalid operands to binary expression ('sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') and 'ix10x5_t' (aka 'int __attribute__((matrix_type(10, 5)))'))}}
48   d = a * a;
49   // expected-error@-1 {{assigning to 'ix10x10_t' (aka 'int __attribute__((matrix_type(10, 10)))') from incompatible type 'float __attribute__((matrix_type(10, 10)))'}}
50 
51   p = a * a;
52   // expected-error@-1 {{assigning to 'char *' from incompatible type 'float __attribute__((matrix_type(10, 10)))'}}
53 }
54 
mat_scalar_multiply(sx10x10_t a,sx5x10_t b,float sf,char * p)55 void mat_scalar_multiply(sx10x10_t a, sx5x10_t b, float sf, char *p) {
56   // Shape of multiplication result does not match the type of b.
57   b = a * sf;
58   // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))')}}
59   b = sf * a;
60   // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))')}}
61 
62   a = a * p;
63   // expected-error@-1 {{casting 'char *' to incompatible type 'float'}}
64   // expected-error@-2 {{invalid operands to binary expression ('sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))') and 'char *')}}
65   a = p * a;
66   // expected-error@-1 {{casting 'char *' to incompatible type 'float'}}
67   // expected-error@-2 {{invalid operands to binary expression ('char *' and 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))'))}}
68 
69   sf = a * sf;
70   // expected-error@-1 {{assigning to 'float' from incompatible type 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10)))')}}
71 }
72 
73 sx5x10_t get_matrix();
74 
insert(sx5x10_t a,float f)75 void insert(sx5x10_t a, float f) {
76   // Non integer indexes.
77   a[3][f] = 0;
78   // expected-error@-1 {{matrix column index is not an integer}}
79   a[f][9] = 0;
80   // expected-error@-1 {{matrix row index is not an integer}}
81   a[f][f] = 0;
82   // expected-error@-1 {{matrix row index is not an integer}}
83   // expected-error@-2 {{matrix column index is not an integer}}
84   a[0][f] = 0;
85   // expected-error@-1 {{matrix column index is not an integer}}
86 
87   a[f][f] = 0;
88   // expected-error@-1 {{matrix row index is not an integer}}
89   // expected-error@-2 {{matrix column index is not an integer}}
90 
91   // Invalid element type.
92   a[3][4] = &f;
93   // expected-error@-1 {{assigning to 'float' from incompatible type 'float *'; remove &}}
94 
95   // Indexes outside allowed dimensions.
96   a[-1][3] = 10.0;
97   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
98   a[3][-1] = 10.0;
99   // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
100   a[3][-1u] = 10.0;
101   // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
102   a[-1u][3] = 10.0;
103   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
104   a[5][2] = 10.0;
105   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
106   a[4][10] = 10.0;
107   // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
108   a[5][0] = f;
109   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
110   (a[1])[1] = f;
111   // expected-error@-1 {{matrix row and column subscripts cannot be separated by any expression}}
112 
113   a[3] = 5.0;
114   // expected-error@-1 {{single subscript expressions are not allowed for matrix values}}
115 
116   (a[3]) = 5.0;
117   // expected-error@-1 {{single subscript expressions are not allowed for matrix values}}
118 
119   get_matrix()[0][0] = f;
120   // expected-error@-1 {{expression is not assignable}}
121   get_matrix()[5][1] = f;
122   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
123   get_matrix()[3] = 5.0;
124   // expected-error@-1 {{single subscript expressions are not allowed for matrix values}}
125 
126   (get_matrix()[5])[10.0] = f;
127   // expected-error@-1 {{matrix row and column subscripts cannot be separated by any expression}}
128   (get_matrix()[3]) = 5.0;
129   // expected-error@-1 {{single subscript expressions are not allowed for matrix values}}
130 
131   a([0])[0] = f;
132   // expected-error@-1 {{expected expression}}
133   a[0]([0]) = f;
134   // expected-error@-1 {{expected expression}}
135 }
136 
extract(sx5x10_t a,float f)137 void extract(sx5x10_t a, float f) {
138   // Non integer indexes.
139   float v1 = a[3][f];
140   // expected-error@-1 {{matrix column index is not an integer}}
141   float v2 = a[f][9];
142   // expected-error@-1 {{matrix row index is not an integer}}
143   float v3 = a[f][f];
144   // expected-error@-1 {{matrix row index is not an integer}}
145   // expected-error@-2 {{matrix column index is not an integer}}
146 
147   // Invalid element type.
148   char *v4 = a[3][4];
149   // expected-error@-1 {{initializing 'char *' with an expression of incompatible type 'float'}}
150 
151   // Indexes outside allowed dimensions.
152   float v5 = a[-1][3];
153   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
154   float v6 = a[3][-1];
155   // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
156   float v8 = a[-1u][3];
157   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
158   float v9 = a[5][2];
159   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
160   float v10 = a[4][10];
161   // expected-error@-1 {{matrix column index is outside the allowed range [0, 10)}}
162   float v11 = a[5][9];
163   // expected-error@-1 {{matrix row index is outside the allowed range [0, 5)}}
164 
165   float v12 = a[3];
166   // expected-error@-1 {{single subscript expressions are not allowed for matrix values}}
167 }
168 
address_of_element(sx5x10_t * a)169 float *address_of_element(sx5x10_t *a) {
170   return &(*a)[0][1];
171   // expected-error@-1 {{address of matrix element requested}}
172 }
173