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