| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-additional-options "-DSYNC_FALLBACK" { target { ! cas_int } } } */ |
| 3 |
|
| 4 |
#ifdef SYNC_FALLBACK |
| 5 |
/* The SYNC_FALLBACK code is just so we don't have to restrict this test |
| 6 |
to any subset of targets. For targets with no atomics support at |
| 7 |
all, the cas_int effective-target is false and the fallback provides |
| 8 |
a PASS. Where the bug trigs (at the time this test-case was added), |
| 9 |
cas_int is also false but the fallback isn't used. */ |
| 10 |
__attribute__((__noinline__, __noclone__)) |
| 11 |
unsigned |
| 12 |
# if __INT_MAX__ == 0x7fff |
| 13 |
__sync_fetch_and_add_2 |
| 14 |
# else |
| 15 |
__sync_fetch_and_add_4 |
| 16 |
# endif |
| 17 |
(volatile void *at, unsigned val) |
| 18 |
{ |
| 19 |
unsigned tmp = *(volatile unsigned*)at; |
| 20 |
asm (""); |
| 21 |
*(volatile unsigned*)at = tmp + val; |
| 22 |
return tmp; |
| 23 |
} |
| 24 |
#endif |
| 25 |
|
| 26 |
__attribute__((__noinline__, __noclone__)) |
| 27 |
void g (unsigned *at, unsigned val) |
| 28 |
{ |
| 29 |
asm (""); |
| 30 |
__sync_fetch_and_add (at, val); |
| 31 |
} |
| 32 |
|
| 33 |
int main(void) |
| 34 |
{ |
| 35 |
/* On PTX it is not valid to perform atomic operations on auto |
| 36 |
variables, which end up in .local. Making this static places it |
| 37 |
in .global. */ |
| 38 |
static unsigned x = 41; |
| 39 |
unsigned a = 1; |
| 40 |
g (&x, a); |
| 41 |
|
| 42 |
if (x != 42) |
| 43 |
__builtin_abort (); |
| 44 |
__builtin_exit (0); |
| 45 |
} |