Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-intprops.c @ 14761:6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
* modules/intprops-tests (Files): Add tests/macros.h.
* tests/test-intprops.c: Include macros.h.
(TYPE_IS_INTEGER): Use ASSERT, not verify, to test this macro, as
it's no longer documented to expand to an integer constant expression.
(TYPE_SIGNED): Use ASSERT, not verify, to test this macro when the
argument is floating point, as it's no longer documented to expand
to an integer constant expression in that case.
(UINT_MAX, ULONG_MAX, UINTMAX_MAX): Redefine to work around
compiler bugs reported by Bruno Haible. See
<http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.
(U0, U1): New constants, to work around the same bugs. Also,
in tests, use e.g., "(unsigned int) 39" rather than "39u".
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 19 May 2011 01:43:17 -0700 |
parents | eb6ac457b650 |
children | 05ca371c9c6e |
rev | line source |
---|---|
14741 | 1 /* Test intprops.h. |
2 Copyright (C) 2011 Free Software Foundation, Inc. | |
3 | |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 /* Written by Paul Eggert. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include "intprops.h" | |
22 #include "verify.h" | |
23 | |
24 #include <stdbool.h> | |
25 #include <inttypes.h> | |
26 | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
27 #include "macros.h" |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
28 |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
29 /* Work around compiler bugs in HP-UX 11.23 cc, IRIX 6.5 cc, OSF/1 5.1 |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
30 cc, and Solaris 9 cc. See |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
31 <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */ |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
32 #undef UINT_MAX |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
33 #undef ULONG_MAX |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
34 #undef UINTMAX_MAX |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
35 #define UINT_MAX ((unsigned int) -1) |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
36 #define ULONG_MAX ((unsigned long int) -1) |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
37 #define UINTMAX_MAX ((uintmax_t) -1) |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
38 #define U0 ((unsigned int) 0) |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
39 #define U1 ((unsigned int) 1) |
14741 | 40 |
41 /* Integer representation. */ | |
42 verify (INT_MIN + INT_MAX < 0 | |
43 ? (TYPE_TWOS_COMPLEMENT (int) | |
44 && ! TYPE_ONES_COMPLEMENT (int) && ! TYPE_SIGNED_MAGNITUDE (int)) | |
45 : (! TYPE_TWOS_COMPLEMENT (int) | |
46 && (TYPE_ONES_COMPLEMENT (int) || TYPE_SIGNED_MAGNITUDE (int)))); | |
47 | |
48 /* TYPE_SIGNED. */ | |
49 /* verify (! TYPE_SIGNED (bool)); */ /* not guaranteed by gnulib substitute */ | |
50 verify (TYPE_SIGNED (signed char)); | |
51 verify (! TYPE_SIGNED (unsigned char)); | |
52 verify (TYPE_SIGNED (short int)); | |
53 verify (! TYPE_SIGNED (unsigned short int)); | |
54 verify (TYPE_SIGNED (int)); | |
55 verify (! TYPE_SIGNED (unsigned int)); | |
56 verify (TYPE_SIGNED (long int)); | |
57 verify (! TYPE_SIGNED (unsigned long int)); | |
58 verify (TYPE_SIGNED (intmax_t)); | |
59 verify (! TYPE_SIGNED (uintmax_t)); | |
60 | |
61 /* TYPE_MINIMUM, TYPE_MAXIMUM. */ | |
62 verify (TYPE_MINIMUM (char) == CHAR_MIN); | |
63 verify (TYPE_MAXIMUM (char) == CHAR_MAX); | |
64 verify (TYPE_MINIMUM (unsigned char) == 0); | |
65 verify (TYPE_MAXIMUM (unsigned char) == UCHAR_MAX); | |
66 verify (TYPE_MINIMUM (signed char) == SCHAR_MIN); | |
67 verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX); | |
68 verify (TYPE_MINIMUM (short int) == SHRT_MIN); | |
69 verify (TYPE_MAXIMUM (short int) == SHRT_MAX); | |
70 verify (TYPE_MINIMUM (unsigned short int) == 0); | |
71 verify (TYPE_MAXIMUM (unsigned short int) == USHRT_MAX); | |
72 verify (TYPE_MINIMUM (int) == INT_MIN); | |
73 verify (TYPE_MAXIMUM (int) == INT_MAX); | |
74 verify (TYPE_MINIMUM (unsigned int) == 0); | |
75 verify (TYPE_MAXIMUM (unsigned int) == UINT_MAX); | |
76 verify (TYPE_MINIMUM (long int) == LONG_MIN); | |
77 verify (TYPE_MAXIMUM (long int) == LONG_MAX); | |
78 verify (TYPE_MINIMUM (unsigned long int) == 0); | |
79 verify (TYPE_MAXIMUM (unsigned long int) == ULONG_MAX); | |
80 verify (TYPE_MINIMUM (intmax_t) == INTMAX_MIN); | |
81 verify (TYPE_MAXIMUM (intmax_t) == INTMAX_MAX); | |
82 verify (TYPE_MINIMUM (uintmax_t) == 0); | |
83 verify (TYPE_MAXIMUM (uintmax_t) == UINTMAX_MAX); | |
84 | |
85 /* INT_BITS_STRLEN_BOUND. */ | |
86 verify (INT_BITS_STRLEN_BOUND (1) == 1); | |
87 verify (INT_BITS_STRLEN_BOUND (2620) == 789); | |
88 | |
89 /* INT_STRLEN_BOUND, INT_BUFSIZE_BOUND. */ | |
90 #ifdef INT32_MAX /* POSIX guarantees int32_t; this ports to non-POSIX hosts */ | |
91 verify (INT_STRLEN_BOUND (int32_t) == sizeof ("-2147483648") - 1); | |
92 verify (INT_BUFSIZE_BOUND (int32_t) == sizeof ("-2147483648")); | |
93 #endif | |
94 #ifdef INT64_MAX | |
95 verify (INT_STRLEN_BOUND (int64_t) == sizeof ("-9223372036854775808") - 1); | |
96 verify (INT_BUFSIZE_BOUND (int64_t) == sizeof ("-9223372036854775808")); | |
97 #endif | |
98 | |
99 /* All the INT_<op>_RANGE_OVERFLOW tests are equally valid as | |
100 INT_<op>_OVERFLOW tests, so define a single macro to do both. */ | |
101 #define check_binop(op, a, b, min, max, overflow) \ | |
102 (INT_##op##_RANGE_OVERFLOW (a, b, min, max) == (overflow) \ | |
103 && INT_##op##_OVERFLOW (a, b) == (overflow)) | |
104 #define check_unop(op, a, min, max, overflow) \ | |
105 (INT_##op##_RANGE_OVERFLOW (a, min, max) == (overflow) \ | |
106 && INT_##op##_OVERFLOW (a) == (overflow)) | |
107 | |
108 /* INT_<op>_RANGE_OVERFLOW, INT_<op>_OVERFLOW. */ | |
109 verify (INT_ADD_RANGE_OVERFLOW (INT_MAX, 1, INT_MIN, INT_MAX)); | |
110 verify (INT_ADD_OVERFLOW (INT_MAX, 1)); | |
111 verify (check_binop (ADD, INT_MAX, 1, INT_MIN, INT_MAX, true)); | |
112 verify (check_binop (ADD, INT_MAX, -1, INT_MIN, INT_MAX, false)); | |
113 verify (check_binop (ADD, INT_MIN, 1, INT_MIN, INT_MAX, false)); | |
114 verify (check_binop (ADD, INT_MIN, -1, INT_MIN, INT_MAX, true)); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
115 verify (check_binop (ADD, UINT_MAX, U1, U0, UINT_MAX, true)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
116 verify (check_binop (ADD, U0, U1, U0, UINT_MAX, false)); |
14741 | 117 |
118 verify (check_binop (SUBTRACT, INT_MAX, 1, INT_MIN, INT_MAX, false)); | |
119 verify (check_binop (SUBTRACT, INT_MAX, -1, INT_MIN, INT_MAX, true)); | |
120 verify (check_binop (SUBTRACT, INT_MIN, 1, INT_MIN, INT_MAX, true)); | |
121 verify (check_binop (SUBTRACT, INT_MIN, -1, INT_MIN, INT_MAX, false)); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
122 verify (check_binop (SUBTRACT, UINT_MAX, U1, U0, UINT_MAX, false)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
123 verify (check_binop (SUBTRACT, U0, U1, U0, UINT_MAX, true)); |
14741 | 124 |
125 verify (check_unop (NEGATE, INT_MIN, INT_MIN, INT_MAX, | |
126 TYPE_TWOS_COMPLEMENT (int))); | |
127 verify (check_unop (NEGATE, 0, INT_MIN, INT_MAX, false)); | |
128 verify (check_unop (NEGATE, INT_MAX, INT_MIN, INT_MAX, false)); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
129 verify (check_unop (NEGATE, U0, U0, UINT_MAX, false)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
130 verify (check_unop (NEGATE, U1, U0, UINT_MAX, true)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
131 verify (check_unop (NEGATE, UINT_MAX, U0, UINT_MAX, true)); |
14741 | 132 |
133 verify (check_binop (MULTIPLY, INT_MAX, INT_MAX, INT_MIN, INT_MAX, true)); | |
134 verify (check_binop (MULTIPLY, INT_MAX, INT_MIN, INT_MIN, INT_MAX, true)); | |
135 verify (check_binop (MULTIPLY, INT_MIN, INT_MAX, INT_MIN, INT_MAX, true)); | |
136 verify (check_binop (MULTIPLY, INT_MIN, INT_MIN, INT_MIN, INT_MAX, true)); | |
137 verify (check_binop (MULTIPLY, -1, INT_MIN, INT_MIN, INT_MAX, | |
138 INT_NEGATE_OVERFLOW (INT_MIN))); | |
139 verify (check_binop (MULTIPLY, LONG_MIN / INT_MAX, (long int) INT_MAX, | |
140 LONG_MIN, LONG_MIN, false)); | |
141 | |
142 verify (check_binop (DIVIDE, INT_MIN, -1, INT_MIN, INT_MAX, | |
143 INT_NEGATE_OVERFLOW (INT_MIN))); | |
144 verify (check_binop (DIVIDE, INT_MAX, 1, INT_MIN, INT_MAX, false)); | |
145 verify (check_binop (DIVIDE, (unsigned int) INT_MIN, | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
146 -U1, U0, UINT_MAX, false)); |
14741 | 147 |
148 verify (check_binop (REMAINDER, INT_MIN, -1, INT_MIN, INT_MAX, | |
149 INT_NEGATE_OVERFLOW (INT_MIN))); | |
150 verify (check_binop (REMAINDER, INT_MAX, 1, INT_MIN, INT_MAX, false)); | |
151 verify (check_binop (REMAINDER, (unsigned int) INT_MIN, | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
152 -U1, U0, UINT_MAX, false)); |
14741 | 153 |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
154 verify (check_binop (LEFT_SHIFT, UINT_MAX, 1, U0, UINT_MAX, true)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
155 verify (check_binop (LEFT_SHIFT, UINT_MAX / 2 + 1, 1, U0, UINT_MAX, true)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
156 verify (check_binop (LEFT_SHIFT, UINT_MAX / 2, 1, U0, UINT_MAX, false)); |
14741 | 157 |
158 /* INT_<op>_OVERFLOW with mixed types. */ | |
159 #define check_sum(a, b, overflow) \ | |
160 verify (INT_ADD_OVERFLOW (a, b) == (overflow)); \ | |
161 verify (INT_ADD_OVERFLOW (b, a) == (overflow)) | |
162 check_sum (-1, LONG_MIN, true); | |
163 check_sum (-1, UINT_MAX, false); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
164 check_sum (- (long) 1, INT_MIN, INT_MIN == LONG_MIN); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
165 check_sum (U0, -1, true); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
166 check_sum (U0, 0, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
167 check_sum (U0, 1, false); |
14741 | 168 check_sum (1, LONG_MAX, true); |
169 check_sum (1, UINT_MAX, true); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
170 check_sum ((long) 1, INT_MAX, INT_MAX == LONG_MAX); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
171 check_sum (U1, INT_MAX, INT_MAX == UINT_MAX); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
172 check_sum (U1, INT_MIN, true); |
14741 | 173 |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
174 verify (! INT_SUBTRACT_OVERFLOW (INT_MAX, U1)); |
14741 | 175 verify (! INT_SUBTRACT_OVERFLOW (UINT_MAX, 1)); |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
176 verify (! INT_SUBTRACT_OVERFLOW (U0, -1)); |
14741 | 177 verify (INT_SUBTRACT_OVERFLOW (UINT_MAX, -1)); |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
178 verify (INT_SUBTRACT_OVERFLOW (INT_MIN, U1)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
179 verify (INT_SUBTRACT_OVERFLOW (-1, U0)); |
14741 | 180 |
181 #define check_product(a, b, overflow) \ | |
182 verify (INT_MULTIPLY_OVERFLOW (a, b) == (overflow)); \ | |
183 verify (INT_MULTIPLY_OVERFLOW (b, a) == (overflow)) | |
184 | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
185 check_product (-1, U1, true); |
14741 | 186 check_product (-1, INT_MIN, INT_NEGATE_OVERFLOW (INT_MIN)); |
187 check_product (-1, UINT_MAX, true); | |
188 check_product (-12345, LONG_MAX / -12345 - 1, true); | |
189 check_product (-12345, LONG_MAX / -12345, false); | |
190 check_product (0, -1, false); | |
191 check_product (0, 0, false); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
192 check_product (0, U0, false); |
14741 | 193 check_product (0, 1, false); |
194 check_product (0, INT_MAX, false); | |
195 check_product (0, INT_MIN, false); | |
196 check_product (0, UINT_MAX, false); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
197 check_product (U0, -1, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
198 check_product (U0, 0, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
199 check_product (U0, U0, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
200 check_product (U0, 1, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
201 check_product (U0, INT_MAX, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
202 check_product (U0, INT_MIN, false); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
203 check_product (U0, UINT_MAX, false); |
14741 | 204 check_product (1, INT_MAX, false); |
205 check_product (1, INT_MIN, false); | |
206 check_product (1, UINT_MAX, false); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
207 check_product (U1, INT_MIN, true); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
208 check_product (U1, INT_MAX, UINT_MAX < INT_MAX); |
14741 | 209 check_product (INT_MAX, UINT_MAX, true); |
210 check_product (INT_MAX, ULONG_MAX, true); | |
211 check_product (INT_MIN, LONG_MAX / INT_MIN - 1, true); | |
212 check_product (INT_MIN, LONG_MAX / INT_MIN, false); | |
213 check_product (INT_MIN, UINT_MAX, true); | |
214 check_product (INT_MIN, ULONG_MAX, true); | |
215 | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
216 verify (INT_DIVIDE_OVERFLOW (INT_MIN, - (long) 1) |
14741 | 217 == (TYPE_TWOS_COMPLEMENT (long int) && INT_MIN == LONG_MIN)); |
218 verify (! INT_DIVIDE_OVERFLOW (INT_MIN, UINT_MAX)); | |
219 verify (! INT_DIVIDE_OVERFLOW (INTMAX_MIN, UINTMAX_MAX)); | |
220 verify (! INT_DIVIDE_OVERFLOW (INTMAX_MIN, UINT_MAX)); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
221 verify (INT_DIVIDE_OVERFLOW (-11, (unsigned int) 10)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
222 verify (INT_DIVIDE_OVERFLOW (-10, (unsigned int) 10)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
223 verify (! INT_DIVIDE_OVERFLOW (-9, (unsigned int) 10)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
224 verify (INT_DIVIDE_OVERFLOW ((unsigned int) 11, -10)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
225 verify (INT_DIVIDE_OVERFLOW ((unsigned int) 10, -10)); |
14741 | 226 verify (! INT_DIVIDE_OVERFLOW (9u, -10)); |
227 | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
228 verify (INT_REMAINDER_OVERFLOW (INT_MIN, - (long) 1) |
14741 | 229 == (TYPE_TWOS_COMPLEMENT (long int) && INT_MIN == LONG_MIN)); |
230 verify (INT_REMAINDER_OVERFLOW (-1, UINT_MAX)); | |
231 verify (INT_REMAINDER_OVERFLOW ((intmax_t) -1, UINTMAX_MAX)); | |
232 verify (INT_REMAINDER_OVERFLOW (INTMAX_MIN, UINT_MAX) | |
233 == (INTMAX_MAX < UINT_MAX | |
234 && - (unsigned int) INTMAX_MIN % UINT_MAX != 0)); | |
235 verify (INT_REMAINDER_OVERFLOW (INT_MIN, ULONG_MAX) | |
236 == (INT_MIN % ULONG_MAX != 1)); | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
237 verify (! INT_REMAINDER_OVERFLOW (U1, -1)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
238 verify (! INT_REMAINDER_OVERFLOW (37 * (unsigned int) 39, -39)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
239 verify (INT_REMAINDER_OVERFLOW (37 * (unsigned int) 39 + 1, -39)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
240 verify (INT_REMAINDER_OVERFLOW (37 * (unsigned int) 39 - 1, -39)); |
14741 | 241 verify (! INT_REMAINDER_OVERFLOW (LONG_MAX, -INT_MAX)); |
242 | |
243 int | |
244 main (void) | |
245 { | |
14761
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
246 /* Test expressions that might not be integer constant expressions. */ |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
247 |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
248 /* TYPE_IS_INTEGER. */ |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
249 ASSERT (TYPE_IS_INTEGER (bool)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
250 ASSERT (TYPE_IS_INTEGER (char)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
251 ASSERT (TYPE_IS_INTEGER (signed char)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
252 ASSERT (TYPE_IS_INTEGER (unsigned char)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
253 ASSERT (TYPE_IS_INTEGER (short int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
254 ASSERT (TYPE_IS_INTEGER (unsigned short int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
255 ASSERT (TYPE_IS_INTEGER (int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
256 ASSERT (TYPE_IS_INTEGER (unsigned int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
257 ASSERT (TYPE_IS_INTEGER (long int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
258 ASSERT (TYPE_IS_INTEGER (unsigned long int)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
259 ASSERT (TYPE_IS_INTEGER (intmax_t)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
260 ASSERT (TYPE_IS_INTEGER (uintmax_t)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
261 ASSERT (! TYPE_IS_INTEGER (float)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
262 ASSERT (! TYPE_IS_INTEGER (double)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
263 ASSERT (! TYPE_IS_INTEGER (long double)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
264 |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
265 /* TYPE_SIGNED. */ |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
266 ASSERT (TYPE_SIGNED (float)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
267 ASSERT (TYPE_SIGNED (double)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
268 ASSERT (TYPE_SIGNED (long double)); |
6c5502aeb486
intprop-tests: port to older and more-pedantic compilers
Paul Eggert <eggert@cs.ucla.edu>
parents:
14741
diff
changeset
|
269 |
14741 | 270 return 0; |
271 } |