1*4684ddb6SLionel Sambuc //===-- addvdi3_test.c - Test __addvdi3 -----------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __addvdi3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc
17*4684ddb6SLionel Sambuc // Returns: a + b
18*4684ddb6SLionel Sambuc
19*4684ddb6SLionel Sambuc // Effects: aborts if a + b overflows
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc di_int __addvdi3(di_int a, di_int b);
22*4684ddb6SLionel Sambuc
test__addvdi3(di_int a,di_int b)23*4684ddb6SLionel Sambuc int test__addvdi3(di_int a, di_int b)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc di_int x = __addvdi3(a, b);
26*4684ddb6SLionel Sambuc di_int expected = a + b;
27*4684ddb6SLionel Sambuc if (x != expected)
28*4684ddb6SLionel Sambuc printf("error in test__addvdi3(0x%llX, 0x%llX) = %lld, expected %lld\n",
29*4684ddb6SLionel Sambuc a, b, x, expected);
30*4684ddb6SLionel Sambuc return x != expected;
31*4684ddb6SLionel Sambuc }
32*4684ddb6SLionel Sambuc
main()33*4684ddb6SLionel Sambuc int main()
34*4684ddb6SLionel Sambuc {
35*4684ddb6SLionel Sambuc // test__addvdi3(0x8000000000000000LL, -1); // should abort
36*4684ddb6SLionel Sambuc // test__addvdi3(-1, 0x8000000000000000LL); // should abort
37*4684ddb6SLionel Sambuc // test__addvdi3(1, 0x7FFFFFFFFFFFFFFFLL); // should abort
38*4684ddb6SLionel Sambuc // test__addvdi3(0x7FFFFFFFFFFFFFFFLL, 1); // should abort
39*4684ddb6SLionel Sambuc
40*4684ddb6SLionel Sambuc if (test__addvdi3(0x8000000000000000LL, 1))
41*4684ddb6SLionel Sambuc return 1;
42*4684ddb6SLionel Sambuc if (test__addvdi3(1, 0x8000000000000000LL))
43*4684ddb6SLionel Sambuc return 1;
44*4684ddb6SLionel Sambuc if (test__addvdi3(0x8000000000000000LL, 0))
45*4684ddb6SLionel Sambuc return 1;
46*4684ddb6SLionel Sambuc if (test__addvdi3(0, 0x8000000000000000LL))
47*4684ddb6SLionel Sambuc return 1;
48*4684ddb6SLionel Sambuc if (test__addvdi3(0x7FFFFFFFFFFFFFFLL, -1))
49*4684ddb6SLionel Sambuc return 1;
50*4684ddb6SLionel Sambuc if (test__addvdi3(-1, 0x7FFFFFFFFFFFFFFLL))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__addvdi3(0x7FFFFFFFFFFFFFFFLL, 0))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc if (test__addvdi3(0, 0x7FFFFFFFFFFFFFFFLL))
55*4684ddb6SLionel Sambuc return 1;
56*4684ddb6SLionel Sambuc
57*4684ddb6SLionel Sambuc return 0;
58*4684ddb6SLionel Sambuc }
59