]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c-family/c-cppbuiltin.c
Update TEST_I_F calls in ARM fp-int-convert tests.
[thirdparty/gcc.git] / gcc / c-family / c-cppbuiltin.c
CommitLineData
cb60f38d 1/* Define builtin-in macros for the C family front ends.
818ab71a 2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
cb60f38d
NB
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
cb60f38d
NB
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
cb60f38d
NB
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
2adfab87 23#include "target.h"
2adfab87
AM
24#include "c-common.h"
25#include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */
d8a2d370 26#include "stringpool.h"
2adfab87 27#include "stor-layout.h"
cb60f38d 28#include "flags.h"
cb60f38d 29#include "c-pragma.h"
a4b7d13c 30#include "output.h" /* For user_label_prefix. */
f4ce02c5 31#include "debug.h" /* For dwarf2out_do_cfi_asm. */
677f3fa8 32#include "common/common-target.h"
8e680db5 33#include "cpp-id-data.h"
82a1c2fe 34#include "cppbuiltin.h"
cb60f38d 35
4e2e315f
NB
36#ifndef TARGET_OS_CPP_BUILTINS
37# define TARGET_OS_CPP_BUILTINS()
38#endif
39
40#ifndef TARGET_OBJFMT_CPP_BUILTINS
41# define TARGET_OBJFMT_CPP_BUILTINS()
42#endif
43
cb60f38d
NB
44#ifndef REGISTER_PREFIX
45#define REGISTER_PREFIX ""
46#endif
47
21282b1e 48/* Non-static as some targets don't use it. */
35b1a6fa
AJ
49static void builtin_define_with_hex_fp_value (const char *, tree,
50 int, const char *,
264c41ed 51 const char *,
35b1a6fa 52 const char *);
85291069 53static void builtin_define_stdint_macros (void);
207bf79d
JM
54static void builtin_define_constants (const char *, tree);
55static void builtin_define_type_max (const char *, tree);
56static void builtin_define_type_minmax (const char *, const char *, tree);
b8698a0f 57static void builtin_define_float_constants (const char *,
1b1562a5 58 const char *,
264c41ed
CD
59 const char *,
60 const char *,
35b1a6fa 61 tree);
cb60f38d 62
0069111f
MM
63/* Return true if MODE provides a fast multiply/add (FMA) builtin function.
64 Originally this function used the fma optab, but that doesn't work with
65 -save-temps, so just rely on the HAVE_fma macros for the standard floating
66 point types. */
67
68static bool
ef4bddc2 69mode_has_fma (machine_mode mode)
0069111f
MM
70{
71 switch (mode)
72 {
73#ifdef HAVE_fmasf4
74 case SFmode:
75 return !!HAVE_fmasf4;
76#endif
77
78#ifdef HAVE_fmadf4
79 case DFmode:
80 return !!HAVE_fmadf4;
81#endif
82
83#ifdef HAVE_fmaxf4
84 case XFmode:
85 return !!HAVE_fmaxf4;
86#endif
87
88#ifdef HAVE_fmatf4
89 case TFmode:
90 return !!HAVE_fmatf4;
91#endif
92
93 default:
94 break;
95 }
96
97 return false;
98}
99
024a85ae 100/* Define NAME with value TYPE size_unit. */
7049e4eb 101void
024a85ae
AK
102builtin_define_type_sizeof (const char *name, tree type)
103{
104 builtin_define_with_int_value (name,
ae7e9ddd 105 tree_to_uhwi (TYPE_SIZE_UNIT (type)));
024a85ae
AK
106}
107
264c41ed
CD
108/* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
109 and FP_CAST. */
cb60f38d 110static void
b8698a0f
L
111builtin_define_float_constants (const char *name_prefix,
112 const char *fp_suffix,
113 const char *fp_cast,
1b1562a5 114 const char *fma_suffix,
264c41ed 115 tree type)
cb60f38d
NB
116{
117 /* Used to convert radix-based values to base 10 values in several cases.
118
119 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
120 least 6 significant digits for correct results. Using the fraction
121 formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
122 intermediate; perhaps someone can find a better approximation, in the
123 mean time, I suspect using doubles won't harm the bootstrap here. */
124
125 const double log10_2 = .30102999566398119521;
126 double log10_b;
127 const struct real_format *fmt;
c65699ef 128 const struct real_format *widefmt;
cb60f38d
NB
129
130 char name[64], buf[128];
131 int dig, min_10_exp, max_10_exp;
132 int decimal_dig;
2778d766 133 int type_decimal_dig;
cb60f38d 134
70a01792 135 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
9a8ce21f 136 gcc_assert (fmt->b != 10);
c65699ef
JM
137 widefmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node));
138 gcc_assert (widefmt->b != 10);
139 for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
140 {
141 tree wtype = FLOATN_NX_TYPE_NODE (i);
142 if (wtype != NULL_TREE)
143 {
144 const struct real_format *wfmt
145 = REAL_MODE_FORMAT (TYPE_MODE (wtype));
146 gcc_assert (wfmt->b != 10);
147 if (wfmt->p > widefmt->p)
148 widefmt = wfmt;
149 }
150 }
cb60f38d
NB
151
152 /* The radix of the exponent representation. */
153 if (type == float_type_node)
154 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
4d8a8a0a 155 log10_b = log10_2;
cb60f38d
NB
156
157 /* The number of radix digits, p, in the floating-point significand. */
158 sprintf (name, "__%s_MANT_DIG__", name_prefix);
159 builtin_define_with_int_value (name, fmt->p);
160
161 /* The number of decimal digits, q, such that any floating-point number
162 with q decimal digits can be rounded into a floating-point number with
163 p radix b digits and back again without change to the q decimal digits,
164
165 p log10 b if b is a power of 10
35b1a6fa 166 floor((p - 1) log10 b) otherwise
cb60f38d
NB
167 */
168 dig = (fmt->p - 1) * log10_b;
169 sprintf (name, "__%s_DIG__", name_prefix);
170 builtin_define_with_int_value (name, dig);
171
172 /* The minimum negative int x such that b**(x-1) is a normalized float. */
173 sprintf (name, "__%s_MIN_EXP__", name_prefix);
174 sprintf (buf, "(%d)", fmt->emin);
175 builtin_define_with_value (name, buf, 0);
176
177 /* The minimum negative int x such that 10**x is a normalized float,
178
179 ceil (log10 (b ** (emin - 1)))
180 = ceil (log10 (b) * (emin - 1))
181
182 Recall that emin is negative, so the integer truncation calculates
183 the ceiling, not the floor, in this case. */
184 min_10_exp = (fmt->emin - 1) * log10_b;
185 sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
186 sprintf (buf, "(%d)", min_10_exp);
187 builtin_define_with_value (name, buf, 0);
188
189 /* The maximum int x such that b**(x-1) is a representable float. */
190 sprintf (name, "__%s_MAX_EXP__", name_prefix);
191 builtin_define_with_int_value (name, fmt->emax);
192
193 /* The maximum int x such that 10**x is in the range of representable
194 finite floating-point numbers,
195
196 floor (log10((1 - b**-p) * b**emax))
197 = floor (log10(1 - b**-p) + log10(b**emax))
198 = floor (log10(1 - b**-p) + log10(b)*emax)
199
200 The safest thing to do here is to just compute this number. But since
201 we don't link cc1 with libm, we cannot. We could implement log10 here
202 a series expansion, but that seems too much effort because:
203
204 Note that the first term, for all extant p, is a number exceedingly close
205 to zero, but slightly negative. Note that the second term is an integer
206 scaling an irrational number, and that because of the floor we are only
207 interested in its integral portion.
208
209 In order for the first term to have any effect on the integral portion
210 of the second term, the second term has to be exceedingly close to an
211 integer itself (e.g. 123.000000000001 or something). Getting a result
212 that close to an integer requires that the irrational multiplicand have
213 a long series of zeros in its expansion, which doesn't occur in the
214 first 20 digits or so of log10(b).
215
216 Hand-waving aside, crunching all of the sets of constants above by hand
217 does not yield a case for which the first term is significant, which
218 in the end is all that matters. */
219 max_10_exp = fmt->emax * log10_b;
220 sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
221 builtin_define_with_int_value (name, max_10_exp);
222
223 /* The number of decimal digits, n, such that any floating-point number
224 can be rounded to n decimal digits and back again without change to
35b1a6fa 225 the value.
cb60f38d
NB
226
227 p * log10(b) if b is a power of 10
228 ceil(1 + p * log10(b)) otherwise
229
230 The only macro we care about is this number for the widest supported
231 floating type, but we want this value for rendering constants below. */
232 {
8ce94e44 233 double d_decimal_dig
c65699ef 234 = 1 + (fmt->p < widefmt->p ? widefmt->p : fmt->p) * log10_b;
cb60f38d
NB
235 decimal_dig = d_decimal_dig;
236 if (decimal_dig < d_decimal_dig)
237 decimal_dig++;
238 }
2778d766
JM
239 /* Similar, for this type rather than long double. */
240 {
241 double type_d_decimal_dig = 1 + fmt->p * log10_b;
242 type_decimal_dig = type_d_decimal_dig;
243 if (type_decimal_dig < type_d_decimal_dig)
244 type_decimal_dig++;
245 }
c65699ef
JM
246 /* Arbitrarily, define __DECIMAL_DIG__ when defining macros for long
247 double, although it may be greater than the value for long
248 double. */
cb60f38d
NB
249 if (type == long_double_type_node)
250 builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
c65699ef
JM
251 sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
252 builtin_define_with_int_value (name, type_decimal_dig);
cb60f38d
NB
253
254 /* Since, for the supported formats, B is always a power of 2, we
255 construct the following numbers directly as a hexadecimal
256 constants. */
7faa1bbb 257 get_max_float (fmt, buf, sizeof (buf));
b8698a0f 258
cb60f38d 259 sprintf (name, "__%s_MAX__", name_prefix);
264c41ed 260 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
cb60f38d
NB
261
262 /* The minimum normalized positive floating-point number,
263 b**(emin-1). */
264 sprintf (name, "__%s_MIN__", name_prefix);
4d8a8a0a 265 sprintf (buf, "0x1p%d", fmt->emin - 1);
264c41ed 266 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
cb60f38d
NB
267
268 /* The difference between 1 and the least value greater than 1 that is
269 representable in the given floating point type, b**(1-p). */
270 sprintf (name, "__%s_EPSILON__", name_prefix);
59d7d767
GK
271 if (fmt->pnan < fmt->p)
272 /* This is an IBM extended double format, so 1.0 + any double is
273 representable precisely. */
4d8a8a0a 274 sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
c22cacf3 275 else
4d8a8a0a 276 sprintf (buf, "0x1p%d", 1 - fmt->p);
264c41ed 277 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
cb60f38d 278
179b5a55
MG
279 /* For C++ std::numeric_limits<T>::denorm_min and C11 *_TRUE_MIN.
280 The minimum denormalized positive floating-point number, b**(emin-p).
281 The minimum normalized positive floating-point number for formats
282 that don't support denormals. */
cb60f38d 283 sprintf (name, "__%s_DENORM_MIN__", name_prefix);
179b5a55
MG
284 sprintf (buf, "0x1p%d", fmt->emin - (fmt->has_denorm ? fmt->p : 1));
285 builtin_define_with_hex_fp_value (name, type, decimal_dig,
286 buf, fp_suffix, fp_cast);
cb60f38d 287
264c41ed
CD
288 sprintf (name, "__%s_HAS_DENORM__", name_prefix);
289 builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
290
cb60f38d
NB
291 /* For C++ std::numeric_limits<T>::has_infinity. */
292 sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
35b1a6fa 293 builtin_define_with_int_value (name,
cb60f38d
NB
294 MODE_HAS_INFINITIES (TYPE_MODE (type)));
295 /* For C++ std::numeric_limits<T>::has_quiet_NaN. We do not have a
296 predicate to distinguish a target that has both quiet and
297 signalling NaNs from a target that has only quiet NaNs or only
298 signalling NaNs, so we assume that a target that has any kind of
299 NaN has quiet NaNs. */
300 sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
301 builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
1b1562a5
MM
302
303 /* Note whether we have fast FMA. */
c65699ef 304 if (mode_has_fma (TYPE_MODE (type)) && fma_suffix != NULL)
1b1562a5
MM
305 {
306 sprintf (name, "__FP_FAST_FMA%s", fma_suffix);
307 builtin_define_with_int_value (name, 1);
308 }
cb60f38d
NB
309}
310
9a8ce21f
JG
311/* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
312static void
b8698a0f
L
313builtin_define_decimal_float_constants (const char *name_prefix,
314 const char *suffix,
9a8ce21f
JG
315 tree type)
316{
317 const struct real_format *fmt;
318 char name[64], buf[128], *p;
319 int digits;
320
321 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
322
323 /* The number of radix digits, p, in the significand. */
324 sprintf (name, "__%s_MANT_DIG__", name_prefix);
325 builtin_define_with_int_value (name, fmt->p);
326
327 /* The minimum negative int x such that b**(x-1) is a normalized float. */
328 sprintf (name, "__%s_MIN_EXP__", name_prefix);
329 sprintf (buf, "(%d)", fmt->emin);
330 builtin_define_with_value (name, buf, 0);
331
332 /* The maximum int x such that b**(x-1) is a representable float. */
333 sprintf (name, "__%s_MAX_EXP__", name_prefix);
334 builtin_define_with_int_value (name, fmt->emax);
335
336 /* Compute the minimum representable value. */
337 sprintf (name, "__%s_MIN__", name_prefix);
c52ec948 338 sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
b8698a0f 339 builtin_define_with_value (name, buf, 0);
9a8ce21f
JG
340
341 /* Compute the maximum representable value. */
342 sprintf (name, "__%s_MAX__", name_prefix);
343 p = buf;
344 for (digits = fmt->p; digits; digits--)
345 {
346 *p++ = '9';
347 if (digits == fmt->p)
348 *p++ = '.';
349 }
350 *p = 0;
c52ec948
JJ
351 /* fmt->p plus 1, to account for the decimal point and fmt->emax
352 minus 1 because the digits are nines, not 1.0. */
b8698a0f 353 sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix);
9a8ce21f
JG
354 builtin_define_with_value (name, buf, 0);
355
356 /* Compute epsilon (the difference between 1 and least value greater
357 than 1 representable). */
358 sprintf (name, "__%s_EPSILON__", name_prefix);
359 sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
360 builtin_define_with_value (name, buf, 0);
361
c52ec948
JJ
362 /* Minimum subnormal positive decimal value. */
363 sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
9a8ce21f
JG
364 p = buf;
365 for (digits = fmt->p; digits > 1; digits--)
366 {
367 *p++ = '0';
368 if (digits == fmt->p)
369 *p++ = '.';
370 }
371 *p = 0;
b8698a0f 372 sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix);
9a8ce21f
JG
373 builtin_define_with_value (name, buf, 0);
374}
375
0f996086
CF
376/* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */
377
378static void
379builtin_define_fixed_point_constants (const char *name_prefix,
380 const char *suffix,
381 tree type)
382{
383 char name[64], buf[256], *new_buf;
384 int i, mod;
385
386 sprintf (name, "__%s_FBIT__", name_prefix);
387 builtin_define_with_int_value (name, TYPE_FBIT (type));
388
389 sprintf (name, "__%s_IBIT__", name_prefix);
390 builtin_define_with_int_value (name, TYPE_IBIT (type));
391
392 /* If there is no suffix, defines are for fixed-point modes.
393 We just return. */
394 if (strcmp (suffix, "") == 0)
395 return;
396
397 if (TYPE_UNSIGNED (type))
398 {
399 sprintf (name, "__%s_MIN__", name_prefix);
400 sprintf (buf, "0.0%s", suffix);
401 builtin_define_with_value (name, buf, 0);
402 }
403 else
404 {
405 sprintf (name, "__%s_MIN__", name_prefix);
406 if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
407 sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
408 TYPE_IBIT (type) - 1, suffix);
409 else
410 sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
411 builtin_define_with_value (name, buf, 0);
412 }
413
414 sprintf (name, "__%s_MAX__", name_prefix);
415 sprintf (buf, "0X");
416 new_buf = buf + 2;
417 mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
418 if (mod)
419 sprintf (new_buf++, "%x", (1 << mod) - 1);
420 for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
421 sprintf (new_buf++, "F");
422 sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
423 builtin_define_with_value (name, buf, 0);
424
425 sprintf (name, "__%s_EPSILON__", name_prefix);
426 sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
427 builtin_define_with_value (name, buf, 0);
428}
429
207bf79d 430/* Define macros used by <stdint.h>. */
85291069
JM
431static void
432builtin_define_stdint_macros (void)
433{
207bf79d
JM
434 builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node);
435 builtin_define_constants ("__INTMAX_C", intmax_type_node);
436 builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node);
437 builtin_define_constants ("__UINTMAX_C", uintmax_type_node);
438 if (sig_atomic_type_node)
439 builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__",
440 sig_atomic_type_node);
441 if (int8_type_node)
442 builtin_define_type_max ("__INT8_MAX__", int8_type_node);
443 if (int16_type_node)
444 builtin_define_type_max ("__INT16_MAX__", int16_type_node);
445 if (int32_type_node)
446 builtin_define_type_max ("__INT32_MAX__", int32_type_node);
447 if (int64_type_node)
448 builtin_define_type_max ("__INT64_MAX__", int64_type_node);
449 if (uint8_type_node)
450 builtin_define_type_max ("__UINT8_MAX__", uint8_type_node);
ac868f29
EB
451 if (c_uint16_type_node)
452 builtin_define_type_max ("__UINT16_MAX__", c_uint16_type_node);
207bf79d
JM
453 if (c_uint32_type_node)
454 builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node);
455 if (c_uint64_type_node)
456 builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node);
457 if (int_least8_type_node)
458 {
459 builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node);
460 builtin_define_constants ("__INT8_C", int_least8_type_node);
461 }
462 if (int_least16_type_node)
463 {
464 builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node);
465 builtin_define_constants ("__INT16_C", int_least16_type_node);
466 }
467 if (int_least32_type_node)
468 {
469 builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node);
470 builtin_define_constants ("__INT32_C", int_least32_type_node);
471 }
472 if (int_least64_type_node)
473 {
474 builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node);
475 builtin_define_constants ("__INT64_C", int_least64_type_node);
476 }
477 if (uint_least8_type_node)
478 {
479 builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node);
480 builtin_define_constants ("__UINT8_C", uint_least8_type_node);
481 }
482 if (uint_least16_type_node)
483 {
484 builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node);
485 builtin_define_constants ("__UINT16_C", uint_least16_type_node);
486 }
487 if (uint_least32_type_node)
488 {
489 builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node);
490 builtin_define_constants ("__UINT32_C", uint_least32_type_node);
491 }
492 if (uint_least64_type_node)
493 {
494 builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node);
495 builtin_define_constants ("__UINT64_C", uint_least64_type_node);
496 }
497 if (int_fast8_type_node)
498 builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node);
499 if (int_fast16_type_node)
500 builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node);
501 if (int_fast32_type_node)
502 builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node);
503 if (int_fast64_type_node)
504 builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node);
505 if (uint_fast8_type_node)
506 builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node);
507 if (uint_fast16_type_node)
508 builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node);
509 if (uint_fast32_type_node)
510 builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node);
511 if (uint_fast64_type_node)
512 builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node);
513 if (intptr_type_node)
514 builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node);
515 if (uintptr_type_node)
516 builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node);
85291069
JM
517}
518
ab442df7
MM
519/* Adjust the optimization macros when a #pragma GCC optimization is done to
520 reflect the current level. */
521void
522c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
523 tree cur_tree)
524{
525 struct cl_optimization *prev = TREE_OPTIMIZATION (prev_tree);
526 struct cl_optimization *cur = TREE_OPTIMIZATION (cur_tree);
527 bool prev_fast_math;
528 bool cur_fast_math;
529
530 /* -undef turns off target-specific built-ins. */
531 if (flag_undef)
532 return;
533
534 /* Other target-independent built-ins determined by command-line
535 options. */
e3339d0f 536 if (!prev->x_optimize_size && cur->x_optimize_size)
ab442df7 537 cpp_define (pfile, "__OPTIMIZE_SIZE__");
e3339d0f 538 else if (prev->x_optimize_size && !cur->x_optimize_size)
ab442df7
MM
539 cpp_undef (pfile, "__OPTIMIZE_SIZE__");
540
e3339d0f 541 if (!prev->x_optimize && cur->x_optimize)
ab442df7 542 cpp_define (pfile, "__OPTIMIZE__");
e3339d0f 543 else if (prev->x_optimize && !cur->x_optimize)
ab442df7
MM
544 cpp_undef (pfile, "__OPTIMIZE__");
545
546 prev_fast_math = fast_math_flags_struct_set_p (prev);
547 cur_fast_math = fast_math_flags_struct_set_p (cur);
548 if (!prev_fast_math && cur_fast_math)
549 cpp_define (pfile, "__FAST_MATH__");
550 else if (prev_fast_math && !cur_fast_math)
551 cpp_undef (pfile, "__FAST_MATH__");
552
e3339d0f 553 if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
ab442df7 554 cpp_define (pfile, "__SUPPORT_SNAN__");
e3339d0f 555 else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
ab442df7
MM
556 cpp_undef (pfile, "__SUPPORT_SNAN__");
557
2079956a
JM
558 if (!prev->x_flag_errno_math && cur->x_flag_errno_math)
559 cpp_undef (pfile, "__NO_MATH_ERRNO__");
560 else if (prev->x_flag_errno_math && !cur->x_flag_errno_math)
561 cpp_define (pfile, "__NO_MATH_ERRNO__");
562
e3339d0f 563 if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
ab442df7
MM
564 {
565 cpp_undef (pfile, "__FINITE_MATH_ONLY__");
566 cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
567 }
0e3fdb48 568 else if (prev->x_flag_finite_math_only && !cur->x_flag_finite_math_only)
ab442df7
MM
569 {
570 cpp_undef (pfile, "__FINITE_MATH_ONLY__");
571 cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
572 }
573}
574
575
62bad7cd
AM
576/* This function will emit cpp macros to indicate the presence of various lock
577 free atomic operations. */
578
579static void
580cpp_atomic_builtins (cpp_reader *pfile)
581{
582 /* Set a flag for each size of object that compare and swap exists for up to
583 a 16 byte object. */
584#define SWAP_LIMIT 17
585 bool have_swap[SWAP_LIMIT];
586 unsigned int psize;
587
588 /* Clear the map of sizes compare_and swap exists for. */
589 memset (have_swap, 0, sizeof (have_swap));
590
591 /* Tell source code if the compiler makes sync_compare_and_swap
592 builtins available. */
593#ifndef HAVE_sync_compare_and_swapqi
594#define HAVE_sync_compare_and_swapqi 0
595#endif
596#ifndef HAVE_atomic_compare_and_swapqi
597#define HAVE_atomic_compare_and_swapqi 0
598#endif
599
600 if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
601 {
602 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
603 have_swap[1] = true;
604 }
605
606#ifndef HAVE_sync_compare_and_swaphi
607#define HAVE_sync_compare_and_swaphi 0
608#endif
609#ifndef HAVE_atomic_compare_and_swaphi
610#define HAVE_atomic_compare_and_swaphi 0
611#endif
612 if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
613 {
614 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
615 have_swap[2] = true;
616 }
617
618#ifndef HAVE_sync_compare_and_swapsi
619#define HAVE_sync_compare_and_swapsi 0
620#endif
621#ifndef HAVE_atomic_compare_and_swapsi
622#define HAVE_atomic_compare_and_swapsi 0
623#endif
624 if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
625 {
626 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
627 have_swap[4] = true;
628 }
629
630#ifndef HAVE_sync_compare_and_swapdi
631#define HAVE_sync_compare_and_swapdi 0
632#endif
633#ifndef HAVE_atomic_compare_and_swapdi
634#define HAVE_atomic_compare_and_swapdi 0
635#endif
636 if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
637 {
638 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
639 have_swap[8] = true;
640 }
641
642#ifndef HAVE_sync_compare_and_swapti
643#define HAVE_sync_compare_and_swapti 0
644#endif
645#ifndef HAVE_atomic_compare_and_swapti
646#define HAVE_atomic_compare_and_swapti 0
647#endif
648 if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
649 {
650 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
651 have_swap[16] = true;
652 }
653
48b0b196 654 /* Tell the source code about various types. These map to the C++11 and C11
62bad7cd
AM
655 macros where 2 indicates lock-free always, and 1 indicates sometimes
656 lock free. */
ae7e9ddd 657#define SIZEOF_NODE(T) (tree_to_uhwi (TYPE_SIZE_UNIT (T)))
62bad7cd
AM
658#define SWAP_INDEX(T) ((SIZEOF_NODE (T) < SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
659 builtin_define_with_int_value ("__GCC_ATOMIC_BOOL_LOCK_FREE",
660 (have_swap[SWAP_INDEX (boolean_type_node)]? 2 : 1));
661 builtin_define_with_int_value ("__GCC_ATOMIC_CHAR_LOCK_FREE",
662 (have_swap[SWAP_INDEX (signed_char_type_node)]? 2 : 1));
663 builtin_define_with_int_value ("__GCC_ATOMIC_CHAR16_T_LOCK_FREE",
664 (have_swap[SWAP_INDEX (char16_type_node)]? 2 : 1));
665 builtin_define_with_int_value ("__GCC_ATOMIC_CHAR32_T_LOCK_FREE",
666 (have_swap[SWAP_INDEX (char32_type_node)]? 2 : 1));
667 builtin_define_with_int_value ("__GCC_ATOMIC_WCHAR_T_LOCK_FREE",
668 (have_swap[SWAP_INDEX (wchar_type_node)]? 2 : 1));
669 builtin_define_with_int_value ("__GCC_ATOMIC_SHORT_LOCK_FREE",
670 (have_swap[SWAP_INDEX (short_integer_type_node)]? 2 : 1));
671 builtin_define_with_int_value ("__GCC_ATOMIC_INT_LOCK_FREE",
672 (have_swap[SWAP_INDEX (integer_type_node)]? 2 : 1));
673 builtin_define_with_int_value ("__GCC_ATOMIC_LONG_LOCK_FREE",
674 (have_swap[SWAP_INDEX (long_integer_type_node)]? 2 : 1));
675 builtin_define_with_int_value ("__GCC_ATOMIC_LLONG_LOCK_FREE",
676 (have_swap[SWAP_INDEX (long_long_integer_type_node)]? 2 : 1));
677
57c5ab1b
RH
678 /* If we're dealing with a "set" value that doesn't exactly correspond
679 to a boolean truth value, let the library work around that. */
680 builtin_define_with_int_value ("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL",
681 targetm.atomic_test_and_set_trueval);
682
62bad7cd
AM
683 /* ptr_type_node can't be used here since ptr_mode is only set when
684 toplev calls backend_init which is not done with -E or pch. */
5b8300ea 685 psize = POINTER_SIZE_UNITS;
62bad7cd
AM
686 if (psize >= SWAP_LIMIT)
687 psize = 0;
688 builtin_define_with_int_value ("__GCC_ATOMIC_POINTER_LOCK_FREE",
689 (have_swap[psize]? 2 : 1));
690}
691
9193fb05
JM
692/* Return the value for __GCC_IEC_559. */
693static int
694cpp_iec_559_value (void)
695{
696 /* The default is support for IEEE 754-2008. */
697 int ret = 2;
698
699 /* float and double must be binary32 and binary64. If they are but
700 with reversed NaN convention, at most IEEE 754-1985 is
701 supported. */
702 const struct real_format *ffmt
703 = REAL_MODE_FORMAT (TYPE_MODE (float_type_node));
704 const struct real_format *dfmt
705 = REAL_MODE_FORMAT (TYPE_MODE (double_type_node));
706 if (!ffmt->qnan_msb_set || !dfmt->qnan_msb_set)
707 ret = 1;
708 if (ffmt->b != 2
709 || ffmt->p != 24
710 || ffmt->pnan != 24
711 || ffmt->emin != -125
712 || ffmt->emax != 128
713 || ffmt->signbit_rw != 31
714 || ffmt->round_towards_zero
715 || !ffmt->has_sign_dependent_rounding
716 || !ffmt->has_nans
717 || !ffmt->has_inf
718 || !ffmt->has_denorm
719 || !ffmt->has_signed_zero
720 || dfmt->b != 2
721 || dfmt->p != 53
722 || dfmt->pnan != 53
723 || dfmt->emin != -1021
724 || dfmt->emax != 1024
725 || dfmt->signbit_rw != 63
726 || dfmt->round_towards_zero
727 || !dfmt->has_sign_dependent_rounding
728 || !dfmt->has_nans
729 || !dfmt->has_inf
730 || !dfmt->has_denorm
731 || !dfmt->has_signed_zero)
732 ret = 0;
733
734 /* In strict C standards conformance mode, consider unpredictable
6dbe0958
JM
735 excess precision to mean lack of IEEE 754 support. The same
736 applies to unpredictable contraction. For C++, and outside
737 strict conformance mode, do not consider these options to mean
738 lack of IEEE 754 support. */
9193fb05
JM
739 if (flag_iso
740 && !c_dialect_cxx ()
741 && TARGET_FLT_EVAL_METHOD != 0
254a0760 742 && flag_excess_precision_cmdline != EXCESS_PRECISION_STANDARD)
9193fb05 743 ret = 0;
6dbe0958
JM
744 if (flag_iso
745 && !c_dialect_cxx ()
746 && flag_fp_contract_mode == FP_CONTRACT_FAST)
747 ret = 0;
9193fb05
JM
748
749 /* Various options are contrary to IEEE 754 semantics. */
750 if (flag_unsafe_math_optimizations
751 || flag_associative_math
752 || flag_reciprocal_math
753 || flag_finite_math_only
754 || !flag_signed_zeros
755 || flag_single_precision_constant)
756 ret = 0;
757
758 /* If the target does not support IEEE 754 exceptions and rounding
759 modes, consider IEEE 754 support to be absent. */
760 if (!targetm.float_exceptions_rounding_supported_p ())
761 ret = 0;
762
763 return ret;
764}
765
766/* Return the value for __GCC_IEC_559_COMPLEX. */
767static int
768cpp_iec_559_complex_value (void)
769{
770 /* The value is no bigger than that of __GCC_IEC_559. */
771 int ret = cpp_iec_559_value ();
772
773 /* Some options are contrary to the required default state of the
774 CX_LIMITED_RANGE pragma. */
775 if (flag_complex_method != 2)
776 ret = 0;
777
778 return ret;
779}
780
cb60f38d
NB
781/* Hook that registers front end and target-specific built-ins. */
782void
35b1a6fa 783c_cpp_builtins (cpp_reader *pfile)
cb60f38d 784{
78a7c317
DD
785 int i;
786
cb60f38d
NB
787 /* -undef turns off target-specific built-ins. */
788 if (flag_undef)
789 return;
790
82a1c2fe
FXC
791 define_language_independent_builtin_macros (pfile);
792
793 if (c_dialect_cxx ())
794 {
795 int major;
796 parse_basever (&major, NULL, NULL);
797 cpp_define_formatted (pfile, "__GNUG__=%d", major);
798 }
cb60f38d
NB
799
800 /* For stddef.h. They require macros defined in c-common.c. */
801 c_stddef_cpp_builtins ();
802
a15f7cb8 803 /* Set include test macros for all C/C++ (not for just C++11 etc.)
42fd12b1 804 The builtins __has_include__ and __has_include_next__ are defined
a15f7cb8
ESR
805 in libcpp. */
806 cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
807 cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
808
37fa72e9 809 if (c_dialect_cxx ())
cb60f38d 810 {
c22cacf3 811 if (flag_weak && SUPPORTS_ONE_ONLY)
cb60f38d
NB
812 cpp_define (pfile, "__GXX_WEAK__=1");
813 else
814 cpp_define (pfile, "__GXX_WEAK__=0");
a15f7cb8 815
cb60f38d
NB
816 if (warn_deprecated)
817 cpp_define (pfile, "__DEPRECATED");
a15f7cb8 818
ba551ec2 819 if (flag_rtti)
42fd12b1
ESR
820 {
821 cpp_define (pfile, "__GXX_RTTI");
822 cpp_define (pfile, "__cpp_rtti=199711");
823 }
a15f7cb8 824
604b2bfc 825 if (cxx_dialect >= cxx11)
c573f4d5 826 cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
a15f7cb8
ESR
827
828 /* Binary literals have been allowed in g++ before C++11
829 and were standardized for C++14. */
830 if (!pedantic || cxx_dialect > cxx11)
831 cpp_define (pfile, "__cpp_binary_literals=201304");
94a073b2 832
2aaeea19
JM
833 /* Similarly for hexadecimal floating point literals and C++17. */
834 if (!pedantic || cpp_get_options (parse_in)->extended_numbers)
835 cpp_define (pfile, "__cpp_hex_float=201603");
836
94a073b2
JM
837 /* Arrays of runtime bound were removed from C++14, but we still
838 support GNU VLAs. Let's define this macro to a low number
839 (corresponding to the initial test release of GNU C++) if we won't
840 complain about use of VLAs. */
841 if (c_dialect_cxx ()
842 && (pedantic ? warn_vla == 0 : warn_vla <= 0))
843 cpp_define (pfile, "__cpp_runtime_arrays=198712");
844
a15f7cb8
ESR
845 if (cxx_dialect >= cxx11)
846 {
329524f5 847 /* Set feature test macros for C++11. */
13b380a3
JM
848 if (cxx_dialect <= cxx14)
849 cpp_define (pfile, "__cpp_unicode_characters=200704");
a15f7cb8
ESR
850 cpp_define (pfile, "__cpp_raw_strings=200710");
851 cpp_define (pfile, "__cpp_unicode_literals=200710");
852 cpp_define (pfile, "__cpp_user_defined_literals=200809");
853 cpp_define (pfile, "__cpp_lambdas=200907");
acaa5911
JM
854 if (cxx_dialect == cxx11)
855 cpp_define (pfile, "__cpp_constexpr=200704");
9aa36ae5
JM
856 if (cxx_dialect <= cxx14)
857 cpp_define (pfile, "__cpp_range_based_for=200907");
329524f5
PC
858 if (cxx_dialect <= cxx14)
859 cpp_define (pfile, "__cpp_static_assert=200410");
a15f7cb8
ESR
860 cpp_define (pfile, "__cpp_decltype=200707");
861 cpp_define (pfile, "__cpp_attributes=200809");
862 cpp_define (pfile, "__cpp_rvalue_reference=200610");
98d44e93 863 cpp_define (pfile, "__cpp_rvalue_references=200610");
a15f7cb8 864 cpp_define (pfile, "__cpp_variadic_templates=200704");
42fd12b1
ESR
865 cpp_define (pfile, "__cpp_initializer_lists=200806");
866 cpp_define (pfile, "__cpp_delegating_constructors=200604");
867 cpp_define (pfile, "__cpp_nsdmi=200809");
868 cpp_define (pfile, "__cpp_inheriting_constructors=200802");
869 cpp_define (pfile, "__cpp_ref_qualifiers=200710");
a15f7cb8
ESR
870 cpp_define (pfile, "__cpp_alias_templates=200704");
871 }
872 if (cxx_dialect > cxx11)
873 {
329524f5 874 /* Set feature test macros for C++14. */
a15f7cb8
ESR
875 cpp_define (pfile, "__cpp_return_type_deduction=201304");
876 cpp_define (pfile, "__cpp_init_captures=201304");
877 cpp_define (pfile, "__cpp_generic_lambdas=201304");
98e5a19a
JM
878 if (cxx_dialect <= cxx14)
879 cpp_define (pfile, "__cpp_constexpr=201304");
a15f7cb8 880 cpp_define (pfile, "__cpp_decltype_auto=201304");
26f0e1d6 881 cpp_define (pfile, "__cpp_aggregate_nsdmi=201304");
a15f7cb8
ESR
882 cpp_define (pfile, "__cpp_variable_templates=201304");
883 cpp_define (pfile, "__cpp_digit_separators=201309");
a15f7cb8 884 }
329524f5
PC
885 if (cxx_dialect > cxx14)
886 {
887 /* Set feature test macros for C++1z. */
13b380a3 888 cpp_define (pfile, "__cpp_unicode_characters=201411");
329524f5 889 cpp_define (pfile, "__cpp_static_assert=201411");
bdaaa8b7 890 cpp_define (pfile, "__cpp_namespace_attributes=201411");
13b380a3 891 cpp_define (pfile, "__cpp_enumerator_attributes=201411");
bdaaa8b7 892 cpp_define (pfile, "__cpp_nested_namespace_definitions=201411");
08a1cadc 893 cpp_define (pfile, "__cpp_fold_expressions=201603");
2a9fb712 894 cpp_define (pfile, "__cpp_nontype_template_args=201411");
9aa36ae5 895 cpp_define (pfile, "__cpp_range_based_for=201603");
98e5a19a 896 cpp_define (pfile, "__cpp_constexpr=201603");
452df4a4 897 cpp_define (pfile, "__cpp_if_constexpr=201606");
329524f5 898 }
971e17ff
AS
899 if (flag_concepts)
900 /* Use a value smaller than the 201507 specified in
901 the TS, since we don't yet support extended auto. */
902 cpp_define (pfile, "__cpp_concepts=201500");
b8fd7909
JM
903 if (flag_tm)
904 /* Use a value smaller than the 201505 specified in
905 the TS, since we don't yet support atomic_cancel. */
906 cpp_define (pfile, "__cpp_transactional_memory=210500");
a7fa8d18
ESR
907 if (flag_sized_deallocation)
908 cpp_define (pfile, "__cpp_sized_deallocation=201309");
cb60f38d 909 }
6cd77c3f
RH
910 /* Note that we define this for C as well, so that we know if
911 __attribute__((cleanup)) will interface with EH. */
2288bdbb 912 if (flag_exceptions)
42fd12b1
ESR
913 {
914 cpp_define (pfile, "__EXCEPTIONS");
915 if (c_dialect_cxx ())
916 cpp_define (pfile, "__cpp_exceptions=199711");
917 }
cb60f38d 918
e0a21ab9 919 /* Represents the C++ ABI version, always defined so it can be used while
cb60f38d 920 preprocessing C and assembler. */
57702a80 921 if (flag_abi_version == 0)
785f21af
JM
922 /* We should have set this to something real in c_common_post_options. */
923 gcc_unreachable ();
57702a80 924 else if (flag_abi_version == 1)
1f838355 925 /* Due to a historical accident, this version had the value
57702a80
MM
926 "102". */
927 builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
928 else
e0a21ab9 929 /* Newer versions have values 1002, 1003, .... */
c22cacf3 930 builtin_define_with_int_value ("__GXX_ABI_VERSION",
57702a80 931 1000 + flag_abi_version);
cb60f38d
NB
932
933 /* libgcc needs to know this. */
677f3fa8 934 if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
cb60f38d
NB
935 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
936
207bf79d
JM
937 /* limits.h and stdint.h need to know these. */
938 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node);
939 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node);
940 builtin_define_type_max ("__INT_MAX__", integer_type_node);
941 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node);
942 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node);
943 builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__",
944 underlying_wchar_type_node);
945 builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node);
946 builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node);
947 builtin_define_type_max ("__SIZE_MAX__", size_type_node);
cb60f38d 948
e1217ac7
DD
949 if (c_dialect_cxx ())
950 for (i = 0; i < NUM_INT_N_ENTS; i ++)
951 if (int_n_enabled_p[i])
952 {
953 char buf[35+20+20];
954
955 /* These are used to configure the C++ library. */
956
957 if (!flag_iso || int_n_data[i].bitsize == POINTER_SIZE)
958 {
959 sprintf (buf, "__GLIBCXX_TYPE_INT_N_%d=__int%d", i, int_n_data[i].bitsize);
960 cpp_define (parse_in, buf);
961
962 sprintf (buf, "__GLIBCXX_BITSIZE_INT_N_%d=%d", i, int_n_data[i].bitsize);
963 cpp_define (parse_in, buf);
964 }
965 }
78a7c317 966
207bf79d 967 /* stdint.h and the testsuite need to know these. */
85291069
JM
968 builtin_define_stdint_macros ();
969
9193fb05
JM
970 /* Provide information for library headers to determine whether to
971 define macros such as __STDC_IEC_559__ and
972 __STDC_IEC_559_COMPLEX__. */
973 builtin_define_with_int_value ("__GCC_IEC_559", cpp_iec_559_value ());
974 builtin_define_with_int_value ("__GCC_IEC_559_COMPLEX",
975 cpp_iec_559_complex_value ());
976
82a1c2fe 977 /* float.h needs to know this. */
cb60f38d
NB
978 builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
979 TARGET_FLT_EVAL_METHOD);
980
9a8ce21f
JG
981 /* And decfloat.h needs this. */
982 builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
983 TARGET_DEC_EVAL_METHOD);
984
1b1562a5 985 builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
6ec637a4
JJ
986 /* Cast the double precision constants. This is needed when single
987 precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
988 is used. The correct result is computed by the compiler when using
bb0a9581
NF
989 macros that include a cast. We use a different cast for C++ to avoid
990 problems with -Wold-style-cast. */
991 builtin_define_float_constants ("DBL", "L",
992 (c_dialect_cxx ()
993 ? "double(%s)"
994 : "((double)%s)"),
995 "", double_type_node);
1b1562a5
MM
996 builtin_define_float_constants ("LDBL", "L", "%s", "L",
997 long_double_type_node);
cb60f38d 998
c65699ef
JM
999 for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
1000 {
1001 if (FLOATN_NX_TYPE_NODE (i) == NULL_TREE)
1002 continue;
1003 char prefix[20], csuffix[20];
1004 sprintf (prefix, "FLT%d%s", floatn_nx_types[i].n,
1005 floatn_nx_types[i].extended ? "X" : "");
1006 sprintf (csuffix, "F%d%s", floatn_nx_types[i].n,
1007 floatn_nx_types[i].extended ? "x" : "");
1008 builtin_define_float_constants (prefix, csuffix, "%s", NULL,
1009 FLOATN_NX_TYPE_NODE (i));
1010 }
1011
9a8ce21f
JG
1012 /* For decfloat.h. */
1013 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
1014 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
1015 builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
1016
0f996086
CF
1017 /* For fixed-point fibt, ibit, max, min, and epsilon. */
1018 if (targetm.fixed_point_supported_p ())
1019 {
1020 builtin_define_fixed_point_constants ("SFRACT", "HR",
1021 short_fract_type_node);
1022 builtin_define_fixed_point_constants ("USFRACT", "UHR",
1023 unsigned_short_fract_type_node);
1024 builtin_define_fixed_point_constants ("FRACT", "R",
1025 fract_type_node);
1026 builtin_define_fixed_point_constants ("UFRACT", "UR",
1027 unsigned_fract_type_node);
1028 builtin_define_fixed_point_constants ("LFRACT", "LR",
1029 long_fract_type_node);
1030 builtin_define_fixed_point_constants ("ULFRACT", "ULR",
1031 unsigned_long_fract_type_node);
1032 builtin_define_fixed_point_constants ("LLFRACT", "LLR",
1033 long_long_fract_type_node);
1034 builtin_define_fixed_point_constants ("ULLFRACT", "ULLR",
1035 unsigned_long_long_fract_type_node);
1036 builtin_define_fixed_point_constants ("SACCUM", "HK",
1037 short_accum_type_node);
1038 builtin_define_fixed_point_constants ("USACCUM", "UHK",
1039 unsigned_short_accum_type_node);
1040 builtin_define_fixed_point_constants ("ACCUM", "K",
1041 accum_type_node);
1042 builtin_define_fixed_point_constants ("UACCUM", "UK",
1043 unsigned_accum_type_node);
1044 builtin_define_fixed_point_constants ("LACCUM", "LK",
1045 long_accum_type_node);
1046 builtin_define_fixed_point_constants ("ULACCUM", "ULK",
1047 unsigned_long_accum_type_node);
1048 builtin_define_fixed_point_constants ("LLACCUM", "LLK",
1049 long_long_accum_type_node);
1050 builtin_define_fixed_point_constants ("ULLACCUM", "ULLK",
1051 unsigned_long_long_accum_type_node);
1052
1053 builtin_define_fixed_point_constants ("QQ", "", qq_type_node);
1054 builtin_define_fixed_point_constants ("HQ", "", hq_type_node);
1055 builtin_define_fixed_point_constants ("SQ", "", sq_type_node);
1056 builtin_define_fixed_point_constants ("DQ", "", dq_type_node);
1057 builtin_define_fixed_point_constants ("TQ", "", tq_type_node);
1058 builtin_define_fixed_point_constants ("UQQ", "", uqq_type_node);
1059 builtin_define_fixed_point_constants ("UHQ", "", uhq_type_node);
1060 builtin_define_fixed_point_constants ("USQ", "", usq_type_node);
1061 builtin_define_fixed_point_constants ("UDQ", "", udq_type_node);
1062 builtin_define_fixed_point_constants ("UTQ", "", utq_type_node);
1063 builtin_define_fixed_point_constants ("HA", "", ha_type_node);
1064 builtin_define_fixed_point_constants ("SA", "", sa_type_node);
1065 builtin_define_fixed_point_constants ("DA", "", da_type_node);
1066 builtin_define_fixed_point_constants ("TA", "", ta_type_node);
1067 builtin_define_fixed_point_constants ("UHA", "", uha_type_node);
1068 builtin_define_fixed_point_constants ("USA", "", usa_type_node);
1069 builtin_define_fixed_point_constants ("UDA", "", uda_type_node);
1070 builtin_define_fixed_point_constants ("UTA", "", uta_type_node);
1071 }
1072
10e48e39
RO
1073 /* For libgcc-internal use only. */
1074 if (flag_building_libgcc)
53d68b9f 1075 {
66bb34c0 1076 /* Properties of floating-point modes for libgcc2.c. */
ef4bddc2 1077 for (machine_mode mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
66bb34c0
JM
1078 mode != VOIDmode;
1079 mode = GET_MODE_WIDER_MODE (mode))
1080 {
1081 const char *name = GET_MODE_NAME (mode);
1082 char *macro_name
1083 = (char *) alloca (strlen (name)
1084 + sizeof ("__LIBGCC__MANT_DIG__"));
1085 sprintf (macro_name, "__LIBGCC_%s_MANT_DIG__", name);
1086 builtin_define_with_int_value (macro_name,
1087 REAL_MODE_FORMAT (mode)->p);
8cc4b7a2
JM
1088 if (!targetm.scalar_mode_supported_p (mode)
1089 || !targetm.libgcc_floating_mode_supported_p (mode))
1090 continue;
1091 macro_name = (char *) alloca (strlen (name)
1092 + sizeof ("__LIBGCC_HAS__MODE__"));
1093 sprintf (macro_name, "__LIBGCC_HAS_%s_MODE__", name);
1094 cpp_define (pfile, macro_name);
dd69f047
JM
1095 macro_name = (char *) alloca (strlen (name)
1096 + sizeof ("__LIBGCC__FUNC_EXT__"));
1097 sprintf (macro_name, "__LIBGCC_%s_FUNC_EXT__", name);
1098 const char *suffix;
1099 if (mode == TYPE_MODE (double_type_node))
1100 suffix = "";
1101 else if (mode == TYPE_MODE (float_type_node))
1102 suffix = "f";
1103 else if (mode == TYPE_MODE (long_double_type_node))
1104 suffix = "l";
1105 /* ??? The following assumes the built-in functions (defined
1106 in target-specific code) match the suffixes used for
1107 constants. Because in fact such functions are not
1108 defined for the 'w' suffix, 'l' is used there
1109 instead. */
1110 else if (mode == targetm.c.mode_for_suffix ('q'))
1111 suffix = "q";
1112 else if (mode == targetm.c.mode_for_suffix ('w'))
1113 suffix = "l";
1114 else
1115 gcc_unreachable ();
1116 builtin_define_with_value (macro_name, suffix, 0);
9a79452d
JM
1117 bool excess_precision = false;
1118 if (TARGET_FLT_EVAL_METHOD != 0
1119 && mode != TYPE_MODE (long_double_type_node)
1120 && (mode == TYPE_MODE (float_type_node)
1121 || mode == TYPE_MODE (double_type_node)))
1122 switch (TARGET_FLT_EVAL_METHOD)
1123 {
1124 case -1:
1125 case 2:
1126 excess_precision = true;
1127 break;
1128
1129 case 1:
1130 excess_precision = mode == TYPE_MODE (float_type_node);
1131 break;
1132
1133 default:
1134 gcc_unreachable ();
1135 }
1136 macro_name = (char *) alloca (strlen (name)
1137 + sizeof ("__LIBGCC__EXCESS_"
1138 "PRECISION__"));
1139 sprintf (macro_name, "__LIBGCC_%s_EXCESS_PRECISION__", name);
1140 builtin_define_with_int_value (macro_name, excess_precision);
66bb34c0
JM
1141 }
1142
53d68b9f
JM
1143 /* For libgcc crtstuff.c and libgcc2.c. */
1144 builtin_define_with_int_value ("__LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__",
1145 EH_TABLES_CAN_BE_READ_ONLY);
1146#ifdef EH_FRAME_SECTION_NAME
1147 builtin_define_with_value ("__LIBGCC_EH_FRAME_SECTION_NAME__",
1148 EH_FRAME_SECTION_NAME, 1);
1149#endif
1150#ifdef JCR_SECTION_NAME
1151 builtin_define_with_value ("__LIBGCC_JCR_SECTION_NAME__",
1152 JCR_SECTION_NAME, 1);
1153#endif
1154#ifdef CTORS_SECTION_ASM_OP
1155 builtin_define_with_value ("__LIBGCC_CTORS_SECTION_ASM_OP__",
1156 CTORS_SECTION_ASM_OP, 1);
1157#endif
1158#ifdef DTORS_SECTION_ASM_OP
1159 builtin_define_with_value ("__LIBGCC_DTORS_SECTION_ASM_OP__",
1160 DTORS_SECTION_ASM_OP, 1);
1161#endif
1162#ifdef TEXT_SECTION_ASM_OP
1163 builtin_define_with_value ("__LIBGCC_TEXT_SECTION_ASM_OP__",
1164 TEXT_SECTION_ASM_OP, 1);
1165#endif
1166#ifdef INIT_SECTION_ASM_OP
1167 builtin_define_with_value ("__LIBGCC_INIT_SECTION_ASM_OP__",
1168 INIT_SECTION_ASM_OP, 1);
1169#endif
1170#ifdef INIT_ARRAY_SECTION_ASM_OP
1171 /* Despite the name of this target macro, the expansion is not
1172 actually used, and may be empty rather than a string
1173 constant. */
1174 cpp_define (pfile, "__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__");
1175#endif
1176
1177 /* For libgcc enable-execute-stack.c. */
1178 builtin_define_with_int_value ("__LIBGCC_TRAMPOLINE_SIZE__",
1179 TRAMPOLINE_SIZE);
1180
1181 /* For libgcc generic-morestack.c and unwinder code. */
581edfa3
TS
1182 if (STACK_GROWS_DOWNWARD)
1183 cpp_define (pfile, "__LIBGCC_STACK_GROWS_DOWNWARD__");
53d68b9f
JM
1184
1185 /* For libgcc unwinder code. */
1186#ifdef DONT_USE_BUILTIN_SETJMP
1187 cpp_define (pfile, "__LIBGCC_DONT_USE_BUILTIN_SETJMP__");
1188#endif
1189#ifdef DWARF_ALT_FRAME_RETURN_COLUMN
1190 builtin_define_with_int_value ("__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__",
1191 DWARF_ALT_FRAME_RETURN_COLUMN);
1192#endif
1193 builtin_define_with_int_value ("__LIBGCC_DWARF_FRAME_REGISTERS__",
1194 DWARF_FRAME_REGISTERS);
1195#ifdef EH_RETURN_STACKADJ_RTX
1196 cpp_define (pfile, "__LIBGCC_EH_RETURN_STACKADJ_RTX__");
1197#endif
1198#ifdef JMP_BUF_SIZE
1199 builtin_define_with_int_value ("__LIBGCC_JMP_BUF_SIZE__",
1200 JMP_BUF_SIZE);
1201#endif
1202 builtin_define_with_int_value ("__LIBGCC_STACK_POINTER_REGNUM__",
1203 STACK_POINTER_REGNUM);
1204
1205 /* For libgcov. */
1206 builtin_define_with_int_value ("__LIBGCC_VTABLE_USES_DESCRIPTORS__",
1207 TARGET_VTABLE_USES_DESCRIPTORS);
1208 }
10e48e39 1209
cb60f38d
NB
1210 /* For use in assembly language. */
1211 builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
1212 builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
1213
1214 /* Misc. */
da1c7394
ILT
1215 if (flag_gnu89_inline)
1216 cpp_define (pfile, "__GNUC_GNU_INLINE__");
1217 else
1218 cpp_define (pfile, "__GNUC_STDC_INLINE__");
1219
e90acd93 1220 if (flag_no_inline)
cb60f38d 1221 cpp_define (pfile, "__NO_INLINE__");
cb60f38d
NB
1222
1223 if (flag_iso)
1224 cpp_define (pfile, "__STRICT_ANSI__");
1225
1226 if (!flag_signed_char)
1227 cpp_define (pfile, "__CHAR_UNSIGNED__");
1228
8df83eae 1229 if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
cb60f38d
NB
1230 cpp_define (pfile, "__WCHAR_UNSIGNED__");
1231
62bad7cd
AM
1232 cpp_atomic_builtins (pfile);
1233
d4ea4622 1234#ifdef DWARF2_UNWIND_INFO
058514b3 1235 if (dwarf2out_do_cfi_asm ())
d4ea4622
RH
1236 cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
1237#endif
1238
cb60f38d 1239 /* Make the choice of ObjC runtime visible to source code. */
37fa72e9 1240 if (c_dialect_objc () && flag_next_runtime)
cb60f38d
NB
1241 cpp_define (pfile, "__NEXT_RUNTIME__");
1242
84b8b0e0 1243 /* Show the availability of some target pragmas. */
c54d7dc9 1244 cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
84b8b0e0 1245
0ffb94cd
JW
1246 /* Make the choice of the stack protector runtime visible to source code.
1247 The macro names and values here were chosen for compatibility with an
1248 earlier implementation, i.e. ProPolice. */
5434dc07
MD
1249 if (flag_stack_protect == 4)
1250 cpp_define (pfile, "__SSP_EXPLICIT__=4");
f6bc1c4a
HS
1251 if (flag_stack_protect == 3)
1252 cpp_define (pfile, "__SSP_STRONG__=3");
7d69de61
RH
1253 if (flag_stack_protect == 2)
1254 cpp_define (pfile, "__SSP_ALL__=2");
1255 else if (flag_stack_protect == 1)
1256 cpp_define (pfile, "__SSP__=1");
1257
41dbbb37
TS
1258 if (flag_openacc)
1259 cpp_define (pfile, "_OPENACC=201306");
1260
953ff289 1261 if (flag_openmp)
d9a6bd32 1262 cpp_define (pfile, "_OPENMP=201511");
953ff289 1263
78a7c317
DD
1264 for (i = 0; i < NUM_INT_N_ENTS; i ++)
1265 if (int_n_enabled_p[i])
1266 {
1267 char buf[15+20];
1268 sprintf(buf, "__SIZEOF_INT%d__", int_n_data[i].bitsize);
1269 builtin_define_type_sizeof (buf,
1270 int_n_trees[i].signed_type);
1271 }
024a85ae
AK
1272 builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
1273 builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
1274 builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
1275 unsigned_ptrdiff_type_node);
024a85ae 1276
cb60f38d
NB
1277 /* A straightforward target hook doesn't work, because of problems
1278 linking that hook's body when part of non-C front ends. */
1279# define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
1280# define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
1281# define builtin_define(TXT) cpp_define (pfile, TXT)
1282# define builtin_assert(TXT) cpp_assert (pfile, TXT)
1283 TARGET_CPU_CPP_BUILTINS ();
1284 TARGET_OS_CPP_BUILTINS ();
4e2e315f 1285 TARGET_OBJFMT_CPP_BUILTINS ();
63c5b495
MM
1286
1287 /* Support the __declspec keyword by turning them into attributes.
1288 Note that the current way we do this may result in a collision
1289 with predefined attributes later on. This can be solved by using
1290 one attribute, say __declspec__, and passing args to it. The
1291 problem with that approach is that args are not accumulated: each
1292 new appearance would clobber any existing args. */
1293 if (TARGET_DECLSPEC)
1294 builtin_define ("__declspec(x)=__attribute__((x))");
79b87c74 1295
589dd995
JJ
1296 /* If decimal floating point is supported, tell the user if the
1297 alternate format (BID) is used instead of the standard (DPD)
1298 format. */
1299 if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
1300 cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
cb60f38d
NB
1301}
1302
1303/* Pass an object-like macro. If it doesn't lie in the user's
1304 namespace, defines it unconditionally. Otherwise define a version
1305 with two leading underscores, and another version with two leading
1306 and trailing underscores, and define the original only if an ISO
1307 standard was not nominated.
1308
1309 e.g. passing "unix" defines "__unix", "__unix__" and possibly
1310 "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
1311 "_mips". */
21282b1e 1312void
35b1a6fa 1313builtin_define_std (const char *macro)
cb60f38d
NB
1314{
1315 size_t len = strlen (macro);
cceb1885 1316 char *buff = (char *) alloca (len + 5);
cb60f38d
NB
1317 char *p = buff + 2;
1318 char *q = p + len;
1319
1320 /* prepend __ (or maybe just _) if in user's namespace. */
1321 memcpy (p, macro, len + 1);
1322 if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
1323 {
1324 if (*p != '_')
1325 *--p = '_';
1326 if (p[1] != '_')
1327 *--p = '_';
1328 }
1329 cpp_define (parse_in, p);
1330
1331 /* If it was in user's namespace... */
1332 if (p != buff + 2)
1333 {
1334 /* Define the macro with leading and following __. */
1335 if (q[-1] != '_')
1336 *q++ = '_';
1337 if (q[-2] != '_')
1338 *q++ = '_';
1339 *q = '\0';
1340 cpp_define (parse_in, p);
1341
1342 /* Finally, define the original macro if permitted. */
1343 if (!flag_iso)
1344 cpp_define (parse_in, macro);
1345 }
1346}
1347
1348/* Pass an object-like macro and a value to define it to. The third
1349 parameter says whether or not to turn the value into a string
1350 constant. */
1351void
35b1a6fa 1352builtin_define_with_value (const char *macro, const char *expansion, int is_str)
cb60f38d
NB
1353{
1354 char *buf;
1355 size_t mlen = strlen (macro);
1356 size_t elen = strlen (expansion);
1357 size_t extra = 2; /* space for an = and a NUL */
1358
1359 if (is_str)
53d68b9f
JM
1360 {
1361 char *quoted_expansion = (char *) alloca (elen * 4 + 1);
1362 const char *p;
1363 char *q;
1364 extra += 2; /* space for two quote marks */
1365 for (p = expansion, q = quoted_expansion; *p; p++)
1366 {
1367 switch (*p)
1368 {
1369 case '\n':
1370 *q++ = '\\';
1371 *q++ = 'n';
1372 break;
1373
1374 case '\t':
1375 *q++ = '\\';
1376 *q++ = 't';
1377 break;
1378
1379 case '\\':
1380 *q++ = '\\';
1381 *q++ = '\\';
1382 break;
1383
1384 case '"':
1385 *q++ = '\\';
1386 *q++ = '"';
1387 break;
1388
1389 default:
1390 if (ISPRINT ((unsigned char) *p))
1391 *q++ = *p;
1392 else
1393 {
1394 sprintf (q, "\\%03o", (unsigned char) *p);
1395 q += 4;
1396 }
1397 }
1398 }
1399 *q = '\0';
1400 expansion = quoted_expansion;
1401 elen = q - expansion;
1402 }
cb60f38d 1403
cceb1885 1404 buf = (char *) alloca (mlen + elen + extra);
cb60f38d
NB
1405 if (is_str)
1406 sprintf (buf, "%s=\"%s\"", macro, expansion);
1407 else
1408 sprintf (buf, "%s=%s", macro, expansion);
1409
1410 cpp_define (parse_in, buf);
1411}
1412
cb60f38d
NB
1413
1414/* Pass an object-like macro and an integer value to define it to. */
7049e4eb 1415void
35b1a6fa 1416builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
cb60f38d
NB
1417{
1418 char *buf;
1419 size_t mlen = strlen (macro);
1420 size_t vlen = 18;
1421 size_t extra = 2; /* space for = and NUL. */
1422
cceb1885 1423 buf = (char *) alloca (mlen + vlen + extra);
cb60f38d
NB
1424 memcpy (buf, macro, mlen);
1425 buf[mlen] = '=';
1426 sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
1427
1428 cpp_define (parse_in, buf);
1429}
1430
8e680db5
JJ
1431/* builtin_define_with_hex_fp_value is very expensive, so the following
1432 array and function allows it to be done lazily when __DBL_MAX__
1433 etc. is first used. */
1434
5bca794b 1435struct GTY(()) lazy_hex_fp_value_struct
8e680db5
JJ
1436{
1437 const char *hex_str;
1438 cpp_macro *macro;
ef4bddc2 1439 machine_mode mode;
8e680db5
JJ
1440 int digits;
1441 const char *fp_suffix;
5bca794b
JJ
1442};
1443static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12];
1444static GTY(()) int lazy_hex_fp_value_count;
8e680db5
JJ
1445
1446static bool
1447lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
1448 cpp_hashnode *node)
1449{
1450 REAL_VALUE_TYPE real;
1451 char dec_str[64], buf1[256];
1452 unsigned int idx;
1453 if (node->value.builtin < BT_FIRST_USER
1454 || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
1455 return false;
1456
1457 idx = node->value.builtin - BT_FIRST_USER;
1458 real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
1459 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
1460 lazy_hex_fp_values[idx].digits, 0,
1461 lazy_hex_fp_values[idx].mode);
1462
1463 sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
1464 node->flags &= ~(NODE_BUILTIN | NODE_USED);
1465 node->value.macro = lazy_hex_fp_values[idx].macro;
1466 for (idx = 0; idx < node->value.macro->count; idx++)
1467 if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
1468 break;
1469 gcc_assert (idx < node->value.macro->count);
1470 node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
1471 node->value.macro->exp.tokens[idx].val.str.text
5bca794b 1472 = (const unsigned char *) ggc_strdup (buf1);
8e680db5
JJ
1473 return true;
1474}
1475
cb60f38d
NB
1476/* Pass an object-like macro a hexadecimal floating-point value. */
1477static void
35b1a6fa 1478builtin_define_with_hex_fp_value (const char *macro,
3e479de3 1479 tree type, int digits,
b8698a0f 1480 const char *hex_str,
264c41ed
CD
1481 const char *fp_suffix,
1482 const char *fp_cast)
cb60f38d
NB
1483{
1484 REAL_VALUE_TYPE real;
264c41ed 1485 char dec_str[64], buf1[256], buf2[256];
cb60f38d 1486
8e680db5
JJ
1487 /* This is very expensive, so if possible expand them lazily. */
1488 if (lazy_hex_fp_value_count < 12
1489 && flag_dump_macros == 0
1490 && !cpp_get_options (parse_in)->traditional)
1491 {
1492 struct cpp_hashnode *node;
1493 if (lazy_hex_fp_value_count == 0)
1494 cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
1495 sprintf (buf2, fp_cast, "1.1");
1496 sprintf (buf1, "%s=%s", macro, buf2);
1497 cpp_define (parse_in, buf1);
1498 node = C_CPP_HASHNODE (get_identifier (macro));
5bca794b
JJ
1499 lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
1500 = ggc_strdup (hex_str);
8e680db5
JJ
1501 lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
1502 lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
1503 lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
1504 lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
1505 node->flags |= NODE_BUILTIN;
b49cf425
JR
1506 node->value.builtin
1507 = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
8e680db5
JJ
1508 lazy_hex_fp_value_count++;
1509 return;
1510 }
1511
cb60f38d
NB
1512 /* Hex values are really cool and convenient, except that they're
1513 not supported in strict ISO C90 mode. First, the "p-" sequence
1514 is not valid as part of a preprocessor number. Second, we get a
1515 pedwarn from the preprocessor, which has no context, so we can't
1516 suppress the warning with __extension__.
1517
35b1a6fa 1518 So instead what we do is construct the number in hex (because
cb60f38d
NB
1519 it's easy to get the exact correct value), parse it as a real,
1520 then print it back out as decimal. */
1521
1522 real_from_string (&real, hex_str);
3e479de3
UW
1523 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
1524 TYPE_MODE (type));
cb60f38d 1525
264c41ed
CD
1526 /* Assemble the macro in the following fashion
1527 macro = fp_cast [dec_str fp_suffix] */
1528 sprintf (buf1, "%s%s", dec_str, fp_suffix);
1529 sprintf (buf2, fp_cast, buf1);
1530 sprintf (buf1, "%s=%s", macro, buf2);
b8698a0f 1531
264c41ed 1532 cpp_define (parse_in, buf1);
cb60f38d
NB
1533}
1534
207bf79d
JM
1535/* Return a string constant for the suffix for a value of type TYPE
1536 promoted according to the integer promotions. The type must be one
1537 of the standard integer type nodes. */
1538
1539static const char *
1540type_suffix (tree type)
1541{
1542 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
1543 int unsigned_suffix;
1544 int is_long;
78a7c317 1545 int tp = TYPE_PRECISION (type);
207bf79d
JM
1546
1547 if (type == long_long_integer_type_node
78a7c317
DD
1548 || type == long_long_unsigned_type_node
1549 || tp > TYPE_PRECISION (long_integer_type_node))
207bf79d
JM
1550 is_long = 2;
1551 else if (type == long_integer_type_node
78a7c317
DD
1552 || type == long_unsigned_type_node
1553 || tp > TYPE_PRECISION (integer_type_node))
207bf79d
JM
1554 is_long = 1;
1555 else if (type == integer_type_node
1556 || type == unsigned_type_node
1557 || type == short_integer_type_node
1558 || type == short_unsigned_type_node
1559 || type == signed_char_type_node
1560 || type == unsigned_char_type_node
1561 /* ??? "char" is not a signed or unsigned integer type and
1562 so is not permitted for the standard typedefs, but some
1563 systems use it anyway. */
1564 || type == char_type_node)
1565 is_long = 0;
1566 else
1567 gcc_unreachable ();
1568
1569 unsigned_suffix = TYPE_UNSIGNED (type);
1570 if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
1571 unsigned_suffix = 0;
1572 return suffixes[is_long * 2 + unsigned_suffix];
1573}
1574
1575/* Define MACRO as a <stdint.h> constant-suffix macro for TYPE. */
1576static void
1577builtin_define_constants (const char *macro, tree type)
1578{
1579 const char *suffix;
1580 char *buf;
1581
1582 suffix = type_suffix (type);
1583
1584 if (suffix[0] == 0)
1585 {
1586 buf = (char *) alloca (strlen (macro) + 6);
1587 sprintf (buf, "%s(c)=c", macro);
1588 }
1589 else
1590 {
1591 buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1);
1592 sprintf (buf, "%s(c)=c ## %s", macro, suffix);
1593 }
1594
1595 cpp_define (parse_in, buf);
1596}
1597
1598/* Define MAX for TYPE based on the precision of the type. */
1599
1600static void
1601builtin_define_type_max (const char *macro, tree type)
1602{
1603 builtin_define_type_minmax (NULL, macro, type);
1604}
1605
ca49b74e
DD
1606/* Given a value with COUNT LSBs set, fill BUF with a hexidecimal
1607 representation of that value. For example, a COUNT of 10 would
1608 return "0x3ff". */
1609
1610static void
1611print_bits_of_hex (char *buf, int bufsz, int count)
1612{
1613 gcc_assert (bufsz > 3);
1614 *buf++ = '0';
1615 *buf++ = 'x';
1616 bufsz -= 2;
1617
1618 gcc_assert (count > 0);
1619
1620 switch (count % 4) {
1621 case 0:
1622 break;
1623 case 1:
1624 *buf++ = '1';
1625 bufsz --;
1626 count -= 1;
1627 break;
1628 case 2:
1629 *buf++ = '3';
1630 bufsz --;
1631 count -= 2;
1632 break;
1633 case 3:
1634 *buf++ = '7';
1635 bufsz --;
1636 count -= 3;
1637 break;
1638 }
1639 while (count >= 4)
1640 {
1641 gcc_assert (bufsz > 1);
1642 *buf++ = 'f';
1643 bufsz --;
1644 count -= 4;
1645 }
1646 gcc_assert (bufsz > 0);
1647 *buf++ = 0;
1648}
1649
207bf79d
JM
1650/* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
1651 precision of the type. */
cb60f38d
NB
1652
1653static void
207bf79d
JM
1654builtin_define_type_minmax (const char *min_macro, const char *max_macro,
1655 tree type)
cb60f38d 1656{
ca49b74e
DD
1657#define PBOH_SZ (MAX_BITSIZE_MODE_ANY_INT/4+4)
1658 char value[PBOH_SZ];
1659
1660 const char *suffix;
cb60f38d 1661 char *buf;
ca49b74e 1662 int bits;
cb60f38d 1663
ca49b74e
DD
1664 bits = TYPE_PRECISION (type) + (TYPE_UNSIGNED (type) ? 0 : -1);
1665
1666 print_bits_of_hex (value, PBOH_SZ, bits);
cb60f38d 1667
207bf79d 1668 suffix = type_suffix (type);
cb60f38d 1669
207bf79d 1670 buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)
cceb1885 1671 + strlen (suffix) + 1);
207bf79d 1672 sprintf (buf, "%s=%s%s", max_macro, value, suffix);
cb60f38d
NB
1673
1674 cpp_define (parse_in, buf);
207bf79d
JM
1675
1676 if (min_macro)
1677 {
1678 if (TYPE_UNSIGNED (type))
1679 {
1680 buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1);
1681 sprintf (buf, "%s=0%s", min_macro, suffix);
1682 }
1683 else
1684 {
1685 buf = (char *) alloca (strlen (min_macro) + 3
1686 + strlen (max_macro) + 6);
1687 sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro);
1688 }
1689 cpp_define (parse_in, buf);
1690 }
cb60f38d 1691}
5bca794b
JJ
1692
1693#include "gt-c-family-c-cppbuiltin.h"