1 /* PR middle-end/99612 - Missing warning on incorrect memory order without
3 Verify warnings for atomic functions with optimization.
4 { dg-do compile { target c++11 } }
5 { dg-options "-O1" } */
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;
16 extern std::atomic<int> eai;
18 void test_load (int *pi)
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);
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 } */
33 void test_store (int *pi)
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);
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 } */
49 void test_exchange (const int *pi)
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);
60 void test_compare_exchange (int *pi, int *pj)
62 #define cmpxchg(x, y, z, o1, o2) \
63 std::atomic_compare_exchange_weak_explicit (x, y, z, o1, o2)
65 cmpxchg (&eai, pi++, *pj++, relaxed, relaxed);
66 cmpxchg (&eai, pi++, *pj++, relaxed, consume); // warning
67 cmpxchg (&eai, pi++, *pj++, relaxed, acquire); // warning
68 cmpxchg (&eai, pi++, *pj++, relaxed, release); // warning
69 cmpxchg (&eai, pi++, *pj++, relaxed, acq_rel); // warning
70 cmpxchg (&eai, pi++, *pj++, relaxed, seq_cst); // warning
71 cmpxchg (&eai, pi++, *pj++, relaxed, relaxed);
73 /* { dg-regexp " *inlined from \[^\n\r\]+.C:66:.*" "" { target *-*-* } 0 }
74 { dg-regexp " *inlined from \[^\n\r\]+.C:67:.*" "" { target *-*-* } 0 }
75 { dg-regexp " *inlined from \[^\n\r\]+.C:68:.*" "" { target *-*-* } 0 }
76 { dg-regexp " *inlined from \[^\n\r\]+.C:69:.*" "" { target *-*-* } 0 }
77 { dg-regexp " *inlined from \[^\n\r\]+.C:70:.*" "" { target *-*-* } 0 }
78 { dg-warning "__atomic_compare_exchange\[^\n\r\]* \\\[-Winvalid-memory-model" "cmpxchg 1" { target *-*-* } 0 } */