[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / builtins-arm64-mte.c
blob1b0621f3c5e3100114efafbe9e3826fe6177207d
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>
7 #ifndef NO_MTE
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);
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);
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
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
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);
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);
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);
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
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
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);
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);
83 void get_tag1(void) {
84 // expected-error@+1 {{too few arguments to function call, expected 1, have 0}}
85 __arm_mte_get_tag();
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);
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
103 void set_tag1(void) {
104 // expected-error@+1 {{too few arguments to function call, expected 1, have 0}}
105 __arm_mte_set_tag();
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);
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);
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);
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);
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);
133 #ifdef __cplusplus
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);
138 #endif
140 #else
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);
145 #endif