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