xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/builtins-arm-exclusive.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc struct Simple {
4f4a2713aSLionel Sambuc   char a, b;
5f4a2713aSLionel Sambuc };
6f4a2713aSLionel Sambuc 
test_ldrex(char * addr)7f4a2713aSLionel Sambuc int test_ldrex(char *addr) {
8f4a2713aSLionel Sambuc   int sum = 0;
9f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex(addr);
10f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((short *)addr);
11f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((int *)addr);
12f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((long long *)addr);
13f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((float *)addr);
14f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((double *)addr);
15f4a2713aSLionel Sambuc   sum += *__builtin_arm_ldrex((int **)addr);
16f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((struct Simple **)addr)->a;
17f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((volatile char *)addr);
18f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((const volatile char *)addr);
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc   // In principle this might be valid, but stick to ints and floats for scalar
21f4a2713aSLionel Sambuc   // types at the moment.
22f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((struct Simple *)addr).a; // expected-error {{address argument to atomic builtin must be a pointer to}}
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc   sum += __builtin_arm_ldrex((__int128 *)addr); // expected-error {{__int128 is not supported on this target}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2,4 or 8 byte type}}
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc   __builtin_arm_ldrex(); // expected-error {{too few arguments to function call}}
27f4a2713aSLionel Sambuc   __builtin_arm_ldrex(1, 2); // expected-error {{too many arguments to function call}}
28f4a2713aSLionel Sambuc   return sum;
29f4a2713aSLionel Sambuc }
30f4a2713aSLionel Sambuc 
test_strex(char * addr)31f4a2713aSLionel Sambuc int test_strex(char *addr) {
32f4a2713aSLionel Sambuc   int res = 0;
33f4a2713aSLionel Sambuc   struct Simple var = {0};
34f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(4, addr);
35f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (short *)addr);
36f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (int *)addr);
37f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (long long *)addr);
38f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(2.71828f, (float *)addr);
39f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(3.14159, (double *)addr);
40f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(&var, (struct Simple **)addr);
41f4a2713aSLionel Sambuc 
42f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (volatile char *)addr);
43f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (char *const)addr);
44f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(42, (const char *)addr); // expected-warning {{passing 'const char *' to parameter of type 'volatile char *' discards qualifiers}}
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc 
47f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(var, (struct Simple *)addr); // expected-error {{address argument to atomic builtin must be a pointer to}}
48f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(var, (struct Simple **)addr); // expected-error {{passing 'struct Simple' to parameter of incompatible type 'struct Simple *'}}
49f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(&var, (struct Simple **)addr).a; // expected-error {{is not a structure or union}}
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc   res |= __builtin_arm_strex(1, (__int128 *)addr); // expected-error {{__int128 is not supported on this target}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2,4 or 8 byte type}}
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc   __builtin_arm_strex(1); // expected-error {{too few arguments to function call}}
54f4a2713aSLionel Sambuc   __builtin_arm_strex(1, 2, 3); // expected-error {{too many arguments to function call}}
55f4a2713aSLionel Sambuc   return res;
56f4a2713aSLionel Sambuc }
57f4a2713aSLionel Sambuc 
test_ldaex(char * addr)58*0a6a1f1dSLionel Sambuc int test_ldaex(char *addr) {
59*0a6a1f1dSLionel Sambuc   int sum = 0;
60*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex(addr);
61*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((short *)addr);
62*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((int *)addr);
63*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((long long *)addr);
64*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((float *)addr);
65*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((double *)addr);
66*0a6a1f1dSLionel Sambuc   sum += *__builtin_arm_ldaex((int **)addr);
67*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((struct Simple **)addr)->a;
68*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((volatile char *)addr);
69*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((const volatile char *)addr);
70*0a6a1f1dSLionel Sambuc 
71*0a6a1f1dSLionel Sambuc   // In principle this might be valid, but stick to ints and floats for scalar
72*0a6a1f1dSLionel Sambuc   // types at the moment.
73*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((struct Simple *)addr).a; // expected-error {{address argument to atomic builtin must be a pointer to}}
74*0a6a1f1dSLionel Sambuc 
75*0a6a1f1dSLionel Sambuc   sum += __builtin_arm_ldaex((__int128 *)addr); // expected-error {{__int128 is not supported on this target}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2,4 or 8 byte type}}
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc   __builtin_arm_ldaex(); // expected-error {{too few arguments to function call}}
78*0a6a1f1dSLionel Sambuc   __builtin_arm_ldaex(1, 2); // expected-error {{too many arguments to function call}}
79*0a6a1f1dSLionel Sambuc   return sum;
80*0a6a1f1dSLionel Sambuc }
81*0a6a1f1dSLionel Sambuc 
test_stlex(char * addr)82*0a6a1f1dSLionel Sambuc int test_stlex(char *addr) {
83*0a6a1f1dSLionel Sambuc   int res = 0;
84*0a6a1f1dSLionel Sambuc   struct Simple var = {0};
85*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(4, addr);
86*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (short *)addr);
87*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (int *)addr);
88*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (long long *)addr);
89*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(2.71828f, (float *)addr);
90*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(3.14159, (double *)addr);
91*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(&var, (struct Simple **)addr);
92*0a6a1f1dSLionel Sambuc 
93*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (volatile char *)addr);
94*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (char *const)addr);
95*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(42, (const char *)addr); // expected-warning {{passing 'const char *' to parameter of type 'volatile char *' discards qualifiers}}
96*0a6a1f1dSLionel Sambuc 
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(var, (struct Simple *)addr); // expected-error {{address argument to atomic builtin must be a pointer to}}
99*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(var, (struct Simple **)addr); // expected-error {{passing 'struct Simple' to parameter of incompatible type 'struct Simple *'}}
100*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(&var, (struct Simple **)addr).a; // expected-error {{is not a structure or union}}
101*0a6a1f1dSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc   res |= __builtin_arm_stlex(1, (__int128 *)addr); // expected-error {{__int128 is not supported on this target}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2,4 or 8 byte type}}
103*0a6a1f1dSLionel Sambuc 
104*0a6a1f1dSLionel Sambuc   __builtin_arm_stlex(1); // expected-error {{too few arguments to function call}}
105*0a6a1f1dSLionel Sambuc   __builtin_arm_stlex(1, 2, 3); // expected-error {{too many arguments to function call}}
106*0a6a1f1dSLionel Sambuc   return res;
107*0a6a1f1dSLionel Sambuc }
108*0a6a1f1dSLionel Sambuc 
test_clrex()109f4a2713aSLionel Sambuc void test_clrex() {
110f4a2713aSLionel Sambuc   __builtin_arm_clrex();
111f4a2713aSLionel Sambuc   __builtin_arm_clrex(1); // expected-error {{too many arguments to function call}}
112f4a2713aSLionel Sambuc }
113