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