1 // RUN: %clang_cc1 %s -verify -fsyntax-only 2 // RUN: %clang_cc1 %s -verify=off -fsyntax-only -Wno-atomic-access 3 // off-no-diagnostics 4 5 _Atomic(unsigned int) data1; 6 int _Atomic data2; 7 8 // Shift operations 9 func_01(int x)10int func_01 (int x) { 11 return data1 << x; 12 } 13 func_02(int x)14int func_02 (int x) { 15 return x << data1; 16 } 17 func_03(int x)18int func_03 (int x) { 19 return data2 << x; 20 } 21 func_04(int x)22int func_04 (int x) { 23 return x << data2; 24 } 25 func_05(void)26int func_05 (void) { 27 return data2 << data1; 28 } 29 func_06(void)30int func_06 (void) { 31 return data1 << data2; 32 } 33 func_07(int x)34void func_07 (int x) { 35 data1 <<= x; 36 } 37 func_08(int x)38void func_08 (int x) { 39 data2 <<= x; 40 } 41 func_09(int * xp)42void func_09 (int* xp) { 43 *xp <<= data1; 44 } 45 func_10(int * xp)46void func_10 (int* xp) { 47 *xp <<= data2; 48 } 49 func_11(int x)50int func_11 (int x) { 51 return data1 == x; 52 } 53 func_12(void)54int func_12 (void) { 55 return data1 < data2; 56 } 57 func_13(int x,unsigned y)58int func_13 (int x, unsigned y) { 59 return x ? data1 : y; 60 } 61 func_14(void)62int func_14 (void) { 63 return data1 == 0; 64 } 65 func_15(void)66void func_15(void) { 67 // Ensure that the result of an assignment expression properly strips the 68 // _Atomic qualifier; Issue 48742. 69 _Atomic int x; 70 int y = (x = 2); 71 int z = (int)(x = 2); 72 y = (x = 2); 73 z = (int)(x = 2); 74 y = (x += 2); 75 76 _Static_assert(__builtin_types_compatible_p(__typeof__(x = 2), int), "incorrect"); 77 _Static_assert(__builtin_types_compatible_p(__typeof__(x += 2), int), "incorrect"); 78 } 79 80 // Ensure that member access of an atomic structure or union type is properly 81 // diagnosed as being undefined behavior; Issue 54563. func_16(void)82void func_16(void) { 83 // LHS member access. 84 _Atomic struct { int val; } x, *xp; 85 x.val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 86 xp->val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 87 88 _Atomic union { 89 int ival; 90 float fval; 91 } y, *yp; 92 y.ival = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 93 yp->fval = 1.2f; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 94 95 // RHS member access. 96 int xval = x.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 97 xval = xp->val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 98 int yval = y.ival; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 99 yval = yp->ival; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 100 101 // Using the type specifier instead of the type qualifier. 102 _Atomic(struct { int val; }) z; 103 z.val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 104 int zval = z.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}} 105 106 // Don't diagnose in an unevaluated context, however. 107 (void)sizeof(x.val); 108 (void)sizeof(xp->val); 109 (void)sizeof(y.ival); 110 (void)sizeof(yp->ival); 111 } 112