brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.4 KiB · dbb3de5 Raw
172 lines · c
1// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify %s2 3// General tests of __builtin_arm_ldrex[d] and __builtin_arm_strex[d] error checking.4//5// This test is compiled for Armv7-A, which provides exclusive load/store6// instructions for 1-, 2-, 4- and 8-byte quantities. Other Arm architecture7// versions provide subsets of those, requiring different error reporting.8// Those are tested in builtins-arm-exclusive-124.c, builtins-arm-exclusive-4.c9// and builtins-arm-exclusive-none.c.10 11struct Simple {12  char a, b;13};14 15int test_ldrex(char *addr) {16  int sum = 0;17  sum += __builtin_arm_ldrex(addr);18  sum += __builtin_arm_ldrex((short *)addr);19  sum += __builtin_arm_ldrex((int *)addr);20  sum += __builtin_arm_ldrex((long long *)addr);21  sum += __builtin_arm_ldrex((float *)addr);22  sum += __builtin_arm_ldrex((double *)addr);23  sum += *__builtin_arm_ldrex((int **)addr);24  sum += __builtin_arm_ldrex((struct Simple **)addr)->a;25  sum += __builtin_arm_ldrex((volatile char *)addr);26  sum += __builtin_arm_ldrex((const volatile char *)addr);27 28  // In principle this might be valid, but stick to ints and floats for scalar29  // types at the moment.30  sum += __builtin_arm_ldrex((struct Simple *)addr).a; // expected-error {{address argument to atomic builtin must be a pointer to}}31 32  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}}33 34  __builtin_arm_ldrex(); // expected-error {{too few arguments to function call}}35  __builtin_arm_ldrex(1, 2); // expected-error {{too many arguments to function call}}36  return sum;37}38 39int test_strex(char *addr) {40  int res = 0;41  struct Simple var = {0};42  res |= __builtin_arm_strex(4, addr);43  res |= __builtin_arm_strex(42, (short *)addr);44  res |= __builtin_arm_strex(42, (int *)addr);45  res |= __builtin_arm_strex(42, (long long *)addr);46  res |= __builtin_arm_strex(2.71828f, (float *)addr);47  res |= __builtin_arm_strex(3.14159, (double *)addr);48  res |= __builtin_arm_strex(&var, (struct Simple **)addr);49 50  res |= __builtin_arm_strex(42, (volatile char *)addr);51  res |= __builtin_arm_strex(42, (char *const)addr);52  res |= __builtin_arm_strex(42, (const char *)addr); // expected-warning {{passing 'const char *' to parameter of type 'volatile char *' discards qualifiers}}53 54 55  res |= __builtin_arm_strex(var, (struct Simple *)addr); // expected-error {{address argument to atomic builtin must be a pointer to}}56  res |= __builtin_arm_strex(var, (struct Simple **)addr); // expected-error {{passing 'struct Simple' to parameter of incompatible type 'struct Simple *'}}57  res |= __builtin_arm_strex(&var, (struct Simple **)addr).a; // expected-error {{is not a structure or union}}58 59  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}}60 61  __builtin_arm_strex(1); // expected-error {{too few arguments to function call}}62  __builtin_arm_strex(1, 2, 3); // expected-error {{too many arguments to function call}}63  return res;64}65 66int test_ldrexd(char *addr) {67  int sum = 0;68  sum += __builtin_arm_ldrexd(addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}69  sum += __builtin_arm_ldrexd((short *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}70  sum += __builtin_arm_ldrexd((int *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}71  sum += __builtin_arm_ldrexd((long long *)addr);72  sum += __builtin_arm_ldrexd((float *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}73  sum += __builtin_arm_ldrexd((double *)addr);74  sum += *__builtin_arm_ldrexd((int **)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}75  sum += __builtin_arm_ldrexd((struct Simple **)addr)->a; // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}76  sum += __builtin_arm_ldrexd((volatile char *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}77  sum += __builtin_arm_ldrexd((const volatile char *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}78 79  // In principle this might be valid, but stick to ints and floats for scalar80  // types at the moment.81  sum += __builtin_arm_ldrexd((struct Simple *)addr).a; // expected-error {{address argument to atomic builtin must be a pointer to}}82 83  sum += __builtin_arm_ldrexd((__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 8 byte type}}84 85  __builtin_arm_ldrexd(); // expected-error {{too few arguments to function call}}86  __builtin_arm_ldrexd(1, 2); // expected-error {{too many arguments to function call}}87  return sum;88}89 90int test_strexd(char *addr) {91  int res = 0;92  struct Simple var = {0};93  res |= __builtin_arm_strexd(4, addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}94  res |= __builtin_arm_strexd(42, (short *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}95  res |= __builtin_arm_strexd(42, (int *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}96  res |= __builtin_arm_strexd(42, (long long *)addr);97  res |= __builtin_arm_strexd(2.71828f, (float *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}98  res |= __builtin_arm_strexd(3.14159, (double *)addr);99  res |= __builtin_arm_strexd(&var, (struct Simple **)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}100 101  res |= __builtin_arm_strexd(42, (volatile char *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}102  res |= __builtin_arm_strexd(42, (char *const)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}103  res |= __builtin_arm_strexd(42, (const char *)addr); // expected-warning {{passing 'const char *' to parameter of type 'volatile char *' discards qualifiers}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}104 105 106  res |= __builtin_arm_strexd(var, (struct Simple *)addr); // expected-error {{address argument to atomic builtin must be a pointer to}}107  res |= __builtin_arm_strexd(var, (struct Simple **)addr); // expected-error {{passing 'struct Simple' to parameter of incompatible type 'struct Simple *'}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}108  res |= __builtin_arm_strexd(&var, (struct Simple **)addr).a; // expected-error {{is not a structure or union}} expected-error {{address argument to load or store exclusive builtin must be a pointer to 8 byte type}}109 110  res |= __builtin_arm_strexd(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 8 byte type}}111 112  __builtin_arm_strexd(1); // expected-error {{too few arguments to function call}}113  __builtin_arm_strexd(1, 2, 3); // expected-error {{too many arguments to function call}}114  return res;115}116 117int test_ldaex(char *addr) {118  int sum = 0;119  sum += __builtin_arm_ldaex(addr);120  sum += __builtin_arm_ldaex((short *)addr);121  sum += __builtin_arm_ldaex((int *)addr);122  sum += __builtin_arm_ldaex((long long *)addr);123  sum += __builtin_arm_ldaex((float *)addr);124  sum += __builtin_arm_ldaex((double *)addr);125  sum += *__builtin_arm_ldaex((int **)addr);126  sum += __builtin_arm_ldaex((struct Simple **)addr)->a;127  sum += __builtin_arm_ldaex((volatile char *)addr);128  sum += __builtin_arm_ldaex((const volatile char *)addr);129 130  // In principle this might be valid, but stick to ints and floats for scalar131  // types at the moment.132  sum += __builtin_arm_ldaex((struct Simple *)addr).a; // expected-error {{address argument to atomic builtin must be a pointer to}}133 134  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}}135 136  __builtin_arm_ldaex(); // expected-error {{too few arguments to function call}}137  __builtin_arm_ldaex(1, 2); // expected-error {{too many arguments to function call}}138  return sum;139}140 141int test_stlex(char *addr) {142  int res = 0;143  struct Simple var = {0};144  res |= __builtin_arm_stlex(4, addr);145  res |= __builtin_arm_stlex(42, (short *)addr);146  res |= __builtin_arm_stlex(42, (int *)addr);147  res |= __builtin_arm_stlex(42, (long long *)addr);148  res |= __builtin_arm_stlex(2.71828f, (float *)addr);149  res |= __builtin_arm_stlex(3.14159, (double *)addr);150  res |= __builtin_arm_stlex(&var, (struct Simple **)addr);151 152  res |= __builtin_arm_stlex(42, (volatile char *)addr);153  res |= __builtin_arm_stlex(42, (char *const)addr);154  res |= __builtin_arm_stlex(42, (const char *)addr); // expected-warning {{passing 'const char *' to parameter of type 'volatile char *' discards qualifiers}}155 156 157  res |= __builtin_arm_stlex(var, (struct Simple *)addr); // expected-error {{address argument to atomic builtin must be a pointer to}}158  res |= __builtin_arm_stlex(var, (struct Simple **)addr); // expected-error {{passing 'struct Simple' to parameter of incompatible type 'struct Simple *'}}159  res |= __builtin_arm_stlex(&var, (struct Simple **)addr).a; // expected-error {{is not a structure or union}}160 161  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}}162 163  __builtin_arm_stlex(1); // expected-error {{too few arguments to function call}}164  __builtin_arm_stlex(1, 2, 3); // expected-error {{too many arguments to function call}}165  return res;166}167 168void test_clrex(void) {169  __builtin_arm_clrex();170  __builtin_arm_clrex(1); // expected-error {{too many arguments to function call}}171}172