Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / absvsi2_test.c
blobd7f7bdcf8eed92eaa323c392b1bf7e3e6f84f661
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_absvsi2
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 si_int __absvsi2(si_int a);
14 int test__absvsi2(si_int a)
16 si_int x = __absvsi2(a);
17 si_int expected = a;
18 if (expected < 0)
19 expected = -expected;
20 if (x != expected || expected < 0)
21 printf("error in __absvsi2(0x%X) = %d, expected positive %d\n",
22 a, x, expected);
23 return x != expected;
26 int main()
28 // if (test__absvsi2(0x80000000)) // should abort
29 // return 1;
30 if (test__absvsi2(0x00000000))
31 return 1;
32 if (test__absvsi2(0x00000001))
33 return 1;
34 if (test__absvsi2(0x00000002))
35 return 1;
36 if (test__absvsi2(0x7FFFFFFE))
37 return 1;
38 if (test__absvsi2(0x7FFFFFFF))
39 return 1;
40 if (test__absvsi2(0x80000001))
41 return 1;
42 if (test__absvsi2(0x80000002))
43 return 1;
44 if (test__absvsi2(0xFFFFFFFE))
45 return 1;
46 if (test__absvsi2(0xFFFFFFFF))
47 return 1;
49 int i;
50 for (i = 0; i < 10000; ++i)
51 if (test__absvsi2(rand()))
52 return 1;
54 return 0;