| 1 |
// Validate that the __sync builtins are overloaded properly in templates. |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-options "-Werror" } |
| 4 |
|
| 5 |
|
| 6 |
#define TEST1(BUILTIN) \ |
| 7 |
template<typename T> \ |
| 8 |
void f##BUILTIN(T *p) \ |
| 9 |
{ \ |
| 10 |
__typeof(BUILTIN(p, 1)) *pp; \ |
| 11 |
pp = p; \ |
| 12 |
} |
| 13 |
|
| 14 |
TEST1(__sync_fetch_and_add) |
| 15 |
TEST1(__sync_fetch_and_sub) |
| 16 |
TEST1(__sync_fetch_and_or) |
| 17 |
TEST1(__sync_fetch_and_and) |
| 18 |
TEST1(__sync_fetch_and_xor) |
| 19 |
TEST1(__sync_fetch_and_nand) |
| 20 |
|
| 21 |
TEST1(__sync_add_and_fetch) |
| 22 |
TEST1(__sync_sub_and_fetch) |
| 23 |
TEST1(__sync_or_and_fetch) |
| 24 |
TEST1(__sync_and_and_fetch) |
| 25 |
TEST1(__sync_xor_and_fetch) |
| 26 |
TEST1(__sync_nand_and_fetch) |
| 27 |
|
| 28 |
TEST1(__sync_lock_test_and_set) |
| 29 |
|
| 30 |
template<typename T> |
| 31 |
void f__sync_val_compare_and_swap(T *p) |
| 32 |
{ |
| 33 |
__typeof(__sync_val_compare_and_swap(p, 1, 2)) *pp; |
| 34 |
pp = p; |
| 35 |
} |
| 36 |
|
| 37 |
#define TEST2(TYPE) \ |
| 38 |
void h_##TYPE () \ |
| 39 |
{ \ |
| 40 |
TYPE x; \ |
| 41 |
f__sync_fetch_and_add (&x); \ |
| 42 |
f__sync_fetch_and_sub (&x); \ |
| 43 |
f__sync_fetch_and_or (&x); \ |
| 44 |
f__sync_fetch_and_and (&x); \ |
| 45 |
f__sync_fetch_and_xor (&x); \ |
| 46 |
f__sync_fetch_and_nand (&x); \ |
| 47 |
f__sync_add_and_fetch (&x); \ |
| 48 |
f__sync_sub_and_fetch (&x); \ |
| 49 |
f__sync_or_and_fetch (&x); \ |
| 50 |
f__sync_and_and_fetch (&x); \ |
| 51 |
f__sync_xor_and_fetch (&x); \ |
| 52 |
f__sync_nand_and_fetch (&x); \ |
| 53 |
f__sync_lock_test_and_set (&x); \ |
| 54 |
f__sync_val_compare_and_swap (&x); \ |
| 55 |
} |
| 56 |
|
| 57 |
TEST2(int) |
| 58 |
TEST2(long) |