gcc/
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / 20101011-1.c
blob9299bb9205a850b6551e765025b359dc1d16fb7c
1 /* With -fnon-call-exceptions 0 / 0 should not be eliminated. The .x
2 file sets the option. */
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 (__mips__) && !defined(__linux__)
22 /* MIPS divisions do trap by default, but libgloss targets do not
23 intercept the trap and raise a SIGFPE. The same is probably
24 true of other bare-metal environments, so restrict the test to
25 systems that use the Linux kernel. */
26 # define DO_TEST 0
27 #elif defined (__mips16) && defined(__linux__)
28 /* Not all Linux kernels deal correctly the breakpoints generated by
29 MIPS16 divisions by zero. They show up as a SIGTRAP instead. */
30 # define DO_TEST 0
31 #elif defined (__MICROBLAZE__)
32 /* We cannot rely on division by zero generating a trap. */
33 # define DO_TEST 0
34 #elif defined (__epiphany__)
35 /* Epiphany does not have hardware division, and the software implementation
36 has truly undefined behaviour for division by 0. */
37 # define DO_TEST 0
38 #elif defined (__m68k__) && !defined(__linux__)
39 /* Attempting to trap division-by-zero in this way isn't likely to work on
40 bare-metal m68k systems. */
41 # define DO_TEST 0
42 #elif defined (__CRIS__)
43 /* No SIGFPE for CRIS integer division. */
44 # define DO_TEST 0
45 #elif defined (__MMIX__)
46 /* By default we emit a sequence with DIVU, which "never signals an
47 exceptional condition, even when dividing by zero". */
48 # define DO_TEST 0
49 #elif defined (__arc__)
50 /* No SIGFPE for ARC integer division. */
51 # define DO_TEST 0
52 #elif defined (__arm__) && defined (__ARM_EABI__)
53 # ifdef __ARM_ARCH_EXT_IDIV__
54 /* Hardware division instructions may not trap, and handle trapping
55 differently anyway. Skip the test if we have those instructions. */
56 # define DO_TEST 0
57 # else
58 # include <signal.h>
59 /* ARM division-by-zero behaviour is to call a helper function, which
60 can do several different things, depending on requirements. Emulate
61 the behaviour of other targets here by raising SIGFPE. */
62 int __attribute__((used))
63 __aeabi_idiv0 (int return_value)
65 raise (SIGFPE);
66 return return_value;
68 # define DO_TEST 1
69 # endif
70 #elif defined (__nios2__)
71 /* Nios II requires both hardware support and user configuration to
72 raise an exception on divide by zero. */
73 # define DO_TEST 0
74 #else
75 # define DO_TEST 1
76 #endif
78 #if DO_TEST
80 #include <signal.h>
82 void
83 sigfpe (int signum __attribute__ ((unused)))
85 exit (0);
88 #endif
90 /* When optimizing, the compiler is smart enough to constant fold the
91 static unset variables i and j to produce 0 / 0, but it can't
92 eliminate the assignment to the global k. */
93 static int i;
94 static int j;
95 int k __attribute__ ((used));
97 int
98 main ()
100 #if DO_TEST
101 signal (SIGFPE, sigfpe);
102 k = i / j;
103 abort ();
104 #else
105 exit (0);
106 #endif