Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/divconst-2.c

raw
1 void abort (void);
2 void exit (int);
3
4 long
5 f (long x)
6 {
7 return x / (-0x7fffffffL - 1L);
8 }
9
10 long
11 r (long x)
12 {
13 return x % (-0x7fffffffL - 1L);
14 }
15
16 /* Since we have a negative divisor, this equation must hold for the
17 results of / and %; no specific results are guaranteed. */
18 long
19 std_eqn (long num, long denom, long quot, long rem)
20 {
21 /* For completeness, a check for "ABS (rem) < ABS (denom)" belongs here,
22 but causes trouble on 32-bit machines and isn't worthwhile. */
23 return quot * (-0x7fffffffL - 1L) + rem == num;
24 }
25
26 long nums[] =
27 {
28 -1L, 0x7fffffffL, -0x7fffffffL - 1L
29 };
30
31 int
32 main (void)
33 {
34 int i;
35
36 for (i = 0;
37 i < sizeof (nums) / sizeof (nums[0]);
38 i++)
39 if (std_eqn (nums[i], -0x7fffffffL - 1L, f (nums[i]), r (nums[i])) == 0)
40 abort ();
41
42 exit (0);
43 }