LCOV - code coverage report
Current view: top level - gcc/c-family - c-lex.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.1 % 921 738
Test Date: 2026-02-28 14:20:25 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       201608 : init_c_lex (void)
      64              : {
      65       201608 :   struct c_fileinfo *toplevel;
      66              : 
      67              :   /* The get_fileinfo data structure must be initialized before
      68              :      cpp_read_main_file is called.  */
      69       201608 :   toplevel = get_fileinfo ("<top level>");
      70       201608 :   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       201608 :   struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
      78              : 
      79       201608 :   cb->line_change = cb_line_change;
      80       201608 :   cb->ident = cb_ident;
      81       201608 :   cb->def_pragma = cb_def_pragma;
      82       201608 :   cb->valid_pch = c_common_valid_pch;
      83       201608 :   cb->read_pch = c_common_read_pch;
      84       201608 :   cb->has_attribute = c_common_has_attribute;
      85       201608 :   cb->has_builtin = c_common_has_builtin;
      86       201608 :   cb->has_feature = c_common_has_feature;
      87       201608 :   cb->get_source_date_epoch = cb_get_source_date_epoch;
      88       201608 :   cb->get_suggestion = cb_get_suggestion;
      89       201608 :   cb->remap_filename = remap_macro_filename;
      90              : 
      91              :   /* Set the debug callbacks if we can use them.  */
      92       201608 :   if ((debug_info_level == DINFO_LEVEL_VERBOSE
      93          521 :        && dwarf_debuginfo_p ())
      94       201608 :       || flag_dump_go_spec != NULL)
      95              :     {
      96          525 :       cb->define = cb_define;
      97          525 :       cb->undef = cb_undef;
      98              :     }
      99       201608 : }
     100              : 
     101              : struct c_fileinfo *
     102    329290087 : get_fileinfo (const char *name)
     103              : {
     104    329290087 :   splay_tree_node n;
     105    329290087 :   struct c_fileinfo *fi;
     106              : 
     107    329290087 :   if (!file_info_tree)
     108       202941 :     file_info_tree = splay_tree_new (splay_tree_compare_strings,
     109              :                                      0,
     110              :                                      splay_tree_delete_pointers);
     111              : 
     112    329290087 :   n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
     113    329290087 :   if (n)
     114    325574689 :     return (struct c_fileinfo *) n->value;
     115              : 
     116      3715398 :   fi = XNEW (struct c_fileinfo);
     117      3715398 :   fi->time = 0;
     118      3715398 :   fi->interface_only = 0;
     119      3715398 :   fi->interface_unknown = 1;
     120      3715398 :   splay_tree_insert (file_info_tree, (splay_tree_key) name,
     121              :                      (splay_tree_value) fi);
     122      3715398 :   return fi;
     123              : }
     124              : 
     125              : static void
     126     19696991 : 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     19696991 :   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     19696991 : }
     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   1646209976 : cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
     186              :                 int parsing_args)
     187              : {
     188   1646209976 :   if (token->type != CPP_EOF && !parsing_args)
     189   1639346004 :     input_location = token->src_loc;
     190   1646209976 : }
     191              : 
     192              : void
     193     19898175 : fe_file_change (const line_map_ordinary *new_map)
     194              : {
     195     19898175 :   if (new_map == NULL)
     196              :     return;
     197              : 
     198     19696991 :   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      9618023 :       if (!MAIN_FILE_P (new_map))
     203              :         {
     204      9416415 :           location_t included_at = linemap_included_from (new_map);
     205      9416415 :           int line = 0;
     206      9416415 :           if (included_at > BUILTINS_LOCATION)
     207      9416415 :             line = SOURCE_LINE (new_map - 1, included_at);
     208              : 
     209      9416415 :           input_location = new_map->start_location;
     210      9416415 :           (*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     10078968 :   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      9416412 :       input_location = new_map->start_location;
     233              : 
     234      9416412 :       (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
     235              :     }
     236              : 
     237     19696991 :   update_header_times (LINEMAP_FILE (new_map));
     238     19696991 :   input_location = new_map->start_location;
     239              : }
     240              : 
     241              : static void
     242         1448 : 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         1448 :   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         1448 : }
     276              : 
     277              : /* #define callback for DWARF and DWARF2 debug info.  */
     278              : static void
     279       257252 : cb_define (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
     280              : {
     281       257252 :   const struct line_map *map = linemap_lookup (line_table, loc);
     282       257252 :   (*debug_hooks->define) (SOURCE_LINE (linemap_check_ordinary (map), loc),
     283       257252 :                           (const char *) cpp_macro_definition (pfile, node));
     284       257252 : }
     285              : 
     286              : /* #undef callback for DWARF and DWARF2 debug info.  */
     287              : static void
     288         1433 : cb_undef (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
     289              : {
     290         1433 :   if (lang_hooks.preprocess_undef)
     291            0 :     lang_hooks.preprocess_undef (pfile, loc, node);
     292              : 
     293         1433 :   const struct line_map *map = linemap_lookup (line_table, loc);
     294         1433 :   (*debug_hooks->undef) (SOURCE_LINE (linemap_check_ordinary (map), loc),
     295         1433 :                          (const char *) NODE_NAME (node));
     296         1433 : }
     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  12581886530 : get_token (cpp_reader *pfile, location_t *loc = nullptr)
     305              : {
     306  12581886530 :   if (flag_preprocess_only)
     307              :     {
     308        76507 :       location_t x;
     309        76507 :       if (!loc)
     310            0 :         loc = &x;
     311        76507 :       const auto tok = cpp_get_token_with_location (pfile, loc);
     312        76507 :       c_pp_stream_token (pfile, tok, *loc);
     313        76507 :       return tok;
     314              :     }
     315              :   else
     316  12581810023 :     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     22193112 : get_token_no_padding (cpp_reader *pfile)
     326              : {
     327     22193408 :   for (;;)
     328              :     {
     329     22193408 :       const cpp_token *ret = cpp_peek_token (pfile, 0);
     330     22193408 :       if (ret->type == CPP_EOF)
     331              :         return ret;
     332     22193388 :       ret = cpp_get_token (pfile);
     333     22193388 :       if (ret->type != CPP_PADDING)
     334              :         return ret;
     335              :     }
     336              : }
     337              : 
     338              : /* Callback for has_attribute.  */
     339              : int
     340       786411 : c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
     341              : {
     342       786411 :   int result = 0;
     343       786411 :   tree attr_name = NULL_TREE;
     344       786411 :   const cpp_token *token;
     345              : 
     346       786411 :   token = get_token_no_padding (pfile);
     347       786411 :   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       786409 :   token = get_token_no_padding (pfile);
     354       786409 :   if (token->type == CPP_NAME)
     355              :     {
     356       786405 :       attr_name = get_identifier ((const char *)
     357              :                                   cpp_token_as_text (pfile, token));
     358       786405 :       attr_name = canonicalize_attr_name (attr_name);
     359       786405 :       bool have_scope = false;
     360       786405 :       int idx = 0;
     361       786465 :       const cpp_token *nxt_token;
     362       786465 :       do
     363       786465 :         nxt_token = cpp_peek_token (pfile, idx++);
     364       786465 :       while (nxt_token->type == CPP_PADDING);
     365       786405 :       if (!c_dialect_cxx ()
     366       397464 :           && 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       786405 :       if (nxt_token->type == CPP_SCOPE || have_scope)
     386              :         {
     387          808 :           have_scope = true;
     388          808 :           get_token_no_padding (pfile); // Eat scope.
     389          808 :           nxt_token = get_token_no_padding (pfile);
     390          808 :           if (nxt_token->type == CPP_NAME)
     391              :             {
     392          807 :               tree attr_ns = attr_name;
     393          807 :               tree attr_id
     394          807 :                 = get_identifier ((const char *)
     395              :                                   cpp_token_as_text (pfile, nxt_token));
     396          807 :               attr_id = canonicalize_attr_name (attr_id);
     397              :               /* OpenMP attributes need special handling.  */
     398          711 :               if ((flag_openmp || flag_openmp_simd)
     399          192 :                   && is_attribute_p ("omp", attr_ns)
     400          999 :                   && (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          663 :               if (result)
     405              :                 attr_name = NULL_TREE;
     406              :               else
     407          663 :                 attr_name = build_tree_list (attr_ns, attr_id);
     408              :             }
     409              :           else
     410              :             {
     411            1 :               cpp_error (pfile, CPP_DL_ERROR,
     412              :                          "attribute identifier required after scope");
     413            1 :               attr_name = NULL_TREE;
     414              :             }
     415              :         }
     416              :       else
     417              :         {
     418              :           /* Some standard attributes need special handling.  */
     419       785597 :           if (c_dialect_cxx ())
     420              :             {
     421       388214 :               if (is_attribute_p ("noreturn", attr_name))
     422              :                 result = 200809;
     423       388165 :               else if (is_attribute_p ("deprecated", attr_name))
     424              :                 result = 201309;
     425       366652 :               else if (is_attribute_p ("maybe_unused", attr_name)
     426       366652 :                        || is_attribute_p ("fallthrough", attr_name))
     427              :                 result = 201603;
     428       366187 :               else if (is_attribute_p ("no_unique_address", attr_name)
     429       354213 :                        || is_attribute_p ("likely", attr_name)
     430       720394 :                        || is_attribute_p ("unlikely", attr_name))
     431              :                 result = 201803;
     432       354201 :               else if (is_attribute_p ("nodiscard", attr_name))
     433              :                 result = 201907;
     434       354192 :               else if (is_attribute_p ("assume", attr_name))
     435              :                 result = 202207;
     436       343832 :               else if (is_attribute_p ("init_priority", attr_name))
     437              :                 {
     438              :                   /* The (non-standard) init_priority attribute is always
     439              :                      included in the attribute table, but we don't want to
     440              :                      advertise the attribute unless the target actually
     441              :                      supports init priorities.  */
     442              :                   result = SUPPORTS_INIT_PRIORITY ? 1 : 0;
     443              :                   attr_name = NULL_TREE;
     444              :                 }
     445              :             }
     446              :           else
     447              :             {
     448       397383 :               if (is_attribute_p ("deprecated", attr_name)
     449       372562 :                   || is_attribute_p ("fallthrough", attr_name)
     450       372408 :                   || is_attribute_p ("maybe_unused", attr_name)
     451       372406 :                   || is_attribute_p ("nodiscard", attr_name)
     452       372404 :                   || is_attribute_p ("noreturn", attr_name)
     453       372390 :                   || is_attribute_p ("_Noreturn", attr_name)
     454       372388 :                   || is_attribute_p ("reproducible", attr_name)
     455       769769 :                   || is_attribute_p ("unsequenced", attr_name))
     456              :                 result = 202311;
     457              :             }
     458              :           if (result)
     459              :             attr_name = NULL_TREE;
     460              :         }
     461       707073 :       if (attr_name && (have_scope || !std_syntax))
     462              :         {
     463       707068 :           init_attributes ();
     464       707068 :           const struct attribute_spec *attr = lookup_attribute_spec (attr_name);
     465       707068 :           if (attr)
     466       716387 :             result = 1;
     467              :         }
     468              :     }
     469              :   else
     470              :     {
     471            4 :       cpp_error (pfile, CPP_DL_ERROR,
     472              :                  "macro %<__has_attribute%> requires an identifier");
     473            4 :       return 0;
     474              :     }
     475              : 
     476       786405 :   if (get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
     477            3 :     cpp_error (pfile, CPP_DL_ERROR,
     478              :                "missing %<)%> after %<__has_attribute%>");
     479              : 
     480              :   return result;
     481              : }
     482              : 
     483              : /* Helper for __has_{builtin,feature,extension}.  */
     484              : 
     485              : static const char *
     486      6610735 : c_common_lex_availability_macro (cpp_reader *pfile, const char *builtin)
     487              : {
     488      6610735 :   const cpp_token *token = get_token_no_padding (pfile);
     489      6610735 :   if (token->type != CPP_OPEN_PAREN)
     490              :     {
     491            4 :       cpp_error (pfile, CPP_DL_ERROR,
     492              :                  "missing %<(%> after %<__has_%s%>", builtin);
     493            4 :       return 0;
     494              :     }
     495              : 
     496      6610731 :   const char *name = "";
     497      6610731 :   token = get_token_no_padding (pfile);
     498      6610731 :   if (token->type == CPP_NAME)
     499              :     {
     500      6610699 :       name = (const char *) cpp_token_as_text (pfile, token);
     501      6610699 :       token = get_token_no_padding (pfile);
     502      6610699 :       if (token->type != CPP_CLOSE_PAREN)
     503              :         {
     504           16 :           cpp_error (pfile, CPP_DL_ERROR,
     505              :                      "expected %<)%> after %qs", name);
     506           16 :           name = "";
     507              :         }
     508              :     }
     509              :   else
     510              :     {
     511           32 :       cpp_error (pfile, CPP_DL_ERROR,
     512              :                  "macro %<__has_%s%> requires an identifier", builtin);
     513           32 :       if (token->type == CPP_CLOSE_PAREN)
     514              :         return 0;
     515              :     }
     516              : 
     517              :   /* Consume tokens up to the closing parenthesis, including any nested
     518              :      pairs of parentheses, to avoid confusing redundant errors.  */
     519      6610831 :   for (unsigned nparen = 1; ; token = get_token_no_padding (pfile))
     520              :     {
     521      6610831 :       if (token->type == CPP_OPEN_PAREN)
     522           24 :         ++nparen;
     523      6610807 :       else if (token->type == CPP_CLOSE_PAREN)
     524      6610731 :         --nparen;
     525           76 :       else if (token->type == CPP_EOF)
     526              :         break;
     527      6610819 :       if (!nparen)
     528              :         break;
     529              :     }
     530              : 
     531              :   return name;
     532              : }
     533              : 
     534              : /* Callback for has_builtin.  */
     535              : 
     536              : int
     537      6485435 : c_common_has_builtin (cpp_reader *pfile)
     538              : {
     539      6485435 :   const char *name = c_common_lex_availability_macro (pfile, "builtin");
     540      6485435 :   if (!name)
     541              :     return 0;
     542              : 
     543      6485427 :   return names_builtin_p (name);
     544              : }
     545              : 
     546              : /* Callback for has_feature.  STRICT_P is true for has_feature and false
     547              :    for has_extension.  */
     548              : 
     549              : int
     550       125300 : c_common_has_feature (cpp_reader *pfile, bool strict_p)
     551              : {
     552       125300 :   const char *builtin = strict_p ? "feature" : "extension";
     553       125300 :   const char *name = c_common_lex_availability_macro (pfile, builtin);
     554       125300 :   if (!name)
     555              :     return 0;
     556              : 
     557              :   /* If -pedantic-errors is given, __has_extension is equivalent to
     558              :      __has_feature.  */
     559       125300 :   strict_p |= flag_pedantic_errors;
     560       125300 :   return has_feature_p (name, strict_p);
     561              : }
     562              : 
     563              : 
     564              : /* Read a token and return its type.  Fill *VALUE with its value, if
     565              :    applicable.  Fill *CPP_FLAGS with the token's flags, if it is
     566              :    non-NULL.  */
     567              : 
     568              : enum cpp_ttype
     569  11472956706 : c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
     570              :                   int lex_flags)
     571              : {
     572  11472956706 :   const cpp_token *tok;
     573  11472956706 :   enum cpp_ttype type;
     574  11472956706 :   unsigned char add_flags = 0;
     575  11472956706 :   enum overflow_type overflow = OT_NONE;
     576              : 
     577  11472956706 :   timevar_push (TV_CPP);
     578  12581886344 :  retry:
     579  12581886344 :   tok = get_token (parse_in, loc);
     580  12581886152 :   type = tok->type;
     581              : 
     582  12581886296 :  retry_after_at:
     583  12581886296 :   switch (type)
     584              :     {
     585   1108929296 :     case CPP_PADDING:
     586   1108929296 :       goto retry;
     587              : 
     588   5252996157 :     case CPP_NAME:
     589   5252996157 :       *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
     590   5252996157 :       break;
     591              : 
     592    192215393 :     case CPP_NUMBER:
     593    192215393 :       {
     594    192215393 :         const char *suffix = NULL;
     595    192215393 :         unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc);
     596              : 
     597    192215393 :         switch (flags & CPP_N_CATEGORY)
     598              :           {
     599          174 :           case CPP_N_INVALID:
     600              :             /* cpplib has issued an error.  */
     601          174 :             *value = error_mark_node;
     602          174 :             break;
     603              : 
     604    187461577 :           case CPP_N_INTEGER:
     605              :             /* C++ uses '0' to mark virtual functions as pure.
     606              :                Set PURE_ZERO to pass this information to the C++ parser.  */
     607    187461577 :             if (tok->val.str.len == 1 && *tok->val.str.text == '0')
     608              :               add_flags = PURE_ZERO | DECIMAL_INT;
     609    150396295 :             else if ((flags & CPP_N_INTEGER) && (flags & CPP_N_DECIMAL))
     610              :               /* -Wxor-used-as-pow is only active for LHS of ^ expressed
     611              :                  as a decimal integer. */
     612    187461577 :               add_flags = DECIMAL_INT;
     613    187461577 :             *value = interpret_integer (tok, flags, &overflow);
     614    187461577 :             break;
     615              : 
     616      4753642 :           case CPP_N_FLOATING:
     617      4753642 :             *value = interpret_float (tok, flags, suffix, &overflow);
     618      4753642 :             break;
     619              : 
     620            0 :           default:
     621            0 :             gcc_unreachable ();
     622              :           }
     623              : 
     624    192215393 :         if (flags & CPP_N_USERDEF)
     625              :           {
     626       222285 :             char *str;
     627       222285 :             tree literal;
     628       222285 :             tree suffix_id = get_identifier (suffix);
     629       222285 :             int len = tok->val.str.len - strlen (suffix);
     630              :             /* If this is going to be used as a C string to pass to a
     631              :                raw literal operator, we need to add a trailing NUL.  */
     632       444570 :             tree num_string = build_string (len + 1,
     633       222285 :                                             (const char *) tok->val.str.text);
     634       222285 :             TREE_TYPE (num_string) = char_array_type_node;
     635       222285 :             num_string = fix_string_type (num_string);
     636       222285 :             str = const_cast<char *> (TREE_STRING_POINTER (num_string));
     637       222285 :             str[len] = '\0';
     638       222285 :             literal = build_userdef_literal (suffix_id, *value, overflow,
     639              :                                              num_string);
     640       222285 :             *value = literal;
     641              :           }
     642              :       }
     643    192215393 :       break;
     644              : 
     645            3 :     case CPP_ATSIGN:
     646              :       /* An @ may give the next token special significance in Objective-C.  */
     647            3 :       if (c_dialect_objc ())
     648              :         {
     649            0 :           location_t atloc = *loc;
     650            0 :           location_t newloc;
     651              : 
     652            0 :         retry_at:
     653            0 :           tok = get_token (parse_in, &newloc);
     654            0 :           type = tok->type;
     655            0 :           switch (type)
     656              :             {
     657            0 :             case CPP_PADDING:
     658            0 :               goto retry_at;
     659              : 
     660            0 :             case CPP_STRING:
     661            0 :             case CPP_WSTRING:
     662            0 :             case CPP_STRING16:
     663            0 :             case CPP_STRING32:
     664            0 :             case CPP_UTF8STRING:
     665            0 :               type = lex_string (tok, value, true, true);
     666            0 :               break;
     667              : 
     668            0 :             case CPP_NAME:
     669            0 :               *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
     670            0 :               if (OBJC_IS_AT_KEYWORD (C_RID_CODE (*value))
     671              :                   || OBJC_IS_CXX_KEYWORD (C_RID_CODE (*value)))
     672              :                 {
     673            0 :                   type = CPP_AT_NAME;
     674              :                   /* Note the complication: if we found an OBJC_CXX
     675              :                      keyword, for example, 'class', we will be
     676              :                      returning a token of type CPP_AT_NAME and rid
     677              :                      code RID_CLASS (not RID_AT_CLASS).  The language
     678              :                      parser needs to convert that to RID_AT_CLASS.
     679              :                      However, we've now spliced the '@' together with the
     680              :                      keyword that follows; Adjust the location so that we
     681              :                      get a source range covering the composite.
     682              :                   */
     683            0 :                  *loc = make_location (atloc, atloc, newloc);
     684            0 :                   break;
     685              :                 }
     686              :               /* FALLTHROUGH */
     687              : 
     688            0 :             default:
     689              :               /* ... or not.  */
     690            0 :               error_at (atloc, "stray %<@%> in program");
     691            0 :               *loc = newloc;
     692            0 :               goto retry_after_at;
     693              :             }
     694            0 :           break;
     695              :         }
     696              : 
     697              :       /* FALLTHROUGH */
     698           23 :     case CPP_HASH:
     699           23 :     case CPP_PASTE:
     700           23 :       {
     701           23 :         unsigned char name[8];
     702              : 
     703           23 :         *cpp_spell_token (parse_in, tok, name, true) = 0;
     704              : 
     705           23 :         error_at (*loc, "stray %qs in program", name);
     706              :       }
     707              : 
     708           23 :       goto retry;
     709              : 
     710          135 :     case CPP_OTHER:
     711          135 :       {
     712          135 :         cppchar_t c = tok->val.str.text[0];
     713              : 
     714          135 :         if (c == '"' || c == '\'')
     715           25 :           error_at (*loc, "missing terminating %c character", (int) c);
     716          110 :         else if (ISGRAPH (c))
     717          102 :           error_at (*loc, "stray %qc in program", (int) c);
     718              :         else
     719              :           {
     720            8 :             rich_location rich_loc (line_table, *loc);
     721            8 :             rich_loc.set_escape_on_output (true);
     722            8 :             error_at (&rich_loc, "stray %<\\%o%> in program", (int) c);
     723            8 :           }
     724              :       }
     725          135 :       goto retry;
     726              : 
     727          110 :     case CPP_CHAR_USERDEF:
     728          110 :     case CPP_WCHAR_USERDEF:
     729          110 :     case CPP_CHAR16_USERDEF:
     730          110 :     case CPP_CHAR32_USERDEF:
     731          110 :     case CPP_UTF8CHAR_USERDEF:
     732          110 :       {
     733          110 :         tree literal;
     734          110 :         cpp_token temp_tok = *tok;
     735          110 :         const char *suffix = cpp_get_userdef_suffix (tok);
     736          110 :         temp_tok.val.str.len -= strlen (suffix);
     737          110 :         temp_tok.type = cpp_userdef_char_remove_type (type);
     738          110 :         literal = build_userdef_literal (get_identifier (suffix),
     739              :                                          lex_charconst (&temp_tok),
     740              :                                          OT_NONE, NULL_TREE);
     741          110 :         *value = literal;
     742              :       }
     743          110 :       break;
     744              : 
     745      8691096 :     case CPP_CHAR:
     746      8691096 :     case CPP_WCHAR:
     747      8691096 :     case CPP_CHAR16:
     748      8691096 :     case CPP_CHAR32:
     749      8691096 :     case CPP_UTF8CHAR:
     750      8691096 :       *value = lex_charconst (tok);
     751      8691096 :       break;
     752              : 
     753       300148 :     case CPP_STRING_USERDEF:
     754       300148 :     case CPP_WSTRING_USERDEF:
     755       300148 :     case CPP_STRING16_USERDEF:
     756       300148 :     case CPP_STRING32_USERDEF:
     757       300148 :     case CPP_UTF8STRING_USERDEF:
     758       300148 :       {
     759       300148 :         tree literal, string;
     760       300148 :         const char *suffix = cpp_get_userdef_suffix (tok);
     761       600296 :         string = build_string (tok->val.str.len - strlen (suffix),
     762       300148 :                                (const char *) tok->val.str.text);
     763       300148 :         literal = build_userdef_literal (get_identifier (suffix),
     764              :                                          string, OT_NONE, NULL_TREE);
     765       300148 :         *value = literal;
     766              :       }
     767       300148 :       break;
     768              : 
     769     53943830 :     case CPP_STRING:
     770     53943830 :     case CPP_WSTRING:
     771     53943830 :     case CPP_STRING16:
     772     53943830 :     case CPP_STRING32:
     773     53943830 :     case CPP_UTF8STRING:
     774     53943830 :       if ((lex_flags & C_LEX_STRING_NO_JOIN) == 0)
     775              :         {
     776           18 :           type = lex_string (tok, value, false,
     777              :                              (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
     778           18 :           break;
     779              :         }
     780     53943812 :       *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
     781     53943812 :       break;
     782              : 
     783      8768828 :     case CPP_PRAGMA:
     784      8768828 :       *value = build_int_cst (integer_type_node, tok->val.pragma);
     785      8768828 :       break;
     786              : 
     787          855 :     case CPP_HEADER_NAME:
     788          855 :       *value = build_string (tok->val.str.len, (const char *)tok->val.str.text);
     789          855 :       break;
     790              : 
     791          386 :     case CPP_EMBED:
     792          386 :       *value = make_node (RAW_DATA_CST);
     793          386 :       TREE_TYPE (*value) = integer_type_node;
     794          386 :       RAW_DATA_LENGTH (*value) = tok->val.str.len;
     795          386 :       if (pch_file)
     796              :         {
     797              :           /* When writing PCH headers, copy the data over, such that
     798              :              the owner is a STRING_CST.  */
     799            6 :           int off = 0;
     800            6 :           if (tok->val.str.len <= INT_MAX - 2)
     801              :             /* See below.  */
     802            6 :             off = 1;
     803           12 :           tree owner = build_string (tok->val.str.len + 2 * off,
     804            6 :                                      (const char *) tok->val.str.text - off);
     805            6 :           TREE_TYPE (owner) = build_array_type_nelts (unsigned_char_type_node,
     806            6 :                                                       tok->val.str.len);
     807            6 :           RAW_DATA_OWNER (*value) = owner;
     808            6 :           RAW_DATA_POINTER (*value) = TREE_STRING_POINTER (owner) + off;
     809              :         }
     810              :       else
     811              :         {
     812              :           /* Otherwise add another dummy RAW_DATA_CST as owner which
     813              :              indicates the data is owned by libcpp.  */
     814          380 :           RAW_DATA_POINTER (*value) = (const char *) tok->val.str.text;
     815          380 :           tree owner = make_node (RAW_DATA_CST);
     816          380 :           TREE_TYPE (owner) = integer_type_node;
     817          380 :           RAW_DATA_LENGTH (owner) = tok->val.str.len;
     818          380 :           RAW_DATA_POINTER (owner) = (const char *) tok->val.str.text;
     819          380 :           if (tok->val.str.len <= INT_MAX - 2)
     820              :             {
     821              :               /* The preprocessor surrounds at least smaller CPP_EMBEDs
     822              :                  in between CPP_NUMBER CPP_COMMA before and
     823              :                  CPP_COMMA CPP_NUMBER after, so the actual libcpp buffer
     824              :                  holds those 2 extra bytes around it.  Don't do that if
     825              :                  CPP_EMBED is at the maximum ~ 2GB size.  */
     826          380 :               RAW_DATA_LENGTH (owner) += 2;
     827          380 :               RAW_DATA_POINTER (owner)--;
     828              :             }
     829          380 :           RAW_DATA_OWNER (*value) = owner;
     830              :         }
     831              :       break;
     832              : 
     833              :       /* This token should not be visible outside cpplib.  */
     834            0 :     case CPP_MACRO_ARG:
     835            0 :       gcc_unreachable ();
     836              : 
     837              :     /* CPP_COMMENT will appear when compiling with -C.  Ignore, except
     838              :        when it is a FALLTHROUGH comment, in that case set
     839              :        PREV_FALLTHROUGH flag on the next non-comment token.  */
     840          328 :     case CPP_COMMENT:
     841          328 :       if (tok->flags & PREV_FALLTHROUGH)
     842              :         {
     843          168 :           do
     844              :             {
     845          168 :               tok = get_token (parse_in, loc);
     846          168 :               type = tok->type;
     847              :             }
     848          168 :           while (type == CPP_PADDING || type == CPP_COMMENT);
     849          144 :           add_flags |= PREV_FALLTHROUGH;
     850          144 :           goto retry_after_at;
     851              :         }
     852          184 :       goto retry;
     853              : 
     854   5956039711 :     default:
     855   5956039711 :       *value = NULL_TREE;
     856   5956039711 :       break;
     857              :     }
     858              : 
     859  11472956514 :   if (cpp_flags)
     860  11472956514 :     *cpp_flags = tok->flags | add_flags;
     861              : 
     862  11472956514 :   timevar_pop (TV_CPP);
     863              : 
     864  11472956514 :   return type;
     865              : }
     866              : 
     867              : /* Returns the narrowest C-visible unsigned type, starting with the
     868              :    minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if
     869              :    there isn't one.  */
     870              : 
     871              : static enum integer_type_kind
     872    187442253 : narrowest_unsigned_type (const widest_int &val, unsigned int flags)
     873              : {
     874    187442253 :   int itk;
     875              : 
     876    187442253 :   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
     877              :     itk = itk_unsigned_int;
     878      3630746 :   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
     879              :     itk = itk_unsigned_long;
     880              :   else
     881      1283351 :     itk = itk_unsigned_long_long;
     882              : 
     883    187674755 :   for (; itk < itk_none; itk += 2 /* skip unsigned types */)
     884              :     {
     885    187674755 :       tree upper;
     886              : 
     887    187674755 :       if (integer_types[itk] == NULL_TREE)
     888            0 :         continue;
     889    187674755 :       upper = TYPE_MAX_VALUE (integer_types[itk]);
     890              : 
     891    187674755 :       if (wi::geu_p (wi::to_widest (upper), val))
     892    187442253 :         return (enum integer_type_kind) itk;
     893              :     }
     894              : 
     895              :   return itk_none;
     896              : }
     897              : 
     898              : /* Ditto, but narrowest signed type.  */
     899              : static enum integer_type_kind
     900    183719089 : narrowest_signed_type (const widest_int &val, unsigned int flags)
     901              : {
     902    183719089 :   int itk;
     903              : 
     904    183719089 :   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
     905              :     itk = itk_int;
     906      1268250 :   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
     907              :     itk = itk_long;
     908              :   else
     909       293976 :     itk = itk_long_long;
     910              : 
     911    183923207 :   for (; itk < itk_none; itk += 2 /* skip signed types */)
     912              :     {
     913    183922109 :       tree upper;
     914              : 
     915    183922109 :       if (integer_types[itk] == NULL_TREE)
     916         4392 :         continue;
     917    183917717 :       upper = TYPE_MAX_VALUE (integer_types[itk]);
     918              : 
     919    183917717 :       if (wi::geu_p (wi::to_widest (upper), val))
     920    183717991 :         return (enum integer_type_kind) itk;
     921              :     }
     922              : 
     923              :   return itk_none;
     924              : }
     925              : 
     926              : /* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
     927              : static tree
     928    187461577 : interpret_integer (const cpp_token *token, unsigned int flags,
     929              :                    enum overflow_type *overflow)
     930              : {
     931    187461577 :   tree value, type;
     932    187461577 :   enum integer_type_kind itk;
     933    187461577 :   cpp_num integer;
     934    187461577 :   HOST_WIDE_INT ival[3];
     935              : 
     936    187461577 :   *overflow = OT_NONE;
     937              : 
     938    187461577 :   if (UNLIKELY (flags & CPP_N_BITINT))
     939              :     {
     940        19324 :       unsigned int suffix_len = 2 + ((flags & CPP_N_UNSIGNED) ? 1 : 0);
     941        19324 :       int max_bits_per_digit = 4; // ceil (log2 (10))
     942        19324 :       unsigned int prefix_len = 0;
     943        19324 :       bool hex = false;
     944        19324 :       const int bitint_maxwidth = WIDE_INT_MAX_PRECISION - 1;
     945        19324 :       if ((flags & CPP_N_RADIX) == CPP_N_OCTAL)
     946              :         {
     947          949 :           max_bits_per_digit = 3;
     948          949 :           prefix_len = 1;
     949          949 :           if (token->val.str.len > 2
     950          949 :               && (token->val.str.text[1] == 'o'
     951          948 :                   || token->val.str.text[1] == 'O'))
     952        19324 :             prefix_len = 2;
     953              :         }
     954        18375 :       else if ((flags & CPP_N_RADIX) == CPP_N_HEX)
     955              :         {
     956              :           max_bits_per_digit = 4;
     957              :           prefix_len = 2;
     958              :           hex = true;
     959              :         }
     960        18204 :       else if ((flags & CPP_N_RADIX) == CPP_N_BINARY)
     961              :         {
     962            1 :           max_bits_per_digit = 1;
     963            1 :           prefix_len = 2;
     964              :         }
     965        19324 :       int max_digits
     966        19324 :         = TYPE_PRECISION (intmax_type_node) >> max_bits_per_digit;
     967        19324 :       const int max_buf = 128;
     968        19324 :       if (max_digits > max_buf)
     969              :         max_digits = max_buf;
     970              : 
     971        19324 :       widest_int wval;
     972        19324 :       unsigned int prec;
     973        19324 :       gcc_checking_assert (token->val.str.len > prefix_len + suffix_len
     974              :                            || token->val.str.len == 1 + suffix_len);
     975        19324 :       if (token->val.str.len - (prefix_len + suffix_len)
     976        19324 :           <= (unsigned) max_digits)
     977              :         {
     978         2929 :           integer = cpp_interpret_integer (parse_in, token,
     979              :                                            (flags & CPP_N_RADIX)
     980              :                                            | CPP_N_UNSIGNED);
     981         2929 :           ival[0] = integer.low;
     982         2929 :           ival[1] = integer.high;
     983         2929 :           ival[2] = 0;
     984         2929 :           wval = widest_int::from_array (ival, 3);
     985              :         }
     986              :       else
     987              :         {
     988        16395 :           unsigned char buf[3 + max_buf];
     989        16395 :           memcpy (buf, token->val.str.text, prefix_len);
     990        16395 :           wval = 0U;
     991        16395 :           const unsigned char *p = token->val.str.text + prefix_len;
     992        16395 :           cpp_token tok = *token;
     993        16395 :           tok.val.str.text = buf;
     994        16395 :           if (!prefix_len)
     995        16238 :             max_digits = 19;
     996       200025 :           do
     997              :             {
     998       108210 :               unsigned char *q = buf + prefix_len;
     999      1534369 :               do
    1000              :                 {
    1001      1534369 :                   unsigned char c = *p++;
    1002      1534369 :                   if (ISDIGIT (c) || (hex && ISXDIGIT (c)))
    1003              :                     {
    1004      1502739 :                       *q++ = c;
    1005      1502739 :                       if (q == buf + prefix_len + max_digits)
    1006              :                         break;
    1007              :                     }
    1008        31630 :                   else if (c != '\'')
    1009              :                     {
    1010              :                       --p;
    1011              :                       break;
    1012              :                     }
    1013              :                 }
    1014              :               while (1);
    1015       108210 :               if (q == buf + prefix_len)
    1016              :                 break;
    1017              :               else
    1018              :                 {
    1019        91815 :                   wi::overflow_type wioverflow;
    1020        91815 :                   *q = '\0';
    1021        91815 :                   tok.val.str.len = q - buf;
    1022        91815 :                   if (wval == 0)
    1023              :                     ;
    1024        75393 :                   else if (prefix_len)
    1025              :                     {
    1026         2562 :                       prec = wi::min_precision (wval, UNSIGNED);
    1027         2562 :                       unsigned HOST_WIDE_INT shift
    1028         2562 :                         = (tok.val.str.len - prefix_len) * max_bits_per_digit;
    1029         2562 :                       if (prec + shift > bitint_maxwidth)
    1030            0 :                         goto bitint_overflow;
    1031         3332 :                       wval = wi::lshift (wval, shift);
    1032              :                     }
    1033              :                   else
    1034              :                     {
    1035        72831 :                       static unsigned HOST_WIDE_INT tens[]
    1036              :                         = { 1U, 10U, 100U, 1000U,
    1037              :                             HOST_WIDE_INT_UC (10000),
    1038              :                             HOST_WIDE_INT_UC (100000),
    1039              :                             HOST_WIDE_INT_UC (1000000),
    1040              :                             HOST_WIDE_INT_UC (10000000),
    1041              :                             HOST_WIDE_INT_UC (100000000),
    1042              :                             HOST_WIDE_INT_UC (1000000000),
    1043              :                             HOST_WIDE_INT_UC (10000000000),
    1044              :                             HOST_WIDE_INT_UC (100000000000),
    1045              :                             HOST_WIDE_INT_UC (1000000000000),
    1046              :                             HOST_WIDE_INT_UC (10000000000000),
    1047              :                             HOST_WIDE_INT_UC (100000000000000),
    1048              :                             HOST_WIDE_INT_UC (1000000000000000),
    1049              :                             HOST_WIDE_INT_UC (10000000000000000),
    1050              :                             HOST_WIDE_INT_UC (100000000000000000),
    1051              :                             HOST_WIDE_INT_UC (1000000000000000000),
    1052              :                             HOST_WIDE_INT_UC (10000000000000000000) };
    1053        72831 :                       widest_int ten = tens[q - buf];
    1054        72831 :                       wval = wi::umul (wval, ten, &wioverflow);
    1055        72831 :                       if (wioverflow)
    1056            0 :                         goto bitint_overflow;
    1057        72831 :                     }
    1058        91815 :                   integer = cpp_interpret_integer (parse_in, &tok,
    1059              :                                                    (flags & CPP_N_RADIX)
    1060              :                                                    | CPP_N_UNSIGNED);
    1061        91815 :                   ival[0] = integer.low;
    1062        91815 :                   ival[1] = integer.high;
    1063        91815 :                   ival[2] = 0;
    1064        91815 :                   if (prefix_len)
    1065         3516 :                     wval = wval + widest_int::from_array (ival, 3);
    1066              :                   else
    1067              :                     {
    1068        89069 :                       widest_int addend = widest_int::from_array (ival, 3);
    1069        89069 :                       wval = wi::add (wval, addend, UNSIGNED, &wioverflow);
    1070        89069 :                       if (wioverflow)
    1071            0 :                         goto bitint_overflow;
    1072        89069 :                     }
    1073              :                 }
    1074        91815 :             }
    1075              :           while (1);
    1076              :         }
    1077              : 
    1078        19324 :       prec = wi::min_precision (wval, UNSIGNED);
    1079        19324 :       if (prec == 0)
    1080              :         prec = 1;
    1081        19324 :       if ((flags & CPP_N_UNSIGNED) == 0)
    1082        13866 :         ++prec;
    1083        19324 :       if (prec > bitint_maxwidth)
    1084              :         {
    1085            0 :         bitint_overflow:
    1086            0 :           if ((flags & CPP_N_UNSIGNED) != 0)
    1087            0 :             error ("integer constant is too large for "
    1088              :                    "%<unsigned _BitInt(%d)%> type", bitint_maxwidth);
    1089              :           else
    1090            0 :             error ("integer constant is too large for "
    1091              :                    "%<_BitInt(%d)%> type", bitint_maxwidth);
    1092            0 :           return integer_zero_node;
    1093              :         }
    1094              : 
    1095        19324 :       struct bitint_info info;
    1096        19324 :       if (!targetm.c.bitint_type_info (prec, &info))
    1097              :         {
    1098            0 :           sorry ("%<_BitInt(%d)%> is not supported on this target", prec);
    1099            0 :           return integer_zero_node;
    1100              :         }
    1101              : 
    1102        19324 :       type = build_bitint_type (prec, (flags & CPP_N_UNSIGNED) != 0);
    1103        19324 :       return wide_int_to_tree (type, wval);
    1104        19324 :     }
    1105              : 
    1106    187442253 :   integer = cpp_interpret_integer (parse_in, token, flags);
    1107    187442253 :   if (integer.overflow)
    1108           20 :     *overflow = OT_OVERFLOW;
    1109              : 
    1110    187442253 :   ival[0] = integer.low;
    1111    187442253 :   ival[1] = integer.high;
    1112    187442253 :   ival[2] = 0;
    1113    374884506 :   widest_int wval = widest_int::from_array (ival, 3);
    1114              : 
    1115              :   /* The type of a constant with a U suffix is straightforward.  */
    1116    187442253 :   if (flags & CPP_N_UNSIGNED)
    1117      3723164 :     itk = narrowest_unsigned_type (wval, flags);
    1118              :   else
    1119              :     {
    1120              :       /* The type of a potentially-signed integer constant varies
    1121              :          depending on the base it's in, the standard in use, and the
    1122              :          length suffixes.  */
    1123    183719089 :       enum integer_type_kind itk_u
    1124    183719089 :         = narrowest_unsigned_type (wval, flags);
    1125    183719089 :       enum integer_type_kind itk_s
    1126    183719089 :         = narrowest_signed_type (wval, flags);
    1127              : 
    1128              :       /* In both C89 and C99, octal and hex constants may be signed or
    1129              :          unsigned, whichever fits tighter.  We do not warn about this
    1130              :          choice differing from the traditional choice, as the constant
    1131              :          is probably a bit pattern and either way will work.  */
    1132    183719089 :       if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
    1133    183719074 :         itk = MIN (itk_u, itk_s);
    1134              :       else
    1135              :         {
    1136              :           /* In C99, decimal constants are always signed.
    1137              :              In C89, decimal constants that don't fit in long have
    1138              :              undefined behavior; we try to make them unsigned long.
    1139              :              In GCC's extended C89, that last is true of decimal
    1140              :              constants that don't fit in long long, too.  */
    1141              : 
    1142    133062250 :           itk = itk_s;
    1143    133062250 :           if (itk_s > itk_u && itk_s > itk_long)
    1144              :             {
    1145           31 :               if (!flag_isoc99)
    1146              :                 {
    1147           15 :                   if (itk_u < itk_unsigned_long)
    1148              :                     itk_u = itk_unsigned_long;
    1149           15 :                   itk = itk_u;
    1150           15 :                   warning (0, "this decimal constant is unsigned only in ISO C90");
    1151              :                 }
    1152              :               else
    1153           16 :                 warning (OPT_Wtraditional,
    1154              :                          "this decimal constant would be unsigned in ISO C90");
    1155              :             }
    1156              :         }
    1157              :     }
    1158              : 
    1159    187442253 :   if (itk == itk_none)
    1160              :     /* cpplib has already issued a warning for overflow.  */
    1161            0 :     type = ((flags & CPP_N_UNSIGNED)
    1162            0 :             ? widest_unsigned_literal_type_node
    1163              :             : widest_integer_literal_type_node);
    1164    187442253 :   else if (flags & CPP_N_SIZE_T)
    1165              :     {
    1166              :       /* itk refers to fundamental types not aliased size types.  */
    1167          878 :       if (flags & CPP_N_UNSIGNED)
    1168          870 :         type = size_type_node;
    1169              :       else
    1170            8 :         type = signed_size_type_node;
    1171              :     }
    1172              :   else
    1173              :     {
    1174    187441375 :       type = integer_types[itk];
    1175    187441375 :       if (itk > itk_unsigned_long
    1176      1299276 :           && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
    1177        15925 :         emit_diagnostic
    1178        47775 :           ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
    1179              :            ? diagnostics::kind::pedwarn : diagnostics::kind::warning,
    1180        15925 :            input_location, OPT_Wlong_long,
    1181              :            (flags & CPP_N_UNSIGNED)
    1182              :            ? "integer constant is too large for %<unsigned long%> type"
    1183              :            : "integer constant is too large for %<long%> type");
    1184              :     }
    1185              : 
    1186    187442253 :   value = wide_int_to_tree (type, wval);
    1187              : 
    1188              :   /* Convert imaginary to a complex type.  */
    1189    187442253 :   if (flags & CPP_N_IMAGINARY)
    1190         3133 :     value = build_complex (NULL_TREE, build_int_cst (type, 0), value);
    1191              : 
    1192    187442253 :   return value;
    1193              : }
    1194              : 
    1195              : /* Interpret TOKEN, a floating point number with FLAGS as classified
    1196              :    by cpplib.  For C++11 SUFFIX may contain a user-defined literal suffix.  */
    1197              : static tree
    1198      4753642 : interpret_float (const cpp_token *token, unsigned int flags,
    1199              :                  const char *suffix, enum overflow_type *overflow)
    1200              : {
    1201      4753642 :   tree type;
    1202      4753642 :   tree const_type;
    1203      4753642 :   tree value;
    1204      4753642 :   REAL_VALUE_TYPE real;
    1205      4753642 :   REAL_VALUE_TYPE real_trunc;
    1206      4753642 :   char *copy;
    1207      4753642 :   size_t copylen;
    1208              : 
    1209      4753642 :   *overflow = OT_NONE;
    1210              : 
    1211              :   /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64
    1212              :      pragma has been used and is either double or _Decimal64.  Types
    1213              :      that are not allowed with decimal float default to double.  */
    1214      4753642 :   if (flags & CPP_N_DEFAULT)
    1215              :     {
    1216      2500775 :       flags ^= CPP_N_DEFAULT;
    1217      2500775 :       flags |= CPP_N_MEDIUM;
    1218              : 
    1219      2500775 :       if (((flags & CPP_N_HEX) == 0) && ((flags & CPP_N_IMAGINARY) == 0))
    1220              :         {
    1221      2476252 :           warning (OPT_Wunsuffixed_float_constants,
    1222              :                    "unsuffixed floating constant");
    1223      2476252 :           if (float_const_decimal64_p ())
    1224           23 :             flags |= CPP_N_DFLOAT;
    1225              :         }
    1226              :     }
    1227              : 
    1228              :   /* Decode _Fract and _Accum.  */
    1229      4753642 :   if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM)
    1230           54 :     return interpret_fixed (token, flags);
    1231              : 
    1232              :   /* Decode type based on width and properties. */
    1233      4753588 :   if (flags & CPP_N_DFLOAT)
    1234        16110 :     if (!targetm.decimal_float_supported_p ())
    1235              :       {
    1236            0 :         error ("decimal floating-point not supported for this target");
    1237            0 :         return error_mark_node;
    1238              :       }
    1239        16110 :     else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1240         5088 :       type = dfloat128_type_node;
    1241        11022 :     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1242         5518 :       type = dfloat32_type_node;
    1243         5504 :     else if ((flags & CPP_N_FLOATNX) != 0)
    1244           81 :       type = dfloat64x_type_node;
    1245              :     else
    1246         5423 :       type = dfloat64_type_node;
    1247              :   else
    1248      4737478 :     if (flags & CPP_N_WIDTH_MD)
    1249              :       {
    1250       193204 :         char suffix;
    1251       193204 :         machine_mode mode;
    1252              : 
    1253       193204 :         if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W)
    1254              :           suffix = 'w';
    1255              :         else
    1256       193167 :           suffix = 'q';
    1257              : 
    1258       193204 :         mode = targetm.c.mode_for_suffix (suffix);
    1259       193204 :         if (mode == VOIDmode)
    1260              :           {
    1261            0 :             error ("unsupported non-standard suffix on floating constant");
    1262              : 
    1263            0 :             return error_mark_node;
    1264              :           }
    1265              :         else
    1266       193204 :           pedwarn (input_location, OPT_Wpedantic, "non-standard suffix on floating constant");
    1267              : 
    1268       193204 :         type = c_common_type_for_mode (mode, 0);
    1269              :         /* For Q suffix, prefer float128t_type_node (__float128) type
    1270              :            over float128_type_node (_Float128) type if they are distinct.  */
    1271       193204 :         if (type == float128_type_node && float128t_type_node)
    1272       193204 :           type = float128t_type_node;
    1273       193204 :         gcc_assert (type);
    1274              :       }
    1275      4544274 :     else if ((flags & (CPP_N_FLOATN | CPP_N_FLOATNX)) != 0)
    1276              :       {
    1277       405880 :         unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
    1278       405880 :         bool extended = (flags & CPP_N_FLOATNX) != 0;
    1279       405880 :         type = NULL_TREE;
    1280       982811 :         for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    1281       982811 :           if (floatn_nx_types[i].n == (int) n
    1282       408586 :               && floatn_nx_types[i].extended == extended)
    1283              :             {
    1284       405880 :               type = FLOATN_NX_TYPE_NODE (i);
    1285       405880 :               break;
    1286              :             }
    1287       405880 :         if (type == NULL_TREE)
    1288              :           {
    1289            0 :             error ("unsupported non-standard suffix on floating constant");
    1290            0 :             return error_mark_node;
    1291              :           }
    1292       405880 :         else if (!c_dialect_cxx ())
    1293              :           {
    1294        94510 :             if (warn_c11_c23_compat > 0)
    1295              :               {
    1296           12 :                 if (pedantic && !flag_isoc23)
    1297            0 :                   pedwarn (input_location, OPT_Wc11_c23_compat,
    1298              :                            "non-standard suffix on floating constant "
    1299              :                            "before C23");
    1300              :                 else
    1301           12 :                   warning (OPT_Wc11_c23_compat,
    1302              :                            "non-standard suffix on floating constant "
    1303              :                            "before C23");
    1304              :               }
    1305        94498 :             else if (warn_c11_c23_compat != 0 && pedantic && !flag_isoc23)
    1306           40 :               pedwarn (input_location, OPT_Wpedantic,
    1307              :                        "non-standard suffix on floating constant "
    1308              :                        "before C23");
    1309              :           }
    1310       311370 :         else if (!extended)
    1311              :           {
    1312       311254 :             if (cxx_dialect < cxx23 && pedantic)
    1313         3956 :               pedwarn (input_location, OPT_Wc__23_extensions,
    1314              :                        "%<f%d%> or %<F%d%> suffix on floating constant only "
    1315              :                        "available with %<-std=c++23%> or %<-std=gnu++23%>",
    1316              :                        n, n);
    1317              :           }
    1318              :         else
    1319          116 :           pedwarn (input_location, OPT_Wpedantic,
    1320              :                    "non-standard suffix on floating constant");
    1321              :       }
    1322      4138394 :     else if ((flags & CPP_N_BFLOAT16) != 0)
    1323              :       {
    1324        78455 :         type = bfloat16_type_node;
    1325        78455 :         if (type == NULL_TREE)
    1326              :           {
    1327            0 :             error ("unsupported non-standard suffix on floating constant");
    1328            0 :             return error_mark_node;
    1329              :           }
    1330        78455 :         if (!c_dialect_cxx ())
    1331          916 :           pedwarn (input_location, OPT_Wpedantic,
    1332              :                    "non-standard suffix on floating constant");
    1333        77539 :         else if (cxx_dialect < cxx23 && pedantic)
    1334         2464 :           pedwarn (input_location, OPT_Wc__23_extensions,
    1335              :                    "%<bf16%> or %<BF16%> suffix on floating constant only "
    1336              :                    "available with %<-std=c++23%> or %<-std=gnu++23%>");
    1337              :       }
    1338      4059939 :     else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1339      1137708 :       type = long_double_type_node;
    1340      2922231 :     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
    1341      2500892 :              || flag_single_precision_constant)
    1342       421530 :       type = float_type_node;
    1343              :     else
    1344      2500701 :       type = double_type_node;
    1345              : 
    1346      4753588 :   const_type = excess_precision_type (type);
    1347      4753588 :   if (!const_type)
    1348      4642252 :     const_type = type;
    1349              : 
    1350              :   /* Copy the constant to a nul-terminated buffer.  If the constant
    1351              :      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
    1352              :      can't handle them.  */
    1353      4753588 :   copylen = token->val.str.len;
    1354      4753588 :   if (flags & CPP_N_USERDEF)
    1355        31758 :     copylen -= strlen (suffix);
    1356      4721830 :   else if (flags & CPP_N_DFLOAT)
    1357              :     {
    1358        16110 :       if (ISDIGIT (token->val.str.text[copylen - 1]))
    1359          146 :         copylen -= (flags & CPP_N_LARGE) ? 4 : 3;
    1360        16027 :       else if ((flags & CPP_N_FLOATNX) != 0)
    1361           81 :         copylen -= 4;
    1362              :       else
    1363        15946 :         copylen -= 2;
    1364              :     }
    1365              :   else
    1366              :     {
    1367      4705720 :       if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
    1368              :         /* Must be an F or L or machine defined suffix.  */
    1369      2204828 :         copylen--;
    1370      4705720 :       if (flags & CPP_N_IMAGINARY)
    1371              :         /* I or J suffix.  */
    1372        51274 :         copylen--;
    1373      4705720 :       if (flags & CPP_N_FLOATNX)
    1374         2706 :         copylen--;
    1375      4705720 :       if (flags & (CPP_N_FLOATN | CPP_N_FLOATNX))
    1376              :         {
    1377       405880 :           unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
    1378      1312314 :           while (n > 0)
    1379              :             {
    1380       906434 :               copylen--;
    1381       906434 :               n /= 10;
    1382              :             }
    1383              :         }
    1384              :     }
    1385              : 
    1386      4753588 :   copy = (char *) alloca (copylen + 1);
    1387      4753588 :   if (c_dialect_cxx () ? cxx_dialect > cxx11 : flag_isoc23)
    1388              :     {
    1389              :       size_t maxlen = 0;
    1390     62435580 :       for (size_t i = 0; i < copylen; ++i)
    1391     57871743 :         if (token->val.str.text[i] != '\'')
    1392     57871687 :           copy[maxlen++] = token->val.str.text[i];
    1393      4563837 :       copy[maxlen] = '\0';
    1394              :     }
    1395              :   else
    1396              :     {
    1397       189751 :       memcpy (copy, token->val.str.text, copylen);
    1398       189751 :       copy[copylen] = '\0';
    1399              :     }
    1400              : 
    1401      4753588 :   real_from_string3 (&real, copy, TYPE_MODE (const_type));
    1402      4753588 :   if (const_type != type)
    1403              :     /* Diagnosing if the result of converting the value with excess
    1404              :        precision to the semantic type would overflow (with associated
    1405              :        double rounding) is more appropriate than diagnosing if the
    1406              :        result of converting the string directly to the semantic type
    1407              :        would overflow.  */
    1408       111336 :     real_convert (&real_trunc, TYPE_MODE (type), &real);
    1409              : 
    1410              :   /* Both C and C++ require a diagnostic for a floating constant
    1411              :      outside the range of representable values of its type.  Since we
    1412              :      have __builtin_inf* to produce an infinity, this is now a
    1413              :      mandatory pedwarn if the target does not support infinities.  */
    1414      4753588 :   if (REAL_VALUE_ISINF (real)
    1415      4753588 :       || (const_type != type && REAL_VALUE_ISINF (real_trunc)))
    1416              :     {
    1417           58 :       *overflow = OT_OVERFLOW;
    1418           58 :       if (!(flags & CPP_N_USERDEF))
    1419              :         {
    1420          188 :           if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
    1421            0 :             pedwarn (input_location, 0,
    1422              :                      "floating constant exceeds range of %qT", type);
    1423              :           else
    1424           49 :             warning (OPT_Woverflow,
    1425              :                      "floating constant exceeds range of %qT", type);
    1426              :         }
    1427              :     }
    1428              :   /* We also give a warning if the value underflows.  */
    1429      4753530 :   else if (real_equal (&real, &dconst0)
    1430      4753530 :            || (const_type != type
    1431        45325 :                && real_equal (&real_trunc, &dconst0)))
    1432              :     {
    1433      1185042 :       REAL_VALUE_TYPE realvoidmode;
    1434      1185042 :       int oflow = real_from_string (&realvoidmode, copy);
    1435      1185042 :       *overflow = (oflow == 0 ? OT_NONE
    1436           21 :                               : (oflow < 0 ? OT_UNDERFLOW : OT_OVERFLOW));
    1437      1185042 :       if (!(flags & CPP_N_USERDEF))
    1438              :         {
    1439      1153521 :           if (oflow < 0 || !real_equal (&realvoidmode, &dconst0))
    1440           30 :             warning (OPT_Woverflow, "floating constant truncated to zero");
    1441              :         }
    1442              :     }
    1443              : 
    1444              :   /* Create a node with determined type and value.  */
    1445      4753588 :   value = build_real (const_type, real);
    1446      4753588 :   if (flags & CPP_N_IMAGINARY)
    1447              :     {
    1448        51274 :       value = build_complex (NULL_TREE,
    1449              :                              fold_convert (const_type,
    1450              :                                            integer_zero_node), value);
    1451        51274 :       if (type != const_type)
    1452              :         {
    1453           58 :           const_type = TREE_TYPE (value);
    1454           58 :           type = build_complex_type (type);
    1455              :         }
    1456              :     }
    1457              : 
    1458      4753588 :   if (type != const_type)
    1459       111336 :     value = build1_loc (token->src_loc, EXCESS_PRECISION_EXPR, type, value);
    1460              : 
    1461              :   return value;
    1462              : }
    1463              : 
    1464              : /* Interpret TOKEN, a fixed-point number with FLAGS as classified
    1465              :    by cpplib.  */
    1466              : 
    1467              : static tree
    1468           54 : interpret_fixed (const cpp_token *token, unsigned int flags)
    1469              : {
    1470           54 :   tree type;
    1471           54 :   tree value;
    1472           54 :   FIXED_VALUE_TYPE fixed;
    1473           54 :   char *copy;
    1474           54 :   size_t copylen;
    1475              : 
    1476           54 :   copylen = token->val.str.len;
    1477              : 
    1478           54 :   if (flags & CPP_N_FRACT) /* _Fract.  */
    1479              :     {
    1480           36 :       if (flags & CPP_N_UNSIGNED) /* Unsigned _Fract.  */
    1481              :         {
    1482            0 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1483              :             {
    1484            0 :               type = unsigned_long_long_fract_type_node;
    1485            0 :               copylen -= 4;
    1486              :             }
    1487            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1488              :             {
    1489            0 :               type = unsigned_long_fract_type_node;
    1490            0 :               copylen -= 3;
    1491              :             }
    1492            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1493              :             {
    1494            0 :               type = unsigned_short_fract_type_node;
    1495            0 :               copylen -= 3;
    1496              :             }
    1497              :           else
    1498              :             {
    1499            0 :               type = unsigned_fract_type_node;
    1500            0 :               copylen -= 2;
    1501              :             }
    1502              :         }
    1503              :       else /* Signed _Fract.  */
    1504              :         {
    1505           36 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1506              :             {
    1507            0 :               type = long_long_fract_type_node;
    1508            0 :               copylen -= 3;
    1509              :             }
    1510           36 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1511              :             {
    1512            0 :               type = long_fract_type_node;
    1513            0 :               copylen -= 2;
    1514              :             }
    1515           36 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1516              :             {
    1517            0 :               type = short_fract_type_node;
    1518            0 :               copylen -= 2;
    1519              :             }
    1520              :           else
    1521              :             {
    1522           36 :               type = fract_type_node;
    1523           36 :               copylen --;
    1524              :             }
    1525              :           }
    1526              :     }
    1527              :   else /* _Accum.  */
    1528              :     {
    1529           18 :       if (flags & CPP_N_UNSIGNED) /* Unsigned _Accum.  */
    1530              :         {
    1531            0 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1532              :             {
    1533            0 :               type = unsigned_long_long_accum_type_node;
    1534            0 :               copylen -= 4;
    1535              :             }
    1536            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1537              :             {
    1538            0 :               type = unsigned_long_accum_type_node;
    1539            0 :               copylen -= 3;
    1540              :             }
    1541            0 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1542              :             {
    1543            0 :               type = unsigned_short_accum_type_node;
    1544            0 :               copylen -= 3;
    1545              :              }
    1546              :           else
    1547              :             {
    1548            0 :               type = unsigned_accum_type_node;
    1549            0 :               copylen -= 2;
    1550              :             }
    1551              :         }
    1552              :       else /* Signed _Accum.  */
    1553              :         {
    1554           18 :           if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    1555              :             {
    1556            0 :               type = long_long_accum_type_node;
    1557            0 :               copylen -= 3;
    1558              :             }
    1559           18 :           else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
    1560              :             {
    1561            0 :               type = long_accum_type_node;
    1562            0 :               copylen -= 2;
    1563              :             }
    1564           18 :           else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
    1565              :             {
    1566            0 :               type = short_accum_type_node;
    1567            0 :               copylen -= 2;
    1568              :             }
    1569              :           else
    1570              :             {
    1571           18 :               type = accum_type_node;
    1572           18 :               copylen --;
    1573              :             }
    1574              :         }
    1575              :     }
    1576              : 
    1577           54 :   copy = (char *) alloca (copylen + 1);
    1578           54 :   memcpy (copy, token->val.str.text, copylen);
    1579           54 :   copy[copylen] = '\0';
    1580              : 
    1581           54 :   fixed_from_string (&fixed, copy, SCALAR_TYPE_MODE (type));
    1582              : 
    1583              :   /* Create a node with determined type and value.  */
    1584           54 :   value = build_fixed (type, fixed);
    1585              : 
    1586           54 :   return value;
    1587              : }
    1588              : 
    1589              : /* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
    1590              :    UTF8STRING tokens into a tree, performing string constant
    1591              :    concatenation.  TOK is the first of these.  VALP is the location to
    1592              :    write the string into.  OBJC_STRING indicates whether an '@' token
    1593              :    preceded the incoming token (in that case, the strings can either
    1594              :    be ObjC strings, preceded by a single '@', or normal strings, not
    1595              :    preceded by '@'.  The result will be a CPP_OBJC_STRING).  Returns
    1596              :    the CPP token type of the result (CPP_STRING, CPP_WSTRING,
    1597              :    CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
    1598              : 
    1599              :    This is unfortunately more work than it should be.  If any of the
    1600              :    strings in the series has an L prefix, the result is a wide string
    1601              :    (6.4.5p4).  Whether or not the result is a wide string affects the
    1602              :    meaning of octal and hexadecimal escapes (6.4.4.4p6,9).  But escape
    1603              :    sequences do not continue across the boundary between two strings in
    1604              :    a series (6.4.5p7), so we must not lose the boundaries.  Therefore
    1605              :    cpp_interpret_string takes a vector of cpp_string structures, which
    1606              :    we must arrange to provide.  */
    1607              : 
    1608              : static enum cpp_ttype
    1609           18 : lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
    1610              : {
    1611           18 :   tree value;
    1612           18 :   size_t concats = 0;
    1613           18 :   struct obstack str_ob;
    1614           18 :   struct obstack loc_ob;
    1615           18 :   cpp_string istr;
    1616           18 :   enum cpp_ttype type = tok->type;
    1617              : 
    1618              :   /* Try to avoid the overhead of creating and destroying an obstack
    1619              :      for the common case of just one string.  */
    1620           18 :   cpp_string str = tok->val.str;
    1621           18 :   location_t init_loc = tok->src_loc;
    1622           18 :   cpp_string *strs = &str;
    1623           18 :   location_t *locs = NULL;
    1624              : 
    1625              :   /* objc_at_sign_was_seen is only used when doing Objective-C string
    1626              :      concatenation.  It is 'true' if we have seen an '@' before the
    1627              :      current string, and 'false' if not.  We must see exactly one or
    1628              :      zero '@' before each string.  */
    1629           18 :   bool objc_at_sign_was_seen = false;
    1630              : 
    1631           18 :  retry:
    1632           18 :   tok = get_token (parse_in);
    1633           18 :   switch (tok->type)
    1634              :     {
    1635            0 :     case CPP_PADDING:
    1636            0 :       goto retry;
    1637            0 :     case CPP_ATSIGN:
    1638            0 :       if (objc_string)
    1639              :         {
    1640            0 :           if (objc_at_sign_was_seen)
    1641            0 :             error ("repeated %<@%> before Objective-C string");
    1642              : 
    1643            0 :           objc_at_sign_was_seen = true;
    1644            0 :           goto retry;
    1645              :         }
    1646              :       /* FALLTHROUGH */
    1647              : 
    1648           18 :     default:
    1649           18 :       break;
    1650              : 
    1651            0 :     case CPP_WSTRING:
    1652            0 :     case CPP_STRING16:
    1653            0 :     case CPP_STRING32:
    1654            0 :     case CPP_UTF8STRING:
    1655            0 :       if (type != tok->type)
    1656              :         {
    1657            0 :           if (type == CPP_STRING)
    1658            0 :             type = tok->type;
    1659              :           else
    1660            0 :             error ("unsupported non-standard concatenation of string literals");
    1661              :         }
    1662              :       /* FALLTHROUGH */
    1663              : 
    1664            0 :     case CPP_STRING:
    1665            0 :       if (!concats)
    1666              :         {
    1667            0 :           gcc_obstack_init (&str_ob);
    1668            0 :           gcc_obstack_init (&loc_ob);
    1669            0 :           obstack_grow (&str_ob, &str, sizeof (cpp_string));
    1670            0 :           obstack_grow (&loc_ob, &init_loc, sizeof (location_t));
    1671              :         }
    1672              : 
    1673            0 :       concats++;
    1674            0 :       obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
    1675            0 :       obstack_grow (&loc_ob, &tok->src_loc, sizeof (location_t));
    1676              : 
    1677            0 :       if (objc_string)
    1678            0 :         objc_at_sign_was_seen = false;
    1679            0 :       goto retry;
    1680              :     }
    1681              : 
    1682              :   /* It is an error if we saw a '@' with no following string.  */
    1683           18 :   if (objc_at_sign_was_seen)
    1684            0 :     error ("stray %<@%> in program");
    1685              : 
    1686              :   /* We have read one more token than we want.  */
    1687           18 :   _cpp_backup_tokens (parse_in, 1);
    1688           18 :   if (concats)
    1689              :     {
    1690            0 :       strs = XOBFINISH (&str_ob, cpp_string *);
    1691            0 :       locs = XOBFINISH (&loc_ob, location_t *);
    1692              :     }
    1693              : 
    1694           18 :   if (concats && !objc_string && !in_system_header_at (input_location))
    1695            0 :     warning (OPT_Wtraditional,
    1696              :              "traditional C rejects string constant concatenation");
    1697              : 
    1698           18 :   if ((translate
    1699           18 :        ? cpp_interpret_string : cpp_interpret_string_notranslate)
    1700           18 :       (parse_in, strs, concats + 1, &istr, type))
    1701              :     {
    1702           18 :       value = build_string (istr.len, (const char *) istr.text);
    1703           18 :       free (const_cast<unsigned char *> (istr.text));
    1704           18 :       if (concats)
    1705              :         {
    1706            0 :           gcc_assert (locs);
    1707            0 :           gcc_assert (g_string_concat_db);
    1708            0 :           g_string_concat_db->record_string_concatenation (concats + 1, locs);
    1709              :         }
    1710              :     }
    1711              :   else
    1712              :     {
    1713              :       /* Callers cannot generally handle error_mark_node in this context,
    1714              :          so return the empty string instead.  cpp_interpret_string has
    1715              :          issued an error.  */
    1716            0 :       switch (type)
    1717              :         {
    1718            0 :         default:
    1719            0 :         case CPP_STRING:
    1720            0 :         case CPP_UTF8STRING:
    1721            0 :           if (type == CPP_UTF8STRING && flag_char8_t)
    1722              :             {
    1723            0 :               value = build_string (TYPE_PRECISION (char8_type_node)
    1724            0 :                                     / TYPE_PRECISION (char_type_node),
    1725              :                                     "");  /* char8_t is 8 bits */
    1726              :             }
    1727              :           else
    1728            0 :             value = build_string (1, "");
    1729              :           break;
    1730            0 :         case CPP_STRING16:
    1731            0 :           value = build_string (TYPE_PRECISION (char16_type_node)
    1732            0 :                                 / TYPE_PRECISION (char_type_node),
    1733              :                                 "\0");  /* char16_t is 16 bits */
    1734            0 :           break;
    1735            0 :         case CPP_STRING32:
    1736            0 :           value = build_string (TYPE_PRECISION (char32_type_node)
    1737            0 :                                 / TYPE_PRECISION (char_type_node),
    1738              :                                 "\0\0\0");  /* char32_t is 32 bits */
    1739            0 :           break;
    1740            0 :         case CPP_WSTRING:
    1741            0 :           value = build_string (TYPE_PRECISION (wchar_type_node)
    1742            0 :                                 / TYPE_PRECISION (char_type_node),
    1743              :                                 "\0\0\0");  /* widest supported wchar_t
    1744              :                                                is 32 bits */
    1745            0 :           break;
    1746              :         }
    1747              :     }
    1748              : 
    1749           18 :   switch (type)
    1750              :     {
    1751           18 :     default:
    1752           18 :     case CPP_STRING:
    1753           18 :       TREE_TYPE (value) = char_array_type_node;
    1754           18 :       break;
    1755            0 :     case CPP_UTF8STRING:
    1756            0 :       if (flag_char8_t)
    1757            0 :         TREE_TYPE (value) = char8_array_type_node;
    1758              :       else
    1759            0 :         TREE_TYPE (value) = char_array_type_node;
    1760              :       break;
    1761            0 :     case CPP_STRING16:
    1762            0 :       TREE_TYPE (value) = char16_array_type_node;
    1763            0 :       break;
    1764            0 :     case CPP_STRING32:
    1765            0 :       TREE_TYPE (value) = char32_array_type_node;
    1766            0 :       break;
    1767            0 :     case CPP_WSTRING:
    1768            0 :       TREE_TYPE (value) = wchar_array_type_node;
    1769              :     }
    1770           18 :   *valp = fix_string_type (value);
    1771              : 
    1772           18 :   if (concats)
    1773              :     {
    1774            0 :       obstack_free (&str_ob, 0);
    1775            0 :       obstack_free (&loc_ob, 0);
    1776              :     }
    1777              : 
    1778           18 :   return objc_string ? CPP_OBJC_STRING : type;
    1779              : }
    1780              : 
    1781              : /* Converts a (possibly wide) character constant token into a tree.  */
    1782              : static tree
    1783      8691206 : lex_charconst (const cpp_token *token)
    1784              : {
    1785      8691206 :   cppchar_t result;
    1786      8691206 :   tree type, value;
    1787      8691206 :   unsigned int chars_seen;
    1788      8691206 :   int unsignedp = 0;
    1789              : 
    1790      8691206 :   result = cpp_interpret_charconst (parse_in, token,
    1791              :                                     &chars_seen, &unsignedp);
    1792              : 
    1793      8691206 :   if (token->type == CPP_WCHAR)
    1794       505143 :     type = wchar_type_node;
    1795      8186063 :   else if (token->type == CPP_CHAR32)
    1796        18848 :     type = char32_type_node;
    1797      8167215 :   else if (token->type == CPP_CHAR16)
    1798        18445 :     type = char16_type_node;
    1799      8148770 :   else if (token->type == CPP_UTF8CHAR)
    1800              :     {
    1801          194 :       if (flag_char8_t)
    1802          160 :         type = char8_type_node;
    1803              :       else
    1804           34 :         type = char_type_node;
    1805              :     }
    1806              :   /* In C, a character constant has type 'int'.
    1807              :      In C++ 'char', but multi-char charconsts have type 'int'.  */
    1808      8148576 :   else if (!c_dialect_cxx () || chars_seen > 1)
    1809       112729 :     type = integer_type_node;
    1810              :   else
    1811      8035847 :     type = char_type_node;
    1812              : 
    1813              :   /* Cast to cppchar_signed_t to get correct sign-extension of RESULT
    1814              :      before possibly widening to HOST_WIDE_INT for build_int_cst.  */
    1815      8691206 :   if (unsignedp || (cppchar_signed_t) result >= 0)
    1816      8689050 :     value = build_int_cst (type, result);
    1817              :   else
    1818         2156 :     value = build_int_cst (type, (cppchar_signed_t) result);
    1819              : 
    1820      8691206 :   return value;
    1821              : }
    1822              : 
    1823              : /* Helper function for c_parser_peek_conflict_marker
    1824              :    and cp_lexer_peek_conflict_marker.
    1825              :    Given a possible conflict marker token of kind TOK1_KIND
    1826              :    consisting of a pair of characters, get the token kind for the
    1827              :    standalone final character.  */
    1828              : 
    1829              : enum cpp_ttype
    1830          100 : conflict_marker_get_final_tok_kind (enum cpp_ttype tok1_kind)
    1831              : {
    1832          100 :   switch (tok1_kind)
    1833              :     {
    1834            0 :     default: gcc_unreachable ();
    1835              :     case CPP_LSHIFT:
    1836              :       /* "<<" and '<' */
    1837              :       return CPP_LESS;
    1838              : 
    1839           31 :     case CPP_EQ_EQ:
    1840              :       /* "==" and '=' */
    1841           31 :       return CPP_EQ;
    1842              : 
    1843           35 :     case CPP_RSHIFT:
    1844              :       /* ">>" and '>' */
    1845           35 :       return CPP_GREATER;
    1846              :     }
    1847              : }
        

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.