[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / matrix-type-builtins.c
blobd684f765aa1a57a0aa92c47d0418a7c1dff9c843
1 // RUN: %clang_cc1 %s -fenable-matrix -fdouble-square-bracket-attributes -pedantic -verify -triple=x86_64-apple-darwin9
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)));
8 // Verify that we can use the [[]] spelling of the attribute.
9 // We intentionally use the same type alias name to check that both versions
10 // define the same type.
11 typedef float [[clang::matrix_type(5, 10)]] sx5x10_t;
12 typedef int [[clang::matrix_type(3, 2)]] ix3x2_t;
13 [[clang::matrix_type(5, 10)]] typedef float sx5x10_t;
14 // expected-warning@-1 {{applying attribute 'matrix_type' to a declaration is deprecated; apply it to the type instead}}
15 [[clang::matrix_type(3, 2)]] typedef int ix3x2_t;
16 // expected-warning@-1 {{applying attribute 'matrix_type' to a declaration is deprecated; apply it to the type instead}}
18 // Attribute may not be used outside typedefs.
19 [[clang::matrix_type(3, 2)]] int ix3x2_var;
20 // expected-error@-1 {{'matrix_type' attribute only applies to typedefs}}
21 int [[clang::matrix_type(3, 2)]] ix3x2_var;
22 // expected-error@-1 {{'matrix_type' attribute only applies to typedefs}}
24 void transpose(sx5x10_t a, ix3x2_t b, dx3x3 c, int *d, int e) {
25 a = __builtin_matrix_transpose(b);
26 // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
27 b = __builtin_matrix_transpose(b);
28 // expected-error@-1 {{assigning to 'ix3x2_t' (aka 'int __attribute__((matrix_type(3, 2)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
29 __builtin_matrix_transpose(d);
30 // expected-error@-1 {{1st argument must be a matrix}}
31 __builtin_matrix_transpose(e);
32 // expected-error@-1 {{1st argument must be a matrix}}
33 __builtin_matrix_transpose("test");
34 // expected-error@-1 {{1st argument must be a matrix}}
36 ix3x3 m = __builtin_matrix_transpose(c);
37 // 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)))'}}
40 struct Foo {
41 unsigned x;
44 void column_major_load(float *p1, int *p2, _Bool *p3, struct Foo *p4) {
45 sx5x10_t a1 = __builtin_matrix_column_major_load(p1, 5, 11, 5);
46 // 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)))'}}
47 sx5x10_t a2 = __builtin_matrix_column_major_load(p1, 5, 9, 5);
48 // 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)))'}}
49 sx5x10_t a3 = __builtin_matrix_column_major_load(p1, 6, 10, 6);
50 // 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)))'}}
51 sx5x10_t a4 = __builtin_matrix_column_major_load(p1, 4, 10, 4);
52 // 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)))'}}
53 sx5x10_t a5 = __builtin_matrix_column_major_load(p1, 6, 9, 6);
54 // 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)))'}}
55 sx5x10_t a6 = __builtin_matrix_column_major_load(p2, 5, 10, 6);
56 // 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)))'}}
58 sx5x10_t a7 = __builtin_matrix_column_major_load(p1, 5, 10, 3);
59 // expected-error@-1 {{stride must be greater or equal to the number of rows}}
61 sx5x10_t a8 = __builtin_matrix_column_major_load(p3, 5, 10, 6);
62 // expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
64 sx5x10_t a9 = __builtin_matrix_column_major_load(p4, 5, 10, 6);
65 // expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
67 sx5x10_t a10 = __builtin_matrix_column_major_load(p1, 1ull << 21, 10, 6);
68 // expected-error@-1 {{row dimension is outside the allowed range [1, 1048575}}
69 sx5x10_t a11 = __builtin_matrix_column_major_load(p1, 10, 1ull << 21, 10);
70 // expected-error@-1 {{column dimension is outside the allowed range [1, 1048575}}
72 sx5x10_t a12 = __builtin_matrix_column_major_load(
73 10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
74 1ull << 21, // expected-error {{row dimension is outside the allowed range [1, 1048575]}}
75 1ull << 21, // expected-error {{column dimension is outside the allowed range [1, 1048575]}}
76 ""); // expected-error {{incompatible pointer to integer conversion casting 'char[1]' to type 'unsigned long'}}
78 sx5x10_t a13 = __builtin_matrix_column_major_load(
79 10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
80 *p4, // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
81 "", // expected-error {{column argument must be a constant unsigned integer expression}}
82 // expected-error@-1 {{incompatible pointer to integer conversion casting 'char[1]' to type 'unsigned long'}}
83 10);
86 void column_major_store(sx5x10_t *m1, ix3x2_t *m2, float *p1, int *p2, struct Foo *p3, const float *p4) {
87 __builtin_matrix_column_major_store(*m1, p1, 1);
88 // expected-error@-1 {{stride must be greater or equal to the number of rows}}
89 __builtin_matrix_column_major_store(*m1, p1, 0);
90 // expected-error@-1 {{stride must be greater or equal to the number of rows}}
91 __builtin_matrix_column_major_store(*m1, p2, 10);
92 // expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('int' != 'float')}}
93 __builtin_matrix_column_major_store(p1, p2, 10);
94 // expected-error@-1 {{1st argument must be a matrix}}
96 __builtin_matrix_column_major_store(
97 "", // expected-error {{1st argument must be a matrix}}
98 10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
99 *p3); // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
101 __builtin_matrix_column_major_store(
102 *m1,
103 10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
104 10);
106 *m1 = __builtin_matrix_column_major_store(*m1, p1, 10);
107 // expected-error@-1 {{assigning to 'sx5x10_t' (aka 'float __attribute__((matrix_type(5, 10)))') from incompatible type 'void'}}
109 int x = __builtin_matrix_column_major_store(*m1, p1, 10);
110 // expected-error@-1 {{initializing 'int' with an expression of incompatible type 'void'}}
112 __builtin_matrix_column_major_store(*m1, p4, 20);
113 // expected-error@-1 {{cannot store matrix to read-only pointer}}