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

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