138fd1498Szrj /* Define builtin-in macros for the C family front ends.
238fd1498Szrj Copyright (C) 2002-2018 Free Software Foundation, Inc.
338fd1498Szrj
438fd1498Szrj This file is part of GCC.
538fd1498Szrj
638fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
738fd1498Szrj the terms of the GNU General Public License as published by the Free
838fd1498Szrj Software Foundation; either version 3, or (at your option) any later
938fd1498Szrj version.
1038fd1498Szrj
1138fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1238fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1438fd1498Szrj for more details.
1538fd1498Szrj
1638fd1498Szrj You should have received a copy of the GNU General Public License
1738fd1498Szrj along with GCC; see the file COPYING3. If not see
1838fd1498Szrj <http://www.gnu.org/licenses/>. */
1938fd1498Szrj
2038fd1498Szrj #include "config.h"
2138fd1498Szrj #include "system.h"
2238fd1498Szrj #include "coretypes.h"
2338fd1498Szrj #include "target.h"
2438fd1498Szrj #include "c-common.h"
2538fd1498Szrj #include "memmodel.h"
2638fd1498Szrj #include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */
2738fd1498Szrj #include "stringpool.h"
2838fd1498Szrj #include "stor-layout.h"
2938fd1498Szrj #include "flags.h"
3038fd1498Szrj #include "c-pragma.h"
3138fd1498Szrj #include "output.h" /* For user_label_prefix. */
3238fd1498Szrj #include "debug.h" /* For dwarf2out_do_cfi_asm. */
3338fd1498Szrj #include "common/common-target.h"
3438fd1498Szrj #include "cpp-id-data.h"
3538fd1498Szrj #include "cppbuiltin.h"
3638fd1498Szrj
3738fd1498Szrj #ifndef TARGET_OS_CPP_BUILTINS
3838fd1498Szrj # define TARGET_OS_CPP_BUILTINS()
3938fd1498Szrj #endif
4038fd1498Szrj
4138fd1498Szrj #ifndef TARGET_OBJFMT_CPP_BUILTINS
4238fd1498Szrj # define TARGET_OBJFMT_CPP_BUILTINS()
4338fd1498Szrj #endif
4438fd1498Szrj
4538fd1498Szrj #ifndef REGISTER_PREFIX
4638fd1498Szrj #define REGISTER_PREFIX ""
4738fd1498Szrj #endif
4838fd1498Szrj
4938fd1498Szrj /* Non-static as some targets don't use it. */
5038fd1498Szrj static void builtin_define_with_hex_fp_value (const char *, tree,
5138fd1498Szrj int, const char *,
5238fd1498Szrj const char *,
5338fd1498Szrj const char *);
5438fd1498Szrj static void builtin_define_stdint_macros (void);
5538fd1498Szrj static void builtin_define_constants (const char *, tree);
5638fd1498Szrj static void builtin_define_type_max (const char *, tree);
5738fd1498Szrj static void builtin_define_type_minmax (const char *, const char *, tree);
5838fd1498Szrj static void builtin_define_type_width (const char *, tree, tree);
5938fd1498Szrj static void builtin_define_float_constants (const char *,
6038fd1498Szrj const char *,
6138fd1498Szrj const char *,
6238fd1498Szrj const char *,
6338fd1498Szrj tree);
6438fd1498Szrj
6538fd1498Szrj /* Return true if MODE provides a fast multiply/add (FMA) builtin function.
6638fd1498Szrj Originally this function used the fma optab, but that doesn't work with
6738fd1498Szrj -save-temps, so just rely on the HAVE_fma macros for the standard floating
6838fd1498Szrj point types. */
6938fd1498Szrj
7038fd1498Szrj static bool
mode_has_fma(machine_mode mode)7138fd1498Szrj mode_has_fma (machine_mode mode)
7238fd1498Szrj {
7338fd1498Szrj switch (mode)
7438fd1498Szrj {
7538fd1498Szrj #ifdef HAVE_fmasf4
7638fd1498Szrj case E_SFmode:
7738fd1498Szrj return !!HAVE_fmasf4;
7838fd1498Szrj #endif
7938fd1498Szrj
8038fd1498Szrj #ifdef HAVE_fmadf4
8138fd1498Szrj case E_DFmode:
8238fd1498Szrj return !!HAVE_fmadf4;
8338fd1498Szrj #endif
8438fd1498Szrj
8538fd1498Szrj #ifdef HAVE_fmakf4 /* PowerPC if long double != __float128. */
8638fd1498Szrj case E_KFmode:
8738fd1498Szrj return !!HAVE_fmakf4;
8838fd1498Szrj #endif
8938fd1498Szrj
9038fd1498Szrj #ifdef HAVE_fmaxf4
9138fd1498Szrj case E_XFmode:
9238fd1498Szrj return !!HAVE_fmaxf4;
9338fd1498Szrj #endif
9438fd1498Szrj
9538fd1498Szrj #ifdef HAVE_fmatf4
9638fd1498Szrj case E_TFmode:
9738fd1498Szrj return !!HAVE_fmatf4;
9838fd1498Szrj #endif
9938fd1498Szrj
10038fd1498Szrj default:
10138fd1498Szrj break;
10238fd1498Szrj }
10338fd1498Szrj
10438fd1498Szrj return false;
10538fd1498Szrj }
10638fd1498Szrj
10738fd1498Szrj /* Define NAME with value TYPE size_unit. */
10838fd1498Szrj void
builtin_define_type_sizeof(const char * name,tree type)10938fd1498Szrj builtin_define_type_sizeof (const char *name, tree type)
11038fd1498Szrj {
11138fd1498Szrj builtin_define_with_int_value (name,
11238fd1498Szrj tree_to_uhwi (TYPE_SIZE_UNIT (type)));
11338fd1498Szrj }
11438fd1498Szrj
11538fd1498Szrj /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
11638fd1498Szrj and FP_CAST. */
11738fd1498Szrj static void
builtin_define_float_constants(const char * name_prefix,const char * fp_suffix,const char * fp_cast,const char * fma_suffix,tree type)11838fd1498Szrj builtin_define_float_constants (const char *name_prefix,
11938fd1498Szrj const char *fp_suffix,
12038fd1498Szrj const char *fp_cast,
12138fd1498Szrj const char *fma_suffix,
12238fd1498Szrj tree type)
12338fd1498Szrj {
12438fd1498Szrj /* Used to convert radix-based values to base 10 values in several cases.
12538fd1498Szrj
12638fd1498Szrj In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
12738fd1498Szrj least 6 significant digits for correct results. Using the fraction
12838fd1498Szrj formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
12938fd1498Szrj intermediate; perhaps someone can find a better approximation, in the
13038fd1498Szrj mean time, I suspect using doubles won't harm the bootstrap here. */
13138fd1498Szrj
13238fd1498Szrj const double log10_2 = .30102999566398119521;
13338fd1498Szrj double log10_b;
13438fd1498Szrj const struct real_format *fmt;
13538fd1498Szrj const struct real_format *widefmt;
13638fd1498Szrj
13738fd1498Szrj char name[64], buf[128];
13838fd1498Szrj int dig, min_10_exp, max_10_exp;
13938fd1498Szrj int decimal_dig;
14038fd1498Szrj int type_decimal_dig;
14138fd1498Szrj
14238fd1498Szrj fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
14338fd1498Szrj gcc_assert (fmt->b != 10);
14438fd1498Szrj widefmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node));
14538fd1498Szrj gcc_assert (widefmt->b != 10);
14638fd1498Szrj for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
14738fd1498Szrj {
14838fd1498Szrj tree wtype = FLOATN_NX_TYPE_NODE (i);
14938fd1498Szrj if (wtype != NULL_TREE)
15038fd1498Szrj {
15138fd1498Szrj const struct real_format *wfmt
15238fd1498Szrj = REAL_MODE_FORMAT (TYPE_MODE (wtype));
15338fd1498Szrj gcc_assert (wfmt->b != 10);
15438fd1498Szrj if (wfmt->p > widefmt->p)
15538fd1498Szrj widefmt = wfmt;
15638fd1498Szrj }
15738fd1498Szrj }
15838fd1498Szrj
15938fd1498Szrj /* The radix of the exponent representation. */
16038fd1498Szrj if (type == float_type_node)
16138fd1498Szrj builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
16238fd1498Szrj log10_b = log10_2;
16338fd1498Szrj
16438fd1498Szrj /* The number of radix digits, p, in the floating-point significand. */
16538fd1498Szrj sprintf (name, "__%s_MANT_DIG__", name_prefix);
16638fd1498Szrj builtin_define_with_int_value (name, fmt->p);
16738fd1498Szrj
16838fd1498Szrj /* The number of decimal digits, q, such that any floating-point number
16938fd1498Szrj with q decimal digits can be rounded into a floating-point number with
17038fd1498Szrj p radix b digits and back again without change to the q decimal digits,
17138fd1498Szrj
17238fd1498Szrj p log10 b if b is a power of 10
17338fd1498Szrj floor((p - 1) log10 b) otherwise
17438fd1498Szrj */
17538fd1498Szrj dig = (fmt->p - 1) * log10_b;
17638fd1498Szrj sprintf (name, "__%s_DIG__", name_prefix);
17738fd1498Szrj builtin_define_with_int_value (name, dig);
17838fd1498Szrj
17938fd1498Szrj /* The minimum negative int x such that b**(x-1) is a normalized float. */
18038fd1498Szrj sprintf (name, "__%s_MIN_EXP__", name_prefix);
18138fd1498Szrj sprintf (buf, "(%d)", fmt->emin);
18238fd1498Szrj builtin_define_with_value (name, buf, 0);
18338fd1498Szrj
18438fd1498Szrj /* The minimum negative int x such that 10**x is a normalized float,
18538fd1498Szrj
18638fd1498Szrj ceil (log10 (b ** (emin - 1)))
18738fd1498Szrj = ceil (log10 (b) * (emin - 1))
18838fd1498Szrj
18938fd1498Szrj Recall that emin is negative, so the integer truncation calculates
19038fd1498Szrj the ceiling, not the floor, in this case. */
19138fd1498Szrj min_10_exp = (fmt->emin - 1) * log10_b;
19238fd1498Szrj sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
19338fd1498Szrj sprintf (buf, "(%d)", min_10_exp);
19438fd1498Szrj builtin_define_with_value (name, buf, 0);
19538fd1498Szrj
19638fd1498Szrj /* The maximum int x such that b**(x-1) is a representable float. */
19738fd1498Szrj sprintf (name, "__%s_MAX_EXP__", name_prefix);
19838fd1498Szrj builtin_define_with_int_value (name, fmt->emax);
19938fd1498Szrj
20038fd1498Szrj /* The maximum int x such that 10**x is in the range of representable
20138fd1498Szrj finite floating-point numbers,
20238fd1498Szrj
20338fd1498Szrj floor (log10((1 - b**-p) * b**emax))
20438fd1498Szrj = floor (log10(1 - b**-p) + log10(b**emax))
20538fd1498Szrj = floor (log10(1 - b**-p) + log10(b)*emax)
20638fd1498Szrj
20738fd1498Szrj The safest thing to do here is to just compute this number. But since
20838fd1498Szrj we don't link cc1 with libm, we cannot. We could implement log10 here
20938fd1498Szrj a series expansion, but that seems too much effort because:
21038fd1498Szrj
21138fd1498Szrj Note that the first term, for all extant p, is a number exceedingly close
21238fd1498Szrj to zero, but slightly negative. Note that the second term is an integer
21338fd1498Szrj scaling an irrational number, and that because of the floor we are only
21438fd1498Szrj interested in its integral portion.
21538fd1498Szrj
21638fd1498Szrj In order for the first term to have any effect on the integral portion
21738fd1498Szrj of the second term, the second term has to be exceedingly close to an
21838fd1498Szrj integer itself (e.g. 123.000000000001 or something). Getting a result
21938fd1498Szrj that close to an integer requires that the irrational multiplicand have
22038fd1498Szrj a long series of zeros in its expansion, which doesn't occur in the
22138fd1498Szrj first 20 digits or so of log10(b).
22238fd1498Szrj
22338fd1498Szrj Hand-waving aside, crunching all of the sets of constants above by hand
22438fd1498Szrj does not yield a case for which the first term is significant, which
22538fd1498Szrj in the end is all that matters. */
22638fd1498Szrj max_10_exp = fmt->emax * log10_b;
22738fd1498Szrj sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
22838fd1498Szrj builtin_define_with_int_value (name, max_10_exp);
22938fd1498Szrj
23038fd1498Szrj /* The number of decimal digits, n, such that any floating-point number
23138fd1498Szrj can be rounded to n decimal digits and back again without change to
23238fd1498Szrj the value.
23338fd1498Szrj
23438fd1498Szrj p * log10(b) if b is a power of 10
23538fd1498Szrj ceil(1 + p * log10(b)) otherwise
23638fd1498Szrj
23738fd1498Szrj The only macro we care about is this number for the widest supported
23838fd1498Szrj floating type, but we want this value for rendering constants below. */
23938fd1498Szrj {
24038fd1498Szrj double d_decimal_dig
24138fd1498Szrj = 1 + (fmt->p < widefmt->p ? widefmt->p : fmt->p) * log10_b;
24238fd1498Szrj decimal_dig = d_decimal_dig;
24338fd1498Szrj if (decimal_dig < d_decimal_dig)
24438fd1498Szrj decimal_dig++;
24538fd1498Szrj }
24638fd1498Szrj /* Similar, for this type rather than long double. */
24738fd1498Szrj {
24838fd1498Szrj double type_d_decimal_dig = 1 + fmt->p * log10_b;
24938fd1498Szrj type_decimal_dig = type_d_decimal_dig;
25038fd1498Szrj if (type_decimal_dig < type_d_decimal_dig)
25138fd1498Szrj type_decimal_dig++;
25238fd1498Szrj }
25338fd1498Szrj /* Define __DECIMAL_DIG__ to the value for long double to be
25438fd1498Szrj compatible with C99 and C11; see DR#501 and N2108. */
25538fd1498Szrj if (type == long_double_type_node)
25638fd1498Szrj builtin_define_with_int_value ("__DECIMAL_DIG__", type_decimal_dig);
25738fd1498Szrj sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
25838fd1498Szrj builtin_define_with_int_value (name, type_decimal_dig);
25938fd1498Szrj
26038fd1498Szrj /* Since, for the supported formats, B is always a power of 2, we
26138fd1498Szrj construct the following numbers directly as a hexadecimal
26238fd1498Szrj constants. */
26338fd1498Szrj get_max_float (fmt, buf, sizeof (buf));
26438fd1498Szrj
26538fd1498Szrj sprintf (name, "__%s_MAX__", name_prefix);
26638fd1498Szrj builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
26738fd1498Szrj
26838fd1498Szrj /* The minimum normalized positive floating-point number,
26938fd1498Szrj b**(emin-1). */
27038fd1498Szrj sprintf (name, "__%s_MIN__", name_prefix);
27138fd1498Szrj sprintf (buf, "0x1p%d", fmt->emin - 1);
27238fd1498Szrj builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
27338fd1498Szrj
27438fd1498Szrj /* The difference between 1 and the least value greater than 1 that is
27538fd1498Szrj representable in the given floating point type, b**(1-p). */
27638fd1498Szrj sprintf (name, "__%s_EPSILON__", name_prefix);
27738fd1498Szrj if (fmt->pnan < fmt->p)
27838fd1498Szrj /* This is an IBM extended double format, so 1.0 + any double is
27938fd1498Szrj representable precisely. */
28038fd1498Szrj sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
28138fd1498Szrj else
28238fd1498Szrj sprintf (buf, "0x1p%d", 1 - fmt->p);
28338fd1498Szrj builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
28438fd1498Szrj
28538fd1498Szrj /* For C++ std::numeric_limits<T>::denorm_min and C11 *_TRUE_MIN.
28638fd1498Szrj The minimum denormalized positive floating-point number, b**(emin-p).
28738fd1498Szrj The minimum normalized positive floating-point number for formats
28838fd1498Szrj that don't support denormals. */
28938fd1498Szrj sprintf (name, "__%s_DENORM_MIN__", name_prefix);
29038fd1498Szrj sprintf (buf, "0x1p%d", fmt->emin - (fmt->has_denorm ? fmt->p : 1));
29138fd1498Szrj builtin_define_with_hex_fp_value (name, type, decimal_dig,
29238fd1498Szrj buf, fp_suffix, fp_cast);
29338fd1498Szrj
29438fd1498Szrj sprintf (name, "__%s_HAS_DENORM__", name_prefix);
29538fd1498Szrj builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
29638fd1498Szrj
29738fd1498Szrj /* For C++ std::numeric_limits<T>::has_infinity. */
29838fd1498Szrj sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
29938fd1498Szrj builtin_define_with_int_value (name,
30038fd1498Szrj MODE_HAS_INFINITIES (TYPE_MODE (type)));
30138fd1498Szrj /* For C++ std::numeric_limits<T>::has_quiet_NaN. We do not have a
30238fd1498Szrj predicate to distinguish a target that has both quiet and
30338fd1498Szrj signalling NaNs from a target that has only quiet NaNs or only
30438fd1498Szrj signalling NaNs, so we assume that a target that has any kind of
30538fd1498Szrj NaN has quiet NaNs. */
30638fd1498Szrj sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
30738fd1498Szrj builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
30838fd1498Szrj
30938fd1498Szrj /* Note whether we have fast FMA. */
31038fd1498Szrj if (mode_has_fma (TYPE_MODE (type)) && fma_suffix != NULL)
31138fd1498Szrj {
31238fd1498Szrj sprintf (name, "__FP_FAST_FMA%s", fma_suffix);
31338fd1498Szrj builtin_define_with_int_value (name, 1);
31438fd1498Szrj }
31538fd1498Szrj }
31638fd1498Szrj
31738fd1498Szrj /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
31838fd1498Szrj static void
builtin_define_decimal_float_constants(const char * name_prefix,const char * suffix,tree type)31938fd1498Szrj builtin_define_decimal_float_constants (const char *name_prefix,
32038fd1498Szrj const char *suffix,
32138fd1498Szrj tree type)
32238fd1498Szrj {
32338fd1498Szrj const struct real_format *fmt;
32438fd1498Szrj char name[64], buf[128], *p;
32538fd1498Szrj int digits;
32638fd1498Szrj
32738fd1498Szrj fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
32838fd1498Szrj
32938fd1498Szrj /* The number of radix digits, p, in the significand. */
33038fd1498Szrj sprintf (name, "__%s_MANT_DIG__", name_prefix);
33138fd1498Szrj builtin_define_with_int_value (name, fmt->p);
33238fd1498Szrj
33338fd1498Szrj /* The minimum negative int x such that b**(x-1) is a normalized float. */
33438fd1498Szrj sprintf (name, "__%s_MIN_EXP__", name_prefix);
33538fd1498Szrj sprintf (buf, "(%d)", fmt->emin);
33638fd1498Szrj builtin_define_with_value (name, buf, 0);
33738fd1498Szrj
33838fd1498Szrj /* The maximum int x such that b**(x-1) is a representable float. */
33938fd1498Szrj sprintf (name, "__%s_MAX_EXP__", name_prefix);
34038fd1498Szrj builtin_define_with_int_value (name, fmt->emax);
34138fd1498Szrj
34238fd1498Szrj /* Compute the minimum representable value. */
34338fd1498Szrj sprintf (name, "__%s_MIN__", name_prefix);
34438fd1498Szrj sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
34538fd1498Szrj builtin_define_with_value (name, buf, 0);
34638fd1498Szrj
34738fd1498Szrj /* Compute the maximum representable value. */
34838fd1498Szrj sprintf (name, "__%s_MAX__", name_prefix);
34938fd1498Szrj p = buf;
35038fd1498Szrj for (digits = fmt->p; digits; digits--)
35138fd1498Szrj {
35238fd1498Szrj *p++ = '9';
35338fd1498Szrj if (digits == fmt->p)
35438fd1498Szrj *p++ = '.';
35538fd1498Szrj }
35638fd1498Szrj *p = 0;
35738fd1498Szrj /* fmt->p plus 1, to account for the decimal point and fmt->emax
35838fd1498Szrj minus 1 because the digits are nines, not 1.0. */
35938fd1498Szrj sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix);
36038fd1498Szrj builtin_define_with_value (name, buf, 0);
36138fd1498Szrj
36238fd1498Szrj /* Compute epsilon (the difference between 1 and least value greater
36338fd1498Szrj than 1 representable). */
36438fd1498Szrj sprintf (name, "__%s_EPSILON__", name_prefix);
36538fd1498Szrj sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
36638fd1498Szrj builtin_define_with_value (name, buf, 0);
36738fd1498Szrj
36838fd1498Szrj /* Minimum subnormal positive decimal value. */
36938fd1498Szrj sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
37038fd1498Szrj p = buf;
37138fd1498Szrj for (digits = fmt->p; digits > 1; digits--)
37238fd1498Szrj {
37338fd1498Szrj *p++ = '0';
37438fd1498Szrj if (digits == fmt->p)
37538fd1498Szrj *p++ = '.';
37638fd1498Szrj }
37738fd1498Szrj *p = 0;
37838fd1498Szrj sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix);
37938fd1498Szrj builtin_define_with_value (name, buf, 0);
38038fd1498Szrj }
38138fd1498Szrj
38238fd1498Szrj /* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */
38338fd1498Szrj
38438fd1498Szrj static void
builtin_define_fixed_point_constants(const char * name_prefix,const char * suffix,tree type)38538fd1498Szrj builtin_define_fixed_point_constants (const char *name_prefix,
38638fd1498Szrj const char *suffix,
38738fd1498Szrj tree type)
38838fd1498Szrj {
38938fd1498Szrj char name[64], buf[256], *new_buf;
39038fd1498Szrj int i, mod;
39138fd1498Szrj
39238fd1498Szrj sprintf (name, "__%s_FBIT__", name_prefix);
39338fd1498Szrj builtin_define_with_int_value (name, TYPE_FBIT (type));
39438fd1498Szrj
39538fd1498Szrj sprintf (name, "__%s_IBIT__", name_prefix);
39638fd1498Szrj builtin_define_with_int_value (name, TYPE_IBIT (type));
39738fd1498Szrj
39838fd1498Szrj /* If there is no suffix, defines are for fixed-point modes.
39938fd1498Szrj We just return. */
40038fd1498Szrj if (strcmp (suffix, "") == 0)
40138fd1498Szrj return;
40238fd1498Szrj
40338fd1498Szrj if (TYPE_UNSIGNED (type))
40438fd1498Szrj {
40538fd1498Szrj sprintf (name, "__%s_MIN__", name_prefix);
40638fd1498Szrj sprintf (buf, "0.0%s", suffix);
40738fd1498Szrj builtin_define_with_value (name, buf, 0);
40838fd1498Szrj }
40938fd1498Szrj else
41038fd1498Szrj {
41138fd1498Szrj sprintf (name, "__%s_MIN__", name_prefix);
41238fd1498Szrj if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
41338fd1498Szrj sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
41438fd1498Szrj TYPE_IBIT (type) - 1, suffix);
41538fd1498Szrj else
41638fd1498Szrj sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
41738fd1498Szrj builtin_define_with_value (name, buf, 0);
41838fd1498Szrj }
41938fd1498Szrj
42038fd1498Szrj sprintf (name, "__%s_MAX__", name_prefix);
42138fd1498Szrj sprintf (buf, "0X");
42238fd1498Szrj new_buf = buf + 2;
42338fd1498Szrj mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
42438fd1498Szrj if (mod)
42538fd1498Szrj sprintf (new_buf++, "%x", (1 << mod) - 1);
42638fd1498Szrj for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
42738fd1498Szrj sprintf (new_buf++, "F");
42838fd1498Szrj sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
42938fd1498Szrj builtin_define_with_value (name, buf, 0);
43038fd1498Szrj
43138fd1498Szrj sprintf (name, "__%s_EPSILON__", name_prefix);
43238fd1498Szrj sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
43338fd1498Szrj builtin_define_with_value (name, buf, 0);
43438fd1498Szrj }
43538fd1498Szrj
43638fd1498Szrj /* Define macros used by <stdint.h>. */
43738fd1498Szrj static void
builtin_define_stdint_macros(void)43838fd1498Szrj builtin_define_stdint_macros (void)
43938fd1498Szrj {
44038fd1498Szrj builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node);
44138fd1498Szrj builtin_define_constants ("__INTMAX_C", intmax_type_node);
44238fd1498Szrj builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node);
44338fd1498Szrj builtin_define_constants ("__UINTMAX_C", uintmax_type_node);
44438fd1498Szrj builtin_define_type_width ("__INTMAX_WIDTH__", intmax_type_node,
44538fd1498Szrj uintmax_type_node);
44638fd1498Szrj if (sig_atomic_type_node)
44738fd1498Szrj {
44838fd1498Szrj builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__",
44938fd1498Szrj sig_atomic_type_node);
45038fd1498Szrj builtin_define_type_width ("__SIG_ATOMIC_WIDTH__", sig_atomic_type_node,
45138fd1498Szrj NULL_TREE);
45238fd1498Szrj }
45338fd1498Szrj if (int8_type_node)
45438fd1498Szrj builtin_define_type_max ("__INT8_MAX__", int8_type_node);
45538fd1498Szrj if (int16_type_node)
45638fd1498Szrj builtin_define_type_max ("__INT16_MAX__", int16_type_node);
45738fd1498Szrj if (int32_type_node)
45838fd1498Szrj builtin_define_type_max ("__INT32_MAX__", int32_type_node);
45938fd1498Szrj if (int64_type_node)
46038fd1498Szrj builtin_define_type_max ("__INT64_MAX__", int64_type_node);
46138fd1498Szrj if (uint8_type_node)
46238fd1498Szrj builtin_define_type_max ("__UINT8_MAX__", uint8_type_node);
46338fd1498Szrj if (c_uint16_type_node)
46438fd1498Szrj builtin_define_type_max ("__UINT16_MAX__", c_uint16_type_node);
46538fd1498Szrj if (c_uint32_type_node)
46638fd1498Szrj builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node);
46738fd1498Szrj if (c_uint64_type_node)
46838fd1498Szrj builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node);
46938fd1498Szrj if (int_least8_type_node)
47038fd1498Szrj {
47138fd1498Szrj builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node);
47238fd1498Szrj builtin_define_constants ("__INT8_C", int_least8_type_node);
47338fd1498Szrj builtin_define_type_width ("__INT_LEAST8_WIDTH__", int_least8_type_node,
47438fd1498Szrj uint_least8_type_node);
47538fd1498Szrj }
47638fd1498Szrj if (int_least16_type_node)
47738fd1498Szrj {
47838fd1498Szrj builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node);
47938fd1498Szrj builtin_define_constants ("__INT16_C", int_least16_type_node);
48038fd1498Szrj builtin_define_type_width ("__INT_LEAST16_WIDTH__",
48138fd1498Szrj int_least16_type_node,
48238fd1498Szrj uint_least16_type_node);
48338fd1498Szrj }
48438fd1498Szrj if (int_least32_type_node)
48538fd1498Szrj {
48638fd1498Szrj builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node);
48738fd1498Szrj builtin_define_constants ("__INT32_C", int_least32_type_node);
48838fd1498Szrj builtin_define_type_width ("__INT_LEAST32_WIDTH__",
48938fd1498Szrj int_least32_type_node,
49038fd1498Szrj uint_least32_type_node);
49138fd1498Szrj }
49238fd1498Szrj if (int_least64_type_node)
49338fd1498Szrj {
49438fd1498Szrj builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node);
49538fd1498Szrj builtin_define_constants ("__INT64_C", int_least64_type_node);
49638fd1498Szrj builtin_define_type_width ("__INT_LEAST64_WIDTH__",
49738fd1498Szrj int_least64_type_node,
49838fd1498Szrj uint_least64_type_node);
49938fd1498Szrj }
50038fd1498Szrj if (uint_least8_type_node)
50138fd1498Szrj {
50238fd1498Szrj builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node);
50338fd1498Szrj builtin_define_constants ("__UINT8_C", uint_least8_type_node);
50438fd1498Szrj }
50538fd1498Szrj if (uint_least16_type_node)
50638fd1498Szrj {
50738fd1498Szrj builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node);
50838fd1498Szrj builtin_define_constants ("__UINT16_C", uint_least16_type_node);
50938fd1498Szrj }
51038fd1498Szrj if (uint_least32_type_node)
51138fd1498Szrj {
51238fd1498Szrj builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node);
51338fd1498Szrj builtin_define_constants ("__UINT32_C", uint_least32_type_node);
51438fd1498Szrj }
51538fd1498Szrj if (uint_least64_type_node)
51638fd1498Szrj {
51738fd1498Szrj builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node);
51838fd1498Szrj builtin_define_constants ("__UINT64_C", uint_least64_type_node);
51938fd1498Szrj }
52038fd1498Szrj if (int_fast8_type_node)
52138fd1498Szrj {
52238fd1498Szrj builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node);
52338fd1498Szrj builtin_define_type_width ("__INT_FAST8_WIDTH__", int_fast8_type_node,
52438fd1498Szrj uint_fast8_type_node);
52538fd1498Szrj }
52638fd1498Szrj if (int_fast16_type_node)
52738fd1498Szrj {
52838fd1498Szrj builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node);
52938fd1498Szrj builtin_define_type_width ("__INT_FAST16_WIDTH__", int_fast16_type_node,
53038fd1498Szrj uint_fast16_type_node);
53138fd1498Szrj }
53238fd1498Szrj if (int_fast32_type_node)
53338fd1498Szrj {
53438fd1498Szrj builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node);
53538fd1498Szrj builtin_define_type_width ("__INT_FAST32_WIDTH__", int_fast32_type_node,
53638fd1498Szrj uint_fast32_type_node);
53738fd1498Szrj }
53838fd1498Szrj if (int_fast64_type_node)
53938fd1498Szrj {
54038fd1498Szrj builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node);
54138fd1498Szrj builtin_define_type_width ("__INT_FAST64_WIDTH__", int_fast64_type_node,
54238fd1498Szrj uint_fast64_type_node);
54338fd1498Szrj }
54438fd1498Szrj if (uint_fast8_type_node)
54538fd1498Szrj builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node);
54638fd1498Szrj if (uint_fast16_type_node)
54738fd1498Szrj builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node);
54838fd1498Szrj if (uint_fast32_type_node)
54938fd1498Szrj builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node);
55038fd1498Szrj if (uint_fast64_type_node)
55138fd1498Szrj builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node);
55238fd1498Szrj if (intptr_type_node)
55338fd1498Szrj {
55438fd1498Szrj builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node);
55538fd1498Szrj builtin_define_type_width ("__INTPTR_WIDTH__", intptr_type_node,
55638fd1498Szrj uintptr_type_node);
55738fd1498Szrj }
55838fd1498Szrj if (uintptr_type_node)
55938fd1498Szrj builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node);
56038fd1498Szrj }
56138fd1498Szrj
56238fd1498Szrj /* Adjust the optimization macros when a #pragma GCC optimization is done to
56338fd1498Szrj reflect the current level. */
56438fd1498Szrj void
c_cpp_builtins_optimize_pragma(cpp_reader * pfile,tree prev_tree,tree cur_tree)56538fd1498Szrj c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
56638fd1498Szrj tree cur_tree)
56738fd1498Szrj {
56838fd1498Szrj struct cl_optimization *prev = TREE_OPTIMIZATION (prev_tree);
56938fd1498Szrj struct cl_optimization *cur = TREE_OPTIMIZATION (cur_tree);
57038fd1498Szrj bool prev_fast_math;
57138fd1498Szrj bool cur_fast_math;
57238fd1498Szrj
57338fd1498Szrj /* -undef turns off target-specific built-ins. */
57438fd1498Szrj if (flag_undef)
57538fd1498Szrj return;
57638fd1498Szrj
57738fd1498Szrj /* Other target-independent built-ins determined by command-line
57838fd1498Szrj options. */
57938fd1498Szrj if (!prev->x_optimize_size && cur->x_optimize_size)
58038fd1498Szrj cpp_define (pfile, "__OPTIMIZE_SIZE__");
58138fd1498Szrj else if (prev->x_optimize_size && !cur->x_optimize_size)
58238fd1498Szrj cpp_undef (pfile, "__OPTIMIZE_SIZE__");
58338fd1498Szrj
58438fd1498Szrj if (!prev->x_optimize && cur->x_optimize)
58538fd1498Szrj cpp_define (pfile, "__OPTIMIZE__");
58638fd1498Szrj else if (prev->x_optimize && !cur->x_optimize)
58738fd1498Szrj cpp_undef (pfile, "__OPTIMIZE__");
58838fd1498Szrj
58938fd1498Szrj prev_fast_math = fast_math_flags_struct_set_p (prev);
59038fd1498Szrj cur_fast_math = fast_math_flags_struct_set_p (cur);
59138fd1498Szrj if (!prev_fast_math && cur_fast_math)
59238fd1498Szrj cpp_define (pfile, "__FAST_MATH__");
59338fd1498Szrj else if (prev_fast_math && !cur_fast_math)
59438fd1498Szrj cpp_undef (pfile, "__FAST_MATH__");
59538fd1498Szrj
59638fd1498Szrj if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
59738fd1498Szrj cpp_define (pfile, "__SUPPORT_SNAN__");
59838fd1498Szrj else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
59938fd1498Szrj cpp_undef (pfile, "__SUPPORT_SNAN__");
60038fd1498Szrj
60138fd1498Szrj if (!prev->x_flag_errno_math && cur->x_flag_errno_math)
60238fd1498Szrj cpp_undef (pfile, "__NO_MATH_ERRNO__");
60338fd1498Szrj else if (prev->x_flag_errno_math && !cur->x_flag_errno_math)
60438fd1498Szrj cpp_define (pfile, "__NO_MATH_ERRNO__");
60538fd1498Szrj
60638fd1498Szrj if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
60738fd1498Szrj {
60838fd1498Szrj cpp_undef (pfile, "__FINITE_MATH_ONLY__");
60938fd1498Szrj cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
61038fd1498Szrj }
61138fd1498Szrj else if (prev->x_flag_finite_math_only && !cur->x_flag_finite_math_only)
61238fd1498Szrj {
61338fd1498Szrj cpp_undef (pfile, "__FINITE_MATH_ONLY__");
61438fd1498Szrj cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
61538fd1498Szrj }
61638fd1498Szrj }
61738fd1498Szrj
61838fd1498Szrj
61938fd1498Szrj /* This function will emit cpp macros to indicate the presence of various lock
62038fd1498Szrj free atomic operations. */
62138fd1498Szrj
62238fd1498Szrj static void
cpp_atomic_builtins(cpp_reader * pfile)62338fd1498Szrj cpp_atomic_builtins (cpp_reader *pfile)
62438fd1498Szrj {
62538fd1498Szrj /* Set a flag for each size of object that compare and swap exists for up to
62638fd1498Szrj a 16 byte object. */
62738fd1498Szrj #define SWAP_LIMIT 17
62838fd1498Szrj bool have_swap[SWAP_LIMIT];
62938fd1498Szrj unsigned int psize;
63038fd1498Szrj
63138fd1498Szrj /* Clear the map of sizes compare_and swap exists for. */
63238fd1498Szrj memset (have_swap, 0, sizeof (have_swap));
63338fd1498Szrj
63438fd1498Szrj /* Tell source code if the compiler makes sync_compare_and_swap
63538fd1498Szrj builtins available. */
63638fd1498Szrj #ifndef HAVE_sync_compare_and_swapqi
63738fd1498Szrj #define HAVE_sync_compare_and_swapqi 0
63838fd1498Szrj #endif
63938fd1498Szrj #ifndef HAVE_atomic_compare_and_swapqi
64038fd1498Szrj #define HAVE_atomic_compare_and_swapqi 0
64138fd1498Szrj #endif
64238fd1498Szrj
64338fd1498Szrj if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
64438fd1498Szrj {
64538fd1498Szrj cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
64638fd1498Szrj have_swap[1] = true;
64738fd1498Szrj }
64838fd1498Szrj
64938fd1498Szrj #ifndef HAVE_sync_compare_and_swaphi
65038fd1498Szrj #define HAVE_sync_compare_and_swaphi 0
65138fd1498Szrj #endif
65238fd1498Szrj #ifndef HAVE_atomic_compare_and_swaphi
65338fd1498Szrj #define HAVE_atomic_compare_and_swaphi 0
65438fd1498Szrj #endif
65538fd1498Szrj if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
65638fd1498Szrj {
65738fd1498Szrj cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
65838fd1498Szrj have_swap[2] = true;
65938fd1498Szrj }
66038fd1498Szrj
66138fd1498Szrj #ifndef HAVE_sync_compare_and_swapsi
66238fd1498Szrj #define HAVE_sync_compare_and_swapsi 0
66338fd1498Szrj #endif
66438fd1498Szrj #ifndef HAVE_atomic_compare_and_swapsi
66538fd1498Szrj #define HAVE_atomic_compare_and_swapsi 0
66638fd1498Szrj #endif
66738fd1498Szrj if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
66838fd1498Szrj {
66938fd1498Szrj cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
67038fd1498Szrj have_swap[4] = true;
67138fd1498Szrj }
67238fd1498Szrj
67338fd1498Szrj #ifndef HAVE_sync_compare_and_swapdi
67438fd1498Szrj #define HAVE_sync_compare_and_swapdi 0
67538fd1498Szrj #endif
67638fd1498Szrj #ifndef HAVE_atomic_compare_and_swapdi
67738fd1498Szrj #define HAVE_atomic_compare_and_swapdi 0
67838fd1498Szrj #endif
67938fd1498Szrj if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
68038fd1498Szrj {
68138fd1498Szrj cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
68238fd1498Szrj have_swap[8] = true;
68338fd1498Szrj }
68438fd1498Szrj
68538fd1498Szrj #ifndef HAVE_sync_compare_and_swapti
68638fd1498Szrj #define HAVE_sync_compare_and_swapti 0
68738fd1498Szrj #endif
68838fd1498Szrj #ifndef HAVE_atomic_compare_and_swapti
68938fd1498Szrj #define HAVE_atomic_compare_and_swapti 0
69038fd1498Szrj #endif
69138fd1498Szrj if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
69238fd1498Szrj {
69338fd1498Szrj cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
69438fd1498Szrj have_swap[16] = true;
69538fd1498Szrj }
69638fd1498Szrj
69738fd1498Szrj /* Tell the source code about various types. These map to the C++11 and C11
69838fd1498Szrj macros where 2 indicates lock-free always, and 1 indicates sometimes
69938fd1498Szrj lock free. */
70038fd1498Szrj #define SIZEOF_NODE(T) (tree_to_uhwi (TYPE_SIZE_UNIT (T)))
70138fd1498Szrj #define SWAP_INDEX(T) ((SIZEOF_NODE (T) < SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
70238fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_BOOL_LOCK_FREE",
70338fd1498Szrj (have_swap[SWAP_INDEX (boolean_type_node)]? 2 : 1));
70438fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_CHAR_LOCK_FREE",
70538fd1498Szrj (have_swap[SWAP_INDEX (signed_char_type_node)]? 2 : 1));
70638fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_CHAR16_T_LOCK_FREE",
70738fd1498Szrj (have_swap[SWAP_INDEX (char16_type_node)]? 2 : 1));
70838fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_CHAR32_T_LOCK_FREE",
70938fd1498Szrj (have_swap[SWAP_INDEX (char32_type_node)]? 2 : 1));
71038fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_WCHAR_T_LOCK_FREE",
71138fd1498Szrj (have_swap[SWAP_INDEX (wchar_type_node)]? 2 : 1));
71238fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_SHORT_LOCK_FREE",
71338fd1498Szrj (have_swap[SWAP_INDEX (short_integer_type_node)]? 2 : 1));
71438fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_INT_LOCK_FREE",
71538fd1498Szrj (have_swap[SWAP_INDEX (integer_type_node)]? 2 : 1));
71638fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_LONG_LOCK_FREE",
71738fd1498Szrj (have_swap[SWAP_INDEX (long_integer_type_node)]? 2 : 1));
71838fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_LLONG_LOCK_FREE",
71938fd1498Szrj (have_swap[SWAP_INDEX (long_long_integer_type_node)]? 2 : 1));
72038fd1498Szrj
72138fd1498Szrj /* If we're dealing with a "set" value that doesn't exactly correspond
72238fd1498Szrj to a boolean truth value, let the library work around that. */
72338fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL",
72438fd1498Szrj targetm.atomic_test_and_set_trueval);
72538fd1498Szrj
72638fd1498Szrj /* ptr_type_node can't be used here since ptr_mode is only set when
72738fd1498Szrj toplev calls backend_init which is not done with -E or pch. */
72838fd1498Szrj psize = POINTER_SIZE_UNITS;
72938fd1498Szrj if (psize >= SWAP_LIMIT)
73038fd1498Szrj psize = 0;
73138fd1498Szrj builtin_define_with_int_value ("__GCC_ATOMIC_POINTER_LOCK_FREE",
73238fd1498Szrj (have_swap[psize]? 2 : 1));
73338fd1498Szrj }
73438fd1498Szrj
73538fd1498Szrj /* Return TRUE if the implicit excess precision in which the back-end will
73638fd1498Szrj compute floating-point calculations is not more than the explicit
73738fd1498Szrj excess precision that the front-end will apply under
73838fd1498Szrj -fexcess-precision=[standard|fast].
73938fd1498Szrj
74038fd1498Szrj More intuitively, return TRUE if the excess precision proposed by the
74138fd1498Szrj front-end is the excess precision that will actually be used. */
74238fd1498Szrj
74338fd1498Szrj static bool
c_cpp_flt_eval_method_iec_559(void)74438fd1498Szrj c_cpp_flt_eval_method_iec_559 (void)
74538fd1498Szrj {
74638fd1498Szrj enum excess_precision_type front_end_ept
74738fd1498Szrj = (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
74838fd1498Szrj ? EXCESS_PRECISION_TYPE_STANDARD
74938fd1498Szrj : EXCESS_PRECISION_TYPE_FAST);
75038fd1498Szrj
75138fd1498Szrj enum flt_eval_method back_end
75238fd1498Szrj = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT);
75338fd1498Szrj
75438fd1498Szrj enum flt_eval_method front_end
75538fd1498Szrj = targetm.c.excess_precision (front_end_ept);
75638fd1498Szrj
75738fd1498Szrj return excess_precision_mode_join (front_end, back_end) == front_end;
75838fd1498Szrj }
75938fd1498Szrj
76038fd1498Szrj /* Return the value for __GCC_IEC_559. */
76138fd1498Szrj static int
cpp_iec_559_value(void)76238fd1498Szrj cpp_iec_559_value (void)
76338fd1498Szrj {
76438fd1498Szrj /* The default is support for IEEE 754-2008. */
76538fd1498Szrj int ret = 2;
76638fd1498Szrj
76738fd1498Szrj /* float and double must be binary32 and binary64. If they are but
76838fd1498Szrj with reversed NaN convention, at most IEEE 754-1985 is
76938fd1498Szrj supported. */
77038fd1498Szrj const struct real_format *ffmt
77138fd1498Szrj = REAL_MODE_FORMAT (TYPE_MODE (float_type_node));
77238fd1498Szrj const struct real_format *dfmt
77338fd1498Szrj = REAL_MODE_FORMAT (TYPE_MODE (double_type_node));
77438fd1498Szrj if (!ffmt->qnan_msb_set || !dfmt->qnan_msb_set)
77538fd1498Szrj ret = 1;
77638fd1498Szrj if (ffmt->b != 2
77738fd1498Szrj || ffmt->p != 24
77838fd1498Szrj || ffmt->pnan != 24
77938fd1498Szrj || ffmt->emin != -125
78038fd1498Szrj || ffmt->emax != 128
78138fd1498Szrj || ffmt->signbit_rw != 31
78238fd1498Szrj || ffmt->round_towards_zero
78338fd1498Szrj || !ffmt->has_sign_dependent_rounding
78438fd1498Szrj || !ffmt->has_nans
78538fd1498Szrj || !ffmt->has_inf
78638fd1498Szrj || !ffmt->has_denorm
78738fd1498Szrj || !ffmt->has_signed_zero
78838fd1498Szrj || dfmt->b != 2
78938fd1498Szrj || dfmt->p != 53
79038fd1498Szrj || dfmt->pnan != 53
79138fd1498Szrj || dfmt->emin != -1021
79238fd1498Szrj || dfmt->emax != 1024
79338fd1498Szrj || dfmt->signbit_rw != 63
79438fd1498Szrj || dfmt->round_towards_zero
79538fd1498Szrj || !dfmt->has_sign_dependent_rounding
79638fd1498Szrj || !dfmt->has_nans
79738fd1498Szrj || !dfmt->has_inf
79838fd1498Szrj || !dfmt->has_denorm
79938fd1498Szrj || !dfmt->has_signed_zero)
80038fd1498Szrj ret = 0;
80138fd1498Szrj
80238fd1498Szrj /* In strict C standards conformance mode, consider a back-end providing
80338fd1498Szrj more implicit excess precision than the explicit excess precision
80438fd1498Szrj the front-end options would require to mean a lack of IEEE 754
80538fd1498Szrj support. For C++, and outside strict conformance mode, do not consider
80638fd1498Szrj this to mean a lack of IEEE 754 support. */
80738fd1498Szrj
80838fd1498Szrj if (flag_iso
80938fd1498Szrj && !c_dialect_cxx ()
81038fd1498Szrj && !c_cpp_flt_eval_method_iec_559 ())
81138fd1498Szrj ret = 0;
81238fd1498Szrj
81338fd1498Szrj if (flag_iso
81438fd1498Szrj && !c_dialect_cxx ()
81538fd1498Szrj && flag_fp_contract_mode == FP_CONTRACT_FAST)
81638fd1498Szrj ret = 0;
81738fd1498Szrj
81838fd1498Szrj /* Various options are contrary to IEEE 754 semantics. */
81938fd1498Szrj if (flag_unsafe_math_optimizations
82038fd1498Szrj || flag_associative_math
82138fd1498Szrj || flag_reciprocal_math
82238fd1498Szrj || flag_finite_math_only
82338fd1498Szrj || !flag_signed_zeros
82438fd1498Szrj || flag_single_precision_constant)
82538fd1498Szrj ret = 0;
82638fd1498Szrj
82738fd1498Szrj /* If the target does not support IEEE 754 exceptions and rounding
82838fd1498Szrj modes, consider IEEE 754 support to be absent. */
82938fd1498Szrj if (!targetm.float_exceptions_rounding_supported_p ())
83038fd1498Szrj ret = 0;
83138fd1498Szrj
83238fd1498Szrj return ret;
83338fd1498Szrj }
83438fd1498Szrj
83538fd1498Szrj /* Return the value for __GCC_IEC_559_COMPLEX. */
83638fd1498Szrj static int
cpp_iec_559_complex_value(void)83738fd1498Szrj cpp_iec_559_complex_value (void)
83838fd1498Szrj {
83938fd1498Szrj /* The value is no bigger than that of __GCC_IEC_559. */
84038fd1498Szrj int ret = cpp_iec_559_value ();
84138fd1498Szrj
84238fd1498Szrj /* Some options are contrary to the required default state of the
84338fd1498Szrj CX_LIMITED_RANGE pragma. */
84438fd1498Szrj if (flag_complex_method != 2)
84538fd1498Szrj ret = 0;
84638fd1498Szrj
84738fd1498Szrj return ret;
84838fd1498Szrj }
84938fd1498Szrj
85038fd1498Szrj /* Hook that registers front end and target-specific built-ins. */
85138fd1498Szrj void
c_cpp_builtins(cpp_reader * pfile)85238fd1498Szrj c_cpp_builtins (cpp_reader *pfile)
85338fd1498Szrj {
85438fd1498Szrj int i;
85538fd1498Szrj
85638fd1498Szrj /* -undef turns off target-specific built-ins. */
85738fd1498Szrj if (flag_undef)
85838fd1498Szrj return;
85938fd1498Szrj
86038fd1498Szrj define_language_independent_builtin_macros (pfile);
86138fd1498Szrj
86238fd1498Szrj if (c_dialect_cxx ())
86338fd1498Szrj {
86438fd1498Szrj int major;
86538fd1498Szrj parse_basever (&major, NULL, NULL);
86638fd1498Szrj cpp_define_formatted (pfile, "__GNUG__=%d", major);
86738fd1498Szrj }
86838fd1498Szrj
86938fd1498Szrj /* For stddef.h. They require macros defined in c-common.c. */
87038fd1498Szrj c_stddef_cpp_builtins ();
87138fd1498Szrj
87238fd1498Szrj /* Set include test macros for all C/C++ (not for just C++11 etc.)
87338fd1498Szrj The builtins __has_include__ and __has_include_next__ are defined
87438fd1498Szrj in libcpp. */
87538fd1498Szrj cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
87638fd1498Szrj cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
87738fd1498Szrj
87838fd1498Szrj if (c_dialect_cxx ())
87938fd1498Szrj {
88038fd1498Szrj if (flag_weak && SUPPORTS_ONE_ONLY)
88138fd1498Szrj cpp_define (pfile, "__GXX_WEAK__=1");
88238fd1498Szrj else
88338fd1498Szrj cpp_define (pfile, "__GXX_WEAK__=0");
88438fd1498Szrj
88538fd1498Szrj if (warn_deprecated)
88638fd1498Szrj cpp_define (pfile, "__DEPRECATED");
88738fd1498Szrj
88838fd1498Szrj if (flag_rtti)
88938fd1498Szrj {
89038fd1498Szrj cpp_define (pfile, "__GXX_RTTI");
89138fd1498Szrj cpp_define (pfile, "__cpp_rtti=199711");
89238fd1498Szrj }
89338fd1498Szrj
89438fd1498Szrj if (cxx_dialect >= cxx11)
89538fd1498Szrj cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
89638fd1498Szrj
89738fd1498Szrj /* Binary literals have been allowed in g++ before C++11
89838fd1498Szrj and were standardized for C++14. */
89938fd1498Szrj if (!pedantic || cxx_dialect > cxx11)
90038fd1498Szrj cpp_define (pfile, "__cpp_binary_literals=201304");
90138fd1498Szrj
90238fd1498Szrj /* Similarly for hexadecimal floating point literals and C++17. */
90338fd1498Szrj if (!pedantic || cpp_get_options (parse_in)->extended_numbers)
90438fd1498Szrj cpp_define (pfile, "__cpp_hex_float=201603");
90538fd1498Szrj
90638fd1498Szrj /* Arrays of runtime bound were removed from C++14, but we still
90738fd1498Szrj support GNU VLAs. Let's define this macro to a low number
90838fd1498Szrj (corresponding to the initial test release of GNU C++) if we won't
90938fd1498Szrj complain about use of VLAs. */
91038fd1498Szrj if (c_dialect_cxx ()
91138fd1498Szrj && (pedantic ? warn_vla == 0 : warn_vla <= 0))
91238fd1498Szrj cpp_define (pfile, "__cpp_runtime_arrays=198712");
91338fd1498Szrj
91438fd1498Szrj if (cxx_dialect >= cxx11)
91538fd1498Szrj {
91638fd1498Szrj /* Set feature test macros for C++11. */
91738fd1498Szrj if (cxx_dialect <= cxx14)
91838fd1498Szrj cpp_define (pfile, "__cpp_unicode_characters=200704");
91938fd1498Szrj cpp_define (pfile, "__cpp_raw_strings=200710");
92038fd1498Szrj cpp_define (pfile, "__cpp_unicode_literals=200710");
92138fd1498Szrj cpp_define (pfile, "__cpp_user_defined_literals=200809");
92238fd1498Szrj cpp_define (pfile, "__cpp_lambdas=200907");
92338fd1498Szrj if (cxx_dialect == cxx11)
92438fd1498Szrj cpp_define (pfile, "__cpp_constexpr=200704");
92538fd1498Szrj if (cxx_dialect <= cxx14)
92638fd1498Szrj cpp_define (pfile, "__cpp_range_based_for=200907");
92738fd1498Szrj if (cxx_dialect <= cxx14)
92838fd1498Szrj cpp_define (pfile, "__cpp_static_assert=200410");
92938fd1498Szrj cpp_define (pfile, "__cpp_decltype=200707");
93038fd1498Szrj cpp_define (pfile, "__cpp_attributes=200809");
93138fd1498Szrj cpp_define (pfile, "__cpp_rvalue_reference=200610");
93238fd1498Szrj cpp_define (pfile, "__cpp_rvalue_references=200610");
93338fd1498Szrj cpp_define (pfile, "__cpp_variadic_templates=200704");
93438fd1498Szrj cpp_define (pfile, "__cpp_initializer_lists=200806");
93538fd1498Szrj cpp_define (pfile, "__cpp_delegating_constructors=200604");
93638fd1498Szrj cpp_define (pfile, "__cpp_nsdmi=200809");
93738fd1498Szrj if (!flag_new_inheriting_ctors)
93838fd1498Szrj cpp_define (pfile, "__cpp_inheriting_constructors=200802");
93938fd1498Szrj else
94038fd1498Szrj cpp_define (pfile, "__cpp_inheriting_constructors=201511");
94138fd1498Szrj cpp_define (pfile, "__cpp_ref_qualifiers=200710");
94238fd1498Szrj cpp_define (pfile, "__cpp_alias_templates=200704");
94338fd1498Szrj }
94438fd1498Szrj if (cxx_dialect > cxx11)
94538fd1498Szrj {
94638fd1498Szrj /* Set feature test macros for C++14. */
94738fd1498Szrj cpp_define (pfile, "__cpp_return_type_deduction=201304");
94838fd1498Szrj cpp_define (pfile, "__cpp_init_captures=201304");
94938fd1498Szrj cpp_define (pfile, "__cpp_generic_lambdas=201304");
95038fd1498Szrj if (cxx_dialect <= cxx14)
95138fd1498Szrj cpp_define (pfile, "__cpp_constexpr=201304");
95238fd1498Szrj cpp_define (pfile, "__cpp_decltype_auto=201304");
95338fd1498Szrj cpp_define (pfile, "__cpp_aggregate_nsdmi=201304");
95438fd1498Szrj cpp_define (pfile, "__cpp_variable_templates=201304");
95538fd1498Szrj cpp_define (pfile, "__cpp_digit_separators=201309");
95638fd1498Szrj }
95738fd1498Szrj if (cxx_dialect > cxx14)
95838fd1498Szrj {
95938fd1498Szrj /* Set feature test macros for C++1z. */
96038fd1498Szrj cpp_define (pfile, "__cpp_unicode_characters=201411");
96138fd1498Szrj cpp_define (pfile, "__cpp_static_assert=201411");
96238fd1498Szrj cpp_define (pfile, "__cpp_namespace_attributes=201411");
96338fd1498Szrj cpp_define (pfile, "__cpp_enumerator_attributes=201411");
96438fd1498Szrj cpp_define (pfile, "__cpp_nested_namespace_definitions=201411");
96538fd1498Szrj cpp_define (pfile, "__cpp_fold_expressions=201603");
96638fd1498Szrj cpp_define (pfile, "__cpp_nontype_template_args=201411");
96738fd1498Szrj cpp_define (pfile, "__cpp_range_based_for=201603");
96838fd1498Szrj cpp_define (pfile, "__cpp_constexpr=201603");
96938fd1498Szrj cpp_define (pfile, "__cpp_if_constexpr=201606");
97038fd1498Szrj cpp_define (pfile, "__cpp_capture_star_this=201603");
97138fd1498Szrj cpp_define (pfile, "__cpp_inline_variables=201606");
97238fd1498Szrj cpp_define (pfile, "__cpp_aggregate_bases=201603");
97338fd1498Szrj cpp_define (pfile, "__cpp_deduction_guides=201611");
97438fd1498Szrj cpp_define (pfile, "__cpp_noexcept_function_type=201510");
975*58e805e6Szrj /* Old macro, superseded by
976*58e805e6Szrj __cpp_nontype_template_parameter_auto. */
97738fd1498Szrj cpp_define (pfile, "__cpp_template_auto=201606");
97838fd1498Szrj cpp_define (pfile, "__cpp_structured_bindings=201606");
97938fd1498Szrj cpp_define (pfile, "__cpp_variadic_using=201611");
980*58e805e6Szrj cpp_define (pfile, "__cpp_guaranteed_copy_elision=201606");
981*58e805e6Szrj cpp_define (pfile, "__cpp_nontype_template_parameter_auto=201606");
98238fd1498Szrj }
98338fd1498Szrj if (flag_concepts)
98438fd1498Szrj cpp_define (pfile, "__cpp_concepts=201507");
98538fd1498Szrj if (flag_tm)
98638fd1498Szrj /* Use a value smaller than the 201505 specified in
98738fd1498Szrj the TS, since we don't yet support atomic_cancel. */
98838fd1498Szrj cpp_define (pfile, "__cpp_transactional_memory=210500");
98938fd1498Szrj if (flag_sized_deallocation)
99038fd1498Szrj cpp_define (pfile, "__cpp_sized_deallocation=201309");
99138fd1498Szrj if (aligned_new_threshold)
99238fd1498Szrj {
99338fd1498Szrj cpp_define (pfile, "__cpp_aligned_new=201606");
99438fd1498Szrj cpp_define_formatted (pfile, "__STDCPP_DEFAULT_NEW_ALIGNMENT__=%d",
99538fd1498Szrj aligned_new_threshold);
99638fd1498Szrj }
99738fd1498Szrj if (flag_new_ttp)
99838fd1498Szrj cpp_define (pfile, "__cpp_template_template_args=201611");
99938fd1498Szrj if (flag_threadsafe_statics)
100038fd1498Szrj cpp_define (pfile, "__cpp_threadsafe_static_init=200806");
100138fd1498Szrj }
100238fd1498Szrj /* Note that we define this for C as well, so that we know if
100338fd1498Szrj __attribute__((cleanup)) will interface with EH. */
100438fd1498Szrj if (flag_exceptions)
100538fd1498Szrj {
100638fd1498Szrj cpp_define (pfile, "__EXCEPTIONS");
100738fd1498Szrj if (c_dialect_cxx ())
100838fd1498Szrj cpp_define (pfile, "__cpp_exceptions=199711");
100938fd1498Szrj }
101038fd1498Szrj
101138fd1498Szrj /* Represents the C++ ABI version, always defined so it can be used while
101238fd1498Szrj preprocessing C and assembler. */
101338fd1498Szrj if (flag_abi_version == 0)
101438fd1498Szrj /* We should have set this to something real in c_common_post_options. */
101538fd1498Szrj gcc_unreachable ();
101638fd1498Szrj else if (flag_abi_version == 1)
101738fd1498Szrj /* Due to a historical accident, this version had the value
101838fd1498Szrj "102". */
101938fd1498Szrj builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
102038fd1498Szrj else
102138fd1498Szrj /* Newer versions have values 1002, 1003, .... */
102238fd1498Szrj builtin_define_with_int_value ("__GXX_ABI_VERSION",
102338fd1498Szrj 1000 + flag_abi_version);
102438fd1498Szrj
102538fd1498Szrj /* libgcc needs to know this. */
102638fd1498Szrj if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
102738fd1498Szrj cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
102838fd1498Szrj
102938fd1498Szrj /* limits.h and stdint.h need to know these. */
103038fd1498Szrj builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node);
103138fd1498Szrj builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node);
103238fd1498Szrj builtin_define_type_max ("__INT_MAX__", integer_type_node);
103338fd1498Szrj builtin_define_type_max ("__LONG_MAX__", long_integer_type_node);
103438fd1498Szrj builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node);
103538fd1498Szrj builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__",
103638fd1498Szrj underlying_wchar_type_node);
103738fd1498Szrj builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node);
103838fd1498Szrj builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node);
103938fd1498Szrj builtin_define_type_max ("__SIZE_MAX__", size_type_node);
104038fd1498Szrj
104138fd1498Szrj /* These are needed for TS 18661-1. */
104238fd1498Szrj builtin_define_type_width ("__SCHAR_WIDTH__", signed_char_type_node,
104338fd1498Szrj unsigned_char_type_node);
104438fd1498Szrj builtin_define_type_width ("__SHRT_WIDTH__", short_integer_type_node,
104538fd1498Szrj short_unsigned_type_node);
104638fd1498Szrj builtin_define_type_width ("__INT_WIDTH__", integer_type_node,
104738fd1498Szrj unsigned_type_node);
104838fd1498Szrj builtin_define_type_width ("__LONG_WIDTH__", long_integer_type_node,
104938fd1498Szrj long_unsigned_type_node);
105038fd1498Szrj builtin_define_type_width ("__LONG_LONG_WIDTH__",
105138fd1498Szrj long_long_integer_type_node,
105238fd1498Szrj long_long_unsigned_type_node);
105338fd1498Szrj builtin_define_type_width ("__WCHAR_WIDTH__", underlying_wchar_type_node,
105438fd1498Szrj NULL_TREE);
105538fd1498Szrj builtin_define_type_width ("__WINT_WIDTH__", wint_type_node, NULL_TREE);
105638fd1498Szrj builtin_define_type_width ("__PTRDIFF_WIDTH__", ptrdiff_type_node, NULL_TREE);
105738fd1498Szrj builtin_define_type_width ("__SIZE_WIDTH__", size_type_node, NULL_TREE);
105838fd1498Szrj
105938fd1498Szrj if (c_dialect_cxx ())
106038fd1498Szrj for (i = 0; i < NUM_INT_N_ENTS; i ++)
106138fd1498Szrj if (int_n_enabled_p[i])
106238fd1498Szrj {
106338fd1498Szrj char buf[35+20+20];
106438fd1498Szrj
106538fd1498Szrj /* These are used to configure the C++ library. */
106638fd1498Szrj
106738fd1498Szrj if (!flag_iso || int_n_data[i].bitsize == POINTER_SIZE)
106838fd1498Szrj {
106938fd1498Szrj sprintf (buf, "__GLIBCXX_TYPE_INT_N_%d=__int%d", i, int_n_data[i].bitsize);
107038fd1498Szrj cpp_define (parse_in, buf);
107138fd1498Szrj
107238fd1498Szrj sprintf (buf, "__GLIBCXX_BITSIZE_INT_N_%d=%d", i, int_n_data[i].bitsize);
107338fd1498Szrj cpp_define (parse_in, buf);
107438fd1498Szrj }
107538fd1498Szrj }
107638fd1498Szrj
107738fd1498Szrj /* stdint.h and the testsuite need to know these. */
107838fd1498Szrj builtin_define_stdint_macros ();
107938fd1498Szrj
108038fd1498Szrj /* Provide information for library headers to determine whether to
108138fd1498Szrj define macros such as __STDC_IEC_559__ and
108238fd1498Szrj __STDC_IEC_559_COMPLEX__. */
108338fd1498Szrj builtin_define_with_int_value ("__GCC_IEC_559", cpp_iec_559_value ());
108438fd1498Szrj builtin_define_with_int_value ("__GCC_IEC_559_COMPLEX",
108538fd1498Szrj cpp_iec_559_complex_value ());
108638fd1498Szrj
108738fd1498Szrj /* float.h needs these to correctly set FLT_EVAL_METHOD
108838fd1498Szrj
108938fd1498Szrj We define two values:
109038fd1498Szrj
109138fd1498Szrj __FLT_EVAL_METHOD__
109238fd1498Szrj Which, depending on the value given for
109338fd1498Szrj -fpermitted-flt-eval-methods, may be limited to only those values
109438fd1498Szrj for FLT_EVAL_METHOD defined in C99/C11.
109538fd1498Szrj
109638fd1498Szrj __FLT_EVAL_METHOD_TS_18661_3__
109738fd1498Szrj Which always permits the values for FLT_EVAL_METHOD defined in
109838fd1498Szrj ISO/IEC TS 18661-3. */
109938fd1498Szrj builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
110038fd1498Szrj c_flt_eval_method (true));
110138fd1498Szrj builtin_define_with_int_value ("__FLT_EVAL_METHOD_TS_18661_3__",
110238fd1498Szrj c_flt_eval_method (false));
110338fd1498Szrj
110438fd1498Szrj /* And decfloat.h needs this. */
110538fd1498Szrj builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
110638fd1498Szrj TARGET_DEC_EVAL_METHOD);
110738fd1498Szrj
110838fd1498Szrj builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
110938fd1498Szrj /* Cast the double precision constants. This is needed when single
111038fd1498Szrj precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
111138fd1498Szrj is used. The correct result is computed by the compiler when using
111238fd1498Szrj macros that include a cast. We use a different cast for C++ to avoid
111338fd1498Szrj problems with -Wold-style-cast. */
111438fd1498Szrj builtin_define_float_constants ("DBL", "L",
111538fd1498Szrj (c_dialect_cxx ()
111638fd1498Szrj ? "double(%s)"
111738fd1498Szrj : "((double)%s)"),
111838fd1498Szrj "", double_type_node);
111938fd1498Szrj builtin_define_float_constants ("LDBL", "L", "%s", "L",
112038fd1498Szrj long_double_type_node);
112138fd1498Szrj
112238fd1498Szrj for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
112338fd1498Szrj {
112438fd1498Szrj if (FLOATN_NX_TYPE_NODE (i) == NULL_TREE)
112538fd1498Szrj continue;
112638fd1498Szrj char prefix[20], csuffix[20];
112738fd1498Szrj sprintf (prefix, "FLT%d%s", floatn_nx_types[i].n,
112838fd1498Szrj floatn_nx_types[i].extended ? "X" : "");
112938fd1498Szrj sprintf (csuffix, "F%d%s", floatn_nx_types[i].n,
113038fd1498Szrj floatn_nx_types[i].extended ? "x" : "");
113138fd1498Szrj builtin_define_float_constants (prefix, ggc_strdup (csuffix), "%s",
113238fd1498Szrj csuffix, FLOATN_NX_TYPE_NODE (i));
113338fd1498Szrj }
113438fd1498Szrj
113538fd1498Szrj /* For decfloat.h. */
113638fd1498Szrj builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
113738fd1498Szrj builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
113838fd1498Szrj builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
113938fd1498Szrj
114038fd1498Szrj /* For fixed-point fibt, ibit, max, min, and epsilon. */
114138fd1498Szrj if (targetm.fixed_point_supported_p ())
114238fd1498Szrj {
114338fd1498Szrj builtin_define_fixed_point_constants ("SFRACT", "HR",
114438fd1498Szrj short_fract_type_node);
114538fd1498Szrj builtin_define_fixed_point_constants ("USFRACT", "UHR",
114638fd1498Szrj unsigned_short_fract_type_node);
114738fd1498Szrj builtin_define_fixed_point_constants ("FRACT", "R",
114838fd1498Szrj fract_type_node);
114938fd1498Szrj builtin_define_fixed_point_constants ("UFRACT", "UR",
115038fd1498Szrj unsigned_fract_type_node);
115138fd1498Szrj builtin_define_fixed_point_constants ("LFRACT", "LR",
115238fd1498Szrj long_fract_type_node);
115338fd1498Szrj builtin_define_fixed_point_constants ("ULFRACT", "ULR",
115438fd1498Szrj unsigned_long_fract_type_node);
115538fd1498Szrj builtin_define_fixed_point_constants ("LLFRACT", "LLR",
115638fd1498Szrj long_long_fract_type_node);
115738fd1498Szrj builtin_define_fixed_point_constants ("ULLFRACT", "ULLR",
115838fd1498Szrj unsigned_long_long_fract_type_node);
115938fd1498Szrj builtin_define_fixed_point_constants ("SACCUM", "HK",
116038fd1498Szrj short_accum_type_node);
116138fd1498Szrj builtin_define_fixed_point_constants ("USACCUM", "UHK",
116238fd1498Szrj unsigned_short_accum_type_node);
116338fd1498Szrj builtin_define_fixed_point_constants ("ACCUM", "K",
116438fd1498Szrj accum_type_node);
116538fd1498Szrj builtin_define_fixed_point_constants ("UACCUM", "UK",
116638fd1498Szrj unsigned_accum_type_node);
116738fd1498Szrj builtin_define_fixed_point_constants ("LACCUM", "LK",
116838fd1498Szrj long_accum_type_node);
116938fd1498Szrj builtin_define_fixed_point_constants ("ULACCUM", "ULK",
117038fd1498Szrj unsigned_long_accum_type_node);
117138fd1498Szrj builtin_define_fixed_point_constants ("LLACCUM", "LLK",
117238fd1498Szrj long_long_accum_type_node);
117338fd1498Szrj builtin_define_fixed_point_constants ("ULLACCUM", "ULLK",
117438fd1498Szrj unsigned_long_long_accum_type_node);
117538fd1498Szrj
117638fd1498Szrj builtin_define_fixed_point_constants ("QQ", "", qq_type_node);
117738fd1498Szrj builtin_define_fixed_point_constants ("HQ", "", hq_type_node);
117838fd1498Szrj builtin_define_fixed_point_constants ("SQ", "", sq_type_node);
117938fd1498Szrj builtin_define_fixed_point_constants ("DQ", "", dq_type_node);
118038fd1498Szrj builtin_define_fixed_point_constants ("TQ", "", tq_type_node);
118138fd1498Szrj builtin_define_fixed_point_constants ("UQQ", "", uqq_type_node);
118238fd1498Szrj builtin_define_fixed_point_constants ("UHQ", "", uhq_type_node);
118338fd1498Szrj builtin_define_fixed_point_constants ("USQ", "", usq_type_node);
118438fd1498Szrj builtin_define_fixed_point_constants ("UDQ", "", udq_type_node);
118538fd1498Szrj builtin_define_fixed_point_constants ("UTQ", "", utq_type_node);
118638fd1498Szrj builtin_define_fixed_point_constants ("HA", "", ha_type_node);
118738fd1498Szrj builtin_define_fixed_point_constants ("SA", "", sa_type_node);
118838fd1498Szrj builtin_define_fixed_point_constants ("DA", "", da_type_node);
118938fd1498Szrj builtin_define_fixed_point_constants ("TA", "", ta_type_node);
119038fd1498Szrj builtin_define_fixed_point_constants ("UHA", "", uha_type_node);
119138fd1498Szrj builtin_define_fixed_point_constants ("USA", "", usa_type_node);
119238fd1498Szrj builtin_define_fixed_point_constants ("UDA", "", uda_type_node);
119338fd1498Szrj builtin_define_fixed_point_constants ("UTA", "", uta_type_node);
119438fd1498Szrj }
119538fd1498Szrj
119638fd1498Szrj /* For libgcc-internal use only. */
119738fd1498Szrj if (flag_building_libgcc)
119838fd1498Szrj {
119938fd1498Szrj /* Properties of floating-point modes for libgcc2.c. */
120038fd1498Szrj opt_scalar_float_mode mode_iter;
120138fd1498Szrj FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT)
120238fd1498Szrj {
120338fd1498Szrj scalar_float_mode mode = mode_iter.require ();
120438fd1498Szrj const char *name = GET_MODE_NAME (mode);
120538fd1498Szrj char *macro_name
120638fd1498Szrj = (char *) alloca (strlen (name)
120738fd1498Szrj + sizeof ("__LIBGCC__MANT_DIG__"));
120838fd1498Szrj sprintf (macro_name, "__LIBGCC_%s_MANT_DIG__", name);
120938fd1498Szrj builtin_define_with_int_value (macro_name,
121038fd1498Szrj REAL_MODE_FORMAT (mode)->p);
121138fd1498Szrj if (!targetm.scalar_mode_supported_p (mode)
121238fd1498Szrj || !targetm.libgcc_floating_mode_supported_p (mode))
121338fd1498Szrj continue;
121438fd1498Szrj macro_name = (char *) alloca (strlen (name)
121538fd1498Szrj + sizeof ("__LIBGCC_HAS__MODE__"));
121638fd1498Szrj sprintf (macro_name, "__LIBGCC_HAS_%s_MODE__", name);
121738fd1498Szrj cpp_define (pfile, macro_name);
121838fd1498Szrj macro_name = (char *) alloca (strlen (name)
121938fd1498Szrj + sizeof ("__LIBGCC__FUNC_EXT__"));
122038fd1498Szrj sprintf (macro_name, "__LIBGCC_%s_FUNC_EXT__", name);
122138fd1498Szrj char suffix[20] = "";
122238fd1498Szrj if (mode == TYPE_MODE (double_type_node))
122338fd1498Szrj ; /* Empty suffix correct. */
122438fd1498Szrj else if (mode == TYPE_MODE (float_type_node))
122538fd1498Szrj suffix[0] = 'f';
122638fd1498Szrj else if (mode == TYPE_MODE (long_double_type_node))
122738fd1498Szrj suffix[0] = 'l';
122838fd1498Szrj else
122938fd1498Szrj {
123038fd1498Szrj bool found_suffix = false;
123138fd1498Szrj for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
123238fd1498Szrj if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
123338fd1498Szrj && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
123438fd1498Szrj {
123538fd1498Szrj sprintf (suffix, "f%d%s", floatn_nx_types[i].n,
123638fd1498Szrj floatn_nx_types[i].extended ? "x" : "");
123738fd1498Szrj found_suffix = true;
123838fd1498Szrj break;
123938fd1498Szrj }
124038fd1498Szrj gcc_assert (found_suffix);
124138fd1498Szrj }
124238fd1498Szrj builtin_define_with_value (macro_name, suffix, 0);
124338fd1498Szrj
124438fd1498Szrj /* The way __LIBGCC_*_EXCESS_PRECISION__ is used is about
124538fd1498Szrj eliminating excess precision from results assigned to
124638fd1498Szrj variables - meaning it should be about the implicit excess
124738fd1498Szrj precision only. */
124838fd1498Szrj bool excess_precision = false;
124938fd1498Szrj machine_mode float16_type_mode = (float16_type_node
125038fd1498Szrj ? TYPE_MODE (float16_type_node)
125138fd1498Szrj : VOIDmode);
125238fd1498Szrj switch (targetm.c.excess_precision
125338fd1498Szrj (EXCESS_PRECISION_TYPE_IMPLICIT))
125438fd1498Szrj {
125538fd1498Szrj case FLT_EVAL_METHOD_UNPREDICTABLE:
125638fd1498Szrj case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
125738fd1498Szrj excess_precision = (mode == float16_type_mode
125838fd1498Szrj || mode == TYPE_MODE (float_type_node)
125938fd1498Szrj || mode == TYPE_MODE (double_type_node));
126038fd1498Szrj break;
126138fd1498Szrj
126238fd1498Szrj case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
126338fd1498Szrj excess_precision = (mode == float16_type_mode
126438fd1498Szrj || mode == TYPE_MODE (float_type_node));
126538fd1498Szrj break;
126638fd1498Szrj case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
126738fd1498Szrj excess_precision = mode == float16_type_mode;
126838fd1498Szrj break;
126938fd1498Szrj case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16:
127038fd1498Szrj excess_precision = false;
127138fd1498Szrj break;
127238fd1498Szrj default:
127338fd1498Szrj gcc_unreachable ();
127438fd1498Szrj }
127538fd1498Szrj macro_name = (char *) alloca (strlen (name)
127638fd1498Szrj + sizeof ("__LIBGCC__EXCESS_"
127738fd1498Szrj "PRECISION__"));
127838fd1498Szrj sprintf (macro_name, "__LIBGCC_%s_EXCESS_PRECISION__", name);
127938fd1498Szrj builtin_define_with_int_value (macro_name, excess_precision);
128038fd1498Szrj }
128138fd1498Szrj
128238fd1498Szrj /* For libgcc crtstuff.c and libgcc2.c. */
128338fd1498Szrj builtin_define_with_int_value ("__LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__",
128438fd1498Szrj EH_TABLES_CAN_BE_READ_ONLY);
128538fd1498Szrj #ifdef EH_FRAME_SECTION_NAME
128638fd1498Szrj builtin_define_with_value ("__LIBGCC_EH_FRAME_SECTION_NAME__",
128738fd1498Szrj EH_FRAME_SECTION_NAME, 1);
128838fd1498Szrj #endif
128938fd1498Szrj #ifdef CTORS_SECTION_ASM_OP
129038fd1498Szrj builtin_define_with_value ("__LIBGCC_CTORS_SECTION_ASM_OP__",
129138fd1498Szrj CTORS_SECTION_ASM_OP, 1);
129238fd1498Szrj #endif
129338fd1498Szrj #ifdef DTORS_SECTION_ASM_OP
129438fd1498Szrj builtin_define_with_value ("__LIBGCC_DTORS_SECTION_ASM_OP__",
129538fd1498Szrj DTORS_SECTION_ASM_OP, 1);
129638fd1498Szrj #endif
129738fd1498Szrj #ifdef TEXT_SECTION_ASM_OP
129838fd1498Szrj builtin_define_with_value ("__LIBGCC_TEXT_SECTION_ASM_OP__",
129938fd1498Szrj TEXT_SECTION_ASM_OP, 1);
130038fd1498Szrj #endif
130138fd1498Szrj #ifdef INIT_SECTION_ASM_OP
130238fd1498Szrj builtin_define_with_value ("__LIBGCC_INIT_SECTION_ASM_OP__",
130338fd1498Szrj INIT_SECTION_ASM_OP, 1);
130438fd1498Szrj #endif
130538fd1498Szrj #ifdef INIT_ARRAY_SECTION_ASM_OP
130638fd1498Szrj /* Despite the name of this target macro, the expansion is not
130738fd1498Szrj actually used, and may be empty rather than a string
130838fd1498Szrj constant. */
130938fd1498Szrj cpp_define (pfile, "__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__");
131038fd1498Szrj #endif
131138fd1498Szrj
131238fd1498Szrj /* For libgcc enable-execute-stack.c. */
131338fd1498Szrj builtin_define_with_int_value ("__LIBGCC_TRAMPOLINE_SIZE__",
131438fd1498Szrj TRAMPOLINE_SIZE);
131538fd1498Szrj
131638fd1498Szrj /* For libgcc generic-morestack.c and unwinder code. */
131738fd1498Szrj if (STACK_GROWS_DOWNWARD)
131838fd1498Szrj cpp_define (pfile, "__LIBGCC_STACK_GROWS_DOWNWARD__");
131938fd1498Szrj
132038fd1498Szrj /* For libgcc unwinder code. */
132138fd1498Szrj #ifdef DONT_USE_BUILTIN_SETJMP
132238fd1498Szrj cpp_define (pfile, "__LIBGCC_DONT_USE_BUILTIN_SETJMP__");
132338fd1498Szrj #endif
132438fd1498Szrj #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
132538fd1498Szrj builtin_define_with_int_value ("__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__",
132638fd1498Szrj DWARF_ALT_FRAME_RETURN_COLUMN);
132738fd1498Szrj #endif
132838fd1498Szrj builtin_define_with_int_value ("__LIBGCC_DWARF_FRAME_REGISTERS__",
132938fd1498Szrj DWARF_FRAME_REGISTERS);
133038fd1498Szrj #ifdef EH_RETURN_STACKADJ_RTX
133138fd1498Szrj cpp_define (pfile, "__LIBGCC_EH_RETURN_STACKADJ_RTX__");
133238fd1498Szrj #endif
133338fd1498Szrj #ifdef JMP_BUF_SIZE
133438fd1498Szrj builtin_define_with_int_value ("__LIBGCC_JMP_BUF_SIZE__",
133538fd1498Szrj JMP_BUF_SIZE);
133638fd1498Szrj #endif
133738fd1498Szrj builtin_define_with_int_value ("__LIBGCC_STACK_POINTER_REGNUM__",
133838fd1498Szrj STACK_POINTER_REGNUM);
133938fd1498Szrj
134038fd1498Szrj /* For libgcov. */
134138fd1498Szrj builtin_define_with_int_value ("__LIBGCC_VTABLE_USES_DESCRIPTORS__",
134238fd1498Szrj TARGET_VTABLE_USES_DESCRIPTORS);
134338fd1498Szrj }
134438fd1498Szrj
134538fd1498Szrj /* For use in assembly language. */
134638fd1498Szrj builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
134738fd1498Szrj builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
134838fd1498Szrj
134938fd1498Szrj /* Misc. */
135038fd1498Szrj if (flag_gnu89_inline)
135138fd1498Szrj cpp_define (pfile, "__GNUC_GNU_INLINE__");
135238fd1498Szrj else
135338fd1498Szrj cpp_define (pfile, "__GNUC_STDC_INLINE__");
135438fd1498Szrj
135538fd1498Szrj if (flag_no_inline)
135638fd1498Szrj cpp_define (pfile, "__NO_INLINE__");
135738fd1498Szrj
135838fd1498Szrj if (flag_iso)
135938fd1498Szrj cpp_define (pfile, "__STRICT_ANSI__");
136038fd1498Szrj
136138fd1498Szrj if (!flag_signed_char)
136238fd1498Szrj cpp_define (pfile, "__CHAR_UNSIGNED__");
136338fd1498Szrj
136438fd1498Szrj if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
136538fd1498Szrj cpp_define (pfile, "__WCHAR_UNSIGNED__");
136638fd1498Szrj
136738fd1498Szrj cpp_atomic_builtins (pfile);
136838fd1498Szrj
136938fd1498Szrj #ifdef DWARF2_UNWIND_INFO
137038fd1498Szrj if (dwarf2out_do_cfi_asm ())
137138fd1498Szrj cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
137238fd1498Szrj #endif
137338fd1498Szrj
137438fd1498Szrj /* Make the choice of ObjC runtime visible to source code. */
137538fd1498Szrj if (c_dialect_objc () && flag_next_runtime)
137638fd1498Szrj cpp_define (pfile, "__NEXT_RUNTIME__");
137738fd1498Szrj
137838fd1498Szrj /* Show the availability of some target pragmas. */
137938fd1498Szrj cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
138038fd1498Szrj
138138fd1498Szrj /* Make the choice of the stack protector runtime visible to source code.
138238fd1498Szrj The macro names and values here were chosen for compatibility with an
138338fd1498Szrj earlier implementation, i.e. ProPolice. */
138438fd1498Szrj if (flag_stack_protect == 4)
138538fd1498Szrj cpp_define (pfile, "__SSP_EXPLICIT__=4");
138638fd1498Szrj if (flag_stack_protect == 3)
138738fd1498Szrj cpp_define (pfile, "__SSP_STRONG__=3");
138838fd1498Szrj if (flag_stack_protect == 2)
138938fd1498Szrj cpp_define (pfile, "__SSP_ALL__=2");
139038fd1498Szrj else if (flag_stack_protect == 1)
139138fd1498Szrj cpp_define (pfile, "__SSP__=1");
139238fd1498Szrj
139338fd1498Szrj if (flag_openacc)
139438fd1498Szrj cpp_define (pfile, "_OPENACC=201306");
139538fd1498Szrj
139638fd1498Szrj if (flag_openmp)
139738fd1498Szrj cpp_define (pfile, "_OPENMP=201511");
139838fd1498Szrj
139938fd1498Szrj for (i = 0; i < NUM_INT_N_ENTS; i ++)
140038fd1498Szrj if (int_n_enabled_p[i])
140138fd1498Szrj {
140238fd1498Szrj char buf[15+20];
140338fd1498Szrj sprintf(buf, "__SIZEOF_INT%d__", int_n_data[i].bitsize);
140438fd1498Szrj builtin_define_type_sizeof (buf,
140538fd1498Szrj int_n_trees[i].signed_type);
140638fd1498Szrj }
140738fd1498Szrj builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
140838fd1498Szrj builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
140938fd1498Szrj builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
141038fd1498Szrj unsigned_ptrdiff_type_node);
141138fd1498Szrj
141238fd1498Szrj /* A straightforward target hook doesn't work, because of problems
141338fd1498Szrj linking that hook's body when part of non-C front ends. */
141438fd1498Szrj # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
141538fd1498Szrj # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
141638fd1498Szrj # define builtin_define(TXT) cpp_define (pfile, TXT)
141738fd1498Szrj # define builtin_assert(TXT) cpp_assert (pfile, TXT)
141838fd1498Szrj TARGET_CPU_CPP_BUILTINS ();
141938fd1498Szrj TARGET_OS_CPP_BUILTINS ();
142038fd1498Szrj TARGET_OBJFMT_CPP_BUILTINS ();
142138fd1498Szrj
142238fd1498Szrj /* Support the __declspec keyword by turning them into attributes.
142338fd1498Szrj Note that the current way we do this may result in a collision
142438fd1498Szrj with predefined attributes later on. This can be solved by using
142538fd1498Szrj one attribute, say __declspec__, and passing args to it. The
142638fd1498Szrj problem with that approach is that args are not accumulated: each
142738fd1498Szrj new appearance would clobber any existing args. */
142838fd1498Szrj if (TARGET_DECLSPEC)
142938fd1498Szrj builtin_define ("__declspec(x)=__attribute__((x))");
143038fd1498Szrj
143138fd1498Szrj /* If decimal floating point is supported, tell the user if the
143238fd1498Szrj alternate format (BID) is used instead of the standard (DPD)
143338fd1498Szrj format. */
143438fd1498Szrj if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
143538fd1498Szrj cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
143638fd1498Szrj }
143738fd1498Szrj
143838fd1498Szrj /* Pass an object-like macro. If it doesn't lie in the user's
143938fd1498Szrj namespace, defines it unconditionally. Otherwise define a version
144038fd1498Szrj with two leading underscores, and another version with two leading
144138fd1498Szrj and trailing underscores, and define the original only if an ISO
144238fd1498Szrj standard was not nominated.
144338fd1498Szrj
144438fd1498Szrj e.g. passing "unix" defines "__unix", "__unix__" and possibly
144538fd1498Szrj "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
144638fd1498Szrj "_mips". */
144738fd1498Szrj void
builtin_define_std(const char * macro)144838fd1498Szrj builtin_define_std (const char *macro)
144938fd1498Szrj {
145038fd1498Szrj size_t len = strlen (macro);
145138fd1498Szrj char *buff = (char *) alloca (len + 5);
145238fd1498Szrj char *p = buff + 2;
145338fd1498Szrj char *q = p + len;
145438fd1498Szrj
145538fd1498Szrj /* prepend __ (or maybe just _) if in user's namespace. */
145638fd1498Szrj memcpy (p, macro, len + 1);
145738fd1498Szrj if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
145838fd1498Szrj {
145938fd1498Szrj if (*p != '_')
146038fd1498Szrj *--p = '_';
146138fd1498Szrj if (p[1] != '_')
146238fd1498Szrj *--p = '_';
146338fd1498Szrj }
146438fd1498Szrj cpp_define (parse_in, p);
146538fd1498Szrj
146638fd1498Szrj /* If it was in user's namespace... */
146738fd1498Szrj if (p != buff + 2)
146838fd1498Szrj {
146938fd1498Szrj /* Define the macro with leading and following __. */
147038fd1498Szrj if (q[-1] != '_')
147138fd1498Szrj *q++ = '_';
147238fd1498Szrj if (q[-2] != '_')
147338fd1498Szrj *q++ = '_';
147438fd1498Szrj *q = '\0';
147538fd1498Szrj cpp_define (parse_in, p);
147638fd1498Szrj
147738fd1498Szrj /* Finally, define the original macro if permitted. */
147838fd1498Szrj if (!flag_iso)
147938fd1498Szrj cpp_define (parse_in, macro);
148038fd1498Szrj }
148138fd1498Szrj }
148238fd1498Szrj
148338fd1498Szrj /* Pass an object-like macro and a value to define it to. The third
148438fd1498Szrj parameter says whether or not to turn the value into a string
148538fd1498Szrj constant. */
148638fd1498Szrj void
builtin_define_with_value(const char * macro,const char * expansion,int is_str)148738fd1498Szrj builtin_define_with_value (const char *macro, const char *expansion, int is_str)
148838fd1498Szrj {
148938fd1498Szrj char *buf;
149038fd1498Szrj size_t mlen = strlen (macro);
149138fd1498Szrj size_t elen = strlen (expansion);
149238fd1498Szrj size_t extra = 2; /* space for an = and a NUL */
149338fd1498Szrj
149438fd1498Szrj if (is_str)
149538fd1498Szrj {
149638fd1498Szrj char *quoted_expansion = (char *) alloca (elen * 4 + 1);
149738fd1498Szrj const char *p;
149838fd1498Szrj char *q;
149938fd1498Szrj extra += 2; /* space for two quote marks */
150038fd1498Szrj for (p = expansion, q = quoted_expansion; *p; p++)
150138fd1498Szrj {
150238fd1498Szrj switch (*p)
150338fd1498Szrj {
150438fd1498Szrj case '\n':
150538fd1498Szrj *q++ = '\\';
150638fd1498Szrj *q++ = 'n';
150738fd1498Szrj break;
150838fd1498Szrj
150938fd1498Szrj case '\t':
151038fd1498Szrj *q++ = '\\';
151138fd1498Szrj *q++ = 't';
151238fd1498Szrj break;
151338fd1498Szrj
151438fd1498Szrj case '\\':
151538fd1498Szrj *q++ = '\\';
151638fd1498Szrj *q++ = '\\';
151738fd1498Szrj break;
151838fd1498Szrj
151938fd1498Szrj case '"':
152038fd1498Szrj *q++ = '\\';
152138fd1498Szrj *q++ = '"';
152238fd1498Szrj break;
152338fd1498Szrj
152438fd1498Szrj default:
152538fd1498Szrj if (ISPRINT ((unsigned char) *p))
152638fd1498Szrj *q++ = *p;
152738fd1498Szrj else
152838fd1498Szrj {
152938fd1498Szrj sprintf (q, "\\%03o", (unsigned char) *p);
153038fd1498Szrj q += 4;
153138fd1498Szrj }
153238fd1498Szrj }
153338fd1498Szrj }
153438fd1498Szrj *q = '\0';
153538fd1498Szrj expansion = quoted_expansion;
153638fd1498Szrj elen = q - expansion;
153738fd1498Szrj }
153838fd1498Szrj
153938fd1498Szrj buf = (char *) alloca (mlen + elen + extra);
154038fd1498Szrj if (is_str)
154138fd1498Szrj sprintf (buf, "%s=\"%s\"", macro, expansion);
154238fd1498Szrj else
154338fd1498Szrj sprintf (buf, "%s=%s", macro, expansion);
154438fd1498Szrj
154538fd1498Szrj cpp_define (parse_in, buf);
154638fd1498Szrj }
154738fd1498Szrj
154838fd1498Szrj
154938fd1498Szrj /* Pass an object-like macro and an integer value to define it to. */
155038fd1498Szrj void
builtin_define_with_int_value(const char * macro,HOST_WIDE_INT value)155138fd1498Szrj builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
155238fd1498Szrj {
155338fd1498Szrj char *buf;
155438fd1498Szrj size_t mlen = strlen (macro);
155538fd1498Szrj size_t vlen = 18;
155638fd1498Szrj size_t extra = 2; /* space for = and NUL. */
155738fd1498Szrj
155838fd1498Szrj buf = (char *) alloca (mlen + vlen + extra);
155938fd1498Szrj memcpy (buf, macro, mlen);
156038fd1498Szrj buf[mlen] = '=';
156138fd1498Szrj sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
156238fd1498Szrj
156338fd1498Szrj cpp_define (parse_in, buf);
156438fd1498Szrj }
156538fd1498Szrj
156638fd1498Szrj /* builtin_define_with_hex_fp_value is very expensive, so the following
156738fd1498Szrj array and function allows it to be done lazily when __DBL_MAX__
156838fd1498Szrj etc. is first used. */
156938fd1498Szrj
157038fd1498Szrj struct GTY(()) lazy_hex_fp_value_struct
157138fd1498Szrj {
157238fd1498Szrj const char *hex_str;
157338fd1498Szrj cpp_macro *macro;
157438fd1498Szrj machine_mode mode;
157538fd1498Szrj int digits;
157638fd1498Szrj const char *fp_suffix;
157738fd1498Szrj };
157838fd1498Szrj /* Number of the expensive to compute macros we should evaluate lazily.
157938fd1498Szrj Each builtin_define_float_constants invocation calls
158038fd1498Szrj builtin_define_with_hex_fp_value 4 times and builtin_define_float_constants
158138fd1498Szrj is called for FLT, DBL, LDBL and up to NUM_FLOATN_NX_TYPES times for
158238fd1498Szrj FLTNN*. */
158338fd1498Szrj #define LAZY_HEX_FP_VALUES_CNT (4 * (3 + NUM_FLOATN_NX_TYPES))
158438fd1498Szrj static GTY(()) struct lazy_hex_fp_value_struct
158538fd1498Szrj lazy_hex_fp_values[LAZY_HEX_FP_VALUES_CNT];
158638fd1498Szrj static GTY(()) int lazy_hex_fp_value_count;
158738fd1498Szrj
158838fd1498Szrj static bool
lazy_hex_fp_value(cpp_reader * pfile ATTRIBUTE_UNUSED,cpp_hashnode * node)158938fd1498Szrj lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
159038fd1498Szrj cpp_hashnode *node)
159138fd1498Szrj {
159238fd1498Szrj REAL_VALUE_TYPE real;
159338fd1498Szrj char dec_str[64], buf1[256];
159438fd1498Szrj unsigned int idx;
159538fd1498Szrj if (node->value.builtin < BT_FIRST_USER
159638fd1498Szrj || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
159738fd1498Szrj return false;
159838fd1498Szrj
159938fd1498Szrj idx = node->value.builtin - BT_FIRST_USER;
160038fd1498Szrj real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
160138fd1498Szrj real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
160238fd1498Szrj lazy_hex_fp_values[idx].digits, 0,
160338fd1498Szrj lazy_hex_fp_values[idx].mode);
160438fd1498Szrj
160538fd1498Szrj sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
160638fd1498Szrj node->flags &= ~(NODE_BUILTIN | NODE_USED);
160738fd1498Szrj node->value.macro = lazy_hex_fp_values[idx].macro;
160838fd1498Szrj for (idx = 0; idx < node->value.macro->count; idx++)
160938fd1498Szrj if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
161038fd1498Szrj break;
161138fd1498Szrj gcc_assert (idx < node->value.macro->count);
161238fd1498Szrj node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
161338fd1498Szrj node->value.macro->exp.tokens[idx].val.str.text
161438fd1498Szrj = (const unsigned char *) ggc_strdup (buf1);
161538fd1498Szrj return true;
161638fd1498Szrj }
161738fd1498Szrj
161838fd1498Szrj /* Pass an object-like macro a hexadecimal floating-point value. */
161938fd1498Szrj static void
builtin_define_with_hex_fp_value(const char * macro,tree type,int digits,const char * hex_str,const char * fp_suffix,const char * fp_cast)162038fd1498Szrj builtin_define_with_hex_fp_value (const char *macro,
162138fd1498Szrj tree type, int digits,
162238fd1498Szrj const char *hex_str,
162338fd1498Szrj const char *fp_suffix,
162438fd1498Szrj const char *fp_cast)
162538fd1498Szrj {
162638fd1498Szrj REAL_VALUE_TYPE real;
162738fd1498Szrj char dec_str[64], buf[256], buf1[128], buf2[64];
162838fd1498Szrj
162938fd1498Szrj /* This is very expensive, so if possible expand them lazily. */
163038fd1498Szrj if (lazy_hex_fp_value_count < LAZY_HEX_FP_VALUES_CNT
163138fd1498Szrj && flag_dump_macros == 0
163238fd1498Szrj && !cpp_get_options (parse_in)->traditional)
163338fd1498Szrj {
163438fd1498Szrj struct cpp_hashnode *node;
163538fd1498Szrj if (lazy_hex_fp_value_count == 0)
163638fd1498Szrj cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
163738fd1498Szrj sprintf (buf2, fp_cast, "1.1");
163838fd1498Szrj sprintf (buf1, "%s=%s", macro, buf2);
163938fd1498Szrj cpp_define (parse_in, buf1);
164038fd1498Szrj node = C_CPP_HASHNODE (get_identifier (macro));
164138fd1498Szrj lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
164238fd1498Szrj = ggc_strdup (hex_str);
164338fd1498Szrj lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
164438fd1498Szrj lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
164538fd1498Szrj lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
164638fd1498Szrj lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
164738fd1498Szrj node->flags |= NODE_BUILTIN;
164838fd1498Szrj node->value.builtin
164938fd1498Szrj = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
165038fd1498Szrj lazy_hex_fp_value_count++;
165138fd1498Szrj return;
165238fd1498Szrj }
165338fd1498Szrj
165438fd1498Szrj /* Hex values are really cool and convenient, except that they're
165538fd1498Szrj not supported in strict ISO C90 mode. First, the "p-" sequence
165638fd1498Szrj is not valid as part of a preprocessor number. Second, we get a
165738fd1498Szrj pedwarn from the preprocessor, which has no context, so we can't
165838fd1498Szrj suppress the warning with __extension__.
165938fd1498Szrj
166038fd1498Szrj So instead what we do is construct the number in hex (because
166138fd1498Szrj it's easy to get the exact correct value), parse it as a real,
166238fd1498Szrj then print it back out as decimal. */
166338fd1498Szrj
166438fd1498Szrj real_from_string (&real, hex_str);
166538fd1498Szrj real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
166638fd1498Szrj TYPE_MODE (type));
166738fd1498Szrj
166838fd1498Szrj /* Assemble the macro in the following fashion
166938fd1498Szrj macro = fp_cast [dec_str fp_suffix] */
167038fd1498Szrj sprintf (buf2, "%s%s", dec_str, fp_suffix);
167138fd1498Szrj sprintf (buf1, fp_cast, buf2);
167238fd1498Szrj sprintf (buf, "%s=%s", macro, buf1);
167338fd1498Szrj
167438fd1498Szrj cpp_define (parse_in, buf);
167538fd1498Szrj }
167638fd1498Szrj
167738fd1498Szrj /* Return a string constant for the suffix for a value of type TYPE
167838fd1498Szrj promoted according to the integer promotions. The type must be one
167938fd1498Szrj of the standard integer type nodes. */
168038fd1498Szrj
168138fd1498Szrj static const char *
type_suffix(tree type)168238fd1498Szrj type_suffix (tree type)
168338fd1498Szrj {
168438fd1498Szrj static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
168538fd1498Szrj int unsigned_suffix;
168638fd1498Szrj int is_long;
168738fd1498Szrj int tp = TYPE_PRECISION (type);
168838fd1498Szrj
168938fd1498Szrj if (type == long_long_integer_type_node
169038fd1498Szrj || type == long_long_unsigned_type_node
169138fd1498Szrj || tp > TYPE_PRECISION (long_integer_type_node))
169238fd1498Szrj is_long = 2;
169338fd1498Szrj else if (type == long_integer_type_node
169438fd1498Szrj || type == long_unsigned_type_node
169538fd1498Szrj || tp > TYPE_PRECISION (integer_type_node))
169638fd1498Szrj is_long = 1;
169738fd1498Szrj else if (type == integer_type_node
169838fd1498Szrj || type == unsigned_type_node
169938fd1498Szrj || type == short_integer_type_node
170038fd1498Szrj || type == short_unsigned_type_node
170138fd1498Szrj || type == signed_char_type_node
170238fd1498Szrj || type == unsigned_char_type_node
170338fd1498Szrj /* ??? "char" is not a signed or unsigned integer type and
170438fd1498Szrj so is not permitted for the standard typedefs, but some
170538fd1498Szrj systems use it anyway. */
170638fd1498Szrj || type == char_type_node)
170738fd1498Szrj is_long = 0;
170838fd1498Szrj else
170938fd1498Szrj gcc_unreachable ();
171038fd1498Szrj
171138fd1498Szrj unsigned_suffix = TYPE_UNSIGNED (type);
171238fd1498Szrj if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
171338fd1498Szrj unsigned_suffix = 0;
171438fd1498Szrj return suffixes[is_long * 2 + unsigned_suffix];
171538fd1498Szrj }
171638fd1498Szrj
171738fd1498Szrj /* Define MACRO as a <stdint.h> constant-suffix macro for TYPE. */
171838fd1498Szrj static void
builtin_define_constants(const char * macro,tree type)171938fd1498Szrj builtin_define_constants (const char *macro, tree type)
172038fd1498Szrj {
172138fd1498Szrj const char *suffix;
172238fd1498Szrj char *buf;
172338fd1498Szrj
172438fd1498Szrj suffix = type_suffix (type);
172538fd1498Szrj
172638fd1498Szrj if (suffix[0] == 0)
172738fd1498Szrj {
172838fd1498Szrj buf = (char *) alloca (strlen (macro) + 6);
172938fd1498Szrj sprintf (buf, "%s(c)=c", macro);
173038fd1498Szrj }
173138fd1498Szrj else
173238fd1498Szrj {
173338fd1498Szrj buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1);
173438fd1498Szrj sprintf (buf, "%s(c)=c ## %s", macro, suffix);
173538fd1498Szrj }
173638fd1498Szrj
173738fd1498Szrj cpp_define (parse_in, buf);
173838fd1498Szrj }
173938fd1498Szrj
174038fd1498Szrj /* Define MAX for TYPE based on the precision of the type. */
174138fd1498Szrj
174238fd1498Szrj static void
builtin_define_type_max(const char * macro,tree type)174338fd1498Szrj builtin_define_type_max (const char *macro, tree type)
174438fd1498Szrj {
174538fd1498Szrj builtin_define_type_minmax (NULL, macro, type);
174638fd1498Szrj }
174738fd1498Szrj
174838fd1498Szrj /* Given a value with COUNT LSBs set, fill BUF with a hexidecimal
174938fd1498Szrj representation of that value. For example, a COUNT of 10 would
175038fd1498Szrj return "0x3ff". */
175138fd1498Szrj
175238fd1498Szrj static void
print_bits_of_hex(char * buf,int bufsz,int count)175338fd1498Szrj print_bits_of_hex (char *buf, int bufsz, int count)
175438fd1498Szrj {
175538fd1498Szrj gcc_assert (bufsz > 3);
175638fd1498Szrj *buf++ = '0';
175738fd1498Szrj *buf++ = 'x';
175838fd1498Szrj bufsz -= 2;
175938fd1498Szrj
176038fd1498Szrj gcc_assert (count > 0);
176138fd1498Szrj
176238fd1498Szrj switch (count % 4) {
176338fd1498Szrj case 0:
176438fd1498Szrj break;
176538fd1498Szrj case 1:
176638fd1498Szrj *buf++ = '1';
176738fd1498Szrj bufsz --;
176838fd1498Szrj count -= 1;
176938fd1498Szrj break;
177038fd1498Szrj case 2:
177138fd1498Szrj *buf++ = '3';
177238fd1498Szrj bufsz --;
177338fd1498Szrj count -= 2;
177438fd1498Szrj break;
177538fd1498Szrj case 3:
177638fd1498Szrj *buf++ = '7';
177738fd1498Szrj bufsz --;
177838fd1498Szrj count -= 3;
177938fd1498Szrj break;
178038fd1498Szrj }
178138fd1498Szrj while (count >= 4)
178238fd1498Szrj {
178338fd1498Szrj gcc_assert (bufsz > 1);
178438fd1498Szrj *buf++ = 'f';
178538fd1498Szrj bufsz --;
178638fd1498Szrj count -= 4;
178738fd1498Szrj }
178838fd1498Szrj gcc_assert (bufsz > 0);
178938fd1498Szrj *buf++ = 0;
179038fd1498Szrj }
179138fd1498Szrj
179238fd1498Szrj /* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
179338fd1498Szrj precision of the type. */
179438fd1498Szrj
179538fd1498Szrj static void
builtin_define_type_minmax(const char * min_macro,const char * max_macro,tree type)179638fd1498Szrj builtin_define_type_minmax (const char *min_macro, const char *max_macro,
179738fd1498Szrj tree type)
179838fd1498Szrj {
179938fd1498Szrj #define PBOH_SZ (MAX_BITSIZE_MODE_ANY_INT/4+4)
180038fd1498Szrj char value[PBOH_SZ];
180138fd1498Szrj
180238fd1498Szrj const char *suffix;
180338fd1498Szrj char *buf;
180438fd1498Szrj int bits;
180538fd1498Szrj
180638fd1498Szrj bits = TYPE_PRECISION (type) + (TYPE_UNSIGNED (type) ? 0 : -1);
180738fd1498Szrj
180838fd1498Szrj print_bits_of_hex (value, PBOH_SZ, bits);
180938fd1498Szrj
181038fd1498Szrj suffix = type_suffix (type);
181138fd1498Szrj
181238fd1498Szrj buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)
181338fd1498Szrj + strlen (suffix) + 1);
181438fd1498Szrj sprintf (buf, "%s=%s%s", max_macro, value, suffix);
181538fd1498Szrj
181638fd1498Szrj cpp_define (parse_in, buf);
181738fd1498Szrj
181838fd1498Szrj if (min_macro)
181938fd1498Szrj {
182038fd1498Szrj if (TYPE_UNSIGNED (type))
182138fd1498Szrj {
182238fd1498Szrj buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1);
182338fd1498Szrj sprintf (buf, "%s=0%s", min_macro, suffix);
182438fd1498Szrj }
182538fd1498Szrj else
182638fd1498Szrj {
182738fd1498Szrj buf = (char *) alloca (strlen (min_macro) + 3
182838fd1498Szrj + strlen (max_macro) + 6);
182938fd1498Szrj sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro);
183038fd1498Szrj }
183138fd1498Szrj cpp_define (parse_in, buf);
183238fd1498Szrj }
183338fd1498Szrj }
183438fd1498Szrj
183538fd1498Szrj /* Define WIDTH_MACRO for the width of TYPE. If TYPE2 is not NULL,
183638fd1498Szrj both types must have the same width. */
183738fd1498Szrj
183838fd1498Szrj static void
builtin_define_type_width(const char * width_macro,tree type,tree type2)183938fd1498Szrj builtin_define_type_width (const char *width_macro, tree type, tree type2)
184038fd1498Szrj {
184138fd1498Szrj if (type2 != NULL_TREE)
184238fd1498Szrj gcc_assert (TYPE_PRECISION (type) == TYPE_PRECISION (type2));
184338fd1498Szrj builtin_define_with_int_value (width_macro, TYPE_PRECISION (type));
184438fd1498Szrj }
184538fd1498Szrj
184638fd1498Szrj #include "gt-c-family-c-cppbuiltin.h"
1847