LCOV - code coverage report
Current view: top level - gcc/c-family - c-lex.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.2 % 925 742
Test Date: 2026-07-11 15:47:05 Functions: 92.3 % 26 24
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Mainly the interface between cpplib and the C front ends.
       2              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       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
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "target.h"
      24              : #include "c-common.h"
      25              : #include "timevar.h"
      26              : #include "stringpool.h"
      27              : #include "stor-layout.h"
      28              : #include "c-pragma.h"
      29              : #include "debug.h"
      30              : #include "flags.h"
      31              : #include "file-prefix-map.h" /* remap_macro_filename()  */
      32              : #include "langhooks.h"
      33              : #include "attribs.h"
      34              : #include "rich-location.h"
      35              : 
      36              : /* We may keep statistics about how long which files took to compile.  */
      37              : static int header_time, body_time;
      38              : static splay_tree file_info_tree;
      39              : 
      40              : int pending_lang_change; /* If we need to switch languages - C++ only */
      41              : int c_header_level;      /* depth in C headers - C++ only */
      42              : 
      43              : static tree interpret_integer (const cpp_token *, unsigned int,
      44              :                                enum overflow_type *);
      45              : static tree interpret_float (const cpp_token *, unsigned int, const char *,
      46              :                              enum overflow_type *);
      47              : static tree interpret_fixed (const cpp_token *, unsigned int);
      48              : static enum integer_type_kind narrowest_unsigned_type
      49              :         (const widest_int &, unsigned int);
      50              : static enum integer_type_kind narrowest_signed_type
      51              :         (const widest_int &, unsigned int);
      52              : static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool);
      53              : static tree lex_charconst (const cpp_token *);
      54              : static void update_header_times (const char *);
      55              : static int dump_one_header (splay_tree_node, void *);
      56              : static void cb_line_change (cpp_reader *, const cpp_token *, int);
      57              : static void cb_ident (cpp_reader *, location_t, const cpp_string *);
      58              : static void cb_def_pragma (cpp_reader *, location_t);
      59              : static void cb_define (cpp_reader *, location_t, cpp_hashnode *);
      60              : static void cb_undef (cpp_reader *, location_t, cpp_hashnode *);
      61              : 
      62              : void
      63       204999 : init_c_lex (void)
      64              : {
      65       204999 :   struct c_fileinfo *toplevel;
      66              : 
      67              :   /* The get_fileinfo data structure must be initialized before
      68              :      cpp_read_main_file is called.  */
      69       204999 :   toplevel = get_fileinfo ("<top level>");
      70       204999 :   if (flag_detailed_statistics)
      71              :     {
      72            0 :       header_time = 0;
      73            0 :       body_time = get_run_time ();
      74            0 :       toplevel->time = body_time;
      75              :     }
      76              : 
      77       204999 :   struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
      78              : 
      79       204999 :   cb->line_change = cb_line_change;
      80       204999 :   cb->ident = cb_ident;
      81       204999 :   cb->def_pragma = cb_def_pragma;
      82       204999 :   cb->valid_pch = c_common_valid_pch;
      83       204999 :   cb->read_pch = c_common_read_pch;
      84       204999 :   cb->has_attribute = c_common_has_attribute;
      85       204999 :   cb->has_builtin = c_common_has_builtin;
      86       204999 :   cb->has_feature = c_common_has_feature;
      87       204999 :   cb->get_source_date_epoch = cb_get_source_date_epoch;
      88       204999 :   cb->get_suggestion = cb_get_suggestion;
      89       204999 :   cb->remap_filename = remap_macro_filename;
      90              : 
      91              :   /* Set the debug callbacks if we can use them.  */
      92       204999 :   if ((debug_info_level == DINFO_LEVEL_VERBOSE
      93          522 :        && dwarf_debuginfo_p ())
      94       204999 :       || flag_dump_go_spec != NULL)
      95              :     {
      96          526 :       cb->define = cb_define;
      97          526 :       cb->undef = cb_undef;
      98              :     }
      99       204999 : }
     100              : 
     101              : struct c_fileinfo *
     102    334279557 : get_fileinfo (const char *name)
     103              : {
     104    334279557 :   splay_tree_node n;
     105    334279557 :   struct c_fileinfo *fi;
     106              : 
     107    334279557 :   if (!file_info_tree)
     108       206393 :     file_info_tree = splay_tree_new (splay_tree_compare_strings,
     109              :                                      0,
     110              :                                      splay_tree_delete_pointers);
     111              : 
     112    334279557 :   n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
     113    334279557 :   if (n)
     114    330280286 :     return (struct c_fileinfo *) n->value;
     115              : 
     116      3999271 :   fi = XNEW (struct c_fileinfo);
     117      3999271 :   fi->time = 0;
     118      3999271 :   fi->interface_only = 0;
     119      3999271 :   fi->interface_unknown = 1;
     120      3999271 :   splay_tree_insert (file_info_tree, (splay_tree_key) name,
     121              :                      (splay_tree_value) fi);
     122      3999271 :   return fi;
     123              : }
     124              : 
     125              : static void
     126     20968135 : update_header_times (const char *name)
     127              : {
     128              :   /* Changing files again.  This means currently collected time
     129              :      is charged against header time, and body time starts back at 0.  */
     130     20968135 :   if (flag_detailed_statistics)
     131              :     {
     132            0 :       int this_time = get_run_time ();
     133            0 :       struct c_fileinfo *file = get_fileinfo (name);
     134            0 :       header_time += this_time - body_time;
     135            0 :       file->time += this_time - body_time;
     136            0 :       body_time = this_time;
     137              :     }
     138     20968135 : }
     139              : 
     140              : static int
     141            0 : dump_one_header (splay_tree_node n, void * ARG_UNUSED (dummy))
     142              : {
     143            0 :   print_time ((const char *) n->key,
     144            0 :               ((struct c_fileinfo *) n->value)->time);
     145            0 :   return 0;
     146              : }
     147              : 
     148              : void
     149            0 : dump_time_statistics (void)
     150              : {
     151            0 :   struct c_fileinfo *file = get_fileinfo (LOCATION_FILE (input_location));
     152            0 :   int this_time = get_run_time ();
     153            0 :   file->time += this_time - body_time;
     154              : 
     155            0 :   fprintf (stderr, "\n******\n");
     156            0 :   print_time ("header files (total)", header_time);
     157            0 :   print_time ("main file (total)", this_time - body_time);
     158            0 :   fprintf (stderr, "ratio = %g : 1\n",
     159            0 :            (double) header_time / (double) (this_time - body_time));
     160            0 :   fprintf (stderr, "\n******\n");
     161              : 
     162            0 :   splay_tree_foreach (file_info_tree, dump_one_header, 0);
     163            0 : }
     164              : 
     165              : static void
     166           22 : cb_ident (cpp_reader * ARG_UNUSED (pfile),
     167              :           location_t ARG_UNUSED (line),
     168              :           const cpp_string * ARG_UNUSED (str))
     169              : {
     170           22 :   if (!flag_no_ident)
     171              :     {
     172              :       /* Convert escapes in the string.  */
     173           22 :       cpp_string cstr = { 0, 0 };
     174           22 :       if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING))
     175              :         {
     176           22 :           targetm.asm_out.output_ident ((const char *) cstr.text);
     177           22 :           free (const_cast<unsigned char *> (cstr.text));
     178              :         }
     179              :     }
     180           22 : }
     181              : 
     182              : /* Called at the start of every non-empty line.  TOKEN is the first
     183              :    lexed token on the line.  Used for diagnostic line numbers.  */
     184              : static void
     185   1739162480 : cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
     186              :                 int parsing_args)
     187              : {
     188   1739162480 :   if (token->type != CPP_EOF && !parsing_args)
     189   1732343023 :     input_location = token->src_loc;
     190   1739162480 : }
     191              : 
     192              : void
     193     21172708 : fe_file_change (const line_map_ordinary *new_map)
     194              : {
     195     21172708 :   if (new_map == NULL)
     196              :     return;
     197              : 
     198     20968135 :   if (new_map->reason == LC_ENTER)
     199              :     {
     200              :       /* Don't stack the main buffer on the input stack;
     201              :          we already did in compile_file.  */
     202     10247975 :       if (!MAIN_FILE_P (new_map))
     203              :         {
     204     10042976 :           location_t included_at = linemap_included_from (new_map);
     205     10042976 :           int line = 0;
     206     10042976 :           if (included_at > BUILTINS_LOCATION)
     207     10042976 :             line = SOURCE_LINE (new_map - 1, included_at);
     208              : 
     209     10042976 :           input_location = new_map->start_location;
     210     10042976 :           (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
     211              : #ifdef SYSTEM_IMPLICIT_EXTERN_C
     212              :           if (c_header_level)
     213              :             ++c_header_level;
     214              :           else if (LINEMAP_SYSP (new_map) == 2)
     215              :             {
     216              :               c_header_level = 1;
     217              :               ++pending_lang_change;
     218              :             }
     219              : #endif
     220              :         }
     221              :     }
     222     10720160 :   else if (new_map->reason == LC_LEAVE)
     223              :     {
     224              : #ifdef SYSTEM_IMPLICIT_EXTERN_C
     225              :       if (c_header_level && --c_header_level == 0)
     226              :         {
     227              :           if (LINEMAP_SYSP (new_map) == 2)
     228              :             warning (0, "badly nested C headers from preprocessor");
     229              :           --pending_lang_change;
     230              :         }
     231              : #endif
     232     10042973 :       input_location = new_map->start_location;
     233              : 
     234     10042973 :       (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
     235              :     }
     236              : 
     237     20968135 :   update_header_times (LINEMAP_FILE (new_map));
     238     20968135 :   input_location = new_map->start_location;
     239              : }
     240              : 
     241              : static void
     242         1685 : cb_def_pragma (cpp_reader *pfile, location_t loc)
     243              : {
     244              :   /* Issue a warning message if we have been asked to do so.  Ignore
     245              :      unknown pragmas in system headers unless an explicit
     246              :      -Wunknown-pragmas has been given.  */
     247         1685 :   if (warn_unknown_pragmas > in_system_header_at (input_location))
     248              :     {
     249           65 :       const unsigned char *space, *name;
     250           65 :       const cpp_token *s;
     251              : 
     252              :       /* If we are processing a _Pragma, LOC is not a valid location, but libcpp
     253              :          will provide a good location via this function instead.  */
     254           65 :       location_t fe_loc = cpp_get_diagnostic_override_loc (pfile);
     255           65 :       if (fe_loc == UNKNOWN_LOCATION)
     256           42 :         fe_loc = loc;
     257              : 
     258           65 :       space = name = (const unsigned char *) "";
     259              : 
     260              :       /* N.B.  It's fine to call cpp_get_token () directly here (rather than our
     261              :          local wrapper get_token ()), because this callback is not used with
     262              :          flag_preprocess_only==true.  */
     263           65 :       s = cpp_get_token (pfile);
     264           65 :       if (s->type != CPP_EOF)
     265              :         {
     266           64 :           space = cpp_token_as_text (pfile, s);
     267           64 :           s = cpp_get_token (pfile);
     268           64 :           if (s->type == CPP_NAME)
     269           37 :             name = cpp_token_as_text (pfile, s);
     270              :         }
     271              : 
     272           65 :       warning_at (fe_loc, OPT_Wunknown_pragmas, "ignoring %<#pragma %s %s%>",
     273              :                   space, name);
     274              :     }
     275         1685 : }
     276              : 
     277              : /* #define callback for DWARF and DWARF2 debug info.  */
     278              : static void
     279       258567 : cb_define (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
     280              : {
     281       258567 :   const struct line_map *map = linemap_lookup (line_table, loc);
     282       258567 :   (*debug_hooks->define) (SOURCE_LINE (linemap_check_ordinary (map), loc),
     283       258567 :                           (const char *) cpp_macro_definition (pfile, node));
     284       258567 : }
     285              : 
     286              : /* #undef callback for DWARF and DWARF2 debug info.  */
     287              : static void
     288         1539 : cb_undef (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
     289              : {
     290         1539 :   if (lang_hooks.preprocess_undef)
     291            0 :     lang_hooks.preprocess_undef (pfile, loc, node);
     292              : 
     293         1539 :   const struct line_map *map = linemap_lookup (line_table, loc);
     294         1539 :   (*debug_hooks->undef) (SOURCE_LINE (linemap_check_ordinary (map), loc),
     295         1539 :                          (const char *) NODE_NAME (node));
     296         1539 : }
     297              : 
     298              : /* Wrapper around cpp_get_token_with_location to stream the token to the
     299              :    preprocessor so it can output it.  This is necessary with
     300              :    flag_preprocess_only if we are obtaining tokens here instead of from the loop
     301              :    in c-ppoutput.cc, such as while processing a #pragma.  */
     302              : 
     303              : static const cpp_token *
     304  13281248415 : get_token (cpp_reader *pfile, location_t *loc = nullptr)
     305              : {
     306  13281248415 :   if (flag_preprocess_only)
     307              :     {
     308        89656 :       location_t x;
     309        89656 :       if (!loc)
     310            0 :         loc = &x;
     311        89656 :       const auto tok = cpp_get_token_with_location (pfile, loc);
     312        89656 :       c_pp_stream_token (pfile, tok, *loc);
     313        89656 :       return tok;
     314              :     }
     315              :   else
     316  13281158759 :     return cpp_get_token_with_location (pfile, loc);
     317              : }
     318              : 
     319              : /* Wrapper around cpp_get_token to skip CPP_PADDING tokens
     320              :    and not consume CPP_EOF.  This does not perform the optional
     321              :    streaming in preprocess_only mode, so is suitable to be used
     322              :    when processing builtin expansions such as c_common_has_attribute.  */
     323              : 
     324              : static const cpp_token *
     325     26852454 : get_token_no_padding (cpp_reader *pfile)
     326              : {
     327     26852750 :   for (;;)
     328              :     {
     329     26852750 :       const cpp_token *ret = cpp_peek_token (pfile, 0);
     330     26852750 :       if (ret->type == CPP_EOF)
     331              :         return ret;
     332     26852730 :       ret = cpp_get_token (pfile);
     333     26852730 :       if (ret->type != CPP_PADDING)
     334              :         return ret;
     335              :     }
     336              : }
     337              : 
     338              : /* Callback for has_attribute.  */
     339              : int
     340       824811 : c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
     341              : {
     342       824811 :   int result = 0;
     343       824811 :   tree attr_name = NULL_TREE;
     344       824811 :   const cpp_token *token;
     345              : 
     346       824811 :   token = get_token_no_padding (pfile);
     347       824811 :   if (token->type != CPP_OPEN_PAREN)
     348              :     {
     349            2 :       cpp_error (pfile, CPP_DL_ERROR,
     350              :                  "missing %<(%> after %<__has_attribute%>");
     351            2 :       return 0;
     352              :     }
     353       824809 :   token = get_token_no_padding (pfile);
     354       824809 :   if (token->type == CPP_NAME)
     355              :     {
     356       824805 :       attr_name = get_identifier ((const char *)
     357              :                                   cpp_token_as_text (pfile, token));
     358       824805 :       attr_name = canonicalize_attr_name (attr_name);
     359       824805 :       bool have_scope = false;
     360       824805 :       int idx = 0;
     361       824865 :       const cpp_token *nxt_token;
     362       824865 :       do
     363       824865 :         nxt_token = cpp_peek_token (pfile, idx++);
     364       824865 :       while (nxt_token->type == CPP_PADDING);
     365       824805 :       if (!c_dialect_cxx ()
     366       401097 :           && nxt_token->type == CPP_COLON
     367            2 :           && (nxt_token->flags & COLON_SCOPE) != 0)
     368              :         {
     369              :           const cpp_token *prev_token = nxt_token;
     370            2 :           do
     371            2 :             nxt_token = cpp_peek_token (pfile, idx++);
     372            2 :           while (nxt_token->type == CPP_PADDING);
     373            2 :           if (nxt_token->type == CPP_COLON)
     374              :             {
     375              :               /* __has_attribute (vendor::attr) in -std=c17 etc. modes.
     376              :                  :: isn't CPP_SCOPE but 2 CPP_COLON tokens, where the
     377              :                  first one should have COLON_SCOPE flag to distinguish
     378              :                  it from : :.  */
     379            2 :               have_scope = true;
     380            2 :               get_token_no_padding (pfile); // Eat first colon.
     381              :             }
     382              :           else
     383              :             nxt_token = prev_token;
     384              :         }
     385       824805 :       if (nxt_token->type == CPP_SCOPE || have_scope)
     386              :         {
     387          820 :           have_scope = true;
     388          820 :           get_token_no_padding (pfile); // Eat scope.
     389          820 :           nxt_token = get_token_no_padding (pfile);
     390          820 :           if (nxt_token->type == CPP_NAME)
     391              :             {
     392          819 :               tree attr_ns = attr_name;
     393          819 :               tree attr_id
     394          819 :                 = get_identifier ((const char *)
     395              :                                   cpp_token_as_text (pfile, nxt_token));
     396          819 :               attr_id = canonicalize_attr_name (attr_id);
     397              :               /* OpenMP attributes need special handling.  */
     398          723 :               if ((flag_openmp || flag_openmp_simd)
     399          192 :                   && is_attribute_p ("omp", attr_ns)
     400         1011 :                   && (is_attribute_p ("directive", attr_id)
     401          144 :                       || is_attribute_p ("sequence", attr_id)
     402           96 :                       || is_attribute_p ("decl", attr_id)))
     403              :                 result = 1;
     404          675 :               if (result)
     405              :                 attr_name = NULL_TREE;
     406              :               /* gnu::trivial_abi is in the attribute table just
     407              :                  to error on it and suggest using [[clang::trivial_abi]]
     408              :                  or __attribute__((trivial_abi)).  Don't advertise it.  */
     409          675 :               else if (c_dialect_cxx ()
     410          631 :                        && is_attribute_p ("gnu", attr_ns)
     411          732 :                        && is_attribute_p ("trivial_abi", attr_id))
     412              :                 attr_name = NULL_TREE;
     413              :               else
     414          669 :                 attr_name = build_tree_list (attr_ns, attr_id);
     415              :             }
     416              :           else
     417              :             {
     418            1 :               cpp_error (pfile, CPP_DL_ERROR,
     419              :                          "attribute identifier required after scope");
     420            1 :               attr_name = NULL_TREE;
     421              :             }
     422              :         }
     423              :       else
     424              :         {
     425              :           /* Some standard attributes need special handling.  */
     426       823985 :           if (c_dialect_cxx ())
     427              :             {
     428       422969 :               if (is_attribute_p ("noreturn", attr_name))
     429              :                 result = 200809;
     430       422918 :               else if (is_attribute_p ("deprecated", attr_name))
     431              :                 result = 201309;
     432       400036 :               else if (is_attribute_p ("maybe_unused", attr_name)
     433       400036 :                        || is_attribute_p ("fallthrough", attr_name))
     434              :                 result = 201603;
     435       399567 :               else if (is_attribute_p ("no_unique_address", attr_name)
     436       376767 :                        || is_attribute_p ("likely", attr_name)
     437       776326 :                        || is_attribute_p ("unlikely", attr_name))
     438              :                 result = 201803;
     439       376751 :               else if (is_attribute_p ("nodiscard", attr_name))
     440              :                 result = 201907;
     441       376740 :               else if (is_attribute_p ("assume", attr_name))
     442              :                 result = 202207;
     443       365455 :               else if (is_attribute_p ("init_priority", attr_name))
     444              :                 {
     445              :                   /* The (non-standard) init_priority attribute is always
     446              :                      included in the attribute table, but we don't want to
     447              :                      advertise the attribute unless the target actually
     448              :                      supports init priorities.  */
     449              :                   result = SUPPORTS_INIT_PRIORITY ? 1 : 0;
     450              :                   attr_name = NULL_TREE;
     451              :                 }
     452              :             }
     453              :           else
     454              :             {
     455       401016 :               if (is_attribute_p ("deprecated", attr_name)
     456       375968 :                   || is_attribute_p ("fallthrough", attr_name)
     457       375813 :                   || is_attribute_p ("maybe_unused", attr_name)
     458       375811 :                   || is_attribute_p ("nodiscard", attr_name)
     459       375809 :                   || is_attribute_p ("noreturn", attr_name)
     460       375795 :                   || is_attribute_p ("_Noreturn", attr_name)
     461       375793 :                   || is_attribute_p ("reproducible", attr_name)
     462       776807 :                   || is_attribute_p ("unsequenced", attr_name))
     463              :                 result = 202311;
     464              :             }
     465              :           if (result)
     466              :             attr_name = NULL_TREE;
     467              :         }
     468       731637 :       if (attr_name && (have_scope || !std_syntax))
     469              :         {
     470       731632 :           init_attributes ();
     471       731632 :           const struct attribute_spec *attr = lookup_attribute_spec (attr_name);
     472       731632 :           if (attr)
     473       741421 :             result = 1;
     474              :         }
     475              :     }
     476              :   else
     477              :     {
     478            4 :       cpp_error (pfile, CPP_DL_ERROR,
     479              :                  "macro %<__has_attribute%> requires an identifier");
     480            4 :       return 0;
     481              :     }
     482              : 
     483       824805 :   if (get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
     484            3 :     cpp_error (pfile, CPP_DL_ERROR,
     485              :                "missing %<)%> after %<__has_attribute%>");
     486              : 
     487              :   return result;
     488              : }
     489              : 
     490              : /* Helper for __has_{builtin,feature,extension}.  */
     491              : 
     492              : static const char *
     493      8125441 : c_common_lex_availability_macro (cpp_reader *pfile, const char *builtin)
     494              : {
     495      8125441 :   const cpp_token *token = get_token_no_padding (pfile);
     496      8125441 :   if (token->type != CPP_OPEN_PAREN)
     497              :     {
     498            4 :       cpp_error (pfile, CPP_DL_ERROR,
     499              :                  "missing %<(%> after %<__has_%s%>", builtin);
     500            4 :       return 0;
     501              :     }
     502              : 
     503      8125437 :   const char *name = "";
     504      8125437 :   token = get_token_no_padding (pfile);
     505      8125437 :   if (token->type == CPP_NAME)
     506              :     {
     507      8125405 :       name = (const char *) cpp_token_as_text (pfile, token);
     508      8125405 :       token = get_token_no_padding (pfile);
     509      8125405 :       if (token->type != CPP_CLOSE_PAREN)
     510              :         {
     511           16 :           cpp_error (pfile, CPP_DL_ERROR,
     512              :                      "expected %<)%> after %qs", name);
     513           16 :           name = "";
     514              :         }
     515              :     }
     516              :   else
     517              :     {
     518           32 :       cpp_error (pfile, CPP_DL_ERROR,
     519              :                  "macro %<__has_%s%> requires an identifier", builtin);
     520           32 :       if (token->type == CPP_CLOSE_PAREN)
     521              :         return 0;
     522              :     }
     523              : 
     524              :   /* Consume tokens up to the closing parenthesis, including any nested
     525              :      pairs of parentheses, to avoid confusing redundant errors.  */
     526      8125537 :   for (unsigned nparen = 1; ; token = get_token_no_padding (pfile))
     527              :     {
     528      8125537 :       if (token->type == CPP_OPEN_PAREN)
     529           24 :         ++nparen;
     530      8125513 :       else if (token->type == CPP_CLOSE_PAREN)
     531      8125437 :         --nparen;
     532           76 :       else if (token->type == CPP_EOF)
     533              :         break;
     534      8125525 :       if (!nparen)
     535              :         break;
     536              :     }
     537              : 
     538              :   return name;
     539              : }
     540              : 
     541              : /* Callback for has_builtin.  */
     542              : 
     543              : int
     544      7994499 : c_common_has_builtin (cpp_reader *pfile)
     545              : {
     546      7994499 :   const char *name = c_common_lex_availability_macro (pfile, "builtin");
     547      7994499 :   if (!name)
     548              :     return 0;
     549              : 
     550      7994491 :   return names_builtin_p (name);
     551              : }
     552              : 
     553              : /* Callback for has_feature.  STRICT_P is true for has_feature and false
     554              :    for has_extension.  */
     555              : 
     556              : int
     557       130942 : c_common_has_feature (cpp_reader *pfile, bool strict_p)
     558              : {
     559       130942 :   const char *builtin = strict_p ? "feature" : "extension";
     560       130942 :   const char *name = c_common_lex_availability_macro (pfile, builtin);
     561       130942 :   if (!name)
     562              :     return 0;
     563              : 
     564              :   /* If -pedantic-errors is given, __has_extension is equivalent to
     565              :      __has_feature.  */
     566       130942 :   strict_p |= flag_pedantic_errors;
     567       130942 :   return has_feature_p (name, strict_p);
     568              : }
     569              : 
     570              : 
     571              : /* Read a token and return its type.  Fill *VALUE with its value, if
     572              :    applicable.  Fill *CPP_FLAGS with the token's flags, if it is
     573              :    non-NULL.  */
     574              : 
     575              : enum cpp_ttype
     576  12109757506 : c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
     577              :                   int lex_flags)
     578              : {
     579  12109757506 :   const cpp_token *tok;
     580  12109757506 :   enum cpp_ttype type;
     581  12109757506 :   unsigned char add_flags = 0;
     582  12109757506 :   enum overflow_type overflow = OT_NONE;
     583              : 
     584  12109757506 :   timevar_push (TV_CPP);
     585  13281248229 :  retry:
     586  13281248229 :   tok = get_token (parse_in, loc);
     587  13281248037 :   type = tok->type;
     588              : 
     589  13281248181 :  retry_after_at:
     590  13281248181 :   switch (type)
     591              :     {
     592   1171490381 :     case CPP_PADDING:
     593   1171490381 :       goto retry;
     594              : 
     595   5544558351 :     case CPP_NAME:
     596   5544558351 :       *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
     597   5544558351 :       break;
     598              : 
     599    201552487 :     case CPP_NUMBER:
     600    201552487 :       {
     601    201552487 :         const char *suffix = NULL;
     602    201552487 :         unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc);
     603              : 
     604    201552487 :         switch (flags & CPP_N_CATEGORY)
     605              :           {
     606          174 :           case CPP_N_INVALID:
     607              :             /* cpplib has issued an error.  */
     608          174 :             *value = error_mark_node;
     609          174 :             break;
     610              : 
     611    196529593 :           case CPP_N_INTEGER:
     612              :             /* C++ uses '0' to mark virtual functions as pure.
     613              :                Set PURE_ZERO to pass this information to the C++ parser.  */
     614    196529593 :             if (tok->val.str.len == 1 && *tok->val.str.text == '0')
     615              :               add_flags = PURE_ZERO | DECIMAL_INT;
     616    157321479 :             else if ((flags & CPP_N_INTEGER) && (flags & CPP_N_DECIMAL))
     617              :               /* -Wxor-used-as-pow is only active for LHS of ^ expressed
     618              :                  as a decimal integer. */
     619    196529593 :               add_flags = DECIMAL_INT;
     620    196529593 :             *value = interpret_integer (tok, flags, &overflow);
     621    196529593 :             break;
     622              : 
     623      5022720 :           case CPP_N_FLOATING:
     624      5022720 :             *value = interpret_float (tok, flags, suffix, &overflow);
     625      5022720 :             break;
     626              : 
     627            0 :           default:
     628            0 :             gcc_unreachable ();
     629              :           }
     630              : 
     631    201552487 :         if (flags & CPP_N_USERDEF)
     632              :           {
     633       221111 :             char *str;
     634       221111 :             tree literal;
     635       221111 :             tree suffix_id = get_identifier (suffix);
     636       221111 :             int len = tok->val.str.len - strlen (suffix);
     637              :             /* If this is going to be used as a C string to pass to a
     638              :                raw literal operator, we need to add a trailing NUL.  */
     639       442222 :             tree num_string = build_string (len + 1,
     640       221111 :                                             (const char *) tok->val.str.text);
     641       221111 :             TREE_TYPE (num_string) = char_array_type_node;
     642       221111 :             num_string = fix_string_type (num_string);
     643       221111 :             str = const_cast<char *> (TREE_STRING_POINTER (num_string));
     644       221111 :             str[len] = '\0';
     645       221111 :             literal = build_userdef_literal (suffix_id, *value, overflow,
     646              :                                              num_string);
     647       221111 :             *value = literal;
     648              :           }
     649              :       }
     650    201552487 :       break;
     651              : 
     652            3 :     case CPP_ATSIGN:
     653              :       /* An @ may give the next token special significance in Objective-C.  */
     654            3 :       if (c_dialect_objc ())
     655              :         {
     656            0 :           location_t atloc = *loc;
     657            0 :           location_t newloc;
     658              : 
     659            0 :         retry_at:
     660            0 :           tok = get_token (parse_in, &newloc);
     661            0 :           type = tok->type;
     662            0 :           switch (type)
     663              :             {
     664            0 :             case CPP_PADDING:
     665            0 :               goto retry_at;
     666              : 
     667            0 :             case CPP_STRING:
     668            0 :             case CPP_WSTRING:
     669            0 :             case CPP_STRING16:
     670            0 :             case CPP_STRING32:
     671            0 :             case CPP_UTF8STRING:
     672            0 :               type = lex_string (tok, value, true, true);
     673            0 :               break;
     674              : 
     675            0 :             case CPP_NAME:
     676            0 :               *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
     677            0 :               if (OBJC_IS_AT_KEYWORD (C_RID_CODE (*value))
     678              :                   || OBJC_IS_CXX_KEYWORD (C_RID_CODE (*value)))
     679              :                 {
     680            0 :                   type = CPP_AT_NAME;
     681              :                   /* Note the complication: if we found an OBJC_CXX
     682              :                      keyword, for example, 'class', we will be
     683              :                      returning a token of type CPP_AT_NAME and rid
     684              :                      code RID_CLASS (not RID_AT_CLASS).  The language
     685              :                      parser needs to convert that to RID_AT_CLASS.
     686              :                      However, we've now spliced the '@' together with the
     687              :                      keyword that follows; Adjust the location so that we
     688              :                      get a source range covering the composite.
     689              :                   */
     690            0 :                  *loc = make_location (atloc, atloc, newloc);
     691            0 :                   break;
     692              :                 }
     693              :               /* FALLTHROUGH */
     694              : 
     695            0 :             default:
     696              :               /* ... or not.  */
     697            0 :               error_at (atloc, "stray %<@%> in program");
     698            0 :               *loc = newloc;
     699            0 :               goto retry_after_at;
     700              :             }
     701            0 :           break;
     702              :         }
     703              : 
     704              :       /* FALLTHROUGH */
     705           23 :     case CPP_HASH:
     706           23 :     case CPP_PASTE:
     707           23 :       {
     708           23 :         unsigned char name[8];
     709              : 
     710           23 :         *cpp_spell_token (parse_in, tok, name, true) = 0;
     711              : 
     712           23 :         error_at (*loc, "stray %qs in program", name);
     713              :       }
     714              : 
     715           23 :       goto retry;
     716              : 
     717          135 :     case CPP_OTHER:
     718          135 :       {
     719          135 :         cppchar_t c = tok->val.str.text[0];
     720              : 
     721          135 :         if (c == '"' || c == '\'')
     722           25 :           error_at (*loc, "missing terminating %c character", (int) c);
     723          110 :         else if (ISGRAPH (c))
     724          102 :           error_at (*loc, "stray %qc in program", (int) c);
     725              :         else
     726              :           {
     727            8 :             rich_location rich_loc (line_table, *loc);
     728            8 :             rich_loc.set_escape_on_output (true);
     729            8 :             error_at (&rich_loc, "stray %<\\%o%> in program", (int) c);
     730            8 :           }
     731              :       }
     732          135 :       goto retry;
     733              : 
     734          110 :     case CPP_CHAR_USERDEF:
     735          110 :     case CPP_WCHAR_USERDEF:
     736          110 :     case CPP_CHAR16_USERDEF:
     737          110 :     case CPP_CHAR32_USERDEF:
     738          110 :     case CPP_UTF8CHAR_USERDEF:
     739          110 :       {
     740          110 :         tree literal;
     741          110 :         cpp_token temp_tok = *tok;
     742          110 :         const char *suffix = cpp_get_userdef_suffix (tok);
     743          110 :         temp_tok.val.str.len -= strlen (suffix);
     744          110 :         temp_tok.type = cpp_userdef_char_remove_type (type);
     745          110 :         literal = build_userdef_literal (get_identifier (suffix),
     746              :                                          lex_charconst (&temp_tok),
     747              :                                          OT_NONE, NULL_TREE);
     748          110 :         *value = literal;
     749              :       }
     750          110 :       break;
     751              : 
     752      9280641 :     case CPP_CHAR:
     753      9280641 :     case CPP_WCHAR:
     754      9280641 :     case CPP_CHAR16:
     755      9280641 :     case CPP_CHAR32:
     756      9280641 :     case CPP_UTF8CHAR:
     757      9280641 :       *value = lex_charconst (tok);
     758      9280641 :       break;
     759              : 
     760       318975 :     case CPP_STRING_USERDEF:
     761       318975 :     case CPP_WSTRING_USERDEF:
     762       318975 :     case CPP_STRING16_USERDEF:
     763       318975 :     case CPP_STRING32_USERDEF:
     764       318975 :     case CPP_UTF8STRING_USERDEF:
     765       318975 :       {
     766       318975 :         tree literal, string;
     767       318975 :         const char *suffix = cpp_get_userdef_suffix (tok);
     768       637950 :         string = build_string (tok->val.str.len - strlen (suffix),
     769       318975 :                                (const char *) tok->val.str.text);
     770       318975 :         literal = build_userdef_literal (get_identifier (suffix),
     771              :                                          string, OT_NONE, NULL_TREE);
     772       318975 :         *value = literal;
     773              :       }
     774       318975 :       break;
     775              : 
     776     56187856 :     case CPP_STRING:
     777     56187856 :     case CPP_WSTRING:
     778     56187856 :     case CPP_STRING16:
     779     56187856 :     case CPP_STRING32:
     780     56187856 :     case CPP_UTF8STRING:
     781     56187856 :       if ((lex_flags & C_LEX_STRING_NO_JOIN) == 0)
     782              :         {
     783           18 :           type = lex_string (tok, value, false,
     784              :                              (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
     785           18 :           break;
     786              :         }
     787     56187838 :       *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
     788     56187838 :       break;
     789              : 
     790      9473781 :     case CPP_PRAGMA:
     791      9473781 :       *value = build_int_cst (integer_type_node, tok->val.pragma);
     792      9473781 :       break;
     793              : 
     794          877 :     case CPP_HEADER_NAME:
     795          877 :       *value = build_string (tok->val.str.len, (const char *)tok->val.str.text);
     796          877 :       break;
     797              : 
     798          404 :     case CPP_EMBED:
     799          404 :       *value = make_node (RAW_DATA_CST);
     800          404 :       TREE_TYPE (*value) = integer_type_node;
     801          404 :       RAW_DATA_LENGTH (*value) = tok->val.str.len;
     802          404 :       if (pch_file)
     803              :         {
     804              :           /* When writing PCH headers, copy the data over, such that
     805              :              the owner is a STRING_CST.  */
     806            6 :           int off = 0;
     807            6 :           if (tok->val.str.len <= INT_MAX - 2)
     808              :             /* See below.  */
     809            6 :             off = 1;
     810           12 :           tree owner = build_string (tok->val.str.len + 2 * off,
     811            6 :                                      (const char *) tok->val.str.text - off);
     812            6 :           TREE_TYPE (owner) = build_array_type_nelts (unsigned_char_type_node,
     813            6 :                                                       tok->val.str.len);
     814            6 :           RAW_DATA_OWNER (*value) = owner;
     815            6 :           RAW_DATA_POINTER (*value) = TREE_STRING_POINTER (owner) + off;
     816              :         }
     817              :       else
     818              :         {
     819              :           /* Otherwise add another dummy RAW_DATA_CST as owner which
     820              :              indicates the data is owned by libcpp.  */
     821          398 :           RAW_DATA_POINTER (*value) = (const char *) tok->val.str.text;
     822          398 :           tree owner = make_node (RAW_DATA_CST);
     823          398 :           TREE_TYPE (owner) = integer_type_node;
     824          398 :           RAW_DATA_LENGTH (owner) = tok->val.str.len;
     825          398 :           RAW_DATA_POINTER (owner) = (const char *) tok->val.str.text;
     826          398 :           if (tok->val.str.len <= INT_MAX - 2)
     827              :             {
     828              :               /* The preprocessor surrounds at least smaller CPP_EMBEDs
     829              :                  in between CPP_NUMBER CPP_COMMA before and
     830              :                  CPP_COMMA CPP_NUMBER after, so the actual libcpp buffer
     831              :                  holds those 2 extra bytes around it.  Don't do that if
     832              :                  CPP_EMBED is at the maximum ~ 2GB size.  */
     833          398 :               RAW_DATA_LENGTH (owner) += 2;
     834          398 :               RAW_DATA_POINTER (owner)--;
     835              :             }
     836          398 :           RAW_DATA_OWNER (*value) = owner;
     837              :         }
     838              :       break;
     839              : 
     840              :       /* This token should not be visible outside cpplib.  */
     841            0 :     case CPP_MACRO_ARG:
     842            0 :       gcc_unreachable ();
     843              : 
     844              :     /* CPP_COMMENT will appear when compiling with -C.  Ignore, except
     845              :        when it is a FALLTHROUGH comment, in that case set
     846              :        PREV_FALLTHROUGH flag on the next non-comment token.  */
     847          328 :     case CPP_COMMENT:
     848          328 :       if (tok->flags & PREV_FALLTHROUGH)
     849              :         {
     850          168 :           do
     851              :             {
     852          168 :               tok = get_token (parse_in, loc);
     853          168 :               type = tok->type;
     854              :             }
     855          168 :           while (type == CPP_PADDING || type == CPP_COMMENT);
     856          144 :           add_flags |= PREV_FALLTHROUGH;
     857          144 :           goto retry_after_at;
     858              :         }
     859          184 :       goto retry;
     860              : 
     861   6288383832 :     default:
     862   6288383832 :       *value = NULL_TREE;
     863   6288383832 :       break;
     864              :     }
     865              : 
     866  12109757314 :   if (cpp_flags)
     867  12109757314 :     *cpp_flags = tok->flags | add_flags;
     868              : 
     869  12109757314 :   timevar_pop (TV_CPP);
     870              : 
     871  12109757314 :   return type;
     872              : }
     873              : 
     874              : /* Returns the narrowest C-visible unsigned type, starting with the
     875              :    minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if
     876              :    there isn't one.  */
     877              : 
     878              : static enum integer_type_kind
     879    196509246 : narrowest_unsigned_type (const widest_int &val, unsigned int flags)
     880              : {
     881    196509246 :   int itk;
     882              : 
     883    196509246 :   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
     884              :     itk = itk_unsigned_int;
     885      3773901 :   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
     886              :     itk = itk_unsigned_long;
     887              :   else
     888      1300597 :     itk = itk_unsigned_long_long;
     889              : 
     890    196749100 :   for (; itk < itk_none; itk += 2 /* skip unsigned types */)
     891              :     {
     892    196749100 :       tree upper;
     893              : 
     894    196749100 :       if (integer_types[itk] == NULL_TREE)
     895            0 :         continue;
     896    196749100 :       upper = TYPE_MAX_VALUE (integer_types[itk]);
     897              : 
     898    196749100 :       if (wi::geu_p (wi::to_widest (upper), val))
     899    196509246 :         return (enum integer_type_kind) itk;
     900              :     }
     901              : 
     902              :   return itk_none;
     903              : }
     904              : 
     905              : /* Ditto, but narrowest signed type.  */
     906              : static enum integer_type_kind
     907    192640447 : narrowest_signed_type (const widest_int &val, unsigned int flags)
     908              : {
     909    192640447 :   int itk;
     910              : 
     911    192640447 :   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
     912              :     itk = itk_int;
     913      1334733 :   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
     914              :     itk = itk_long;
     915              :   else
     916       298923 :     itk = itk_long_long;
     917              : 
     918    192853128 :   for (; itk < itk_none; itk += 2 /* skip signed types */)
     919              :     {
     920    192852030 :       tree upper;
     921              : 
     922    192852030 :       if (integer_types[itk] == NULL_TREE)
     923         4392 :         continue;
     924    192847638 :       upper = TYPE_MAX_VALUE (integer_types[itk]);
     925              : 
     926    192847638 :       if (wi::geu_p (wi::to_widest (upper), val))
     927    192639349 :         return (enum integer_type_kind) itk;
     928              :     }
     929              : 
     930              :   return itk_none;
     931              : }
     932              : 
     933              : /* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
     934              : static tree
     935    196529593 : interpret_integer (const cpp_token *token, unsigned int flags,
     936              :                    enum overflow_type *overflow)
     937              : {
     938    196529593 :   tree value, type;
     939    196529593 :   enum integer_type_kind itk;
     940    196529593 :   cpp_num integer;
     941    196529593 :   HOST_WIDE_INT ival[3];
     942              : 
     943    196529593 :   *overflow = OT_NONE;
     944              : 
     945    196529593 :   if (UNLIKELY (flags & CPP_N_BITINT))
     946              :     {
     947        20347 :       unsigned int suffix_len = 2 + ((flags & CPP_N_UNSIGNED) ? 1 : 0);
     948        20347 :       int max_bits_per_digit = 4; // ceil (log2 (10))
     949        20347 :       unsigned int prefix_len = 0;
     950        20347 :       bool hex = false;
     951        20347 :       const int bitint_maxwidth = WIDE_INT_MAX_PRECISION - 1;
     952        20347 :       if ((flags & CPP_N_RADIX) == CPP_N_OCTAL)
     953              :         {
     954         1201 :           max_bits_per_digit = 3;
     955         1201 :           prefix_len = 1;
     956         1201 :           if (token->val.str.len > 2
     957         1201 :               && (token->val.str.text[1] == 'o'
     958         1200 :                   || token->val.str.text[1] == 'O'))
     959        20347 :             prefix_len = 2;
     960              :         }
     961        19146 :       else if ((flags & CPP_N_RADIX) == CPP_N_HEX)
     962              :         {
     963              :           max_bits_per_digit = 4;
     964              :           prefix_len = 2;
     965              :           hex = true;
     966              :         }
     967        18876 :       else if ((flags & CPP_N_RADIX) == CPP_N_BINARY)
     968              :         {
     969            1 :           max_bits_per_digit = 1;
     970            1 :           prefix_len = 2;
     971              :         }
     972        20347 :       int max_digits
     973        20347 :         = TYPE_PRECISION (intmax_type_node) >> max_bits_per_digit;
     974        20347 :       const int max_buf = 128;
     975        20347 :       if (max_digits > max_buf)
     976              :         max_digits = max_buf;
     977              : 
     978        20347 :       widest_int wval;
     979        20347 :       unsigned int prec;
     980        20347 :       gcc_checking_assert (token->val.str.len > prefix_len + suffix_len
     981              :                            || token->val.str.len == 1 + suffix_len);
     982        20347 :       if (token->val.str.len - (prefix_len + suffix_len)
     983        20347 :           <= (unsigned) max_digits)
     984              :         {
     985         3233 :           integer = cpp_interpret_integer (parse_in, token,
     986              :                                            (flags & CPP_N_RADIX)
     987              :                                            | CPP_N_UNSIGNED);
     988         3233 :           ival[0] = integer.low;
     989         3233 :           ival[1] = integer.high;
     990         3233 :           ival[2] = 0;
     991         3233 :           wval = widest_int::from_array (ival, 3);
     992              :         }
     993              :       else
     994              :         {
     995        17114 :           unsigned char buf[3 + max_buf];
     996        17114 :           memcpy (buf, token->val.str.text, prefix_len);
     997        17114 :           wval = 0U;
     998        17114 :           const unsigned char *p = token->val.str.text + prefix_len;
     999        17114 :           cpp_token tok = *token;
    1000        17114 :           tok.val.str.text = buf;
    1001        17114 :           if (!prefix_len)
    1002        16860 :             max_digits = 19;
    1003       213910 :           do
    1004              :             {
    1005       115512 :               unsigned char *q = buf + prefix_len;
    1006      1620109 :               do
    1007              :                 {
    1008      1620109 :                   unsigned char c = *p++;
    1009      1620109 :                   if (ISDIGIT (c) || (hex && ISXDIGIT (c)))
    1010              :                     {
    1011      1587085 :                       *q++ = c;
    1012      1587085 :                       if (q == buf + prefix_len + max_digits)
    1013              :                         break;
    1014              :                     }
    1015        33024 :                   else if (c != '\'')
    1016              :                     {
    1017              :                       --p;
    1018              :                       break;
    1019              :                     }
    1020              :                 }
    1021              :               while (1);
    1022       115512 :               if (q == buf + prefix_len)
    1023              :                 break;
    1024              :               else
    1025              :                 {
    1026        98398 :                   wi::overflow_type wioverflow;
    1027        98398 :                   *q = '\0';
    1028        98398 :                   tok.val.str.len = q - buf;
    1029        98398 :                   if (wval == 0)
    1030              :                     ;
    1031        81257 :                   else if (prefix_len)
    1032              :                     {
    1033         4549 :                       prec = wi::min_precision (wval, UNSIGNED);
    1034         4549 :                       unsigned HOST_WIDE_INT shift
    1035         4549 :                         = (tok.val.str.len - prefix_len) * max_bits_per_digit;
    1036         4549 :                       if (prec + shift > bitint_maxwidth)
    1037            0 :                         goto bitint_overflow;
    1038         5733 :                       wval = wi::lshift (wval, shift);
    1039              :                     }
    1040              :                   else
    1041              :                     {
    1042        76708 :                       static unsigned HOST_WIDE_INT tens[]
    1043              :                         = { 1U, 10U, 100U, 1000U,
    1044              :                             HOST_WIDE_INT_UC (10000),
    1045              :                             HOST_WIDE_INT_UC (100000),
    1046              :                             HOST_WIDE_INT_UC (1000000),
    1047              :                             HOST_WIDE_INT_UC (10000000),
    1048              :                             HOST_WIDE_INT_UC (100000000),
    1049              :                             HOST_WIDE_INT_UC (1000000000),
    1050              :                             HOST_WIDE_INT_UC (10000000000),
    1051              :                             HOST_WIDE_INT_UC (100000000000),
    1052              :                             HOST_WIDE_INT_UC (1000000000000),
    1053              :                             HOST_WIDE_INT_UC (10000000000000),
    1054              :                             HOST_WIDE_INT_UC (100000000000000),
    1055              :                             HOST_WIDE_INT_UC (1000000000000000),
    1056              :                             HOST_WIDE_INT_UC (10000000000000000),
    1057              :                             HOST_WIDE_INT_UC (100000000000000000),
    1058              :                             HOST_WIDE_INT_UC (1000000000000000000),
    1059              :                             HOST_WIDE_INT_UC (10000000000000000000) };
    1060        76708 :                       widest_int ten = tens[q - buf];
    1061        76708 :                       wval = wi::umul (wval, ten, &wioverflow);
    1062        76708 :                       if (wioverflow)
    1063            0 :                         goto bitint_overflow;
    1064        76708 :                     }
    1065        98398 :                   integer = cpp_interpret_integer (parse_in, &tok,
    1066              :                                                    (flags & CPP_N_RADIX)
    1067              :                                                    | CPP_N_UNSIGNED);
    1068        98398 :                   ival[0] = integer.low;
    1069        98398 :                   ival[1] = integer.high;
    1070        98398 :                   ival[2] = 0;
    1071        98398 :                   if (prefix_len)
    1072         6014 :                     wval = wval + widest_int::from_array (ival, 3);
    1073              :                   else
    1074              :                     {
    1075        93568 :                       widest_int addend = widest_int::from_array (ival, 3);
    1076        93568 :                       wval = wi::add (wval, addend, UNSIGNED, &wioverflow);
    1077        93568 :                       if (wioverflow)
    1078            0 :                         goto bitint_overflow;
    1079        93568 :                     }
    1080              :                 }
    1081        98398 :             }
    1082              :           while (1);
    1083              :         }
    1084              : 
    1085        20347 :       prec = wi::min_precision (wval, UNSIGNED);
    1086        20347 :       if (prec == 0 && ((flags & CPP_N_UNSIGNED) != 0 || !flag_isoc2y))
    1087          455 :         prec = 1;
    1088        19846 :       if ((flags & CPP_N_UNSIGNED) == 0)
    1089        14474 :         ++prec;
    1090        20347 :       if (prec > bitint_maxwidth)
    1091              :         {
    1092            0 :         bitint_overflow:
    1093            0 :           if ((flags & CPP_N_UNSIGNED) != 0)
    1094            0 :             error ("integer constant is too large for "
    1095              :                    "%<unsigned _BitInt(%d)%> type", bitint_maxwidth);
    1096              :           else
    1097            0 :             error ("integer constant is too large for "
    1098              :                    "%<_BitInt(%d)%> type", bitint_maxwidth);
    1099            0 :           return integer_zero_node;
    1100              :         }
    1101              : 
    1102        20347 :       struct bitint_info info;
    1103        20347 :       if (!targetm.c.bitint_type_info (prec, &info))
    1104              :         {
    1105            0 :           sorry ("%<_BitInt(%d)%> is not supported on this target", prec);
    1106            0 :           return integer_zero_node;
    1107              :         }
    1108              : 
    1109        20347 :       type = build_bitint_type (prec, (flags & CPP_N_UNSIGNED) != 0);
    1110        20347 :       return wide_int_to_tree (type, wval);
    1111        20347 :     }
    1112              : 
    1113    196509246 :   integer = cpp_interpret_integer (parse_in, token, flags);
    1114    196509246 :   if (integer.overflow)
    1115           20 :     *overflow = OT_OVERFLOW;
    1116              : 
    1117    196509246 :   ival[0] = integer.low;
    1118    196509246 :   ival[1] = integer.high;
    1119    196509246 :   ival[2] = 0;
    1120    393018492 :   widest_int wval = widest_int::from_array (ival, 3);
    1121              : 
    1122              :   /* The type of a constant with a U suffix is straightforward.  */
    1123    196509246 :   if (flags & CPP_N_UNSIGNED)
    1124      3868799 :     itk = narrowest_unsigned_type (wval, flags);
    1125              :   else
    1126              :     {
    1127              :       /* The type of a potentially-signed integer constant varies
    1128              :          depending on the base it's in, the standard in use, and the
    1129              :          length suffixes.  */
    1130    192640447 :       enum integer_type_kind itk_u
    1131    192640447 :         = narrowest_unsigned_type (wval, flags);
    1132    192640447 :       enum integer_type_kind itk_s
    1133    192640447 :         = narrowest_signed_type (wval, flags);
    1134              : 
    1135              :       /* In both C89 and C99, octal and hex constants may be signed or
    1136              :          unsigned, whichever fits tighter.  We do not warn about this
    1137              :          choice differing from the traditional choice, as the constant
    1138              :          is probably a bit pattern and either way will work.  */
    1139    192640447 :       if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
    1140    192640432 :         itk = MIN (itk_u, itk_s);
    1141              :       else
    1142              :         {
    1143              :           /* In C99, decimal constants are always signed.
    1144              :              In C89, decimal constants that don't fit in long have
    1145              :              undefined behavior; we try to make them unsigned long.
    1146              :              In GCC's extended C89, that last is true of decimal
    1147              :              constants that don't fit in long long, too.  */
    1148              : 
    1149    139723633 :           itk = itk_s;
    1150    139723633 :           if (itk_s > itk_u && itk_s > itk_long)
    1151              :             {
    1152           32 :               if (!flag_isoc99)
    1153              :                 {
    1154           15 :                   if (itk_u < itk_unsigned_long)
    1155              :                     itk_u = itk_unsigned_long;
    1156           15 :                   itk = itk_u;
    1157           15 :                   warning (0, "this decimal constant is unsigned only in ISO C90");
    1158              :                 }
    1159              :               else
    1160           17 :                 warning (OPT_Wtraditional,
    1161              :                          "this decimal constant would be unsigned in ISO C90");
    1162              :             }
    1163              :         }
    1164              :     }
    1165              : 
    1166    196509246 :   if (itk == itk_none)
    1167              :     /* cpplib has already issued a warning for overflow.  */
    1168            0 :     type = ((flags & CPP_N_UNSIGNED)
    1169            0 :             ? widest_unsigned_literal_type_node
    1170              :             : widest_integer_literal_type_node);
    1171    196509246 :   else if (flags & CPP_N_SIZE_T)
    1172              :     {
    1173              :       /* itk refers to fundamental types not aliased size types.  */
    1174         2136 :       if (flags & CPP_N_UNSIGNED)
    1175         2127 :         type = size_type_node;
    1176              :       else
    1177            9 :         type = signed_size_type_node;
    1178              :     }
    1179              :   else
    1180              :     {
    1181    196507110 :       type = integer_types[itk];
    1182    196507110 :       if (itk > itk_unsigned_long
    1183      1316539 :           && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
    1184        15942 :         emit_diagnostic
    1185        47826 :           ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
    1186              :            ? diagnostics::kind::pedwarn : diagnostics::kind::warning,
    1187        15942 :            input_location, OPT_Wlong_long,
    1188              :            (flags & CPP_N_UNSIGNED)
    1189              :            ? "integer constant is too large for %<unsigned long%> type"
    1190              :            : "integer constant is too large for %<long%> type");
    1191              :     }
    1192              : 
    1193    196509246 :   value = wide_int_to_tree (type, wval);
    1194              : 
    1195              :   /* Convert imaginary to a complex type.  */
    1196    196509246 :   if (flags & CPP_N_IMAGINARY)
    1197         3150 :     value = build_complex (NULL_TREE, build_int_cst (type, 0), value);
    1198              : 
    1199    196509246 :   return value;
    1200              : }
    1201              : 
    1202              : /* Interpret TOKEN, a floating point number with FLAGS as classified
    1203              :    by cpplib.  For C++11 SUFFIX may contain a user-defined literal suffix.  */
    1204              : static tree
    1205      5022720 : interpret_float (const cpp_token *token, unsigned int flags,
    1206              :                  const char *suffix, enum overflow_type *overflow)
    1207              : {
    1208      5022720 :   tree type;
    1209      5022720 :   tree const_type;
    1210      5022720 :   tree value;
    1211      5022720 :   REAL_VALUE_TYPE real;
    1212      5022720 :   REAL_VALUE_TYPE real_trunc;
    1213      5022720 :   char *copy;
    1214      5022720 :   size_t copylen;
    1215              : 
    1216      5022720 :   *overflow = OT_NONE;
    1217              : 
    1218              :   /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64
    1219              :      pragma has been used and is either double or _Decimal64.  Types
    1220              :      that are not allowed with decimal float default to double.  */
    1221      5022720 :   if (flags & CPP_N_DEFAULT)
    1222              :     {
    1223      2593506 :       flags ^= CPP_N_DEFAULT;
    1224      2593506 :       flags |= CPP_N_MEDIUM;
    1225              : 
    1226      2593506 :       if (((flags & CPP_N_HEX) == 0) && ((flags & CPP_N_IMAGINARY) == 0))
    1227              :         {
    1228      2569036 :           warning (OPT_Wunsuffixed_float_constants,
    1229              :                    "unsuffixed floating constant");
    1230      2569036 :           if (float_const_decimal64_p ())
    1231           23 :             flags |= CPP_N_DFLOAT;
    1232              :         }
    1233              :     }
    1234              : 
    1235              :   /* Decode _Fract and _Accum.  */
    1236      5022720 :   if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM)
    1237           54 :     return interpret_fixed (token, flags);
    1238              : 
    1239              :   /* Decode type based on width and properties. */
    1240      5022666 :   if (flags & CPP_N_DFLOAT)
    1241        16109 :     if (!targetm.decimal_float_supported_p ())
    1242              :       {
    1243            0 :         error ("decimal floating-point not supported for this target");
    1244            0 :         return error_mark_node;
    1245              :       }
    1246        16109 :     else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1247         5088 :       type = dfloat128_type_node;
    1248        11021 :     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1249         5518 :       type = dfloat32_type_node;
    1250         5503 :     else if ((flags & CPP_N_FLOATNX) != 0)
    1251           81 :       type = dfloat64x_type_node;
    1252              :     else
    1253         5422 :       type = dfloat64_type_node;
    1254              :   else
    1255      5006557 :     if (flags & CPP_N_WIDTH_MD)
    1256              :       {
    1257       202694 :         char suffix;
    1258       202694 :         machine_mode mode;
    1259              : 
    1260       202694 :         if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W)
    1261              :           suffix = 'w';
    1262              :         else
    1263       202657 :           suffix = 'q';
    1264              : 
    1265       202694 :         mode = targetm.c.mode_for_suffix (suffix);
    1266       202694 :         if (mode == VOIDmode)
    1267              :           {
    1268            0 :             error ("unsupported non-standard suffix on floating constant");
    1269              : 
    1270            0 :             return error_mark_node;
    1271              :           }
    1272              :         else
    1273       202694 :           pedwarn (input_location, OPT_Wpedantic, "non-standard suffix on floating constant");
    1274              : 
    1275       202694 :         type = c_common_type_for_mode (mode, 0);
    1276              :         /* For Q suffix, prefer float128t_type_node (__float128) type
    1277              :            over float128_type_node (_Float128) type if they are distinct.  */
    1278       202694 :         if (type == float128_type_node && float128t_type_node)
    1279       202694 :           type = float128t_type_node;
    1280       202694 :         gcc_assert (type);
    1281              :       }
    1282      4803863 :     else if ((flags & (CPP_N_FLOATN | CPP_N_FLOATNX)) != 0)
    1283              :       {
    1284       476225 :         unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
    1285       476225 :         bool extended = (flags & CPP_N_FLOATNX) != 0;
    1286       476225 :         type = NULL_TREE;
    1287      1159136 :         for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    1288      1159136 :           if (floatn_nx_types[i].n == (int) n
    1289       479003 :               && floatn_nx_types[i].extended == extended)
    1290              :             {
    1291       476225 :               type = FLOATN_NX_TYPE_NODE (i);
    1292       476225 :               break;
    1293              :             }
    1294       476225 :         if (type == NULL_TREE)
    1295              :           {
    1296            0 :             error ("unsupported non-standard suffix on floating constant");
    1297            0 :             return error_mark_node;
    1298              :           }
    1299       476225 :         else if (!c_dialect_cxx ())
    1300              :           {
    1301        94778 :             if (warn_c11_c23_compat > 0)
    1302              :               {
    1303           12 :                 if (pedantic && !flag_isoc23)
    1304            0 :                   pedwarn (input_location, OPT_Wc11_c23_compat,
    1305              :                            "non-standard suffix on floating constant "
    1306              :                            "before C23");
    1307              :                 else
    1308           12 :                   warning (OPT_Wc11_c23_compat,
    1309              :                            "non-standard suffix on floating constant "
    1310              :                            "before C23");
    1311              :               }
    1312        94766 :             else if (warn_c11_c23_compat != 0 && pedantic && !flag_isoc23)
    1313           40 :               pedwarn (input_location, OPT_Wpedantic,
    1314              :                        "non-standard suffix on floating constant "
    1315              :                        "before C23");
    1316              :           }
    1317       381447 :         else if (!extended)
    1318              :           {
    1319       381273 :             if (cxx_dialect < cxx23 && pedantic)
    1320         3992 :               pedwarn (input_location, OPT_Wc__23_extensions,
    1321              :                        "%<f%d%> or %<F%d%> suffix on floating constant only "
    1322              :                        "available with %<-std=c++23%> or %<-std=gnu++23%>",
    1323              :                        n, n);
    1324              :           }
    1325              :         else
    1326          174 :           pedwarn (input_location, OPT_Wpedantic,
    1327              :                    "non-standard suffix on floating constant");
    1328              :       }
    1329      4327638 :     else if ((flags & CPP_N_BFLOAT16) != 0)
    1330              :       {
    1331       103609 :         type = bfloat16_type_node;
    1332       103609 :         if (type == NULL_TREE)
    1333              :           {
    1334            0 :             error ("unsupported non-standard suffix on floating constant");
    1335            0 :             return error_mark_node;
    1336              :           }
    1337       103609 :         if (!c_dialect_cxx ())
    1338          916 :           pedwarn (input_location, OPT_Wpedantic,
    1339              :                    "non-standard suffix on floating constant");
    1340       102693 :         else if (cxx_dialect < cxx23 && pedantic)
    1341         2492 :           pedwarn (input_location, OPT_Wc__23_extensions,
    1342              :                    "%<bf16%> or %<BF16%> suffix on floating constant only "
    1343              :                    "available with %<-std=c++23%> or %<-std=gnu++23%>");
    1344              :       }
    1345      4224029 :     else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1346      1194151 :       type = long_double_type_node;
    1347      3029878 :     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
    1348      2593623 :              || flag_single_precision_constant)
    1349       436448 :       type = float_type_node;
    1350              :     else
    1351      2593430 :       type = double_type_node;
    1352              : 
    1353      5022666 :   const_type = excess_precision_type (type);
    1354      5022666 :   if (!const_type)
    1355      4869037 :     const_type = type;
    1356              : 
    1357              :   /* Copy the constant to a nul-terminated buffer.  If the constant
    1358              :      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
    1359              :      can't handle them.  */
    1360      5022666 :   copylen = token->val.str.len;
    1361      5022666 :   if (flags & CPP_N_USERDEF)
    1362        31759 :     copylen -= strlen (suffix);
    1363      4990907 :   else if (flags & CPP_N_DFLOAT)
    1364              :     {
    1365        16109 :       if (ISDIGIT (token->val.str.text[copylen - 1]))
    1366          146 :         copylen -= (flags & CPP_N_LARGE) ? 4 : 3;
    1367        16026 :       else if ((flags & CPP_N_FLOATNX) != 0)
    1368           81 :         copylen -= 4;
    1369              :       else
    1370        15945 :         copylen -= 2;
    1371              :     }
    1372              :   else
    1373              :     {
    1374      4974798 :       if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
    1375              :         /* Must be an F or L or machine defined suffix.  */
    1376      2381175 :         copylen--;
    1377      4974798 :       if (flags & CPP_N_IMAGINARY)
    1378              :         /* I or J suffix.  */
    1379        51274 :         copylen--;
    1380      4974798 :       if (flags & CPP_N_FLOATNX)
    1381         2778 :         copylen--;
    1382      4974798 :       if (flags & (CPP_N_FLOATN | CPP_N_FLOATNX))
    1383              :         {
    1384       476225 :           unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
    1385      1540960 :           while (n > 0)
    1386              :             {
    1387      1064735 :               copylen--;
    1388      1064735 :               n /= 10;
    1389              :             }
    1390              :         }
    1391              :     }
    1392              : 
    1393      5022666 :   copy = (char *) alloca (copylen + 1);
    1394      5022666 :   if (c_dialect_cxx () ? cxx_dialect > cxx11 : flag_isoc23)
    1395              :     {
    1396              :       size_t maxlen = 0;
    1397     68123659 :       for (size_t i = 0; i < copylen; ++i)
    1398     63298229 :         if (token->val.str.text[i] != '\'')
    1399     63298173 :           copy[maxlen++] = token->val.str.text[i];
    1400      4825430 :       copy[maxlen] = '\0';
    1401              :     }
    1402              :   else
    1403              :     {
    1404       197236 :       memcpy (copy, token->val.str.text, copylen);
    1405       197236 :       copy[copylen] = '\0';
    1406              :     }
    1407              : 
    1408      5022666 :   real_from_string3 (&real, copy, TYPE_MODE (const_type));
    1409      5022666 :   if (const_type != type)
    1410              :     /* Diagnosing if the result of converting the value with excess
    1411              :        precision to the semantic type would overflow (with associated
    1412              :        double rounding) is more appropriate than diagnosing if the
    1413              :        result of converting the string directly to the semantic type
    1414              :        would overflow.  */
    1415       153629 :     real_convert (&real_trunc, TYPE_MODE (type), &real);
    1416              : 
    1417              :   /* Both C and C++ require a diagnostic for a floating constant
    1418              :      outside the range of representable values of its type.  Since we
    1419              :      have __builtin_inf* to produce an infinity, this is now a
    1420              :      mandatory pedwarn if the target does not support infinities.  */
    1421      5022666 :   if (REAL_VALUE_ISINF (real)
    1422      5022666 :       || (const_type != type && REAL_VALUE_ISINF (real_trunc)))
    1423              :     {
    1424           58 :       *overflow = OT_OVERFLOW;
    1425           58 :       if (!(flags & CPP_N_USERDEF))
    1426              :         {
    1427          188 :           if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
    1428            0 :             pedwarn (input_location, 0,
    1429              :                      "floating constant exceeds range of %qT", type);
    1430              :           else
    1431           49 :             warning (OPT_Woverflow,
    1432              :                      "floating constant exceeds range of %qT", type);
    1433              :         }
    1434              :     }
    1435              :   /* We also give a warning if the value underflows.  */
    1436      5022608 :   else if (real_equal (&real, &dconst0)
    1437      5022608 :            || (const_type != type
    1438        68754 :                && real_equal (&real_trunc, &dconst0)))
    1439              :     {
    1440      1224757 :       REAL_VALUE_TYPE realvoidmode;
    1441      1224757 :       int oflow = real_from_string (&realvoidmode, copy);
    1442      1224757 :       *overflow = (oflow == 0 ? OT_NONE
    1443           21 :                               : (oflow < 0 ? OT_UNDERFLOW : OT_OVERFLOW));
    1444      1224757 :       if (!(flags & CPP_N_USERDEF))
    1445              :         {
    1446      1193236 :           if (oflow < 0 || !real_equal (&realvoidmode, &dconst0))
    1447           30 :             warning (OPT_Woverflow, "floating constant truncated to zero");
    1448              :         }
    1449              :     }
    1450              : 
    1451              :   /* Create a node with determined type and value.  */
    1452      5022666 :   value = build_real (const_type, real);
    1453      5022666 :   if (flags & CPP_N_IMAGINARY)
    1454              :     {
    1455        51274 :       value = build_complex (NULL_TREE,
    1456              :                              fold_convert (const_type,
    1457              :                                            integer_zero_node), value);
    1458        51274 :       if (type != const_type)
    1459              :         {
    1460           58 :           const_type = TREE_TYPE (value);
    1461           58 :           type = build_complex_type (type);
    1462              :         }
    1463              :     }
    1464              : 
    1465      5022666 :   if (type != const_type)
    1466       153629 :     value = build1_loc (token->src_loc, EXCESS_PRECISION_EXPR, type, value);
    1467              : 
    1468              :   return value;
    1469              : }
    1470              : 
    1471              : /* Interpret TOKEN, a fixed-point number with FLAGS as classified
    1472              :    by cpplib.  */
    1473              : 
    1474              : static tree
    1475           54 : interpret_fixed (const cpp_token *token, unsigned int flags)
    1476              : {
    1477           54 :   tree type;
    1478           54 :   tree value;
    1479           54 :   FIXED_VALUE_TYPE fixed;
    1480           54 :   char *copy;
    1481           54 :   size_t copylen;
    1482              : 
    1483           54 :   copylen = token->val.str.len;
    1484              : 
    1485           54 :   if (flags & CPP_N_FRACT) /* _Fract.  */
    1486              :     {
    1487           36 :       if (flags & CPP_N_UNSIGNED) /* Unsigned _Fract.  */
    1488              :         {
    1489            0 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1490              :             {
    1491            0 :               type = unsigned_long_long_fract_type_node;
    1492            0 :               copylen -= 4;
    1493              :             }
    1494            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1495              :             {
    1496            0 :               type = unsigned_long_fract_type_node;
    1497            0 :               copylen -= 3;
    1498              :             }
    1499            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1500              :             {
    1501            0 :               type = unsigned_short_fract_type_node;
    1502            0 :               copylen -= 3;
    1503              :             }
    1504              :           else
    1505              :             {
    1506            0 :               type = unsigned_fract_type_node;
    1507            0 :               copylen -= 2;
    1508              :             }
    1509              :         }
    1510              :       else /* Signed _Fract.  */
    1511              :         {
    1512           36 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1513              :             {
    1514            0 :               type = long_long_fract_type_node;
    1515            0 :               copylen -= 3;
    1516              :             }
    1517           36 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1518              :             {
    1519            0 :               type = long_fract_type_node;
    1520            0 :               copylen -= 2;
    1521              :             }
    1522           36 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1523              :             {
    1524            0 :               type = short_fract_type_node;
    1525            0 :               copylen -= 2;
    1526              :             }
    1527              :           else
    1528              :             {
    1529           36 :               type = fract_type_node;
    1530           36 :               copylen --;
    1531              :             }
    1532              :           }
    1533              :     }
    1534              :   else /* _Accum.  */
    1535              :     {
    1536           18 :       if (flags & CPP_N_UNSIGNED) /* Unsigned _Accum.  */
    1537              :         {
    1538            0 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1539              :             {
    1540            0 :               type = unsigned_long_long_accum_type_node;
    1541            0 :               copylen -= 4;
    1542              :             }
    1543            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1544              :             {
    1545            0 :               type = unsigned_long_accum_type_node;
    1546            0 :               copylen -= 3;
    1547              :             }
    1548            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1549              :             {
    1550            0 :               type = unsigned_short_accum_type_node;
    1551            0 :               copylen -= 3;
    1552              :              }
    1553              :           else
    1554              :             {
    1555            0 :               type = unsigned_accum_type_node;
    1556            0 :               copylen -= 2;
    1557              :             }
    1558              :         }
    1559              :       else /* Signed _Accum.  */
    1560              :         {
    1561           18 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1562              :             {
    1563            0 :               type = long_long_accum_type_node;
    1564            0 :               copylen -= 3;
    1565              :             }
    1566           18 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1567              :             {
    1568            0 :               type = long_accum_type_node;
    1569            0 :               copylen -= 2;
    1570              :             }
    1571           18 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1572              :             {
    1573            0 :               type = short_accum_type_node;
    1574            0 :               copylen -= 2;
    1575              :             }
    1576              :           else
    1577              :             {
    1578           18 :               type = accum_type_node;
    1579           18 :               copylen --;
    1580              :             }
    1581              :         }
    1582              :     }
    1583              : 
    1584           54 :   copy = (char *) alloca (copylen + 1);
    1585           54 :   memcpy (copy, token->val.str.text, copylen);
    1586           54 :   copy[copylen] = '\0';
    1587              : 
    1588           54 :   fixed_from_string (&fixed, copy, SCALAR_TYPE_MODE (type));
    1589              : 
    1590              :   /* Create a node with determined type and value.  */
    1591           54 :   value = build_fixed (type, fixed);
    1592              : 
    1593           54 :   return value;
    1594              : }
    1595              : 
    1596              : /* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
    1597              :    UTF8STRING tokens into a tree, performing string constant
    1598              :    concatenation.  TOK is the first of these.  VALP is the location to
    1599              :    write the string into.  OBJC_STRING indicates whether an '@' token
    1600              :    preceded the incoming token (in that case, the strings can either
    1601              :    be ObjC strings, preceded by a single '@', or normal strings, not
    1602              :    preceded by '@'.  The result will be a CPP_OBJC_STRING).  Returns
    1603              :    the CPP token type of the result (CPP_STRING, CPP_WSTRING,
    1604              :    CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
    1605              : 
    1606              :    This is unfortunately more work than it should be.  If any of the
    1607              :    strings in the series has an L prefix, the result is a wide string
    1608              :    (6.4.5p4).  Whether or not the result is a wide string affects the
    1609              :    meaning of octal and hexadecimal escapes (6.4.4.4p6,9).  But escape
    1610              :    sequences do not continue across the boundary between two strings in
    1611              :    a series (6.4.5p7), so we must not lose the boundaries.  Therefore
    1612              :    cpp_interpret_string takes a vector of cpp_string structures, which
    1613              :    we must arrange to provide.  */
    1614              : 
    1615              : static enum cpp_ttype
    1616           18 : lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
    1617              : {
    1618           18 :   tree value;
    1619           18 :   size_t concats = 0;
    1620           18 :   struct obstack str_ob;
    1621           18 :   struct obstack loc_ob;
    1622           18 :   cpp_string istr;
    1623           18 :   enum cpp_ttype type = tok->type;
    1624              : 
    1625              :   /* Try to avoid the overhead of creating and destroying an obstack
    1626              :      for the common case of just one string.  */
    1627           18 :   cpp_string str = tok->val.str;
    1628           18 :   location_t init_loc = tok->src_loc;
    1629           18 :   cpp_string *strs = &str;
    1630           18 :   location_t *locs = NULL;
    1631              : 
    1632              :   /* objc_at_sign_was_seen is only used when doing Objective-C string
    1633              :      concatenation.  It is 'true' if we have seen an '@' before the
    1634              :      current string, and 'false' if not.  We must see exactly one or
    1635              :      zero '@' before each string.  */
    1636           18 :   bool objc_at_sign_was_seen = false;
    1637              : 
    1638           18 :  retry:
    1639           18 :   tok = get_token (parse_in);
    1640           18 :   switch (tok->type)
    1641              :     {
    1642            0 :     case CPP_PADDING:
    1643            0 :       goto retry;
    1644            0 :     case CPP_ATSIGN:
    1645            0 :       if (objc_string)
    1646              :         {
    1647            0 :           if (objc_at_sign_was_seen)
    1648            0 :             error ("repeated %<@%> before Objective-C string");
    1649              : 
    1650            0 :           objc_at_sign_was_seen = true;
    1651            0 :           goto retry;
    1652              :         }
    1653              :       /* FALLTHROUGH */
    1654              : 
    1655           18 :     default:
    1656           18 :       break;
    1657              : 
    1658            0 :     case CPP_WSTRING:
    1659            0 :     case CPP_STRING16:
    1660            0 :     case CPP_STRING32:
    1661            0 :     case CPP_UTF8STRING:
    1662            0 :       if (type != tok->type)
    1663              :         {
    1664            0 :           if (type == CPP_STRING)
    1665            0 :             type = tok->type;
    1666              :           else
    1667            0 :             error ("unsupported non-standard concatenation of string literals");
    1668              :         }
    1669              :       /* FALLTHROUGH */
    1670              : 
    1671            0 :     case CPP_STRING:
    1672            0 :       if (!concats)
    1673              :         {
    1674            0 :           gcc_obstack_init (&str_ob);
    1675            0 :           gcc_obstack_init (&loc_ob);
    1676            0 :           obstack_grow (&str_ob, &str, sizeof (cpp_string));
    1677            0 :           obstack_grow (&loc_ob, &init_loc, sizeof (location_t));
    1678              :         }
    1679              : 
    1680            0 :       concats++;
    1681            0 :       obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
    1682            0 :       obstack_grow (&loc_ob, &tok->src_loc, sizeof (location_t));
    1683              : 
    1684            0 :       if (objc_string)
    1685            0 :         objc_at_sign_was_seen = false;
    1686            0 :       goto retry;
    1687              :     }
    1688              : 
    1689              :   /* It is an error if we saw a '@' with no following string.  */
    1690           18 :   if (objc_at_sign_was_seen)
    1691            0 :     error ("stray %<@%> in program");
    1692              : 
    1693              :   /* We have read one more token than we want.  */
    1694           18 :   _cpp_backup_tokens (parse_in, 1);
    1695           18 :   if (concats)
    1696              :     {
    1697            0 :       strs = XOBFINISH (&str_ob, cpp_string *);
    1698            0 :       locs = XOBFINISH (&loc_ob, location_t *);
    1699              :     }
    1700              : 
    1701           18 :   if (concats && !objc_string && !in_system_header_at (input_location))
    1702            0 :     warning (OPT_Wtraditional,
    1703              :              "traditional C rejects string constant concatenation");
    1704              : 
    1705           18 :   if ((translate
    1706           18 :        ? cpp_interpret_string : cpp_interpret_string_notranslate)
    1707           18 :       (parse_in, strs, concats + 1, &istr, type))
    1708              :     {
    1709           18 :       value = build_string (istr.len, (const char *) istr.text);
    1710           18 :       free (const_cast<unsigned char *> (istr.text));
    1711           18 :       if (concats)
    1712              :         {
    1713            0 :           gcc_assert (locs);
    1714            0 :           gcc_assert (g_string_concat_db);
    1715            0 :           g_string_concat_db->record_string_concatenation (concats + 1, locs);
    1716              :         }
    1717              :     }
    1718              :   else
    1719              :     {
    1720              :       /* Callers cannot generally handle error_mark_node in this context,
    1721              :          so return the empty string instead.  cpp_interpret_string has
    1722              :          issued an error.  */
    1723            0 :       switch (type)
    1724              :         {
    1725            0 :         default:
    1726            0 :         case CPP_STRING:
    1727            0 :         case CPP_UTF8STRING:
    1728            0 :           if (type == CPP_UTF8STRING && flag_char8_t)
    1729              :             {
    1730            0 :               value = build_string (TYPE_PRECISION (char8_type_node)
    1731            0 :                                     / TYPE_PRECISION (char_type_node),
    1732              :                                     "");  /* char8_t is 8 bits */
    1733              :             }
    1734              :           else
    1735            0 :             value = build_string (1, "");
    1736              :           break;
    1737            0 :         case CPP_STRING16:
    1738            0 :           value = build_string (TYPE_PRECISION (char16_type_node)
    1739            0 :                                 / TYPE_PRECISION (char_type_node),
    1740              :                                 "\0");  /* char16_t is 16 bits */
    1741            0 :           break;
    1742            0 :         case CPP_STRING32:
    1743            0 :           value = build_string (TYPE_PRECISION (char32_type_node)
    1744            0 :                                 / TYPE_PRECISION (char_type_node),
    1745              :                                 "\0\0\0");  /* char32_t is 32 bits */
    1746            0 :           break;
    1747            0 :         case CPP_WSTRING:
    1748            0 :           value = build_string (TYPE_PRECISION (wchar_type_node)
    1749            0 :                                 / TYPE_PRECISION (char_type_node),
    1750              :                                 "\0\0\0");  /* widest supported wchar_t
    1751              :                                                is 32 bits */
    1752            0 :           break;
    1753              :         }
    1754              :     }
    1755              : 
    1756           18 :   switch (type)
    1757              :     {
    1758           18 :     default:
    1759           18 :     case CPP_STRING:
    1760           18 :       TREE_TYPE (value) = char_array_type_node;
    1761           18 :       break;
    1762            0 :     case CPP_UTF8STRING:
    1763            0 :       if (flag_char8_t)
    1764            0 :         TREE_TYPE (value) = char8_array_type_node;
    1765              :       else
    1766            0 :         TREE_TYPE (value) = char_array_type_node;
    1767              :       break;
    1768            0 :     case CPP_STRING16:
    1769            0 :       TREE_TYPE (value) = char16_array_type_node;
    1770            0 :       break;
    1771            0 :     case CPP_STRING32:
    1772            0 :       TREE_TYPE (value) = char32_array_type_node;
    1773            0 :       break;
    1774            0 :     case CPP_WSTRING:
    1775            0 :       TREE_TYPE (value) = wchar_array_type_node;
    1776              :     }
    1777           18 :   *valp = fix_string_type (value);
    1778              : 
    1779           18 :   if (concats)
    1780              :     {
    1781            0 :       obstack_free (&str_ob, 0);
    1782            0 :       obstack_free (&loc_ob, 0);
    1783              :     }
    1784              : 
    1785           18 :   return objc_string ? CPP_OBJC_STRING : type;
    1786              : }
    1787              : 
    1788              : /* Converts a (possibly wide) character constant token into a tree.  */
    1789              : static tree
    1790      9280751 : lex_charconst (const cpp_token *token)
    1791              : {
    1792      9280751 :   cppchar_t result;
    1793      9280751 :   tree type, value;
    1794      9280751 :   unsigned int chars_seen;
    1795      9280751 :   int unsignedp = 0;
    1796              : 
    1797      9280751 :   result = cpp_interpret_charconst (parse_in, token,
    1798              :                                     &chars_seen, &unsignedp);
    1799              : 
    1800      9280751 :   if (token->type == CPP_WCHAR)
    1801       545861 :     type = wchar_type_node;
    1802      8734890 :   else if (token->type == CPP_CHAR32)
    1803        19664 :     type = char32_type_node;
    1804      8715226 :   else if (token->type == CPP_CHAR16)
    1805        19298 :     type = char16_type_node;
    1806      8695928 :   else if (token->type == CPP_UTF8CHAR)
    1807              :     {
    1808          210 :       if (flag_char8_t)
    1809          176 :         type = char8_type_node;
    1810              :       else
    1811           34 :         type = char_type_node;
    1812              :     }
    1813              :   /* In C, a character constant has type 'int'.
    1814              :      In C++ 'char', but multi-char charconsts have type 'int'.  */
    1815      8695718 :   else if (!c_dialect_cxx () || chars_seen > 1)
    1816       118197 :     type = integer_type_node;
    1817              :   else
    1818      8577521 :     type = char_type_node;
    1819              : 
    1820              :   /* Cast to cppchar_signed_t to get correct sign-extension of RESULT
    1821              :      before possibly widening to HOST_WIDE_INT for build_int_cst.  */
    1822      9280751 :   if (unsignedp || (cppchar_signed_t) result >= 0)
    1823      9278142 :     value = build_int_cst (type, result);
    1824              :   else
    1825         2609 :     value = build_int_cst (type, (cppchar_signed_t) result);
    1826              : 
    1827      9280751 :   return value;
    1828              : }
    1829              : 
    1830              : /* Helper function for c_parser_peek_conflict_marker
    1831              :    and cp_lexer_peek_conflict_marker.
    1832              :    Given a possible conflict marker token of kind TOK1_KIND
    1833              :    consisting of a pair of characters, get the token kind for the
    1834              :    standalone final character.  */
    1835              : 
    1836              : enum cpp_ttype
    1837          100 : conflict_marker_get_final_tok_kind (enum cpp_ttype tok1_kind)
    1838              : {
    1839          100 :   switch (tok1_kind)
    1840              :     {
    1841            0 :     default: gcc_unreachable ();
    1842              :     case CPP_LSHIFT:
    1843              :       /* "<<" and '<' */
    1844              :       return CPP_LESS;
    1845              : 
    1846           31 :     case CPP_EQ_EQ:
    1847              :       /* "==" and '=' */
    1848           31 :       return CPP_EQ;
    1849              : 
    1850           35 :     case CPP_RSHIFT:
    1851              :       /* ">>" and '>' */
    1852           35 :       return CPP_GREATER;
    1853              :     }
    1854              : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.