brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.4 KiB · 77e3b8a Raw
115 lines · c
1// RUN: %clang_cc1 %s -fenable-matrix -pedantic -verify -triple=x86_64-apple-darwin92 3typedef float sx5x10_t __attribute__((matrix_type(5, 10)));4typedef int ix3x2_t __attribute__((matrix_type(3, 2)));5typedef double dx3x3 __attribute__((matrix_type(3, 3)));6typedef unsigned ix3x3 __attribute__((matrix_type(3, 3)));7 8// Verify that we can use the [[]] spelling of the attribute.9// We intentionally use the same type alias name to check that both versions10// define the same type.11typedef float [[clang::matrix_type(5, 10)]] sx5x10_t; // expected-warning {{[[]] attributes are a C23 extension}}12typedef int [[clang::matrix_type(3, 2)]] ix3x2_t; // expected-warning {{[[]] attributes are a C23 extension}}13[[clang::matrix_type(5, 10)]] typedef float sx5x10_t; // expected-warning {{[[]] attributes are a C23 extension}}14// expected-warning@-1 {{applying attribute 'clang::matrix_type' to a declaration is deprecated; apply it to the type instead}}15[[clang::matrix_type(3, 2)]] typedef int ix3x2_t; // expected-warning {{[[]] attributes are a C23 extension}}16// expected-warning@-1 {{applying attribute 'clang::matrix_type' to a declaration is deprecated; apply it to the type instead}}17 18// Attribute may not be used outside typedefs.19[[clang::matrix_type(3, 2)]] int ix3x2_var; // expected-warning {{[[]] attributes are a C23 extension}}20// expected-error@-1 {{'clang::matrix_type' attribute only applies to typedefs}}21int [[clang::matrix_type(3, 2)]] ix3x2_var; // expected-warning {{[[]] attributes are a C23 extension}}22// expected-error@-1 {{'clang::matrix_type' attribute only applies to typedefs}}23 24void 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}}35 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)))'}}38}39 40struct Foo {41  unsigned x;42};43 44void 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)))'}}57 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}}60 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}}63 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}}66 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}}71 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 '__size_t' (aka 'unsigned long')}}77 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 '__size_t' (aka '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 '__size_t' (aka 'unsigned long')}}83      10);84}85 86void 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}}95 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 '__size_t' (aka 'unsigned long')}}100 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);105 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'}}108 109  int x = __builtin_matrix_column_major_store(*m1, p1, 10);110  // expected-error@-1 {{initializing 'int' with an expression of incompatible type 'void'}}111 112  __builtin_matrix_column_major_store(*m1, p4, 20);113  // expected-error@-1 {{cannot store matrix to read-only pointer}}114}115