1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_negvdi2
3
4#include "int_lib.h"
5#include <stdio.h>
6
7// Returns: -a
8
9// Effects: aborts if -a overflows
10
11COMPILER_RT_ABI di_int __negvdi2(di_int a);
12
13int test__negvdi2(di_int a)
14{
15 di_int x = __negvdi2(a);
16 di_int expected = -a;
17 if (x != expected)
18 printf("error in __negvdi2(0x%llX) = %lld, expected %lld\n",
19 a, x, expected);
20 return x != expected;
21}
22
23int main()
24{
25// if (test__negvdi2(0x8000000000000000LL)) // should abort
26// return 1;
27 if (test__negvdi2(0x0000000000000000LL))
28 return 1;
29 if (test__negvdi2(0x0000000000000001LL))
30 return 1;
31 if (test__negvdi2(0x0000000000000002LL))
32 return 1;
33 if (test__negvdi2(0x7FFFFFFFFFFFFFFELL))
34 return 1;
35 if (test__negvdi2(0x7FFFFFFFFFFFFFFFLL))
36 return 1;
37 if (test__negvdi2(0x8000000000000001LL))
38 return 1;
39 if (test__negvdi2(0x8000000000000002LL))
40 return 1;
41 if (test__negvdi2(0xFFFFFFFFFFFFFFFELL))
42 return 1;
43 if (test__negvdi2(0xFFFFFFFFFFFFFFFFLL))
44 return 1;
45
46 return 0;
47}
48