Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-family/c-cppbuiltin.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Define builtin-in macros for the C family front ends. | 1 /* Define builtin-in macros for the C family front ends. |
2 Copyright (C) 2002-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2002-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
29 #include "flags.h" | 29 #include "flags.h" |
30 #include "c-pragma.h" | 30 #include "c-pragma.h" |
31 #include "output.h" /* For user_label_prefix. */ | 31 #include "output.h" /* For user_label_prefix. */ |
32 #include "debug.h" /* For dwarf2out_do_cfi_asm. */ | 32 #include "debug.h" /* For dwarf2out_do_cfi_asm. */ |
33 #include "common/common-target.h" | 33 #include "common/common-target.h" |
34 #include "cpp-id-data.h" | |
35 #include "cppbuiltin.h" | 34 #include "cppbuiltin.h" |
36 | 35 |
37 #ifndef TARGET_OS_CPP_BUILTINS | 36 #ifndef TARGET_OS_CPP_BUILTINS |
38 # define TARGET_OS_CPP_BUILTINS() | 37 # define TARGET_OS_CPP_BUILTINS() |
39 #endif | 38 #endif |
78 #endif | 77 #endif |
79 | 78 |
80 #ifdef HAVE_fmadf4 | 79 #ifdef HAVE_fmadf4 |
81 case E_DFmode: | 80 case E_DFmode: |
82 return !!HAVE_fmadf4; | 81 return !!HAVE_fmadf4; |
82 #endif | |
83 | |
84 #ifdef HAVE_fmakf4 /* PowerPC if long double != __float128. */ | |
85 case E_KFmode: | |
86 return !!HAVE_fmakf4; | |
83 #endif | 87 #endif |
84 | 88 |
85 #ifdef HAVE_fmaxf4 | 89 #ifdef HAVE_fmaxf4 |
86 case E_XFmode: | 90 case E_XFmode: |
87 return !!HAVE_fmaxf4; | 91 return !!HAVE_fmaxf4; |
963 cpp_define (pfile, "__cpp_constexpr=201603"); | 967 cpp_define (pfile, "__cpp_constexpr=201603"); |
964 cpp_define (pfile, "__cpp_if_constexpr=201606"); | 968 cpp_define (pfile, "__cpp_if_constexpr=201606"); |
965 cpp_define (pfile, "__cpp_capture_star_this=201603"); | 969 cpp_define (pfile, "__cpp_capture_star_this=201603"); |
966 cpp_define (pfile, "__cpp_inline_variables=201606"); | 970 cpp_define (pfile, "__cpp_inline_variables=201606"); |
967 cpp_define (pfile, "__cpp_aggregate_bases=201603"); | 971 cpp_define (pfile, "__cpp_aggregate_bases=201603"); |
968 cpp_define (pfile, "__cpp_deduction_guides=201606"); | 972 cpp_define (pfile, "__cpp_deduction_guides=201703"); |
969 cpp_define (pfile, "__cpp_noexcept_function_type=201510"); | 973 cpp_define (pfile, "__cpp_noexcept_function_type=201510"); |
970 cpp_define (pfile, "__cpp_template_auto=201606"); | 974 cpp_define (pfile, "__cpp_template_auto=201606"); |
971 cpp_define (pfile, "__cpp_structured_bindings=201606"); | 975 cpp_define (pfile, "__cpp_structured_bindings=201606"); |
972 cpp_define (pfile, "__cpp_variadic_using=201611"); | 976 cpp_define (pfile, "__cpp_variadic_using=201611"); |
973 } | 977 } |
974 if (flag_concepts) | 978 if (flag_concepts) |
975 cpp_define (pfile, "__cpp_concepts=201507"); | 979 cpp_define (pfile, "__cpp_concepts=201507"); |
976 if (flag_tm) | 980 if (flag_tm) |
977 /* Use a value smaller than the 201505 specified in | 981 /* Use a value smaller than the 201505 specified in |
978 the TS, since we don't yet support atomic_cancel. */ | 982 the TS, since we don't yet support atomic_cancel. */ |
979 cpp_define (pfile, "__cpp_transactional_memory=210500"); | 983 cpp_define (pfile, "__cpp_transactional_memory=201500"); |
980 if (flag_sized_deallocation) | 984 if (flag_sized_deallocation) |
981 cpp_define (pfile, "__cpp_sized_deallocation=201309"); | 985 cpp_define (pfile, "__cpp_sized_deallocation=201309"); |
982 if (aligned_new_threshold) | 986 if (aligned_new_threshold) |
983 { | 987 { |
984 cpp_define (pfile, "__cpp_aligned_new=201606"); | 988 cpp_define (pfile, "__cpp_aligned_new=201606"); |
1117 char prefix[20], csuffix[20]; | 1121 char prefix[20], csuffix[20]; |
1118 sprintf (prefix, "FLT%d%s", floatn_nx_types[i].n, | 1122 sprintf (prefix, "FLT%d%s", floatn_nx_types[i].n, |
1119 floatn_nx_types[i].extended ? "X" : ""); | 1123 floatn_nx_types[i].extended ? "X" : ""); |
1120 sprintf (csuffix, "F%d%s", floatn_nx_types[i].n, | 1124 sprintf (csuffix, "F%d%s", floatn_nx_types[i].n, |
1121 floatn_nx_types[i].extended ? "x" : ""); | 1125 floatn_nx_types[i].extended ? "x" : ""); |
1122 builtin_define_float_constants (prefix, csuffix, "%s", NULL, | 1126 builtin_define_float_constants (prefix, ggc_strdup (csuffix), "%s", |
1123 FLOATN_NX_TYPE_NODE (i)); | 1127 csuffix, FLOATN_NX_TYPE_NODE (i)); |
1124 } | 1128 } |
1125 | 1129 |
1126 /* For decfloat.h. */ | 1130 /* For decfloat.h. */ |
1127 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node); | 1131 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node); |
1128 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node); | 1132 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node); |
1354 | 1358 |
1355 if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node)) | 1359 if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node)) |
1356 cpp_define (pfile, "__WCHAR_UNSIGNED__"); | 1360 cpp_define (pfile, "__WCHAR_UNSIGNED__"); |
1357 | 1361 |
1358 cpp_atomic_builtins (pfile); | 1362 cpp_atomic_builtins (pfile); |
1359 | 1363 |
1364 /* Show support for __builtin_speculation_safe_value () if the target | |
1365 has been updated to fully support it. */ | |
1366 if (targetm.have_speculation_safe_value (false)) | |
1367 cpp_define (pfile, "__HAVE_SPECULATION_SAFE_VALUE"); | |
1368 | |
1360 #ifdef DWARF2_UNWIND_INFO | 1369 #ifdef DWARF2_UNWIND_INFO |
1361 if (dwarf2out_do_cfi_asm ()) | 1370 if (dwarf2out_do_cfi_asm ()) |
1362 cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM"); | 1371 cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM"); |
1363 #endif | 1372 #endif |
1364 | 1373 |
1559 etc. is first used. */ | 1568 etc. is first used. */ |
1560 | 1569 |
1561 struct GTY(()) lazy_hex_fp_value_struct | 1570 struct GTY(()) lazy_hex_fp_value_struct |
1562 { | 1571 { |
1563 const char *hex_str; | 1572 const char *hex_str; |
1564 cpp_macro *macro; | |
1565 machine_mode mode; | 1573 machine_mode mode; |
1566 int digits; | 1574 int digits; |
1567 const char *fp_suffix; | 1575 const char *fp_suffix; |
1568 }; | 1576 }; |
1569 static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12]; | 1577 /* Number of the expensive to compute macros we should evaluate lazily. |
1570 static GTY(()) int lazy_hex_fp_value_count; | 1578 Each builtin_define_float_constants invocation calls |
1571 | 1579 builtin_define_with_hex_fp_value 4 times and builtin_define_float_constants |
1572 static bool | 1580 is called for FLT, DBL, LDBL and up to NUM_FLOATN_NX_TYPES times for |
1573 lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED, | 1581 FLTNN*. */ |
1574 cpp_hashnode *node) | 1582 #define LAZY_HEX_FP_VALUES_CNT (4 * (3 + NUM_FLOATN_NX_TYPES)) |
1583 static GTY(()) struct lazy_hex_fp_value_struct | |
1584 lazy_hex_fp_values[LAZY_HEX_FP_VALUES_CNT]; | |
1585 static GTY(()) unsigned lazy_hex_fp_value_count; | |
1586 | |
1587 static void | |
1588 lazy_hex_fp_value (cpp_reader *, cpp_macro *macro, unsigned num) | |
1575 { | 1589 { |
1576 REAL_VALUE_TYPE real; | 1590 REAL_VALUE_TYPE real; |
1577 char dec_str[64], buf1[256]; | 1591 char dec_str[64], buf1[256]; |
1578 unsigned int idx; | 1592 |
1579 if (node->value.builtin < BT_FIRST_USER | 1593 gcc_checking_assert (num < lazy_hex_fp_value_count); |
1580 || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count) | 1594 |
1581 return false; | 1595 real_from_string (&real, lazy_hex_fp_values[num].hex_str); |
1582 | |
1583 idx = node->value.builtin - BT_FIRST_USER; | |
1584 real_from_string (&real, lazy_hex_fp_values[idx].hex_str); | |
1585 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), | 1596 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), |
1586 lazy_hex_fp_values[idx].digits, 0, | 1597 lazy_hex_fp_values[num].digits, 0, |
1587 lazy_hex_fp_values[idx].mode); | 1598 lazy_hex_fp_values[num].mode); |
1588 | 1599 |
1589 sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix); | 1600 size_t len |
1590 node->flags &= ~(NODE_BUILTIN | NODE_USED); | 1601 = sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[num].fp_suffix); |
1591 node->value.macro = lazy_hex_fp_values[idx].macro; | 1602 gcc_assert (len < sizeof (buf1)); |
1592 for (idx = 0; idx < node->value.macro->count; idx++) | 1603 for (unsigned idx = 0; idx < macro->count; idx++) |
1593 if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER) | 1604 if (macro->exp.tokens[idx].type == CPP_NUMBER) |
1594 break; | 1605 { |
1595 gcc_assert (idx < node->value.macro->count); | 1606 macro->exp.tokens[idx].val.str.len = len; |
1596 node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1); | 1607 macro->exp.tokens[idx].val.str.text |
1597 node->value.macro->exp.tokens[idx].val.str.text | 1608 = (const unsigned char *) ggc_strdup (buf1); |
1598 = (const unsigned char *) ggc_strdup (buf1); | 1609 return; |
1599 return true; | 1610 } |
1611 | |
1612 /* We must have replaced a token. */ | |
1613 gcc_unreachable (); | |
1600 } | 1614 } |
1601 | 1615 |
1602 /* Pass an object-like macro a hexadecimal floating-point value. */ | 1616 /* Pass an object-like macro a hexadecimal floating-point value. */ |
1603 static void | 1617 static void |
1604 builtin_define_with_hex_fp_value (const char *macro, | 1618 builtin_define_with_hex_fp_value (const char *macro, |
1606 const char *hex_str, | 1620 const char *hex_str, |
1607 const char *fp_suffix, | 1621 const char *fp_suffix, |
1608 const char *fp_cast) | 1622 const char *fp_cast) |
1609 { | 1623 { |
1610 REAL_VALUE_TYPE real; | 1624 REAL_VALUE_TYPE real; |
1611 char dec_str[64], buf1[256], buf2[256]; | 1625 char dec_str[64], buf[256], buf1[128], buf2[64]; |
1612 | 1626 |
1613 /* This is very expensive, so if possible expand them lazily. */ | 1627 /* This is very expensive, so if possible expand them lazily. */ |
1614 if (lazy_hex_fp_value_count < 12 | 1628 if (lazy_hex_fp_value_count < LAZY_HEX_FP_VALUES_CNT |
1615 && flag_dump_macros == 0 | 1629 && flag_dump_macros == 0 |
1616 && !cpp_get_options (parse_in)->traditional) | 1630 && !cpp_get_options (parse_in)->traditional) |
1617 { | 1631 { |
1618 struct cpp_hashnode *node; | |
1619 if (lazy_hex_fp_value_count == 0) | 1632 if (lazy_hex_fp_value_count == 0) |
1620 cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value; | 1633 cpp_get_callbacks (parse_in)->user_lazy_macro = lazy_hex_fp_value; |
1621 sprintf (buf2, fp_cast, "1.1"); | 1634 sprintf (buf2, fp_cast, "1.1"); |
1622 sprintf (buf1, "%s=%s", macro, buf2); | 1635 sprintf (buf1, "%s=%s", macro, buf2); |
1623 cpp_define (parse_in, buf1); | 1636 cpp_define (parse_in, buf1); |
1624 node = C_CPP_HASHNODE (get_identifier (macro)); | 1637 struct cpp_hashnode *node = C_CPP_HASHNODE (get_identifier (macro)); |
1625 lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str | 1638 lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str |
1626 = ggc_strdup (hex_str); | 1639 = ggc_strdup (hex_str); |
1627 lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type); | 1640 lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type); |
1628 lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits; | 1641 lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits; |
1629 lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix; | 1642 lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix; |
1630 lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro; | 1643 cpp_define_lazily (parse_in, node, lazy_hex_fp_value_count++); |
1631 node->flags |= NODE_BUILTIN; | |
1632 node->value.builtin | |
1633 = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count); | |
1634 lazy_hex_fp_value_count++; | |
1635 return; | 1644 return; |
1636 } | 1645 } |
1637 | 1646 |
1638 /* Hex values are really cool and convenient, except that they're | 1647 /* Hex values are really cool and convenient, except that they're |
1639 not supported in strict ISO C90 mode. First, the "p-" sequence | 1648 not supported in strict ISO C90 mode. First, the "p-" sequence |
1649 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0, | 1658 real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0, |
1650 TYPE_MODE (type)); | 1659 TYPE_MODE (type)); |
1651 | 1660 |
1652 /* Assemble the macro in the following fashion | 1661 /* Assemble the macro in the following fashion |
1653 macro = fp_cast [dec_str fp_suffix] */ | 1662 macro = fp_cast [dec_str fp_suffix] */ |
1654 sprintf (buf1, "%s%s", dec_str, fp_suffix); | 1663 sprintf (buf2, "%s%s", dec_str, fp_suffix); |
1655 sprintf (buf2, fp_cast, buf1); | 1664 sprintf (buf1, fp_cast, buf2); |
1656 sprintf (buf1, "%s=%s", macro, buf2); | 1665 sprintf (buf, "%s=%s", macro, buf1); |
1657 | 1666 |
1658 cpp_define (parse_in, buf1); | 1667 cpp_define (parse_in, buf); |
1659 } | 1668 } |
1660 | 1669 |
1661 /* Return a string constant for the suffix for a value of type TYPE | 1670 /* Return a string constant for the suffix for a value of type TYPE |
1662 promoted according to the integer promotions. The type must be one | 1671 promoted according to the integer promotions. The type must be one |
1663 of the standard integer type nodes. */ | 1672 of the standard integer type nodes. */ |