1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_subvsi3
3
4#include "int_lib.h"
5#include <stdio.h>
6#include <stdlib.h>
7
8// Returns: a - b
9
10// Effects: aborts if a - b overflows
11
12COMPILER_RT_ABI si_int __subvsi3(si_int a, si_int b);
13
14int test__subvsi3(si_int a, si_int b)
15{
16 si_int x = __subvsi3(a, b);
17 si_int expected = a - b;
18 if (x != expected)
19 printf("error in test__subvsi3(0x%X, 0x%X) = %d, expected %d\n",
20 a, b, x, expected);
21 return x != expected;
22}
23
24int main()
25{
26// test__subvsi3(0x80000000, 1); // should abort
27// test__subvsi3(0, 0x80000000); // should abort
28// test__subvsi3(1, 0x80000000); // should abort
29// test__subvsi3(0x7FFFFFFF, -1); // should abort
30// test__subvsi3(-2, 0x7FFFFFFF); // should abort
31
32 if (test__subvsi3(0x80000000, -1))
33 return 1;
34 if (test__subvsi3(0x80000000, 0))
35 return 1;
36 if (test__subvsi3(-1, 0x80000000))
37 return 1;
38 if (test__subvsi3(0x7FFFFFFF, 1))
39 return 1;
40 if (test__subvsi3(0x7FFFFFFF, 0))
41 return 1;
42 if (test__subvsi3(1, 0x7FFFFFFF))
43 return 1;
44 if (test__subvsi3(0, 0x7FFFFFFF))
45 return 1;
46 if (test__subvsi3(-1, 0x7FFFFFFF))
47 return 1;
48
49 return 0;
50}
51