1/* { dg-options "-fnon-call-exceptions" } */ 2/* With -fnon-call-exceptions 0 / 0 should not be eliminated. */ 3 4#ifdef SIGNAL_SUPPRESS 5# define DO_TEST 0 6#elif defined (__powerpc__) || defined (__PPC__) || defined (__ppc__) || defined (__POWERPC__) || defined (__ppc) 7 /* On PPC division by zero does not trap. */ 8# define DO_TEST 0 9#elif defined (__SPU__) 10 /* On SPU division by zero does not trap. */ 11# define DO_TEST 0 12#elif defined (__sh__) 13 /* On SH division by zero does not trap. */ 14# define DO_TEST 0 15#elif defined (__aarch64__) 16 /* On AArch64 integer division by zero does not trap. */ 17# define DO_TEST 0 18#elif defined (__TMS320C6X__) 19 /* On TI C6X division by zero does not trap. */ 20# define DO_TEST 0 21#elif defined (__VISIUM__) 22 /* On Visium division by zero does not trap. */ 23# define DO_TEST 0 24#elif defined (__mips__) && !defined(__linux__) 25 /* MIPS divisions do trap by default, but libgloss targets do not 26 intercept the trap and raise a SIGFPE. The same is probably 27 true of other bare-metal environments, so restrict the test to 28 systems that use the Linux kernel. */ 29# define DO_TEST 0 30#elif defined (__mips16) && defined(__linux__) 31 /* Not all Linux kernels deal correctly the breakpoints generated by 32 MIPS16 divisions by zero. They show up as a SIGTRAP instead. */ 33# define DO_TEST 0 34#elif defined (__MICROBLAZE__) 35/* We cannot rely on division by zero generating a trap. */ 36# define DO_TEST 0 37#elif defined (__epiphany__) 38 /* Epiphany does not have hardware division, and the software implementation 39 has truly undefined behaviour for division by 0. */ 40# define DO_TEST 0 41#elif defined (__m68k__) && !defined(__linux__) 42 /* Attempting to trap division-by-zero in this way isn't likely to work on 43 bare-metal m68k systems. */ 44# define DO_TEST 0 45#elif defined (__CRIS__) 46 /* No SIGFPE for CRIS integer division. */ 47# define DO_TEST 0 48#elif defined (__MMIX__) 49/* By default we emit a sequence with DIVU, which "never signals an 50 exceptional condition, even when dividing by zero". */ 51# define DO_TEST 0 52#elif defined (__arc__) 53 /* No SIGFPE for ARC integer division. */ 54# define DO_TEST 0 55#elif defined (__arm__) && defined (__ARM_EABI__) 56# ifdef __ARM_ARCH_EXT_IDIV__ 57 /* Hardware division instructions may not trap, and handle trapping 58 differently anyway. Skip the test if we have those instructions. */ 59# define DO_TEST 0 60# else 61# include <signal.h> 62 /* ARM division-by-zero behaviour is to call a helper function, which 63 can do several different things, depending on requirements. Emulate 64 the behaviour of other targets here by raising SIGFPE. */ 65int __attribute__((used)) 66__aeabi_idiv0 (int return_value) 67{ 68 raise (SIGFPE); 69 return return_value; 70} 71# define DO_TEST 1 72# endif 73#elif defined (__nios2__) 74 /* Nios II requires both hardware support and user configuration to 75 raise an exception on divide by zero. */ 76# define DO_TEST 0 77#elif defined (__nvptx__) 78/* There isn't even a signal function. */ 79# define DO_TEST 0 80#else 81# define DO_TEST 1 82#endif 83 84extern void abort (void); 85extern void exit (int); 86 87#if DO_TEST 88 89#include <signal.h> 90 91void 92sigfpe (int signum __attribute__ ((unused))) 93{ 94 exit (0); 95} 96 97#endif 98 99/* When optimizing, the compiler is smart enough to constant fold the 100 static unset variables i and j to produce 0 / 0, but it can't 101 eliminate the assignment to the global k. */ 102static int i; 103static int j; 104int k __attribute__ ((used)); 105 106int 107main () 108{ 109#if DO_TEST 110 signal (SIGFPE, sigfpe); 111 k = i / j; 112 abort (); 113#else 114 exit (0); 115#endif 116} 117