| 1 |
/* PR middle-end/99612 - Missing warning on incorrect memory order without |
| 2 |
-Wsystem-headers |
| 3 |
Verify warnings for basic atomic functions with no optimization. |
| 4 |
{ dg-do compile { target c++11 } } |
| 5 |
{ dg-options "-O0 -Wall" } */ |
| 6 |
|
| 7 |
#include <atomic> |
| 8 |
|
| 9 |
static const std::memory_order relaxed = std::memory_order_relaxed; |
| 10 |
static const std::memory_order consume = std::memory_order_consume; |
| 11 |
static const std::memory_order acquire = std::memory_order_acquire; |
| 12 |
static const std::memory_order release = std::memory_order_release; |
| 13 |
static const std::memory_order acq_rel = std::memory_order_acq_rel; |
| 14 |
static const std::memory_order seq_cst = std::memory_order_seq_cst; |
| 15 |
|
| 16 |
extern std::atomic<int> eai; |
| 17 |
|
| 18 |
void test_load (int *pi) |
| 19 |
{ |
| 20 |
*pi++ = eai.load (relaxed); |
| 21 |
*pi++ = eai.load (consume); |
| 22 |
*pi++ = eai.load (acquire); |
| 23 |
*pi++ = eai.load (release); // warning |
| 24 |
*pi++ = eai.load (acq_rel); // warning |
| 25 |
*pi++ = eai.load (seq_cst); |
| 26 |
} |
| 27 |
|
| 28 |
/* { dg-regexp " *inlined from \[^\n\r\]+.C:23:.*" "" { target *-*-* } 0 } |
| 29 |
{ dg-regexp " *inlined from \[^\n\r\]+.C:24:.*" "" { target *-*-* } 0 } |
| 30 |
{ dg-warning "__atomic_load\[^\n\r\]* \\\[-Winvalid-memory-model" "warning" { target *-*-* } 0 } */ |
| 31 |
|
| 32 |
|
| 33 |
void test_store (int *pi) |
| 34 |
{ |
| 35 |
eai.store (*pi++, relaxed); |
| 36 |
eai.store (*pi++, consume); // warning |
| 37 |
eai.store (*pi++, acquire); // warning |
| 38 |
eai.store (*pi++, release); |
| 39 |
eai.store (*pi++, acq_rel); // warning |
| 40 |
eai.store (*pi++, seq_cst); |
| 41 |
} |
| 42 |
|
| 43 |
/* { dg-regexp " *inlined from \[^\n\r\]+.C:36:.*" "" { target *-*-* } 0 } |
| 44 |
{ dg-regexp " *inlined from \[^\n\r\]+.C:37:.*" "" { target *-*-* } 0 } |
| 45 |
{ dg-regexp " *inlined from \[^\n\r\]+.C:39:.*" "" { target *-*-* } 0 } |
| 46 |
{ dg-warning "__atomic_store\[^\n\r]* \\\[-Winvalid-memory-model" "warning" { target *-*-* } 0 } */ |
| 47 |
|
| 48 |
|
| 49 |
void test_exchange (const int *pi) |
| 50 |
{ |
| 51 |
eai.exchange (*pi++, relaxed); |
| 52 |
eai.exchange (*pi++, consume); |
| 53 |
eai.exchange (*pi++, acquire); |
| 54 |
eai.exchange (*pi++, release); |
| 55 |
eai.exchange (*pi++, acq_rel); |
| 56 |
eai.exchange (*pi++, seq_cst); |
| 57 |
} |
| 58 |
|
| 59 |
/* The following tests fail because std::atomic_compare_exchange_weak_explicit |
| 60 |
is not declared with attribute always_inline (like the member functions |
| 61 |
above are). */ |
| 62 |
|
| 63 |
void test_compare_exchange (int *pi, int *pj) |
| 64 |
{ |
| 65 |
#define cmpxchg(x, y, z, o1, o2) \ |
| 66 |
std::atomic_compare_exchange_weak_explicit (x, y, z, o1, o2) |
| 67 |
|
| 68 |
cmpxchg (&eai, pi++, *pj++, relaxed, relaxed); |
| 69 |
cmpxchg (&eai, pi++, *pj++, relaxed, consume); // warning |
| 70 |
cmpxchg (&eai, pi++, *pj++, relaxed, acquire); // warning |
| 71 |
cmpxchg (&eai, pi++, *pj++, relaxed, release); // warning |
| 72 |
cmpxchg (&eai, pi++, *pj++, relaxed, acq_rel); // warning |
| 73 |
cmpxchg (&eai, pi++, *pj++, relaxed, seq_cst); // warning |
| 74 |
cmpxchg (&eai, pi++, *pj++, relaxed, relaxed); |
| 75 |
|
| 76 |
/* HACK: xfail doesn't seem to work for the dg-regexp directives below, |
| 77 |
so disable them by prepending an X to their names... |
| 78 |
{ Xdg-regexp " *inlined from \[^\n\r\]+.C:66:.*" "" { xfail *-*-* } 0 } |
| 79 |
{ Xdg-regexp " *inlined from \[^\n\r\]+.C:67:.*" "" { xfail *-*-* } 0 } |
| 80 |
{ Xdg-regexp " *inlined from \[^\n\r\]+.C:68:.*" "" { xfail *-*-* } 0 } |
| 81 |
{ Xdg-regexp " *inlined from \[^\n\r\]+.C:69:.*" "" { xfail *-*-* } 0 } |
| 82 |
{ Xdg-regexp " *inlined from \[^\n\r\]+.C:70:.*" "" { xfail *-*-* } 0 } |
| 83 |
{ dg-warning "__atomic_compare_exchange\[^\n\r\]* \\\[-Winvalid-memory-model" "cmpxchg 1" { xfail *-*-* } 0 } */ |
| 84 |
} |