| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
|
| 4 |
#include <atomic> |
| 5 |
#include <cstdio> |
| 6 |
|
| 7 |
__attribute__ ((noinline)) long |
| 8 |
val_without_const_folding (long val) |
| 9 |
{ |
| 10 |
return val; |
| 11 |
} |
| 12 |
|
| 13 |
int |
| 14 |
main () |
| 15 |
{ |
| 16 |
int oldval = 0xaa; |
| 17 |
int newval = 0xbb; |
| 18 |
std::atomic<int> amo; |
| 19 |
|
| 20 |
amo.store (oldval); |
| 21 |
|
| 22 |
long longval = val_without_const_folding (0xff80000000000000 + oldval); |
| 23 |
oldval = static_cast<int> (longval); |
| 24 |
|
| 25 |
amo.compare_exchange_strong (oldval, newval); |
| 26 |
|
| 27 |
if (newval != amo.load (std::memory_order_relaxed)) |
| 28 |
__builtin_abort (); |
| 29 |
|
| 30 |
return 0; |
| 31 |
} |
| 32 |
|