]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/builtin-arith-overflow-3.c
[arm] Early split addvdi4
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / builtin-arith-overflow-3.c
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 static int cnt = 0;
5
6 #define LL_MIN ((long long)(-__LONG_LONG_MAX__ - 1))
7
8 #define SC1 (LL_MIN + 5)
9 #define UC1 ((1ULL << (__LONG_LONG_WIDTH__ - 1)) | 5ULL)
10 #define UC2 (~UC1)
11
12 long long __attribute__ ((noinline, noclone))
13 f1 (long long a)
14 {
15 long long x;
16 if (__builtin_add_overflow (a, SC1, &x)) cnt++;
17 return x;
18 }
19
20 unsigned long long __attribute__ ((noinline, noclone))
21 f2 (unsigned long long a)
22 {
23 unsigned long long x;
24 if (__builtin_add_overflow (a, UC1, &x))
25 cnt++;
26 return x;
27 }
28
29 int main ()
30 {
31 if (f1 (-5) != LL_MIN) __builtin_abort ();
32 if (cnt != 0) __builtin_abort ();
33 f1 (-6);
34 if (cnt != 1) __builtin_abort ();
35 cnt = 0;
36 if (f2 (UC2) != ~0ULL) __builtin_abort ();
37 if (cnt != 0) __builtin_abort ();
38 if (f2 (UC2 + 1) != 0) __builtin_abort ();
39 if (cnt != 1) __builtin_abort ();
40 return 0;
41 }