| 1 |
/* { dg-do run { target { stdint_types } } } */ |
| 2 |
|
| 3 |
#include <stdint.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
void f(uint64_t *a, uint64_t aa) __attribute__((noinline)); |
| 7 |
void f(uint64_t *a, uint64_t aa) |
| 8 |
{ |
| 9 |
uint64_t new_value = aa; |
| 10 |
uint64_t old_value = *a; |
| 11 |
int bit_size = 32; |
| 12 |
uint64_t mask = (uint64_t)(unsigned)(-1); |
| 13 |
uint64_t tmp = old_value & mask; |
| 14 |
new_value &= mask; |
| 15 |
/* On overflow we need to add 1 in the upper bits */ |
| 16 |
if (tmp > new_value) |
| 17 |
new_value += 1ull<<bit_size; |
| 18 |
/* Add in the upper bits from the old value */ |
| 19 |
new_value += old_value & ~mask; |
| 20 |
*a = new_value; |
| 21 |
} |
| 22 |
int main(void) |
| 23 |
{ |
| 24 |
uint64_t value, new_value, old_value; |
| 25 |
value = 0x100000001; |
| 26 |
old_value = value; |
| 27 |
new_value = (value+1)&(uint64_t)(unsigned)(-1); |
| 28 |
f(&value, new_value); |
| 29 |
if (value != old_value+1) |
| 30 |
__builtin_abort (); |
| 31 |
return 0; |
| 32 |
} |