blob: 99e70403e8b693c8c80216077420fe7ba7cbba25 [file] [log] [blame]
Weiming Zhao9b7bbec2017-03-21 05:32:51 +00001// RUN: %clang_builtins %s %librt -o %t && %run %t
Daniel Dunbarfd089992009-06-26 16:47:03 +00002//===-- addvdi3_test.c - Test __addvdi3 -----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnant5b791f62010-11-16 22:13:33 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +00008//
9//===----------------------------------------------------------------------===//
10//
11// This file tests __addvdi3 for the compiler_rt library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "int_lib.h"
16#include <stdio.h>
17
18// Returns: a + b
19
20// Effects: aborts if a + b overflows
21
Derek Schuffeb0ebc32015-04-24 15:45:57 +000022COMPILER_RT_ABI di_int __addvdi3(di_int a, di_int b);
Daniel Dunbarfd089992009-06-26 16:47:03 +000023
24int test__addvdi3(di_int a, di_int b)
25{
26 di_int x = __addvdi3(a, b);
27 di_int expected = a + b;
28 if (x != expected)
29 printf("error in test__addvdi3(0x%llX, 0x%llX) = %lld, expected %lld\n",
30 a, b, x, expected);
31 return x != expected;
32}
33
34int main()
35{
36// test__addvdi3(0x8000000000000000LL, -1); // should abort
37// test__addvdi3(-1, 0x8000000000000000LL); // should abort
38// test__addvdi3(1, 0x7FFFFFFFFFFFFFFFLL); // should abort
39// test__addvdi3(0x7FFFFFFFFFFFFFFFLL, 1); // should abort
40
41 if (test__addvdi3(0x8000000000000000LL, 1))
42 return 1;
43 if (test__addvdi3(1, 0x8000000000000000LL))
44 return 1;
45 if (test__addvdi3(0x8000000000000000LL, 0))
46 return 1;
47 if (test__addvdi3(0, 0x8000000000000000LL))
48 return 1;
49 if (test__addvdi3(0x7FFFFFFFFFFFFFFLL, -1))
50 return 1;
51 if (test__addvdi3(-1, 0x7FFFFFFFFFFFFFFLL))
52 return 1;
53 if (test__addvdi3(0x7FFFFFFFFFFFFFFFLL, 0))
54 return 1;
55 if (test__addvdi3(0, 0x7FFFFFFFFFFFFFFFLL))
56 return 1;
57
58 return 0;
59}