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