| 1 |
/* { dg-do run { target hppa*-*-hpux* *-*-linux* *-*-gnu* powerpc*-*-darwin* *-*-darwin[912]* *-*-uclinux* } } */ |
| 2 |
/* FIXME The following additional option should be removed after the fix for radr://19802258. |
| 3 |
/* { dg-xfail-run-if "PR60563 radr://19802258" { *-*-darwin* } } */ |
| 4 |
/* { dg-require-effective-target sync_long_long_runtime } */ |
| 5 |
/* { dg-options "-fexceptions -fnon-call-exceptions -O2" } */ |
| 6 |
/* { dg-additional-options "-march=pentium" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */ |
| 7 |
|
| 8 |
/* Verify that the builtin functions are correctly marked as trapping |
| 9 |
when using -fnon-call-exceptions. */ |
| 10 |
|
| 11 |
#include <stdlib.h> |
| 12 |
#include <signal.h> |
| 13 |
|
| 14 |
typedef int ditype __attribute__ ((mode (DI))); |
| 15 |
|
| 16 |
#define FN(IDX, RET, CALL) \ |
| 17 |
static RET f ## IDX (void *p) __attribute__ ((noinline)); \ |
| 18 |
static RET \ |
| 19 |
f ## IDX (void *p) \ |
| 20 |
{ \ |
| 21 |
return CALL; \ |
| 22 |
} \ |
| 23 |
static void \ |
| 24 |
t ## IDX () \ |
| 25 |
{ \ |
| 26 |
try \ |
| 27 |
{ \ |
| 28 |
f ## IDX(0); \ |
| 29 |
} \ |
| 30 |
catch (...) \ |
| 31 |
{ \ |
| 32 |
return; \ |
| 33 |
} \ |
| 34 |
abort(); \ |
| 35 |
} |
| 36 |
|
| 37 |
FN(1, ditype, (__sync_fetch_and_add((ditype*)p, 1))) |
| 38 |
FN(2, ditype, (__sync_fetch_and_sub((ditype*)p, 1))) |
| 39 |
FN(3, ditype, (__sync_fetch_and_or((ditype*)p, 1))) |
| 40 |
FN(4, ditype, (__sync_fetch_and_and((ditype*)p, 1))) |
| 41 |
FN(5, ditype, (__sync_fetch_and_xor((ditype*)p, 1))) |
| 42 |
FN(6, ditype, (__sync_fetch_and_nand((ditype*)p, 1))) |
| 43 |
|
| 44 |
FN( 7, ditype, (__sync_add_and_fetch((ditype*)p, 1))) |
| 45 |
FN( 8, ditype, (__sync_sub_and_fetch((ditype*)p, 1))) |
| 46 |
FN( 9, ditype, (__sync_or_and_fetch((ditype*)p, 1))) |
| 47 |
FN(10, ditype, (__sync_and_and_fetch((ditype*)p, 1))) |
| 48 |
FN(11, ditype, (__sync_xor_and_fetch((ditype*)p, 1))) |
| 49 |
FN(12, ditype, (__sync_nand_and_fetch((ditype*)p, 1))) |
| 50 |
|
| 51 |
FN(13, bool, (__sync_bool_compare_and_swap((ditype*)p, 1, 2))) |
| 52 |
FN(14, ditype, (__sync_val_compare_and_swap((ditype*)p, 1, 2))) |
| 53 |
|
| 54 |
FN(15, ditype, (__sync_lock_test_and_set((ditype*)p, 1))) |
| 55 |
FN(16, void, (__sync_lock_release((ditype*)p))) |
| 56 |
|
| 57 |
FN(17, bool, (__atomic_test_and_set((ditype*)p, __ATOMIC_SEQ_CST))) |
| 58 |
FN(18, void, (__atomic_clear((ditype*)p, __ATOMIC_SEQ_CST))) |
| 59 |
|
| 60 |
FN(19, void, (__atomic_exchange((ditype*)p, (ditype*)0, (ditype*)0, __ATOMIC_SEQ_CST))) |
| 61 |
FN(20, ditype, (__atomic_exchange_n((ditype*)p, 1, 2))) |
| 62 |
|
| 63 |
FN(21, void, (__atomic_load((ditype*)p, (ditype*)0, __ATOMIC_SEQ_CST))) |
| 64 |
FN(22, ditype, (__atomic_load_n((ditype*)p, __ATOMIC_SEQ_CST))) |
| 65 |
|
| 66 |
FN(23, bool, (__atomic_compare_exchange((ditype*)p, (ditype*)0, (ditype*)0, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))) |
| 67 |
FN(24, bool, (__atomic_compare_exchange_n((ditype*)p, (ditype*)0, 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))) |
| 68 |
|
| 69 |
FN(25, void, (__atomic_store((ditype*)p, (ditype*)0, __ATOMIC_SEQ_CST))) |
| 70 |
FN(26, void, (__atomic_store_n((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 71 |
|
| 72 |
FN(27, ditype, (__atomic_add_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 73 |
FN(28, ditype, (__atomic_sub_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 74 |
FN(29, ditype, (__atomic_and_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 75 |
FN(30, ditype, (__atomic_nand_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 76 |
FN(31, ditype, (__atomic_xor_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 77 |
FN(32, ditype, (__atomic_or_fetch((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 78 |
|
| 79 |
FN(33, ditype, (__atomic_fetch_add((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 80 |
FN(34, ditype, (__atomic_fetch_sub((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 81 |
FN(35, ditype, (__atomic_fetch_and((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 82 |
FN(36, ditype, (__atomic_fetch_nand((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 83 |
FN(37, ditype, (__atomic_fetch_xor((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 84 |
FN(38, ditype, (__atomic_fetch_or((ditype*)p, 1, __ATOMIC_SEQ_CST))) |
| 85 |
|
| 86 |
static void |
| 87 |
handler(int) |
| 88 |
{ |
| 89 |
sigset_t clear; |
| 90 |
|
| 91 |
sigfillset (&clear); |
| 92 |
sigprocmask (SIG_UNBLOCK, &clear, NULL); |
| 93 |
throw 0; |
| 94 |
} |
| 95 |
|
| 96 |
int |
| 97 |
main () |
| 98 |
{ |
| 99 |
signal (SIGSEGV, handler); |
| 100 |
signal (SIGBUS, handler); |
| 101 |
|
| 102 |
t1(); |
| 103 |
t2(); |
| 104 |
t3(); |
| 105 |
t4(); |
| 106 |
t5(); |
| 107 |
t6(); |
| 108 |
t7(); |
| 109 |
t8(); |
| 110 |
t9(); |
| 111 |
t10(); |
| 112 |
t11(); |
| 113 |
t12(); |
| 114 |
t13(); |
| 115 |
t14(); |
| 116 |
t15(); |
| 117 |
t16(); |
| 118 |
t17(); |
| 119 |
t18(); |
| 120 |
t19(); |
| 121 |
t20(); |
| 122 |
|
| 123 |
exit(0); |
| 124 |
} |