1 // RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -fsyntax-only -verify
2 // RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -x c++ -fsyntax-only -verify
3 // RUN: %clang_cc1 -triple arm64-arm-eabi %s -DNO_MTE -x c++ -emit-llvm-only -verify
4 #include <stddef.h>
5 #include <arm_acle.h>
6
7 #ifndef NO_MTE
create_tag1(int a,unsigned b)8 int *create_tag1(int a, unsigned b) {
9 // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}}
10 return __arm_mte_create_random_tag(a,b);
11 }
12
create_tag2(int * a,unsigned * b)13 int *create_tag2(int *a, unsigned *b) {
14 // expected-error@+1 {{second argument of MTE builtin function must be an integer type ('unsigned int *' invalid)}}
15 return __arm_mte_create_random_tag(a,b);
16 }
17
create_tag3(const int * a,unsigned b)18 int *create_tag3(const int *a, unsigned b) {
19 #ifdef __cplusplus
20 // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const int *'}}
21 return __arm_mte_create_random_tag(a,b);
22 #else
23 // expected-warning@+1 {{returning 'const int *' from a function with result type 'int *' discards qualifiers}}
24 return __arm_mte_create_random_tag(a,b);
25 #endif
26 }
27
create_tag4(volatile int * a,unsigned b)28 int *create_tag4(volatile int *a, unsigned b) {
29 #ifdef __cplusplus
30 // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'volatile int *'}}
31 return __arm_mte_create_random_tag(a,b);
32 #else
33 // expected-warning@+1 {{returning 'volatile int *' from a function with result type 'int *' discards qualifiers}}
34 return __arm_mte_create_random_tag(a,b);
35 #endif
36 }
37
increment_tag1(int * a,unsigned b)38 int *increment_tag1(int *a, unsigned b) {
39 // expected-error@+1 {{argument to '__builtin_arm_addg' must be a constant integer}}
40 return __arm_mte_increment_tag(a,b);
41 }
42
increment_tag2(int * a)43 int *increment_tag2(int *a) {
44 // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
45 return __arm_mte_increment_tag(a,16);
46 }
47
increment_tag3(int * a)48 int *increment_tag3(int *a) {
49 // expected-error@+1 {{argument value -1 is outside the valid range [0, 15]}}
50 return __arm_mte_increment_tag(a,-1);
51 }
52
increment_tag4(const int * a)53 int *increment_tag4(const int *a) {
54 #ifdef __cplusplus
55 // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const int *'}}
56 return __arm_mte_increment_tag(a,5);
57 #else
58 // expected-warning@+1 {{returning 'const int *' from a function with result type 'int *' discards qualifiers}}
59 return __arm_mte_increment_tag(a,5);
60 #endif
61 }
62
increment_tag5(const volatile int * a)63 int *increment_tag5(const volatile int *a) {
64 #ifdef __cplusplus
65 // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const volatile int *'}}
66 return __arm_mte_increment_tag(a,5);
67 #else
68 // expected-warning@+1 {{returning 'const volatile int *' from a function with result type 'int *' discards qualifiers}}
69 return __arm_mte_increment_tag(a,5);
70 #endif
71 }
72
exclude_tag1(int * ptr,unsigned m)73 unsigned exclude_tag1(int *ptr, unsigned m) {
74 // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}}
75 return __arm_mte_exclude_tag(*ptr, m);
76 }
77
exclude_tag2(int * ptr,int * m)78 unsigned exclude_tag2(int *ptr, int *m) {
79 // expected-error@+1 {{second argument of MTE builtin function must be an integer type ('int *' invalid)}}
80 return __arm_mte_exclude_tag(ptr, m);
81 }
82
get_tag1(void)83 void get_tag1(void) {
84 // expected-error@+1 {{too few arguments to function call, expected 1, have 0}}
85 __arm_mte_get_tag();
86 }
87
get_tag2(int ptr)88 int *get_tag2(int ptr) {
89 // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}}
90 return __arm_mte_get_tag(ptr);
91 }
92
get_tag3(const volatile int * ptr)93 int *get_tag3(const volatile int *ptr) {
94 #ifdef __cplusplus
95 // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const volatile int *'}}
96 return __arm_mte_get_tag(ptr);
97 #else
98 // expected-warning@+1 {{returning 'const volatile int *' from a function with result type 'int *' discards qualifiers}}
99 return __arm_mte_get_tag(ptr);
100 #endif
101 }
102
set_tag1(void)103 void set_tag1(void) {
104 // expected-error@+1 {{too few arguments to function call, expected 1, have 0}}
105 __arm_mte_set_tag();
106 }
107
set_tag2(int ptr)108 void set_tag2(int ptr) {
109 // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}}
110 __arm_mte_set_tag(ptr);
111 }
112
subtract_pointers1(int a,int * b)113 ptrdiff_t subtract_pointers1(int a, int *b) {
114 // expected-error@+1 {{first argument of MTE builtin function must be a null or a pointer ('int' invalid)}}
115 return __arm_mte_ptrdiff(a, b);
116 }
117
subtract_pointers2(int * a,int b)118 ptrdiff_t subtract_pointers2(int *a, int b) {
119 // expected-error@+1 {{second argument of MTE builtin function must be a null or a pointer ('int' invalid)}}
120 return __arm_mte_ptrdiff(a, b);
121 }
122
subtract_pointers3(char * a,int * b)123 ptrdiff_t subtract_pointers3(char *a, int *b) {
124 // expected-error@+1 {{'char *' and 'int *' are not pointers to compatible types}}
125 return __arm_mte_ptrdiff(a, b);
126 }
127
subtract_pointers4(int * a,char * b)128 ptrdiff_t subtract_pointers4(int *a, char *b) {
129 // expected-error@+1 {{'int *' and 'char *' are not pointers to compatible types}}
130 return __arm_mte_ptrdiff(a, b);
131 }
132
133 #ifdef __cplusplus
subtract_pointers5()134 ptrdiff_t subtract_pointers5() {
135 // expected-error@+1 {{at least one argument of MTE builtin function must be a pointer ('std::nullptr_t', 'std::nullptr_t' invalid)}}
136 return __arm_mte_ptrdiff(nullptr, nullptr);
137 }
138 #endif
139
140 #else
create_tag1(int * a,unsigned b)141 int *create_tag1(int *a, unsigned b) {
142 // expected-error@+1 {{'__builtin_arm_irg' needs target feature mte}}
143 return __arm_mte_create_random_tag(a,b);
144 }
145 #endif