]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/testsuite/overflow_unittest.cc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / testsuite / overflow_unittest.cc
1 // overflow_unittest.cc -- test functions that check for overflow.
2
3 // Copyright (C) 2016-2021 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #include "gold.h"
24 #include "reloc.h"
25
26 #include <sys/types.h>
27
28 #include "test.h"
29
30 namespace gold_testsuite
31 {
32
33 using namespace gold;
34
35 bool
36 Overflow_test(Test_report*)
37 {
38 CHECK(! Bits<16>::has_unsigned_overflow(0ULL));
39 CHECK(! Bits<16>::has_unsigned_overflow(1ULL));
40 CHECK(! Bits<16>::has_unsigned_overflow(0x7fffULL));
41 CHECK(! Bits<16>::has_unsigned_overflow(0x8000ULL));
42 CHECK(! Bits<16>::has_unsigned_overflow(0x8001ULL));
43 CHECK(! Bits<16>::has_unsigned_overflow(0xffffULL));
44 CHECK(Bits<16>::has_unsigned_overflow(0x10000ULL));
45 CHECK(Bits<16>::has_unsigned_overflow(0x10001ULL));
46 CHECK(Bits<16>::has_unsigned_overflow(~0ULL));
47 CHECK(Bits<16>::has_unsigned_overflow(~0x7fffULL + 1));
48 CHECK(Bits<16>::has_unsigned_overflow(~0x8000ULL + 1));
49 CHECK(Bits<16>::has_unsigned_overflow(~0x8001ULL + 1));
50 CHECK(Bits<16>::has_unsigned_overflow(~0xffffULL + 1));
51 CHECK(Bits<16>::has_unsigned_overflow(~0x10000ULL + 1));
52 CHECK(Bits<16>::has_unsigned_overflow(~0x10001ULL + 1));
53
54 CHECK(! Bits<16>::has_overflow(0ULL));
55 CHECK(! Bits<16>::has_overflow(1ULL));
56 CHECK(! Bits<16>::has_overflow(0x7fffULL));
57 CHECK(Bits<16>::has_overflow(0x8000ULL));
58 CHECK(Bits<16>::has_overflow(0x8001ULL));
59 CHECK(Bits<16>::has_overflow(0xffffULL));
60 CHECK(Bits<16>::has_overflow(0x10000ULL));
61 CHECK(Bits<16>::has_overflow(0x10001ULL));
62 CHECK(! Bits<16>::has_overflow(~0ULL));
63 CHECK(! Bits<16>::has_overflow(~0x7fffULL + 1));
64 CHECK(! Bits<16>::has_overflow(~0x8000ULL + 1));
65 CHECK(Bits<16>::has_overflow(~0x8001ULL + 1));
66 CHECK(Bits<16>::has_overflow(~0xffffULL + 1));
67 CHECK(Bits<16>::has_overflow(~0x10000ULL + 1));
68 CHECK(Bits<16>::has_overflow(~0x10001ULL + 1));
69
70 CHECK(! Bits<16>::has_signed_unsigned_overflow64(0ULL));
71 CHECK(! Bits<16>::has_signed_unsigned_overflow64(1ULL));
72 CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x7fffULL));
73 CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x8000ULL));
74 CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x8001ULL));
75 CHECK(! Bits<16>::has_signed_unsigned_overflow64(0xffffULL));
76 CHECK(Bits<16>::has_signed_unsigned_overflow64(0x10000ULL));
77 CHECK(Bits<16>::has_signed_unsigned_overflow64(0x10001ULL));
78 CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0ULL));
79 CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0x7fffULL + 1));
80 CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0x8000ULL + 1));
81 CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x8001ULL + 1));
82 CHECK(Bits<16>::has_signed_unsigned_overflow64(~0xffffULL + 1));
83 CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x10000ULL + 1));
84 CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x10001ULL + 1));
85
86 CHECK(! Bits<16>::has_unsigned_overflow32(0U));
87 CHECK(! Bits<16>::has_unsigned_overflow32(1U));
88 CHECK(! Bits<16>::has_unsigned_overflow32(0x7fffU));
89 CHECK(! Bits<16>::has_unsigned_overflow32(0x8000U));
90 CHECK(! Bits<16>::has_unsigned_overflow32(0x8001U));
91 CHECK(! Bits<16>::has_unsigned_overflow32(0xffffU));
92 CHECK(Bits<16>::has_unsigned_overflow32(0x10000U));
93 CHECK(Bits<16>::has_unsigned_overflow32(0x10001U));
94 CHECK(Bits<16>::has_unsigned_overflow32(~0U));
95 CHECK(Bits<16>::has_unsigned_overflow32(~0x7fffU + 1));
96 CHECK(Bits<16>::has_unsigned_overflow32(~0x8000U + 1));
97 CHECK(Bits<16>::has_unsigned_overflow32(~0x8001U + 1));
98 CHECK(Bits<16>::has_unsigned_overflow32(~0xffffU + 1));
99 CHECK(Bits<16>::has_unsigned_overflow32(~0x10000U + 1));
100 CHECK(Bits<16>::has_unsigned_overflow32(~0x10001U + 1));
101
102 CHECK(! Bits<16>::has_overflow32(0U));
103 CHECK(! Bits<16>::has_overflow32(1U));
104 CHECK(! Bits<16>::has_overflow32(0x7fffU));
105 CHECK(Bits<16>::has_overflow32(0x8000U));
106 CHECK(Bits<16>::has_overflow32(0x8001U));
107 CHECK(Bits<16>::has_overflow32(0xffffU));
108 CHECK(Bits<16>::has_overflow32(0x10000U));
109 CHECK(Bits<16>::has_overflow32(0x10001U));
110 CHECK(! Bits<16>::has_overflow32(~0U));
111 CHECK(! Bits<16>::has_overflow32(~0x7fffU + 1));
112 CHECK(! Bits<16>::has_overflow32(~0x8000U + 1));
113 CHECK(Bits<16>::has_overflow32(~0x8001U + 1));
114 CHECK(Bits<16>::has_overflow32(~0xffffU + 1));
115 CHECK(Bits<16>::has_overflow32(~0x10000U + 1));
116 CHECK(Bits<16>::has_overflow32(~0x10001U + 1));
117
118 CHECK(! Bits<16>::has_signed_unsigned_overflow32(0U));
119 CHECK(! Bits<16>::has_signed_unsigned_overflow32(1U));
120 CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x7fffU));
121 CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x8000U));
122 CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x8001U));
123 CHECK(! Bits<16>::has_signed_unsigned_overflow32(0xffffU));
124 CHECK(Bits<16>::has_signed_unsigned_overflow32(0x10000U));
125 CHECK(Bits<16>::has_signed_unsigned_overflow32(0x10001U));
126 CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0U));
127 CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0x7fffU + 1));
128 CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0x8000U + 1));
129 CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x8001U + 1));
130 CHECK(Bits<16>::has_signed_unsigned_overflow32(~0xffffU + 1));
131 CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x10000U + 1));
132 CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x10001U + 1));
133
134 return true;
135 }
136
137 Register_test overflow_register("Overflow", Overflow_test);
138
139 } // End namespace gold_testsuite.