1 /* Define builtin-in macros for the C family front ends.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
31 #include "debug.h" /* For dwarf2out_do_cfi_asm. */
33 #include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */
35 #include "cpp-id-data.h"
36 #include "cppbuiltin.h"
38 #ifndef TARGET_OS_CPP_BUILTINS
39 # define TARGET_OS_CPP_BUILTINS()
42 #ifndef TARGET_OBJFMT_CPP_BUILTINS
43 # define TARGET_OBJFMT_CPP_BUILTINS()
46 #ifndef REGISTER_PREFIX
47 #define REGISTER_PREFIX ""
50 /* Non-static as some targets don't use it. */
51 void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
52 static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
53 static void builtin_define_with_hex_fp_value (const char *, tree,
57 static void builtin_define_stdint_macros (void);
58 static void builtin_define_constants (const char *, tree);
59 static void builtin_define_type_max (const char *, tree);
60 static void builtin_define_type_minmax (const char *, const char *, tree);
61 static void builtin_define_type_sizeof (const char *, tree);
62 static void builtin_define_float_constants (const char *,
67 /* Define NAME with value TYPE size_unit. */
69 builtin_define_type_sizeof (const char *name, tree type)
71 builtin_define_with_int_value (name,
72 tree_low_cst (TYPE_SIZE_UNIT (type), 1));
75 /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
78 builtin_define_float_constants (const char *name_prefix,
79 const char *fp_suffix,
83 /* Used to convert radix-based values to base 10 values in several cases.
85 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
86 least 6 significant digits for correct results. Using the fraction
87 formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
88 intermediate; perhaps someone can find a better approximation, in the
89 mean time, I suspect using doubles won't harm the bootstrap here. */
91 const double log10_2 = .30102999566398119521;
93 const struct real_format *fmt;
94 const struct real_format *ldfmt;
96 char name[64], buf[128];
97 int dig, min_10_exp, max_10_exp;
101 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
102 gcc_assert (fmt->b != 10);
103 ldfmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node));
104 gcc_assert (ldfmt->b != 10);
106 /* The radix of the exponent representation. */
107 if (type == float_type_node)
108 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
111 /* The number of radix digits, p, in the floating-point significand. */
112 sprintf (name, "__%s_MANT_DIG__", name_prefix);
113 builtin_define_with_int_value (name, fmt->p);
115 /* The number of decimal digits, q, such that any floating-point number
116 with q decimal digits can be rounded into a floating-point number with
117 p radix b digits and back again without change to the q decimal digits,
119 p log10 b if b is a power of 10
120 floor((p - 1) log10 b) otherwise
122 dig = (fmt->p - 1) * log10_b;
123 sprintf (name, "__%s_DIG__", name_prefix);
124 builtin_define_with_int_value (name, dig);
126 /* The minimum negative int x such that b**(x-1) is a normalized float. */
127 sprintf (name, "__%s_MIN_EXP__", name_prefix);
128 sprintf (buf, "(%d)", fmt->emin);
129 builtin_define_with_value (name, buf, 0);
131 /* The minimum negative int x such that 10**x is a normalized float,
133 ceil (log10 (b ** (emin - 1)))
134 = ceil (log10 (b) * (emin - 1))
136 Recall that emin is negative, so the integer truncation calculates
137 the ceiling, not the floor, in this case. */
138 min_10_exp = (fmt->emin - 1) * log10_b;
139 sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
140 sprintf (buf, "(%d)", min_10_exp);
141 builtin_define_with_value (name, buf, 0);
143 /* The maximum int x such that b**(x-1) is a representable float. */
144 sprintf (name, "__%s_MAX_EXP__", name_prefix);
145 builtin_define_with_int_value (name, fmt->emax);
147 /* The maximum int x such that 10**x is in the range of representable
148 finite floating-point numbers,
150 floor (log10((1 - b**-p) * b**emax))
151 = floor (log10(1 - b**-p) + log10(b**emax))
152 = floor (log10(1 - b**-p) + log10(b)*emax)
154 The safest thing to do here is to just compute this number. But since
155 we don't link cc1 with libm, we cannot. We could implement log10 here
156 a series expansion, but that seems too much effort because:
158 Note that the first term, for all extant p, is a number exceedingly close
159 to zero, but slightly negative. Note that the second term is an integer
160 scaling an irrational number, and that because of the floor we are only
161 interested in its integral portion.
163 In order for the first term to have any effect on the integral portion
164 of the second term, the second term has to be exceedingly close to an
165 integer itself (e.g. 123.000000000001 or something). Getting a result
166 that close to an integer requires that the irrational multiplicand have
167 a long series of zeros in its expansion, which doesn't occur in the
168 first 20 digits or so of log10(b).
170 Hand-waving aside, crunching all of the sets of constants above by hand
171 does not yield a case for which the first term is significant, which
172 in the end is all that matters. */
173 max_10_exp = fmt->emax * log10_b;
174 sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
175 builtin_define_with_int_value (name, max_10_exp);
177 /* The number of decimal digits, n, such that any floating-point number
178 can be rounded to n decimal digits and back again without change to
181 p * log10(b) if b is a power of 10
182 ceil(1 + p * log10(b)) otherwise
184 The only macro we care about is this number for the widest supported
185 floating type, but we want this value for rendering constants below. */
188 = 1 + (fmt->p < ldfmt->p ? ldfmt->p : fmt->p) * log10_b;
189 decimal_dig = d_decimal_dig;
190 if (decimal_dig < d_decimal_dig)
193 /* Similar, for this type rather than long double. */
195 double type_d_decimal_dig = 1 + fmt->p * log10_b;
196 type_decimal_dig = type_d_decimal_dig;
197 if (type_decimal_dig < type_d_decimal_dig)
200 if (type == long_double_type_node)
201 builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
204 sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
205 builtin_define_with_int_value (name, type_decimal_dig);
208 /* Since, for the supported formats, B is always a power of 2, we
209 construct the following numbers directly as a hexadecimal
211 get_max_float (fmt, buf, sizeof (buf));
213 sprintf (name, "__%s_MAX__", name_prefix);
214 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
216 /* The minimum normalized positive floating-point number,
218 sprintf (name, "__%s_MIN__", name_prefix);
219 sprintf (buf, "0x1p%d", fmt->emin - 1);
220 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
222 /* The difference between 1 and the least value greater than 1 that is
223 representable in the given floating point type, b**(1-p). */
224 sprintf (name, "__%s_EPSILON__", name_prefix);
225 if (fmt->pnan < fmt->p)
226 /* This is an IBM extended double format, so 1.0 + any double is
227 representable precisely. */
228 sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
230 sprintf (buf, "0x1p%d", 1 - fmt->p);
231 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
233 /* For C++ std::numeric_limits<T>::denorm_min. The minimum denormalized
234 positive floating-point number, b**(emin-p). Zero for formats that
235 don't support denormals. */
236 sprintf (name, "__%s_DENORM_MIN__", name_prefix);
239 sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
240 builtin_define_with_hex_fp_value (name, type, decimal_dig,
241 buf, fp_suffix, fp_cast);
245 sprintf (buf, "0.0%s", fp_suffix);
246 builtin_define_with_value (name, buf, 0);
249 sprintf (name, "__%s_HAS_DENORM__", name_prefix);
250 builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
252 /* For C++ std::numeric_limits<T>::has_infinity. */
253 sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
254 builtin_define_with_int_value (name,
255 MODE_HAS_INFINITIES (TYPE_MODE (type)));
256 /* For C++ std::numeric_limits<T>::has_quiet_NaN. We do not have a
257 predicate to distinguish a target that has both quiet and
258 signalling NaNs from a target that has only quiet NaNs or only
259 signalling NaNs, so we assume that a target that has any kind of
260 NaN has quiet NaNs. */
261 sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
262 builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
265 /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
267 builtin_define_decimal_float_constants (const char *name_prefix,
271 const struct real_format *fmt;
272 char name[64], buf[128], *p;
275 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
277 /* The number of radix digits, p, in the significand. */
278 sprintf (name, "__%s_MANT_DIG__", name_prefix);
279 builtin_define_with_int_value (name, fmt->p);
281 /* The minimum negative int x such that b**(x-1) is a normalized float. */
282 sprintf (name, "__%s_MIN_EXP__", name_prefix);
283 sprintf (buf, "(%d)", fmt->emin);
284 builtin_define_with_value (name, buf, 0);
286 /* The maximum int x such that b**(x-1) is a representable float. */
287 sprintf (name, "__%s_MAX_EXP__", name_prefix);
288 builtin_define_with_int_value (name, fmt->emax);
290 /* Compute the minimum representable value. */
291 sprintf (name, "__%s_MIN__", name_prefix);
292 sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
293 builtin_define_with_value (name, buf, 0);
295 /* Compute the maximum representable value. */
296 sprintf (name, "__%s_MAX__", name_prefix);
298 for (digits = fmt->p; digits; digits--)
301 if (digits == fmt->p)
305 /* fmt->p plus 1, to account for the decimal point and fmt->emax
306 minus 1 because the digits are nines, not 1.0. */
307 sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix);
308 builtin_define_with_value (name, buf, 0);
310 /* Compute epsilon (the difference between 1 and least value greater
311 than 1 representable). */
312 sprintf (name, "__%s_EPSILON__", name_prefix);
313 sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
314 builtin_define_with_value (name, buf, 0);
316 /* Minimum subnormal positive decimal value. */
317 sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
319 for (digits = fmt->p; digits > 1; digits--)
322 if (digits == fmt->p)
326 sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix);
327 builtin_define_with_value (name, buf, 0);
330 /* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */
333 builtin_define_fixed_point_constants (const char *name_prefix,
337 char name[64], buf[256], *new_buf;
340 sprintf (name, "__%s_FBIT__", name_prefix);
341 builtin_define_with_int_value (name, TYPE_FBIT (type));
343 sprintf (name, "__%s_IBIT__", name_prefix);
344 builtin_define_with_int_value (name, TYPE_IBIT (type));
346 /* If there is no suffix, defines are for fixed-point modes.
348 if (strcmp (suffix, "") == 0)
351 if (TYPE_UNSIGNED (type))
353 sprintf (name, "__%s_MIN__", name_prefix);
354 sprintf (buf, "0.0%s", suffix);
355 builtin_define_with_value (name, buf, 0);
359 sprintf (name, "__%s_MIN__", name_prefix);
360 if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
361 sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
362 TYPE_IBIT (type) - 1, suffix);
364 sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
365 builtin_define_with_value (name, buf, 0);
368 sprintf (name, "__%s_MAX__", name_prefix);
371 mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
373 sprintf (new_buf++, "%x", (1 << mod) - 1);
374 for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
375 sprintf (new_buf++, "F");
376 sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
377 builtin_define_with_value (name, buf, 0);
379 sprintf (name, "__%s_EPSILON__", name_prefix);
380 sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
381 builtin_define_with_value (name, buf, 0);
384 /* Define macros used by <stdint.h>. */
386 builtin_define_stdint_macros (void)
388 builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node);
389 builtin_define_constants ("__INTMAX_C", intmax_type_node);
390 builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node);
391 builtin_define_constants ("__UINTMAX_C", uintmax_type_node);
392 if (sig_atomic_type_node)
393 builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__",
394 sig_atomic_type_node);
396 builtin_define_type_max ("__INT8_MAX__", int8_type_node);
398 builtin_define_type_max ("__INT16_MAX__", int16_type_node);
400 builtin_define_type_max ("__INT32_MAX__", int32_type_node);
402 builtin_define_type_max ("__INT64_MAX__", int64_type_node);
404 builtin_define_type_max ("__UINT8_MAX__", uint8_type_node);
405 if (uint16_type_node)
406 builtin_define_type_max ("__UINT16_MAX__", uint16_type_node);
407 if (c_uint32_type_node)
408 builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node);
409 if (c_uint64_type_node)
410 builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node);
411 if (int_least8_type_node)
413 builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node);
414 builtin_define_constants ("__INT8_C", int_least8_type_node);
416 if (int_least16_type_node)
418 builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node);
419 builtin_define_constants ("__INT16_C", int_least16_type_node);
421 if (int_least32_type_node)
423 builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node);
424 builtin_define_constants ("__INT32_C", int_least32_type_node);
426 if (int_least64_type_node)
428 builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node);
429 builtin_define_constants ("__INT64_C", int_least64_type_node);
431 if (uint_least8_type_node)
433 builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node);
434 builtin_define_constants ("__UINT8_C", uint_least8_type_node);
436 if (uint_least16_type_node)
438 builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node);
439 builtin_define_constants ("__UINT16_C", uint_least16_type_node);
441 if (uint_least32_type_node)
443 builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node);
444 builtin_define_constants ("__UINT32_C", uint_least32_type_node);
446 if (uint_least64_type_node)
448 builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node);
449 builtin_define_constants ("__UINT64_C", uint_least64_type_node);
451 if (int_fast8_type_node)
452 builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node);
453 if (int_fast16_type_node)
454 builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node);
455 if (int_fast32_type_node)
456 builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node);
457 if (int_fast64_type_node)
458 builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node);
459 if (uint_fast8_type_node)
460 builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node);
461 if (uint_fast16_type_node)
462 builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node);
463 if (uint_fast32_type_node)
464 builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node);
465 if (uint_fast64_type_node)
466 builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node);
467 if (intptr_type_node)
468 builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node);
469 if (uintptr_type_node)
470 builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node);
473 /* Adjust the optimization macros when a #pragma GCC optimization is done to
474 reflect the current level. */
476 c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
479 struct cl_optimization *prev = TREE_OPTIMIZATION (prev_tree);
480 struct cl_optimization *cur = TREE_OPTIMIZATION (cur_tree);
484 /* -undef turns off target-specific built-ins. */
488 /* Other target-independent built-ins determined by command-line
490 if (!prev->x_optimize_size && cur->x_optimize_size)
491 cpp_define (pfile, "__OPTIMIZE_SIZE__");
492 else if (prev->x_optimize_size && !cur->x_optimize_size)
493 cpp_undef (pfile, "__OPTIMIZE_SIZE__");
495 if (!prev->x_optimize && cur->x_optimize)
496 cpp_define (pfile, "__OPTIMIZE__");
497 else if (prev->x_optimize && !cur->x_optimize)
498 cpp_undef (pfile, "__OPTIMIZE__");
500 prev_fast_math = fast_math_flags_struct_set_p (prev);
501 cur_fast_math = fast_math_flags_struct_set_p (cur);
502 if (!prev_fast_math && cur_fast_math)
503 cpp_define (pfile, "__FAST_MATH__");
504 else if (prev_fast_math && !cur_fast_math)
505 cpp_undef (pfile, "__FAST_MATH__");
507 if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
508 cpp_define (pfile, "__SUPPORT_SNAN__");
509 else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
510 cpp_undef (pfile, "__SUPPORT_SNAN__");
512 if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
514 cpp_undef (pfile, "__FINITE_MATH_ONLY__");
515 cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
517 else if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
519 cpp_undef (pfile, "__FINITE_MATH_ONLY__");
520 cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
525 /* Hook that registers front end and target-specific built-ins. */
527 c_cpp_builtins (cpp_reader *pfile)
529 /* -undef turns off target-specific built-ins. */
533 define_language_independent_builtin_macros (pfile);
535 if (c_dialect_cxx ())
538 parse_basever (&major, NULL, NULL);
539 cpp_define_formatted (pfile, "__GNUG__=%d", major);
542 /* For stddef.h. They require macros defined in c-common.c. */
543 c_stddef_cpp_builtins ();
545 if (c_dialect_cxx ())
547 if (flag_weak && SUPPORTS_ONE_ONLY)
548 cpp_define (pfile, "__GXX_WEAK__=1");
550 cpp_define (pfile, "__GXX_WEAK__=0");
552 cpp_define (pfile, "__DEPRECATED");
554 cpp_define (pfile, "__GXX_RTTI");
555 if (cxx_dialect == cxx0x)
556 cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
558 /* Note that we define this for C as well, so that we know if
559 __attribute__((cleanup)) will interface with EH. */
561 cpp_define (pfile, "__EXCEPTIONS");
563 /* Represents the C++ ABI version, always defined so it can be used while
564 preprocessing C and assembler. */
565 if (flag_abi_version == 0)
566 /* Use a very large value so that:
568 #if __GXX_ABI_VERSION >= <value for version X>
570 will work whether the user explicitly says "-fabi-version=x" or
571 "-fabi-version=0". Do not use INT_MAX because that will be
572 different from system to system. */
573 builtin_define_with_int_value ("__GXX_ABI_VERSION", 999999);
574 else if (flag_abi_version == 1)
575 /* Due to a historical accident, this version had the value
577 builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
579 /* Newer versions have values 1002, 1003, .... */
580 builtin_define_with_int_value ("__GXX_ABI_VERSION",
581 1000 + flag_abi_version);
583 /* libgcc needs to know this. */
584 if (targetm.except_unwind_info () == UI_SJLJ)
585 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
587 /* limits.h and stdint.h need to know these. */
588 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node);
589 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node);
590 builtin_define_type_max ("__INT_MAX__", integer_type_node);
591 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node);
592 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node);
593 builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__",
594 underlying_wchar_type_node);
595 builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node);
596 builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node);
597 builtin_define_type_max ("__SIZE_MAX__", size_type_node);
599 /* stdint.h and the testsuite need to know these. */
600 builtin_define_stdint_macros ();
602 /* float.h needs to know this. */
603 builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
604 TARGET_FLT_EVAL_METHOD);
606 /* And decfloat.h needs this. */
607 builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
608 TARGET_DEC_EVAL_METHOD);
610 builtin_define_float_constants ("FLT", "F", "%s", float_type_node);
611 /* Cast the double precision constants. This is needed when single
612 precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
613 is used. The correct result is computed by the compiler when using
614 macros that include a cast. */
615 builtin_define_float_constants ("DBL", "L", "((double)%s)", double_type_node);
616 builtin_define_float_constants ("LDBL", "L", "%s", long_double_type_node);
618 /* For decfloat.h. */
619 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
620 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
621 builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
623 /* For fixed-point fibt, ibit, max, min, and epsilon. */
624 if (targetm.fixed_point_supported_p ())
626 builtin_define_fixed_point_constants ("SFRACT", "HR",
627 short_fract_type_node);
628 builtin_define_fixed_point_constants ("USFRACT", "UHR",
629 unsigned_short_fract_type_node);
630 builtin_define_fixed_point_constants ("FRACT", "R",
632 builtin_define_fixed_point_constants ("UFRACT", "UR",
633 unsigned_fract_type_node);
634 builtin_define_fixed_point_constants ("LFRACT", "LR",
635 long_fract_type_node);
636 builtin_define_fixed_point_constants ("ULFRACT", "ULR",
637 unsigned_long_fract_type_node);
638 builtin_define_fixed_point_constants ("LLFRACT", "LLR",
639 long_long_fract_type_node);
640 builtin_define_fixed_point_constants ("ULLFRACT", "ULLR",
641 unsigned_long_long_fract_type_node);
642 builtin_define_fixed_point_constants ("SACCUM", "HK",
643 short_accum_type_node);
644 builtin_define_fixed_point_constants ("USACCUM", "UHK",
645 unsigned_short_accum_type_node);
646 builtin_define_fixed_point_constants ("ACCUM", "K",
648 builtin_define_fixed_point_constants ("UACCUM", "UK",
649 unsigned_accum_type_node);
650 builtin_define_fixed_point_constants ("LACCUM", "LK",
651 long_accum_type_node);
652 builtin_define_fixed_point_constants ("ULACCUM", "ULK",
653 unsigned_long_accum_type_node);
654 builtin_define_fixed_point_constants ("LLACCUM", "LLK",
655 long_long_accum_type_node);
656 builtin_define_fixed_point_constants ("ULLACCUM", "ULLK",
657 unsigned_long_long_accum_type_node);
659 builtin_define_fixed_point_constants ("QQ", "", qq_type_node);
660 builtin_define_fixed_point_constants ("HQ", "", hq_type_node);
661 builtin_define_fixed_point_constants ("SQ", "", sq_type_node);
662 builtin_define_fixed_point_constants ("DQ", "", dq_type_node);
663 builtin_define_fixed_point_constants ("TQ", "", tq_type_node);
664 builtin_define_fixed_point_constants ("UQQ", "", uqq_type_node);
665 builtin_define_fixed_point_constants ("UHQ", "", uhq_type_node);
666 builtin_define_fixed_point_constants ("USQ", "", usq_type_node);
667 builtin_define_fixed_point_constants ("UDQ", "", udq_type_node);
668 builtin_define_fixed_point_constants ("UTQ", "", utq_type_node);
669 builtin_define_fixed_point_constants ("HA", "", ha_type_node);
670 builtin_define_fixed_point_constants ("SA", "", sa_type_node);
671 builtin_define_fixed_point_constants ("DA", "", da_type_node);
672 builtin_define_fixed_point_constants ("TA", "", ta_type_node);
673 builtin_define_fixed_point_constants ("UHA", "", uha_type_node);
674 builtin_define_fixed_point_constants ("USA", "", usa_type_node);
675 builtin_define_fixed_point_constants ("UDA", "", uda_type_node);
676 builtin_define_fixed_point_constants ("UTA", "", uta_type_node);
679 /* For use in assembly language. */
680 builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
681 builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
684 if (flag_gnu89_inline)
685 cpp_define (pfile, "__GNUC_GNU_INLINE__");
687 cpp_define (pfile, "__GNUC_STDC_INLINE__");
690 cpp_define (pfile, "__NO_INLINE__");
693 cpp_define (pfile, "__STRICT_ANSI__");
695 if (!flag_signed_char)
696 cpp_define (pfile, "__CHAR_UNSIGNED__");
698 if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
699 cpp_define (pfile, "__WCHAR_UNSIGNED__");
701 /* Tell source code if the compiler makes sync_compare_and_swap
702 builtins available. */
703 #ifdef HAVE_sync_compare_and_swapqi
704 if (HAVE_sync_compare_and_swapqi)
705 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
708 #ifdef HAVE_sync_compare_and_swaphi
709 if (HAVE_sync_compare_and_swaphi)
710 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
713 #ifdef HAVE_sync_compare_and_swapsi
714 if (HAVE_sync_compare_and_swapsi)
715 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
718 #ifdef HAVE_sync_compare_and_swapdi
719 if (HAVE_sync_compare_and_swapdi)
720 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
723 #ifdef HAVE_sync_compare_and_swapti
724 if (HAVE_sync_compare_and_swapti)
725 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
728 #ifdef DWARF2_UNWIND_INFO
729 if (dwarf2out_do_cfi_asm ())
730 cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
733 /* Make the choice of ObjC runtime visible to source code. */
734 if (c_dialect_objc () && flag_next_runtime)
735 cpp_define (pfile, "__NEXT_RUNTIME__");
737 /* Show the availability of some target pragmas. */
738 cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
740 if (targetm.handle_pragma_extern_prefix)
741 cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX");
743 /* Make the choice of the stack protector runtime visible to source code.
744 The macro names and values here were chosen for compatibility with an
745 earlier implementation, i.e. ProPolice. */
746 if (flag_stack_protect == 2)
747 cpp_define (pfile, "__SSP_ALL__=2");
748 else if (flag_stack_protect == 1)
749 cpp_define (pfile, "__SSP__=1");
752 cpp_define (pfile, "_OPENMP=200805");
754 if (int128_integer_type_node != NULL_TREE)
755 builtin_define_type_sizeof ("__SIZEOF_INT128__",
756 int128_integer_type_node);
757 builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
758 builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
759 builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
760 unsigned_ptrdiff_type_node);
762 /* A straightforward target hook doesn't work, because of problems
763 linking that hook's body when part of non-C front ends. */
764 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
765 # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
766 # define builtin_define(TXT) cpp_define (pfile, TXT)
767 # define builtin_assert(TXT) cpp_assert (pfile, TXT)
768 TARGET_CPU_CPP_BUILTINS ();
769 TARGET_OS_CPP_BUILTINS ();
770 TARGET_OBJFMT_CPP_BUILTINS ();
772 /* Support the __declspec keyword by turning them into attributes.
773 Note that the current way we do this may result in a collision
774 with predefined attributes later on. This can be solved by using
775 one attribute, say __declspec__, and passing args to it. The
776 problem with that approach is that args are not accumulated: each
777 new appearance would clobber any existing args. */
779 builtin_define ("__declspec(x)=__attribute__((x))");
781 /* If decimal floating point is supported, tell the user if the
782 alternate format (BID) is used instead of the standard (DPD)
784 if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
785 cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
788 /* Pass an object-like macro. If it doesn't lie in the user's
789 namespace, defines it unconditionally. Otherwise define a version
790 with two leading underscores, and another version with two leading
791 and trailing underscores, and define the original only if an ISO
792 standard was not nominated.
794 e.g. passing "unix" defines "__unix", "__unix__" and possibly
795 "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
798 builtin_define_std (const char *macro)
800 size_t len = strlen (macro);
801 char *buff = (char *) alloca (len + 5);
805 /* prepend __ (or maybe just _) if in user's namespace. */
806 memcpy (p, macro, len + 1);
807 if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
814 cpp_define (parse_in, p);
816 /* If it was in user's namespace... */
819 /* Define the macro with leading and following __. */
825 cpp_define (parse_in, p);
827 /* Finally, define the original macro if permitted. */
829 cpp_define (parse_in, macro);
833 /* Pass an object-like macro and a value to define it to. The third
834 parameter says whether or not to turn the value into a string
837 builtin_define_with_value (const char *macro, const char *expansion, int is_str)
840 size_t mlen = strlen (macro);
841 size_t elen = strlen (expansion);
842 size_t extra = 2; /* space for an = and a NUL */
845 extra += 2; /* space for two quote marks */
847 buf = (char *) alloca (mlen + elen + extra);
849 sprintf (buf, "%s=\"%s\"", macro, expansion);
851 sprintf (buf, "%s=%s", macro, expansion);
853 cpp_define (parse_in, buf);
857 /* Pass an object-like macro and an integer value to define it to. */
859 builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
862 size_t mlen = strlen (macro);
864 size_t extra = 2; /* space for = and NUL. */
866 buf = (char *) alloca (mlen + vlen + extra);
867 memcpy (buf, macro, mlen);
869 sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
871 cpp_define (parse_in, buf);
874 /* builtin_define_with_hex_fp_value is very expensive, so the following
875 array and function allows it to be done lazily when __DBL_MAX__
876 etc. is first used. */
878 struct GTY(()) lazy_hex_fp_value_struct
882 enum machine_mode mode;
884 const char *fp_suffix;
886 static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12];
887 static GTY(()) int lazy_hex_fp_value_count;
890 lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
893 REAL_VALUE_TYPE real;
894 char dec_str[64], buf1[256];
896 if (node->value.builtin < BT_FIRST_USER
897 || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
900 idx = node->value.builtin - BT_FIRST_USER;
901 real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
902 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
903 lazy_hex_fp_values[idx].digits, 0,
904 lazy_hex_fp_values[idx].mode);
906 sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
907 node->flags &= ~(NODE_BUILTIN | NODE_USED);
908 node->value.macro = lazy_hex_fp_values[idx].macro;
909 for (idx = 0; idx < node->value.macro->count; idx++)
910 if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
912 gcc_assert (idx < node->value.macro->count);
913 node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
914 node->value.macro->exp.tokens[idx].val.str.text
915 = (const unsigned char *) ggc_strdup (buf1);
919 /* Pass an object-like macro a hexadecimal floating-point value. */
921 builtin_define_with_hex_fp_value (const char *macro,
922 tree type, int digits,
924 const char *fp_suffix,
927 REAL_VALUE_TYPE real;
928 char dec_str[64], buf1[256], buf2[256];
930 /* This is very expensive, so if possible expand them lazily. */
931 if (lazy_hex_fp_value_count < 12
932 && flag_dump_macros == 0
933 && !cpp_get_options (parse_in)->traditional)
935 struct cpp_hashnode *node;
936 if (lazy_hex_fp_value_count == 0)
937 cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
938 sprintf (buf2, fp_cast, "1.1");
939 sprintf (buf1, "%s=%s", macro, buf2);
940 cpp_define (parse_in, buf1);
941 node = C_CPP_HASHNODE (get_identifier (macro));
942 lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
943 = ggc_strdup (hex_str);
944 lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
945 lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
946 lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
947 lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
948 node->flags |= NODE_BUILTIN;
950 = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
951 lazy_hex_fp_value_count++;
955 /* Hex values are really cool and convenient, except that they're
956 not supported in strict ISO C90 mode. First, the "p-" sequence
957 is not valid as part of a preprocessor number. Second, we get a
958 pedwarn from the preprocessor, which has no context, so we can't
959 suppress the warning with __extension__.
961 So instead what we do is construct the number in hex (because
962 it's easy to get the exact correct value), parse it as a real,
963 then print it back out as decimal. */
965 real_from_string (&real, hex_str);
966 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
969 /* Assemble the macro in the following fashion
970 macro = fp_cast [dec_str fp_suffix] */
971 sprintf (buf1, "%s%s", dec_str, fp_suffix);
972 sprintf (buf2, fp_cast, buf1);
973 sprintf (buf1, "%s=%s", macro, buf2);
975 cpp_define (parse_in, buf1);
978 /* Return a string constant for the suffix for a value of type TYPE
979 promoted according to the integer promotions. The type must be one
980 of the standard integer type nodes. */
983 type_suffix (tree type)
985 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
989 if (type == long_long_integer_type_node
990 || type == long_long_unsigned_type_node)
992 else if (type == long_integer_type_node
993 || type == long_unsigned_type_node)
995 else if (type == integer_type_node
996 || type == unsigned_type_node
997 || type == short_integer_type_node
998 || type == short_unsigned_type_node
999 || type == signed_char_type_node
1000 || type == unsigned_char_type_node
1001 /* ??? "char" is not a signed or unsigned integer type and
1002 so is not permitted for the standard typedefs, but some
1003 systems use it anyway. */
1004 || type == char_type_node)
1009 unsigned_suffix = TYPE_UNSIGNED (type);
1010 if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
1011 unsigned_suffix = 0;
1012 return suffixes[is_long * 2 + unsigned_suffix];
1015 /* Define MACRO as a <stdint.h> constant-suffix macro for TYPE. */
1017 builtin_define_constants (const char *macro, tree type)
1022 suffix = type_suffix (type);
1026 buf = (char *) alloca (strlen (macro) + 6);
1027 sprintf (buf, "%s(c)=c", macro);
1031 buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1);
1032 sprintf (buf, "%s(c)=c ## %s", macro, suffix);
1035 cpp_define (parse_in, buf);
1038 /* Define MAX for TYPE based on the precision of the type. */
1041 builtin_define_type_max (const char *macro, tree type)
1043 builtin_define_type_minmax (NULL, macro, type);
1046 /* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
1047 precision of the type. */
1050 builtin_define_type_minmax (const char *min_macro, const char *max_macro,
1053 static const char *const values[]
1056 "2147483647", "4294967295",
1057 "9223372036854775807", "18446744073709551615",
1058 "170141183460469231731687303715884105727",
1059 "340282366920938463463374607431768211455" };
1061 const char *value, *suffix;
1065 /* Pre-rendering the values mean we don't have to futz with printing a
1066 multi-word decimal value. There are also a very limited number of
1067 precisions that we support, so it's really a waste of time. */
1068 switch (TYPE_PRECISION (type))
1070 case 8: idx = 0; break;
1071 case 16: idx = 2; break;
1072 case 32: idx = 4; break;
1073 case 64: idx = 6; break;
1074 case 128: idx = 8; break;
1075 default: gcc_unreachable ();
1078 value = values[idx + TYPE_UNSIGNED (type)];
1079 suffix = type_suffix (type);
1081 buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)
1082 + strlen (suffix) + 1);
1083 sprintf (buf, "%s=%s%s", max_macro, value, suffix);
1085 cpp_define (parse_in, buf);
1089 if (TYPE_UNSIGNED (type))
1091 buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1);
1092 sprintf (buf, "%s=0%s", min_macro, suffix);
1096 buf = (char *) alloca (strlen (min_macro) + 3
1097 + strlen (max_macro) + 6);
1098 sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro);
1100 cpp_define (parse_in, buf);
1104 #include "gt-c-family-c-cppbuiltin.h"