1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
---|---|
2 | // REQUIRES: librt_has_absvdi2 |
3 | |
4 | #include "int_lib.h" |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | |
8 | // Returns: absolute value |
9 | |
10 | // Effects: aborts if abs(x) < 0 |
11 | |
12 | COMPILER_RT_ABI di_int __absvdi2(di_int a); |
13 | |
14 | int test__absvdi2(di_int a) |
15 | { |
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(format: "error in __absvdi2(0x%llX) = %lld, expected positive %lld\n", |
22 | a, x, expected); |
23 | return x != expected; |
24 | } |
25 | |
26 | int main() |
27 | { |
28 | // if (test__absvdi2(0x8000000000000000LL)) // should abort |
29 | // return 1; |
30 | if (test__absvdi2(a: 0x0000000000000000LL)) |
31 | return 1; |
32 | if (test__absvdi2(a: 0x0000000000000001LL)) |
33 | return 1; |
34 | if (test__absvdi2(a: 0x0000000000000002LL)) |
35 | return 1; |
36 | if (test__absvdi2(a: 0x7FFFFFFFFFFFFFFELL)) |
37 | return 1; |
38 | if (test__absvdi2(a: 0x7FFFFFFFFFFFFFFFLL)) |
39 | return 1; |
40 | if (test__absvdi2(a: 0x8000000000000001LL)) |
41 | return 1; |
42 | if (test__absvdi2(a: 0x8000000000000002LL)) |
43 | return 1; |
44 | if (test__absvdi2(a: 0xFFFFFFFFFFFFFFFELL)) |
45 | return 1; |
46 | if (test__absvdi2(a: 0xFFFFFFFFFFFFFFFFLL)) |
47 | return 1; |
48 | |
49 | int i; |
50 | for (i = 0; i < 10000; ++i) |
51 | if (test__absvdi2(a: ((di_int)rand() << 32) | rand())) |
52 | return 1; |
53 | |
54 | return 0; |
55 | } |
56 |