Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / absvdi2_test.c
blobf146598d759a8409b4d574ced9fb1ce5a6b7af43
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_absvdi2
4 #include "int_lib.h"
5 #include <stdio.h>
6 #include <stdlib.h>
8 // Returns: absolute value
10 // Effects: aborts if abs(x) < 0
12 COMPILER_RT_ABI di_int __absvdi2(di_int a);
14 int test__absvdi2(di_int a)
16 di_int x = __absvdi2(a);
17 di_int expected = a;
18 if (expected < 0)
19 expected = -expected;
20 if (x != expected || expected < 0)
21 printf("error in __absvdi2(0x%llX) = %lld, expected positive %lld\n",
22 a, x, expected);
23 return x != expected;
26 int main()
28 // if (test__absvdi2(0x8000000000000000LL)) // should abort
29 // return 1;
30 if (test__absvdi2(0x0000000000000000LL))
31 return 1;
32 if (test__absvdi2(0x0000000000000001LL))
33 return 1;
34 if (test__absvdi2(0x0000000000000002LL))
35 return 1;
36 if (test__absvdi2(0x7FFFFFFFFFFFFFFELL))
37 return 1;
38 if (test__absvdi2(0x7FFFFFFFFFFFFFFFLL))
39 return 1;
40 if (test__absvdi2(0x8000000000000001LL))
41 return 1;
42 if (test__absvdi2(0x8000000000000002LL))
43 return 1;
44 if (test__absvdi2(0xFFFFFFFFFFFFFFFELL))
45 return 1;
46 if (test__absvdi2(0xFFFFFFFFFFFFFFFFLL))
47 return 1;
49 int i;
50 for (i = 0; i < 10000; ++i)
51 if (test__absvdi2(((di_int)rand() << 32) | rand()))
52 return 1;
54 return 0;