modula2: M2MetaError.{def,mod} and P2SymBuild.mod further cleanup
[official-gcc.git] / gcc / testsuite / gcc.dg / signbit-6.c
blob3a522893222d067eb68e242e48789b2f919fbebb
1 /* { dg-do run } */
2 /* { dg-options "-O1" } */
4 #include <stdint.h>
5 #include <limits.h>
6 #include <stdio.h>
8 #ifndef N
9 #define N 65
10 #endif
12 #ifndef TYPE
13 #define TYPE int32_t
14 #endif
16 #ifndef DEBUG
17 #define DEBUG 1
18 #endif
20 #define BASE ((TYPE) -1 < 0 ? -126 : 4)
22 __attribute__ ((noinline, noipa))
23 void fun1(TYPE *x, int n)
25 for (int i = 0; i < n; i++)
26 x[i] = (-x[i]) >> 31;
29 __attribute__ ((noinline, noipa, optimize("O0")))
30 void fun2(TYPE *x, int n)
32 for (int i = 0; i < n; i++)
33 x[i] = (-x[i]) >> 31;
36 int main ()
38 TYPE a[N];
39 TYPE b[N];
41 /* This will invoke UB due to -INT32_MIN. The test is supposed to pass
42 because GCC is supposed to handle this UB case in a predictable way. */
43 a[0] = INT32_MIN;
44 b[0] = INT32_MIN;
46 for (int i = 1; i < N; ++i)
48 a[i] = BASE + i * 13;
49 b[i] = BASE + i * 13;
50 if (DEBUG)
51 printf ("%d: 0x%x\n", i, a[i]);
54 fun1 (a, N);
55 fun2 (b, N);
57 if (DEBUG)
58 printf ("%d = 0x%x == 0x%x\n", 0, a[0], b[0]);
60 if (a[0] != 0x0 || b[0] != -1)
61 __builtin_abort ();
64 for (int i = 1; i < N; ++i)
66 if (DEBUG)
67 printf ("%d = 0x%x == 0x%x\n", i, a[i], b[i]);
69 if (a[i] != b[i])
70 __builtin_abort ();
72 return 0;