1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_negvsi2
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 si_int __negvsi2(si_int a);
12
13int test__negvsi2(si_int a)
14{
15 si_int x = __negvsi2(a);
16 si_int expected = -a;
17 if (x != expected)
18 printf(format: "error in __negvsi2(0x%X) = %d, expected %d\n", a, x, expected);
19 return x != expected;
20}
21
22int main()
23{
24// if (test__negvsi2(0x80000000)) // should abort
25// return 1;
26 if (test__negvsi2(a: 0x00000000))
27 return 1;
28 if (test__negvsi2(a: 0x00000001))
29 return 1;
30 if (test__negvsi2(a: 0x00000002))
31 return 1;
32 if (test__negvsi2(a: 0x7FFFFFFE))
33 return 1;
34 if (test__negvsi2(a: 0x7FFFFFFF))
35 return 1;
36 if (test__negvsi2(a: 0x80000001))
37 return 1;
38 if (test__negvsi2(a: 0x80000002))
39 return 1;
40 if (test__negvsi2(a: 0xFFFFFFFE))
41 return 1;
42 if (test__negvsi2(a: 0xFFFFFFFF))
43 return 1;
44
45 return 0;
46}
47

source code of compiler-rt/test/builtins/Unit/negvsi2_test.c