LCOV - code coverage report
Current view: top level - gcc/c - c-decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 6402 5908
Test Date: 2026-06-20 15:32:29 Functions: 93.1 % 188 175
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for C compiler.
       2              :    Copyright (C) 1988-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              : /* Process declarations and symbol lookup for C front end.
      21              :    Also constructs types; the standard scalar types at initialization,
      22              :    and structure, union, array and enum types when they are declared.  */
      23              : 
      24              : /* ??? not all decl nodes are given the most useful possible
      25              :    line numbers.  For example, the CONST_DECLs for enum values.  */
      26              : 
      27              : #include "config.h"
      28              : #define INCLUDE_STRING
      29              : #include "system.h"
      30              : #include "coretypes.h"
      31              : #include "target.h"
      32              : #include "function.h"
      33              : #include "c-tree.h"
      34              : #include "timevar.h"
      35              : #include "stringpool.h"
      36              : #include "cgraph.h"
      37              : #include "intl.h"
      38              : #include "print-tree.h"
      39              : #include "stor-layout.h"
      40              : #include "varasm.h"
      41              : #include "attribs.h"
      42              : #include "toplev.h"
      43              : #include "debug.h"
      44              : #include "c-family/c-objc.h"
      45              : #include "c-family/c-pragma.h"
      46              : #include "c-family/c-ubsan.h"
      47              : #include "c-lang.h"
      48              : #include "langhooks.h"
      49              : #include "tree-iterator.h"
      50              : #include "dumpfile.h"
      51              : #include "plugin.h"
      52              : #include "c-family/c-ada-spec.h"
      53              : #include "builtins.h"
      54              : #include "spellcheck-tree.h"
      55              : #include "gcc-rich-location.h"
      56              : #include "asan.h"
      57              : #include "c-family/name-hint.h"
      58              : #include "c-family/known-headers.h"
      59              : #include "c-family/c-spellcheck.h"
      60              : #include "context.h"  /* For 'g'.  */
      61              : #include "omp-general.h"
      62              : #include "omp-offload.h"  /* For offload_vars.  */
      63              : #include "c-parser.h"
      64              : #include "gcc-urlifier.h"
      65              : 
      66              : #include "tree-pretty-print.h"
      67              : 
      68              : /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
      69              : enum decl_context
      70              : { NORMAL,                       /* Ordinary declaration */
      71              :   FUNCDEF,                      /* Function definition */
      72              :   PARM,                         /* Declaration of parm before function body */
      73              :   FIELD,                        /* Declaration inside struct or union */
      74              :   TYPENAME,                     /* Typename (inside cast or sizeof)  */
      75              :   GENERIC_ASSOC };              /* Typename in generic association  */
      76              : 
      77              : /* States indicating how grokdeclarator() should handle declspecs marked
      78              :    with __attribute__((deprecated)) or __attribute__((unavailable)).
      79              :    An object declared as __attribute__((unavailable)) should suppress
      80              :    any reports of being declared  with unavailable or deprecated items.
      81              :    An object declared as __attribute__((deprecated)) should suppress
      82              :    warnings of uses of other deprecated items.  */
      83              : 
      84              : enum deprecated_states {
      85              :   DEPRECATED_NORMAL,
      86              :   DEPRECATED_SUPPRESS,
      87              :   UNAVAILABLE_DEPRECATED_SUPPRESS
      88              : };
      89              : 
      90              : 
      91              : /* Nonzero if we have seen an invalid cross reference
      92              :    to a struct, union, or enum, but not yet printed the message.  */
      93              : tree pending_invalid_xref;
      94              : 
      95              : /* File and line to appear in the eventual error message.  */
      96              : location_t pending_invalid_xref_location;
      97              : 
      98              : /* The file and line that the prototype came from if this is an
      99              :    old-style definition; used for diagnostics in
     100              :    store_parm_decls_oldstyle.  */
     101              : 
     102              : static location_t current_function_prototype_locus;
     103              : 
     104              : /* Whether this prototype was built-in.  */
     105              : 
     106              : static bool current_function_prototype_built_in;
     107              : 
     108              : /* The argument type information of this prototype.  */
     109              : 
     110              : static tree current_function_prototype_arg_types;
     111              : 
     112              : /* The argument information structure for the function currently being
     113              :    defined.  */
     114              : 
     115              : static struct c_arg_info *current_function_arg_info;
     116              : 
     117              : /* The obstack on which parser and related data structures, which are
     118              :    not live beyond their top-level declaration or definition, are
     119              :    allocated.  */
     120              : struct obstack parser_obstack;
     121              : 
     122              : /* The current statement tree.  */
     123              : 
     124              : static GTY(()) struct stmt_tree_s c_stmt_tree;
     125              : 
     126              : /* Zero if we are not in an iteration or switch statement, otherwise
     127              :    a bitmask.  See bitmask definitions in c-tree.h.  */
     128              : unsigned char in_statement;
     129              : 
     130              : /* A list of decls to be made automatically visible in each file scope.  */
     131              : static GTY(()) tree visible_builtins;
     132              : 
     133              : /* Set to 0 at beginning of a function definition, set to 1 if
     134              :    a return statement that specifies a return value is seen.  */
     135              : 
     136              : int current_function_returns_value;
     137              : 
     138              : /* Set to 0 at beginning of a function definition, set to 1 if
     139              :    a return statement with no argument is seen.  */
     140              : 
     141              : int current_function_returns_null;
     142              : 
     143              : /* Set to 0 at beginning of a function definition, set to 1 if
     144              :    a call to a noreturn function is seen.  */
     145              : 
     146              : int current_function_returns_abnormally;
     147              : 
     148              : /* Set to nonzero by `grokdeclarator' for a function
     149              :    whose return type is defaulted, if warnings for this are desired.  */
     150              : 
     151              : static int warn_about_return_type;
     152              : 
     153              : /* Nonzero when the current toplevel function contains a declaration
     154              :    of a nested function which is never defined.  */
     155              : 
     156              : static bool undef_nested_function;
     157              : 
     158              : /* Vector of implicit "omp declare target" attributes to be added into
     159              :    the attribute lists.  */
     160              : vec<c_omp_declare_target_attr, va_gc> *current_omp_declare_target_attribute;
     161              : 
     162              : /* Vector of
     163              :    #pragma omp begin assumes ... #pragma omp end assumes regions
     164              :    we are in.  */
     165              : vec<c_omp_begin_assumes_data, va_gc> *current_omp_begin_assumes;
     166              : 
     167              : /* Vector of "omp begin/end declare variant" blocks we are in.  */
     168              : vec<c_omp_declare_variant_attr, va_gc> *current_omp_declare_variant_attribute;
     169              : 
     170              : /* Vector of loop names with C_DECL_LOOP_NAME or C_DECL_SWITCH_NAME marked
     171              :    LABEL_DECL as the last and canonical for each loop or switch.  */
     172              : static vec<tree> loop_names;
     173              : 
     174              : /* Hash table mapping LABEL_DECLs to the canonical LABEL_DECLs if LOOP_NAMES
     175              :    vector becomes too long.  */
     176              : static decl_tree_map *loop_names_hash;
     177              : 
     178              : /* Each c_binding structure describes one binding of an identifier to
     179              :    a decl.  All the decls in a scope - irrespective of namespace - are
     180              :    chained together by the ->prev field, which (as the name implies)
     181              :    runs in reverse order.  All the decls in a given namespace bound to
     182              :    a given identifier are chained by the ->shadowed field, which runs
     183              :    from inner to outer scopes.
     184              : 
     185              :    The ->decl field usually points to a DECL node, but there are two
     186              :    exceptions.  In the namespace of type tags, the bound entity is a
     187              :    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
     188              :    identifier is encountered, it is bound to error_mark_node to
     189              :    suppress further errors about that identifier in the current
     190              :    function.
     191              : 
     192              :    The ->u.type field stores the type of the declaration in this scope;
     193              :    if NULL, the type is the type of the ->decl field.  This is only of
     194              :    relevance for objects with external or internal linkage which may
     195              :    be redeclared in inner scopes, forming composite types that only
     196              :    persist for the duration of those scopes.  In the external scope,
     197              :    this stores the composite of all the types declared for this
     198              :    object, visible or not.  The ->inner_comp field (used only at file
     199              :    scope) stores whether an incomplete array type at file scope was
     200              :    completed at an inner scope to an array size other than 1.
     201              : 
     202              :    The ->u.label field is used for labels.  It points to a structure
     203              :    which stores additional information used for warnings.
     204              : 
     205              :    The depth field is copied from the scope structure that holds this
     206              :    decl.  It is used to preserve the proper ordering of the ->shadowed
     207              :    field (see bind()) and also for a handful of special-case checks.
     208              :    Finally, the invisible bit is true for a decl which should be
     209              :    ignored for purposes of normal name lookup, and the nested bit is
     210              :    true for a decl that's been bound a second time in an inner scope;
     211              :    in all such cases, the binding in the outer scope will have its
     212              :    invisible bit true.  */
     213              : 
     214              : struct GTY((chain_next ("%h.prev"))) c_binding {
     215              :   union GTY(()) {               /* first so GTY desc can use decl */
     216              :     tree GTY((tag ("0"))) type; /* the type in this scope */
     217              :     struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */
     218              :   } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u;
     219              :   tree decl;                    /* the decl bound */
     220              :   tree id;                      /* the identifier it's bound to */
     221              :   struct c_binding *prev;       /* the previous decl in this scope */
     222              :   struct c_binding *shadowed;   /* the innermost decl shadowed by this one */
     223              :   unsigned int depth : 28;      /* depth of this scope */
     224              :   BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
     225              :   BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
     226              :   BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
     227              :   BOOL_BITFIELD in_struct : 1;  /* currently defined as struct field */
     228              :   location_t locus;             /* location for nested bindings */
     229              : };
     230              : #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
     231              : #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
     232              : #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
     233              : #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
     234              : 
     235              : /* Each C symbol points to three linked lists of c_binding structures.
     236              :    These describe the values of the identifier in the three different
     237              :    namespaces defined by the language.  */
     238              : 
     239              : struct GTY(()) lang_identifier {
     240              :   struct c_common_identifier common_id;
     241              :   struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
     242              :   struct c_binding *tag_binding;    /* struct/union/enum tags */
     243              :   struct c_binding *label_binding;  /* labels */
     244              : };
     245              : 
     246              : /* Validate c-lang.cc's assumptions.  */
     247              : extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
     248              : [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
     249              : 
     250              : /* The binding oracle; see c-tree.h.  */
     251              : void (*c_binding_oracle) (enum c_oracle_request, tree identifier);
     252              : 
     253              : /* This flag is set on an identifier if we have previously asked the
     254              :    binding oracle for this identifier's symbol binding.  */
     255              : #define I_SYMBOL_CHECKED(node) \
     256              :   (TREE_LANG_FLAG_4 (IDENTIFIER_NODE_CHECK (node)))
     257              : 
     258              : static inline struct c_binding* *
     259   4656447362 : i_symbol_binding (tree node)
     260              : {
     261   4656447362 :   struct lang_identifier *lid
     262   4656447362 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     263              : 
     264   4656447362 :   if (lid->symbol_binding == NULL
     265   1713332916 :       && c_binding_oracle != NULL
     266   4656447362 :       && !I_SYMBOL_CHECKED (node))
     267              :     {
     268              :       /* Set the "checked" flag first, to avoid infinite recursion
     269              :          when the binding oracle calls back into gcc.  */
     270            0 :       I_SYMBOL_CHECKED (node) = 1;
     271            0 :       c_binding_oracle (C_ORACLE_SYMBOL, node);
     272              :     }
     273              : 
     274   4656447362 :   return &lid->symbol_binding;
     275              : }
     276              : 
     277              : #define I_SYMBOL_BINDING(node) (*i_symbol_binding (node))
     278              : 
     279              : #define I_SYMBOL_DECL(node) \
     280              :  (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
     281              : 
     282              : /* This flag is set on an identifier if we have previously asked the
     283              :    binding oracle for this identifier's tag binding.  */
     284              : #define I_TAG_CHECKED(node) \
     285              :   (TREE_LANG_FLAG_5 (IDENTIFIER_NODE_CHECK (node)))
     286              : 
     287              : static inline struct c_binding **
     288      4570286 : i_tag_binding (tree node)
     289              : {
     290      4570286 :   struct lang_identifier *lid
     291      4570286 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     292              : 
     293      4570286 :   if (lid->tag_binding == NULL
     294      1265028 :       && c_binding_oracle != NULL
     295      4570286 :       && !I_TAG_CHECKED (node))
     296              :     {
     297              :       /* Set the "checked" flag first, to avoid infinite recursion
     298              :          when the binding oracle calls back into gcc.  */
     299            0 :       I_TAG_CHECKED (node) = 1;
     300            0 :       c_binding_oracle (C_ORACLE_TAG, node);
     301              :     }
     302              : 
     303      4570286 :   return &lid->tag_binding;
     304              : }
     305              : 
     306              : #define I_TAG_BINDING(node) (*i_tag_binding (node))
     307              : 
     308              : #define I_TAG_DECL(node) \
     309              :  (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
     310              : 
     311              : /* This flag is set on an identifier if we have previously asked the
     312              :    binding oracle for this identifier's label binding.  */
     313              : #define I_LABEL_CHECKED(node) \
     314              :   (TREE_LANG_FLAG_6 (IDENTIFIER_NODE_CHECK (node)))
     315              : 
     316              : static inline struct c_binding **
     317       361716 : i_label_binding (tree node)
     318              : {
     319       361716 :   struct lang_identifier *lid
     320       361716 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     321              : 
     322       361716 :   if (lid->label_binding == NULL
     323        48300 :       && c_binding_oracle != NULL
     324       361716 :       && !I_LABEL_CHECKED (node))
     325              :     {
     326              :       /* Set the "checked" flag first, to avoid infinite recursion
     327              :          when the binding oracle calls back into gcc.  */
     328            0 :       I_LABEL_CHECKED (node) = 1;
     329            0 :       c_binding_oracle (C_ORACLE_LABEL, node);
     330              :     }
     331              : 
     332       361716 :   return &lid->label_binding;
     333              : }
     334              : 
     335              : #define I_LABEL_BINDING(node) (*i_label_binding (node))
     336              : 
     337              : #define I_LABEL_DECL(node) \
     338              :  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
     339              : 
     340              : /* Used by C_TOKEN_VEC tree.  */
     341              : struct GTY (()) c_tree_token_vec {
     342              :   struct tree_base base;
     343              :   vec<c_token, va_gc> *tokens;
     344              : };
     345              : 
     346              : STATIC_ASSERT (sizeof (c_tree_token_vec) == sizeof (c_tree_token_vec_struct));
     347              : STATIC_ASSERT (offsetof (c_tree_token_vec, tokens)
     348              :                == offsetof (c_tree_token_vec_struct, tokens));
     349              : 
     350              : /* The resulting tree type.  */
     351              : 
     352              : union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE + 2 * (TREE_CODE (&%h.generic) == C_TOKEN_VEC)"),
     353              :        chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node
     354              :  {
     355              :   union tree_node GTY ((tag ("0"),
     356              :                         desc ("tree_node_structure (&%h)")))
     357              :     generic;
     358              :   struct lang_identifier GTY ((tag ("1"))) identifier;
     359              :   struct c_tree_token_vec GTY ((tag ("2"))) c_token_vec;
     360              : };
     361              : 
     362              : /* Langhook for tree_size.  */
     363              : size_t
     364          911 : c_tree_size (enum tree_code code)
     365              : {
     366          911 :   gcc_checking_assert (code >= NUM_TREE_CODES);
     367          911 :   switch (code)
     368              :     {
     369              :     case C_TOKEN_VEC: return sizeof (c_tree_token_vec);
     370            0 :     default:
     371            0 :       switch (TREE_CODE_CLASS (code))
     372              :         {
     373              :         case tcc_declaration: return sizeof (tree_decl_non_common);
     374            0 :         case tcc_type: return sizeof (tree_type_non_common);
     375            0 :         default: gcc_unreachable ();
     376              :         }
     377              :     }
     378              : }
     379              : 
     380              : /* Track bindings and other things that matter for goto warnings.  For
     381              :    efficiency, we do not gather all the decls at the point of
     382              :    definition.  Instead, we point into the bindings structure.  As
     383              :    scopes are popped, we update these structures and gather the decls
     384              :    that matter at that time.  */
     385              : 
     386              : struct GTY(()) c_spot_bindings {
     387              :   /* The currently open scope which holds bindings defined when the
     388              :      label was defined or the goto statement was found.  */
     389              :   struct c_scope *scope;
     390              :   /* The bindings in the scope field which were defined at the point
     391              :      of the label or goto.  This lets us look at older or newer
     392              :      bindings in the scope, as appropriate.  */
     393              :   struct c_binding *bindings_in_scope;
     394              :   /* The number of statement expressions that have started since this
     395              :      label or goto statement was defined.  This is zero if we are at
     396              :      the same statement expression level.  It is positive if we are in
     397              :      a statement expression started since this spot.  It is negative
     398              :      if this spot was in a statement expression and we have left
     399              :      it.  */
     400              :   int stmt_exprs;
     401              :   /* Whether we started in a statement expression but are no longer in
     402              :      it.  This is set to true if stmt_exprs ever goes negative.  */
     403              :   bool left_stmt_expr;
     404              : };
     405              : 
     406              : /* This structure is used to keep track of bindings seen when a goto
     407              :    statement is defined.  This is only used if we see the goto
     408              :    statement before we see the label.  */
     409              : 
     410              : struct GTY(()) c_goto_bindings {
     411              :   /* The location of the goto statement.  */
     412              :   location_t loc;
     413              :   /* The bindings of the goto statement.  */
     414              :   struct c_spot_bindings goto_bindings;
     415              : };
     416              : 
     417              : typedef struct c_goto_bindings *c_goto_bindings_p;
     418              : 
     419              : /* The additional information we keep track of for a label binding.
     420              :    These fields are updated as scopes are popped.  */
     421              : 
     422              : struct GTY(()) c_label_vars {
     423              :   /* The shadowed c_label_vars, when one label shadows another (which
     424              :      can only happen using a __label__ declaration).  */
     425              :   struct c_label_vars *shadowed;
     426              :   /* The bindings when the label was defined.  */
     427              :   struct c_spot_bindings label_bindings;
     428              :   /* A list of decls that we care about: decls about which we should
     429              :      warn if a goto branches to this label from later in the function.
     430              :      Decls are added to this list as scopes are popped.  We only add
     431              :      the decls that matter.  */
     432              :   vec<tree, va_gc> *decls_in_scope;
     433              :   /* A list of goto statements to this label.  This is only used for
     434              :      goto statements seen before the label was defined, so that we can
     435              :      issue appropriate warnings for them.  */
     436              :   vec<c_goto_bindings_p, va_gc> *gotos;
     437              : };
     438              : 
     439              : /* Each c_scope structure describes the complete contents of one
     440              :    scope.  Four scopes are distinguished specially: the innermost or
     441              :    current scope, the innermost function scope, the file scope (always
     442              :    the second to outermost) and the outermost or external scope.
     443              : 
     444              :    Most declarations are recorded in the current scope.
     445              : 
     446              :    All normal label declarations are recorded in the innermost
     447              :    function scope, as are bindings of undeclared identifiers to
     448              :    error_mark_node.  (GCC permits nested functions as an extension,
     449              :    hence the 'innermost' qualifier.)  Explicitly declared labels
     450              :    (using the __label__ extension) appear in the current scope.
     451              : 
     452              :    Being in the file scope (current_scope == file_scope) causes
     453              :    special behavior in several places below.  Also, under some
     454              :    conditions the Objective-C front end records declarations in the
     455              :    file scope even though that isn't the current scope.
     456              : 
     457              :    All declarations with external linkage are recorded in the external
     458              :    scope, even if they aren't visible there; this models the fact that
     459              :    such declarations are visible to the entire program, and (with a
     460              :    bit of cleverness, see pushdecl) allows diagnosis of some violations
     461              :    of C99 6.2.2p7 and 6.2.7p2:
     462              : 
     463              :      If, within the same translation unit, the same identifier appears
     464              :      with both internal and external linkage, the behavior is
     465              :      undefined.
     466              : 
     467              :      All declarations that refer to the same object or function shall
     468              :      have compatible type; otherwise, the behavior is undefined.
     469              : 
     470              :    Initially only the built-in declarations, which describe compiler
     471              :    intrinsic functions plus a subset of the standard library, are in
     472              :    this scope.
     473              : 
     474              :    The order of the blocks list matters, and it is frequently appended
     475              :    to.  To avoid having to walk all the way to the end of the list on
     476              :    each insertion, or reverse the list later, we maintain a pointer to
     477              :    the last list entry.  (FIXME: It should be feasible to use a reversed
     478              :    list here.)
     479              : 
     480              :    The bindings list is strictly in reverse order of declarations;
     481              :    pop_scope relies on this.  */
     482              : 
     483              : 
     484              : struct GTY((chain_next ("%h.outer"))) c_scope {
     485              :   /* The scope containing this one.  */
     486              :   struct c_scope *outer;
     487              : 
     488              :   /* The next outermost function scope.  */
     489              :   struct c_scope *outer_function;
     490              : 
     491              :   /* All bindings in this scope.  */
     492              :   struct c_binding *bindings;
     493              : 
     494              :   /* For each scope (except the global one), a chain of BLOCK nodes
     495              :      for all the scopes that were entered and exited one level down.  */
     496              :   tree blocks;
     497              :   tree blocks_last;
     498              : 
     499              :   /* The depth of this scope.  Used to keep the ->shadowed chain of
     500              :      bindings sorted innermost to outermost.  */
     501              :   unsigned int depth : 28;
     502              : 
     503              :   /* True if we are currently filling this scope with parameter
     504              :      declarations.  */
     505              :   BOOL_BITFIELD parm_flag : 1;
     506              : 
     507              :   /* True if we saw [*] in this scope.  Used to give an error messages
     508              :      if these appears in a function definition.  */
     509              :   BOOL_BITFIELD had_vla_unspec : 1;
     510              : 
     511              :   /* True if we parsed a list of forward parameter decls in this scope.  */
     512              :   BOOL_BITFIELD had_forward_parm_decls : 1;
     513              : 
     514              :   /* True if this is the outermost block scope of a function body.
     515              :      This scope contains the parameters, the local variables declared
     516              :      in the outermost block, and all the labels (except those in
     517              :      nested functions, or declared at block scope with __label__).  */
     518              :   BOOL_BITFIELD function_body : 1;
     519              : 
     520              :   /* True means make a BLOCK for this scope no matter what.  */
     521              :   BOOL_BITFIELD keep : 1;
     522              : 
     523              :   /* True means that an unsuffixed float constant is _Decimal64.  */
     524              :   BOOL_BITFIELD float_const_decimal64 : 1;
     525              : 
     526              :   /* True if this scope has any label bindings.  This is used to speed
     527              :      up searching for labels when popping scopes, particularly since
     528              :      labels are normally only found at function scope.  */
     529              :   BOOL_BITFIELD has_label_bindings : 1;
     530              : 
     531              :   /* True if we should issue a warning if a goto statement crosses any
     532              :      of the bindings.  We still need to check the list of bindings to
     533              :      find the specific ones we need to warn about.  This is true if
     534              :      decl_jump_unsafe would return true for any of the bindings.  This
     535              :      is used to avoid looping over all the bindings unnecessarily.  */
     536              :   BOOL_BITFIELD has_jump_unsafe_decl : 1;
     537              : };
     538              : 
     539              : /* The scope currently in effect.  */
     540              : 
     541              : static GTY(()) struct c_scope *current_scope;
     542              : 
     543              : /* The innermost function scope.  Ordinary (not explicitly declared)
     544              :    labels, bindings to error_mark_node, and the lazily-created
     545              :    bindings of __func__ and its friends get this scope.  */
     546              : 
     547              : static GTY(()) struct c_scope *current_function_scope;
     548              : 
     549              : /* The C file scope.  This is reset for each input translation unit.  */
     550              : 
     551              : static GTY(()) struct c_scope *file_scope;
     552              : 
     553              : /* The outermost scope.  This is used for all declarations with
     554              :    external linkage, and only these, hence the name.  */
     555              : 
     556              : static GTY(()) struct c_scope *external_scope;
     557              : 
     558              : /* A chain of c_scope structures awaiting reuse.  */
     559              : 
     560              : static GTY((deletable)) struct c_scope *scope_freelist;
     561              : 
     562              : /* A chain of c_binding structures awaiting reuse.  */
     563              : 
     564              : static GTY((deletable)) struct c_binding *binding_freelist;
     565              : 
     566              : /* Append VAR to LIST in scope SCOPE.  */
     567              : #define SCOPE_LIST_APPEND(scope, list, decl) do {       \
     568              :   struct c_scope *s_ = (scope);                         \
     569              :   tree d_ = (decl);                                     \
     570              :   if (s_->list##_last)                                       \
     571              :     BLOCK_CHAIN (s_->list##_last) = d_;                      \
     572              :   else                                                  \
     573              :     s_->list = d_;                                   \
     574              :   s_->list##_last = d_;                                      \
     575              : } while (0)
     576              : 
     577              : /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE.  */
     578              : #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do {        \
     579              :   struct c_scope *t_ = (tscope);                                \
     580              :   struct c_scope *f_ = (fscope);                                \
     581              :   if (t_->to##_last)                                         \
     582              :     BLOCK_CHAIN (t_->to##_last) = f_->from;                       \
     583              :   else                                                          \
     584              :     t_->to = f_->from;                                            \
     585              :   t_->to##_last = f_->from##_last;                                \
     586              : } while (0)
     587              : 
     588              : /* A c_inline_static structure stores details of a static identifier
     589              :    referenced in a definition of a function that may be an inline
     590              :    definition if no subsequent declaration of that function uses
     591              :    "extern" or does not use "inline".  */
     592              : 
     593              : struct GTY((chain_next ("%h.next"))) c_inline_static {
     594              :   /* The location for a diagnostic.  */
     595              :   location_t location;
     596              : 
     597              :   /* The function that may be an inline definition.  */
     598              :   tree function;
     599              : 
     600              :   /* The object or function referenced.  */
     601              :   tree static_decl;
     602              : 
     603              :   /* What sort of reference this is.  */
     604              :   enum c_inline_static_type type;
     605              : 
     606              :   /* The next such structure or NULL.  */
     607              :   struct c_inline_static *next;
     608              : };
     609              : 
     610              : /* List of static identifiers used or referenced in functions that may
     611              :    be inline definitions.  */
     612              : static GTY(()) struct c_inline_static *c_inline_statics;
     613              : 
     614              : /* True means unconditionally make a BLOCK for the next scope pushed.  */
     615              : 
     616              : static bool keep_next_level_flag;
     617              : 
     618              : /* True means the next call to push_scope will be the outermost scope
     619              :    of a function body, so do not push a new scope, merely cease
     620              :    expecting parameter decls.  */
     621              : 
     622              : static bool next_is_function_body;
     623              : 
     624              : /* A vector of pointers to c_binding structures.  */
     625              : 
     626              : typedef struct c_binding *c_binding_ptr;
     627              : 
     628              : /* Information that we keep for a struct or union while it is being
     629              :    parsed.  */
     630              : 
     631      1183468 : class c_struct_parse_info
     632              : {
     633              : public:
     634              :   /* If warn_cxx_compat, a list of types defined within this
     635              :      struct.  */
     636              :   auto_vec<tree> struct_types;
     637              :   /* If warn_cxx_compat, a list of field names which have bindings,
     638              :      and which are defined in this struct, but which are not defined
     639              :      in any enclosing struct.  This is used to clear the in_struct
     640              :      field of the c_bindings structure.  */
     641              :   auto_vec<c_binding_ptr> fields;
     642              :   /* If warn_cxx_compat, a list of typedef names used when defining
     643              :      fields in this struct.  */
     644              :   auto_vec<tree> typedefs_seen;
     645              :   /* The location of a previous definition of this struct.  */
     646              :   location_t refloc;
     647              : };
     648              : 
     649              : 
     650              : /* Hash table for structs and unions.  */
     651              : struct c_struct_hasher : ggc_ptr_hash<tree_node>
     652              : {
     653              :   static hashval_t hash (tree t);
     654              :   static bool equal (tree, tree);
     655              : };
     656              : 
     657              : /* Hash an RECORD OR UNION.  */
     658              : hashval_t
     659      4378969 : c_struct_hasher::hash (tree type)
     660              : {
     661      4378969 :   inchash::hash hstate;
     662              : 
     663      4378969 :   hstate.add_int (TREE_CODE (type));
     664      4378969 :   tree tag = c_type_tag (type);
     665      4378969 :   hstate.add_object (tag);
     666              : 
     667      4378969 :   return hstate.end ();
     668              : }
     669              : 
     670              : /* Compare two RECORD or UNION types.  */
     671              : bool
     672     14703266 : c_struct_hasher::equal (tree t1,  tree t2)
     673              : {
     674     14703266 :   return comptypes_equiv_p (t1, t2);
     675              : }
     676              : 
     677              : /* All tagged typed so that TYPE_CANONICAL can be set correctly.  */
     678              : static GTY (()) hash_table<c_struct_hasher> *c_struct_htab;
     679              : 
     680              : /* Information for the struct or union currently being parsed, or
     681              :    NULL if not parsing a struct or union.  */
     682              : static class c_struct_parse_info *struct_parse_info;
     683              : 
     684              : /* Forward declarations.  */
     685              : static tree lookup_name_in_scope (tree, struct c_scope *);
     686              : static tree c_make_fname_decl (location_t, tree, int);
     687              : static tree grokdeclarator (const struct c_declarator *,
     688              :                             struct c_declspecs *,
     689              :                             enum decl_context, bool, tree *, tree *, tree *,
     690              :                             bool *, enum deprecated_states);
     691              : static tree grokparms (struct c_arg_info *, bool);
     692              : static void layout_array_type (tree);
     693              : static const char *header_for_builtin_fn (tree);
     694              : 
     695              : /* T is a statement.  Add it to the statement-tree.  This is the
     696              :    C/ObjC version--C++ has a slightly different version of this
     697              :    function.  */
     698              : 
     699              : tree
     700     93817478 : add_stmt (tree t)
     701              : {
     702     93817478 :   enum tree_code code = TREE_CODE (t);
     703              : 
     704     93817478 :   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
     705              :     {
     706     93099917 :       if (!EXPR_HAS_LOCATION (t))
     707       155488 :         SET_EXPR_LOCATION (t, input_location);
     708              :     }
     709              : 
     710              :   /* Add T to the statement-tree.  Non-side-effect statements need to be
     711              :      recorded during statement expressions.  */
     712     93817478 :   if (!building_stmt_list_p ())
     713            1 :     push_stmt_list ();
     714              : 
     715     93817478 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     716      1080644 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     717              : 
     718     93817478 :   append_to_statement_list_force (t, &cur_stmt_list);
     719              : 
     720     93817478 :   return t;
     721              : }
     722              : 
     723              : 
     724              : 
     725              : 
     726              : 
     727              : /* Return true if we will want to say something if a goto statement
     728              :    crosses DECL.  */
     729              : 
     730              : static bool
     731    925131120 : decl_jump_unsafe (tree decl)
     732              : {
     733    925131120 :   if (error_operand_p (decl))
     734              :     return false;
     735              : 
     736              :   /* Don't warn for compound literals.  If a goto statement crosses
     737              :      their initialization, it should cross also all the places where
     738              :      the complit is used or where the complit address might be saved
     739              :      into some variable, so code after the label to which goto jumps
     740              :      should not be able to refer to the compound literal.  */
     741    925128851 :   if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl))
     742              :     return false;
     743              : 
     744    924209178 :   if (flag_openmp
     745     12916232 :       && VAR_P (decl)
     746    924240664 :       && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
     747              :     return true;
     748              : 
     749              :   /* Always warn about crossing variably modified types.  */
     750    914166600 :   if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
     751    936590514 :       && c_type_variably_modified_p (TREE_TYPE (decl)))
     752              :     return true;
     753              : 
     754              :   /* Otherwise, only warn if -Wgoto-misses-init and this is an
     755              :      initialized automatic decl.  */
     756    924168651 :   if (warn_jump_misses_init
     757      6074293 :       && VAR_P (decl)
     758        10221 :       && !TREE_STATIC (decl)
     759    924174102 :       && DECL_INITIAL (decl) != NULL_TREE)
     760              :     return true;
     761              : 
     762              :   return false;
     763              : }
     764              : 
     765              : 
     766              : void
     767            0 : c_print_identifier (FILE *file, tree node, int indent)
     768              : {
     769            0 :   void (*save) (enum c_oracle_request, tree identifier);
     770              : 
     771              :   /* Temporarily hide any binding oracle.  Without this, calls to
     772              :      debug_tree from the debugger will end up calling into the oracle,
     773              :      making for a confusing debug session.  As the oracle isn't needed
     774              :      here for normal operation, it's simplest to suppress it.  */
     775            0 :   save = c_binding_oracle;
     776            0 :   c_binding_oracle = NULL;
     777              : 
     778            0 :   print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
     779            0 :   print_node (file, "tag", I_TAG_DECL (node), indent + 4);
     780            0 :   print_node (file, "label", I_LABEL_DECL (node), indent + 4);
     781            0 :   if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
     782              :     {
     783            0 :       tree rid = ridpointers[C_RID_CODE (node)];
     784            0 :       indent_to (file, indent + 4);
     785            0 :       fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
     786            0 :                (void *) rid, IDENTIFIER_POINTER (rid));
     787              :     }
     788              : 
     789            0 :   c_binding_oracle = save;
     790            0 : }
     791              : 
     792              : /* Establish that the scope contains declarations that are sensitive to
     793              :    jumps that cross a binding.  Together with decl_jump_unsafe, this is
     794              :    used to diagnose such jumps.  */
     795              : void
     796           93 : c_mark_decl_jump_unsafe_in_current_scope ()
     797              : {
     798           93 :   current_scope->has_jump_unsafe_decl = 1;
     799           93 : }
     800              : 
     801              : /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
     802              :    which may be any of several kinds of DECL or TYPE or error_mark_node,
     803              :    in the scope SCOPE.  */
     804              : static void
     805    924981965 : bind (tree name, tree decl, struct c_scope *scope, bool invisible,
     806              :       bool nested, location_t locus)
     807              : {
     808    924981965 :   struct c_binding *b, **here;
     809              : 
     810    924981965 :   if (binding_freelist)
     811              :     {
     812    231153488 :       b = binding_freelist;
     813    231153488 :       binding_freelist = b->prev;
     814              :     }
     815              :   else
     816    693828477 :     b = ggc_alloc<c_binding> ();
     817              : 
     818    924981965 :   b->shadowed = 0;
     819    924981965 :   b->decl = decl;
     820    924981965 :   b->id = name;
     821    924981965 :   b->depth = scope->depth;
     822    924981965 :   b->invisible = invisible;
     823    924981965 :   b->nested = nested;
     824    924981965 :   b->inner_comp = 0;
     825    924981965 :   b->in_struct = 0;
     826    924981965 :   b->locus = locus;
     827              : 
     828    924981965 :   b->u.type = NULL;
     829              : 
     830    924981965 :   b->prev = scope->bindings;
     831    924981965 :   scope->bindings = b;
     832              : 
     833    924981965 :   if (decl_jump_unsafe (decl))
     834        24211 :     scope->has_jump_unsafe_decl = 1;
     835              : 
     836    924981965 :   if (!name)
     837              :     return;
     838              : 
     839    916240983 :   switch (TREE_CODE (decl))
     840              :     {
     841        24179 :     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
     842       631830 :     case ENUMERAL_TYPE:
     843       631830 :     case UNION_TYPE:
     844       631830 :     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
     845    915584974 :     case VAR_DECL:
     846    915584974 :     case FUNCTION_DECL:
     847    915584974 :     case TYPE_DECL:
     848    915584974 :     case CONST_DECL:
     849    915584974 :     case PARM_DECL:
     850    915584974 :     case ERROR_MARK:     here = &I_SYMBOL_BINDING (name);  break;
     851              : 
     852            0 :     default:
     853            0 :       gcc_unreachable ();
     854              :     }
     855              : 
     856              :   /* Locate the appropriate place in the chain of shadowed decls
     857              :      to insert this binding.  Normally, scope == current_scope and
     858              :      this does nothing.  */
     859    916241027 :   while (*here && (*here)->depth > scope->depth)
     860           44 :     here = &(*here)->shadowed;
     861              : 
     862    916240983 :   b->shadowed = *here;
     863    916240983 :   *here = b;
     864              : }
     865              : 
     866              : /* Clear the binding structure B, stick it on the binding_freelist,
     867              :    and return the former value of b->prev.  This is used by pop_scope
     868              :    and get_parm_info to iterate destructively over all the bindings
     869              :    from a given scope.  */
     870              : static struct c_binding *
     871    906478038 : free_binding_and_advance (struct c_binding *b)
     872              : {
     873    906478038 :   struct c_binding *prev = b->prev;
     874              : 
     875    906478038 :   memset (b, 0, sizeof (struct c_binding));
     876    906478038 :   b->prev = binding_freelist;
     877    906478038 :   binding_freelist = b;
     878              : 
     879    906478038 :   return prev;
     880              : }
     881              : 
     882              : /* Bind a label.  Like bind, but skip fields which aren't used for
     883              :    labels, and add the LABEL_VARS value.  */
     884              : static void
     885        24179 : bind_label (tree name, tree label, struct c_scope *scope,
     886              :             struct c_label_vars *label_vars)
     887              : {
     888        24179 :   struct c_binding *b;
     889              : 
     890        24179 :   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
     891              :         UNKNOWN_LOCATION);
     892              : 
     893        24179 :   scope->has_label_bindings = true;
     894              : 
     895        24179 :   b = scope->bindings;
     896        24179 :   gcc_assert (b->decl == label);
     897        24179 :   label_vars->shadowed = b->u.label;
     898        24179 :   b->u.label = label_vars;
     899        24179 : }
     900              : 
     901              : /* Hook called at end of compilation to assume 1 elt
     902              :    for a file-scope tentative array defn that wasn't complete before.  */
     903              : 
     904              : void
     905         7498 : c_finish_incomplete_decl (tree decl)
     906              : {
     907         7498 :   if (VAR_P (decl))
     908              :     {
     909         7498 :       tree type = TREE_TYPE (decl);
     910         7498 :       if (type != error_mark_node
     911         7421 :           && TREE_CODE (type) == ARRAY_TYPE
     912         7226 :           && !DECL_EXTERNAL (decl)
     913         7587 :           && TYPE_DOMAIN (type) == NULL_TREE)
     914              :         {
     915           89 :           if (flag_isoc2y && !TREE_PUBLIC (decl))
     916            2 :             error_at (DECL_SOURCE_LOCATION (decl),
     917              :                       "array size missing in %q+D", decl);
     918              :           else
     919           87 :             warning_at (DECL_SOURCE_LOCATION (decl),
     920           87 :                         0, "array %q+D assumed to have one element", decl);
     921              : 
     922           89 :           complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
     923              : 
     924           89 :           relayout_decl (decl);
     925              :         }
     926              :     }
     927         7498 : }
     928              : 
     929              : /* Record that inline function FUNC contains a reference (location
     930              :    LOC) to static DECL (file-scope or function-local according to
     931              :    TYPE).  */
     932              : 
     933              : void
     934           36 : record_inline_static (location_t loc, tree func, tree decl,
     935              :                       enum c_inline_static_type type)
     936              : {
     937           36 :   c_inline_static *csi = ggc_alloc<c_inline_static> ();
     938           36 :   csi->location = loc;
     939           36 :   csi->function = func;
     940           36 :   csi->static_decl = decl;
     941           36 :   csi->type = type;
     942           36 :   csi->next = c_inline_statics;
     943           36 :   c_inline_statics = csi;
     944           36 : }
     945              : 
     946              : /* Check for references to static declarations in inline functions at
     947              :    the end of the translation unit and diagnose them if the functions
     948              :    are still inline definitions.  */
     949              : 
     950              : static void
     951       110626 : check_inline_statics (void)
     952              : {
     953       110626 :   struct c_inline_static *csi;
     954       110662 :   for (csi = c_inline_statics; csi; csi = csi->next)
     955              :     {
     956           36 :       if (DECL_EXTERNAL (csi->function))
     957           30 :         switch (csi->type)
     958              :           {
     959           23 :           case csi_internal:
     960           23 :             pedwarn (csi->location, 0,
     961              :                      "%qD is static but used in inline function %qD "
     962              :                      "which is not static", csi->static_decl, csi->function);
     963           23 :             break;
     964            7 :           case csi_modifiable:
     965            7 :             pedwarn (csi->location, 0,
     966              :                      "%q+D is static but declared in inline function %qD "
     967              :                      "which is not static", csi->static_decl, csi->function);
     968            7 :             break;
     969            0 :           default:
     970            0 :             gcc_unreachable ();
     971              :           }
     972              :     }
     973       110626 :   c_inline_statics = NULL;
     974       110626 : }
     975              : 
     976              : /* Fill in a c_spot_bindings structure.  If DEFINING is true, set it
     977              :    for the current state, otherwise set it to uninitialized.  */
     978              : 
     979              : static void
     980       135509 : set_spot_bindings (struct c_spot_bindings *p, bool defining)
     981              : {
     982            0 :   if (defining)
     983              :     {
     984       128249 :       p->scope = current_scope;
     985        16919 :       p->bindings_in_scope = current_scope->bindings;
     986              :     }
     987              :   else
     988              :     {
     989         7260 :       p->scope = NULL;
     990         7260 :       p->bindings_in_scope = NULL;
     991              :     }
     992       135509 :   p->stmt_exprs = 0;
     993       135509 :   p->left_stmt_expr = false;
     994            0 : }
     995              : 
     996              : /* Update spot bindings P as we pop out of SCOPE.  Return true if we
     997              :    should push decls for a label.  */
     998              : 
     999              : static bool
    1000    470623601 : update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p)
    1001              : {
    1002            0 :   if (p->scope != scope)
    1003              :     {
    1004              :       /* This label or goto is defined in some other scope, or it is a
    1005              :          label which is not yet defined.  There is nothing to
    1006              :          update.  */
    1007              :       return false;
    1008              :     }
    1009              : 
    1010              :   /* Adjust the spot bindings to refer to the bindings already defined
    1011              :      in the enclosing scope.  */
    1012       206935 :   p->scope = scope->outer;
    1013       206935 :   p->bindings_in_scope = p->scope->bindings;
    1014              : 
    1015       152395 :   return true;
    1016              : }
    1017              : 
    1018              : /* The Objective-C front-end often needs to determine the current scope.  */
    1019              : 
    1020              : void *
    1021            0 : objc_get_current_scope (void)
    1022              : {
    1023            0 :   return current_scope;
    1024              : }
    1025              : 
    1026              : /* The following function is used only by Objective-C.  It needs to live here
    1027              :    because it accesses the innards of c_scope.  */
    1028              : 
    1029              : void
    1030            0 : objc_mark_locals_volatile (void *enclosing_blk)
    1031              : {
    1032            0 :   struct c_scope *scope;
    1033            0 :   struct c_binding *b;
    1034              : 
    1035            0 :   for (scope = current_scope;
    1036            0 :        scope && scope != enclosing_blk;
    1037            0 :        scope = scope->outer)
    1038              :     {
    1039            0 :       for (b = scope->bindings; b; b = b->prev)
    1040            0 :         objc_volatilize_decl (b->decl);
    1041              : 
    1042              :       /* Do not climb up past the current function.  */
    1043            0 :       if (scope->function_body)
    1044              :         break;
    1045              :     }
    1046            0 : }
    1047              : 
    1048              : /* Return true if we are in the global binding level.  */
    1049              : 
    1050              : bool
    1051      2093915 : global_bindings_p (void)
    1052              : {
    1053      2093915 :   return current_scope == file_scope;
    1054              : }
    1055              : 
    1056              : /* Return true if we're declaring parameters in an old-style function
    1057              :    declaration.  */
    1058              : 
    1059              : bool
    1060        34936 : old_style_parameter_scope (void)
    1061              : {
    1062              :   /* If processing parameters and there is no function statement list, we
    1063              :    * have an old-style function declaration.  */
    1064        34936 :   return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl));
    1065              : }
    1066              : 
    1067              : void
    1068        52345 : keep_next_level (void)
    1069              : {
    1070        52345 :   keep_next_level_flag = true;
    1071        52345 : }
    1072              : 
    1073              : /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON.  */
    1074              : 
    1075              : void
    1076           20 : set_float_const_decimal64 (void)
    1077              : {
    1078           20 :   current_scope->float_const_decimal64 = true;
    1079           20 : }
    1080              : 
    1081              : /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma.  */
    1082              : 
    1083              : void
    1084           28 : clear_float_const_decimal64 (void)
    1085              : {
    1086           28 :   current_scope->float_const_decimal64 = false;
    1087           28 : }
    1088              : 
    1089              : /* Return nonzero if an unsuffixed float constant is _Decimal64.  */
    1090              : 
    1091              : bool
    1092       602410 : float_const_decimal64_p (void)
    1093              : {
    1094       602410 :   return current_scope->float_const_decimal64;
    1095              : }
    1096              : 
    1097              : /* Identify this scope as currently being filled with parameters.  */
    1098              : 
    1099              : void
    1100     87346736 : declare_parm_level (void)
    1101              : {
    1102     87346736 :   current_scope->parm_flag = true;
    1103     87346736 : }
    1104              : 
    1105              : void
    1106    128680900 : push_scope (void)
    1107              : {
    1108    128680900 :   if (next_is_function_body)
    1109              :     {
    1110              :       /* This is the transition from the parameters to the top level
    1111              :          of the function body.  These are the same scope
    1112              :          (C99 6.2.1p4,6) so we do not push another scope structure.
    1113              :          next_is_function_body is set only by store_parm_decls, which
    1114              :          in turn is called when and only when we are about to
    1115              :          encounter the opening curly brace for the function body.
    1116              : 
    1117              :          The outermost block of a function always gets a BLOCK node,
    1118              :          because the debugging output routines expect that each
    1119              :          function has at least one BLOCK.  */
    1120     36332374 :       current_scope->parm_flag         = false;
    1121     36332374 :       current_scope->function_body     = true;
    1122     36332374 :       current_scope->keep              = true;
    1123     36332374 :       current_scope->outer_function    = current_function_scope;
    1124     36332374 :       current_function_scope           = current_scope;
    1125              : 
    1126     36332374 :       keep_next_level_flag = false;
    1127     36332374 :       next_is_function_body = false;
    1128              : 
    1129              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1130     36332374 :       if (current_scope->outer)
    1131     36332374 :         current_scope->float_const_decimal64
    1132     36332374 :           = current_scope->outer->float_const_decimal64;
    1133              :       else
    1134            0 :         current_scope->float_const_decimal64 = false;
    1135              :     }
    1136              :   else
    1137              :     {
    1138     92348526 :       struct c_scope *scope;
    1139     92348526 :       if (scope_freelist)
    1140              :         {
    1141     91481623 :           scope = scope_freelist;
    1142     91481623 :           scope_freelist = scope->outer;
    1143              :         }
    1144              :       else
    1145       866903 :         scope = ggc_cleared_alloc<c_scope> ();
    1146              : 
    1147              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1148     92348526 :       if (current_scope)
    1149     92231898 :         scope->float_const_decimal64 = current_scope->float_const_decimal64;
    1150              :       else
    1151       116628 :         scope->float_const_decimal64 = false;
    1152              : 
    1153     92348526 :       scope->keep          = keep_next_level_flag;
    1154     92348526 :       scope->outer         = current_scope;
    1155     92348526 :       scope->depth      = current_scope ? (current_scope->depth + 1) : 0;
    1156              : 
    1157              :       /* Check for scope depth overflow.  Unlikely (2^28 == 268,435,456) but
    1158              :          possible.  */
    1159     92348526 :       if (current_scope && scope->depth == 0)
    1160              :         {
    1161            0 :           scope->depth--;
    1162            0 :           sorry ("GCC supports only %u nested scopes", scope->depth);
    1163              :         }
    1164              : 
    1165     92348526 :       current_scope        = scope;
    1166     92348526 :       keep_next_level_flag = false;
    1167              :     }
    1168    128680900 : }
    1169              : 
    1170              : /* This is called when we are leaving SCOPE.  For each label defined
    1171              :    in SCOPE, add any appropriate decls to its decls_in_scope fields.
    1172              :    These are the decls whose initialization will be skipped by a goto
    1173              :    later in the function.  */
    1174              : 
    1175              : static void
    1176     92341596 : update_label_decls (struct c_scope *scope)
    1177              : {
    1178     92341596 :   struct c_scope *s;
    1179              : 
    1180     92341596 :   s = scope;
    1181    333312799 :   while (s != NULL)
    1182              :     {
    1183    282093439 :       if (s->has_label_bindings)
    1184              :         {
    1185       234320 :           struct c_binding *b;
    1186              : 
    1187      2178285 :           for (b = s->bindings; b != NULL; b = b->prev)
    1188              :             {
    1189      1943965 :               struct c_label_vars *label_vars;
    1190      1943965 :               struct c_binding *b1;
    1191      1943965 :               bool hjud;
    1192      1943965 :               unsigned int ix;
    1193      1943965 :               struct c_goto_bindings *g;
    1194              : 
    1195      1943965 :               if (TREE_CODE (b->decl) != LABEL_DECL)
    1196      1433902 :                 continue;
    1197       510063 :               label_vars = b->u.label;
    1198              : 
    1199       510063 :               b1 = label_vars->label_bindings.bindings_in_scope;
    1200       510063 :               if (label_vars->label_bindings.scope == NULL)
    1201              :                 hjud = false;
    1202              :               else
    1203       198498 :                 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
    1204       510063 :               if (update_spot_bindings (scope, &label_vars->label_bindings))
    1205              :                 {
    1206              :                   /* This label is defined in this scope.  */
    1207        54540 :                   if (hjud)
    1208              :                     {
    1209       169690 :                       for (; b1 != NULL; b1 = b1->prev)
    1210              :                         {
    1211              :                           /* A goto from later in the function to this
    1212              :                              label will never see the initialization
    1213              :                              of B1, if any.  Save it to issue a
    1214              :                              warning if needed.  */
    1215       148267 :                           if (decl_jump_unsafe (b1->decl))
    1216        19464 :                             vec_safe_push(label_vars->decls_in_scope, b1->decl);
    1217              :                         }
    1218              :                     }
    1219              :                 }
    1220              : 
    1221              :               /* Update the bindings of any goto statements associated
    1222              :                  with this label.  */
    1223    472352771 :               FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1224    470265933 :                 update_spot_bindings (scope, &g->goto_bindings);
    1225              :             }
    1226              :         }
    1227              : 
    1228              :       /* Don't search beyond the current function.  */
    1229    282093439 :       if (s == current_function_scope)
    1230              :         break;
    1231              : 
    1232    240971203 :       s = s->outer;
    1233              :     }
    1234     92341596 : }
    1235              : 
    1236              : /* Exit a scope.  Restore the state of the identifier-decl mappings
    1237              :    that were in effect when this scope was entered.  Return a BLOCK
    1238              :    node containing all the DECLs in this scope that are of interest
    1239              :    to debug info generation.  */
    1240              : 
    1241              : tree
    1242     92341596 : pop_scope (void)
    1243              : {
    1244     92341596 :   struct c_scope *scope = current_scope;
    1245     92341596 :   tree block, context, p;
    1246     92341596 :   struct c_binding *b;
    1247              : 
    1248     92341596 :   bool functionbody = scope->function_body;
    1249     92341596 :   bool keep = functionbody || scope->keep || scope->bindings;
    1250              : 
    1251     92341596 :   update_label_decls (scope);
    1252              : 
    1253              :   /* If appropriate, create a BLOCK to record the decls for the life
    1254              :      of this function.  */
    1255     92341596 :   block = NULL_TREE;
    1256     92341596 :   if (keep)
    1257              :     {
    1258     36833038 :       block = make_node (BLOCK);
    1259     36833038 :       BLOCK_SUBBLOCKS (block) = scope->blocks;
    1260     36833038 :       TREE_USED (block) = 1;
    1261              : 
    1262              :       /* In each subblock, record that this is its superior.  */
    1263     37113207 :       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
    1264       280169 :         BLOCK_SUPERCONTEXT (p) = block;
    1265              : 
    1266     36833038 :       BLOCK_VARS (block) = NULL_TREE;
    1267              :     }
    1268              : 
    1269              :   /* The TYPE_CONTEXTs for all of the tagged types belonging to this
    1270              :      scope must be set so that they point to the appropriate
    1271              :      construct, i.e.  either to the current FUNCTION_DECL node, or
    1272              :      else to the BLOCK node we just constructed.
    1273              : 
    1274              :      Note that for tagged types whose scope is just the formal
    1275              :      parameter list for some function type specification, we can't
    1276              :      properly set their TYPE_CONTEXTs here, because we don't have a
    1277              :      pointer to the appropriate FUNCTION_TYPE node readily available
    1278              :      to us.  For those cases, the TYPE_CONTEXTs of the relevant tagged
    1279              :      type nodes get set in `grokdeclarator' as soon as we have created
    1280              :      the FUNCTION_TYPE node which will represent the "scope" for these
    1281              :      "parameter list local" tagged types.  */
    1282     92341596 :   if (scope->function_body)
    1283     36332373 :     context = current_function_decl;
    1284     56009223 :   else if (scope == file_scope)
    1285              :     {
    1286       110249 :       tree file_decl
    1287       110249 :         = build_translation_unit_decl (get_identifier (main_input_filename));
    1288       110249 :       context = file_decl;
    1289       110249 :       debug_hooks->register_main_translation_unit (file_decl);
    1290              :     }
    1291              :   else
    1292              :     context = block;
    1293              : 
    1294              :   /* Clear all bindings in this scope.  */
    1295    875053587 :   for (b = scope->bindings; b; b = free_binding_and_advance (b))
    1296              :     {
    1297    782711991 :       p = b->decl;
    1298    782711991 :       switch (TREE_CODE (p))
    1299              :         {
    1300        24179 :         case LABEL_DECL:
    1301              :           /* Warnings for unused labels, errors for undefined labels.  */
    1302        24179 :           if (TREE_USED (p) && !DECL_INITIAL (p))
    1303              :             {
    1304           63 :               error ("label %q+D used but not defined", p);
    1305           63 :               DECL_INITIAL (p) = error_mark_node;
    1306              :             }
    1307              :           else
    1308        24116 :             warn_for_unused_label (p);
    1309              : 
    1310              :           /* Labels go in BLOCK_VARS.  */
    1311        24179 :           DECL_CHAIN (p) = BLOCK_VARS (block);
    1312        24179 :           BLOCK_VARS (block) = p;
    1313        24179 :           gcc_assert (I_LABEL_BINDING (b->id) == b);
    1314        24179 :           I_LABEL_BINDING (b->id) = b->shadowed;
    1315              : 
    1316              :           /* Also pop back to the shadowed label_vars.  */
    1317        24179 :           release_tree_vector (b->u.label->decls_in_scope);
    1318        24179 :           b->u.label = b->u.label->shadowed;
    1319        24179 :           break;
    1320              : 
    1321      1433115 :         case ENUMERAL_TYPE:
    1322      1433115 :         case UNION_TYPE:
    1323      1433115 :         case RECORD_TYPE:
    1324              : 
    1325              :           /* Types may not have tag-names, in which case the type
    1326              :              appears in the bindings list with b->id NULL.  */
    1327      1433115 :           if (b->id)
    1328              :             {
    1329       630004 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    1330       630004 :               I_TAG_BINDING (b->id) = b->shadowed;
    1331              :             }
    1332              :           break;
    1333              : 
    1334    652496869 :         case FUNCTION_DECL:
    1335              :           /* Propagate TREE_ADDRESSABLE from nested functions to their
    1336              :              containing functions.  */
    1337    652496869 :           if (!TREE_ASM_WRITTEN (p)
    1338    652496869 :               && DECL_INITIAL (p) != NULL_TREE
    1339     72304153 :               && TREE_ADDRESSABLE (p)
    1340      3692799 :               && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
    1341    652496869 :               && DECL_ABSTRACT_ORIGIN (p) != p)
    1342            0 :             TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
    1343    652496869 :           if (!TREE_PUBLIC (p)
    1344       359953 :               && !DECL_INITIAL (p)
    1345          170 :               && !b->nested
    1346          139 :               && scope != file_scope
    1347    652496877 :               && scope != external_scope)
    1348              :             {
    1349            8 :               error ("nested function %q+D declared but never defined", p);
    1350            8 :               undef_nested_function = true;
    1351              :             }
    1352    652496861 :           else if (DECL_DECLARED_INLINE_P (p)
    1353     71108309 :                    && TREE_PUBLIC (p)
    1354    723444767 :                    && !DECL_INITIAL (p))
    1355              :             {
    1356              :               /* C99 6.7.4p6: "a function with external linkage... declared
    1357              :                  with an inline function specifier ... shall also be defined
    1358              :                  in the same translation unit."  */
    1359           76 :               if (!flag_gnu89_inline
    1360           51 :                   && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (p))
    1361          111 :                   && scope == external_scope)
    1362           13 :                 pedwarn (input_location, 0,
    1363              :                          "inline function %q+D declared but never defined", p);
    1364           76 :               DECL_EXTERNAL (p) = 1;
    1365              :             }
    1366              : 
    1367    652496869 :           goto common_symbol;
    1368              : 
    1369     10954019 :         case VAR_DECL:
    1370              :           /* Warnings for unused variables.  */
    1371      8396825 :           if ((!TREE_USED (p) || !DECL_READ_P (p))
    1372      2586755 :               && !warning_suppressed_p (p, OPT_Wunused_but_set_variable_)
    1373      2586245 :               && !DECL_IN_SYSTEM_HEADER (p)
    1374      2504696 :               && DECL_NAME (p)
    1375      2504696 :               && !DECL_ARTIFICIAL (p)
    1376      2504309 :               && scope != file_scope
    1377     12574974 :               && scope != external_scope)
    1378              :             {
    1379       739260 :               if (!TREE_USED (p))
    1380              :                 {
    1381       733533 :                   warning (OPT_Wunused_variable, "unused variable %q+D", p);
    1382       733533 :                   suppress_warning (p, OPT_Wunused_variable);
    1383              :                 }
    1384         5727 :               else if (DECL_CONTEXT (p) == current_function_decl)
    1385         5706 :                 warning_at (DECL_SOURCE_LOCATION (p),
    1386         5706 :                             OPT_Wunused_but_set_variable_,
    1387              :                             "variable %qD set but not used", p);
    1388              :             }
    1389              : 
    1390     10954019 :           if (b->inner_comp)
    1391              :             {
    1392            2 :               error ("type of array %q+D completed incompatibly with"
    1393              :                      " implicit initialization", p);
    1394              :             }
    1395              : 
    1396              :           /* Fall through.  */
    1397    681164910 :         case TYPE_DECL:
    1398    681164910 :         case CONST_DECL:
    1399     10954017 :         common_symbol:
    1400              :           /* All of these go in BLOCK_VARS, but only if this is the
    1401              :              binding in the home scope.  */
    1402    681164910 :           if (!b->nested)
    1403              :             {
    1404    409717289 :               DECL_CHAIN (p) = BLOCK_VARS (block);
    1405    409717289 :               BLOCK_VARS (block) = p;
    1406              :             }
    1407    271447621 :           else if (VAR_OR_FUNCTION_DECL_P (p) && scope != file_scope)
    1408              :             {
    1409              :               /* For block local externs add a special
    1410              :                  DECL_EXTERNAL decl for debug info generation.  */
    1411        14596 :               tree extp = copy_node (p);
    1412              : 
    1413        14596 :               DECL_EXTERNAL (extp) = 1;
    1414        14596 :               TREE_STATIC (extp) = 0;
    1415        14596 :               TREE_PUBLIC (extp) = 1;
    1416        14596 :               DECL_INITIAL (extp) = NULL_TREE;
    1417        14596 :               DECL_LANG_SPECIFIC (extp) = NULL;
    1418        14596 :               DECL_CONTEXT (extp) = current_function_decl;
    1419        14596 :               if (TREE_CODE (p) == FUNCTION_DECL)
    1420              :                 {
    1421        13057 :                   DECL_RESULT (extp) = NULL_TREE;
    1422        13057 :                   DECL_SAVED_TREE (extp) = NULL_TREE;
    1423        13057 :                   DECL_STRUCT_FUNCTION (extp) = NULL;
    1424              :                 }
    1425        14596 :               if (b->locus != UNKNOWN_LOCATION)
    1426        14596 :                 DECL_SOURCE_LOCATION (extp) = b->locus;
    1427        14596 :               DECL_CHAIN (extp) = BLOCK_VARS (block);
    1428        14596 :               BLOCK_VARS (block) = extp;
    1429              :             }
    1430              :           /* If this is the file scope set DECL_CONTEXT of each decl to
    1431              :              the TRANSLATION_UNIT_DECL.  This makes same_translation_unit_p
    1432              :              work.  */
    1433    681164910 :           if (scope == file_scope)
    1434    282870363 :               DECL_CONTEXT (p) = context;
    1435              : 
    1436    781254697 :           gcc_fallthrough ();
    1437              :           /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
    1438              :              already been put there by store_parm_decls.  Unused-
    1439              :              parameter warnings are handled by function.cc.
    1440              :              error_mark_node obviously does not go in BLOCK_VARS and
    1441              :              does not get unused-variable warnings.  */
    1442    781254697 :         case PARM_DECL:
    1443    781254697 :         case ERROR_MARK:
    1444              :           /* It is possible for a decl not to have a name.  We get
    1445              :              here with b->id NULL in this case.  */
    1446    781254697 :           if (b->id)
    1447              :             {
    1448    778013053 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    1449    778013053 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    1450    778013053 :               if (b->shadowed && b->shadowed->u.type)
    1451      4781866 :                 TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
    1452              :             }
    1453              :           break;
    1454              : 
    1455            0 :         default:
    1456            0 :           gcc_unreachable ();
    1457              :         }
    1458              :     }
    1459              : 
    1460              : 
    1461              :   /* Dispose of the block that we just made inside some higher level.  */
    1462     92341596 :   if ((scope->function_body || scope == file_scope) && context)
    1463              :     {
    1464     36442620 :       DECL_INITIAL (context) = block;
    1465     36442620 :       BLOCK_SUPERCONTEXT (block) = context;
    1466              :     }
    1467     55898976 :   else if (scope->outer)
    1468              :     {
    1469     55788727 :       if (block)
    1470       280169 :         SCOPE_LIST_APPEND (scope->outer, blocks, block);
    1471              :       /* If we did not make a block for the scope just exited, any
    1472              :          blocks made for inner scopes must be carried forward so they
    1473              :          will later become subblocks of something else.  */
    1474     55508558 :       else if (scope->blocks)
    1475       360099 :         SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
    1476              :     }
    1477              : 
    1478              :   /* Pop the current scope, and free the structure for reuse.  */
    1479     92341596 :   current_scope = scope->outer;
    1480     92341596 :   if (scope->function_body)
    1481     36332373 :     current_function_scope = scope->outer_function;
    1482              : 
    1483     92341596 :   memset (scope, 0, sizeof (struct c_scope));
    1484     92341596 :   scope->outer = scope_freelist;
    1485     92341596 :   scope_freelist = scope;
    1486              : 
    1487     92341596 :   return block;
    1488              : }
    1489              : 
    1490              : void
    1491       110798 : push_file_scope (void)
    1492              : {
    1493       110798 :   tree decl;
    1494              : 
    1495       110798 :   if (file_scope)
    1496              :     return;
    1497              : 
    1498              :   /* Call the target stack_protect_guard hook if the stack protection
    1499              :      guard is declared as a global symbol.  */
    1500       110798 :   if (targetm.stack_protect_guard_symbol_p ())
    1501              :     {
    1502           16 :       tree decl = targetm.stack_protect_guard ();
    1503           16 :       DECL_CHAIN (decl) = visible_builtins;
    1504           16 :       visible_builtins = decl;
    1505              :     }
    1506              : 
    1507       110798 :   push_scope ();
    1508       110798 :   file_scope = current_scope;
    1509              : 
    1510       110798 :   start_fname_decls ();
    1511              : 
    1512    221800495 :   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
    1513    221689697 :     bind (DECL_NAME (decl), decl, file_scope,
    1514    221689697 :           /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
    1515              : }
    1516              : 
    1517              : void
    1518       110626 : pop_file_scope (void)
    1519              : {
    1520              :   /* In case there were missing closebraces, get us back to the global
    1521              :      binding level.  */
    1522       110631 :   while (current_scope != file_scope)
    1523            5 :     pop_scope ();
    1524              : 
    1525              :   /* __FUNCTION__ is defined at file scope ("").  This
    1526              :      call may not be necessary as my tests indicate it
    1527              :      still works without it.  */
    1528       110626 :   finish_fname_decls ();
    1529              : 
    1530       110626 :   check_inline_statics ();
    1531              : 
    1532              :   /* This is the point to write out a PCH if we're doing that.
    1533              :      In that case we do not want to do anything else.  */
    1534       110626 :   if (pch_file)
    1535              :     {
    1536          377 :       c_common_write_pch ();
    1537              :       /* Ensure even the callers don't try to finalize the CU.  */
    1538          377 :       flag_syntax_only = 1;
    1539          377 :       return;
    1540              :     }
    1541              : 
    1542              :   /* Pop off the file scope and close this translation unit.  */
    1543       110249 :   pop_scope ();
    1544       110249 :   file_scope = 0;
    1545              : 
    1546       110249 :   maybe_apply_pending_pragma_weaks ();
    1547              : }
    1548              : 
    1549              : /* Whether we are currently inside the initializer for an
    1550              :    underspecified object definition (C23 auto or constexpr).  */
    1551              : static bool in_underspecified_init;
    1552              : 
    1553              : /* Start an underspecified object definition for NAME at LOC.  This
    1554              :    means that NAME is shadowed inside its initializer, so neither the
    1555              :    definition being initialized, nor any definition from an outer
    1556              :    scope, may be referenced during that initializer.  Return state to
    1557              :    be passed to finish_underspecified_init.  If NAME is NULL_TREE, the
    1558              :    underspecified object is a (constexpr) compound literal; there is
    1559              :    no shadowing in that case, but all the other restrictions on
    1560              :    underspecified object definitions still apply.  */
    1561              : unsigned int
    1562          667 : start_underspecified_init (location_t loc, tree name)
    1563              : {
    1564          667 :   bool prev = in_underspecified_init;
    1565          667 :   bool ok;
    1566          667 :   if (name == NULL_TREE)
    1567              :     ok = true;
    1568              :   else
    1569              :     {
    1570          433 :       tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
    1571          433 :       C_DECL_UNDERSPECIFIED (decl) = 1;
    1572          433 :       struct c_scope *scope = current_scope;
    1573          433 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1574          433 :       if (b && B_IN_SCOPE (b, scope))
    1575              :         {
    1576            4 :           error_at (loc, "underspecified declaration of %qE, which is already "
    1577              :                     "declared in this scope", name);
    1578            4 :           ok = false;
    1579              :         }
    1580              :       else
    1581              :         {
    1582          429 :           bind (name, decl, scope, false, false, loc);
    1583          429 :           ok = true;
    1584              :         }
    1585              :     }
    1586          667 :   in_underspecified_init = true;
    1587          667 :   return ok | (prev << 1);
    1588              : }
    1589              : 
    1590              : /* Finish an underspecified object definition for NAME, before that
    1591              :    name is bound to the real declaration instead of a placeholder.
    1592              :    PREV_STATE is the value returned by the call to
    1593              :    start_underspecified_init.  If NAME is NULL_TREE, this means a
    1594              :    compound literal, as for start_underspecified_init.  */
    1595              : void
    1596          667 : finish_underspecified_init (tree name, unsigned int prev_state)
    1597              : {
    1598          667 :   if (name != NULL_TREE && (prev_state & 1))
    1599              :     {
    1600              :       /* A VAR_DECL was bound to the name to shadow any previous
    1601              :          declarations for the name; remove that binding now.  */
    1602          429 :       struct c_scope *scope = current_scope;
    1603          429 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1604          429 :       gcc_assert (b);
    1605          429 :       gcc_assert (B_IN_SCOPE (b, scope));
    1606          429 :       gcc_assert (VAR_P (b->decl));
    1607          429 :       gcc_assert (C_DECL_UNDERSPECIFIED (b->decl));
    1608          429 :       I_SYMBOL_BINDING (name) = b->shadowed;
    1609              :       /* In erroneous cases there may be other bindings added to this
    1610              :          scope during the initializer.  */
    1611          429 :       struct c_binding **p = &scope->bindings;
    1612          484 :       while (*p != b)
    1613           55 :         p = &((*p)->prev);
    1614          429 :       *p = free_binding_and_advance (*p);
    1615              :     }
    1616          667 :   in_underspecified_init = (prev_state & (1u << 1)) >> 1;
    1617          667 : }
    1618              : 
    1619              : /* Adjust the bindings for the start of a statement expression.  */
    1620              : 
    1621              : void
    1622        34915 : c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
    1623              : {
    1624        34915 :   struct c_scope *scope;
    1625              : 
    1626       235838 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1627              :     {
    1628       200923 :       struct c_binding *b;
    1629              : 
    1630       200923 :       if (!scope->has_label_bindings)
    1631       198496 :         continue;
    1632              : 
    1633        13176 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1634              :         {
    1635        10749 :           struct c_label_vars *label_vars;
    1636        10749 :           unsigned int ix;
    1637        10749 :           struct c_goto_bindings *g;
    1638              : 
    1639        10749 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1640         1948 :             continue;
    1641         8801 :           label_vars = b->u.label;
    1642         8801 :           ++label_vars->label_bindings.stmt_exprs;
    1643        13405 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1644         1891 :             ++g->goto_bindings.stmt_exprs;
    1645              :         }
    1646              :     }
    1647              : 
    1648        34915 :   if (switch_bindings != NULL)
    1649          173 :     ++switch_bindings->stmt_exprs;
    1650        34915 : }
    1651              : 
    1652              : /* Adjust the bindings for the end of a statement expression.  */
    1653              : 
    1654              : void
    1655        34915 : c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
    1656              : {
    1657        34915 :   struct c_scope *scope;
    1658              : 
    1659       200923 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1660              :     {
    1661       166008 :       struct c_binding *b;
    1662              : 
    1663       166008 :       if (!scope->has_label_bindings)
    1664       163346 :         continue;
    1665              : 
    1666        16656 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1667              :         {
    1668        13994 :           struct c_label_vars *label_vars;
    1669        13994 :           unsigned int ix;
    1670        13994 :           struct c_goto_bindings *g;
    1671              : 
    1672        13994 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1673         2012 :             continue;
    1674        11982 :           label_vars = b->u.label;
    1675        11982 :           --label_vars->label_bindings.stmt_exprs;
    1676        11982 :           if (label_vars->label_bindings.stmt_exprs < 0)
    1677              :             {
    1678         3322 :               label_vars->label_bindings.left_stmt_expr = true;
    1679         3322 :               label_vars->label_bindings.stmt_exprs = 0;
    1680              :             }
    1681        16642 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1682              :             {
    1683         1887 :               --g->goto_bindings.stmt_exprs;
    1684         1887 :               if (g->goto_bindings.stmt_exprs < 0)
    1685              :                 {
    1686          128 :                   g->goto_bindings.left_stmt_expr = true;
    1687          128 :                   g->goto_bindings.stmt_exprs = 0;
    1688              :                 }
    1689              :             }
    1690              :         }
    1691              :     }
    1692              : 
    1693        34915 :   if (switch_bindings != NULL)
    1694              :     {
    1695          173 :       --switch_bindings->stmt_exprs;
    1696          173 :       gcc_assert (switch_bindings->stmt_exprs >= 0);
    1697              :     }
    1698        34915 : }
    1699              : 
    1700              : /* Push a definition or a declaration of struct, union or enum tag "name".
    1701              :    "type" should be the type node.
    1702              :    We assume that the tag "name" is not already defined, and has a location
    1703              :    of LOC.
    1704              : 
    1705              :    Note that the definition may really be just a forward reference.
    1706              :    In that case, the TYPE_SIZE will be zero.  */
    1707              : 
    1708              : static void
    1709      1437072 : pushtag (location_t loc, tree name, tree type)
    1710              : {
    1711              :   /* Record the identifier as the type's name if it has none.  */
    1712      1437072 :   if (name && !TYPE_NAME (type))
    1713       631802 :     TYPE_NAME (type) = name;
    1714      1437072 :   bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc);
    1715              : 
    1716              :   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
    1717              :      tagged type we just added to the current scope.  This fake
    1718              :      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
    1719              :      to output a representation of a tagged type, and it also gives
    1720              :      us a convenient place to record the "scope start" address for the
    1721              :      tagged type, and it is used to track whether the type is used
    1722              :      in a non-local context via mark_decl_used.  */
    1723              : 
    1724      1437072 :   TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
    1725              :                                                 TYPE_DECL, NULL_TREE, type));
    1726              : 
    1727              :   /* An approximation for now, so we can tell this is a function-scope tag.
    1728              :      This will be updated in pop_scope.  */
    1729      1437072 :   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
    1730              : 
    1731      1437072 :   if (warn_cxx_compat && name != NULL_TREE)
    1732              :     {
    1733          640 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1734              : 
    1735          640 :       if (b != NULL
    1736           12 :           && b->decl != NULL_TREE
    1737           12 :           && TREE_CODE (b->decl) == TYPE_DECL
    1738           11 :           && (B_IN_CURRENT_SCOPE (b)
    1739            6 :               || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    1740          645 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
    1741            5 :               != TYPE_MAIN_VARIANT (type)))
    1742              :         {
    1743            5 :           auto_diagnostic_group d;
    1744            6 :           if (warning_at (loc, OPT_Wc___compat,
    1745              :                           "using %qD as both a typedef and a tag is "
    1746              :                           "invalid in C++", b->decl)
    1747            5 :               && b->locus != UNKNOWN_LOCATION)
    1748            4 :             inform (b->locus, "originally defined here");
    1749            5 :         }
    1750              :     }
    1751      1437072 : }
    1752              : 
    1753              : /* An exported interface to pushtag.  This is used by the gdb plugin's
    1754              :    binding oracle to introduce a new tag binding.  */
    1755              : 
    1756              : void
    1757            0 : c_pushtag (location_t loc, tree name, tree type)
    1758              : {
    1759            0 :   pushtag (loc, name, type);
    1760            0 : }
    1761              : 
    1762              : /* An exported interface to bind a declaration.  LOC is the location
    1763              :    to use.  DECL is the declaration to bind.  The decl's name is used
    1764              :    to determine how it is bound.  If DECL is a VAR_DECL, then
    1765              :    IS_GLOBAL determines whether the decl is put into the global (file
    1766              :    and external) scope or the current function's scope; if DECL is not
    1767              :    a VAR_DECL then it is always put into the file scope.  */
    1768              : 
    1769              : void
    1770            0 : c_bind (location_t loc, tree decl, bool is_global)
    1771              : {
    1772            0 :   struct c_scope *scope;
    1773            0 :   bool nested = false;
    1774              : 
    1775            0 :   if (!VAR_P (decl) || current_function_scope == NULL)
    1776              :     {
    1777              :       /* Types and functions are always considered to be global.  */
    1778            0 :       scope = file_scope;
    1779            0 :       DECL_EXTERNAL (decl) = 1;
    1780            0 :       TREE_PUBLIC (decl) = 1;
    1781              :     }
    1782            0 :   else if (is_global)
    1783              :     {
    1784              :       /* Also bind it into the external scope.  */
    1785            0 :       bind (DECL_NAME (decl), decl, external_scope, true, false, loc);
    1786            0 :       nested = true;
    1787            0 :       scope = file_scope;
    1788            0 :       DECL_EXTERNAL (decl) = 1;
    1789            0 :       TREE_PUBLIC (decl) = 1;
    1790              :     }
    1791              :   else
    1792              :     {
    1793            0 :       DECL_CONTEXT (decl) = current_function_decl;
    1794            0 :       TREE_PUBLIC (decl) = 0;
    1795            0 :       scope = current_function_scope;
    1796              :     }
    1797              : 
    1798            0 :   bind (DECL_NAME (decl), decl, scope, false, nested, loc);
    1799            0 : }
    1800              : 
    1801              : 
    1802              : /* Stores the first FILE*, const struct tm* etc. argument type (whatever
    1803              :    it is) seen in a declaration of a file I/O etc. built-in, corresponding
    1804              :    to the builtin_structptr_types array.  Subsequent declarations of such
    1805              :    built-ins are expected to refer to it rather than to fileptr_type_node,
    1806              :    etc. which is just void* (or to any other type).
    1807              :    Used only by match_builtin_function_types.  */
    1808              : 
    1809              : static const unsigned builtin_structptr_type_count
    1810              :   = ARRAY_SIZE (builtin_structptr_types);
    1811              : 
    1812              : static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
    1813              : 
    1814              : /* Returns true if types T1 and T2 representing return types or types
    1815              :    of function arguments are close enough to be considered interchangeable
    1816              :    in redeclarations of built-in functions.  */
    1817              : 
    1818              : static bool
    1819       629591 : types_close_enough_to_match (tree t1, tree t2)
    1820              : {
    1821       629591 :   return (TYPE_MODE (t1) == TYPE_MODE (t2)
    1822       629137 :           && POINTER_TYPE_P (t1) == POINTER_TYPE_P (t2)
    1823      2516849 :           && FUNCTION_POINTER_TYPE_P (t1) == FUNCTION_POINTER_TYPE_P (t2));
    1824              : }
    1825              : 
    1826              : /* Subroutine of compare_decls.  Allow harmless mismatches in return
    1827              :    and argument types provided that the type modes match.  Set *STRICT
    1828              :    and *ARGNO to the expected argument type and number in case of
    1829              :    an argument type mismatch or null and zero otherwise.  Return
    1830              :    a unified type given a suitable match, and 0 otherwise.  */
    1831              : 
    1832              : static tree
    1833       145992 : match_builtin_function_types (tree newtype, tree oldtype,
    1834              :                               tree *strict, unsigned *argno)
    1835              : {
    1836       145992 :   *argno = 0;
    1837       145992 :   *strict = NULL_TREE;
    1838              : 
    1839              :   /* Accept the return type of the new declaration if it has the same
    1840              :      mode and if they're both pointers or if neither is.  */
    1841       145992 :   tree oldrettype = TREE_TYPE (oldtype);
    1842       145992 :   tree newrettype = TREE_TYPE (newtype);
    1843              : 
    1844       145992 :   if (!types_close_enough_to_match (oldrettype, newrettype))
    1845              :     return NULL_TREE;
    1846              : 
    1847              :   /* Check that the return types are compatible but don't fail if they
    1848              :      are not (e.g., int vs long in ILP32) and just let the caller know.  */
    1849       145630 :   if (!comptypes (TYPE_MAIN_VARIANT (oldrettype),
    1850       145630 :                   TYPE_MAIN_VARIANT (newrettype)))
    1851           46 :     *strict = oldrettype;
    1852              : 
    1853       145630 :   tree oldargs = TYPE_ARG_TYPES (oldtype);
    1854       145630 :   tree newargs = TYPE_ARG_TYPES (newtype);
    1855       145630 :   tree tryargs = newargs;
    1856              : 
    1857       145630 :   const unsigned nlst = ARRAY_SIZE (last_structptr_types);
    1858       145630 :   const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
    1859              : 
    1860       145630 :   gcc_checking_assert (nlst == nbst);
    1861              : 
    1862       629033 :   for (unsigned i = 1; oldargs || newargs; ++i)
    1863              :     {
    1864       483658 :       if (!oldargs
    1865       483658 :           || !newargs
    1866       483603 :           || !TREE_VALUE (oldargs)
    1867       967261 :           || !TREE_VALUE (newargs))
    1868              :         return NULL_TREE;
    1869              : 
    1870       483603 :       tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
    1871       483603 :       tree newtype = TREE_VALUE (newargs);
    1872       483603 :       if (newtype == error_mark_node)
    1873              :        return NULL_TREE;
    1874       483599 :       newtype = TYPE_MAIN_VARIANT (newtype);
    1875              : 
    1876       483599 :       if (!types_close_enough_to_match (oldtype, newtype))
    1877              :         return NULL_TREE;
    1878              : 
    1879       483456 :       unsigned j = nbst;
    1880       483456 :       if (POINTER_TYPE_P (oldtype))
    1881              :         /* Iterate over well-known struct types like FILE (whose types
    1882              :            aren't known to us) and compare the pointer to each to
    1883              :            the pointer argument.  */
    1884       987643 :         for (j = 0; j < nbst; ++j)
    1885              :           {
    1886       870077 :             if (TREE_VALUE (oldargs) != builtin_structptr_types[j].node)
    1887       724917 :               continue;
    1888              :             /* Store the first FILE* etc. argument type (whatever it is), and
    1889              :                expect any subsequent declarations of file I/O etc. built-ins
    1890              :                to refer to it rather than to fileptr_type_node etc. which is
    1891              :                just void* (or const void*).  */
    1892       145160 :             if (last_structptr_types[j])
    1893              :               {
    1894       127515 :                 if (!comptypes (last_structptr_types[j], newtype))
    1895              :                   {
    1896            2 :                     *argno = i;
    1897            2 :                     *strict = last_structptr_types[j];
    1898              :                   }
    1899              :               }
    1900              :             else
    1901        17645 :               last_structptr_types[j] = newtype;
    1902              :             break;
    1903              :           }
    1904              : 
    1905       483456 :       if (j == nbst && !comptypes (oldtype, newtype))
    1906              :         {
    1907          243 :           if (POINTER_TYPE_P (oldtype))
    1908              :             {
    1909              :               /* For incompatible pointers, only reject differences in
    1910              :                  the unqualified variants of the referenced types but
    1911              :                  consider differences in qualifiers as benign (report
    1912              :                  those to caller via *STRICT below).  */
    1913          204 :               tree oldref = TYPE_MAIN_VARIANT (TREE_TYPE (oldtype));
    1914          204 :               tree newref = TYPE_MAIN_VARIANT (TREE_TYPE (newtype));
    1915          204 :               if (!comptypes (oldref, newref))
    1916              :                 return NULL_TREE;
    1917              :             }
    1918              : 
    1919          190 :           if (!*strict)
    1920              :             {
    1921          186 :               *argno = i;
    1922          186 :               *strict = oldtype;
    1923              :             }
    1924              :         }
    1925              : 
    1926       483403 :       oldargs = TREE_CHAIN (oldargs);
    1927       483403 :       newargs = TREE_CHAIN (newargs);
    1928              :     }
    1929              : 
    1930       145375 :   tree trytype = c_build_function_type (newrettype, tryargs);
    1931              : 
    1932              :   /* Allow declaration to change transaction_safe attribute.  */
    1933       145375 :   tree oldattrs = TYPE_ATTRIBUTES (oldtype);
    1934       145375 :   tree oldtsafe = lookup_attribute ("transaction_safe", oldattrs);
    1935       145375 :   tree newattrs = TYPE_ATTRIBUTES (newtype);
    1936       145375 :   tree newtsafe = lookup_attribute ("transaction_safe", newattrs);
    1937       145375 :   if (oldtsafe && !newtsafe)
    1938            0 :     oldattrs = remove_attribute ("transaction_safe", oldattrs);
    1939       145375 :   else if (newtsafe && !oldtsafe)
    1940            7 :     oldattrs = tree_cons (get_identifier ("transaction_safe"),
    1941              :                           NULL_TREE, oldattrs);
    1942              : 
    1943       145375 :   return c_build_type_attribute_variant (trytype, oldattrs);
    1944              : }
    1945              : 
    1946              : /* Subroutine of diagnose_mismatched_decls.  Check for function type
    1947              :    mismatch involving an empty arglist vs a nonempty one and give clearer
    1948              :    diagnostics.  */
    1949              : static void
    1950          178 : diagnose_arglist_conflict (tree newdecl, tree olddecl,
    1951              :                            tree newtype, tree oldtype)
    1952              : {
    1953          178 :   tree t;
    1954              : 
    1955          178 :   if (TREE_CODE (olddecl) != FUNCTION_DECL
    1956           98 :       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
    1957          305 :       || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == NULL_TREE)
    1958           68 :            || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == NULL_TREE)))
    1959          161 :     return;
    1960              : 
    1961           17 :   t = TYPE_ARG_TYPES (oldtype);
    1962           17 :   if (t == NULL_TREE)
    1963            9 :     t = TYPE_ARG_TYPES (newtype);
    1964           18 :   for (; t; t = TREE_CHAIN (t))
    1965              :     {
    1966           18 :       tree type = TREE_VALUE (t);
    1967              : 
    1968           18 :       if (TREE_CHAIN (t) == NULL_TREE
    1969           18 :           && TYPE_MAIN_VARIANT (type) != void_type_node)
    1970              :         {
    1971           10 :           inform (input_location, "a parameter list with an ellipsis "
    1972              :                   "cannot match an empty parameter name list declaration");
    1973           10 :           break;
    1974              :         }
    1975              : 
    1976            8 :       if (!error_operand_p (type)
    1977            8 :           && c_type_promotes_to (type) != type)
    1978              :         {
    1979            7 :           inform (input_location, "an argument type that has a default "
    1980              :                   "promotion cannot match an empty parameter name list "
    1981              :                   "declaration");
    1982            7 :           break;
    1983              :         }
    1984              :     }
    1985              : }
    1986              : 
    1987              : /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
    1988              :    old-style function definition, NEWDECL is a prototype declaration.
    1989              :    Diagnose inconsistencies in the argument list.  Returns TRUE if
    1990              :    the prototype is compatible, FALSE if not.  */
    1991              : static bool
    1992           19 : validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
    1993              : {
    1994           19 :   tree newargs, oldargs;
    1995           19 :   int i;
    1996              : 
    1997              : #define END_OF_ARGLIST(t) ((t) == void_type_node)
    1998              : 
    1999           19 :   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
    2000           19 :   newargs = TYPE_ARG_TYPES (newtype);
    2001           19 :   i = 1;
    2002              : 
    2003           45 :   for (;;)
    2004              :     {
    2005           32 :       tree oldargtype = TREE_VALUE (oldargs);
    2006           32 :       tree newargtype = TREE_VALUE (newargs);
    2007              : 
    2008           32 :       if (oldargtype == error_mark_node || newargtype == error_mark_node)
    2009              :         return false;
    2010              : 
    2011           58 :       oldargtype = (TYPE_ATOMIC (oldargtype)
    2012           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (oldargtype),
    2013              :                                               TYPE_QUAL_ATOMIC)
    2014           27 :                     : TYPE_MAIN_VARIANT (oldargtype));
    2015           60 :       newargtype = (TYPE_ATOMIC (newargtype)
    2016           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (newargtype),
    2017              :                                               TYPE_QUAL_ATOMIC)
    2018           29 :                     : TYPE_MAIN_VARIANT (newargtype));
    2019              : 
    2020           31 :       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
    2021              :         break;
    2022              : 
    2023              :       /* Reaching the end of just one list means the two decls don't
    2024              :          agree on the number of arguments.  */
    2025           22 :       if (END_OF_ARGLIST (oldargtype))
    2026              :         {
    2027            2 :           error ("prototype for %q+D declares more arguments "
    2028              :                  "than previous old-style definition", newdecl);
    2029            2 :           return false;
    2030              :         }
    2031           20 :       else if (END_OF_ARGLIST (newargtype))
    2032              :         {
    2033            2 :           error ("prototype for %q+D declares fewer arguments "
    2034              :                  "than previous old-style definition", newdecl);
    2035            2 :           return false;
    2036              :         }
    2037              : 
    2038              :       /* Type for passing arg must be consistent with that declared
    2039              :          for the arg.  */
    2040           18 :       else if (!comptypes (oldargtype, newargtype))
    2041              :         {
    2042            5 :           error ("prototype for %q+D declares argument %d"
    2043              :                  " with incompatible type",
    2044              :                  newdecl, i);
    2045            5 :           return false;
    2046              :         }
    2047              : 
    2048           13 :       oldargs = TREE_CHAIN (oldargs);
    2049           13 :       newargs = TREE_CHAIN (newargs);
    2050           13 :       i++;
    2051           13 :     }
    2052              : 
    2053              :   /* If we get here, no errors were found, but do issue a warning
    2054              :      for this poor-style construct.  */
    2055            9 :   warning (0, "prototype for %q+D follows non-prototype definition",
    2056              :            newdecl);
    2057            9 :   return true;
    2058              : #undef END_OF_ARGLIST
    2059              : }
    2060              : 
    2061              : /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
    2062              :    first in a pair of mismatched declarations, using the diagnostic
    2063              :    function DIAG.  */
    2064              : static void
    2065          418 : locate_old_decl (tree decl)
    2066              : {
    2067          418 :   if (TREE_CODE (decl) == FUNCTION_DECL
    2068          198 :       && fndecl_built_in_p (decl)
    2069          421 :       && !C_DECL_DECLARED_BUILTIN (decl))
    2070              :     ;
    2071          418 :   else if (DECL_INITIAL (decl))
    2072          119 :     inform (input_location,
    2073              :             "previous definition of %q+D with type %qT",
    2074          119 :             decl, TREE_TYPE (decl));
    2075          299 :   else if (C_DECL_IMPLICIT (decl))
    2076           16 :     inform (input_location,
    2077              :             "previous implicit declaration of %q+D with type %qT",
    2078           16 :             decl, TREE_TYPE (decl));
    2079              :   else
    2080          283 :     inform (input_location,
    2081              :             "previous declaration of %q+D with type %qT",
    2082          283 :             decl, TREE_TYPE (decl));
    2083          418 : }
    2084              : 
    2085              : 
    2086              : /* Helper function.  For a tagged type, it finds the declaration
    2087              :    for a visible tag declared in the same scope if such a
    2088              :    declaration exists.  */
    2089              : static tree
    2090      1147629 : previous_tag (tree type)
    2091              : {
    2092      1147629 :   struct c_binding *b = NULL;
    2093      1147629 :   tree name = c_type_tag (type);
    2094              : 
    2095      1147629 :   if (name)
    2096       571383 :     b = I_TAG_BINDING (name);
    2097              : 
    2098       571383 :   if (b)
    2099       571383 :     b = b->shadowed;
    2100              : 
    2101      1147629 :   if (b && B_IN_CURRENT_SCOPE (b))
    2102          177 :     return b->decl;
    2103              : 
    2104              :   return NULL_TREE;
    2105              : }
    2106              : 
    2107              : /* Subroutine to mark functions as versioned when using the attribute
    2108              :    'target_version'.  */
    2109              : 
    2110              : static void
    2111            0 : maybe_mark_function_versioned (tree decl)
    2112              : {
    2113            0 :   if (!DECL_FUNCTION_VERSIONED (decl))
    2114              :     {
    2115              :       /* Check if the name of the function has been overridden.  */
    2116            0 :       if (DECL_ASSEMBLER_NAME_SET_P (decl)
    2117            0 :           && IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))[0] == '*')
    2118            0 :         error_at (DECL_SOURCE_LOCATION (decl),
    2119              :                   "cannot use function multiversioning on a renamed function");
    2120              : 
    2121              :       /* We need to insert function version now to make sure the correct
    2122              :          pre-mangled assembler name is recorded.  */
    2123            0 :       cgraph_node *node = cgraph_node::get_create (decl);
    2124              : 
    2125            0 :       if (!node->function_version ())
    2126            0 :         node->insert_new_function_version ();
    2127              : 
    2128            0 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    2129              : 
    2130            0 :       tree mangled_name
    2131            0 :         = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
    2132            0 :       SET_DECL_ASSEMBLER_NAME (decl, mangled_name);
    2133              :     }
    2134            0 : }
    2135              : 
    2136              : /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
    2137              :    Returns true if the caller should proceed to merge the two, false
    2138              :    if OLDDECL should simply be discarded.  As a side effect, issues
    2139              :    all necessary diagnostics for invalid or poor-style combinations.
    2140              :    If it returns true, writes the types of NEWDECL and OLDDECL to
    2141              :    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
    2142              :    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
    2143              : 
    2144              : static bool
    2145      5114834 : diagnose_mismatched_decls (tree newdecl, tree olddecl,
    2146              :                            tree *newtypep, tree *oldtypep)
    2147              : {
    2148      5114834 :   tree newtype, oldtype;
    2149      5114834 :   bool retval = true;
    2150              : 
    2151              : #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL)  \
    2152              :                                   && DECL_EXTERNAL (DECL))
    2153              : 
    2154              :   /* If we have error_mark_node for either decl or type, just discard
    2155              :      the previous decl - we're in an error cascade already.  */
    2156      5114834 :   if (olddecl == error_mark_node || newdecl == error_mark_node)
    2157              :     return false;
    2158      5114814 :   *oldtypep = oldtype = TREE_TYPE (olddecl);
    2159      5114814 :   *newtypep = newtype = TREE_TYPE (newdecl);
    2160      5114814 :   if (oldtype == error_mark_node || newtype == error_mark_node)
    2161              :     return false;
    2162              : 
    2163              :   /* Two different categories of symbol altogether.  This is an error
    2164              :      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
    2165      5114806 :   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2166              :     {
    2167           29 :       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
    2168           17 :             && fndecl_built_in_p (olddecl)
    2169           14 :             && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2170              :         {
    2171           16 :           auto_diagnostic_group d;
    2172           16 :           error ("%q+D redeclared as different kind of symbol", newdecl);
    2173           16 :           locate_old_decl (olddecl);
    2174           16 :         }
    2175           13 :       else if (TREE_PUBLIC (newdecl))
    2176            3 :         warning (OPT_Wbuiltin_declaration_mismatch,
    2177              :                  "built-in function %q+D declared as non-function",
    2178              :                  newdecl);
    2179              :       else
    2180           10 :         warning (OPT_Wshadow, "declaration of %q+D shadows "
    2181              :                  "a built-in function", newdecl);
    2182           29 :       return false;
    2183              :     }
    2184              : 
    2185              :   /* Enumerators have no linkage, so may only be declared once in a
    2186              :      given scope.  */
    2187      5114777 :   if (TREE_CODE (olddecl) == CONST_DECL)
    2188              :     {
    2189           46 :       if (flag_isoc23
    2190           45 :           && TYPE_NAME (DECL_CONTEXT (newdecl))
    2191           43 :           && DECL_CONTEXT (newdecl) != DECL_CONTEXT (olddecl)
    2192           87 :           && TYPE_NAME (DECL_CONTEXT (newdecl)) == TYPE_NAME (DECL_CONTEXT (olddecl)))
    2193              :         {
    2194           38 :           if (!simple_cst_equal (DECL_INITIAL (olddecl), DECL_INITIAL (newdecl)))
    2195              :             {
    2196            1 :               auto_diagnostic_group d;
    2197            1 :               error ("conflicting redeclaration of enumerator %q+D", newdecl);
    2198            1 :               locate_old_decl (olddecl);
    2199            1 :             }
    2200              :         }
    2201              :       else
    2202              :         {
    2203            8 :           auto_diagnostic_group d;
    2204            8 :           error ("redeclaration of enumerator %q+D", newdecl);
    2205            8 :           locate_old_decl (olddecl);
    2206            8 :         }
    2207           46 :       return false;
    2208              :     }
    2209              : 
    2210      5114731 :   bool pedwarned = false;
    2211      5114731 :   bool warned = false;
    2212      5114731 :   bool enum_and_int_p = false;
    2213      5114731 :   auto_diagnostic_group d;
    2214              : 
    2215      5114731 :   bool comptypes_result = comptypes_check_enum_int (oldtype, newtype,
    2216              :                                                     &enum_and_int_p);
    2217      5114731 :   if (!comptypes_result)
    2218              :     {
    2219       146201 :       if (TREE_CODE (olddecl) == FUNCTION_DECL
    2220       146121 :           && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL)
    2221       292194 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2222              :         {
    2223              :           /* Accept "harmless" mismatches in function types such
    2224              :              as missing qualifiers or int vs long when they're the same
    2225              :              size.  However, diagnose return and argument types that are
    2226              :              incompatible according to language rules.  */
    2227       145992 :           tree mismatch_expect;
    2228       145992 :           unsigned mismatch_argno;
    2229              : 
    2230       145992 :           tree trytype = match_builtin_function_types (newtype, oldtype,
    2231              :                                                        &mismatch_expect,
    2232              :                                                        &mismatch_argno);
    2233              : 
    2234       145992 :           if (trytype && comptypes (newtype, trytype))
    2235       145375 :             *oldtypep = oldtype = trytype;
    2236              :           else
    2237              :             {
    2238              :               /* If types don't match for a built-in, throw away the
    2239              :                  built-in.  No point in calling locate_old_decl here, it
    2240              :                  won't print anything.  */
    2241          617 :               const char *header = header_for_builtin_fn (olddecl);
    2242          617 :               location_t loc = DECL_SOURCE_LOCATION (newdecl);
    2243         1017 :               if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    2244              :                               "conflicting types for built-in function %q+D; "
    2245              :                               "expected %qT",
    2246              :                               newdecl, oldtype)
    2247          617 :                   && header)
    2248              :                 {
    2249              :                   /* Suggest the right header to include as the preferred
    2250              :                      solution rather than the spelling of the declaration.  */
    2251          217 :                   rich_location richloc (line_table, loc);
    2252          217 :                   maybe_add_include_fixit (&richloc, header, true);
    2253          217 :                   inform (&richloc,
    2254              :                           "%qD is declared in header %qs", olddecl, header);
    2255          217 :                 }
    2256          617 :               return false;
    2257              :             }
    2258              : 
    2259       145375 :           if (mismatch_expect && extra_warnings)
    2260              :             {
    2261            5 :               location_t newloc = DECL_SOURCE_LOCATION (newdecl);
    2262            5 :               bool warned = false;
    2263            5 :               if (mismatch_argno)
    2264            5 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2265              :                                      "mismatch in argument %u type of built-in "
    2266              :                                      "function %qD; expected %qT",
    2267              :                                      mismatch_argno, newdecl, mismatch_expect);
    2268              :               else
    2269            0 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2270              :                                      "mismatch in return type of built-in "
    2271              :                                      "function %qD; expected %qT",
    2272              :                                      newdecl, mismatch_expect);
    2273            5 :               const char *header = header_for_builtin_fn (olddecl);
    2274            5 :               if (warned && header)
    2275              :                 {
    2276            5 :                   rich_location richloc (line_table, newloc);
    2277            5 :                   maybe_add_include_fixit (&richloc, header, true);
    2278            5 :                   inform (&richloc,
    2279              :                           "%qD is declared in header %qs", olddecl, header);
    2280            5 :                 }
    2281              :             }
    2282              :         }
    2283          209 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2284          209 :                && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    2285              :         {
    2286              :           /* A conflicting function declaration for a predeclared
    2287              :              function that isn't actually built in.  Objective C uses
    2288              :              these.  The new declaration silently overrides everything
    2289              :              but the volatility (i.e. noreturn) indication.  See also
    2290              :              below.  FIXME: Make Objective C use normal builtins.  */
    2291            0 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2292            0 :           return false;
    2293              :         }
    2294              :       /* Permit void foo (...) to match int foo (...) if the latter is
    2295              :          the definition and implicit int was used.  See
    2296              :          c-torture/compile/920625-2.c.  */
    2297          129 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
    2298           64 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
    2299           32 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
    2300          215 :                && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
    2301              :         {
    2302            5 :           pedwarned = pedwarn (input_location, 0,
    2303              :                                "conflicting types for %q+D", newdecl);
    2304              :           /* Make sure we keep void as the return type.  */
    2305            5 :           TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
    2306            5 :           C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
    2307              :         }
    2308              :       /* Permit void foo (...) to match an earlier call to foo (...) with
    2309              :          no declared type (thus, implicitly int).  */
    2310          204 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2311          124 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
    2312           92 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
    2313          227 :                && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
    2314              :         {
    2315           19 :           pedwarned = pedwarn (input_location, 0,
    2316              :                                "conflicting types for %q+D; have %qT",
    2317              :                                newdecl, newtype);
    2318              :           /* Make sure we keep void as the return type.  */
    2319           19 :           TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
    2320              :         }
    2321              :       else
    2322              :         {
    2323          185 :           int new_quals = TYPE_QUALS (newtype);
    2324          185 :           int old_quals = TYPE_QUALS (oldtype);
    2325              : 
    2326          185 :           if (new_quals != old_quals)
    2327              :             {
    2328           21 :               addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
    2329           21 :               addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
    2330           21 :               if (new_addr != old_addr)
    2331              :                 {
    2332            0 :                   if (ADDR_SPACE_GENERIC_P (new_addr))
    2333            0 :                     error ("conflicting named address spaces (generic vs %s) "
    2334              :                            "for %q+D",
    2335              :                            c_addr_space_name (old_addr), newdecl);
    2336            0 :                   else if (ADDR_SPACE_GENERIC_P (old_addr))
    2337            0 :                     error ("conflicting named address spaces (%s vs generic) "
    2338              :                            "for %q+D",
    2339              :                            c_addr_space_name (new_addr), newdecl);
    2340              :                   else
    2341            0 :                     error ("conflicting named address spaces (%s vs %s) "
    2342              :                            "for %q+D",
    2343              :                            c_addr_space_name (new_addr),
    2344              :                            c_addr_space_name (old_addr),
    2345              :                            newdecl);
    2346              :                 }
    2347              : 
    2348           21 :               if (CLEAR_QUAL_ADDR_SPACE (new_quals)
    2349           21 :                   != CLEAR_QUAL_ADDR_SPACE (old_quals))
    2350           21 :                 error ("conflicting type qualifiers for %q+D", newdecl);
    2351              :             }
    2352              :           else
    2353              :             {
    2354          164 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2355              :                 {
    2356           93 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl));
    2357           93 :                   if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl)))
    2358              :                     {
    2359              :                       /* Similar to the C++ front-end, for FUNCTION_DECL,
    2360              :                          if OLDDECL has attributes and NEWDECL doesn't,
    2361              :                          try the type with OLDDECL attributes.  */
    2362           12 :                       tree rettype = TREE_TYPE (newtype);
    2363           12 :                       tree tryargs = TYPE_ARG_TYPES (newtype);
    2364           12 :                       tree trytype = c_build_function_type (rettype,
    2365              :                                                             tryargs);
    2366           12 :                       trytype = c_build_type_attribute_variant (trytype,
    2367              :                                                                 attrs);
    2368           12 :                       if (comptypes (oldtype, trytype))
    2369              :                         {
    2370            7 :                           *newtypep = newtype = trytype;
    2371            7 :                           comptypes_result = true;
    2372              :                         }
    2373              :                     }
    2374              :                 }
    2375              : 
    2376          164 :               if (!comptypes_result)
    2377          157 :                 error ("conflicting types for %q+D; have %qT", newdecl,
    2378              :                        newtype);
    2379              :             }
    2380            7 :           if (!comptypes_result)
    2381              :             {
    2382          178 :               diagnose_arglist_conflict (newdecl, olddecl, newtype,
    2383              :                                          oldtype);
    2384          178 :               locate_old_decl (olddecl);
    2385          178 :               return false;
    2386              :             }
    2387              :         }
    2388              :     }
    2389              :   /* Warn about enum/integer type mismatches.  They are compatible types
    2390              :      (C23 6.7.2.2/5), but may pose portability problems.  */
    2391      4968530 :   else if (enum_and_int_p
    2392          191 :            && TREE_CODE (newdecl) != TYPE_DECL
    2393              :            /* Don't warn about acc_on_device built-in redeclaration,
    2394              :               the built-in is declared with int rather than enum because
    2395              :               the enum isn't intrinsic.  */
    2396      4968717 :            && !(TREE_CODE (olddecl) == FUNCTION_DECL
    2397          150 :                 && fndecl_built_in_p (olddecl, BUILT_IN_ACC_ON_DEVICE)
    2398          120 :                 && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2399           67 :     warned = warning_at (DECL_SOURCE_LOCATION (newdecl),
    2400           67 :                          OPT_Wenum_int_mismatch,
    2401              :                          "conflicting types for %q+D due to enum/integer "
    2402              :                          "mismatch; have %qT", newdecl, newtype);
    2403              : 
    2404              :   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
    2405              :      but silently ignore the redeclaration if either is in a system
    2406              :      header.  (Conflicting redeclarations were handled above.)  This
    2407              :      is allowed for C11 if the types are the same, not just
    2408              :      compatible.  */
    2409      5113936 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2410              :     {
    2411        45871 :       if (!comptypes_same_p (oldtype, newtype))
    2412              :         {
    2413           11 :           error ("redefinition of typedef %q+D with different type", newdecl);
    2414           11 :           locate_old_decl (olddecl);
    2415           11 :           return false;
    2416              :         }
    2417              : 
    2418        45860 :       if (DECL_IN_SYSTEM_HEADER (newdecl)
    2419         2497 :           || DECL_IN_SYSTEM_HEADER (olddecl)
    2420         2275 :           || warning_suppressed_p (newdecl, OPT_Wpedantic)
    2421        48135 :           || warning_suppressed_p (olddecl, OPT_Wpedantic))
    2422        43585 :         return true;  /* Allow OLDDECL to continue in use.  */
    2423              : 
    2424         2275 :       if (c_type_variably_modified_p (newtype))
    2425              :         {
    2426            3 :           error ("redefinition of typedef %q+D with variably modified type",
    2427              :                  newdecl);
    2428            3 :           locate_old_decl (olddecl);
    2429              :         }
    2430         2272 :       else if (pedwarn_c99 (input_location, OPT_Wpedantic,
    2431              :                             "redefinition of typedef %q+D", newdecl))
    2432            8 :         locate_old_decl (olddecl);
    2433              : 
    2434         2275 :       return true;
    2435              :     }
    2436              : 
    2437              :   /* Function declarations can either be 'static' or 'extern' (no
    2438              :      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
    2439              :      can never conflict with each other on account of linkage
    2440              :      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
    2441              :      gnu89 mode permits two definitions if one is 'extern inline' and
    2442              :      one is not.  The non- extern-inline definition supersedes the
    2443              :      extern-inline definition.  */
    2444              : 
    2445      5068065 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2446              :     {
    2447              :       /* If you declare a built-in function name as static, or
    2448              :          define the built-in with an old-style definition (so we
    2449              :          can't validate the argument list) the built-in definition is
    2450              :          overridden, but optionally warn this was a bad choice of name.  */
    2451      5049388 :       if (fndecl_built_in_p (olddecl)
    2452      9045502 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2453              :         {
    2454      3731009 :           if (!TREE_PUBLIC (newdecl)
    2455      3731009 :               || (DECL_INITIAL (newdecl)
    2456         4861 :                   && !prototype_p (TREE_TYPE (newdecl))))
    2457              :             {
    2458          104 :               warning_at (DECL_SOURCE_LOCATION (newdecl),
    2459          104 :                           OPT_Wshadow, "declaration of %qD shadows "
    2460              :                           "a built-in function", newdecl);
    2461              :               /* Discard the old built-in function.  */
    2462          104 :               return false;
    2463              :             }
    2464              : 
    2465      3730905 :           if (!prototype_p (TREE_TYPE (newdecl)))
    2466              :             {
    2467              :               /* Set for built-ins that take no arguments.  */
    2468          342 :               bool func_void_args = false;
    2469          342 :               if (tree at = TYPE_ARG_TYPES (oldtype))
    2470          342 :                 func_void_args = VOID_TYPE_P (TREE_VALUE (at));
    2471              : 
    2472          342 :               if (extra_warnings && !func_void_args)
    2473           47 :                 warning_at (DECL_SOURCE_LOCATION (newdecl),
    2474           47 :                             OPT_Wbuiltin_declaration_mismatch,
    2475              :                             "declaration of built-in function %qD without "
    2476              :                             "a prototype; expected %qT",
    2477           47 :                             newdecl, TREE_TYPE (olddecl));
    2478              :             }
    2479              :         }
    2480              : 
    2481      5049284 :       if (DECL_INITIAL (newdecl))
    2482              :         {
    2483       233452 :           if (DECL_INITIAL (olddecl))
    2484              :             {
    2485              :               /* If the new declaration isn't overriding an extern inline
    2486              :                  reject the new decl. In c99, no overriding is allowed
    2487              :                  in the same translation unit.  */
    2488          209 :               if (!DECL_EXTERN_INLINE (olddecl)
    2489           91 :                   || DECL_EXTERN_INLINE (newdecl)
    2490          204 :                   || (!flag_gnu89_inline
    2491           15 :                       && (!DECL_DECLARED_INLINE_P (olddecl)
    2492           15 :                           || !lookup_attribute ("gnu_inline",
    2493           15 :                                                 DECL_ATTRIBUTES (olddecl)))
    2494            0 :                       && (!DECL_DECLARED_INLINE_P (newdecl)
    2495            0 :                           || !lookup_attribute ("gnu_inline",
    2496            0 :                                                 DECL_ATTRIBUTES (newdecl)))))
    2497              :                 {
    2498           26 :                   auto_diagnostic_group d;
    2499           26 :                   error ("redefinition of %q+D", newdecl);
    2500           26 :                   locate_old_decl (olddecl);
    2501           26 :                   return false;
    2502           26 :                 }
    2503              :             }
    2504              :         }
    2505              :       /* If we have a prototype after an old-style function definition,
    2506              :          the argument types must be checked specially.  */
    2507      4815832 :       else if (DECL_INITIAL (olddecl)
    2508          824 :                && !prototype_p (oldtype) && prototype_p (newtype)
    2509      4815852 :                && TYPE_ACTUAL_ARG_TYPES (oldtype))
    2510              :         {
    2511           19 :           auto_diagnostic_group d;
    2512           19 :           if (!validate_proto_after_old_defn (newdecl, newtype, oldtype))
    2513              :             {
    2514           10 :               locate_old_decl (olddecl);
    2515           10 :               return false;
    2516              :             }
    2517           19 :         }
    2518              :       /* A non-static declaration (even an "extern") followed by a
    2519              :          static declaration is undefined behavior per C99 6.2.2p3-5,7.
    2520              :          The same is true for a static forward declaration at block
    2521              :          scope followed by a non-static declaration/definition at file
    2522              :          scope.  Static followed by non-static at the same scope is
    2523              :          not undefined behavior, and is the most convenient way to get
    2524              :          some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
    2525              :          the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
    2526              :          we do diagnose it if -Wtraditional.  */
    2527      5049248 :       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
    2528              :         {
    2529              :           /* Two exceptions to the rule.  If olddecl is an extern
    2530              :              inline, or a predeclared function that isn't actually
    2531              :              built in, newdecl silently overrides olddecl.  The latter
    2532              :              occur only in Objective C; see also above.  (FIXME: Make
    2533              :              Objective C use normal builtins.)  */
    2534           19 :           if (!DECL_IS_UNDECLARED_BUILTIN (olddecl)
    2535           38 :               && !DECL_EXTERN_INLINE (olddecl))
    2536              :             {
    2537            5 :               auto_diagnostic_group d;
    2538            5 :               error ("static declaration of %q+D follows "
    2539              :                      "non-static declaration", newdecl);
    2540            5 :               locate_old_decl (olddecl);
    2541            5 :             }
    2542           19 :           return false;
    2543              :         }
    2544      5049229 :       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
    2545              :         {
    2546         2329 :           if (DECL_CONTEXT (olddecl))
    2547              :             {
    2548            0 :               auto_diagnostic_group d;
    2549            0 :               error ("non-static declaration of %q+D follows "
    2550              :                      "static declaration", newdecl);
    2551            0 :               locate_old_decl (olddecl);
    2552            0 :               return false;
    2553            0 :             }
    2554         2329 :           else if (warn_traditional)
    2555              :             {
    2556            2 :               warned |= warning (OPT_Wtraditional,
    2557              :                                  "non-static declaration of %q+D "
    2558              :                                  "follows static declaration", newdecl);
    2559              :             }
    2560              :         }
    2561              : 
    2562              :       /* Make sure gnu_inline attribute is either not present, or
    2563              :          present on all inline decls.  */
    2564      5049229 :       if (DECL_DECLARED_INLINE_P (olddecl)
    2565      5050316 :           && DECL_DECLARED_INLINE_P (newdecl))
    2566              :         {
    2567          832 :           bool newa = lookup_attribute ("gnu_inline",
    2568          832 :                                         DECL_ATTRIBUTES (newdecl)) != NULL;
    2569          832 :           bool olda = lookup_attribute ("gnu_inline",
    2570          832 :                                         DECL_ATTRIBUTES (olddecl)) != NULL;
    2571          832 :           if (newa != olda)
    2572              :             {
    2573            0 :               auto_diagnostic_group d;
    2574            0 :               error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
    2575              :                         newa ? newdecl : olddecl);
    2576            0 :               error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
    2577              :                         "but not here");
    2578            0 :             }
    2579              :         }
    2580              :       /* Check if these are unmergeable overlapping FMV declarations.  */
    2581              :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2582              :           && diagnose_versioned_decls (olddecl, newdecl))
    2583              :         return false;
    2584              :     }
    2585        18677 :   else if (VAR_P (newdecl))
    2586              :     {
    2587              :       /* Only variables can be thread-local, and all declarations must
    2588              :          agree on this property.  */
    2589        18640 :       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
    2590              :         {
    2591              :           /* Nothing to check.  Since OLDDECL is marked threadprivate
    2592              :              and NEWDECL does not have a thread-local attribute, we
    2593              :              will merge the threadprivate attribute into NEWDECL.  */
    2594              :           ;
    2595              :         }
    2596        55707 :       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
    2597              :         {
    2598            6 :           auto_diagnostic_group d;
    2599            6 :           if (DECL_THREAD_LOCAL_P (newdecl))
    2600            3 :             error ("thread-local declaration of %q+D follows "
    2601              :                    "non-thread-local declaration", newdecl);
    2602              :           else
    2603            3 :             error ("non-thread-local declaration of %q+D follows "
    2604              :                    "thread-local declaration", newdecl);
    2605              : 
    2606            6 :           locate_old_decl (olddecl);
    2607            6 :           return false;
    2608            6 :         }
    2609              : 
    2610              :       /* Multiple initialized definitions are not allowed (6.9p3,5).
    2611              :          For this purpose, C23 makes it clear that thread-local
    2612              :          declarations without extern are definitions, not tentative
    2613              :          definitions, whether or not they have initializers.  The
    2614              :          wording before C23 was unclear; literally it would have made
    2615              :          uninitialized thread-local declarations into tentative
    2616              :          definitions only if they also used static, but without saying
    2617              :          explicitly whether or not other cases count as
    2618              :          definitions at all.  */
    2619        19195 :       if ((DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
    2620        19194 :           || (flag_isoc23
    2621         6466 :               && DECL_THREAD_LOCAL_P (newdecl)
    2622           25 :               && !DECL_EXTERNAL (newdecl)
    2623           21 :               && !DECL_EXTERNAL (olddecl)))
    2624              :         {
    2625            7 :           auto_diagnostic_group d;
    2626            7 :           error ("redefinition of %q+D", newdecl);
    2627            7 :           locate_old_decl (olddecl);
    2628            7 :           return false;
    2629            7 :         }
    2630              : 
    2631              :       /* Objects declared at file scope: if the first declaration had
    2632              :          external linkage (even if it was an external reference) the
    2633              :          second must have external linkage as well, or the behavior is
    2634              :          undefined.  If the first declaration had internal linkage, then
    2635              :          the second must too, or else be an external reference (in which
    2636              :          case the composite declaration still has internal linkage).
    2637              :          As for function declarations, we warn about the static-then-
    2638              :          extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
    2639        18644 :       if (DECL_FILE_SCOPE_P (newdecl)
    2640        18627 :           && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
    2641              :         {
    2642          147 :           if (DECL_EXTERNAL (newdecl))
    2643              :             {
    2644          144 :               if (!DECL_FILE_SCOPE_P (olddecl))
    2645              :                 {
    2646            2 :                   auto_diagnostic_group d;
    2647            2 :                   error ("extern declaration of %q+D follows "
    2648              :                          "declaration with no linkage", newdecl);
    2649            2 :                   locate_old_decl (olddecl);
    2650            2 :                   return false;
    2651            2 :                 }
    2652          142 :               else if (warn_traditional)
    2653              :                 {
    2654            0 :                   warned |= warning (OPT_Wtraditional,
    2655              :                                      "non-static declaration of %q+D "
    2656              :                                      "follows static declaration", newdecl);
    2657              :                 }
    2658              :             }
    2659              :           else
    2660              :             {
    2661            3 :               auto_diagnostic_group d;
    2662            3 :               if (TREE_PUBLIC (newdecl))
    2663            2 :                 error ("non-static declaration of %q+D follows "
    2664              :                        "static declaration", newdecl);
    2665              :               else
    2666            1 :                 error ("static declaration of %q+D follows "
    2667              :                        "non-static declaration", newdecl);
    2668              : 
    2669            3 :               locate_old_decl (olddecl);
    2670            3 :               return false;
    2671            3 :             }
    2672              :         }
    2673              :       /* Two objects with the same name declared at the same block
    2674              :          scope must both be external references (6.7p3).  */
    2675        18480 :       else if (!DECL_FILE_SCOPE_P (newdecl))
    2676              :         {
    2677           17 :           if (DECL_EXTERNAL (newdecl))
    2678              :             {
    2679              :               /* Extern with initializer at block scope, which will
    2680              :                  already have received an error.  */
    2681              :             }
    2682           15 :           else if (DECL_EXTERNAL (olddecl))
    2683              :             {
    2684            4 :               auto_diagnostic_group d;
    2685            4 :               error ("declaration of %q+D with no linkage follows "
    2686              :                      "extern declaration", newdecl);
    2687            4 :               locate_old_decl (olddecl);
    2688            4 :             }
    2689              :           else
    2690              :             {
    2691           11 :               auto_diagnostic_group d;
    2692           11 :               error ("redeclaration of %q+D with no linkage", newdecl);
    2693           11 :               locate_old_decl (olddecl);
    2694           11 :             }
    2695              : 
    2696           17 :           return false;
    2697              :         }
    2698              : 
    2699              :       /* C++ does not permit a decl to appear multiple times at file
    2700              :          scope.  */
    2701        18605 :       if (warn_cxx_compat
    2702           68 :           && DECL_FILE_SCOPE_P (newdecl)
    2703           68 :           && !DECL_EXTERNAL (newdecl)
    2704        18623 :           && !DECL_EXTERNAL (olddecl))
    2705            5 :         warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
    2706            5 :                               OPT_Wc___compat,
    2707              :                               "duplicate declaration of %qD is "
    2708              :                               "invalid in C++", newdecl);
    2709              :     }
    2710              : 
    2711              :   /* warnings */
    2712              :   /* All decls must agree on a visibility.  */
    2713      5067871 :   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
    2714      5067834 :       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
    2715      5068614 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2716              :     {
    2717            1 :       warned |= warning (0, "redeclaration of %q+D with different visibility "
    2718              :                          "(old visibility preserved)", newdecl);
    2719              :     }
    2720              : 
    2721      5067871 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2722      5049229 :     warned |= diagnose_mismatched_attributes (olddecl, newdecl);
    2723              :   else /* PARM_DECL, VAR_DECL */
    2724              :     {
    2725              :       /* Redeclaration of a parameter is a constraint violation (this is
    2726              :          not explicitly stated, but follows from C99 6.7p3 [no more than
    2727              :          one declaration of the same identifier with no linkage in the
    2728              :          same scope, except type tags] and 6.2.2p6 [parameters have no
    2729              :          linkage]).  We must check for a forward parameter declaration,
    2730              :          indicated by TREE_ASM_WRITTEN on the old declaration - this is
    2731              :          an extension, the mandatory diagnostic for which is handled by
    2732              :          mark_forward_parm_decls.  */
    2733              : 
    2734        18642 :       if (TREE_CODE (newdecl) == PARM_DECL
    2735           37 :           && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
    2736              :         {
    2737            2 :           auto_diagnostic_group d;
    2738            2 :           error ("redefinition of parameter %q+D", newdecl);
    2739            2 :           locate_old_decl (olddecl);
    2740            2 :           return false;
    2741            2 :         }
    2742              :     }
    2743              : 
    2744              :   /* Optional warning for completely redundant decls.  */
    2745      5067869 :   if (!warned && !pedwarned
    2746      5067795 :       && warn_redundant_decls
    2747              :       /* Don't warn about a function declaration followed by a
    2748              :          definition.  */
    2749           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2750            2 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
    2751              :       /* Don't warn about redundant redeclarations of builtins.  */
    2752           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2753            2 :            && !fndecl_built_in_p (newdecl)
    2754            2 :            && fndecl_built_in_p (olddecl)
    2755            2 :            && !C_DECL_DECLARED_BUILTIN (olddecl))
    2756              :       /* Don't warn about an extern followed by a definition.  */
    2757           17 :       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
    2758              :       /* Don't warn about forward parameter decls.  */
    2759           17 :       && !(TREE_CODE (newdecl) == PARM_DECL
    2760            6 :            && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2761              :       /* Don't warn about a variable definition following a declaration.  */
    2762      5067880 :       && !(VAR_P (newdecl)
    2763           10 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
    2764              :     {
    2765            6 :       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
    2766              :                         newdecl);
    2767              :     }
    2768              : 
    2769              :   /* Report location of previous decl/defn.  */
    2770      5067869 :   if (warned || pedwarned)
    2771           80 :     locate_old_decl (olddecl);
    2772              : 
    2773              : #undef DECL_EXTERN_INLINE
    2774              : 
    2775              :   return retval;
    2776      5114731 : }
    2777              : 
    2778              : /* Subroutine of duplicate_decls.  NEWDECL has been found to be
    2779              :    consistent with OLDDECL, but carries new information.  Merge the
    2780              :    new information into OLDDECL.  This function issues no
    2781              :    diagnostics.  */
    2782              : 
    2783              : static void
    2784      5113729 : merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
    2785              : {
    2786      5113729 :   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
    2787      5113729 :                             && DECL_INITIAL (newdecl) != NULL_TREE);
    2788      5113729 :   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
    2789      5113729 :                            && prototype_p (TREE_TYPE (newdecl)));
    2790      5113729 :   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
    2791      5113729 :                            && prototype_p (TREE_TYPE (olddecl)));
    2792              : 
    2793              :   /* For real parm decl following a forward decl, rechain the old decl
    2794              :      in its new location and clear TREE_ASM_WRITTEN (it's not a
    2795              :      forward decl anymore).  */
    2796      5113729 :   if (TREE_CODE (newdecl) == PARM_DECL
    2797           35 :       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2798              :     {
    2799           35 :       struct c_binding *b, **here;
    2800              : 
    2801           54 :       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
    2802           54 :         if ((*here)->decl == olddecl)
    2803           35 :           goto found;
    2804            0 :       gcc_unreachable ();
    2805              : 
    2806           35 :     found:
    2807           35 :       b = *here;
    2808           35 :       *here = b->prev;
    2809           35 :       b->prev = current_scope->bindings;
    2810           35 :       current_scope->bindings = b;
    2811              : 
    2812           35 :       TREE_ASM_WRITTEN (olddecl) = 0;
    2813              :     }
    2814              : 
    2815      5113729 :   DECL_ATTRIBUTES (newdecl)
    2816      5113729 :     = targetm.merge_decl_attributes (olddecl, newdecl);
    2817              : 
    2818              :   /* For typedefs use the old type, as the new type's DECL_NAME points
    2819              :      at newdecl, which will be ggc_freed.  */
    2820      5113729 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2821              :     {
    2822              :       /* But NEWTYPE might have an attribute, honor that.  */
    2823        45860 :       tree tem = newtype;
    2824        45860 :       newtype = oldtype;
    2825              : 
    2826        45860 :       if (TYPE_USER_ALIGN (tem))
    2827              :         {
    2828           15 :           if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2829            6 :             SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2830           15 :           TYPE_USER_ALIGN (newtype) = true;
    2831              :         }
    2832              : 
    2833              :       /* And remove the new type from the variants list.  */
    2834        45860 :       if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2835              :         {
    2836           15 :           tree remove = TREE_TYPE (newdecl);
    2837           15 :           if (TYPE_MAIN_VARIANT (remove) == remove)
    2838              :             {
    2839            2 :               gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2840              :               /* If remove is the main variant, no need to remove that
    2841              :                  from the list.  One of the DECL_ORIGINAL_TYPE
    2842              :                  variants, e.g. created for aligned attribute, might still
    2843              :                  refer to the newdecl TYPE_DECL though, so remove that one
    2844              :                  in that case.  */
    2845            2 :               if (DECL_ORIGINAL_TYPE (newdecl)
    2846            2 :                   && DECL_ORIGINAL_TYPE (newdecl) != remove)
    2847            2 :                 for (tree t = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (newdecl));
    2848            2 :                      t; t = TYPE_MAIN_VARIANT (t))
    2849            2 :                   if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2850              :                     {
    2851            4 :                       TYPE_NEXT_VARIANT (t)
    2852            2 :                         = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2853            2 :                       break;
    2854              :                     }
    2855              :             }
    2856              :           else
    2857           13 :             for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2858            0 :                  t = TYPE_NEXT_VARIANT (t))
    2859           13 :               if (TYPE_NEXT_VARIANT (t) == remove)
    2860              :                 {
    2861           13 :                   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2862           13 :                   break;
    2863              :                 }
    2864              :         }
    2865              : 
    2866              :       /* Make sure we refer to the same type as the olddecl.  */
    2867        45860 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2868              :     }
    2869              : 
    2870              :   /* Merge the data types specified in the two decls.  */
    2871     10227458 :   TREE_TYPE (newdecl)
    2872      5113729 :     = TREE_TYPE (olddecl)
    2873     10227458 :     = composite_type (newtype, oldtype);
    2874              : 
    2875              :   /* Lay the type out, unless already done.  */
    2876      5113729 :   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
    2877              :     {
    2878            0 :       if (TREE_TYPE (newdecl) != error_mark_node)
    2879            0 :         layout_type (TREE_TYPE (newdecl));
    2880            0 :       if (TREE_CODE (newdecl) != FUNCTION_DECL
    2881              :           && TREE_CODE (newdecl) != TYPE_DECL
    2882              :           && TREE_CODE (newdecl) != CONST_DECL)
    2883            0 :         layout_decl (newdecl, 0);
    2884              :     }
    2885              :   else
    2886              :     {
    2887              :       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
    2888      5113729 :       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
    2889      5113729 :       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
    2890      5113729 :       SET_DECL_MODE (newdecl, DECL_MODE (olddecl));
    2891      5113729 :       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    2892              :         {
    2893           44 :           SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    2894           44 :           DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    2895              :         }
    2896      5113685 :       else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    2897      5113685 :                && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    2898            3 :         DECL_USER_ALIGN (newdecl) = 1;
    2899     10227458 :       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    2900      5113729 :           > DECL_WARN_IF_NOT_ALIGN (newdecl))
    2901            0 :         SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    2902              :                                     DECL_WARN_IF_NOT_ALIGN (olddecl));
    2903              :     }
    2904              : 
    2905              :   /* Keep the old rtl since we can safely use it.  */
    2906      5113729 :   if (HAS_RTL_P (olddecl))
    2907      5113729 :     COPY_DECL_RTL (olddecl, newdecl);
    2908              : 
    2909              :   /* Merge the type qualifiers.  */
    2910      5113729 :   if (TREE_READONLY (newdecl))
    2911       410351 :     TREE_READONLY (olddecl) = 1;
    2912              : 
    2913      5113729 :   if (TREE_THIS_VOLATILE (newdecl))
    2914        49826 :     TREE_THIS_VOLATILE (olddecl) = 1;
    2915              : 
    2916              :   /* Merge deprecatedness.  */
    2917      5113729 :   if (TREE_DEPRECATED (newdecl))
    2918          383 :     TREE_DEPRECATED (olddecl) = 1;
    2919              : 
    2920              :   /* Merge unavailability.  */
    2921      5113729 :   if (TREE_UNAVAILABLE (newdecl))
    2922            2 :     TREE_UNAVAILABLE (olddecl) = 1;
    2923              : 
    2924              :   /* If a decl is in a system header and the other isn't, keep the one on the
    2925              :      system header. Otherwise, keep source location of definition rather than
    2926              :      declaration and of prototype rather than non-prototype unless that
    2927              :      prototype is built-in.  */
    2928      5113729 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2929      5113694 :       && DECL_IN_SYSTEM_HEADER (olddecl)
    2930      5811550 :       && !DECL_IN_SYSTEM_HEADER (newdecl) )
    2931         1046 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2932      5112683 :   else if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2933      5112648 :            && DECL_IN_SYSTEM_HEADER (newdecl)
    2934      9487649 :            && !DECL_IN_SYSTEM_HEADER (olddecl))
    2935      3678191 :     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
    2936      1434492 :   else if ((DECL_INITIAL (newdecl) == NULL_TREE
    2937      1200574 :             && DECL_INITIAL (olddecl) != NULL_TREE)
    2938      2634144 :            || (old_is_prototype && !new_is_prototype
    2939          372 :                && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
    2940          950 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2941              : 
    2942              :   /* Merge the initialization information.  */
    2943      5113729 :    if (DECL_INITIAL (newdecl) == NULL_TREE)
    2944      4879739 :     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2945              : 
    2946              :   /* Merge 'constexpr' information.  */
    2947      5113729 :   if (VAR_P (olddecl) && VAR_P (newdecl))
    2948              :     {
    2949        18605 :       if (C_DECL_DECLARED_CONSTEXPR (olddecl))
    2950            2 :         C_DECL_DECLARED_CONSTEXPR (newdecl) = 1;
    2951        18603 :       else if (C_DECL_DECLARED_CONSTEXPR (newdecl))
    2952            1 :         C_DECL_DECLARED_CONSTEXPR (olddecl) = 1;
    2953              :     }
    2954              : 
    2955              :   /* Merge the threadprivate attribute.  */
    2956      5113729 :   if (VAR_P (olddecl) && C_DECL_THREADPRIVATE_P (olddecl))
    2957            7 :     C_DECL_THREADPRIVATE_P (newdecl) = 1;
    2958              : 
    2959      5113729 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl))
    2960              :     {
    2961              :       /* Copy the assembler name.
    2962              :          Currently, it can only be defined in the prototype.  */
    2963      5113694 :       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2964              : 
    2965              :       /* Use visibility of whichever declaration had it specified */
    2966      5113694 :       if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2967              :         {
    2968         4776 :           DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2969         4776 :           DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2970              :         }
    2971              : 
    2972      5113694 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2973              :         {
    2974      5049229 :           DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
    2975      5049229 :           DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2976      5049229 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2977      5049229 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2978      5049229 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2979      5049229 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2980      5049229 :           DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    2981      5049229 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2982            0 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2983      5049229 :           if (DECL_IS_OPERATOR_DELETE_P (olddecl))
    2984            0 :             DECL_SET_IS_OPERATOR_DELETE (newdecl, true);
    2985      5049229 :           TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    2986      5049229 :           DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    2987      5049229 :           DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    2988              :         }
    2989              : 
    2990              :       /* Merge the storage class information.  */
    2991      5113694 :       merge_weak (newdecl, olddecl);
    2992              : 
    2993              :       /* For functions, static overrides non-static.  */
    2994      5113694 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2995              :         {
    2996      5049229 :           TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
    2997              :           /* This is since we don't automatically
    2998              :              copy the attributes of NEWDECL into OLDDECL.  */
    2999      5049229 :           TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3000              :           /* If this clears `static', clear it in the identifier too.  */
    3001      5049229 :           if (!TREE_PUBLIC (olddecl))
    3002         7827 :             TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
    3003              :         }
    3004              :     }
    3005              : 
    3006              :   /* In c99, 'extern' declaration before (or after) 'inline' means this
    3007              :      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
    3008              :      is present.  */
    3009      5113729 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3010      5049229 :       && !flag_gnu89_inline
    3011      5024728 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3012      4834121 :           || DECL_DECLARED_INLINE_P (olddecl))
    3013       190801 :       && (!DECL_DECLARED_INLINE_P (newdecl)
    3014       190607 :           || !DECL_DECLARED_INLINE_P (olddecl)
    3015          819 :           || !DECL_EXTERNAL (olddecl))
    3016       190000 :       && DECL_EXTERNAL (newdecl)
    3017       189792 :       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
    3018      5113827 :       && !current_function_decl)
    3019           81 :     DECL_EXTERNAL (newdecl) = 0;
    3020              : 
    3021              :   /* An inline definition following a static declaration is not
    3022              :      DECL_EXTERNAL.  */
    3023      5113729 :   if (new_is_definition
    3024       233409 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3025        42580 :           || DECL_DECLARED_INLINE_P (olddecl))
    3026      5304772 :       && !TREE_PUBLIC (olddecl))
    3027          912 :     DECL_EXTERNAL (newdecl) = 0;
    3028              : 
    3029      5113729 :   if (DECL_EXTERNAL (newdecl))
    3030              :     {
    3031      5022062 :       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
    3032      5022062 :       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
    3033              : 
    3034              :       /* An extern decl does not override previous storage class.  */
    3035      5022062 :       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3036      5022062 :       if (!DECL_EXTERNAL (newdecl))
    3037              :         {
    3038         1437 :           DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    3039         1437 :           DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3040              :         }
    3041              :     }
    3042              :   else
    3043              :     {
    3044        91667 :       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
    3045        91667 :       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3046              :     }
    3047              : 
    3048      5113729 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3049              :     {
    3050      5049229 :       if (DECL_FUNCTION_VERSIONED (olddecl)
    3051      5049229 :           || DECL_FUNCTION_VERSIONED (newdecl))
    3052              :         {
    3053            0 :           maybe_mark_function_versioned (olddecl);
    3054            0 :           maybe_mark_function_versioned (newdecl);
    3055              :         }
    3056              :       /* If we're redefining a function previously defined as extern
    3057              :          inline, make sure we emit debug info for the inline before we
    3058              :          throw it away, in case it was inlined into a function that
    3059              :          hasn't been written out yet.  */
    3060      5049229 :       if (new_is_definition && DECL_INITIAL (olddecl))
    3061              :         /* The new defn must not be inline.  */
    3062           75 :         DECL_UNINLINABLE (newdecl) = 1;
    3063              :       else
    3064              :         {
    3065              :           /* If either decl says `inline', this fn is inline, unless
    3066              :              its definition was passed already.  */
    3067      5049154 :           if (DECL_DECLARED_INLINE_P (newdecl)
    3068      9907427 :               || DECL_DECLARED_INLINE_P (olddecl))
    3069       191066 :             DECL_DECLARED_INLINE_P (newdecl) = 1;
    3070              : 
    3071     15147462 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3072     10099986 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3073              : 
    3074     10098308 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3075      5049154 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3076      5049154 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3077     10098170 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3078              :         }
    3079              : 
    3080      5049229 :       if (fndecl_built_in_p (olddecl))
    3081              :         {
    3082              :           /* If redeclaring a builtin function, it stays built in.
    3083              :              But it gets tagged as having been declared.  */
    3084      3996010 :           copy_decl_built_in_function (newdecl, olddecl);
    3085      3996010 :           C_DECL_DECLARED_BUILTIN (newdecl) = 1;
    3086      3996010 :           if (new_is_prototype)
    3087              :             {
    3088      3995651 :               C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
    3089      3995651 :               if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3090              :                 {
    3091      3995651 :                   enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3092      3995651 :                   switch (fncode)
    3093              :                     {
    3094              :                       /* If a compatible prototype of these builtin functions
    3095              :                          is seen, assume the runtime implements it with the
    3096              :                          expected semantics.  */
    3097         6616 :                     case BUILT_IN_STPCPY:
    3098         6616 :                       if (builtin_decl_explicit_p (fncode))
    3099         6616 :                         set_builtin_decl_implicit_p (fncode, true);
    3100              :                       break;
    3101      3989035 :                     default:
    3102      3989035 :                       if (builtin_decl_explicit_p (fncode))
    3103      3989035 :                         set_builtin_decl_declared_p (fncode, true);
    3104              :                       break;
    3105              :                     }
    3106              : 
    3107      3995651 :                   copy_attributes_to_builtin (newdecl);
    3108              :                 }
    3109              :             }
    3110              :           else
    3111          718 :             C_DECL_BUILTIN_PROTOTYPE (newdecl)
    3112          718 :               = C_DECL_BUILTIN_PROTOTYPE (olddecl);
    3113              :         }
    3114              : 
    3115              :       /* Preserve function specific target and optimization options */
    3116      5049229 :       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3117      5049735 :           && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3118          470 :         DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3119          470 :           = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3120              : 
    3121      5049229 :       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3122      5072651 :           && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3123            9 :         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3124            9 :           = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3125              : 
    3126              :       /* Also preserve various other info from the definition.  */
    3127      5049229 :       if (!new_is_definition)
    3128              :         {
    3129      4815820 :           tree t;
    3130      4815820 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3131      4815820 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3132      4815820 :           DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3133      4815820 :           DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3134      4815820 :           DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
    3135      7498275 :           for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
    3136      2682455 :             DECL_CONTEXT (t) = newdecl;
    3137              : 
    3138              :           /* See if we've got a function to instantiate from.  */
    3139      4815820 :           if (DECL_SAVED_TREE (olddecl))
    3140         1620 :             DECL_ABSTRACT_ORIGIN (newdecl)
    3141          810 :               = DECL_ABSTRACT_ORIGIN (olddecl);
    3142              :         }
    3143              :     }
    3144              : 
    3145              :   /* Merge the USED information.  */
    3146      5113729 :   if (TREE_USED (olddecl))
    3147       717429 :     TREE_USED (newdecl) = 1;
    3148      4396300 :   else if (TREE_USED (newdecl))
    3149            4 :     TREE_USED (olddecl) = 1;
    3150      5113729 :   if (VAR_P (olddecl) || TREE_CODE (olddecl) == PARM_DECL)
    3151        18640 :     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
    3152      5113729 :   if (DECL_PRESERVE_P (olddecl))
    3153           25 :     DECL_PRESERVE_P (newdecl) = 1;
    3154      5113704 :   else if (DECL_PRESERVE_P (newdecl))
    3155            4 :     DECL_PRESERVE_P (olddecl) = 1;
    3156              : 
    3157              :   /* Merge DECL_COMMON */
    3158        18605 :   if (VAR_P (olddecl) && VAR_P (newdecl)
    3159        18605 :       && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl))
    3160      5132332 :       && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl)))
    3161        37202 :     DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl);
    3162              : 
    3163              :   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
    3164              :      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
    3165              :      DECL_ARGUMENTS (if appropriate).  */
    3166      5113729 :   {
    3167      5113729 :     unsigned olddecl_uid = DECL_UID (olddecl);
    3168      5113729 :     tree olddecl_context = DECL_CONTEXT (olddecl);
    3169      5113729 :     tree olddecl_arguments = NULL;
    3170      5113729 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3171      5049229 :       olddecl_arguments = DECL_ARGUMENTS (olddecl);
    3172              : 
    3173      5113729 :     memcpy ((char *) olddecl + sizeof (struct tree_common),
    3174              :             (char *) newdecl + sizeof (struct tree_common),
    3175              :             sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3176      5113729 :     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3177      5113729 :     switch (TREE_CODE (olddecl))
    3178              :       {
    3179      5067834 :       case FUNCTION_DECL:
    3180      5067834 :       case VAR_DECL:
    3181      5067834 :         {
    3182      5067834 :           struct symtab_node *snode = olddecl->decl_with_vis.symtab_node;
    3183              : 
    3184     10135668 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3185              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3186      5067834 :                   tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3187      5067834 :           olddecl->decl_with_vis.symtab_node = snode;
    3188              : 
    3189      5067834 :           if ((DECL_EXTERNAL (olddecl)
    3190        47209 :                || TREE_PUBLIC (olddecl)
    3191         8100 :                || TREE_STATIC (olddecl))
    3192      5115036 :               && DECL_SECTION_NAME (newdecl) != NULL)
    3193            8 :             set_decl_section_name (olddecl, newdecl);
    3194              : 
    3195              :           /* This isn't quite correct for something like
    3196              :                 int __thread x attribute ((tls_model ("local-exec")));
    3197              :                 extern int __thread x;
    3198              :              as we'll lose the "local-exec" model.  */
    3199      5067834 :           if (VAR_P (olddecl) && DECL_THREAD_LOCAL_P (newdecl))
    3200           89 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3201              :           break;
    3202              :         }
    3203              : 
    3204        45895 :       case FIELD_DECL:
    3205        45895 :       case PARM_DECL:
    3206        45895 :       case LABEL_DECL:
    3207        45895 :       case RESULT_DECL:
    3208        45895 :       case CONST_DECL:
    3209        45895 :       case TYPE_DECL:
    3210        91790 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3211              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3212        45895 :                 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3213        45895 :         break;
    3214              : 
    3215            0 :       default:
    3216              : 
    3217            0 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3218              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3219              :                 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
    3220              :       }
    3221      5113729 :     DECL_UID (olddecl) = olddecl_uid;
    3222      5113729 :     DECL_CONTEXT (olddecl) = olddecl_context;
    3223      5113729 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3224      5049229 :       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
    3225              :   }
    3226              : 
    3227              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3228              :      so that encode_section_info has a chance to look at the new decl
    3229              :      flags and attributes.  */
    3230      5113729 :   if (DECL_RTL_SET_P (olddecl)
    3231      5113735 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3232            6 :           || (VAR_P (olddecl) && TREE_STATIC (olddecl))))
    3233            6 :     make_decl_rtl (olddecl);
    3234      5113729 : }
    3235              : 
    3236              : /* Handle when a new declaration NEWDECL has the same name as an old
    3237              :    one OLDDECL in the same binding contour.  Prints an error message
    3238              :    if appropriate.
    3239              : 
    3240              :    If safely possible, alter OLDDECL to look like NEWDECL, and return
    3241              :    true.  Otherwise, return false.  */
    3242              : 
    3243              : static bool
    3244      5114834 : duplicate_decls (tree newdecl, tree olddecl)
    3245              : {
    3246      5114834 :   tree newtype = NULL, oldtype = NULL;
    3247              : 
    3248      5114834 :   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
    3249              :     {
    3250              :       /* Avoid `unused variable' and other warnings for OLDDECL.  */
    3251         1105 :       suppress_warning (olddecl, OPT_Wunused);
    3252              :       /* If the types are completely different, poison them both with
    3253              :          error_mark_node.  */
    3254         1105 :       if (TREE_CODE (TREE_TYPE (newdecl)) != TREE_CODE (TREE_TYPE (olddecl))
    3255          118 :           && olddecl != error_mark_node
    3256         1203 :           && seen_error ())
    3257              :         {
    3258           65 :           if (TREE_CODE (olddecl) != FUNCTION_DECL)
    3259           53 :             TREE_TYPE (olddecl) = error_mark_node;
    3260           65 :           if (TREE_CODE (newdecl) != FUNCTION_DECL)
    3261           61 :             TREE_TYPE (newdecl) = error_mark_node;
    3262              :         }
    3263         1105 :       return false;
    3264              :     }
    3265              : 
    3266      5113729 :   merge_decls (newdecl, olddecl, newtype, oldtype);
    3267              : 
    3268              :   /* The NEWDECL will no longer be needed.
    3269              : 
    3270              :      Before releasing the node, be sure to remove function from symbol
    3271              :      table that might have been inserted there to record comdat group.
    3272              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3273              :      structure is shared in between NEWDECL and OLDECL.  */
    3274      5113729 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3275      5049229 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3276      5113729 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3277              :     {
    3278      5067834 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3279      5067834 :       if (snode)
    3280          104 :         snode->remove ();
    3281              :     }
    3282      5113729 :   ggc_free (newdecl);
    3283      5113729 :   return true;
    3284              : }
    3285              : 
    3286              : 
    3287              : /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
    3288              : static void
    3289    171126094 : warn_if_shadowing (tree new_decl)
    3290              : {
    3291    171126094 :   struct c_binding *b;
    3292              : 
    3293              :   /* Shadow warnings wanted?  */
    3294    342251272 :   if (!(warn_shadow
    3295    171125358 :         || warn_shadow_local
    3296    171125178 :         || warn_shadow_compatible_local)
    3297              :       /* No shadow warnings for internally generated vars.  */
    3298    171126337 :       || DECL_IS_UNDECLARED_BUILTIN (new_decl))
    3299              :     return;
    3300              : 
    3301              :   /* Is anything being shadowed?  Invisible decls do not count.  */
    3302          253 :   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
    3303          157 :     if (b->decl && b->decl != new_decl && !b->invisible
    3304          214 :         && (b->decl == error_mark_node
    3305           43 :             || diagnostic_report_warnings_p (global_dc,
    3306              :                                              DECL_SOURCE_LOCATION (b->decl))))
    3307              :       {
    3308           57 :         tree old_decl = b->decl;
    3309              : 
    3310           57 :         if (old_decl == error_mark_node)
    3311              :           {
    3312           14 :             warning (OPT_Wshadow, "declaration of %q+D shadows previous "
    3313              :                      "non-variable", new_decl);
    3314           50 :             break;
    3315              :           }
    3316              : 
    3317           43 :         bool warned = false;
    3318           43 :         auto_diagnostic_group d;
    3319           43 :         if (TREE_CODE (old_decl) == PARM_DECL)
    3320              :           {
    3321            5 :             enum opt_code warning_code;
    3322              : 
    3323              :             /* If '-Wshadow=compatible-local' is specified without other
    3324              :                -Wshadow= flags, we will warn only when the types of the
    3325              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3326              :                (old_decl) are compatible.  */
    3327            5 :             if (warn_shadow)
    3328              :               warning_code = OPT_Wshadow;
    3329            2 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3330              :               warning_code = OPT_Wshadow_compatible_local;
    3331              :             else
    3332            2 :               warning_code = OPT_Wshadow_local;
    3333            5 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3334              :                                  "declaration of %qD shadows a parameter",
    3335              :                                  new_decl);
    3336              :           }
    3337           38 :         else if (DECL_FILE_SCOPE_P (old_decl))
    3338              :           {
    3339              :             /* Do not warn if a variable shadows a function, unless
    3340              :                the variable is a function or a pointer-to-function.  */
    3341           34 :             if (TREE_CODE (old_decl) == FUNCTION_DECL
    3342           11 :                 && TREE_CODE (new_decl) != FUNCTION_DECL
    3343           36 :                 && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
    3344            7 :                 continue;
    3345              : 
    3346           20 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
    3347              :                                  "declaration of %qD shadows a global "
    3348              :                                  "declaration",
    3349              :                                  new_decl);
    3350              :           }
    3351           11 :         else if (TREE_CODE (old_decl) == FUNCTION_DECL
    3352           11 :                  && fndecl_built_in_p (old_decl))
    3353              :           {
    3354            0 :             warning (OPT_Wshadow, "declaration of %q+D shadows "
    3355              :                      "a built-in function", new_decl);
    3356            0 :             break;
    3357              :           }
    3358              :         else
    3359              :           {
    3360           11 :             enum opt_code warning_code;
    3361              : 
    3362              :             /* If '-Wshadow=compatible-local' is specified without other
    3363              :                -Wshadow= flags, we will warn only when the types of the
    3364              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3365              :                (old_decl) are compatible.  */
    3366           11 :             if (warn_shadow)
    3367              :               warning_code = OPT_Wshadow;
    3368            8 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3369              :               warning_code = OPT_Wshadow_compatible_local;
    3370              :             else
    3371            2 :               warning_code = OPT_Wshadow_local;
    3372           11 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3373              :                                  "declaration of %qD shadows a previous local",
    3374              :                                  new_decl);
    3375              :           }
    3376              : 
    3377           36 :         if (warned)
    3378           26 :           inform (DECL_SOURCE_LOCATION (old_decl),
    3379              :                   "shadowed declaration is here");
    3380              : 
    3381              :         break;
    3382           43 :       }
    3383              : }
    3384              : 
    3385              : /* Record a decl-node X as belonging to the current lexical scope.
    3386              :    Check for errors (such as an incompatible declaration for the same
    3387              :    name already seen in the same scope).
    3388              : 
    3389              :    Returns either X or an old decl for the same name.
    3390              :    If an old decl is returned, it may have been smashed
    3391              :    to agree with what X says.  */
    3392              : 
    3393              : tree
    3394    204227018 : pushdecl (tree x)
    3395              : {
    3396    204227018 :   tree name = DECL_NAME (x);
    3397    204227018 :   struct c_scope *scope = current_scope;
    3398    204227018 :   struct c_binding *b;
    3399    204227018 :   bool nested = false;
    3400    204227018 :   location_t locus = DECL_SOURCE_LOCATION (x);
    3401              : 
    3402              :   /* Must set DECL_CONTEXT for everything not at file scope or
    3403              :      DECL_FILE_SCOPE_P won't work.  Local externs don't count
    3404              :      unless they have initializers (which generate code).  We
    3405              :      also exclude CONST_DECLs because enumerators will get the
    3406              :      type of the enum as context.  */
    3407    204227018 :   if (current_function_decl
    3408      9147111 :       && TREE_CODE (x) != CONST_DECL
    3409    213216955 :       && (!VAR_OR_FUNCTION_DECL_P (x)
    3410      8711586 :           || DECL_INITIAL (x) || !TREE_PUBLIC (x)))
    3411      8977909 :     DECL_CONTEXT (x) = current_function_decl;
    3412              : 
    3413              :   /* Anonymous decls are just inserted in the scope.  */
    3414    204227018 :   if (!name)
    3415              :     {
    3416      7935712 :       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
    3417              :             locus);
    3418      7935712 :       return x;
    3419              :     }
    3420              : 
    3421              :   /* First, see if there is another declaration with the same name in
    3422              :      the current scope.  If there is, duplicate_decls may do all the
    3423              :      work for us.  If duplicate_decls returns false, that indicates
    3424              :      two incompatible decls in the same scope; we are to silently
    3425              :      replace the old one (duplicate_decls has issued all appropriate
    3426              :      diagnostics).  In particular, we should not consider possible
    3427              :      duplicates in the external scope, or shadowing.  */
    3428    196291306 :   b = I_SYMBOL_BINDING (name);
    3429    196291306 :   if (b && B_IN_SCOPE (b, scope))
    3430              :     {
    3431      1403306 :       struct c_binding *b_ext, *b_use;
    3432      1403306 :       tree type = TREE_TYPE (x);
    3433      1403306 :       tree visdecl = b->decl;
    3434      1403306 :       tree vistype = TREE_TYPE (visdecl);
    3435      1403306 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    3436      1403306 :           && COMPLETE_TYPE_P (TREE_TYPE (x)))
    3437         1372 :         b->inner_comp = false;
    3438      1403306 :       b_use = b;
    3439      1403306 :       b_ext = b;
    3440              :       /* If this is an external linkage declaration, we should check
    3441              :          for compatibility with the type in the external scope before
    3442              :          setting the type at this scope based on the visible
    3443              :          information only.  */
    3444      1403306 :       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
    3445              :         {
    3446      2698422 :           while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    3447      1349221 :             b_ext = b_ext->shadowed;
    3448      1349201 :           if (b_ext)
    3449              :             {
    3450      1349192 :               b_use = b_ext;
    3451      1349192 :               if (b_use->u.type)
    3452       276871 :                 TREE_TYPE (b_use->decl) = b_use->u.type;
    3453              :             }
    3454              :         }
    3455              : 
    3456              :       /* Check if x is part of a FMV set with b_use.
    3457              :          FMV is only supported in c for targets with target_version
    3458              :          attributes.  */
    3459      1403306 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    3460              :           && b_use && TREE_CODE (b_use->decl) == FUNCTION_DECL
    3461              :           && TREE_CODE (x) == FUNCTION_DECL && DECL_FILE_SCOPE_P (b_use->decl)
    3462              :           && DECL_FILE_SCOPE_P (x)
    3463              :           && disjoint_version_decls (x, b_use->decl)
    3464              :           && comptypes (vistype, type))
    3465              :         {
    3466              :           maybe_mark_function_versioned (b_use->decl);
    3467              :           maybe_mark_function_versioned (b->decl);
    3468              :           maybe_mark_function_versioned (x);
    3469              : 
    3470              :           cgraph_node *b_node = cgraph_node::get_create (b_use->decl);
    3471              :           cgraph_function_version_info *b_v = b_node->function_version ();
    3472              :           if (!b_v)
    3473              :             b_v = b_node->insert_new_function_version ();
    3474              : 
    3475              :           /* Check if this new node conflicts with any previous functions
    3476              :              in the set.  */
    3477              :           cgraph_function_version_info *version = b_v;
    3478              :           for (; version; version = version->next)
    3479              :             if (!disjoint_version_decls (version->this_node->decl, x))
    3480              :               {
    3481              :                 /* The decls define overlapping version, so attempt to merge
    3482              :                    or diagnose the conflict.  */
    3483              :                 if (duplicate_decls (x, version->this_node->decl))
    3484              :                   return version->this_node->decl;
    3485              :                 else
    3486              :                   return error_mark_node;
    3487              :               }
    3488              : 
    3489              :           /* This is a new version to be added to FMV structure.  */
    3490              :           cgraph_node::add_function_version (b_v, x);
    3491              : 
    3492              :           /* Get the first node from the structure.  */
    3493              :           cgraph_function_version_info *default_v = b_v;
    3494              :           while (default_v->prev)
    3495              :             default_v = default_v->prev;
    3496              :           /* Always use the default node for the bindings.  */
    3497              :           b_use->decl = default_v->this_node->decl;
    3498              :           b->decl = default_v->this_node->decl;
    3499              : 
    3500              :           /* Node is not a duplicate, so no need to do the rest of the
    3501              :              checks.  */
    3502              :           return x;
    3503              :         }
    3504              : 
    3505      1403306 :       if (duplicate_decls (x, b_use->decl))
    3506              :         {
    3507      1402934 :           if (b_use != b)
    3508              :             {
    3509              :               /* Save the updated type in the external scope and
    3510              :                  restore the proper type for this scope.  */
    3511      1348986 :               tree thistype;
    3512      1348986 :               if (comptypes (vistype, type))
    3513      1348944 :                 thistype = composite_type (vistype, type);
    3514              :               else
    3515           42 :                 thistype = TREE_TYPE (b_use->decl);
    3516      1348986 :               b_use->u.type = TREE_TYPE (b_use->decl);
    3517      1348986 :               if (TREE_CODE (b_use->decl) == FUNCTION_DECL
    3518      1348986 :                   && fndecl_built_in_p (b_use->decl))
    3519       286952 :                 thistype
    3520       286952 :                   = c_build_type_attribute_variant (thistype,
    3521       286952 :                                                     TYPE_ATTRIBUTES
    3522              :                                                     (b_use->u.type));
    3523      1348986 :               TREE_TYPE (b_use->decl) = thistype;
    3524              :             }
    3525      1402934 :           return b_use->decl;
    3526              :         }
    3527              :       else
    3528          372 :         goto skip_external_and_shadow_checks;
    3529              :     }
    3530              : 
    3531              :   /* All declarations with external linkage, and all external
    3532              :      references, go in the external scope, no matter what scope is
    3533              :      current.  However, the binding in that scope is ignored for
    3534              :      purposes of normal name lookup.  A separate binding structure is
    3535              :      created in the requested scope; this governs the normal
    3536              :      visibility of the symbol.
    3537              : 
    3538              :      The binding in the externals scope is used exclusively for
    3539              :      detecting duplicate declarations of the same object, no matter
    3540              :      what scope they are in; this is what we do here.  (C99 6.2.7p2:
    3541              :      All declarations that refer to the same object or function shall
    3542              :      have compatible type; otherwise, the behavior is undefined.)
    3543              :      However, in Objective-C, we also want to detect declarations
    3544              :      conflicting with those of the basic types.  */
    3545    340351278 :   if ((DECL_EXTERNAL (x) || scope == file_scope)
    3546    206450254 :       && (VAR_OR_FUNCTION_DECL_P (x) || c_dialect_objc ()))
    3547              :     {
    3548     51224573 :       tree type = TREE_TYPE (x);
    3549     51224573 :       tree vistype = NULL_TREE;
    3550     51224573 :       tree visdecl = NULL_TREE;
    3551     51224573 :       bool type_saved = false;
    3552      3711555 :       if (b && !B_IN_EXTERNAL_SCOPE (b)
    3553         1038 :           && VAR_OR_FUNCTION_DECL_P (b->decl)
    3554     51225602 :           && DECL_FILE_SCOPE_P (b->decl))
    3555              :         {
    3556          803 :           visdecl = b->decl;
    3557          803 :           vistype = TREE_TYPE (visdecl);
    3558              :         }
    3559     51224573 :       if (scope != file_scope
    3560     51224573 :           && !DECL_IN_SYSTEM_HEADER (x))
    3561        11478 :         warning_at (locus, OPT_Wnested_externs,
    3562              :                     "nested extern declaration of %qD", x);
    3563              : 
    3564     51225997 :       while (b && !B_IN_EXTERNAL_SCOPE (b))
    3565              :         {
    3566              :           /* If this decl might be modified, save its type.  This is
    3567              :              done here rather than when the decl is first bound
    3568              :              because the type may change after first binding, through
    3569              :              being completed or through attributes being added.  If we
    3570              :              encounter multiple such decls, only the first should have
    3571              :              its type saved; the others will already have had their
    3572              :              proper types saved and the types will not have changed as
    3573              :              their scopes will not have been re-entered.  */
    3574         1424 :           if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
    3575              :             {
    3576         1022 :               b->u.type = TREE_TYPE (b->decl);
    3577         1022 :               type_saved = true;
    3578              :             }
    3579         1424 :           if (B_IN_FILE_SCOPE (b)
    3580         1012 :               && VAR_P (b->decl)
    3581          572 :               && TREE_STATIC (b->decl)
    3582          281 :               && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
    3583          138 :               && !TYPE_DOMAIN (TREE_TYPE (b->decl))
    3584           47 :               && TREE_CODE (type) == ARRAY_TYPE
    3585           47 :               && TYPE_DOMAIN (type)
    3586           28 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    3587         1452 :               && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
    3588              :             {
    3589              :               /* Array type completed in inner scope, which should be
    3590              :                  diagnosed if the completion does not have size 1 and
    3591              :                  it does not get completed in the file scope.  */
    3592            6 :               b->inner_comp = true;
    3593              :             }
    3594         1424 :           b = b->shadowed;
    3595              :         }
    3596              : 
    3597              :       /* If a matching external declaration has been found, set its
    3598              :          type to the composite of all the types of that declaration.
    3599              :          After the consistency checks, it will be reset to the
    3600              :          composite of the visible types only.  */
    3601     51224573 :       if (b && b->u.type)
    3602          768 :         TREE_TYPE (b->decl) = b->u.type;
    3603              : 
    3604              :       /* the static does not go in the externals scope.  */
    3605      3711411 :       if (b && duplicate_decls (x, b->decl))
    3606              :         {
    3607      3710678 :           tree thistype;
    3608      3710678 :           if (vistype)
    3609              :             {
    3610          675 :               if (comptypes (vistype, type))
    3611          638 :                 thistype = composite_type (vistype, type);
    3612              :               else
    3613           37 :                 thistype = TREE_TYPE (b->decl);
    3614              :             }
    3615              :           else
    3616              :             thistype = type;
    3617      3710678 :           b->u.type = TREE_TYPE (b->decl);
    3618              :           /* Propagate the type attributes to the decl.  */
    3619      3710678 :           thistype
    3620      3710678 :             = c_build_type_attribute_variant (thistype,
    3621      3710678 :                                               TYPE_ATTRIBUTES (b->u.type));
    3622      3710678 :           TREE_TYPE (b->decl) = thistype;
    3623      3710678 :           bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
    3624              :                 locus);
    3625      3710678 :           return b->decl;
    3626              :         }
    3627     47513895 :       else if (TREE_PUBLIC (x))
    3628              :         {
    3629     47138161 :           if (visdecl && !b && duplicate_decls (x, visdecl))
    3630              :             {
    3631              :               /* An external declaration at block scope referring to a
    3632              :                  visible entity with internal linkage.  The composite
    3633              :                  type will already be correct for this scope, so we
    3634              :                  just need to fall through to make the declaration in
    3635              :                  this scope.  */
    3636              :               nested = true;
    3637              :               x = visdecl;
    3638              :             }
    3639              :           else
    3640              :             {
    3641     47138044 :               bind (name, x, external_scope, /*invisible=*/true,
    3642              :                     /*nested=*/false, locus);
    3643     47138044 :               nested = true;
    3644              :             }
    3645              :         }
    3646              :     }
    3647              : 
    3648    191177322 :   if (TREE_CODE (x) != PARM_DECL)
    3649     71037636 :     warn_if_shadowing (x);
    3650              : 
    3651    120139686 :  skip_external_and_shadow_checks:
    3652    191177694 :   if (TREE_CODE (x) == TYPE_DECL)
    3653              :     {
    3654              :       /* So this is a typedef, set its underlying type.  */
    3655      9990692 :       set_underlying_type (x);
    3656              : 
    3657              :       /* If X is a typedef defined in the current function, record it
    3658              :          for the purpose of implementing the -Wunused-local-typedefs
    3659              :          warning.  */
    3660      9990692 :       record_locally_defined_typedef (x);
    3661              :     }
    3662              : 
    3663    191177694 :   bind (name, x, scope, /*invisible=*/false, nested, locus);
    3664              : 
    3665              :   /* If x's type is incomplete because it's based on a
    3666              :      structure or union which has not yet been fully declared,
    3667              :      attach it to that structure or union type, so we can go
    3668              :      back and complete the variable declaration later, if the
    3669              :      structure or union gets fully declared.
    3670              : 
    3671              :      If the input is erroneous, we can have error_mark in the type
    3672              :      slot (e.g. "f(void a, ...)") - that doesn't count as an
    3673              :      incomplete type.  */
    3674    191177694 :   if (TREE_TYPE (x) != error_mark_node
    3675    191177694 :       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
    3676              :     {
    3677       189800 :       tree element = TREE_TYPE (x);
    3678              : 
    3679       209928 :       while (TREE_CODE (element) == ARRAY_TYPE)
    3680        20128 :         element = TREE_TYPE (element);
    3681       189800 :       element = TYPE_MAIN_VARIANT (element);
    3682              : 
    3683       189800 :       if ((RECORD_OR_UNION_TYPE_P (element)
    3684       145612 :            || TREE_CODE (element) == ENUMERAL_TYPE)
    3685        44259 :           && (TREE_CODE (x) != TYPE_DECL
    3686        40808 :               || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    3687       193261 :           && !COMPLETE_TYPE_P (element))
    3688          321 :         C_TYPE_INCOMPLETE_VARS (element)
    3689          642 :           = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
    3690              :     }
    3691              :   return x;
    3692              : }
    3693              : 
    3694              : 
    3695              : /* Issue a permerror about implicit function declaration.  ID is the function
    3696              :    identifier, OLDDECL is a declaration of the function in a different scope,
    3697              :    or NULL_TREE.  */
    3698              : 
    3699              : static void
    3700         3776 : implicit_decl_permerror (location_t loc, tree id, tree olddecl)
    3701              : {
    3702         3776 :   if (!warn_implicit_function_declaration)
    3703         2617 :     return;
    3704              : 
    3705         1159 :   bool warned;
    3706         1159 :   auto_diagnostic_group d;
    3707         1159 :   name_hint hint;
    3708         1159 :   if (!olddecl)
    3709          553 :     hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc);
    3710              : 
    3711         1159 :   if (flag_isoc99)
    3712              :     {
    3713         1153 :       if (const char *suggestion = hint.suggestion ())
    3714              :         {
    3715          107 :           gcc_rich_location richloc (loc);
    3716          107 :           richloc.add_fixit_replace (suggestion);
    3717          107 :           warned = permerror_opt (&richloc, OPT_Wimplicit_function_declaration,
    3718              :                                   "implicit declaration of function %qE;"
    3719              :                                   " did you mean %qs?",
    3720              :                                   id, suggestion);
    3721          107 :         }
    3722              :       else
    3723         1046 :         warned = permerror_opt (loc, OPT_Wimplicit_function_declaration,
    3724              :                                 "implicit declaration of function %qE", id);
    3725              :     }
    3726            6 :   else if (const char *suggestion = hint.suggestion ())
    3727              :     {
    3728            2 :       gcc_rich_location richloc (loc);
    3729            2 :       richloc.add_fixit_replace (suggestion);
    3730            2 :       warned = warning_at
    3731            2 :         (&richloc, OPT_Wimplicit_function_declaration,
    3732              :          G_("implicit declaration of function %qE; did you mean %qs?"),
    3733              :          id, suggestion);
    3734            2 :     }
    3735              :   else
    3736            4 :     warned = warning_at (loc, OPT_Wimplicit_function_declaration,
    3737              :                          G_("implicit declaration of function %qE"), id);
    3738              : 
    3739         1159 :   if (warned)
    3740              :     {
    3741              :       /* Whether the olddecl is an undeclared builtin function.
    3742              :          locate_old_decl will not generate a diagnostic for those,
    3743              :          so in that case we want to look elsewhere.  */
    3744           90 :       bool undeclared_builtin = (olddecl
    3745           28 :                                  && TREE_CODE (olddecl) == FUNCTION_DECL
    3746           28 :                                  && fndecl_built_in_p (olddecl)
    3747          117 :                                  && !C_DECL_DECLARED_BUILTIN (olddecl));
    3748           90 :       if (undeclared_builtin)
    3749              :         {
    3750           27 :           const char *header = header_for_builtin_fn (olddecl);
    3751           27 :           if (header)
    3752              :             {
    3753           20 :               rich_location richloc (line_table, loc);
    3754           20 :               maybe_add_include_fixit (&richloc, header, true);
    3755           20 :               inform (&richloc,
    3756              :                       "include %qs or provide a declaration of %qE",
    3757              :                       header, id);
    3758           20 :             }
    3759              :         }
    3760           63 :       else if (olddecl)
    3761            1 :         locate_old_decl (olddecl);
    3762              :     }
    3763              : 
    3764         1069 :   if (!warned)
    3765         1159 :     hint.suppress ();
    3766         1159 : }
    3767              : 
    3768              : /* Return the name of the header file that declares built-in function
    3769              :    FNDECL, or null if either we don't know or don't expect to see an
    3770              :    explicit declaration.  */
    3771              : 
    3772              : static const char *
    3773         3177 : header_for_builtin_fn (tree fndecl)
    3774              : {
    3775         3177 :   if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
    3776              :     return NULL;
    3777              : 
    3778         3177 :   switch (DECL_FUNCTION_CODE (fndecl))
    3779              :     {
    3780              :     CASE_FLT_FN (BUILT_IN_ACOS):
    3781              :     CASE_FLT_FN (BUILT_IN_ACOSH):
    3782              :     CASE_FLT_FN (BUILT_IN_ASIN):
    3783              :     CASE_FLT_FN (BUILT_IN_ASINH):
    3784              :     CASE_FLT_FN (BUILT_IN_ATAN):
    3785              :     CASE_FLT_FN (BUILT_IN_ATANH):
    3786              :     CASE_FLT_FN (BUILT_IN_ATAN2):
    3787              :     CASE_FLT_FN (BUILT_IN_CBRT):
    3788              :     CASE_FLT_FN (BUILT_IN_CEIL):
    3789              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
    3790              :     CASE_FLT_FN (BUILT_IN_COPYSIGN):
    3791              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
    3792              :     CASE_FLT_FN (BUILT_IN_COS):
    3793              :     CASE_FLT_FN (BUILT_IN_COSH):
    3794              :     CASE_FLT_FN (BUILT_IN_ERF):
    3795              :     CASE_FLT_FN (BUILT_IN_ERFC):
    3796              :     CASE_FLT_FN (BUILT_IN_EXP):
    3797              :     CASE_FLT_FN (BUILT_IN_EXP2):
    3798              :     CASE_FLT_FN (BUILT_IN_EXPM1):
    3799              :     CASE_FLT_FN (BUILT_IN_FABS):
    3800              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
    3801              :     CASE_FLT_FN (BUILT_IN_FDIM):
    3802              :     CASE_FLT_FN (BUILT_IN_FLOOR):
    3803              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
    3804              :     CASE_FLT_FN (BUILT_IN_FMA):
    3805              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
    3806              :     CASE_FLT_FN (BUILT_IN_FMAX):
    3807              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
    3808              :     CASE_FLT_FN (BUILT_IN_FMIN):
    3809              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
    3810              :     CASE_FLT_FN (BUILT_IN_FMOD):
    3811              :     CASE_FLT_FN (BUILT_IN_FREXP):
    3812              :     CASE_FLT_FN (BUILT_IN_HYPOT):
    3813              :     CASE_FLT_FN (BUILT_IN_ILOGB):
    3814              :     CASE_FLT_FN (BUILT_IN_LDEXP):
    3815              :     CASE_FLT_FN (BUILT_IN_LGAMMA):
    3816              :     CASE_FLT_FN (BUILT_IN_LLRINT):
    3817              :     CASE_FLT_FN (BUILT_IN_LLROUND):
    3818              :     CASE_FLT_FN (BUILT_IN_LOG):
    3819              :     CASE_FLT_FN (BUILT_IN_LOG10):
    3820              :     CASE_FLT_FN (BUILT_IN_LOG1P):
    3821              :     CASE_FLT_FN (BUILT_IN_LOG2):
    3822              :     CASE_FLT_FN (BUILT_IN_LOGB):
    3823              :     CASE_FLT_FN (BUILT_IN_LRINT):
    3824              :     CASE_FLT_FN (BUILT_IN_LROUND):
    3825              :     CASE_FLT_FN (BUILT_IN_MODF):
    3826              :     CASE_FLT_FN (BUILT_IN_NAN):
    3827              :     CASE_FLT_FN (BUILT_IN_NEARBYINT):
    3828              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
    3829              :     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
    3830              :     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
    3831              :     CASE_FLT_FN (BUILT_IN_POW):
    3832              :     CASE_FLT_FN (BUILT_IN_REMAINDER):
    3833              :     CASE_FLT_FN (BUILT_IN_REMQUO):
    3834              :     CASE_FLT_FN (BUILT_IN_RINT):
    3835              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
    3836              :     CASE_FLT_FN (BUILT_IN_ROUND):
    3837              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
    3838              :     CASE_FLT_FN (BUILT_IN_SCALBLN):
    3839              :     CASE_FLT_FN (BUILT_IN_SCALBN):
    3840              :     CASE_FLT_FN (BUILT_IN_SIN):
    3841              :     CASE_FLT_FN (BUILT_IN_SINH):
    3842              :     CASE_FLT_FN (BUILT_IN_SINCOS):
    3843              :     CASE_FLT_FN (BUILT_IN_SQRT):
    3844              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
    3845              :     CASE_FLT_FN (BUILT_IN_TAN):
    3846              :     CASE_FLT_FN (BUILT_IN_TANH):
    3847              :     CASE_FLT_FN (BUILT_IN_TGAMMA):
    3848              :     CASE_FLT_FN (BUILT_IN_TRUNC):
    3849              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
    3850              :     case BUILT_IN_ISINF:
    3851              :     case BUILT_IN_ISNAN:
    3852              :       return "<math.h>";
    3853           29 :     CASE_FLT_FN (BUILT_IN_CABS):
    3854           29 :     CASE_FLT_FN (BUILT_IN_CACOS):
    3855           29 :     CASE_FLT_FN (BUILT_IN_CACOSH):
    3856           29 :     CASE_FLT_FN (BUILT_IN_CARG):
    3857           29 :     CASE_FLT_FN (BUILT_IN_CASIN):
    3858           29 :     CASE_FLT_FN (BUILT_IN_CASINH):
    3859           29 :     CASE_FLT_FN (BUILT_IN_CATAN):
    3860           29 :     CASE_FLT_FN (BUILT_IN_CATANH):
    3861           29 :     CASE_FLT_FN (BUILT_IN_CCOS):
    3862           29 :     CASE_FLT_FN (BUILT_IN_CCOSH):
    3863           29 :     CASE_FLT_FN (BUILT_IN_CEXP):
    3864           29 :     CASE_FLT_FN (BUILT_IN_CIMAG):
    3865           29 :     CASE_FLT_FN (BUILT_IN_CLOG):
    3866           29 :     CASE_FLT_FN (BUILT_IN_CONJ):
    3867           29 :     CASE_FLT_FN (BUILT_IN_CPOW):
    3868           29 :     CASE_FLT_FN (BUILT_IN_CPROJ):
    3869           29 :     CASE_FLT_FN (BUILT_IN_CREAL):
    3870           29 :     CASE_FLT_FN (BUILT_IN_CSIN):
    3871           29 :     CASE_FLT_FN (BUILT_IN_CSINH):
    3872           29 :     CASE_FLT_FN (BUILT_IN_CSQRT):
    3873           29 :     CASE_FLT_FN (BUILT_IN_CTAN):
    3874           29 :     CASE_FLT_FN (BUILT_IN_CTANH):
    3875           29 :       return "<complex.h>";
    3876          228 :     case BUILT_IN_MEMCHR:
    3877          228 :     case BUILT_IN_MEMCMP:
    3878          228 :     case BUILT_IN_MEMCPY:
    3879          228 :     case BUILT_IN_MEMMOVE:
    3880          228 :     case BUILT_IN_MEMSET:
    3881          228 :     case BUILT_IN_STRCAT:
    3882          228 :     case BUILT_IN_STRCHR:
    3883          228 :     case BUILT_IN_STRCMP:
    3884          228 :     case BUILT_IN_STRCPY:
    3885          228 :     case BUILT_IN_STRCSPN:
    3886          228 :     case BUILT_IN_STRLEN:
    3887          228 :     case BUILT_IN_STRNCAT:
    3888          228 :     case BUILT_IN_STRNCMP:
    3889          228 :     case BUILT_IN_STRNCPY:
    3890          228 :     case BUILT_IN_STRPBRK:
    3891          228 :     case BUILT_IN_STRRCHR:
    3892          228 :     case BUILT_IN_STRSPN:
    3893          228 :     case BUILT_IN_STRSTR:
    3894          228 :       return "<string.h>";
    3895          544 :     case BUILT_IN_FPRINTF:
    3896          544 :     case BUILT_IN_PUTC:
    3897          544 :     case BUILT_IN_FPUTC:
    3898          544 :     case BUILT_IN_FPUTS:
    3899          544 :     case BUILT_IN_FSCANF:
    3900          544 :     case BUILT_IN_FWRITE:
    3901          544 :     case BUILT_IN_PRINTF:
    3902          544 :     case BUILT_IN_PUTCHAR:
    3903          544 :     case BUILT_IN_PUTS:
    3904          544 :     case BUILT_IN_SCANF:
    3905          544 :     case BUILT_IN_SNPRINTF:
    3906          544 :     case BUILT_IN_SPRINTF:
    3907          544 :     case BUILT_IN_SSCANF:
    3908          544 :     case BUILT_IN_VFPRINTF:
    3909          544 :     case BUILT_IN_VFSCANF:
    3910          544 :     case BUILT_IN_VPRINTF:
    3911          544 :     case BUILT_IN_VSCANF:
    3912          544 :     case BUILT_IN_VSNPRINTF:
    3913          544 :     case BUILT_IN_VSPRINTF:
    3914          544 :     case BUILT_IN_VSSCANF:
    3915          544 :       return "<stdio.h>";
    3916            2 :     case BUILT_IN_ISALNUM:
    3917            2 :     case BUILT_IN_ISALPHA:
    3918            2 :     case BUILT_IN_ISBLANK:
    3919            2 :     case BUILT_IN_ISCNTRL:
    3920            2 :     case BUILT_IN_ISDIGIT:
    3921            2 :     case BUILT_IN_ISGRAPH:
    3922            2 :     case BUILT_IN_ISLOWER:
    3923            2 :     case BUILT_IN_ISPRINT:
    3924            2 :     case BUILT_IN_ISPUNCT:
    3925            2 :     case BUILT_IN_ISSPACE:
    3926            2 :     case BUILT_IN_ISUPPER:
    3927            2 :     case BUILT_IN_ISXDIGIT:
    3928            2 :     case BUILT_IN_TOLOWER:
    3929            2 :     case BUILT_IN_TOUPPER:
    3930            2 :       return "<ctype.h>";
    3931            0 :     case BUILT_IN_ISWALNUM:
    3932            0 :     case BUILT_IN_ISWALPHA:
    3933            0 :     case BUILT_IN_ISWBLANK:
    3934            0 :     case BUILT_IN_ISWCNTRL:
    3935            0 :     case BUILT_IN_ISWDIGIT:
    3936            0 :     case BUILT_IN_ISWGRAPH:
    3937            0 :     case BUILT_IN_ISWLOWER:
    3938            0 :     case BUILT_IN_ISWPRINT:
    3939            0 :     case BUILT_IN_ISWPUNCT:
    3940            0 :     case BUILT_IN_ISWSPACE:
    3941            0 :     case BUILT_IN_ISWUPPER:
    3942            0 :     case BUILT_IN_ISWXDIGIT:
    3943            0 :     case BUILT_IN_TOWLOWER:
    3944            0 :     case BUILT_IN_TOWUPPER:
    3945            0 :       return "<wctype.h>";
    3946         1818 :     case BUILT_IN_ABORT:
    3947         1818 :     case BUILT_IN_ABS:
    3948         1818 :     case BUILT_IN_CALLOC:
    3949         1818 :     case BUILT_IN_EXIT:
    3950         1818 :     case BUILT_IN_FREE:
    3951         1818 :     case BUILT_IN_LABS:
    3952         1818 :     case BUILT_IN_LLABS:
    3953         1818 :     case BUILT_IN_MALLOC:
    3954         1818 :     case BUILT_IN_REALLOC:
    3955         1818 :     case BUILT_IN__EXIT2:
    3956         1818 :     case BUILT_IN_ALIGNED_ALLOC:
    3957         1818 :       return "<stdlib.h>";
    3958            1 :     case BUILT_IN_IMAXABS:
    3959            1 :       return "<inttypes.h>";
    3960            3 :     case BUILT_IN_STRFTIME:
    3961            3 :       return "<time.h>";
    3962              :     default:
    3963              :       return NULL;
    3964              :     }
    3965              : }
    3966              : 
    3967              : /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
    3968              :    function of type int ().  */
    3969              : 
    3970              : tree
    3971         4729 : implicitly_declare (location_t loc, tree functionid)
    3972              : {
    3973         4729 :   struct c_binding *b;
    3974         4729 :   tree decl = NULL_TREE;
    3975         4729 :   tree asmspec_tree;
    3976              : 
    3977         4743 :   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
    3978              :     {
    3979         3158 :       if (B_IN_SCOPE (b, external_scope))
    3980              :         {
    3981         3144 :           decl = b->decl;
    3982         3144 :           break;
    3983              :         }
    3984              :     }
    3985              : 
    3986         4729 :   if (decl)
    3987              :     {
    3988         3144 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    3989              :         return decl;
    3990              : 
    3991              :       /* FIXME: Objective-C has weird not-really-builtin functions
    3992              :          which are supposed to be visible automatically.  They wind up
    3993              :          in the external scope because they're pushed before the file
    3994              :          scope gets created.  Catch this here and rebind them into the
    3995              :          file scope.  */
    3996         3137 :       if (!fndecl_built_in_p (decl) && DECL_IS_UNDECLARED_BUILTIN (decl))
    3997              :         {
    3998            0 :           bind (functionid, decl, file_scope,
    3999              :                 /*invisible=*/false, /*nested=*/true,
    4000            0 :                 DECL_SOURCE_LOCATION (decl));
    4001            0 :           return decl;
    4002              :         }
    4003              :       else
    4004              :         {
    4005         3137 :           tree newtype = default_function_type;
    4006         3137 :           if (b->u.type)
    4007          753 :             TREE_TYPE (decl) = b->u.type;
    4008              :           /* Implicit declaration of a function already declared
    4009              :              (somehow) in a different scope, or as a built-in.
    4010              :              If this is the first time this has happened, warn;
    4011              :              then recycle the old declaration but with the new type.  */
    4012         3137 :           if (!C_DECL_IMPLICIT (decl))
    4013              :             {
    4014         2191 :               implicit_decl_permerror (loc, functionid, decl);
    4015         2191 :               C_DECL_IMPLICIT (decl) = 1;
    4016              :             }
    4017         3137 :           if (fndecl_built_in_p (decl))
    4018              :             {
    4019         2705 :               newtype = c_build_type_attribute_variant (newtype,
    4020         2705 :                                                         TYPE_ATTRIBUTES
    4021              :                                                         (TREE_TYPE (decl)));
    4022         2705 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4023              :                 {
    4024         2528 :                   auto_diagnostic_group d;
    4025         2528 :                   bool warned = warning_at (loc,
    4026         2528 :                                             OPT_Wbuiltin_declaration_mismatch,
    4027              :                                             "incompatible implicit "
    4028              :                                             "declaration of built-in "
    4029              :                                             "function %qD", decl);
    4030              :                   /* See if we can hint which header to include.  */
    4031         2528 :                   const char *header = header_for_builtin_fn (decl);
    4032         2528 :                   if (header != NULL && warned)
    4033              :                     {
    4034          133 :                       rich_location richloc (line_table, loc);
    4035          133 :                       maybe_add_include_fixit (&richloc, header, true);
    4036          133 :                       inform (&richloc,
    4037              :                               "include %qs or provide a declaration of %qD",
    4038              :                               header, decl);
    4039          133 :                     }
    4040         2528 :                   newtype = TREE_TYPE (decl);
    4041         2528 :                 }
    4042              :             }
    4043              :           else
    4044              :             {
    4045          432 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4046              :                 {
    4047            2 :                   auto_diagnostic_group d;
    4048            2 :                   error_at (loc, "incompatible implicit declaration of "
    4049              :                             "function %qD", decl);
    4050            2 :                   locate_old_decl (decl);
    4051            2 :                 }
    4052              :             }
    4053         3137 :           b->u.type = TREE_TYPE (decl);
    4054         3137 :           TREE_TYPE (decl) = newtype;
    4055         3137 :           bind (functionid, decl, current_scope,
    4056              :                 /*invisible=*/false, /*nested=*/true,
    4057         3137 :                 DECL_SOURCE_LOCATION (decl));
    4058         3137 :           return decl;
    4059              :         }
    4060              :     }
    4061              : 
    4062              :   /* Not seen before.  */
    4063         1585 :   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
    4064         1585 :   DECL_EXTERNAL (decl) = 1;
    4065         1585 :   TREE_PUBLIC (decl) = 1;
    4066         1585 :   C_DECL_IMPLICIT (decl) = 1;
    4067         1585 :   implicit_decl_permerror (loc, functionid, 0);
    4068         1585 :   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
    4069         1585 :   if (asmspec_tree)
    4070            1 :     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
    4071              : 
    4072              :   /* C89 says implicit declarations are in the innermost block.
    4073              :      So we record the decl in the standard fashion.  */
    4074         1585 :   decl = pushdecl (decl);
    4075              : 
    4076              :   /* No need to call objc_check_decl here - it's a function type.  */
    4077         1585 :   rest_of_decl_compilation (decl, 0, 0);
    4078              : 
    4079              :   /* Write a record describing this implicit function declaration
    4080              :      to the prototypes file (if requested).  */
    4081         1585 :   gen_aux_info_record (decl, 0, 1, 0);
    4082              : 
    4083              :   /* Possibly apply some default attributes to this implicit declaration.  */
    4084         1585 :   decl_attributes (&decl, NULL_TREE, 0);
    4085              : 
    4086         1585 :   return decl;
    4087              : }
    4088              : 
    4089              : /* Issue an error message for a reference to an undeclared variable
    4090              :    ID, including a reference to a builtin outside of function-call
    4091              :    context.  Establish a binding of the identifier to error_mark_node
    4092              :    in an appropriate scope, which will suppress further errors for the
    4093              :    same identifier.  The error message should be given location LOC.  */
    4094              : void
    4095         1484 : undeclared_variable (location_t loc, tree id)
    4096              : {
    4097         1484 :   static bool already = false;
    4098         1484 :   struct c_scope *scope;
    4099              : 
    4100         1484 :   auto_diagnostic_group d;
    4101         1484 :   if (current_function_decl == NULL_TREE)
    4102              :     {
    4103          660 :       name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4104          660 :       if (const char *suggestion = guessed_id.suggestion ())
    4105              :         {
    4106           86 :           gcc_rich_location richloc (loc);
    4107           86 :           richloc.add_fixit_replace (suggestion);
    4108           86 :           error_at (&richloc,
    4109              :                     "%qE undeclared here (not in a function);"
    4110              :                     " did you mean %qs?",
    4111              :                     id, suggestion);
    4112           86 :         }
    4113              :       else
    4114          574 :         error_at (loc, "%qE undeclared here (not in a function)", id);
    4115          660 :       scope = current_scope;
    4116          660 :     }
    4117              :   else
    4118              :     {
    4119          824 :       if (!objc_diagnose_private_ivar (id))
    4120              :         {
    4121          824 :           name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4122          824 :           if (const char *suggestion = guessed_id.suggestion ())
    4123              :             {
    4124           39 :               gcc_rich_location richloc (loc);
    4125           39 :               richloc.add_fixit_replace (suggestion);
    4126           39 :               error_at (&richloc,
    4127              :                         "%qE undeclared (first use in this function);"
    4128              :                         " did you mean %qs?",
    4129              :                         id, suggestion);
    4130           39 :             }
    4131              :           else
    4132          785 :             error_at (loc, "%qE undeclared (first use in this function)", id);
    4133          824 :         }
    4134          824 :       if (!already)
    4135              :         {
    4136          201 :           inform (loc, "each undeclared identifier is reported only"
    4137              :                   " once for each function it appears in");
    4138          201 :           already = true;
    4139              :         }
    4140              : 
    4141              :       /* If we are parsing old-style parameter decls, current_function_decl
    4142              :          will be nonnull but current_function_scope will be null.  */
    4143          824 :       scope = current_function_scope ? current_function_scope : current_scope;
    4144              :     }
    4145         1484 :   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
    4146              :         UNKNOWN_LOCATION);
    4147         1484 : }
    4148              : 
    4149              : /* Subroutine of lookup_label, declare_label, define_label: construct a
    4150              :    LABEL_DECL with all the proper frills.  Also create a struct
    4151              :    c_label_vars initialized for the current scope.  */
    4152              : 
    4153              : static tree
    4154        24179 : make_label (location_t location, tree name, bool defining,
    4155              :             struct c_label_vars **p_label_vars)
    4156              : {
    4157        24179 :   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
    4158        24179 :   DECL_CONTEXT (label) = current_function_decl;
    4159        24179 :   SET_DECL_MODE (label, VOIDmode);
    4160              : 
    4161        24179 :   c_label_vars *label_vars = ggc_alloc<c_label_vars> ();
    4162        24179 :   label_vars->shadowed = NULL;
    4163        24179 :   set_spot_bindings (&label_vars->label_bindings, defining);
    4164        24179 :   label_vars->decls_in_scope = make_tree_vector ();
    4165        24179 :   label_vars->gotos = NULL;
    4166        24179 :   *p_label_vars = label_vars;
    4167              : 
    4168        24179 :   return label;
    4169              : }
    4170              : 
    4171              : /* Get the LABEL_DECL corresponding to identifier NAME as a label.
    4172              :    Create one if none exists so far for the current function.
    4173              :    This is called when a label is used in a goto expression or
    4174              :    has its address taken.  */
    4175              : 
    4176              : tree
    4177        85762 : lookup_label (tree name)
    4178              : {
    4179        85762 :   tree label;
    4180        85762 :   struct c_label_vars *label_vars;
    4181              : 
    4182        85762 :   if (current_function_scope == 0)
    4183              :     {
    4184            2 :       error ("label %qE referenced outside of any function", name);
    4185            2 :       return NULL_TREE;
    4186              :     }
    4187              : 
    4188              :   /* Use a label already defined or ref'd with this name, but not if
    4189              :      it is inherited from a containing function and wasn't declared
    4190              :      using __label__.  */
    4191        85760 :   label = I_LABEL_DECL (name);
    4192        79718 :   if (label && (DECL_CONTEXT (label) == current_function_decl
    4193          608 :                 || C_DECLARED_LABEL_FLAG (label)))
    4194              :     {
    4195              :       /* If the label has only been declared, update its apparent
    4196              :          location to point here, for better diagnostics if it
    4197              :          turns out not to have been defined.  */
    4198        79711 :       if (DECL_INITIAL (label) == NULL_TREE)
    4199        62798 :         DECL_SOURCE_LOCATION (label) = input_location;
    4200        79711 :       return label;
    4201              :     }
    4202              : 
    4203              :   /* No label binding for that identifier; make one.  */
    4204         6049 :   label = make_label (input_location, name, false, &label_vars);
    4205              : 
    4206              :   /* Ordinary labels go in the current function scope.  */
    4207         6049 :   bind_label (name, label, current_function_scope, label_vars);
    4208              : 
    4209         6049 :   return label;
    4210              : }
    4211              : 
    4212              : /* Issue a warning about DECL for a goto statement at GOTO_LOC going
    4213              :    to LABEL.  */
    4214              : 
    4215              : static void
    4216         1490 : warn_about_goto (location_t goto_loc, tree label, tree decl)
    4217              : {
    4218         1490 :   auto_diagnostic_group d;
    4219         1490 :   if (c_type_variably_modified_p (TREE_TYPE (decl)))
    4220         1484 :     error_at (goto_loc,
    4221              :               "jump into scope of identifier with variably modified type");
    4222            6 :   else if (flag_openmp
    4223            6 :            && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
    4224            2 :     error_at (goto_loc, "jump skips OpenMP %<allocate%> allocation");
    4225              :   else
    4226            4 :     if (!warning_at (goto_loc, OPT_Wjump_misses_init,
    4227              :                      "jump skips variable initialization"))
    4228            0 :       return;
    4229         1490 :   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4230         1490 :   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
    4231         1490 : }
    4232              : 
    4233              : /* Look up a label because of a goto statement.  This is like
    4234              :    lookup_label, but also issues any appropriate warnings.  */
    4235              : 
    4236              : tree
    4237        83900 : lookup_label_for_goto (location_t loc, tree name)
    4238              : {
    4239        83900 :   tree label;
    4240        83900 :   struct c_label_vars *label_vars;
    4241        83900 :   unsigned int ix;
    4242        83900 :   tree decl;
    4243              : 
    4244        83900 :   label = lookup_label (name);
    4245        83900 :   if (label == NULL_TREE)
    4246              :     return NULL_TREE;
    4247              : 
    4248              :   /* If we are jumping to a different function, we can't issue any
    4249              :      useful warnings.  */
    4250        83900 :   if (DECL_CONTEXT (label) != current_function_decl)
    4251              :     {
    4252          522 :       gcc_assert (C_DECLARED_LABEL_FLAG (label));
    4253              :       return label;
    4254              :     }
    4255              : 
    4256        83378 :   label_vars = I_LABEL_BINDING (name)->u.label;
    4257              : 
    4258              :   /* If the label has not yet been defined, then push this goto on a
    4259              :      list for possible later warnings.  */
    4260        83378 :   if (label_vars->label_bindings.scope == NULL)
    4261              :     {
    4262        66690 :       c_goto_bindings *g = ggc_alloc<c_goto_bindings> ();
    4263              : 
    4264        66690 :       g->loc = loc;
    4265        66690 :       set_spot_bindings (&g->goto_bindings, true);
    4266        66690 :       vec_safe_push (label_vars->gotos, g);
    4267        66690 :       return label;
    4268              :     }
    4269              : 
    4270              :   /* If there are any decls in label_vars->decls_in_scope, then this
    4271              :      goto has missed the declaration of the decl.  This happens for a
    4272              :      case like
    4273              :        int i = 1;
    4274              :       lab:
    4275              :        ...
    4276              :        goto lab;
    4277              :      Issue a warning or error.  */
    4278        17463 :   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
    4279          775 :     warn_about_goto (loc, label, decl);
    4280              : 
    4281        16688 :   if (label_vars->label_bindings.left_stmt_expr)
    4282              :     {
    4283          120 :       auto_diagnostic_group d;
    4284          120 :       error_at (loc, "jump into statement expression");
    4285          120 :       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4286          120 :     }
    4287              : 
    4288              :   return label;
    4289              : }
    4290              : 
    4291              : /* Make a label named NAME in the current function, shadowing silently
    4292              :    any that may be inherited from containing functions or containing
    4293              :    scopes.  This is called for __label__ declarations.  */
    4294              : 
    4295              : tree
    4296         1213 : declare_label (tree name)
    4297              : {
    4298         1213 :   struct c_binding *b = I_LABEL_BINDING (name);
    4299         1213 :   tree label;
    4300         1213 :   struct c_label_vars *label_vars;
    4301              : 
    4302              :   /* Check to make sure that the label hasn't already been declared
    4303              :      at this scope */
    4304         1213 :   if (b && B_IN_CURRENT_SCOPE (b))
    4305              :     {
    4306            2 :       auto_diagnostic_group d;
    4307            2 :       error ("duplicate label declaration %qE", name);
    4308            2 :       locate_old_decl (b->decl);
    4309              : 
    4310              :       /* Just use the previous declaration.  */
    4311            2 :       return b->decl;
    4312            2 :     }
    4313              : 
    4314         1211 :   label = make_label (input_location, name, false, &label_vars);
    4315         1211 :   C_DECLARED_LABEL_FLAG (label) = 1;
    4316              : 
    4317              :   /* Declared labels go in the current scope.  */
    4318         1211 :   bind_label (name, label, current_scope, label_vars);
    4319              : 
    4320         1211 :   return label;
    4321              : }
    4322              : 
    4323              : /* When we define a label, issue any appropriate warnings if there are
    4324              :    any gotos earlier in the function which jump to this label.  */
    4325              : 
    4326              : static void
    4327         7180 : check_earlier_gotos (tree label, struct c_label_vars* label_vars)
    4328              : {
    4329         7180 :   unsigned int ix;
    4330         7180 :   struct c_goto_bindings *g;
    4331              : 
    4332        73804 :   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    4333              :     {
    4334        66624 :       struct c_binding *b;
    4335        66624 :       struct c_scope *scope;
    4336              : 
    4337              :       /* We have a goto to this label.  The goto is going forward.  In
    4338              :          g->scope, the goto is going to skip any binding which was
    4339              :          defined after g->bindings_in_scope.  */
    4340        66624 :       if (g->goto_bindings.scope->has_jump_unsafe_decl)
    4341              :         {
    4342          255 :           for (b = g->goto_bindings.scope->bindings;
    4343          593 :                b != g->goto_bindings.bindings_in_scope;
    4344          338 :                b = b->prev)
    4345              :             {
    4346          338 :               if (decl_jump_unsafe (b->decl))
    4347          176 :                 warn_about_goto (g->loc, label, b->decl);
    4348              :             }
    4349              :         }
    4350              : 
    4351              :       /* We also need to warn about decls defined in any scopes
    4352              :          between the scope of the label and the scope of the goto.  */
    4353        66624 :       for (scope = label_vars->label_bindings.scope;
    4354        69321 :            scope != g->goto_bindings.scope;
    4355         2697 :            scope = scope->outer)
    4356              :         {
    4357         2697 :           gcc_assert (scope != NULL);
    4358         2697 :           if (scope->has_jump_unsafe_decl)
    4359              :             {
    4360          325 :               if (scope == label_vars->label_bindings.scope)
    4361          249 :                 b = label_vars->label_bindings.bindings_in_scope;
    4362              :               else
    4363           76 :                 b = scope->bindings;
    4364          864 :               for (; b != NULL; b = b->prev)
    4365              :                 {
    4366          539 :                   if (decl_jump_unsafe (b->decl))
    4367          539 :                     warn_about_goto (g->loc, label, b->decl);
    4368              :                 }
    4369              :             }
    4370              :         }
    4371              : 
    4372        66624 :       if (g->goto_bindings.stmt_exprs > 0)
    4373              :         {
    4374          100 :           auto_diagnostic_group d;
    4375          100 :           error_at (g->loc, "jump into statement expression");
    4376          100 :           inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
    4377              :                   label);
    4378          100 :         }
    4379              :     }
    4380              : 
    4381              :   /* Now that the label is defined, we will issue warnings about
    4382              :      subsequent gotos to this label when we see them.  */
    4383         7180 :   vec_safe_truncate (label_vars->gotos, 0);
    4384         7180 :   label_vars->gotos = NULL;
    4385         7180 : }
    4386              : 
    4387              : /* Define a label, specifying the location in the source file.
    4388              :    Return the LABEL_DECL node for the label, if the definition is valid.
    4389              :    Otherwise return NULL_TREE.  */
    4390              : 
    4391              : tree
    4392        24128 : define_label (location_t location, tree name)
    4393              : {
    4394              :   /* Find any preexisting label with this name.  It is an error
    4395              :      if that label has already been defined in this function, or
    4396              :      if there is a containing function with a declared label with
    4397              :      the same name.  */
    4398        24128 :   tree label = I_LABEL_DECL (name);
    4399              : 
    4400         7216 :   if (label
    4401         7216 :       && ((DECL_CONTEXT (label) == current_function_decl
    4402         7202 :            && DECL_INITIAL (label) != NULL_TREE)
    4403         7194 :           || (DECL_CONTEXT (label) != current_function_decl
    4404           14 :               && C_DECLARED_LABEL_FLAG (label))))
    4405              :     {
    4406           29 :       auto_diagnostic_group d;
    4407           29 :       error_at (location, "duplicate label %qD", label);
    4408           29 :       locate_old_decl (label);
    4409           29 :       return NULL_TREE;
    4410           29 :     }
    4411        24099 :   else if (label && DECL_CONTEXT (label) == current_function_decl)
    4412              :     {
    4413         7180 :       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
    4414              : 
    4415              :       /* The label has been used or declared already in this function,
    4416              :          but not defined.  Update its location to point to this
    4417              :          definition.  */
    4418         7180 :       DECL_SOURCE_LOCATION (label) = location;
    4419         7180 :       set_spot_bindings (&label_vars->label_bindings, true);
    4420              : 
    4421              :       /* Issue warnings as required about any goto statements from
    4422              :          earlier in the function.  */
    4423         7180 :       check_earlier_gotos (label, label_vars);
    4424              :     }
    4425              :   else
    4426              :     {
    4427        16919 :       struct c_label_vars *label_vars;
    4428              : 
    4429              :       /* No label binding for that identifier; make one.  */
    4430        16919 :       label = make_label (location, name, true, &label_vars);
    4431              : 
    4432              :       /* Ordinary labels go in the current function scope.  */
    4433        16919 :       bind_label (name, label, current_function_scope, label_vars);
    4434              :     }
    4435              : 
    4436        24099 :   if (!in_system_header_at (input_location) && lookup_name (name))
    4437          143 :     warning_at (location, OPT_Wtraditional,
    4438              :                 "traditional C lacks a separate namespace "
    4439              :                 "for labels, identifier %qE conflicts", name);
    4440              : 
    4441              :   /* Mark label as having been defined.  */
    4442        24099 :   DECL_INITIAL (label) = error_mark_node;
    4443        24099 :   return label;
    4444              : }
    4445              : 
    4446              : /* Get the bindings for a new switch statement.  This is used to issue
    4447              :    warnings as appropriate for jumps from the switch to case or
    4448              :    default labels.  */
    4449              : 
    4450              : struct c_spot_bindings *
    4451        37460 : c_get_switch_bindings (void)
    4452              : {
    4453        37460 :   struct c_spot_bindings *switch_bindings;
    4454              : 
    4455        37460 :   switch_bindings = XNEW (struct c_spot_bindings);
    4456        37460 :   set_spot_bindings (switch_bindings, true);
    4457        37460 :   return switch_bindings;
    4458              : }
    4459              : 
    4460              : void
    4461        37460 : c_release_switch_bindings (struct c_spot_bindings *bindings)
    4462              : {
    4463        37460 :   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
    4464        37460 :   XDELETE (bindings);
    4465        37460 : }
    4466              : 
    4467              : /* This is called at the point of a case or default label to issue
    4468              :    warnings about decls as needed.  It returns true if it found an
    4469              :    error, not just a warning.  */
    4470              : 
    4471              : bool
    4472      1031055 : c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
    4473              :                               location_t switch_loc, location_t case_loc)
    4474              : {
    4475      1031055 :   bool saw_error;
    4476      1031055 :   struct c_scope *scope;
    4477              : 
    4478      1031055 :   saw_error = false;
    4479      1031055 :   for (scope = current_scope;
    4480      3093169 :        scope != switch_bindings->scope;
    4481      2062114 :        scope = scope->outer)
    4482              :     {
    4483      2062114 :       struct c_binding *b;
    4484              : 
    4485      2062114 :       gcc_assert (scope != NULL);
    4486              : 
    4487      2062114 :       if (!scope->has_jump_unsafe_decl)
    4488      2062103 :         continue;
    4489              : 
    4490           22 :       for (b = scope->bindings; b != NULL; b = b->prev)
    4491              :         {
    4492           11 :           if (decl_jump_unsafe (b->decl))
    4493              :             {
    4494           11 :               auto_diagnostic_group d;
    4495           11 :               bool emitted;
    4496           11 :               if (c_type_variably_modified_p (TREE_TYPE (b->decl)))
    4497              :                 {
    4498            6 :                   saw_error = true;
    4499            6 :                   error_at (case_loc,
    4500              :                             "switch jumps into scope of identifier with "
    4501              :                             "variably modified type");
    4502            6 :                   emitted = true;
    4503              :                 }
    4504            5 :               else if (flag_openmp
    4505            7 :                        && lookup_attribute ("omp allocate",
    4506            2 :                                             DECL_ATTRIBUTES (b->decl)))
    4507              :                 {
    4508            2 :                   saw_error = true;
    4509            2 :                   error_at (case_loc,
    4510              :                             "switch jumps over OpenMP %<allocate%> allocation");
    4511            2 :                   emitted = true;
    4512              :                 }
    4513              :               else
    4514            3 :                 emitted
    4515            3 :                   = warning_at (case_loc, OPT_Wjump_misses_init,
    4516              :                                 "switch jumps over variable initialization");
    4517           11 :               if (emitted)
    4518              :                 {
    4519           11 :                   inform (switch_loc, "switch starts here");
    4520           11 :                   inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
    4521              :                           b->decl);
    4522              :                 }
    4523           11 :             }
    4524              :         }
    4525              :     }
    4526              : 
    4527      1031055 :   if (switch_bindings->stmt_exprs > 0)
    4528              :     {
    4529            4 :       saw_error = true;
    4530            4 :       auto_diagnostic_group d;
    4531            4 :       error_at (case_loc, "switch jumps into statement expression");
    4532            4 :       inform (switch_loc, "switch starts here");
    4533            4 :     }
    4534              : 
    4535      1031055 :   return saw_error;
    4536              : }
    4537              : 
    4538              : /* Given NAME, an IDENTIFIER_NODE,
    4539              :    return the structure (or union or enum) definition for that name.
    4540              :    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
    4541              :    CODE says which kind of type the caller wants;
    4542              :    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
    4543              :    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
    4544              :    location where the tag was defined.
    4545              :    If the wrong kind of type is found, an error is reported.  */
    4546              : 
    4547              : static tree
    4548      2104644 : lookup_tag (enum tree_code code, tree name, bool thislevel_only,
    4549              :             location_t *ploc)
    4550              : {
    4551      2104644 :   struct c_binding *b = I_TAG_BINDING (name);
    4552      2104644 :   bool thislevel = false;
    4553              : 
    4554      2104644 :   if (!b || !b->decl)
    4555              :     return NULL_TREE;
    4556              : 
    4557              :   /* We only care about whether it's in this level if
    4558              :      thislevel_only was set or it might be a type clash.  */
    4559      1473221 :   if (thislevel_only || TREE_CODE (b->decl) != code)
    4560              :     {
    4561              :       /* For our purposes, a tag in the external scope is the same as
    4562              :          a tag in the file scope.  (Primarily relevant to Objective-C
    4563              :          and its builtin structure tags, which get pushed before the
    4564              :          file scope is created.)  */
    4565       472147 :       if (B_IN_CURRENT_SCOPE (b)
    4566          196 :           || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    4567      1473221 :         thislevel = true;
    4568              :     }
    4569              : 
    4570      1473221 :   if (thislevel_only && !thislevel)
    4571              :     return NULL_TREE;
    4572              : 
    4573      1473046 :   if (TREE_CODE (b->decl) != code)
    4574              :     {
    4575              :       /* Definition isn't the kind we were looking for.  */
    4576           39 :       pending_invalid_xref = name;
    4577           39 :       pending_invalid_xref_location = input_location;
    4578              : 
    4579              :       /* If in the same binding level as a declaration as a tag
    4580              :          of a different type, this must not be allowed to
    4581              :          shadow that tag, so give the error immediately.
    4582              :          (For example, "struct foo; union foo;" is invalid.)  */
    4583           39 :       if (thislevel)
    4584           18 :         pending_xref_error ();
    4585              :     }
    4586              : 
    4587      1473046 :   if (ploc != NULL)
    4588      1026774 :     *ploc = b->locus;
    4589              : 
    4590      1473046 :   return b->decl;
    4591              : }
    4592              : 
    4593              : /* Return true if a definition exists for NAME with code CODE.  */
    4594              : 
    4595              : bool
    4596          387 : tag_exists_p (enum tree_code code, tree name)
    4597              : {
    4598          387 :   struct c_binding *b = I_TAG_BINDING (name);
    4599              : 
    4600          387 :   if (b == NULL || b->decl == NULL_TREE)
    4601              :     return false;
    4602           18 :   return TREE_CODE (b->decl) == code;
    4603              : }
    4604              : 
    4605              : /* Print an error message now
    4606              :    for a recent invalid struct, union or enum cross reference.
    4607              :    We don't print them immediately because they are not invalid
    4608              :    when used in the `struct foo;' construct for shadowing.  */
    4609              : 
    4610              : void
    4611    314872355 : pending_xref_error (void)
    4612              : {
    4613    314872355 :   if (pending_invalid_xref != NULL_TREE)
    4614           27 :     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
    4615              :               pending_invalid_xref);
    4616    314872355 :   pending_invalid_xref = NULL_TREE;
    4617    314872355 : }
    4618              : 
    4619              : 
    4620              : /* Look up NAME in the current scope and its superiors
    4621              :    in the namespace of variables, functions and typedefs.
    4622              :    Return a ..._DECL node of some kind representing its definition,
    4623              :    or return NULL_TREE if it is undefined.  */
    4624              : 
    4625              : tree
    4626   1270480882 : lookup_name (tree name)
    4627              : {
    4628   1270480882 :   struct c_binding *b = I_SYMBOL_BINDING (name);
    4629              :   /* Do not resolve non-default function versions.  */
    4630   1270480882 :   if (b
    4631    857383702 :       && TREE_CODE (b->decl) == FUNCTION_DECL
    4632    117661299 :       && DECL_FUNCTION_VERSIONED (b->decl)
    4633   1270480882 :       && !is_function_default_version (b->decl))
    4634              :     return NULL_TREE;
    4635   1270480882 :   if (b && !b->invisible)
    4636              :     {
    4637    846228878 :       maybe_record_typedef_use (b->decl);
    4638    846228878 :       return b->decl;
    4639              :     }
    4640              :   return NULL_TREE;
    4641              : }
    4642              : 
    4643              : /* Similar to `lookup_name' but look only at the indicated scope.  */
    4644              : 
    4645              : static tree
    4646    132182129 : lookup_name_in_scope (tree name, struct c_scope *scope)
    4647              : {
    4648    132182129 :   struct c_binding *b;
    4649              : 
    4650    132185361 :   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
    4651      7653385 :     if (B_IN_SCOPE (b, scope))
    4652      7650153 :       return b->decl;
    4653              :   return NULL_TREE;
    4654              : }
    4655              : 
    4656              : /* Look for the closest match for NAME within the currently valid
    4657              :    scopes.
    4658              : 
    4659              :    This finds the identifier with the lowest Levenshtein distance to
    4660              :    NAME.  If there are multiple candidates with equal minimal distance,
    4661              :    the first one found is returned.  Scopes are searched from innermost
    4662              :    outwards, and within a scope in reverse order of declaration, thus
    4663              :    benefiting candidates "near" to the current scope.
    4664              : 
    4665              :    The function also looks for similar macro names to NAME, since a
    4666              :    misspelled macro name will not be expanded, and hence looks like an
    4667              :    identifier to the C frontend.
    4668              : 
    4669              :    It also looks for start_typename keywords, to detect "singed" vs "signed"
    4670              :    typos.
    4671              : 
    4672              :    Use LOC for any deferred diagnostics.  */
    4673              : 
    4674              : name_hint
    4675         2292 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    4676              : {
    4677         2292 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    4678              : 
    4679              :   /* Look up function-like macros first; maybe misusing them. */
    4680         4584 :   auto cpp_node = cpp_lookup (parse_in,
    4681         2292 :                               (const unsigned char*)IDENTIFIER_POINTER (name),
    4682         2292 :                               IDENTIFIER_LENGTH (name));
    4683         2292 :   if (cpp_node && cpp_fun_like_macro_p (cpp_node))
    4684            5 :     return name_hint
    4685              :       (nullptr,
    4686            5 :        std::make_unique<macro_like_function_used> (loc,
    4687           10 :                                                    IDENTIFIER_POINTER (name)));
    4688              : 
    4689              :   /* Next, try some well-known names in the C standard library, in case
    4690              :      the user forgot a #include.  */
    4691         2287 :   const char *header_hint
    4692         2287 :     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    4693              : 
    4694         2287 :   if (header_hint)
    4695           56 :     return name_hint
    4696              :       (nullptr,
    4697           56 :        std::make_unique<suggest_missing_header> (loc,
    4698          112 :                                                  IDENTIFIER_POINTER (name),
    4699           56 :                                                  header_hint));
    4700              : 
    4701              :   /* Next, look for exact matches for builtin defines that would have been
    4702              :      defined if the user had passed a command-line option (e.g. -fopenmp
    4703              :      for "_OPENMP").  */
    4704         2231 :   diagnostics::option_id option_id
    4705         2231 :     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
    4706         2231 :   if (option_id.m_idx > 0)
    4707            2 :     return name_hint
    4708              :       (nullptr,
    4709            2 :        std::make_unique<suggest_missing_option> (loc,
    4710            4 :                                                  IDENTIFIER_POINTER (name),
    4711            2 :                                                  option_id));
    4712              : 
    4713              :   /* Only suggest names reserved for the implementation if NAME begins
    4714              :      with an underscore.  */
    4715         2229 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    4716              : 
    4717         2229 :   best_match<tree, tree> bm (name);
    4718              : 
    4719              :   /* Look within currently valid scopes.  */
    4720         9789 :   for (c_scope *scope = current_scope; scope; scope = scope->outer)
    4721     12491719 :     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
    4722              :       {
    4723     12484159 :         if (!binding->id || binding->invisible)
    4724      7090149 :           continue;
    4725      5394010 :         if (binding->decl == error_mark_node)
    4726          374 :           continue;
    4727              :         /* Don't use bindings from implicitly declared functions,
    4728              :            as they were likely misspellings themselves.  */
    4729      5393636 :         if (TREE_CODE (binding->decl) == FUNCTION_DECL)
    4730      4978673 :           if (C_DECL_IMPLICIT (binding->decl))
    4731          229 :             continue;
    4732              :         /* Don't suggest names that are reserved for use by the
    4733              :            implementation, unless NAME began with an underscore.  */
    4734      5393407 :         if (!consider_implementation_names)
    4735              :           {
    4736      2343855 :             const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
    4737      2343855 :             if (name_reserved_for_implementation_p (suggestion_str))
    4738      2285434 :               continue;
    4739              :           }
    4740      3107973 :         switch (kind)
    4741              :           {
    4742        31031 :           case FUZZY_LOOKUP_TYPENAME:
    4743        31031 :             if (TREE_CODE (binding->decl) != TYPE_DECL)
    4744        23576 :               continue;
    4745              :             break;
    4746              : 
    4747       129178 :           case FUZZY_LOOKUP_FUNCTION_NAME:
    4748       129178 :             if (TREE_CODE (binding->decl) != FUNCTION_DECL)
    4749              :               {
    4750              :                 /* Allow function pointers.  */
    4751        26502 :                 if ((VAR_P (binding->decl)
    4752        21977 :                      || TREE_CODE (binding->decl) == PARM_DECL)
    4753         5400 :                     && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
    4754        27782 :                     && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
    4755              :                         == FUNCTION_TYPE))
    4756              :                   break;
    4757        26483 :                 continue;
    4758              :               }
    4759              :             break;
    4760              : 
    4761              :           default:
    4762              :             break;
    4763              :           }
    4764      3057914 :         bm.consider (binding->id);
    4765              :       }
    4766              : 
    4767              :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    4768              :      as:
    4769              :        x = SOME_OTHER_MACRO (y);
    4770              :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    4771              :      as a misspelled identifier.
    4772              : 
    4773              :      Use the best distance so far so that a candidate is only set if
    4774              :      a macro is better than anything so far.  This allows early rejection
    4775              :      (without calculating the edit distance) of macro names that must have
    4776              :      distance >= bm.get_best_distance (), and means that we only get a
    4777              :      non-NULL result for best_macro_match if it's better than any of
    4778              :      the identifiers already checked, which avoids needless creation
    4779              :      of identifiers for macro hashnodes.  */
    4780         2229 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    4781         2229 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    4782              :   /* If a macro is the closest so far to NAME, use it, creating an
    4783              :      identifier tree node for it.  */
    4784         2229 :   if (best_macro)
    4785              :     {
    4786           11 :       const char *id = (const char *)best_macro->ident.str;
    4787           11 :       tree macro_as_identifier
    4788           11 :         = get_identifier_with_length (id, best_macro->ident.len);
    4789           11 :       bm.set_best_so_far (macro_as_identifier,
    4790              :                           bmm.get_best_distance (),
    4791              :                           bmm.get_best_candidate_length ());
    4792              :     }
    4793              : 
    4794              :   /* Try the "start_typename" keywords to detect
    4795              :      "singed" vs "signed" typos.  */
    4796         2229 :   if (kind == FUZZY_LOOKUP_TYPENAME)
    4797              :     {
    4798        56870 :       for (unsigned i = 0; i < num_c_common_reswords; i++)
    4799              :         {
    4800        56628 :           const c_common_resword *resword = &c_common_reswords[i];
    4801        56628 :           if (!c_keyword_starts_typename (resword->rid))
    4802        43318 :             continue;
    4803        13310 :           tree resword_identifier = ridpointers [resword->rid];
    4804        13310 :           if (!resword_identifier)
    4805           30 :             continue;
    4806        13280 :           gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    4807        13280 :           bm.consider (resword_identifier);
    4808              :         }
    4809              :     }
    4810              : 
    4811         2229 :   tree best = bm.get_best_meaningful_candidate ();
    4812         2229 :   if (best)
    4813          278 :     return name_hint (IDENTIFIER_POINTER (best), NULL);
    4814              :   else
    4815         1951 :     return name_hint (NULL, NULL);
    4816              : }
    4817              : 
    4818              : 
    4819              : /* Handle the standard [[nodiscard]] attribute.  */
    4820              : 
    4821              : static tree
    4822           34 : handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
    4823              :                             int /*flags*/, bool *no_add_attrs)
    4824              : {
    4825           34 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4826              :     {
    4827           18 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
    4828            1 :         warning_at (DECL_SOURCE_LOCATION (*node),
    4829            1 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    4830              :                     "return type", name, *node);
    4831              :     }
    4832           16 :   else if (RECORD_OR_UNION_TYPE_P (*node)
    4833           12 :            || TREE_CODE (*node) == ENUMERAL_TYPE)
    4834              :     /* OK */;
    4835              :   else
    4836              :     {
    4837           10 :       pedwarn (input_location,
    4838           10 :                OPT_Wattributes, "%qE attribute can only be applied to "
    4839              :                "functions or to structure, union or enumeration types", name);
    4840           10 :       *no_add_attrs = true;
    4841              :     }
    4842           34 :   return NULL_TREE;
    4843              : }
    4844              : 
    4845              : /* Handle the standard [[noreturn]] attribute.  */
    4846              : 
    4847              : static tree
    4848           44 : handle_std_noreturn_attribute (tree *node, tree name, tree args,
    4849              :                                int flags, bool *no_add_attrs)
    4850              : {
    4851              :   /* Unlike GNU __attribute__ ((noreturn)), the standard [[noreturn]]
    4852              :      only applies to functions, not function pointers.  */
    4853           44 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4854           22 :     return handle_noreturn_attribute (node, name, args, flags, no_add_attrs);
    4855              :   else
    4856              :     {
    4857           22 :       pedwarn (input_location, OPT_Wattributes,
    4858              :                "standard %qE attribute can only be applied to functions",
    4859              :                name);
    4860           22 :       *no_add_attrs = true;
    4861           22 :       return NULL_TREE;
    4862              :     }
    4863              : }
    4864              : 
    4865              : /* Handle the standard [[unsequenced]] attribute.  */
    4866              : 
    4867              : static tree
    4868           68 : handle_std_unsequenced_attribute (tree *node, tree name, tree args,
    4869              :                                   int flags, bool *no_add_attrs)
    4870              : {
    4871              :   /* Unlike GNU __attribute__ ((unsequenced)), the standard [[unsequenced]]
    4872              :      should be only applied to function declarators or type specifiers which
    4873              :      have function type.  */
    4874           68 :   if (node[2])
    4875              :     {
    4876            8 :       auto_diagnostic_group d;
    4877            8 :       if (pedwarn (input_location, OPT_Wattributes,
    4878              :                    "standard %qE attribute can only be applied to function "
    4879              :                    "declarators or type specifiers with function type", name))
    4880            8 :         inform (input_location, "did you mean to specify it after %<)%> "
    4881              :                                 "following function parameters?");
    4882            8 :       *no_add_attrs = true;
    4883            8 :       return NULL_TREE;
    4884            8 :     }
    4885           60 :   return handle_unsequenced_attribute (node, name, args, flags, no_add_attrs);
    4886              : }
    4887              : 
    4888              : /* Handle the standard [[reproducible]] attribute.  */
    4889              : 
    4890              : static tree
    4891           34 : handle_std_reproducible_attribute (tree *node, tree name, tree args,
    4892              :                                    int flags, bool *no_add_attrs)
    4893              : {
    4894           34 :   return handle_std_unsequenced_attribute (node, name, args, flags,
    4895           34 :                                            no_add_attrs);
    4896              : }
    4897              : 
    4898              : /* Table of supported standard (C23) attributes.  */
    4899              : static const attribute_spec std_attributes[] =
    4900              : {
    4901              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    4902              :        affects_type_identity, handler, exclude } */
    4903              :   { "_Noreturn", 0, 0, false, false, false, false,
    4904              :     handle_std_noreturn_attribute, NULL },
    4905              :   { "deprecated", 0, 1, false, false, false, false,
    4906              :     handle_deprecated_attribute, NULL },
    4907              :   { "fallthrough", 0, 0, false, false, false, false,
    4908              :     handle_fallthrough_attribute, NULL },
    4909              :   { "maybe_unused", 0, 0, false, false, false, false,
    4910              :     handle_unused_attribute, NULL },
    4911              :   { "nodiscard", 0, 1, false, false, false, false,
    4912              :     handle_nodiscard_attribute, NULL },
    4913              :   { "noreturn", 0, 0, false, false, false, false,
    4914              :     handle_std_noreturn_attribute, NULL },
    4915              :   { "reproducible", 0, 0, false, true, true, false,
    4916              :     handle_std_reproducible_attribute, NULL },
    4917              :   { "unsequenced", 0, 0, false, true, true, false,
    4918              :     handle_std_unsequenced_attribute, NULL }
    4919              : };
    4920              : 
    4921              : const scoped_attribute_specs std_attribute_table =
    4922              : {
    4923              :   nullptr, { std_attributes }
    4924              : };
    4925              : 
    4926              : /* Create the predefined scalar types of C,
    4927              :    and some nodes representing standard constants (0, 1, (void *) 0).
    4928              :    Initialize the global scope.
    4929              :    Make definitions for built-in primitive functions.  */
    4930              : 
    4931              : void
    4932       116628 : c_init_decl_processing (void)
    4933              : {
    4934       116628 :   location_t save_loc = input_location;
    4935              : 
    4936              :   /* Initialize reserved words for parser.  */
    4937       116628 :   c_parse_init ();
    4938              : 
    4939       116628 :   current_function_decl = NULL_TREE;
    4940              : 
    4941       116628 :   gcc_obstack_init (&parser_obstack);
    4942              : 
    4943              :   /* Make the externals scope.  */
    4944       116628 :   push_scope ();
    4945       116628 :   external_scope = current_scope;
    4946              : 
    4947              :   /* Declarations from c_common_nodes_and_builtins must not be associated
    4948              :      with this input file, lest we get differences between using and not
    4949              :      using preprocessed headers.  */
    4950       116628 :   input_location = BUILTINS_LOCATION;
    4951              : 
    4952       116628 :   c_common_nodes_and_builtins ();
    4953              : 
    4954              :   /* In C, comparisons and TRUTH_* expressions have type int.  */
    4955       116628 :   truthvalue_type_node = integer_type_node;
    4956       116628 :   truthvalue_true_node = integer_one_node;
    4957       116628 :   truthvalue_false_node = integer_zero_node;
    4958              : 
    4959              :   /* Even in C99, which has a real boolean type.  */
    4960       116628 :   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
    4961              :                         boolean_type_node));
    4962              : 
    4963              :   /* C-specific nullptr initialization.  */
    4964       116628 :   record_builtin_type (RID_MAX, "typeof (nullptr)", nullptr_type_node);
    4965              :   /* The size and alignment of nullptr_t is the same as for a pointer to
    4966              :      character type.  */
    4967       116628 :   SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4968              : 
    4969       116628 :   input_location = save_loc;
    4970              : 
    4971       116628 :   make_fname_decl = c_make_fname_decl;
    4972       116628 :   start_fname_decls ();
    4973              : 
    4974       116628 :   if (warn_keyword_macro)
    4975              :     {
    4976         1175 :       for (unsigned int i = 0; i < num_c_common_reswords; ++i)
    4977              :         /* For C register keywords which don't start with underscore
    4978              :            or start with just single underscore.  Don't complain about
    4979              :            ObjC or Transactional Memory keywords.  */
    4980         1170 :         if (c_common_reswords[i].word[0] == '_'
    4981          540 :             && c_common_reswords[i].word[1] == '_')
    4982          400 :           continue;
    4983          995 :         else if (c_common_reswords[i].disable
    4984          770 :                  & (D_TRANSMEM | D_OBJC | D_CXX_OBJC))
    4985          225 :           continue;
    4986              :         else
    4987              :           {
    4988          545 :             tree id = get_identifier (c_common_reswords[i].word);
    4989          545 :             if (C_IS_RESERVED_WORD (id)
    4990          545 :                 && C_RID_CODE (id) != RID_CXX_COMPAT_WARN)
    4991          332 :               cpp_warn (parse_in, IDENTIFIER_POINTER (id),
    4992          332 :                         IDENTIFIER_LENGTH (id));
    4993              :           }
    4994              :     }
    4995       116628 : }
    4996              : 
    4997              : /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
    4998              :    give the decl, NAME is the initialization string and TYPE_DEP
    4999              :    indicates whether NAME depended on the type of the function.  As we
    5000              :    don't yet implement delayed emission of static data, we mark the
    5001              :    decl as emitted so it is not placed in the output.  Anything using
    5002              :    it must therefore pull out the STRING_CST initializer directly.
    5003              :    FIXME.  */
    5004              : 
    5005              : static tree
    5006         2948 : c_make_fname_decl (location_t loc, tree id, int type_dep)
    5007              : {
    5008         2948 :   const char *name = fname_as_string (type_dep);
    5009         2948 :   tree decl, type, init;
    5010         2948 :   size_t length = strlen (name);
    5011              : 
    5012         2948 :   type = c_build_array_type (char_type_node,
    5013         2948 :                              build_index_type (size_int (length)));
    5014         2948 :   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
    5015              : 
    5016         2948 :   decl = build_decl (loc, VAR_DECL, id, type);
    5017              : 
    5018         2948 :   TREE_STATIC (decl) = 1;
    5019         2948 :   TREE_READONLY (decl) = 1;
    5020         2948 :   DECL_ARTIFICIAL (decl) = 1;
    5021              : 
    5022         2948 :   init = build_string (length + 1, name);
    5023         2948 :   free (const_cast<char *> (name));
    5024         2948 :   TREE_TYPE (init) = type;
    5025         2948 :   DECL_INITIAL (decl) = init;
    5026              : 
    5027         2948 :   TREE_USED (decl) = 1;
    5028              : 
    5029         2948 :   if (current_function_decl
    5030              :       /* For invalid programs like this:
    5031              : 
    5032              :          void foo()
    5033              :          const char* p = __FUNCTION__;
    5034              : 
    5035              :          the __FUNCTION__ is believed to appear in K&R style function
    5036              :          parameter declarator.  In that case we still don't have
    5037              :          function_scope.  */
    5038         2941 :       && current_function_scope)
    5039              :     {
    5040         2933 :       DECL_CONTEXT (decl) = current_function_decl;
    5041         2933 :       bind (id, decl, current_function_scope,
    5042              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
    5043              :     }
    5044              : 
    5045         2948 :   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
    5046              : 
    5047         2948 :   return decl;
    5048              : }
    5049              : 
    5050              : tree
    5051    341489882 : c_builtin_function (tree decl)
    5052              : {
    5053    341489882 :   tree type = TREE_TYPE (decl);
    5054    341489882 :   tree   id = DECL_NAME (decl);
    5055              : 
    5056    341489882 :   const char *name = IDENTIFIER_POINTER (id);
    5057    341489882 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5058              : 
    5059              :   /* Should never be called on a symbol with a preexisting meaning.  */
    5060    341489882 :   gcc_assert (!I_SYMBOL_BINDING (id));
    5061              : 
    5062    341489882 :   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
    5063              :         UNKNOWN_LOCATION);
    5064              : 
    5065              :   /* Builtins in the implementation namespace are made visible without
    5066              :      needing to be explicitly declared.  See push_file_scope.  */
    5067    341489882 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5068              :     {
    5069    233089408 :       DECL_CHAIN (decl) = visible_builtins;
    5070    233089408 :       visible_builtins = decl;
    5071              :     }
    5072              : 
    5073    341489882 :   return decl;
    5074              : }
    5075              : 
    5076              : tree
    5077     10506574 : c_builtin_function_ext_scope (tree decl)
    5078              : {
    5079     10506574 :   tree type = TREE_TYPE (decl);
    5080     10506574 :   tree   id = DECL_NAME (decl);
    5081              : 
    5082     10506574 :   const char *name = IDENTIFIER_POINTER (id);
    5083     10506574 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5084              : 
    5085     10506574 :   if (external_scope)
    5086     10316568 :     bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
    5087              :           UNKNOWN_LOCATION);
    5088              : 
    5089              :   /* Builtins in the implementation namespace are made visible without
    5090              :      needing to be explicitly declared.  See push_file_scope.  */
    5091     10506574 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5092              :     {
    5093     10506574 :       DECL_CHAIN (decl) = visible_builtins;
    5094     10506574 :       visible_builtins = decl;
    5095              :     }
    5096              : 
    5097     10506574 :   return decl;
    5098              : }
    5099              : 
    5100              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5101              : 
    5102              : tree
    5103            0 : c_simulate_builtin_function_decl (tree decl)
    5104              : {
    5105            0 :   tree type = TREE_TYPE (decl);
    5106            0 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5107            0 :   return pushdecl (decl);
    5108              : }
    5109              : 
    5110              : /* Warn about attributes in a context where they are unused
    5111              :    (attribute-declarations, except for the "fallthrough" case, and
    5112              :    attributes on statements).  */
    5113              : 
    5114              : void
    5115     41626227 : c_warn_unused_attributes (tree attrs)
    5116              : {
    5117     41626272 :   for (tree t = attrs; t != NULL_TREE; t = TREE_CHAIN (t))
    5118           45 :     if (get_attribute_namespace (t) == NULL_TREE)
    5119              :       /* The specifications of standard attributes mean this is a
    5120              :          constraint violation.  */
    5121           29 :       pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5122              :                get_attribute_name (t));
    5123           16 :     else if (!attribute_ignored_p (t))
    5124           12 :       warning (OPT_Wattributes, "%qE attribute ignored",
    5125              :                get_attribute_name (t));
    5126     41626227 : }
    5127              : 
    5128              : /* Warn for standard attributes being applied to a type that is not
    5129              :    being defined, where that is a constraint violation, and return a
    5130              :    list of attributes with them removed.  */
    5131              : 
    5132              : tree
    5133    436981072 : c_warn_type_attributes (tree type, tree attrs)
    5134              : {
    5135    436981072 :   tree *attr_ptr = &attrs;
    5136    437004336 :   while (*attr_ptr)
    5137        23264 :     if (get_attribute_namespace (*attr_ptr) == NULL_TREE)
    5138              :       {
    5139           89 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    5140              :           {
    5141           65 :             tree name = get_attribute_name (*attr_ptr);
    5142              :             /* [[unsequenced]] and [[reproducible]] is fine on function
    5143              :                types that aren't being defined.  */
    5144           65 :             if (is_attribute_p ("unsequenced", name)
    5145           65 :                 || is_attribute_p ("reproducible", name))
    5146              :               {
    5147           60 :                 attr_ptr = &TREE_CHAIN (*attr_ptr);
    5148           60 :                 continue;
    5149              :               }
    5150              :           }
    5151           29 :         pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5152              :                  get_attribute_name (*attr_ptr));
    5153           29 :         *attr_ptr = TREE_CHAIN (*attr_ptr);
    5154              :       }
    5155              :     else
    5156        23175 :       attr_ptr = &TREE_CHAIN (*attr_ptr);
    5157    436981072 :   return attrs;
    5158              : }
    5159              : 
    5160              : /* Called when a declaration is seen that contains no names to declare.
    5161              :    If its type is a reference to a structure, union or enum inherited
    5162              :    from a containing scope, shadow that tag name for the current scope
    5163              :    with a forward reference.
    5164              :    If its type defines a new named structure or union
    5165              :    or defines an enum, it is valid but we need not do anything here.
    5166              :    Otherwise, it is an error.  */
    5167              : 
    5168              : void
    5169       508149 : shadow_tag (const struct c_declspecs *declspecs)
    5170              : {
    5171       508149 :   shadow_tag_warned (declspecs, 0);
    5172       508149 : }
    5173              : 
    5174              : /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
    5175              :    but no pedwarn.  */
    5176              : void
    5177       508219 : shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
    5178              : {
    5179       508219 :   bool found_tag = false;
    5180              : 
    5181       508219 :   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
    5182              :     {
    5183       508105 :       tree value = declspecs->type;
    5184       508105 :       enum tree_code code = TREE_CODE (value);
    5185              : 
    5186       508105 :       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
    5187              :         /* Used to test also that TYPE_SIZE (value) != 0.
    5188              :            That caused warning for `struct foo;' at top level in the file.  */
    5189              :         {
    5190       508054 :           tree name = TYPE_NAME (value);
    5191       508054 :           tree t;
    5192              : 
    5193       508054 :           found_tag = true;
    5194              : 
    5195       508054 :           if (declspecs->restrict_p)
    5196              :             {
    5197            2 :               error ("invalid use of %<restrict%>");
    5198            2 :               warned = 1;
    5199              :             }
    5200              : 
    5201       508054 :           if (in_underspecified_init)
    5202              :             {
    5203              :               /* This can only occur with extensions such as statement
    5204              :                  expressions, but is still appropriate as an error to
    5205              :                  avoid types declared in such a context escaping to
    5206              :                  the type of an auto variable.  */
    5207            1 :               error ("%qT declared in underspecified object initializer",
    5208              :                      value);
    5209            1 :               warned = 1;
    5210              :             }
    5211              : 
    5212       508054 :           if (name == NULL_TREE)
    5213              :             {
    5214        61771 :               if (warned != 1 && code != ENUMERAL_TYPE)
    5215              :                 /* Empty unnamed enum OK */
    5216              :                 {
    5217           19 :                   pedwarn (input_location, 0,
    5218              :                            "unnamed struct/union that defines no instances");
    5219           19 :                   warned = 1;
    5220              :                 }
    5221              :             }
    5222       446283 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5223        89143 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5224        26472 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5225        26464 :                    && declspecs->storage_class != csc_none)
    5226              :             {
    5227            2 :               if (warned != 1)
    5228            2 :                 pedwarn (input_location, 0,
    5229              :                          "empty declaration with storage class specifier "
    5230              :                          "does not redeclare tag");
    5231            2 :               warned = 1;
    5232            2 :               pending_xref_error ();
    5233              :             }
    5234       446281 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5235        89141 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5236        26470 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5237        26462 :                    && (declspecs->const_p
    5238        26459 :                        || declspecs->volatile_p
    5239        26459 :                        || declspecs->atomic_p
    5240        26459 :                        || declspecs->restrict_p
    5241        26459 :                        || declspecs->address_space))
    5242              :             {
    5243            3 :               if (warned != 1)
    5244            3 :                 pedwarn (input_location, 0,
    5245              :                          "empty declaration with type qualifier "
    5246              :                           "does not redeclare tag");
    5247            3 :               warned = 1;
    5248            3 :               pending_xref_error ();
    5249              :             }
    5250       446278 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5251        89138 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5252        26467 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5253        26459 :                    && declspecs->alignas_p)
    5254              :             {
    5255            1 :               if (warned != 1)
    5256            1 :                 pedwarn (input_location, 0,
    5257              :                          "empty declaration with %<_Alignas%> "
    5258              :                           "does not redeclare tag");
    5259            1 :               warned = 1;
    5260            1 :               pending_xref_error ();
    5261              :             }
    5262       446277 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5263        89137 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5264        26466 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5265        26458 :                    && code == ENUMERAL_TYPE
    5266           15 :                    && !declspecs->enum_type_specifier_ref_p)
    5267              :             {
    5268            3 :               bool warned_enum = false;
    5269            3 :               if (warned != 1)
    5270            3 :                 warned_enum = pedwarn (input_location, OPT_Wpedantic,
    5271              :                                        "empty declaration of %<enum%> type "
    5272              :                                        "does not redeclare tag");
    5273            3 :               if (warned_enum)
    5274            2 :                 warned = 1;
    5275            3 :               pending_xref_error ();
    5276            3 :             }
    5277              :           else
    5278              :             {
    5279       446274 :               pending_invalid_xref = NULL_TREE;
    5280       446274 :               t = lookup_tag (code, name, true, NULL);
    5281              : 
    5282       446274 :               if (t == NULL_TREE)
    5283              :                 {
    5284            2 :                   t = make_node (code);
    5285            2 :                   if (flag_isoc23 || code == ENUMERAL_TYPE)
    5286            1 :                     SET_TYPE_STRUCTURAL_EQUALITY (t);
    5287            2 :                   pushtag (input_location, name, t);
    5288              :                 }
    5289              :             }
    5290              :         }
    5291              :       else
    5292              :         {
    5293           51 :           if (warned != 1 && !in_system_header_at (input_location))
    5294              :             {
    5295           44 :               pedwarn (input_location, 0,
    5296              :                        "useless type name in empty declaration");
    5297           44 :               warned = 1;
    5298              :             }
    5299              :         }
    5300              :     }
    5301           71 :   else if (warned != 1 && !in_system_header_at (input_location)
    5302          185 :            && declspecs->typedef_p)
    5303              :     {
    5304           11 :       pedwarn (input_location, 0, "useless type name in empty declaration");
    5305           11 :       warned = 1;
    5306              :     }
    5307              : 
    5308       508219 :   pending_invalid_xref = NULL_TREE;
    5309              : 
    5310       508219 :   if (declspecs->inline_p)
    5311              :     {
    5312            5 :       error ("%<inline%> in empty declaration");
    5313            5 :       warned = 1;
    5314              :     }
    5315              : 
    5316       508219 :   if (declspecs->noreturn_p)
    5317              :     {
    5318            2 :       error ("%<_Noreturn%> in empty declaration");
    5319            2 :       warned = 1;
    5320              :     }
    5321              : 
    5322       508219 :   if (declspecs->constexpr_p)
    5323              :     {
    5324            7 :       error ("%<constexpr%> in empty declaration");
    5325            7 :       warned = 1;
    5326              :     }
    5327              : 
    5328       508219 :   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
    5329              :     {
    5330            2 :       error ("%<auto%> in file-scope empty declaration");
    5331            2 :       warned = 1;
    5332              :     }
    5333              : 
    5334       508219 :   if (current_scope == file_scope && declspecs->storage_class == csc_register)
    5335              :     {
    5336            2 :       error ("%<register%> in file-scope empty declaration");
    5337            2 :       warned = 1;
    5338              :     }
    5339              : 
    5340       508219 :   if (declspecs->enum_type_specifier_ref_p && !warned)
    5341              :     {
    5342           39 :       if (declspecs->storage_class != csc_none)
    5343              :         {
    5344            1 :           error ("storage class specifier in empty declaration with %<enum%> "
    5345              :                  "underlying type");
    5346            1 :           warned = 1;
    5347              :         }
    5348           38 :       else if (declspecs->thread_p)
    5349              :         {
    5350            2 :           error ("%qs in empty declaration with %<enum%> underlying type",
    5351            1 :                  declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5352            1 :           warned = 1;
    5353              :         }
    5354           37 :       else if (declspecs->const_p
    5355           36 :                || declspecs->volatile_p
    5356           36 :                || declspecs->atomic_p
    5357           36 :                || declspecs->restrict_p
    5358           36 :                || declspecs->address_space)
    5359              :         {
    5360            1 :           error ("type qualifier in empty declaration with %<enum%> "
    5361              :                  "underlying type");
    5362            1 :           warned = 1;
    5363              :         }
    5364           36 :       else if (declspecs->alignas_p)
    5365              :         {
    5366            1 :           error ("%<alignas%> in empty declaration with %<enum%> "
    5367              :                  "underlying type");
    5368            1 :           warned = 1;
    5369              :         }
    5370              :     }
    5371              : 
    5372       508051 :   if (!warned && !in_system_header_at (input_location)
    5373       627309 :       && declspecs->storage_class != csc_none)
    5374              :     {
    5375           12 :       warning (0, "useless storage class specifier in empty declaration");
    5376           12 :       warned = 2;
    5377              :     }
    5378              : 
    5379       508219 :   if (!warned && !in_system_header_at (input_location) && declspecs->thread_p)
    5380              :     {
    5381            3 :       warning (0, "useless %qs in empty declaration",
    5382            3 :                declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5383            3 :       warned = 2;
    5384              :     }
    5385              : 
    5386            3 :   if (!warned
    5387       508032 :       && !in_system_header_at (input_location)
    5388       627299 :       && (declspecs->const_p
    5389       119075 :           || declspecs->volatile_p
    5390       119075 :           || declspecs->atomic_p
    5391       119075 :           || declspecs->restrict_p
    5392       119075 :           || declspecs->address_space))
    5393              :     {
    5394            8 :       warning (0, "useless type qualifier in empty declaration");
    5395            8 :       warned = 2;
    5396              :     }
    5397              : 
    5398       508032 :   if (!warned && !in_system_header_at (input_location)
    5399       627286 :       && declspecs->alignas_p)
    5400              :     {
    5401            4 :       warning (0, "useless %<_Alignas%> in empty declaration");
    5402            4 :       warned = 2;
    5403              :     }
    5404              : 
    5405       508219 :   if (found_tag
    5406       508219 :       && warned == 2
    5407           23 :       && (declspecs->typespec_kind == ctsk_tagref_attrs
    5408           23 :           || declspecs->typespec_kind == ctsk_tagfirstref_attrs))
    5409              :     {
    5410              :       /* Standard attributes after the "struct" or "union" keyword are
    5411              :          only permitted when the contents of the type are defined, or
    5412              :          in the form "struct-or-union attribute-specifier-sequence
    5413              :          identifier;".  If the ';' was not present, attributes were
    5414              :          diagnosed in the parser.  Here, ensure that any other useless
    5415              :          elements of the declaration result in a pedwarn, not just a
    5416              :          warning.  Forward declarations of enum types are not part of
    5417              :          standard C, but handle them the same.  */
    5418            2 :       pedwarn (input_location, 0,
    5419              :                "invalid use of attributes in empty declaration");
    5420            2 :       warned = 1;
    5421              :     }
    5422              : 
    5423       508219 :   if (warned != 1)
    5424              :     {
    5425       508045 :       if (declspecs->declspecs_seen_p
    5426       508045 :           && !declspecs->non_std_attrs_seen_p)
    5427              :         /* An attribute declaration (but not a fallthrough attribute
    5428              :            declaration, which was handled separately); warn if there
    5429              :            are any attributes being ignored (but not if the attributes
    5430              :            were empty).  */
    5431           48 :         c_warn_unused_attributes (declspecs->attrs);
    5432       507997 :       else if (!found_tag)
    5433           10 :         pedwarn (input_location, 0, "empty declaration");
    5434              :     }
    5435       508219 : }
    5436              : 
    5437              : 
    5438              : /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
    5439              :    bits.  SPECS represents declaration specifiers that the grammar
    5440              :    only permits to contain type qualifiers and attributes.  */
    5441              : 
    5442              : int
    5443     18387663 : quals_from_declspecs (const struct c_declspecs *specs)
    5444              : {
    5445     18387663 :   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
    5446              :                | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
    5447              :                | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
    5448     18387663 :                | (specs->atomic_p ? TYPE_QUAL_ATOMIC : 0)
    5449     18387663 :                | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
    5450     18387663 :   gcc_assert (!specs->type
    5451              :               && !specs->decl_attr
    5452              :               && specs->typespec_word == cts_none
    5453              :               && specs->storage_class == csc_none
    5454              :               && !specs->typedef_p
    5455              :               && !specs->explicit_signed_p
    5456              :               && !specs->deprecated_p
    5457              :               && !specs->unavailable_p
    5458              :               && !specs->long_p
    5459              :               && !specs->long_long_p
    5460              :               && !specs->short_p
    5461              :               && !specs->signed_p
    5462              :               && !specs->unsigned_p
    5463              :               && !specs->complex_p
    5464              :               && !specs->inline_p
    5465              :               && !specs->noreturn_p
    5466              :               && !specs->thread_p);
    5467     18387663 :   return quals;
    5468              : }
    5469              : 
    5470              : /* Construct an array declarator.  LOC is the location of the
    5471              :    beginning of the array (usually the opening brace).  EXPR is the
    5472              :    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
    5473              :    inside the [] (to be applied to the pointer to which a parameter
    5474              :    array is converted).  STATIC_P is true if "static" is inside the
    5475              :    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
    5476              :    VLA of unspecified length which is nevertheless a complete type,
    5477              :    false otherwise.  The field for the contained declarator is left to
    5478              :    be filled in by set_array_declarator_inner.  */
    5479              : 
    5480              : struct c_declarator *
    5481      1143824 : build_array_declarator (location_t loc,
    5482              :                         tree expr, struct c_declspecs *quals, bool static_p,
    5483              :                         bool vla_unspec_p)
    5484              : {
    5485      1143824 :   struct c_declarator *declarator = XOBNEW (&parser_obstack,
    5486              :                                             struct c_declarator);
    5487      1143824 :   declarator->id_loc = loc;
    5488      1143824 :   declarator->kind = cdk_array;
    5489      1143824 :   declarator->declarator = 0;
    5490      1143824 :   declarator->u.array.dimen = expr;
    5491      1143824 :   if (quals)
    5492              :     {
    5493          966 :       declarator->u.array.attrs = quals->attrs;
    5494          966 :       declarator->u.array.quals = quals_from_declspecs (quals);
    5495              :     }
    5496              :   else
    5497              :     {
    5498      1142858 :       declarator->u.array.attrs = NULL_TREE;
    5499      1142858 :       declarator->u.array.quals = 0;
    5500              :     }
    5501      1143824 :   declarator->u.array.static_p = static_p;
    5502      1143824 :   declarator->u.array.vla_unspec_p = vla_unspec_p;
    5503      1143824 :   if (static_p || quals != NULL)
    5504         1069 :     pedwarn_c90 (loc, OPT_Wpedantic,
    5505              :                  "ISO C90 does not support %<static%> or type "
    5506              :                  "qualifiers in parameter array declarators");
    5507      1143824 :   if (vla_unspec_p)
    5508              :     {
    5509          152 :       pedwarn_c90 (loc, OPT_Wpedantic,
    5510              :                    "ISO C90 does not support %<[*]%> array declarators");
    5511          152 :       if (current_scope->parm_flag)
    5512          144 :         current_scope->had_vla_unspec = true;
    5513              :     }
    5514      1143824 :   return declarator;
    5515              : }
    5516              : 
    5517              : /* Set the contained declarator of an array declarator.  DECL is the
    5518              :    declarator, as constructed by build_array_declarator; INNER is what
    5519              :    appears on the left of the [].  */
    5520              : 
    5521              : struct c_declarator *
    5522      1143824 : set_array_declarator_inner (struct c_declarator *decl,
    5523              :                             struct c_declarator *inner)
    5524              : {
    5525      1143824 :   decl->declarator = inner;
    5526      1143824 :   return decl;
    5527              : }
    5528              : 
    5529              : /* Determine whether TYPE is a one-element array type "[1]".  */
    5530              : static bool
    5531       535973 : one_element_array_type_p (const_tree type)
    5532              : {
    5533       535973 :   if (TREE_CODE (type) != ARRAY_TYPE)
    5534              :     return false;
    5535       535973 :   return integer_zerop (array_type_nelts_minus_one (type));
    5536              : }
    5537              : 
    5538              : /* Determine whether TYPE is a zero-length array type "[0]".  */
    5539              : static bool
    5540       535973 : zero_length_array_type_p (const_tree type)
    5541              : {
    5542       535973 :   if (TREE_CODE (type) == ARRAY_TYPE)
    5543       535973 :     if (tree type_size = TYPE_SIZE_UNIT (type))
    5544       449955 :       if ((integer_zerop (type_size))
    5545         1828 :            && TYPE_DOMAIN (type) != NULL_TREE
    5546       451783 :            && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
    5547              :         return true;
    5548              :   return false;
    5549              : }
    5550              : 
    5551              : /* INIT is a constructor that forms DECL's initializer.  If the final
    5552              :    element initializes a flexible array field, adjust the size of the
    5553              :    DECL with the initializer based on whether the DECL is a union or
    5554              :    a structure.  */
    5555              : 
    5556              : static void
    5557       105847 : add_flexible_array_elts_to_size (tree decl, tree init)
    5558              : {
    5559       105847 :   tree elt, type;
    5560              : 
    5561       105847 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    5562         1600 :     return;
    5563              : 
    5564       104247 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    5565       104247 :   type = TREE_TYPE (elt);
    5566       104247 :   if (c_flexible_array_member_type_p (type))
    5567              :     {
    5568          221 :       complete_array_type (&type, elt, false);
    5569              :       /* For a structure, add the size of the initializer to the DECL's
    5570              :          size.  */
    5571          221 :       if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    5572              :         {
    5573          211 :           DECL_SIZE (decl)
    5574          211 :             = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5575          211 :           DECL_SIZE_UNIT (decl)
    5576          422 :             = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    5577              :                           TYPE_SIZE_UNIT (type));
    5578              :         }
    5579              :       /* For a union, the DECL's size is the maximum of the current size
    5580              :          and the size of the initializer.  */
    5581              :       else
    5582              :         {
    5583           10 :           DECL_SIZE (decl)
    5584           10 :             = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5585           10 :           DECL_SIZE_UNIT (decl)
    5586           20 :             = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    5587              :                           TYPE_SIZE_UNIT (type));
    5588              :         }
    5589              :     }
    5590              : }
    5591              : 
    5592              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.
    5593              :    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
    5594              :    before the type name, and set *EXPR_CONST_OPERANDS, if
    5595              :    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
    5596              :    appear in a constant expression.  */
    5597              : 
    5598              : tree
    5599    121580717 : groktypename (struct c_type_name *type_name, tree *expr,
    5600              :               bool *expr_const_operands)
    5601              : {
    5602    121580717 :   tree type;
    5603    121580717 :   tree attrs = type_name->specs->attrs;
    5604              : 
    5605    121580717 :   type_name->specs->attrs = NULL_TREE;
    5606              : 
    5607    121580717 :   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
    5608              :                          false, NULL, &attrs, expr, expr_const_operands,
    5609              :                          DEPRECATED_NORMAL);
    5610              : 
    5611              :   /* Apply attributes.  */
    5612    121580717 :   attrs = c_warn_type_attributes (type, attrs);
    5613    121580717 :   decl_attributes (&type, attrs, 0);
    5614              : 
    5615    121580717 :   return type;
    5616              : }
    5617              : 
    5618              : 
    5619              : /* Decode a "typename", such as "int **", returning a ..._TYPE node,
    5620              :    as for groktypename but setting the context to GENERIC_ASSOC.  */
    5621              : 
    5622              : tree
    5623         1445 : grokgenassoc (struct c_type_name *type_name)
    5624              : {
    5625         1445 :   tree type;
    5626         1445 :   tree attrs = type_name->specs->attrs;
    5627              : 
    5628         1445 :   type_name->specs->attrs = NULL_TREE;
    5629              : 
    5630         1445 :   type = grokdeclarator (type_name->declarator, type_name->specs, GENERIC_ASSOC,
    5631              :                          false, NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
    5632              : 
    5633              :   /* Apply attributes.  */
    5634         1445 :   attrs = c_warn_type_attributes (type, attrs);
    5635         1445 :   decl_attributes (&type, attrs, 0);
    5636              : 
    5637         1445 :   return type;
    5638              : }
    5639              : 
    5640              : 
    5641              : /* Looks up the most recent pushed declaration corresponding to DECL.  */
    5642              : 
    5643              : static tree
    5644     93102569 : lookup_last_decl (tree decl)
    5645              : {
    5646     93102569 :   tree last_decl = lookup_name (DECL_NAME (decl));
    5647     93102569 :   if (!last_decl)
    5648     90513722 :     last_decl = lookup_name_in_scope (DECL_NAME (decl), external_scope);
    5649     93102569 :   return last_decl;
    5650              : }
    5651              : 
    5652              : /* Wrapper for decl_attributes that adds some implicit attributes
    5653              :    to VAR_DECLs or FUNCTION_DECLs.  */
    5654              : 
    5655              : static tree
    5656     64717472 : c_decl_attributes (tree *node, tree attributes, int flags)
    5657              : {
    5658              :   /* Add implicit "omp declare target" attribute if requested.  */
    5659     64717472 :   if (vec_safe_length (current_omp_declare_target_attribute)
    5660         9167 :       && ((VAR_P (*node) && is_global_var (*node))
    5661         2729 :           || TREE_CODE (*node) == FUNCTION_DECL))
    5662              :     {
    5663         1131 :       if (VAR_P (*node) && !omp_mappable_type (TREE_TYPE (*node)))
    5664           13 :         attributes = tree_cons (get_identifier ("omp declare target implicit"),
    5665              :                                 NULL_TREE, attributes);
    5666              :       else
    5667         1118 :         attributes = tree_cons (get_identifier ("omp declare target"),
    5668              :                                 NULL_TREE, attributes);
    5669         1131 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5670              :         {
    5671         1001 :           int device_type
    5672         1001 :             = current_omp_declare_target_attribute->last ().device_type;
    5673         1001 :           device_type = MAX (device_type, 0);
    5674         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    5675         1001 :               && !lookup_attribute ("omp declare target host", attributes))
    5676            2 :             attributes
    5677            2 :               = tree_cons (get_identifier ("omp declare target host"),
    5678              :                            NULL_TREE, attributes);
    5679         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    5680         1001 :               && !lookup_attribute ("omp declare target nohost", attributes))
    5681            2 :             attributes
    5682            2 :               = tree_cons (get_identifier ("omp declare target nohost"),
    5683              :                            NULL_TREE, attributes);
    5684              : 
    5685         1001 :           int indirect
    5686         1001 :             = current_omp_declare_target_attribute->last ().indirect;
    5687         1001 :           if (indirect && !lookup_attribute ("omp declare target indirect",
    5688              :                                              attributes))
    5689           10 :             attributes
    5690           10 :               = tree_cons (get_identifier ("omp declare target indirect"),
    5691              :                            NULL_TREE, attributes);
    5692              :         }
    5693              :     }
    5694              : 
    5695     64717472 :   if (flag_openmp || flag_openmp_simd)
    5696              :     {
    5697              :       bool diagnosed = false;
    5698      1374282 :       for (tree *pa = &attributes; *pa; )
    5699              :         {
    5700       884552 :           if (is_attribute_namespace_p ("omp", *pa))
    5701              :             {
    5702           65 :               tree name = get_attribute_name (*pa);
    5703           65 :               if (is_attribute_p ("directive", name)
    5704            0 :                   || is_attribute_p ("sequence", name)
    5705           65 :                   || is_attribute_p ("decl", name))
    5706              :                 {
    5707           65 :                   const char *p = NULL;
    5708           65 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    5709           12 :                     p = IDENTIFIER_POINTER (name);
    5710          118 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    5711              :                     {
    5712           53 :                       tree d = TREE_VALUE (a);
    5713           53 :                       gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
    5714           96 :                       if (TREE_PUBLIC (d)
    5715           43 :                           && (VAR_P (*node)
    5716            2 :                               || TREE_CODE (*node) == FUNCTION_DECL)
    5717           96 :                           && c_maybe_parse_omp_decl (*node, d))
    5718           43 :                         continue;
    5719           10 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    5720              :                     }
    5721           65 :                   if (p && !diagnosed)
    5722              :                     {
    5723           22 :                       error ("%<omp::%s%> not allowed to be specified in "
    5724              :                              "this context", p);
    5725           22 :                       diagnosed = true;
    5726              :                     }
    5727           65 :                   if (p)
    5728              :                     {
    5729           22 :                       *pa = TREE_CHAIN (*pa);
    5730           22 :                       continue;
    5731              :                     }
    5732              :                 }
    5733              :             }
    5734       884530 :           pa = &TREE_CHAIN (*pa);
    5735              :         }
    5736              :     }
    5737              : 
    5738              :   /* Look up the current declaration with all the attributes merged
    5739              :      so far so that attributes on the current declaration that's
    5740              :      about to be pushed that conflict with the former can be detected,
    5741              :      diagnosed, and rejected as appropriate.  To match the C++ FE, do
    5742              :      not pass an error_mark_node when we found an undeclared variable.  */
    5743     64717472 :   tree last_decl = lookup_last_decl (*node);
    5744     64717472 :   if (last_decl == error_mark_node)
    5745           20 :     last_decl = NULL_TREE;
    5746     64717472 :   tree attr = decl_attributes (node, attributes, flags, last_decl);
    5747     64717471 :   if (VAR_P (*node) && DECL_THREAD_LOCAL_P (*node))
    5748              :     {
    5749              :       // tls_model attribute can set a stronger TLS access model.
    5750         2886 :       tls_model model = DECL_TLS_MODEL (*node);
    5751         2886 :       tls_model default_model = decl_default_tls_model (*node);
    5752         2886 :       if (default_model > model)
    5753         1631 :         set_decl_tls_model (*node, default_model);
    5754              :     }
    5755     64717471 :   return attr;
    5756              : }
    5757              : 
    5758              : 
    5759              : /* Decode a declarator in an ordinary declaration or data definition.
    5760              :    This is called as soon as the type information and variable name
    5761              :    have been parsed, before parsing the initializer if any.
    5762              :    Here we create the ..._DECL node, fill in its type,
    5763              :    and (if DO_PUSH) put it on the list of decls for the current context.
    5764              :    When nonnull, set *LASTLOC to the location of the prior declaration
    5765              :    of the same entity if one exists.
    5766              :    The ..._DECL node is returned as the value.
    5767              : 
    5768              :    Exception: for arrays where the length is not specified,
    5769              :    the type is left null, to be filled in by `finish_decl'.
    5770              : 
    5771              :    Function definitions do not come here; they go to start_function
    5772              :    instead.  However, external and forward declarations of functions
    5773              :    do go through here.  Structure field declarations are done by
    5774              :    grokfield and not through here.  */
    5775              : 
    5776              : tree
    5777     28385121 : start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
    5778              :             bool initialized, tree attributes, bool do_push /* = true */,
    5779              :             location_t *lastloc /* = NULL */)
    5780              : {
    5781     28385121 :   tree decl;
    5782     28385121 :   tree old_decl;
    5783     28385121 :   tree tem;
    5784     28385121 :   tree expr = NULL_TREE;
    5785     28385121 :   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
    5786              : 
    5787              :   /* An object declared as __attribute__((unavailable)) suppresses
    5788              :      warnings and errors from __attribute__((deprecated/unavailable))
    5789              :      components.
    5790              :      An object declared as __attribute__((deprecated)) suppresses
    5791              :      warnings of uses of other deprecated items.  */
    5792     28385121 :   if (lookup_attribute ("unavailable", attributes))
    5793              :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
    5794     28385097 :   else if (lookup_attribute ("deprecated", attributes))
    5795        30020 :     deprecated_state = DEPRECATED_SUPPRESS;
    5796              : 
    5797     28385121 :   decl = grokdeclarator (declarator, declspecs,
    5798              :                          NORMAL, initialized, NULL, &attributes, &expr, NULL,
    5799              :                          deprecated_state);
    5800     28385121 :   if (!decl || decl == error_mark_node)
    5801              :     return NULL_TREE;
    5802              : 
    5803     28385097 :   old_decl = lookup_last_decl (decl);
    5804              : 
    5805     28385097 :   if (tree lastdecl = lastloc ? old_decl : NULL_TREE)
    5806      4883894 :     if (lastdecl != error_mark_node)
    5807      4883885 :       *lastloc = DECL_SOURCE_LOCATION (lastdecl);
    5808              : 
    5809              :   /* Make sure the size expression is evaluated at this point.  */
    5810     28385097 :   if (expr && !current_scope->parm_flag)
    5811        12973 :     add_stmt (fold_convert (void_type_node, expr));
    5812              : 
    5813     13289625 :   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))
    5814     28385099 :       && TREE_PUBLIC (decl))
    5815            1 :     warning (OPT_Wmain, "%q+D is usually a function", decl);
    5816              : 
    5817           14 :   if (warn_missing_variable_declarations && VAR_P (decl)
    5818     28385110 :       && !DECL_EXTERNAL (decl) && TREE_PUBLIC (decl) && old_decl == NULL_TREE)
    5819            5 :     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_variable_declarations,
    5820              :                 "no previous declaration for %qD", decl);
    5821              : 
    5822     28385097 :   if (initialized)
    5823              :     /* Is it valid for this decl to have an initializer at all?
    5824              :        If not, set INITIALIZED to zero, which will indirectly
    5825              :        tell 'finish_decl' to ignore the initializer once it is parsed.  */
    5826      6353300 :     switch (TREE_CODE (decl))
    5827              :       {
    5828            6 :       case TYPE_DECL:
    5829            6 :         error ("typedef %qD is initialized (use %<__typeof__%> instead)", decl);
    5830            6 :         initialized = false;
    5831            6 :         break;
    5832              : 
    5833            9 :       case FUNCTION_DECL:
    5834            9 :         error ("function %qD is initialized like a variable", decl);
    5835            9 :         initialized = false;
    5836            9 :         break;
    5837              : 
    5838           49 :       case PARM_DECL:
    5839              :         /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
    5840           49 :         error ("parameter %qD is initialized", decl);
    5841           49 :         initialized = false;
    5842           49 :         break;
    5843              : 
    5844      6353236 :       default:
    5845              :         /* Don't allow initializations for incomplete types except for
    5846              :            arrays which might be completed by the initialization.  */
    5847              : 
    5848              :         /* This can happen if the array size is an undefined macro.
    5849              :            We already gave a warning, so we don't need another one.  */
    5850      6353236 :         if (TREE_TYPE (decl) == error_mark_node)
    5851              :           initialized = false;
    5852      6353214 :         else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
    5853              :           {
    5854              :             /* A complete type is ok if size is fixed.  If the size is
    5855              :                variable, an empty initializer is OK and nonempty
    5856              :                initializers will be diagnosed in the parser.  */
    5857              :           }
    5858        12337 :         else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
    5859              :           {
    5860            3 :             error ("variable %qD has initializer but incomplete type", decl);
    5861            3 :             initialized = false;
    5862              :           }
    5863              :       }
    5864              : 
    5865           67 :   if (initialized)
    5866              :     {
    5867      6353211 :       if (current_scope == file_scope)
    5868       156980 :         TREE_STATIC (decl) = 1;
    5869              : 
    5870              :       /* Tell 'pushdecl' this is an initialized decl
    5871              :          even though we don't yet have the initializer expression.
    5872              :          Also tell 'finish_decl' it may store the real initializer.  */
    5873      6353211 :       DECL_INITIAL (decl) = error_mark_node;
    5874              :     }
    5875              : 
    5876              :   /* If this is a function declaration, write a record describing it to the
    5877              :      prototypes file (if requested).  */
    5878              : 
    5879     28385097 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5880     15095472 :     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
    5881              : 
    5882              :   /* ANSI specifies that a tentative definition which is not merged with
    5883              :      a non-tentative definition behaves exactly like a definition with an
    5884              :      initializer equal to zero.  (Section 3.7.2)
    5885              : 
    5886              :      -fno-common gives strict ANSI behavior, though this tends to break
    5887              :      a large body of code that grew up without this rule.
    5888              : 
    5889              :      Thread-local variables are never common, since there's no entrenched
    5890              :      body of code to break, and it allows more efficient variable references
    5891              :      in the presence of dynamic linking.  */
    5892              : 
    5893     28385097 :   if (VAR_P (decl)
    5894      8926907 :       && !initialized
    5895      2573696 :       && TREE_PUBLIC (decl)
    5896       988148 :       && !DECL_THREAD_LOCAL_P (decl)
    5897     29370874 :       && !flag_no_common)
    5898          128 :     DECL_COMMON (decl) = 1;
    5899              : 
    5900              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5901     28385097 :   c_decl_attributes (&decl, attributes, 0);
    5902              : 
    5903              :   /* Handle gnu_inline attribute.  */
    5904     28385096 :   if (declspecs->inline_p
    5905         1041 :       && !flag_gnu89_inline
    5906         1009 :       && TREE_CODE (decl) == FUNCTION_DECL
    5907     28386097 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
    5908          978 :           || current_function_decl))
    5909              :     {
    5910           46 :       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
    5911              :         ;
    5912           37 :       else if (declspecs->storage_class != csc_static)
    5913           37 :         DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
    5914              :     }
    5915              : 
    5916     28385096 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5917     15095471 :       && DECL_DECLARED_INLINE_P (decl)
    5918         1031 :       && DECL_UNINLINABLE (decl)
    5919     28385098 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5920              :     {
    5921            2 :       auto_urlify_attributes sentinel;
    5922            2 :       warning (OPT_Wattributes, "inline function %q+D given attribute %qs",
    5923              :                decl, "noinline");
    5924            2 :     }
    5925              : 
    5926              :   /* C99 6.7.4p3: An inline definition of a function with external
    5927              :      linkage shall not contain a definition of a modifiable object
    5928              :      with static storage duration...  */
    5929     28385096 :   if (VAR_P (decl)
    5930      8926907 :       && current_scope != file_scope
    5931      7774685 :       && TREE_STATIC (decl)
    5932        78843 :       && !TREE_READONLY (decl)
    5933        76286 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    5934     28385166 :       && DECL_EXTERNAL (current_function_decl))
    5935            7 :     record_inline_static (input_location, current_function_decl,
    5936              :                           decl, csi_modifiable);
    5937              : 
    5938     28385096 :   if (c_dialect_objc ()
    5939            0 :       && VAR_OR_FUNCTION_DECL_P (decl))
    5940            0 :       objc_check_global_decl (decl);
    5941              : 
    5942              :   /* To enable versions to be created across TU's we mark and mangle all
    5943              :      non-default versioned functions.  */
    5944     28385096 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5945              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
    5946              :       && get_target_version (decl).is_valid ())
    5947              :     {
    5948              :       maybe_mark_function_versioned (decl);
    5949              :       if (current_scope != file_scope)
    5950              :         error ("versioned declarations are only allowed at file scope");
    5951              :     }
    5952              : 
    5953              :   /* Add this decl to the current scope.
    5954              :      TEM may equal DECL or it may be a previous decl of the same name.  */
    5955     28385096 :   if (do_push)
    5956              :     {
    5957     28384744 :       tem = pushdecl (decl);
    5958              : 
    5959     28384744 :       if (initialized && DECL_EXTERNAL (tem))
    5960              :         {
    5961           27 :           DECL_EXTERNAL (tem) = 0;
    5962           27 :           TREE_STATIC (tem) = 1;
    5963              :         }
    5964              : 
    5965     28384744 :       return tem;
    5966              :     }
    5967              :   else
    5968          352 :     return decl;
    5969              : }
    5970              : 
    5971              : /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
    5972              :    DECL or the non-array element type if DECL is an uninitialized array.
    5973              :    If that type has a const member, diagnose this. */
    5974              : 
    5975              : static void
    5976            7 : diagnose_uninitialized_cst_member (tree decl, tree type)
    5977              : {
    5978            7 :   tree field;
    5979           17 :   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
    5980              :     {
    5981           10 :       tree field_type;
    5982           10 :       if (TREE_CODE (field) != FIELD_DECL)
    5983            0 :         continue;
    5984           10 :       field_type = strip_array_types (TREE_TYPE (field));
    5985              : 
    5986           10 :       if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
    5987              :         {
    5988            5 :           auto_diagnostic_group d;
    5989            5 :           if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    5990              :                           "uninitialized const member in %qT is invalid in C++",
    5991            5 :                           strip_array_types (TREE_TYPE (decl))))
    5992            5 :             inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
    5993            5 :         }
    5994              : 
    5995           10 :       if (RECORD_OR_UNION_TYPE_P (field_type))
    5996            2 :         diagnose_uninitialized_cst_member (decl, field_type);
    5997              :     }
    5998            7 : }
    5999              : 
    6000              : /* Finish processing of a declaration;
    6001              :    install its initial value.
    6002              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    6003              :    If the length of an array type is not known before,
    6004              :    it must be determined now, from the initial value, or it is an error.
    6005              : 
    6006              :    INIT_LOC is the location of the initial value.  */
    6007              : 
    6008              : void
    6009    157457169 : finish_decl (tree decl, location_t init_loc, tree init,
    6010              :              tree origtype, tree asmspec_tree)
    6011              : {
    6012    157457169 :   tree type;
    6013    157457169 :   bool was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
    6014    157457169 :   const char *asmspec = 0;
    6015              : 
    6016              :   /* If a name was specified, get the string.  */
    6017    148527261 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6018    172552640 :       && DECL_FILE_SCOPE_P (decl))
    6019     16249210 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    6020    157457169 :   if (asmspec_tree)
    6021       873519 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    6022              : 
    6023    157457169 :   if (VAR_P (decl)
    6024      8929908 :       && TREE_STATIC (decl)
    6025    158521845 :       && global_bindings_p ())
    6026              :     /* So decl is a global variable. Record the types it uses
    6027              :        so that we can decide later to emit debug info for them.  */
    6028       982615 :     record_types_used_by_current_var_decl (decl);
    6029              : 
    6030              :   /* If `start_decl' didn't like having an initialization, ignore it now.  */
    6031    157457169 :   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
    6032              :     init = NULL_TREE;
    6033              : 
    6034              :   /* Don't crash if parm is initialized.  */
    6035    157457169 :   if (TREE_CODE (decl) == PARM_DECL)
    6036              :     init = NULL_TREE;
    6037              : 
    6038     32689996 :   if (init)
    6039      6356213 :     store_init_value (init_loc, decl, init, origtype);
    6040              : 
    6041    157457169 :   if (c_dialect_objc () && (VAR_OR_FUNCTION_DECL_P (decl)
    6042            0 :                             || TREE_CODE (decl) == FIELD_DECL))
    6043            0 :     objc_check_decl (decl);
    6044              : 
    6045    157457169 :   type = TREE_TYPE (decl);
    6046              : 
    6047              :   /* Deduce size of array from initialization, if not already known.
    6048              :      This is only needed for an initialization in the current scope;
    6049              :      it must not be done for a file-scope initialization of a
    6050              :      declaration with external linkage, redeclared in an inner scope
    6051              :      with the outer declaration shadowed in an intermediate scope.  */
    6052    157457169 :   if (TREE_CODE (type) == ARRAY_TYPE
    6053       856773 :       && TYPE_DOMAIN (type) == NULL_TREE
    6054        19965 :       && TREE_CODE (decl) != TYPE_DECL
    6055    157477036 :       && !(TREE_PUBLIC (decl) && current_scope != file_scope))
    6056              :     {
    6057        19680 :       bool do_default
    6058        19680 :         = !TREE_STATIC (decl) && !DECL_EXTERNAL (decl);
    6059        19680 :       int failure
    6060        19680 :         = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
    6061              :                                do_default);
    6062              : 
    6063              :       /* Get the completed type made by complete_array_type.  */
    6064        19680 :       type = TREE_TYPE (decl);
    6065              : 
    6066        19680 :       switch (failure)
    6067              :         {
    6068            0 :         case 1:
    6069            0 :           error ("initializer fails to determine size of %q+D", decl);
    6070            0 :           break;
    6071              : 
    6072         7371 :         case 2:
    6073         7371 :           if (do_default)
    6074            1 :             error ("array size missing in %q+D", decl);
    6075         7370 :           else if (!TREE_PUBLIC (decl))
    6076           37 :             pedwarn_c23 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    6077              :                          "array size missing in %q+D", decl);
    6078              :           break;
    6079              : 
    6080            3 :         case 3:
    6081            3 :           error ("zero or negative size array %q+D", decl);
    6082            3 :           break;
    6083              : 
    6084        12306 :         case 0:
    6085              :           /* For global variables, update the copy of the type that
    6086              :              exists in the binding.  */
    6087        12306 :           if (TREE_PUBLIC (decl))
    6088              :             {
    6089         3830 :               struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
    6090         7660 :               while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    6091         3830 :                 b_ext = b_ext->shadowed;
    6092         3830 :               if (b_ext && TREE_CODE (decl) == TREE_CODE (b_ext->decl))
    6093              :                 {
    6094         3830 :                   if (b_ext->u.type && comptypes (b_ext->u.type, type))
    6095          176 :                     b_ext->u.type = composite_type (b_ext->u.type, type);
    6096              :                   else
    6097         3654 :                     b_ext->u.type = type;
    6098              :                 }
    6099              :             }
    6100              :           break;
    6101              : 
    6102            0 :         default:
    6103            0 :           gcc_unreachable ();
    6104              :         }
    6105              : 
    6106        19680 :       if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
    6107        11437 :         TREE_TYPE (DECL_INITIAL (decl)) = type;
    6108              : 
    6109        19680 :       relayout_decl (decl);
    6110              :     }
    6111              : 
    6112              :   /* Look for braced array initializers for character arrays and
    6113              :      recursively convert them into STRING_CSTs.  */
    6114    157457169 :   if (tree init = DECL_INITIAL (decl))
    6115    131125767 :     DECL_INITIAL (decl) = braced_lists_to_strings (type, init);
    6116              : 
    6117    157457169 :   if (VAR_P (decl))
    6118              :     {
    6119      8929908 :       if (init && TREE_CODE (init) == CONSTRUCTOR)
    6120       105847 :         add_flexible_array_elts_to_size (decl, init);
    6121              : 
    6122      8929908 :       complete_flexible_array_elts (DECL_INITIAL (decl));
    6123              : 
    6124      8929908 :       if (is_global_var (decl))
    6125              :         {
    6126      1235591 :           type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    6127      1235591 :                                        ? TCTX_THREAD_STORAGE
    6128              :                                        : TCTX_STATIC_STORAGE);
    6129      1235591 :           if (!verify_type_context (input_location, context, TREE_TYPE (decl)))
    6130            0 :             TREE_TYPE (decl) = error_mark_node;
    6131              :         }
    6132              : 
    6133      8938021 :       if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node
    6134      8937918 :           && COMPLETE_TYPE_P (TREE_TYPE (decl)))
    6135          107 :         layout_decl (decl, 0);
    6136              : 
    6137      8929908 :       if (DECL_SIZE (decl) == NULL_TREE
    6138              :           /* Don't give an error if we already gave one earlier.  */
    6139         8006 :           && TREE_TYPE (decl) != error_mark_node
    6140      8937811 :           && (TREE_STATIC (decl)
    6141              :               /* A static variable with an incomplete type
    6142              :                  is an error if it is initialized.
    6143              :                  Also if it is not file scope.
    6144              :                  Also if it is thread-local (in C23).
    6145              :                  Otherwise, let it through, but if it is not `extern'
    6146              :                  then it may cause an error message later.  */
    6147          309 :               ? (DECL_INITIAL (decl) != NULL_TREE
    6148          309 :                  || !DECL_FILE_SCOPE_P (decl)
    6149          306 :                  || (flag_isoc23 && DECL_THREAD_LOCAL_P (decl)))
    6150              :               /* An automatic variable with an incomplete type
    6151              :                  is an error.  */
    6152         7594 :               : !DECL_EXTERNAL (decl)))
    6153              :          {
    6154           19 :            error ("storage size of %q+D isn%'t known", decl);
    6155           19 :            TREE_TYPE (decl) = error_mark_node;
    6156              :          }
    6157              : 
    6158     17674948 :       if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    6159      8660681 :           || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    6160       282833 :           && DECL_SIZE (decl) == NULL_TREE
    6161      8930196 :           && TREE_STATIC (decl))
    6162          135 :         incomplete_record_decls.safe_push (decl);
    6163              : 
    6164      8929908 :       if (is_global_var (decl)
    6165      1235591 :           && DECL_SIZE (decl) != NULL_TREE
    6166     10157536 :           && TREE_TYPE (decl) != error_mark_node)
    6167              :         {
    6168      1227608 :           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    6169      1227605 :             constant_expression_warning (DECL_SIZE (decl));
    6170              :           else
    6171              :             {
    6172            3 :               error ("storage size of %q+D isn%'t constant", decl);
    6173            3 :               TREE_TYPE (decl) = error_mark_node;
    6174              :             }
    6175              :         }
    6176              : 
    6177      8929908 :       if (TREE_USED (type))
    6178              :         {
    6179            4 :           TREE_USED (decl) = 1;
    6180            4 :           DECL_READ_P (decl) = 1;
    6181              :         }
    6182              :     }
    6183              : 
    6184              :   /* If this is a function and an assembler name is specified, reset DECL_RTL
    6185              :      so we can give it its new name.  Also, update builtin_decl if it
    6186              :      was a normal built-in.  */
    6187    157457169 :   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
    6188              :     {
    6189       860329 :       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
    6190        72706 :         set_builtin_user_assembler_name (decl, asmspec);
    6191       860329 :       set_user_assembler_name (decl, asmspec);
    6192              :     }
    6193              : 
    6194              :   /* If #pragma weak was used, mark the decl weak now.  */
    6195    157457169 :   maybe_apply_pragma_weak (decl);
    6196              : 
    6197              :   /* Output the assembler code and/or RTL code for variables and functions,
    6198              :      unless the type is an undefined structure or union.
    6199              :      If not, it will get done when the type is completed.  */
    6200              : 
    6201    157457169 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    6202              :     {
    6203              :       /* Determine the ELF visibility.  */
    6204     24025379 :       if (TREE_PUBLIC (decl))
    6205     16224147 :         c_determine_visibility (decl);
    6206              : 
    6207              :       /* This is a no-op in c-lang.cc or something real in objc-act.cc.  */
    6208     24025379 :       if (c_dialect_objc ())
    6209            0 :         objc_check_decl (decl);
    6210              : 
    6211     24025379 :       if (asmspec)
    6212              :         {
    6213              :           /* If this is not a static variable, issue a warning.
    6214              :              It doesn't make any sense to give an ASMSPEC for an
    6215              :              ordinary, non-register local variable.  Historically,
    6216              :              GCC has accepted -- but ignored -- the ASMSPEC in
    6217              :              this case.  */
    6218       874560 :           if (!DECL_FILE_SCOPE_P (decl)
    6219         1041 :               && VAR_P (decl)
    6220         1041 :               && !C_DECL_REGISTER (decl)
    6221       873527 :               && !TREE_STATIC (decl))
    6222            1 :             warning (0, "ignoring %<asm%> specifier for non-static local "
    6223              :                      "variable %q+D", decl);
    6224              :           else
    6225       873518 :             set_user_assembler_name (decl, asmspec);
    6226              :         }
    6227              : 
    6228     24025379 :       if (DECL_FILE_SCOPE_P (decl))
    6229              :         {
    6230     16249210 :           if (DECL_INITIAL (decl) == NULL_TREE
    6231     16249210 :               || DECL_INITIAL (decl) == error_mark_node)
    6232              :             /* Don't output anything
    6233              :                when a tentative file-scope definition is seen.
    6234              :                But at end of compilation, do output code for them.  */
    6235     16092260 :             DECL_DEFER_OUTPUT (decl) = 1;
    6236     16249210 :           if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl))
    6237           68 :             DECL_HARD_REGISTER (decl) = 1;
    6238     16249210 :           rest_of_decl_compilation (decl, true, 0);
    6239              : 
    6240     16249210 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6241              :             {
    6242     15095404 :               tree parms = DECL_ARGUMENTS (decl);
    6243     15095404 :               const bool builtin = fndecl_built_in_p (decl);
    6244     15095404 :               if (tree access = build_attr_access_from_parms (parms, !builtin))
    6245       348085 :                 decl_attributes (&decl, access, 0);
    6246              :             }
    6247              :         }
    6248              :       else
    6249              :         {
    6250              :           /* In conjunction with an ASMSPEC, the `register'
    6251              :              keyword indicates that we should place the variable
    6252              :              in a particular register.  */
    6253      7776169 :           if (asmspec && C_DECL_REGISTER (decl))
    6254              :             {
    6255         1033 :               DECL_HARD_REGISTER (decl) = 1;
    6256              :               /* This cannot be done for a structure with volatile
    6257              :                  fields, on which DECL_REGISTER will have been
    6258              :                  reset.  */
    6259         1033 :               if (!DECL_REGISTER (decl))
    6260            1 :                 error ("cannot put object with volatile field into register");
    6261              :             }
    6262              : 
    6263      7776169 :           if (TREE_CODE (decl) != FUNCTION_DECL)
    6264              :             {
    6265              :               /* If we're building a variable sized type, and we might be
    6266              :                  reachable other than via the top of the current binding
    6267              :                  level, then create a new BIND_EXPR so that we deallocate
    6268              :                  the object at the right time.  */
    6269              :               /* Note that DECL_SIZE can be null due to errors.  */
    6270      7776102 :               if (DECL_SIZE (decl)
    6271      7776056 :                   && !TREE_CONSTANT (DECL_SIZE (decl))
    6272      7783485 :                   && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    6273              :                 {
    6274         1337 :                   tree bind;
    6275         1337 :                   bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    6276         1337 :                   TREE_SIDE_EFFECTS (bind) = 1;
    6277         1337 :                   add_stmt (bind);
    6278         1337 :                   BIND_EXPR_BODY (bind) = push_stmt_list ();
    6279              :                 }
    6280      7776102 :               add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
    6281              :                                     DECL_EXPR, decl));
    6282              :             }
    6283              :         }
    6284              : 
    6285              : 
    6286     24025379 :       if (!DECL_FILE_SCOPE_P (decl))
    6287              :         {
    6288              :           /* Recompute the RTL of a local array now
    6289              :              if it used to be an incomplete type.  */
    6290      7776169 :           if (was_incomplete && !is_global_var (decl))
    6291              :             {
    6292              :               /* If we used it already as memory, it must stay in memory.  */
    6293         5397 :               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    6294              :               /* If it's still incomplete now, no init will save it.  */
    6295         5397 :               if (DECL_SIZE (decl) == NULL_TREE)
    6296          109 :                 DECL_INITIAL (decl) = NULL_TREE;
    6297              :             }
    6298              :         }
    6299              :     }
    6300              : 
    6301    157457169 :   if (TREE_CODE (decl) == TYPE_DECL)
    6302              :     {
    6303      4468265 :       if (!DECL_FILE_SCOPE_P (decl)
    6304      4468265 :           && c_type_variably_modified_p (TREE_TYPE (decl)))
    6305         5321 :         add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6306              : 
    6307      8551903 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
    6308              :     }
    6309              : 
    6310              :   /* Install a cleanup (aka destructor) if one was given.  */
    6311    157457169 :   if (VAR_P (decl) && !TREE_STATIC (decl))
    6312              :     {
    6313      7865229 :       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
    6314      7865229 :       if (attr)
    6315              :         {
    6316          131 :           tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
    6317          131 :           tree cleanup_decl = lookup_name (cleanup_id);
    6318          131 :           tree cleanup;
    6319          131 :           vec<tree, va_gc> *v;
    6320              : 
    6321              :           /* Build "cleanup(&decl)" for the destructor.  */
    6322          131 :           cleanup = build_unary_op (input_location, ADDR_EXPR, decl, false);
    6323          131 :           vec_alloc (v, 1);
    6324          131 :           v->quick_push (cleanup);
    6325          131 :           cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
    6326          131 :                                                vNULL, cleanup_decl, v, NULL);
    6327          131 :           vec_free (v);
    6328              : 
    6329              :           /* Don't warn about decl unused; the cleanup uses it.  */
    6330          131 :           TREE_USED (decl) = 1;
    6331          131 :           TREE_USED (cleanup_decl) = 1;
    6332          131 :           DECL_READ_P (decl) = 1;
    6333              : 
    6334          131 :           push_cleanup (decl, cleanup, false);
    6335              :         }
    6336              :     }
    6337              : 
    6338    157457169 :   if (warn_cxx_compat
    6339        22517 :       && VAR_P (decl)
    6340         7557 :       && !DECL_EXTERNAL (decl)
    6341    157464283 :       && DECL_INITIAL (decl) == NULL_TREE)
    6342              :     {
    6343         2341 :       type = strip_array_types (type);
    6344         2341 :       if (TREE_READONLY (decl))
    6345            6 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    6346              :                     "uninitialized %<const %D%> is invalid in C++", decl);
    6347         2335 :       else if (RECORD_OR_UNION_TYPE_P (type)
    6348         2335 :                && C_TYPE_FIELDS_READONLY (type))
    6349            5 :         diagnose_uninitialized_cst_member (decl, type);
    6350              :     }
    6351              : 
    6352    157457169 :   if (flag_openmp
    6353       469690 :       && VAR_P (decl)
    6354    157481270 :       && lookup_attribute ("omp declare target implicit",
    6355        24101 :                            DECL_ATTRIBUTES (decl)))
    6356              :     {
    6357           13 :       DECL_ATTRIBUTES (decl)
    6358           13 :         = remove_attribute ("omp declare target implicit",
    6359           13 :                             DECL_ATTRIBUTES (decl));
    6360           13 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    6361            9 :         error ("%q+D in declare target directive does not have mappable type",
    6362              :                decl);
    6363            4 :       else if (!lookup_attribute ("omp declare target",
    6364            4 :                                   DECL_ATTRIBUTES (decl))
    6365            8 :                && !lookup_attribute ("omp declare target link",
    6366            4 :                                      DECL_ATTRIBUTES (decl)))
    6367              :         {
    6368            4 :           DECL_ATTRIBUTES (decl)
    6369            4 :             = tree_cons (get_identifier ("omp declare target"),
    6370            4 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    6371            4 :             symtab_node *node = symtab_node::get (decl);
    6372            4 :             if (node != NULL)
    6373              :               {
    6374            4 :                 node->offloadable = 1;
    6375            4 :                 if (ENABLE_OFFLOADING)
    6376              :                   {
    6377              :                     g->have_offload = true;
    6378              :                     if (is_a <varpool_node *> (node))
    6379              :                       vec_safe_push (offload_vars, decl);
    6380              :                   }
    6381              :               }
    6382              :         }
    6383              :     }
    6384              : 
    6385              :   /* This is the last point we can lower alignment so give the target the
    6386              :      chance to do so.  */
    6387    157457169 :   if (VAR_P (decl)
    6388      8929908 :       && !is_global_var (decl)
    6389    165151486 :       && !DECL_HARD_REGISTER (decl))
    6390      7693284 :     targetm.lower_local_decl_alignment (decl);
    6391              : 
    6392    157457169 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    6393    157457169 : }
    6394              : 
    6395              : /* Given a parsed parameter declaration, decode it into a PARM_DECL.
    6396              :    EXPR is NULL or a pointer to an expression that needs to be
    6397              :    evaluated for the side effects of array size expressions in the
    6398              :    parameters.  */
    6399              : 
    6400              : tree
    6401            0 : grokparm (const struct c_parm *parm, tree *expr)
    6402              : {
    6403            0 :   tree attrs = parm->attrs;
    6404            0 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
    6405            0 :                               NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
    6406              : 
    6407            0 :   decl_attributes (&decl, attrs, 0);
    6408              : 
    6409            0 :   return decl;
    6410              : }
    6411              : 
    6412              : 
    6413              : 
    6414              : /* Given a parsed parameter declaration, decode it into a PARM_DECL
    6415              :    and push that on the current scope.  EXPR is a pointer to an
    6416              :    expression that needs to be evaluated for the side effects of array
    6417              :    size expressions in the parameters.  */
    6418              : 
    6419              : void
    6420    124744511 : push_parm_decl (const struct c_parm *parm, tree *expr)
    6421              : {
    6422    124744511 :   tree attrs = parm->attrs;
    6423    124744511 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
    6424    124744511 :                               &attrs, expr, NULL, DEPRECATED_NORMAL);
    6425    124744511 :   if (decl && DECL_P (decl))
    6426    124744511 :     DECL_SOURCE_LOCATION (decl) = parm->loc;
    6427              : 
    6428    124744511 :   decl_attributes (&decl, attrs, 0);
    6429              : 
    6430    124744511 :   decl = pushdecl (decl);
    6431              : 
    6432    124744511 :   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
    6433    124744511 : }
    6434              : 
    6435              : /* Mark all the parameter declarations to date as forward decls.
    6436              :    Also diagnose use of this extension.  */
    6437              : 
    6438              : void
    6439           42 : mark_forward_parm_decls (void)
    6440              : {
    6441           42 :   struct c_binding *b;
    6442              : 
    6443           42 :   if (current_scope->had_forward_parm_decls)
    6444           12 :     warning_at (input_location, OPT_Wmultiple_parameter_fwd_decl_lists,
    6445              :                 "more than one list of forward declarations of parameters");
    6446           42 :   if (pedantic && !current_scope->had_forward_parm_decls)
    6447            4 :     pedwarn (input_location, OPT_Wpedantic,
    6448              :              "ISO C forbids forward parameter declarations");
    6449              : 
    6450           42 :   current_scope->had_forward_parm_decls = true;
    6451              : 
    6452           95 :   for (b = current_scope->bindings; b; b = b->prev)
    6453           53 :     if (TREE_CODE (b->decl) == PARM_DECL)
    6454           53 :       TREE_ASM_WRITTEN (b->decl) = 1;
    6455           42 : }
    6456              : 
    6457              : /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
    6458              :    literal, which may be an incomplete array type completed by the
    6459              :    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
    6460              :    literal.  NON_CONST is true if the initializers contain something
    6461              :    that cannot occur in a constant expression.  If ALIGNAS_ALIGN is nonzero,
    6462              :    it is the (valid) alignment for this compound literal, as specified
    6463              :    with _Alignas.  SCSPECS are the storage class specifiers (C23) from the
    6464              :    compound literal.  */
    6465              : 
    6466              : tree
    6467       919751 : build_compound_literal (location_t loc, tree type, tree init, bool non_const,
    6468              :                         unsigned int alignas_align,
    6469              :                         struct c_declspecs *scspecs)
    6470              : {
    6471              :   /* We do not use start_decl here because we have a type, not a declarator;
    6472              :      and do not use finish_decl because the decl should be stored inside
    6473              :      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
    6474       919751 :   tree decl;
    6475       919751 :   tree complit;
    6476       919751 :   tree stmt;
    6477       919751 :   bool threadp = scspecs ? scspecs->thread_p : false;
    6478          307 :   enum c_storage_class storage_class = (scspecs
    6479              :                                         ? scspecs->storage_class
    6480              :                                         : csc_none);
    6481              : 
    6482       919751 :   if (type == error_mark_node
    6483       919744 :       || init == error_mark_node)
    6484              :     return error_mark_node;
    6485              : 
    6486       919691 :   if (current_scope == file_scope && storage_class == csc_register)
    6487              :     {
    6488            1 :       error_at (loc, "file-scope compound literal specifies %<register%>");
    6489            1 :       storage_class = csc_none;
    6490              :     }
    6491              : 
    6492       919691 :   if (current_scope != file_scope && threadp && storage_class == csc_none)
    6493              :     {
    6494            6 :       error_at (loc, "compound literal implicitly auto and declared %qs",
    6495            3 :                 scspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    6496            3 :       threadp = false;
    6497              :     }
    6498              : 
    6499       919691 :   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
    6500       919691 :   DECL_EXTERNAL (decl) = 0;
    6501       919691 :   TREE_PUBLIC (decl) = 0;
    6502      1839382 :   TREE_STATIC (decl) = (current_scope == file_scope
    6503       919691 :                         || storage_class == csc_static);
    6504       919691 :   DECL_CONTEXT (decl) = current_function_decl;
    6505       919691 :   TREE_USED (decl) = 1;
    6506       919691 :   DECL_READ_P (decl) = 1;
    6507       919691 :   DECL_ARTIFICIAL (decl) = 1;
    6508       919691 :   DECL_IGNORED_P (decl) = 1;
    6509       919691 :   C_DECL_COMPOUND_LITERAL_P (decl) = 1;
    6510      1839151 :   C_DECL_DECLARED_CONSTEXPR (decl) = scspecs && scspecs->constexpr_p;
    6511       919691 :   TREE_TYPE (decl) = type;
    6512       919691 :   if (threadp)
    6513           16 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    6514       919691 :   if (storage_class == csc_register)
    6515              :     {
    6516           25 :       C_DECL_REGISTER (decl) = 1;
    6517           25 :       DECL_REGISTER (decl) = 1;
    6518              :     }
    6519       919691 :   c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl);
    6520       919691 :   if (alignas_align)
    6521              :     {
    6522            3 :       SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    6523            3 :       DECL_USER_ALIGN (decl) = 1;
    6524              :     }
    6525       919691 :   store_init_value (loc, decl, init, NULL_TREE);
    6526       919691 :   if (current_scope != file_scope
    6527       919440 :       && TREE_STATIC (decl)
    6528           28 :       && !TREE_READONLY (decl)
    6529           17 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    6530       919697 :       && DECL_EXTERNAL (current_function_decl))
    6531            4 :     record_inline_static (input_location, current_function_decl,
    6532              :                           decl, csi_modifiable);
    6533              : 
    6534       919691 :   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
    6535              :     {
    6536          267 :       int failure = complete_array_type (&TREE_TYPE (decl),
    6537          267 :                                          DECL_INITIAL (decl), true);
    6538              :       /* If complete_array_type returns 3, it means that the initial value of
    6539              :          the compound literal is empty.  Allow it with a pedwarn; in pre-C23
    6540              :          modes, the empty initializer itself has been diagnosed if pedantic so
    6541              :          does not need to be diagnosed again here.  */
    6542          267 :       gcc_assert (failure == 0 || failure == 3);
    6543          267 :       if (failure == 3 && flag_isoc23)
    6544            1 :         pedwarn (loc, OPT_Wpedantic,
    6545              :                  "array of unknown size with empty initializer");
    6546              : 
    6547          267 :       type = TREE_TYPE (decl);
    6548          267 :       TREE_TYPE (DECL_INITIAL (decl)) = type;
    6549          267 :       relayout_decl (decl);
    6550              :     }
    6551              : 
    6552       919691 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    6553              :     {
    6554           19 :       c_incomplete_type_error (loc, NULL_TREE, type);
    6555           19 :       return error_mark_node;
    6556              :     }
    6557              : 
    6558       919393 :   if ((TREE_STATIC (decl) || C_DECL_DECLARED_CONSTEXPR (decl))
    6559       919893 :       && C_TYPE_VARIABLE_SIZE (type))
    6560            2 :     error_at (loc, "storage size isn%'t constant");
    6561              : 
    6562       919672 :   if (TREE_STATIC (decl)
    6563       919672 :       && !verify_type_context (loc, TCTX_STATIC_STORAGE, type))
    6564            0 :     return error_mark_node;
    6565              : 
    6566       919672 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
    6567       919672 :   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
    6568       919672 :   TREE_SIDE_EFFECTS (complit) = 1;
    6569              : 
    6570       919672 :   layout_decl (decl, 0);
    6571              : 
    6572       919672 :   if (TREE_STATIC (decl))
    6573              :     {
    6574              :       /* This decl needs a name for the assembler output.  */
    6575          279 :       set_compound_literal_name (decl);
    6576          279 :       DECL_DEFER_OUTPUT (decl) = 1;
    6577          279 :       DECL_COMDAT (decl) = 1;
    6578          279 :       pushdecl (decl);
    6579          279 :       rest_of_decl_compilation (decl, 1, 0);
    6580              :     }
    6581       919393 :   else if (current_function_decl && !current_scope->parm_flag)
    6582       919384 :     pushdecl (decl);
    6583              : 
    6584       919672 :   if (non_const)
    6585              :     {
    6586          221 :       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
    6587          221 :       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
    6588              :     }
    6589              : 
    6590              :   return complit;
    6591              : }
    6592              : 
    6593              : /* Check the type of a compound literal.  Here we just check that it
    6594              :    is valid for C++.  */
    6595              : 
    6596              : void
    6597       919748 : check_compound_literal_type (location_t loc, struct c_type_name *type_name)
    6598              : {
    6599       919748 :   if (warn_cxx_compat
    6600          167 :       && (type_name->specs->typespec_kind == ctsk_tagdef
    6601          166 :           || type_name->specs->typespec_kind == ctsk_tagfirstref
    6602          165 :           || type_name->specs->typespec_kind == ctsk_tagfirstref_attrs))
    6603            2 :     warning_at (loc, OPT_Wc___compat,
    6604              :                 "defining a type in a compound literal is invalid in C++");
    6605       919748 : }
    6606              : 
    6607              : /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
    6608              :    replacing with appropriate values if they are invalid.  */
    6609              : 
    6610              : static void
    6611        52797 : check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
    6612              :                                tree orig_name)
    6613              : {
    6614        52797 :   tree type_mv;
    6615        52797 :   unsigned int max_width;
    6616        52797 :   unsigned HOST_WIDE_INT w;
    6617        52797 :   const char *name = (orig_name
    6618        95831 :                       ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
    6619         9763 :                       : _("<anonymous>"));
    6620              : 
    6621              :   /* Detect and ignore out of range field width and process valid
    6622              :      field widths.  */
    6623        52797 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
    6624              :     {
    6625            8 :       error_at (loc, "bit-field %qs width not an integer constant", name);
    6626            8 :       *width = integer_one_node;
    6627              :     }
    6628              :   else
    6629              :     {
    6630        52789 :       if (TREE_CODE (*width) != INTEGER_CST)
    6631              :         {
    6632           12 :           *width = c_fully_fold (*width, false, NULL);
    6633           12 :           if (TREE_CODE (*width) == INTEGER_CST)
    6634            6 :             pedwarn (loc, OPT_Wpedantic,
    6635              :                      "bit-field %qs width not an integer constant expression",
    6636              :                      name);
    6637              :         }
    6638        52789 :       if (TREE_CODE (*width) != INTEGER_CST)
    6639              :         {
    6640            6 :           error_at (loc, "bit-field %qs width not an integer constant", name);
    6641            6 :           *width = integer_one_node;
    6642              :         }
    6643        52789 :       constant_expression_warning (*width);
    6644        52789 :       if (tree_int_cst_sgn (*width) < 0)
    6645              :         {
    6646            2 :           error_at (loc, "negative width in bit-field %qs", name);
    6647            2 :           *width = integer_one_node;
    6648              :         }
    6649        52787 :       else if (integer_zerop (*width) && orig_name)
    6650              :         {
    6651            4 :           error_at (loc, "zero width for bit-field %qs", name);
    6652            4 :           *width = integer_one_node;
    6653              :         }
    6654              :     }
    6655              : 
    6656              :   /* Detect invalid bit-field type.  */
    6657        52797 :   if (TREE_CODE (*type) != INTEGER_TYPE
    6658              :       && TREE_CODE (*type) != BOOLEAN_TYPE
    6659              :       && TREE_CODE (*type) != ENUMERAL_TYPE
    6660        52797 :       && TREE_CODE (*type) != BITINT_TYPE)
    6661              :     {
    6662            8 :       error_at (loc, "bit-field %qs has invalid type", name);
    6663            8 :       *type = unsigned_type_node;
    6664              :     }
    6665              : 
    6666        52797 :   if (TYPE_WARN_IF_NOT_ALIGN (*type))
    6667              :     {
    6668            1 :       error_at (loc, "cannot declare bit-field %qs with %<warn_if_not_aligned%> type",
    6669              :                 name);
    6670            1 :       *type = unsigned_type_node;
    6671              :     }
    6672              : 
    6673        52797 :   type_mv = TYPE_MAIN_VARIANT (*type);
    6674        52797 :   if (!in_system_header_at (input_location)
    6675        29367 :       && type_mv != integer_type_node
    6676        26628 :       && type_mv != unsigned_type_node
    6677        65413 :       && type_mv != boolean_type_node)
    6678        12033 :     pedwarn_c90 (loc, OPT_Wpedantic,
    6679              :                  "type of bit-field %qs is a GCC extension", name);
    6680              : 
    6681        52797 :   max_width = TYPE_PRECISION (*type);
    6682              : 
    6683        52797 :   if (compare_tree_int (*width, max_width) > 0)
    6684              :     {
    6685            4 :       error_at (loc, "width of %qs exceeds its type", name);
    6686            4 :       w = max_width;
    6687            4 :       *width = build_int_cst (integer_type_node, w);
    6688              :     }
    6689              :   else
    6690        52793 :     w = tree_to_uhwi (*width);
    6691              : 
    6692              :   /* Truncation of hardbool false and true representation values is always safe:
    6693              :      either the values remain different, or we'll report a problem when creating
    6694              :      the narrower type.  */
    6695        52797 :   if (c_hardbool_type_attr (*type))
    6696        52797 :     return;
    6697              : 
    6698        52516 :   if (TREE_CODE (*type) == ENUMERAL_TYPE)
    6699              :     {
    6700         4140 :       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
    6701         4140 :       if (!lt
    6702         4130 :           || w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
    6703         8266 :           || w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
    6704           15 :         warning_at (loc, 0, "%qs is narrower than values of its type", name);
    6705              :     }
    6706              : }
    6707              : 
    6708              : 
    6709              : 
    6710              : /* Print warning about variable length array if necessary.  */
    6711              : 
    6712              : static void
    6713        22493 : warn_variable_length_array (tree name, tree size)
    6714              : {
    6715        22493 :   if (TREE_CONSTANT (size))
    6716              :     {
    6717          181 :       if (name)
    6718          168 :         pedwarn_c90 (input_location, OPT_Wvla,
    6719              :                      "ISO C90 forbids array %qE whose size "
    6720              :                      "cannot be evaluated", name);
    6721              :       else
    6722           13 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
    6723              :                      "whose size cannot be evaluated");
    6724              :     }
    6725              :   else
    6726              :     {
    6727        22312 :       if (name)
    6728        13828 :         pedwarn_c90 (input_location, OPT_Wvla,
    6729              :                      "ISO C90 forbids variable length array %qE", name);
    6730              :       else
    6731         8484 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
    6732              :                      "length array");
    6733              :     }
    6734        22493 : }
    6735              : 
    6736              : /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
    6737              :    considering only those c_declspec_words found in LIST, which
    6738              :    must be terminated by cdw_number_of_elements.  */
    6739              : 
    6740              : static location_t
    6741          419 : smallest_type_quals_location (const location_t *locations,
    6742              :                               const c_declspec_word *list)
    6743              : {
    6744          419 :   location_t loc = UNKNOWN_LOCATION;
    6745         2514 :   while (*list != cdw_number_of_elements)
    6746              :     {
    6747         2095 :       location_t newloc = locations[*list];
    6748         2095 :       if (loc == UNKNOWN_LOCATION
    6749         1024 :           || (newloc != UNKNOWN_LOCATION && newloc < loc))
    6750         1071 :         loc = newloc;
    6751         2095 :       list++;
    6752              :     }
    6753              : 
    6754          419 :   return loc;
    6755              : }
    6756              : 
    6757              : 
    6758              : /* We attach an artificial TYPE_DECL to pointed-to type
    6759              :    and arrange for it to be included in a DECL_EXPR.  This
    6760              :    forces the sizes evaluation at a safe point and ensures it
    6761              :    is not deferred until e.g. within a deeper conditional context.
    6762              : 
    6763              :    PARM contexts have no enclosing statement list that
    6764              :    can hold the DECL_EXPR, so we need to use a BIND_EXPR
    6765              :    instead, and add it to the list of expressions that
    6766              :    need to be evaluated.
    6767              : 
    6768              :    TYPENAME contexts do have an enclosing statement list,
    6769              :    but it would be incorrect to use it, as the size should
    6770              :    only be evaluated if the containing expression is
    6771              :    evaluated.  We might also be in the middle of an
    6772              :    expression with side effects on the pointed-to type size
    6773              :    "arguments" prior to the pointer declaration point and
    6774              :    the fake TYPE_DECL in the enclosing context would force
    6775              :    the size evaluation prior to the side effects.  We therefore
    6776              :    use BIND_EXPRs in TYPENAME contexts too.  */
    6777              : static void
    6778         7040 : add_decl_expr (location_t loc, tree type, tree *expr, bool set_name_p)
    6779              : {
    6780         7040 :   tree bind = NULL_TREE;
    6781         7040 :   if (expr)
    6782              :     {
    6783         1598 :       bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, NULL_TREE,
    6784              :                      NULL_TREE);
    6785         1598 :       TREE_SIDE_EFFECTS (bind) = 1;
    6786         1598 :       BIND_EXPR_BODY (bind) = push_stmt_list ();
    6787         1598 :       push_scope ();
    6788              :     }
    6789              : 
    6790         7040 :   tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
    6791         7040 :   pushdecl (decl);
    6792         7040 :   DECL_ARTIFICIAL (decl) = 1;
    6793         7040 :   add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6794         7040 :   if (set_name_p)
    6795         6324 :     TYPE_NAME (type) = decl;
    6796              : 
    6797         7040 :   if (bind)
    6798              :     {
    6799         1598 :       pop_scope ();
    6800         1598 :       BIND_EXPR_BODY (bind) = pop_stmt_list (BIND_EXPR_BODY (bind));
    6801         1598 :       if (*expr)
    6802         1476 :         *expr = build2 (COMPOUND_EXPR, void_type_node, *expr, bind);
    6803              :       else
    6804          122 :         *expr = bind;
    6805              :     }
    6806         7040 : }
    6807              : 
    6808              : 
    6809              : /* Add attribute "arg spec" to ATTRS corresponding to an array/VLA parameter
    6810              :    declared with type TYPE.  The attribute has two arguments.  The first is
    6811              :    a string that encodes the presence of the static keyword.  The second is
    6812              :    the declared type of the array before adjustment, i.e. as an array type
    6813              :    including the outermost bound.  */
    6814              : 
    6815              : static tree
    6816       440728 : build_arg_spec_attribute (tree type, bool static_p, tree attrs)
    6817              : {
    6818       440728 :   tree vbchain = tree_cons (NULL_TREE, type, NULL_TREE);
    6819       440728 :   tree acsstr = static_p ? build_string (7, "static") :
    6820       440606 :                            build_string (1, "");
    6821       440728 :   tree args = tree_cons (NULL_TREE, acsstr, vbchain);
    6822       440728 :   tree name = get_identifier ("arg spec");
    6823       440728 :   return tree_cons (name, args, attrs);
    6824              : }
    6825              : 
    6826              : 
    6827              : /* Given declspecs and a declarator,
    6828              :    determine the name and type of the object declared
    6829              :    and construct a ..._DECL node for it.
    6830              :    (In one case we can return a ..._TYPE node instead.
    6831              :     For invalid input we sometimes return NULL_TREE.)
    6832              : 
    6833              :    DECLSPECS is a c_declspecs structure for the declaration specifiers.
    6834              : 
    6835              :    DECL_CONTEXT says which syntactic context this declaration is in:
    6836              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
    6837              :      FUNCDEF for a function definition.  Like NORMAL but a few different
    6838              :       error messages in each case.  Return value may be zero meaning
    6839              :       this definition is too screwy to try to parse.
    6840              :      PARM for a parameter declaration (either within a function prototype
    6841              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
    6842              :      TYPENAME if for a typename (in a cast or sizeof).
    6843              :       Don't make a DECL node; just return the ..._TYPE node.
    6844              :      GENERIC_ASSOC for typenames in a generic association.
    6845              :      FIELD for a struct or union field; make a FIELD_DECL.
    6846              :    INITIALIZED is true if the decl has an initializer.
    6847              :    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
    6848              :    representing the width of the bit-field.
    6849              :    DECL_ATTRS points to the list of attributes that should be added to this
    6850              :      decl.  Any nested attributes that belong on the decl itself will be
    6851              :      added to this list.
    6852              :    If EXPR is not NULL, any expressions that need to be evaluated as
    6853              :      part of evaluating variably modified types will be stored in *EXPR.
    6854              :    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
    6855              :      set to indicate whether operands in *EXPR can be used in constant
    6856              :      expressions.
    6857              :    DEPRECATED_STATE is a deprecated_states value indicating whether
    6858              :    deprecation/unavailability warnings should be suppressed.
    6859              : 
    6860              :    In the TYPENAME case, DECLARATOR is really an absolute declarator.
    6861              :    It may also be so in the PARM case, for a prototype where the
    6862              :    argument type is specified but not the name.
    6863              : 
    6864              :    This function is where the complicated C meanings of `static'
    6865              :    and `extern' are interpreted.  */
    6866              : 
    6867              : static tree
    6868    315368577 : grokdeclarator (const struct c_declarator *declarator,
    6869              :                 struct c_declspecs *declspecs,
    6870              :                 enum decl_context decl_context, bool initialized, tree *width,
    6871              :                 tree *decl_attrs, tree *expr, bool *expr_const_operands,
    6872              :                 enum deprecated_states deprecated_state)
    6873              : {
    6874    315368577 :   tree type = declspecs->type;
    6875    315368577 :   bool threadp = declspecs->thread_p;
    6876    315368577 :   bool constexprp = declspecs->constexpr_p;
    6877    315368577 :   enum c_storage_class storage_class = declspecs->storage_class;
    6878    315368577 :   int constp;
    6879    315368577 :   int restrictp;
    6880    315368577 :   int volatilep;
    6881    315368577 :   int atomicp;
    6882    315368577 :   int type_quals = TYPE_UNQUALIFIED;
    6883    315368577 :   tree name = NULL_TREE;
    6884    315368577 :   bool funcdef_flag = false;
    6885    315368577 :   bool funcdef_syntax = false;
    6886    315368577 :   bool size_varies = false;
    6887    315368577 :   bool size_error = false;
    6888    315368577 :   tree decl_attr = declspecs->decl_attr;
    6889    315368577 :   int array_ptr_quals = TYPE_UNQUALIFIED;
    6890    315368577 :   tree array_ptr_attrs = NULL_TREE;
    6891    315368577 :   bool array_parm_static = false;
    6892    315368577 :   bool array_parm_vla_unspec_p = false;
    6893    315368577 :   tree returned_attrs = NULL_TREE;
    6894    315368577 :   tree decl_id_attrs = NULL_TREE;
    6895    315368577 :   bool bitfield = width != NULL;
    6896    315368577 :   tree element_type;
    6897    315368577 :   tree orig_qual_type = NULL;
    6898    315368577 :   size_t orig_qual_indirect = 0;
    6899    315368577 :   struct c_arg_info *arg_info = 0;
    6900    315368577 :   addr_space_t as1, as2, address_space;
    6901    315368577 :   location_t loc = UNKNOWN_LOCATION;
    6902    315368577 :   tree expr_dummy;
    6903    315368577 :   bool expr_const_operands_dummy;
    6904    315368577 :   enum c_declarator_kind first_non_attr_kind;
    6905    315368577 :   unsigned int alignas_align = 0;
    6906              : 
    6907    315368577 :   if (type == NULL_TREE)
    6908              :     {
    6909              :       /* This can occur for auto on a parameter in C23 mode.  Set a
    6910              :          dummy type here so subsequent code can give diagnostics for
    6911              :          this case.  */
    6912            2 :       gcc_assert (declspecs->c23_auto_p);
    6913            2 :       gcc_assert (decl_context == PARM);
    6914            2 :       type = declspecs->type = integer_type_node;
    6915              :     }
    6916    315368577 :   if (TREE_CODE (type) == ERROR_MARK)
    6917           29 :     return error_mark_node;
    6918    315368548 :   if (expr == NULL)
    6919              :     {
    6920        38288 :       expr = &expr_dummy;
    6921        38288 :       expr_dummy = NULL_TREE;
    6922              :     }
    6923    315368548 :   if (expr_const_operands == NULL)
    6924    193845884 :     expr_const_operands = &expr_const_operands_dummy;
    6925              : 
    6926    315368548 :   if (declspecs->expr)
    6927              :     {
    6928          953 :       if (*expr)
    6929            7 :         *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
    6930              :                         declspecs->expr);
    6931              :       else
    6932          946 :         *expr = declspecs->expr;
    6933              :     }
    6934    315368548 :   *expr_const_operands = declspecs->expr_const_operands;
    6935              : 
    6936    315368548 :   if (decl_context == FUNCDEF)
    6937     36332413 :     funcdef_flag = true, decl_context = NORMAL;
    6938              : 
    6939              :   /* Look inside a declarator for the name being declared
    6940              :      and get it as an IDENTIFIER_NODE, for an error message.  */
    6941    315368548 :   {
    6942    315368548 :     const struct c_declarator *decl = declarator;
    6943              : 
    6944    315368548 :     first_non_attr_kind = cdk_attrs;
    6945    385919970 :     while (decl)
    6946    385919970 :       switch (decl->kind)
    6947              :         {
    6948      1143824 :         case cdk_array:
    6949      1143824 :           loc = decl->id_loc;
    6950              :           /* FALL THRU.  */
    6951              : 
    6952     70544633 :         case cdk_function:
    6953     70544633 :         case cdk_pointer:
    6954     70544633 :           funcdef_syntax = (decl->kind == cdk_function);
    6955     70544633 :           if (first_non_attr_kind == cdk_attrs)
    6956     68406893 :             first_non_attr_kind = decl->kind;
    6957     70544633 :           decl = decl->declarator;
    6958     70544633 :           break;
    6959              : 
    6960         6789 :         case cdk_attrs:
    6961         6789 :           decl = decl->declarator;
    6962         6789 :           break;
    6963              : 
    6964    315368548 :         case cdk_id:
    6965    315368548 :           loc = decl->id_loc;
    6966    315368548 :           if (decl->u.id.id)
    6967              :             name = decl->u.id.id;
    6968    315368548 :           decl_id_attrs = decl->u.id.attrs;
    6969    315368548 :           if (first_non_attr_kind == cdk_attrs)
    6970    246961655 :             first_non_attr_kind = decl->kind;
    6971              :           decl = 0;
    6972              :           break;
    6973              : 
    6974            0 :         default:
    6975            0 :           gcc_unreachable ();
    6976              :         }
    6977    315368548 :     if (name == NULL_TREE)
    6978              :       {
    6979    126241647 :         gcc_assert (decl_context == PARM
    6980              :                     || decl_context == TYPENAME
    6981              :                     || decl_context == GENERIC_ASSOC
    6982              :                     || (decl_context == FIELD
    6983              :                         && declarator->kind == cdk_id));
    6984    126241647 :         gcc_assert (!initialized);
    6985              :       }
    6986              :   }
    6987              : 
    6988              :   /* An enum type specifier (": specifier-qualifier-list") may only be
    6989              :      specified when the enum is being defined or in an empty
    6990              :      declaration of the form "enum identifier enum-type-specifier;".
    6991              :      Except for the case of an empty declaration that has additional
    6992              :      declaration specifiers, all invalid contexts (declarations that
    6993              :      aren't empty, type names, parameter declarations, member
    6994              :      declarations) pass through grokdeclarator.  */
    6995    315368548 :   if (declspecs->enum_type_specifier_ref_p)
    6996            6 :     error_at (loc, "%<enum%> underlying type may not be specified here");
    6997              : 
    6998              :   /* A function definition's declarator must have the form of
    6999              :      a function declarator.  */
    7000              : 
    7001    315368548 :   if (funcdef_flag && !funcdef_syntax)
    7002              :     return NULL_TREE;
    7003              : 
    7004              :   /* If this looks like a function definition, make it one,
    7005              :      even if it occurs where parms are expected.
    7006              :      Then store_parm_decls will reject it and not use it as a parm.  */
    7007    315368517 :   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
    7008        22662 :     decl_context = PARM;
    7009              : 
    7010    315368517 :   if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    7011              :     {
    7012    315368493 :       if (declspecs->unavailable_p)
    7013           28 :         error_unavailable_use (declspecs->type, declspecs->decl_attr);
    7014    315368465 :       else if (declspecs->deprecated_p
    7015           46 :                 && deprecated_state != DEPRECATED_SUPPRESS)
    7016           38 :         warn_deprecated_use (declspecs->type, declspecs->decl_attr);
    7017              :     }
    7018              : 
    7019    315368517 :   if ((decl_context == NORMAL || decl_context == FIELD)
    7020     69019199 :       && current_scope == file_scope
    7021    376312234 :       && c_type_variably_modified_p (type))
    7022              :     {
    7023            3 :       if (name)
    7024            3 :         error_at (loc, "variably modified %qE at file scope", name);
    7025              :       else
    7026            0 :         error_at (loc, "variably modified field at file scope");
    7027            3 :       type = integer_type_node;
    7028              :     }
    7029              : 
    7030    315368517 :   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
    7031              : 
    7032              :   /* Diagnose defaulting to "int".  */
    7033              : 
    7034    315368517 :   if (declspecs->default_int_p)
    7035              :     {
    7036              :       /* Issue a warning if this is an ISO C 99 program or if
    7037              :          -Wreturn-type and this is a function, or if -Wimplicit;
    7038              :          prefer the former warning since it is more explicit.  */
    7039         9764 :       if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99)
    7040         1229 :           && funcdef_flag)
    7041          702 :         warn_about_return_type = 1;
    7042              :       else
    7043              :         {
    7044         9062 :           if (name)
    7045         9052 :             permerror_opt (loc, OPT_Wimplicit_int,
    7046              :                            "type defaults to %<int%> in declaration "
    7047              :                            "of %qE", name);
    7048              :           else
    7049           10 :             permerror_opt (loc, OPT_Wimplicit_int,
    7050              :                            "type defaults to %<int%> in type name");
    7051              :         }
    7052              :     }
    7053              : 
    7054              :   /* Adjust the type if a bit-field is being declared,
    7055              :      -funsigned-bitfields applied and the type is not explicitly
    7056              :      "signed".  */
    7057    315368517 :   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
    7058           40 :       && TREE_CODE (type) == INTEGER_TYPE)
    7059           38 :     type = c_common_unsigned_type (type);
    7060              : 
    7061              :   /* Figure out the type qualifiers for the declaration.  There are
    7062              :      two ways a declaration can become qualified.  One is something
    7063              :      like `const int i' where the `const' is explicit.  Another is
    7064              :      something like `typedef const int CI; CI i' where the type of the
    7065              :      declaration contains the `const'.  A third possibility is that
    7066              :      there is a type qualifier on the element type of a typedefed
    7067              :      array type, in which case we should extract that qualifier so
    7068              :      that c_apply_type_quals_to_decl receives the full list of
    7069              :      qualifiers to work with (C90 is not entirely clear about whether
    7070              :      duplicate qualifiers should be diagnosed in this case, but it
    7071              :      seems most appropriate to do so).  */
    7072    315368517 :   element_type = strip_array_types (type);
    7073    315368517 :   constp = declspecs->const_p + TYPE_READONLY (element_type);
    7074    315368517 :   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
    7075    315368517 :   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
    7076    315368517 :   atomicp = declspecs->atomic_p + TYPE_ATOMIC (element_type);
    7077    315368517 :   as1 = declspecs->address_space;
    7078    315368517 :   as2 = TYPE_ADDR_SPACE (element_type);
    7079    315368517 :   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
    7080              : 
    7081    315368517 :   if (constp > 1)
    7082           25 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>");
    7083    315368517 :   if (restrictp > 1)
    7084            6 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>");
    7085    315368517 :   if (volatilep > 1)
    7086           15 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>");
    7087    315368517 :   if (atomicp > 1)
    7088            9 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>");
    7089              : 
    7090    315368517 :   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
    7091            0 :     error_at (loc, "conflicting named address spaces (%s vs %s)",
    7092              :               c_addr_space_name (as1), c_addr_space_name (as2));
    7093              : 
    7094    315368517 :   if ((TREE_CODE (type) == ARRAY_TYPE
    7095    315191070 :        || first_non_attr_kind == cdk_array)
    7096    316443212 :       && TYPE_QUALS (element_type))
    7097              :     {
    7098           73 :       orig_qual_type = type;
    7099           73 :       type = c_build_qualified_type (type, TYPE_UNQUALIFIED);
    7100              :     }
    7101    315368517 :   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
    7102    315368517 :                 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
    7103    315368517 :                 | (volatilep ? TYPE_QUAL_VOLATILE : 0)
    7104    315368517 :                 | (atomicp ? TYPE_QUAL_ATOMIC : 0)
    7105    315368517 :                 | ENCODE_QUAL_ADDR_SPACE (address_space));
    7106    315368517 :   if (type_quals != TYPE_QUALS (element_type))
    7107     12868027 :     orig_qual_type = NULL_TREE;
    7108              : 
    7109              :   /* Applying the _Atomic qualifier to an array type (through the use
    7110              :      of typedefs or typeof) must be detected here.  If the qualifier
    7111              :      is introduced later, any appearance of applying it to an array is
    7112              :      actually applying it to an element of that array.  */
    7113    315368517 :   if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
    7114            6 :     error_at (loc, "%<_Atomic%>-qualified array type");
    7115              : 
    7116              :   /* Warn about storage classes that are invalid for certain
    7117              :      kinds of declarations (parameters, typenames, etc.).  */
    7118              : 
    7119    315368517 :   if (funcdef_flag
    7120     36332382 :       && (threadp
    7121              :           || constexprp
    7122     36332380 :           || storage_class == csc_auto
    7123     36332380 :           || storage_class == csc_register
    7124     36332335 :           || storage_class == csc_typedef))
    7125              :     {
    7126           47 :       if (storage_class == csc_auto)
    7127           42 :         pedwarn (loc,
    7128           81 :                  (current_scope == file_scope) ? 0 : OPT_Wpedantic,
    7129              :                  "function definition declared %<auto%>");
    7130           50 :       if (storage_class == csc_register)
    7131            3 :         error_at (loc, "function definition declared %<register%>");
    7132           50 :       if (storage_class == csc_typedef)
    7133            3 :         error_at (loc, "function definition declared %<typedef%>");
    7134           50 :       if (threadp)
    7135            2 :         error_at (loc, "function definition declared %qs",
    7136            2 :                   declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7137           50 :       threadp = false;
    7138              :       /* The parser ensures a constexpr function definition never
    7139              :          reaches here.  */
    7140           50 :       gcc_assert (!constexprp);
    7141           50 :       if (storage_class == csc_auto
    7142           50 :           || storage_class == csc_register
    7143              :           || storage_class == csc_typedef)
    7144           55 :         storage_class = csc_none;
    7145              :     }
    7146    315368467 :   else if (decl_context != NORMAL && (storage_class != csc_none
    7147    250673688 :                                       || threadp
    7148    250673105 :                                       || constexprp
    7149    250673103 :                                       || declspecs->c23_auto_p))
    7150              :     {
    7151          587 :       if (decl_context == PARM
    7152          587 :           && storage_class == csc_register
    7153          568 :           && !constexprp
    7154          566 :           && !declspecs->c23_auto_p)
    7155              :         ;
    7156              :       else
    7157              :         {
    7158           21 :           switch (decl_context)
    7159              :             {
    7160            0 :             case FIELD:
    7161            0 :               if (name)
    7162            0 :                 error_at (loc, "storage class specified for structure "
    7163              :                           "field %qE", name);
    7164              :               else
    7165            0 :                 error_at (loc, "storage class specified for structure field");
    7166              :               break;
    7167           21 :             case PARM:
    7168           21 :               if (name)
    7169            7 :                 error_at (loc, "storage class specified for parameter %qE",
    7170              :                           name);
    7171              :               else
    7172           14 :                 error_at (loc, "storage class specified for unnamed parameter");
    7173              :               break;
    7174            0 :             default:
    7175            0 :               error_at (loc, "storage class specified for typename");
    7176            0 :               break;
    7177              :             }
    7178    315368517 :           storage_class = csc_none;
    7179    315368517 :           threadp = false;
    7180    315368517 :           constexprp = false;
    7181              :         }
    7182              :     }
    7183    315367880 :   else if (storage_class == csc_extern
    7184    315367880 :            && initialized
    7185     35471774 :            && !funcdef_flag)
    7186              :     {
    7187              :       /* 'extern' with initialization is invalid if not at file scope.  */
    7188           28 :        if (current_scope == file_scope)
    7189              :          {
    7190              :            /* It is fine to have 'extern const' when compiling at C
    7191              :               and C++ intersection.  */
    7192           19 :            if (!(warn_cxx_compat && constp))
    7193           18 :              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
    7194              :                          name);
    7195              :          }
    7196              :       else
    7197            9 :         error_at (loc, "%qE has both %<extern%> and initializer", name);
    7198              :     }
    7199    315367852 :   else if (current_scope == file_scope)
    7200              :     {
    7201     61820460 :       if (storage_class == csc_auto)
    7202            7 :         error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
    7203              :                   name);
    7204     61820460 :       if (pedantic && storage_class == csc_register)
    7205            4 :         pedwarn (input_location, OPT_Wpedantic,
    7206              :                  "file-scope declaration of %qE specifies %<register%>", name);
    7207              :     }
    7208              :   else
    7209              :     {
    7210    253547392 :       if (storage_class == csc_extern && funcdef_flag)
    7211            3 :         error_at (loc, "nested function %qE declared %<extern%>", name);
    7212    253547389 :       else if (threadp && storage_class == csc_none)
    7213              :         {
    7214           14 :           error_at (loc, "function-scope %qE implicitly auto and declared "
    7215              :                     "%qs", name,
    7216            7 :                     declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7217            7 :           threadp = false;
    7218              :         }
    7219              :     }
    7220              : 
    7221              :   /* Now figure out the structure of the declarator proper.
    7222              :      Descend through it, creating more complex types, until we reach
    7223              :      the declared identifier (or NULL_TREE, in an absolute declarator).
    7224              :      At each stage we maintain an unqualified version of the type
    7225              :      together with any qualifiers that should be applied to it with
    7226              :      c_build_qualified_type; this way, array types including
    7227              :      multidimensional array types are first built up in unqualified
    7228              :      form and then the qualified form is created with
    7229              :      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
    7230              : 
    7231    385919938 :   while (declarator && declarator->kind != cdk_id)
    7232              :     {
    7233     70551421 :       if (type == error_mark_node)
    7234              :         {
    7235           39 :           declarator = declarator->declarator;
    7236           39 :           continue;
    7237              :         }
    7238              : 
    7239              :       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
    7240              :          a cdk_pointer (for *...),
    7241              :          a cdk_function (for ...(...)),
    7242              :          a cdk_attrs (for nested attributes),
    7243              :          or a cdk_id (for the name being declared
    7244              :          or the place in an absolute declarator
    7245              :          where the name was omitted).
    7246              :          For the last case, we have just exited the loop.
    7247              : 
    7248              :          At this point, TYPE is the type of elements of an array,
    7249              :          or for a function to return, or for a pointer to point to.
    7250              :          After this sequence of ifs, TYPE is the type of the
    7251              :          array or function or pointer, and DECLARATOR has had its
    7252              :          outermost layer removed.  */
    7253              : 
    7254     70551382 :       if (array_ptr_quals != TYPE_UNQUALIFIED
    7255     70551382 :           || array_ptr_attrs != NULL_TREE
    7256     70551382 :           || array_parm_static)
    7257              :         {
    7258              :           /* Only the innermost declarator (making a parameter be of
    7259              :              array type which is converted to pointer type)
    7260              :              may have static or type qualifiers.  */
    7261            1 :           error_at (loc, "static or type qualifiers in non-parameter array declarator");
    7262            1 :           array_ptr_quals = TYPE_UNQUALIFIED;
    7263            1 :           array_ptr_attrs = NULL_TREE;
    7264            1 :           array_parm_static = false;
    7265              :         }
    7266              : 
    7267     70551382 :       switch (declarator->kind)
    7268              :         {
    7269         6789 :         case cdk_attrs:
    7270         6789 :           {
    7271              :             /* A declarator with embedded attributes.  */
    7272         6789 :             tree attrs = declarator->u.attrs;
    7273         6789 :             const struct c_declarator *inner_decl;
    7274         6789 :             int attr_flags = 0;
    7275         6789 :             declarator = declarator->declarator;
    7276              :             /* Standard attribute syntax precisely defines what entity
    7277              :                an attribute in each position appertains to, so only
    7278              :                apply laxity about positioning to GNU attribute syntax.
    7279              :                Standard attributes applied to a function or array
    7280              :                declarator apply exactly to that type; standard
    7281              :                attributes applied to the identifier apply to the
    7282              :                declaration rather than to the type, and are specified
    7283              :                using a cdk_id declarator rather than using
    7284              :                cdk_attrs.  */
    7285         6789 :             inner_decl = declarator;
    7286         6789 :             while (inner_decl->kind == cdk_attrs)
    7287            0 :               inner_decl = inner_decl->declarator;
    7288         6789 :             if (!cxx11_attribute_p (attrs))
    7289              :               {
    7290         6691 :                 if (inner_decl->kind == cdk_id)
    7291              :                   attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
    7292              :                 else if (inner_decl->kind == cdk_function)
    7293              :                   attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
    7294              :                 else if (inner_decl->kind == cdk_array)
    7295         6789 :                   attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
    7296              :               }
    7297         6789 :             attrs = c_warn_type_attributes (type, attrs);
    7298         6789 :             returned_attrs = decl_attributes (&type,
    7299              :                                               chainon (returned_attrs, attrs),
    7300              :                                               attr_flags);
    7301         6789 :             break;
    7302              :           }
    7303      1143814 :         case cdk_array:
    7304      1143814 :           {
    7305      1143814 :             tree itype = NULL_TREE;
    7306      1143814 :             tree size = declarator->u.array.dimen;
    7307              :             /* The index is a signed object `sizetype' bits wide.  */
    7308      1143814 :             tree index_type = c_common_signed_type (sizetype);
    7309              : 
    7310      1143814 :             array_ptr_quals = declarator->u.array.quals;
    7311      1143814 :             array_ptr_attrs = declarator->u.array.attrs;
    7312      1143814 :             array_parm_static = declarator->u.array.static_p;
    7313      1143814 :             array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
    7314              : 
    7315      1143814 :             declarator = declarator->declarator;
    7316              : 
    7317              :             /* Check for some types that there cannot be arrays of.  */
    7318              : 
    7319      1143814 :             if (VOID_TYPE_P (type))
    7320              :               {
    7321           11 :                 if (name)
    7322            9 :                   error_at (loc, "declaration of %qE as array of voids", name);
    7323              :                 else
    7324            2 :                   error_at (loc, "declaration of type name as array of voids");
    7325           11 :                 type = error_mark_node;
    7326              :               }
    7327              : 
    7328      1143814 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7329              :               {
    7330            3 :                 if (name)
    7331            2 :                   error_at (loc, "declaration of %qE as array of functions",
    7332              :                             name);
    7333              :                 else
    7334            1 :                   error_at (loc, "declaration of type name as array of "
    7335              :                             "functions");
    7336            3 :                 type = error_mark_node;
    7337              :               }
    7338              : 
    7339        21330 :             if (pedantic && !in_system_header_at (input_location)
    7340      1158855 :                 && flexible_array_type_p (type))
    7341           20 :               pedwarn (loc, OPT_Wpedantic,
    7342              :                        "invalid use of structure with flexible array member");
    7343              : 
    7344      1143814 :             if (size == error_mark_node)
    7345          119 :               type = error_mark_node;
    7346              : 
    7347      1143814 :             if (type == error_mark_node)
    7348          133 :               continue;
    7349              : 
    7350      1143681 :             if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, type))
    7351              :               {
    7352            0 :                 type = error_mark_node;
    7353            0 :                 continue;
    7354              :               }
    7355              : 
    7356              :             /* If size was specified, set ITYPE to a range-type for
    7357              :                that size.  Otherwise, ITYPE remains null.  finish_decl
    7358              :                may figure it out from an initial value.  */
    7359              : 
    7360      1143681 :             if (size)
    7361              :               {
    7362       971609 :                 bool size_maybe_const = true;
    7363       971609 :                 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
    7364       971609 :                                        && !TREE_OVERFLOW (size));
    7365       971609 :                 bool this_size_varies = false;
    7366              : 
    7367              :                 /* Strip NON_LVALUE_EXPRs since we aren't using as an
    7368              :                    lvalue.  */
    7369       971618 :                 STRIP_TYPE_NOPS (size);
    7370              : 
    7371       971609 :                 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
    7372              :                   {
    7373           16 :                     if (name)
    7374           14 :                       error_at (loc, "size of array %qE has non-integer type",
    7375              :                                 name);
    7376              :                     else
    7377            2 :                       error_at (loc,
    7378              :                                 "size of unnamed array has non-integer type");
    7379           16 :                     size = integer_one_node;
    7380           16 :                     size_int_const = true;
    7381           16 :                     size_error = true;
    7382              :                   }
    7383              :                 /* This can happen with enum forward declaration.  */
    7384       971593 :                 else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
    7385              :                   {
    7386            0 :                     if (name)
    7387            0 :                       error_at (loc, "size of array %qE has incomplete type",
    7388              :                                 name);
    7389              :                     else
    7390            0 :                       error_at (loc, "size of unnamed array has incomplete "
    7391              :                                 "type");
    7392            0 :                     size = integer_one_node;
    7393            0 :                     size_int_const = true;
    7394            0 :                     size_error = true;
    7395              :                   }
    7396              : 
    7397       971609 :                 size = c_fully_fold (size, false, &size_maybe_const);
    7398              : 
    7399       971609 :                 if (pedantic && size_maybe_const && integer_zerop (size))
    7400              :                   {
    7401            3 :                     if (name)
    7402            3 :                       pedwarn (loc, OPT_Wpedantic,
    7403              :                                "ISO C forbids zero-size array %qE", name);
    7404              :                     else
    7405            0 :                       pedwarn (loc, OPT_Wpedantic,
    7406              :                                "ISO C forbids zero-size array");
    7407              :                   }
    7408              : 
    7409       971609 :                 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
    7410              :                   {
    7411       949250 :                     constant_expression_warning (size);
    7412       949250 :                     if (tree_int_cst_sgn (size) < 0)
    7413              :                       {
    7414          784 :                         if (name)
    7415          781 :                           error_at (loc, "size of array %qE is negative", name);
    7416              :                         else
    7417            3 :                           error_at (loc, "size of unnamed array is negative");
    7418          784 :                         size = integer_one_node;
    7419          784 :                         size_int_const = true;
    7420          784 :                         size_error = true;
    7421              :                       }
    7422              :                     /* Handle a size folded to an integer constant but
    7423              :                        not an integer constant expression.  */
    7424       949250 :                     if (!size_int_const)
    7425              :                       {
    7426              :                         /* If this is a file scope declaration of an
    7427              :                            ordinary identifier, this is invalid code;
    7428              :                            diagnosing it here and not subsequently
    7429              :                            treating the type as variable-length avoids
    7430              :                            more confusing diagnostics later.  */
    7431          155 :                         if ((decl_context == NORMAL || decl_context == FIELD)
    7432          142 :                             && current_scope == file_scope)
    7433           14 :                           pedwarn (input_location, 0,
    7434              :                                    "variably modified %qE at file scope",
    7435              :                                    name);
    7436              :                         else
    7437              :                           this_size_varies = size_varies = true;
    7438          155 :                         warn_variable_length_array (name, size);
    7439              :                       }
    7440              :                   }
    7441        22359 :                 else if ((decl_context == NORMAL || decl_context == FIELD)
    7442        13257 :                          && current_scope == file_scope)
    7443              :                   {
    7444           21 :                     error_at (loc, "variably modified %qE at file scope", name);
    7445           21 :                     size = integer_one_node;
    7446              :                   }
    7447              :                 else
    7448              :                   {
    7449              :                     /* Make sure the array size remains visibly
    7450              :                        nonconstant even if it is (eg) a const variable
    7451              :                        with known value.  */
    7452        22338 :                     this_size_varies = size_varies = true;
    7453        22338 :                     warn_variable_length_array (name, size);
    7454        22338 :                     if (sanitize_flags_p (SANITIZE_VLA)
    7455          181 :                         && current_function_decl != NULL_TREE
    7456        22501 :                         && decl_context == NORMAL)
    7457              :                       {
    7458              :                         /* Evaluate the array size only once.  */
    7459          155 :                         size = save_expr (size);
    7460          155 :                         size = c_fully_fold (size, false, NULL);
    7461          155 :                         size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7462              :                                             ubsan_instrument_vla (loc, size),
    7463              :                                             size);
    7464              :                       }
    7465              :                   }
    7466              : 
    7467       971609 :                 if (integer_zerop (size) && !this_size_varies)
    7468              :                   {
    7469              :                     /* A zero-length array cannot be represented with
    7470              :                        an unsigned index type, which is what we'll
    7471              :                        get with build_index_type.  Create an
    7472              :                        open-ended range instead.  */
    7473         2609 :                     itype = build_index_type (NULL_TREE);
    7474              :                   }
    7475              :                 else
    7476              :                   {
    7477              :                     /* Arrange for the SAVE_EXPR on the inside of the
    7478              :                        MINUS_EXPR, which allows the -1 to get folded
    7479              :                        with the +1 that happens when building TYPE_SIZE.  */
    7480       969000 :                     if (size_varies)
    7481        22854 :                       size = save_expr (size);
    7482       969000 :                     if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
    7483          141 :                       size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7484              :                                      integer_zero_node, size);
    7485              : 
    7486              :                     /* Compute the maximum valid index, that is, size
    7487              :                        - 1.  Do the calculation in index_type, so that
    7488              :                        if it is a variable the computations will be
    7489              :                        done in the proper mode.  */
    7490       969000 :                     itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
    7491              :                                              convert (index_type, size),
    7492              :                                              convert (index_type,
    7493              :                                                       size_one_node));
    7494              : 
    7495              :                     /* The above overflows when size does not fit
    7496              :                        in index_type.
    7497              :                        ???  While a size of INT_MAX+1 technically shouldn't
    7498              :                        cause an overflow (because we subtract 1), handling
    7499              :                        this case seems like an unnecessary complication.  */
    7500       969000 :                     if (TREE_CODE (size) == INTEGER_CST
    7501       946521 :                         && !int_fits_type_p (size, index_type))
    7502              :                       {
    7503            6 :                         if (name)
    7504            5 :                           error_at (loc, "size of array %qE is too large",
    7505              :                                     name);
    7506              :                         else
    7507            1 :                           error_at (loc, "size of unnamed array is too large");
    7508            6 :                         type = error_mark_node;
    7509            6 :                         continue;
    7510              :                       }
    7511              : 
    7512       968994 :                     itype = build_index_type (itype);
    7513              :                   }
    7514       971603 :                 if (this_size_varies)
    7515              :                   {
    7516        22479 :                     if (TREE_SIDE_EFFECTS (size))
    7517              :                       {
    7518        22116 :                         if (*expr)
    7519         8178 :                           *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7520              :                                           *expr, size);
    7521              :                         else
    7522        13938 :                           *expr = size;
    7523              :                       }
    7524        22479 :                     *expr_const_operands &= size_maybe_const;
    7525              :                   }
    7526              :               }
    7527       172072 :             else if (decl_context == FIELD)
    7528              :               {
    7529        86029 :                 bool flexible_array_member = false;
    7530        86029 :                 if (array_parm_vla_unspec_p)
    7531              :                   /* Field names can in fact have function prototype
    7532              :                      scope so [*] is disallowed here through making
    7533              :                      the field variably modified, not through being
    7534              :                      something other than a declaration with function
    7535              :                      prototype scope.  */
    7536              :                   size_varies = true;
    7537              :                 else
    7538              :                   {
    7539              :                     const struct c_declarator *t = declarator;
    7540        86026 :                     while (t->kind == cdk_attrs)
    7541            0 :                       t = t->declarator;
    7542        86026 :                     flexible_array_member = (t->kind == cdk_id);
    7543              :                   }
    7544        86026 :                 if (flexible_array_member
    7545        86026 :                     && !in_system_header_at (input_location))
    7546        84995 :                   pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    7547              :                                "support flexible array members");
    7548              : 
    7549              :                 /* ISO C99 Flexible array members are effectively
    7550              :                    identical to GCC's zero-length array extension.  */
    7551        86029 :                 if (flexible_array_member)
    7552        86006 :                   itype = build_index_type (NULL_TREE);
    7553              :               }
    7554              : 
    7555              :             /* Complain about arrays of incomplete types.  */
    7556      1143675 :             if (!COMPLETE_TYPE_P (type))
    7557              :               {
    7558           58 :                 auto_diagnostic_group d;
    7559           58 :                 error_at (loc, "array type has incomplete element type %qT",
    7560              :                           type);
    7561              :                 /* See if we can be more helpful.  */
    7562           58 :                 if (TREE_CODE (type) == ARRAY_TYPE)
    7563              :                   {
    7564           29 :                     if (name)
    7565           24 :                       inform (loc, "declaration of %qE as multidimensional "
    7566              :                               "array must have bounds for all dimensions "
    7567              :                               "except the first", name);
    7568              :                     else
    7569            5 :                       inform (loc, "declaration of multidimensional array "
    7570              :                               "must have bounds for all dimensions except "
    7571              :                               "the first");
    7572              :                   }
    7573           58 :                 type = error_mark_node;
    7574           58 :               }
    7575              :             else
    7576              :             /* When itype is NULL, a shared incomplete array type is
    7577              :                returned for all array of a given type.  Elsewhere we
    7578              :                make sure we don't complete that type before copying
    7579              :                it, but here we want to make sure we don't ever
    7580              :                modify the shared type, so we gcc_assert (itype)
    7581              :                below.  */
    7582              :               {
    7583      1143617 :                 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
    7584      1143617 :                 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
    7585            0 :                   type = c_build_qualified_type (type,
    7586              :                                                  ENCODE_QUAL_ADDR_SPACE (as));
    7587      1143617 :                 if (array_parm_vla_unspec_p)
    7588          151 :                   type = c_build_array_type_unspecified (type);
    7589              :                 else
    7590      1143466 :                   type = c_build_array_type (type, itype);
    7591              :               }
    7592              : 
    7593      1143675 :             if (array_parm_vla_unspec_p)
    7594              :               {
    7595              :                 /* C99 6.7.5.2p4 */
    7596          151 :                 if (decl_context == TYPENAME)
    7597            6 :                   warning (0, "%<[*]%> not in a declaration");
    7598          145 :                 else if (decl_context != GENERIC_ASSOC
    7599          145 :                          && decl_context != PARM
    7600            7 :                          && decl_context != FIELD)
    7601              :                   {
    7602            4 :                     error ("%<[*]%> not allowed in other than function prototype scope "
    7603              :                            "or generic association");
    7604            4 :                     type = error_mark_node;
    7605              :                   }
    7606              :                 size_varies = true;
    7607              :               }
    7608              : 
    7609      1143675 :             if (type != error_mark_node)
    7610              :               {
    7611              :                 /* The GCC extension for zero-length arrays differs from
    7612              :                    ISO flexible array members in that sizeof yields
    7613              :                    zero.  */
    7614      1143613 :                 if (size && integer_zerop (size))
    7615              :                   {
    7616         2602 :                     gcc_assert (itype);
    7617         2602 :                     type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7618         2602 :                     TYPE_SIZE (type) = bitsize_zero_node;
    7619         2602 :                     TYPE_SIZE_UNIT (type) = size_zero_node;
    7620         2602 :                     SET_TYPE_STRUCTURAL_EQUALITY (type);
    7621              :                   }
    7622              : 
    7623      1143613 :                 if (!valid_array_size_p (loc, type, name))
    7624           33 :                   type = error_mark_node;
    7625              :               }
    7626              : 
    7627      1143675 :             if (decl_context != PARM
    7628       822444 :                 && (array_ptr_quals != TYPE_UNQUALIFIED
    7629       822444 :                     || array_ptr_attrs != NULL_TREE
    7630       822443 :                     || array_parm_static))
    7631              :               {
    7632            2 :                 error_at (loc, "static or type qualifiers in non-parameter "
    7633              :                           "array declarator");
    7634            2 :                 array_ptr_quals = TYPE_UNQUALIFIED;
    7635            2 :                 array_ptr_attrs = NULL_TREE;
    7636            2 :                 array_parm_static = false;
    7637              :               }
    7638      1143675 :             orig_qual_indirect++;
    7639      1143675 :             break;
    7640              :           }
    7641     51014234 :         case cdk_function:
    7642     51014234 :           {
    7643              :             /* Say it's a definition only for the declarator closest
    7644              :                to the identifier, apart possibly from some
    7645              :                attributes.  */
    7646     51014234 :             bool really_funcdef = false;
    7647     51014234 :             tree arg_types;
    7648     51014234 :             orig_qual_type = NULL_TREE;
    7649     51014234 :             if (funcdef_flag)
    7650              :               {
    7651     36332405 :                 const struct c_declarator *t = declarator->declarator;
    7652     36332423 :                 while (t->kind == cdk_attrs)
    7653           18 :                   t = t->declarator;
    7654     36332405 :                 really_funcdef = (t->kind == cdk_id);
    7655              :               }
    7656              : 
    7657              :             /* Declaring a function type.  Make sure we have a valid
    7658              :                type for the function to return.  */
    7659     51014234 :             if (type == error_mark_node)
    7660            0 :               continue;
    7661              : 
    7662     51014234 :             size_varies = false;
    7663              : 
    7664              :             /* Warn about some types functions can't return.  */
    7665     51014234 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7666              :               {
    7667            0 :                 if (name)
    7668            0 :                   error_at (loc, "%qE declared as function returning a "
    7669              :                                  "function", name);
    7670              :                 else
    7671            0 :                   error_at (loc, "type name declared as function "
    7672              :                             "returning a function");
    7673            0 :                 type = integer_type_node;
    7674              :               }
    7675     51014234 :             if (TREE_CODE (type) == ARRAY_TYPE)
    7676              :               {
    7677            0 :                 if (name)
    7678            0 :                   error_at (loc, "%qE declared as function returning an array",
    7679              :                             name);
    7680              :                 else
    7681            0 :                   error_at (loc, "type name declared as function returning "
    7682              :                             "an array");
    7683            0 :                 type = integer_type_node;
    7684              :               }
    7685              : 
    7686              :             /* Construct the function type and go to the next
    7687              :                inner layer of declarator.  */
    7688     51014234 :             arg_info = declarator->u.arg_info;
    7689     51014234 :             arg_types = grokparms (arg_info, really_funcdef);
    7690              : 
    7691              :             /* Type qualifiers before the return type of the function
    7692              :                qualify the return type, not the function type.  */
    7693     51014234 :             if (type_quals)
    7694              :               {
    7695          419 :                 const enum c_declspec_word ignored_quals_list[] =
    7696              :                   {
    7697              :                     cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
    7698              :                     cdw_atomic, cdw_number_of_elements
    7699              :                   };
    7700          419 :                 location_t specs_loc
    7701          419 :                   = smallest_type_quals_location (declspecs->locations,
    7702              :                                                   ignored_quals_list);
    7703          419 :                 if (specs_loc == UNKNOWN_LOCATION)
    7704          139 :                   specs_loc = declspecs->locations[cdw_typedef];
    7705          139 :                 if (specs_loc == UNKNOWN_LOCATION)
    7706           15 :                   specs_loc = loc;
    7707              : 
    7708              :                 /* Type qualifiers on a function return type are
    7709              :                    normally permitted by the standard but have no
    7710              :                    effect, so give a warning at -Wreturn-type.
    7711              :                    Qualifiers on a void return type are banned on
    7712              :                    function definitions in ISO C; GCC used to used
    7713              :                    them for noreturn functions.  The resolution of C11
    7714              :                    DR#423 means qualifiers (other than _Atomic) are
    7715              :                    actually removed from the return type when
    7716              :                    determining the function type.  For C23, _Atomic is
    7717              :                    removed as well.  */
    7718          419 :                 int quals_used = type_quals;
    7719          419 :                 if (flag_isoc23)
    7720              :                   quals_used = 0;
    7721           65 :                 else if (flag_isoc11)
    7722           31 :                   quals_used &= TYPE_QUAL_ATOMIC;
    7723           65 :                 if (quals_used && VOID_TYPE_P (type) && really_funcdef)
    7724            5 :                   pedwarn (specs_loc, 0,
    7725              :                            "function definition has qualified void "
    7726              :                            "return type");
    7727              :                 else
    7728          414 :                   warning_at (specs_loc, OPT_Wignored_qualifiers,
    7729              :                               "type qualifiers ignored on function "
    7730              :                               "return type");
    7731              : 
    7732              :                 /* Ensure an error for restrict on invalid types; the
    7733              :                    DR#423 resolution is not entirely clear about
    7734              :                    this.  */
    7735          419 :                 if (flag_isoc11
    7736          385 :                     && (type_quals & TYPE_QUAL_RESTRICT)
    7737          425 :                     && (!POINTER_TYPE_P (type)
    7738            4 :                         || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
    7739            4 :                   error_at (loc, "invalid use of %<restrict%>");
    7740          419 :                 type = c_build_qualified_type (type, quals_used);
    7741              :               }
    7742     51014234 :             type_quals = TYPE_UNQUALIFIED;
    7743              : 
    7744    102028468 :             type = c_build_function_type (type, arg_types,
    7745     51014234 :                                           arg_info->no_named_args_stdarg_p);
    7746     51014234 :             declarator = declarator->declarator;
    7747              : 
    7748              :             /* Set the TYPE_CONTEXTs for each tagged type which is local to
    7749              :                the formal parameter list of this FUNCTION_TYPE to point to
    7750              :                the FUNCTION_TYPE node itself.  */
    7751     51014234 :             {
    7752     51014234 :               c_arg_tag *tag;
    7753     51014234 :               unsigned ix;
    7754              : 
    7755    436934451 :               FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
    7756          142 :                 TYPE_CONTEXT (tag->type) = type;
    7757              :             }
    7758              :             break;
    7759              :           }
    7760     18386545 :         case cdk_pointer:
    7761     18386545 :           {
    7762              :             /* Merge any constancy or volatility into the target type
    7763              :                for the pointer.  */
    7764     18386545 :             if ((type_quals & TYPE_QUAL_ATOMIC)
    7765         1988 :                 && TREE_CODE (type) == FUNCTION_TYPE)
    7766              :               {
    7767            2 :                 error_at (loc,
    7768              :                           "%<_Atomic%>-qualified function type");
    7769            2 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    7770              :               }
    7771     18386543 :             else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7772         1708 :                      && type_quals)
    7773            0 :               pedwarn (loc, OPT_Wpedantic,
    7774              :                        "ISO C forbids qualified function types");
    7775     18384837 :             if (type_quals)
    7776      6055403 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7777              :                                              orig_qual_indirect);
    7778     18386545 :             orig_qual_type = NULL_TREE;
    7779     18386545 :             size_varies = false;
    7780              : 
    7781              :             /* When the pointed-to type involves components of variable size,
    7782              :                care must be taken to ensure that the size evaluation code is
    7783              :                emitted early enough to dominate all the possible later uses
    7784              :                and late enough for the variables on which it depends to have
    7785              :                been assigned.
    7786              : 
    7787              :                This is expected to happen automatically when the pointed-to
    7788              :                type has a name/declaration of it's own, but special attention
    7789              :                is required if the type is anonymous. */
    7790     18386545 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    7791              :               {
    7792         5949 :                 bool bind_p = decl_context == TYPENAME
    7793              :                               || decl_context == FIELD
    7794         5949 :                               || decl_context == PARM;
    7795        11391 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    7796              :               }
    7797              : 
    7798     18386545 :             type = c_build_pointer_type (type);
    7799              : 
    7800              :             /* Process type qualifiers (such as const or volatile)
    7801              :                that were given inside the `*'.  */
    7802     18386545 :             type_quals = declarator->u.pointer_quals;
    7803              : 
    7804     18386545 :             declarator = declarator->declarator;
    7805     18386545 :             break;
    7806              :           }
    7807            0 :         default:
    7808            0 :           gcc_unreachable ();
    7809              :         }
    7810              :     }
    7811    315368517 :   *decl_attrs = chainon (returned_attrs, *decl_attrs);
    7812    315368517 :   *decl_attrs = chainon (decl_id_attrs, *decl_attrs);
    7813              : 
    7814              :   /* Now TYPE has the actual type, apart from any qualifiers in
    7815              :      TYPE_QUALS.  */
    7816              : 
    7817              :   /* Warn about address space used for things other than static memory or
    7818              :      pointers.  */
    7819    315368517 :   address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
    7820    315368517 :   if (!ADDR_SPACE_GENERIC_P (address_space))
    7821              :     {
    7822           10 :       if (decl_context == NORMAL)
    7823              :         {
    7824           10 :           switch (storage_class)
    7825              :             {
    7826            0 :             case csc_auto:
    7827            0 :               error ("%qs combined with %<auto%> qualifier for %qE",
    7828              :                      c_addr_space_name (address_space), name);
    7829            0 :               break;
    7830            0 :             case csc_register:
    7831            0 :               error ("%qs combined with %<register%> qualifier for %qE",
    7832              :                      c_addr_space_name (address_space), name);
    7833            0 :               break;
    7834            6 :             case csc_none:
    7835            6 :               if (current_function_scope)
    7836              :                 {
    7837            0 :                   error ("%qs specified for auto variable %qE",
    7838              :                          c_addr_space_name (address_space), name);
    7839            0 :                   break;
    7840              :                 }
    7841              :               break;
    7842              :             case csc_static:
    7843              :             case csc_extern:
    7844              :             case csc_typedef:
    7845              :               break;
    7846            0 :             default:
    7847            0 :               gcc_unreachable ();
    7848              :             }
    7849              :         }
    7850            0 :       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
    7851              :         {
    7852            0 :           if (name)
    7853            0 :             error ("%qs specified for parameter %qE",
    7854              :                    c_addr_space_name (address_space), name);
    7855              :           else
    7856            0 :             error ("%qs specified for unnamed parameter",
    7857              :                    c_addr_space_name (address_space));
    7858              :         }
    7859            0 :       else if (decl_context == FIELD)
    7860              :         {
    7861            0 :           if (name)
    7862            0 :             error ("%qs specified for structure field %qE",
    7863              :                    c_addr_space_name (address_space), name);
    7864              :           else
    7865            0 :             error ("%qs specified for structure field",
    7866              :                    c_addr_space_name (address_space));
    7867              :         }
    7868              :     }
    7869              : 
    7870              :   /* Check the type and width of a bit-field.  */
    7871    315368517 :   if (bitfield)
    7872              :     {
    7873        52797 :       check_bitfield_type_and_width (loc, &type, width, name);
    7874              :       /* C11 makes it implementation-defined (6.7.2.1#5) whether
    7875              :          atomic types are permitted for bit-fields; we have no code to
    7876              :          make bit-field accesses atomic, so disallow them.  */
    7877        52797 :       if (type_quals & TYPE_QUAL_ATOMIC)
    7878              :         {
    7879            2 :           if (name)
    7880            1 :             error_at (loc, "bit-field %qE has atomic type", name);
    7881              :           else
    7882            1 :             error_at (loc, "bit-field has atomic type");
    7883            2 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7884              :         }
    7885              :     }
    7886              : 
    7887              :   /* Reject invalid uses of _Alignas.  */
    7888    315368517 :   if (declspecs->alignas_p)
    7889              :     {
    7890          190 :       if (storage_class == csc_typedef)
    7891            1 :         error_at (loc, "alignment specified for typedef %qE", name);
    7892          189 :       else if (storage_class == csc_register)
    7893            1 :         error_at (loc, "alignment specified for %<register%> object %qE",
    7894              :                   name);
    7895          188 :       else if (decl_context == PARM)
    7896              :         {
    7897            2 :           if (name)
    7898            1 :             error_at (loc, "alignment specified for parameter %qE", name);
    7899              :           else
    7900            1 :             error_at (loc, "alignment specified for unnamed parameter");
    7901              :         }
    7902          186 :       else if (bitfield)
    7903              :         {
    7904            0 :           if (name)
    7905            0 :             error_at (loc, "alignment specified for bit-field %qE", name);
    7906              :           else
    7907            0 :             error_at (loc, "alignment specified for unnamed bit-field");
    7908              :         }
    7909          186 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
    7910            1 :         error_at (loc, "alignment specified for function %qE", name);
    7911          185 :       else if (declspecs->align_log != -1 && TYPE_P (type))
    7912              :         {
    7913          158 :           alignas_align = 1U << declspecs->align_log;
    7914          158 :           if (alignas_align < min_align_of_type (type))
    7915              :             {
    7916           26 :               if (name)
    7917           25 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7918              :                           "alignment of %qE", name);
    7919              :               else
    7920            1 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7921              :                           "alignment of unnamed field");
    7922              :               alignas_align = 0;
    7923              :             }
    7924              :         }
    7925              :     }
    7926              : 
    7927              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
    7928              : 
    7929    315368517 :   if (storage_class == csc_typedef)
    7930              :     {
    7931      4340056 :       tree decl;
    7932      4340056 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7933        12630 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7934              :         {
    7935            0 :           error_at (loc,
    7936              :                     "%<_Atomic%>-qualified function type");
    7937            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7938              :         }
    7939      4340056 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7940          537 :                && type_quals)
    7941            0 :         pedwarn (loc, OPT_Wpedantic,
    7942              :                  "ISO C forbids qualified function types");
    7943      4339519 :       if (type_quals)
    7944        31769 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7945              :                                        orig_qual_indirect);
    7946      8680112 :       decl = build_decl (declarator->id_loc,
    7947      4340056 :                          TYPE_DECL, declarator->u.id.id, type);
    7948      4340056 :       if (declspecs->explicit_signed_p)
    7949       353424 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
    7950      4340056 :       if (declspecs->inline_p)
    7951            4 :         pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
    7952      4340056 :       if (declspecs->noreturn_p)
    7953            1 :         pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
    7954              : 
    7955      4340056 :       if (warn_cxx_compat && declarator->u.id.id != NULL_TREE)
    7956              :         {
    7957         1828 :           struct c_binding *b = I_TAG_BINDING (declarator->u.id.id);
    7958              : 
    7959         1828 :           if (b != NULL
    7960           40 :               && b->decl != NULL_TREE
    7961           40 :               && (B_IN_CURRENT_SCOPE (b)
    7962            4 :                   || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    7963         1864 :               && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
    7964              :             {
    7965            7 :               auto_diagnostic_group d;
    7966            8 :               if (warning_at (declarator->id_loc, OPT_Wc___compat,
    7967              :                               "using %qD as both a typedef and a tag is "
    7968              :                               "invalid in C++", decl)
    7969            7 :                   && b->locus != UNKNOWN_LOCATION)
    7970            6 :                 inform (b->locus, "originally defined here");
    7971            7 :             }
    7972              :         }
    7973              : 
    7974      4340056 :       return decl;
    7975              :     }
    7976              : 
    7977              :   /* If this is a type name (such as, in a cast or sizeof),
    7978              :      compute the type and return it now.  */
    7979              : 
    7980    311028461 :   if (decl_context == TYPENAME || decl_context == GENERIC_ASSOC)
    7981              :     {
    7982              :       /* Note that the grammar rejects storage classes in typenames
    7983              :          and fields.  */
    7984    121582145 :       gcc_assert (storage_class == csc_none && !threadp
    7985              :                   && !declspecs->inline_p && !declspecs->noreturn_p);
    7986    121582145 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7987          257 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7988              :         {
    7989            0 :           error_at (loc,
    7990              :                     "%<_Atomic%>-qualified function type");
    7991            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7992              :         }
    7993    121582145 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7994           22 :                && type_quals)
    7995            0 :         pedwarn (loc, OPT_Wpedantic,
    7996              :                  "ISO C forbids const or volatile function types");
    7997    121582123 :       if (type_quals)
    7998          893 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7999              :                                        orig_qual_indirect);
    8000    121582145 :       return type;
    8001              :     }
    8002              : 
    8003       364109 :   if (pedantic && decl_context == FIELD
    8004    189468914 :       && c_type_variably_modified_p (type))
    8005              :     {
    8006              :       /* C99 6.7.2.1p8 */
    8007            7 :       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
    8008              :                "have a variably modified type");
    8009              :     }
    8010              : 
    8011              :   /* Aside from typedefs and type names (handle above),
    8012              :      `void' at top level (not within pointer)
    8013              :      is allowed only in public variables.
    8014              :      We don't complain about parms either, but that is because
    8015              :      a better error message can be made later.  */
    8016              : 
    8017    189446316 :   if (VOID_TYPE_P (type) && decl_context != PARM
    8018           64 :       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
    8019              :             && (storage_class == csc_extern
    8020           27 :                 || (current_scope == file_scope
    8021           18 :                     && !(storage_class == csc_static
    8022              :                          || storage_class == csc_register)))))
    8023              :     {
    8024           15 :       error_at (loc, "variable or field %qE declared void", name);
    8025           15 :       type = integer_type_node;
    8026              :     }
    8027              : 
    8028              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
    8029              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
    8030              : 
    8031    188466799 :   {
    8032    188466799 :     tree decl;
    8033              : 
    8034    188466799 :     if (decl_context == PARM)
    8035              :       {
    8036    124767173 :         tree promoted_type;
    8037    124767173 :         bool array_parameter_p = false;
    8038              : 
    8039              :         /* A parameter declared as an array of T is really a pointer to T.
    8040              :            One declared as a function is really a pointer to a function.  */
    8041              : 
    8042    124767173 :         if (TREE_CODE (type) == ARRAY_TYPE)
    8043              :           {
    8044       440742 :             if (!size_error)
    8045       440728 :               *decl_attrs = build_arg_spec_attribute (type, array_parm_static,
    8046              :                                                       *decl_attrs);
    8047              : 
    8048              :             /* Transfer const-ness of array into that of type pointed to.  */
    8049       440742 :             type = TREE_TYPE (type);
    8050       440742 :             if (orig_qual_type != NULL_TREE)
    8051              :               {
    8052            7 :                 if (orig_qual_indirect == 0)
    8053            5 :                   orig_qual_type = TREE_TYPE (orig_qual_type);
    8054              :                 else
    8055            2 :                   orig_qual_indirect--;
    8056              :               }
    8057       440742 :             if (type_quals)
    8058        48492 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8059              :                                              orig_qual_indirect);
    8060              : 
    8061              :             /* The pointed-to type may need a decl expr (see above).  */
    8062       440742 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    8063              :               {
    8064          375 :                 bool bind_p = decl_context == TYPENAME
    8065              :                               || decl_context == FIELD
    8066              :                               || decl_context == PARM;
    8067          375 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    8068              :               }
    8069              : 
    8070       440742 :             type = c_build_pointer_type (type);
    8071       440742 :             type_quals = array_ptr_quals;
    8072       440742 :             if (type_quals)
    8073          965 :               type = c_build_qualified_type (type, type_quals);
    8074              : 
    8075              :             /* We don't yet implement attributes in this context.  */
    8076       440742 :             if (array_ptr_attrs != NULL_TREE)
    8077            0 :               warning_at (loc, OPT_Wattributes,
    8078              :                           "attributes in parameter array declarator ignored");
    8079              : 
    8080              :             size_varies = false;
    8081              :             array_parameter_p = true;
    8082              :           }
    8083    124326431 :         else if (TREE_CODE (type) == FUNCTION_TYPE)
    8084              :           {
    8085          301 :             if (type_quals & TYPE_QUAL_ATOMIC)
    8086              :               {
    8087            1 :                 error_at (loc,
    8088              :                           "%<_Atomic%>-qualified function type");
    8089            1 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    8090              :               }
    8091          300 :             else if (type_quals)
    8092            0 :               pedwarn (loc, OPT_Wpedantic,
    8093              :                        "ISO C forbids qualified function types");
    8094            1 :             if (type_quals)
    8095            0 :               type = c_build_qualified_type (type, type_quals);
    8096          301 :             type = c_build_pointer_type (type);
    8097          301 :             type_quals = TYPE_UNQUALIFIED;
    8098              :           }
    8099    124326130 :         else if (type_quals)
    8100      9973537 :           type = c_build_qualified_type (type, type_quals);
    8101              : 
    8102    249534346 :         decl = build_decl (declarator->id_loc,
    8103    124767173 :                            PARM_DECL, declarator->u.id.id, type);
    8104    124767173 :         if (size_varies)
    8105           42 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8106    124767173 :         C_ARRAY_PARAMETER (decl) = array_parameter_p;
    8107              : 
    8108              :         /* Compute the type actually passed in the parmlist,
    8109              :            for the case where there is no prototype.
    8110              :            (For example, shorts and chars are passed as ints.)
    8111              :            When there is a prototype, this is overridden later.  */
    8112              : 
    8113    124767173 :         if (type == error_mark_node)
    8114              :           promoted_type = type;
    8115              :         else
    8116    124767089 :           promoted_type = c_type_promotes_to (type);
    8117              : 
    8118    124767173 :         DECL_ARG_TYPE (decl) = promoted_type;
    8119    124767173 :         if (declspecs->inline_p)
    8120            4 :           pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
    8121    124767173 :         if (declspecs->noreturn_p)
    8122            1 :           pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
    8123              :       }
    8124     64679143 :     else if (decl_context == FIELD)
    8125              :       {
    8126              :         /* Note that the grammar rejects storage classes in typenames
    8127              :            and fields.  */
    8128      4324370 :         gcc_assert (storage_class == csc_none && !threadp
    8129              :                     && !declspecs->inline_p && !declspecs->noreturn_p);
    8130              : 
    8131              :         /* Structure field.  It may not be a function.  */
    8132              : 
    8133      4324370 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8134              :           {
    8135            0 :             error_at (loc, "field %qE declared as a function", name);
    8136            0 :             type = c_build_pointer_type (type);
    8137              :           }
    8138      4324370 :         else if (TREE_CODE (type) != ERROR_MARK
    8139      4324370 :                  && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
    8140              :           {
    8141           24 :             if (name)
    8142           17 :               error_at (loc, "field %qE has incomplete type", name);
    8143              :             else
    8144            7 :               error_at (loc, "unnamed field has incomplete type");
    8145           24 :             type = error_mark_node;
    8146              :           }
    8147      4324346 :         else if (TREE_CODE (type) == ARRAY_TYPE
    8148      4324346 :                  && TYPE_DOMAIN (type) == NULL_TREE)
    8149              :           {
    8150              :             /* We have a flexible array member through a typedef.
    8151              :                Set suitable range.  Whether this is a correct position
    8152              :                for a flexible array member will be determined elsewhere.  */
    8153           14 :             if (!in_system_header_at (input_location))
    8154           14 :               pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    8155              :                            "support flexible array members");
    8156           14 :             type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    8157           14 :             TYPE_DOMAIN (type) = build_index_type (NULL_TREE);
    8158           14 :             if (orig_qual_indirect == 0)
    8159      4324370 :               orig_qual_type = NULL_TREE;
    8160              :           }
    8161      4324370 :         if (type != error_mark_node
    8162      4324370 :             && !verify_type_context (loc, TCTX_FIELD, type))
    8163            0 :           type = error_mark_node;
    8164              : 
    8165      4324370 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8166              :                                        orig_qual_indirect);
    8167      8648740 :         decl = build_decl (declarator->id_loc,
    8168      4324370 :                            FIELD_DECL, declarator->u.id.id, type);
    8169      4324370 :         DECL_NONADDRESSABLE_P (decl) = bitfield;
    8170      4324370 :         if (bitfield && !declarator->u.id.id)
    8171         9763 :           DECL_PADDING_P (decl) = 1;
    8172              : 
    8173      4324370 :         if (size_varies)
    8174          669 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8175              :       }
    8176     60354773 :     else if (TREE_CODE (type) == FUNCTION_TYPE)
    8177              :       {
    8178     51427859 :         if (storage_class == csc_register || threadp || constexprp)
    8179              :           {
    8180           12 :             error_at (loc, "invalid storage class for function %qE", name);
    8181              :           }
    8182     51427847 :         else if (current_scope != file_scope)
    8183              :           {
    8184              :             /* Function declaration not at file scope.  Storage
    8185              :                classes other than `extern' are not allowed, C99
    8186              :                6.7.1p5, and `extern' makes no difference.  However,
    8187              :                GCC allows 'auto', perhaps with 'inline', to support
    8188              :                nested functions.  */
    8189        10563 :             if (storage_class == csc_auto)
    8190           66 :                 pedwarn (loc, OPT_Wpedantic,
    8191              :                          "invalid storage class for function %qE", name);
    8192        10497 :             else if (storage_class == csc_static)
    8193              :               {
    8194           20 :                 error_at (loc, "invalid storage class for function %qE", name);
    8195           20 :                 if (funcdef_flag)
    8196            8 :                   storage_class = declspecs->storage_class = csc_none;
    8197              :                 else
    8198              :                   return NULL_TREE;
    8199              :               }
    8200              :           }
    8201              : 
    8202    102855694 :         decl = build_decl (declarator->id_loc,
    8203     51427847 :                            FUNCTION_DECL, declarator->u.id.id, type);
    8204     51427847 :         decl = build_decl_attribute_variant (decl, decl_attr);
    8205              : 
    8206     51427847 :         if (type_quals & TYPE_QUAL_ATOMIC)
    8207              :           {
    8208            2 :             error_at (loc,
    8209              :                       "%<_Atomic%>-qualified function type");
    8210            2 :             type_quals &= ~TYPE_QUAL_ATOMIC;
    8211              :           }
    8212     51427845 :         else if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
    8213            9 :           pedwarn (loc, OPT_Wpedantic,
    8214              :                    "ISO C forbids qualified function types");
    8215              : 
    8216              :         /* Every function declaration is an external reference
    8217              :            (DECL_EXTERNAL) except for those which are not at file
    8218              :            scope and are explicitly declared "auto".  This is
    8219              :            forbidden by standard C (C99 6.7.1p5) and is interpreted by
    8220              :            GCC to signify a forward declaration of a nested function.  */
    8221     51427847 :         if (storage_class == csc_auto && current_scope != file_scope)
    8222           66 :           DECL_EXTERNAL (decl) = 0;
    8223              :         /* In C99, a function which is declared 'inline' with 'extern'
    8224              :            is not an external reference (which is confusing).  It
    8225              :            means that the later definition of the function must be output
    8226              :            in this file, C99 6.7.4p6.  In GNU C89, a function declared
    8227              :            'extern inline' is an external reference.  */
    8228     51427781 :         else if (declspecs->inline_p && storage_class != csc_static)
    8229     35475502 :           DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
    8230     35475502 :                                   == flag_gnu89_inline);
    8231              :         else
    8232     15952279 :           DECL_EXTERNAL (decl) = !initialized;
    8233              : 
    8234              :         /* Record absence of global scope for `static' or `auto'.  */
    8235     51427847 :         TREE_PUBLIC (decl)
    8236     51427847 :           = !(storage_class == csc_static || storage_class == csc_auto);
    8237              : 
    8238              :         /* For a function definition, record the argument information
    8239              :            block where store_parm_decls will look for it.  */
    8240     51427847 :         if (funcdef_flag)
    8241     36332375 :           current_function_arg_info = arg_info;
    8242              : 
    8243     51427847 :         if (declspecs->default_int_p)
    8244         9220 :           C_FUNCTION_IMPLICIT_INT (decl) = 1;
    8245              : 
    8246              :         /* Record presence of `inline' and `_Noreturn', if it is
    8247              :            reasonable.  */
    8248     51427847 :         if (flag_hosted && MAIN_NAME_P (declarator->u.id.id))
    8249              :           {
    8250        50226 :             if (declspecs->inline_p)
    8251            5 :               pedwarn (loc, 0, "cannot inline function %<main%>");
    8252        50226 :             if (declspecs->noreturn_p)
    8253            1 :               pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
    8254              :           }
    8255              :         else
    8256              :           {
    8257     51377621 :             if (declspecs->inline_p)
    8258              :               /* Record that the function is declared `inline'.  */
    8259     35637058 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8260     51377621 :             if (declspecs->noreturn_p)
    8261              :               {
    8262        23307 :                 if (flag_isoc99)
    8263        23304 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8264              :                                "ISO C99 does not support %<_Noreturn%>");
    8265              :                 else
    8266            3 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8267              :                                "ISO C90 does not support %<_Noreturn%>");
    8268        23307 :                 TREE_THIS_VOLATILE (decl) = 1;
    8269              :               }
    8270              :           }
    8271              : 
    8272              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8273              :            behavior) to create an 'extern' declaration for a
    8274              :            function if there is a global declaration that is
    8275              :            'static' and the global declaration is not visible.
    8276              :            (If the static declaration _is_ currently visible,
    8277              :            the 'extern' declaration is taken to refer to that decl.) */
    8278     51427847 :         if (!initialized
    8279     15095463 :             && TREE_PUBLIC (decl)
    8280     15087506 :             && current_scope != file_scope)
    8281              :           {
    8282         8890 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8283         8890 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8284              : 
    8285         8890 :             if (global_decl
    8286         8890 :                 && global_decl != visible_decl
    8287         1713 :                 && VAR_OR_FUNCTION_DECL_P (global_decl)
    8288         1713 :                 && !TREE_PUBLIC (global_decl))
    8289            2 :               error_at (loc, "function previously declared %<static%> "
    8290              :                         "redeclared %<extern%>");
    8291              :           }
    8292              :       }
    8293              :     else
    8294              :       {
    8295              :         /* It's a variable.  */
    8296              :         /* An uninitialized decl with `extern' is a reference.  */
    8297      8926914 :         int extern_ref = !initialized && storage_class == csc_extern;
    8298              : 
    8299      8926914 :         if (constexprp)
    8300              :           {
    8301              :             /* The type of a constexpr variable must not be variably
    8302              :                modified, volatile, atomic or restrict qualified or
    8303              :                have a member with such a qualifier.  const
    8304              :                qualification is implicitly added, and, at file scope,
    8305              :                has internal linkage.  */
    8306          360 :             if (c_type_variably_modified_p (type))
    8307            1 :               error_at (loc, "%<constexpr%> object has variably modified "
    8308              :                         "type");
    8309          360 :             if (type_quals
    8310          360 :                 & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    8311            9 :               error_at (loc, "invalid qualifiers for %<constexpr%> object");
    8312              :             else
    8313              :               {
    8314          351 :                 tree type_no_array = strip_array_types (type);
    8315          351 :                 if (RECORD_OR_UNION_TYPE_P (type_no_array)
    8316          351 :                     && C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array))
    8317            8 :                   error_at (loc, "invalid qualifiers for field of "
    8318              :                             "%<constexpr%> object");
    8319              :               }
    8320          360 :             type_quals |= TYPE_QUAL_CONST;
    8321          360 :             if (current_scope == file_scope)
    8322          294 :               storage_class = csc_static;
    8323              :           }
    8324              : 
    8325      8926914 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8326              :                                        orig_qual_indirect);
    8327              : 
    8328              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8329              :            behavior) to create an 'extern' declaration for a
    8330              :            variable if there is a global declaration that is
    8331              :            'static' and the global declaration is not visible.
    8332              :            (If the static declaration _is_ currently visible,
    8333              :            the 'extern' declaration is taken to refer to that decl.) */
    8334      8926914 :         if (extern_ref && current_scope != file_scope)
    8335              :           {
    8336         1571 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8337         1571 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8338              : 
    8339         1571 :             if (global_decl
    8340         1571 :                 && global_decl != visible_decl
    8341          282 :                 && VAR_P (global_decl)
    8342          282 :                 && !TREE_PUBLIC (global_decl))
    8343            8 :               error_at (loc, "variable previously declared %<static%> "
    8344              :                         "redeclared %<extern%>");
    8345              :           }
    8346              : 
    8347     17853828 :         decl = build_decl (declarator->id_loc,
    8348      8926914 :                            VAR_DECL, declarator->u.id.id, type);
    8349      8926914 :         if (size_varies)
    8350         7443 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8351      8926914 :         if (constexprp)
    8352          360 :           C_DECL_DECLARED_CONSTEXPR (decl) = 1;
    8353              : 
    8354      8926914 :         if (declspecs->inline_p)
    8355            4 :           pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
    8356      8926914 :         if (declspecs->noreturn_p)
    8357            1 :           pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
    8358              : 
    8359              :         /* At file scope, an initialized extern declaration may follow
    8360              :            a static declaration.  In that case, DECL_EXTERNAL will be
    8361              :            reset later in start_decl.  */
    8362      8926914 :         DECL_EXTERNAL (decl) = (storage_class == csc_extern);
    8363              : 
    8364              :         /* At file scope, the presence of a `static' or `register' storage
    8365              :            class specifier, or the absence of all storage class specifiers
    8366              :            makes this declaration a definition (perhaps tentative).  Also,
    8367              :            the absence of `static' makes it public.  */
    8368      8926914 :         if (current_scope == file_scope)
    8369              :           {
    8370      1152229 :             TREE_PUBLIC (decl) = storage_class != csc_static;
    8371      1152229 :             TREE_STATIC (decl) = !extern_ref;
    8372              :           }
    8373              :         /* Not at file scope, only `static' makes a static definition.  */
    8374              :         else
    8375              :           {
    8376      7774685 :             TREE_STATIC (decl) = (storage_class == csc_static);
    8377      7774685 :             TREE_PUBLIC (decl) = extern_ref;
    8378              :           }
    8379              : 
    8380              :         // NB: Set a tentative TLS model to avoid tls_model attribute
    8381              :         // warnings due to lack of thread storage duration.  It will
    8382              :         // be updated by c_decl_attributes later.
    8383      8926914 :         if (threadp)
    8384         2871 :           set_decl_tls_model (decl, TLS_MODEL_REAL);
    8385              :       }
    8386              : 
    8387    189446304 :     if ((storage_class == csc_extern
    8388    139024077 :          || (storage_class == csc_none
    8389    138560382 :              && TREE_CODE (type) == FUNCTION_TYPE
    8390       813067 :              && !funcdef_flag))
    8391    189755058 :         && c_type_variably_modified_p (type))
    8392              :       {
    8393              :         /* C99 6.7.5.2p2 */
    8394            6 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8395            4 :           error_at (loc, "non-nested function with variably modified type");
    8396              :         else
    8397            2 :           error_at (loc, "object with variably modified type must have "
    8398              :                     "no linkage");
    8399              :       }
    8400              : 
    8401              :     /* For nested functions disqualify ones taking VLAs by value
    8402              :        from inlining since the middle-end cannot deal with this.
    8403              :        ???  We should arrange for those to be passed by reference
    8404              :        with emitting the copy on the caller side in the frontend.  */
    8405    189446304 :     if (storage_class == csc_none
    8406    138560382 :         && TREE_CODE (type) == FUNCTION_TYPE)
    8407      4186659 :       for (tree al = TYPE_ARG_TYPES (type); al; al = TREE_CHAIN (al))
    8408              :         {
    8409      3373632 :           tree arg = TREE_VALUE (al);
    8410      3373632 :           if (arg != error_mark_node
    8411      3373632 :               && C_TYPE_VARIABLE_SIZE (arg))
    8412              :             {
    8413           40 :               DECL_UNINLINABLE (decl) = 1;
    8414           40 :               break;
    8415              :             }
    8416              :         }
    8417              : 
    8418              :     /* Record `register' declaration for warnings on &
    8419              :        and in case doing stupid register allocation.  */
    8420              : 
    8421    189446304 :     if (storage_class == csc_register
    8422         3609 :         && TREE_CODE (type) != FUNCTION_TYPE)
    8423              :       {
    8424         3603 :         C_DECL_REGISTER (decl) = 1;
    8425         3603 :         DECL_REGISTER (decl) = 1;
    8426              :       }
    8427              : 
    8428              :     /* Record constancy and volatility.  */
    8429    189446304 :     c_apply_type_quals_to_decl (type_quals, decl);
    8430              : 
    8431              :     /* Apply _Alignas specifiers.  */
    8432    189446304 :     if (alignas_align)
    8433              :       {
    8434          123 :         SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    8435          123 :         DECL_USER_ALIGN (decl) = 1;
    8436              :       }
    8437              : 
    8438              :     /* If a type has volatile components, it should be stored in memory.
    8439              :        Otherwise, the fact that those components are volatile
    8440              :        will be ignored, and would even crash the compiler.
    8441              :        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
    8442    189446304 :     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
    8443    189446304 :         && (VAR_P (decl) ||  TREE_CODE (decl) == PARM_DECL
    8444              :           || TREE_CODE (decl) == RESULT_DECL))
    8445              :       {
    8446              :         /* It is not an error for a structure with volatile fields to
    8447              :            be declared register, but reset DECL_REGISTER since it
    8448              :            cannot actually go in a register.  */
    8449          184 :         int was_reg = C_DECL_REGISTER (decl);
    8450          184 :         C_DECL_REGISTER (decl) = 0;
    8451          184 :         DECL_REGISTER (decl) = 0;
    8452          184 :         c_mark_addressable (decl);
    8453          184 :         C_DECL_REGISTER (decl) = was_reg;
    8454              :       }
    8455              : 
    8456              :   /* This is the earliest point at which we might know the assembler
    8457              :      name of a variable.  Thus, if it's known before this, die horribly.  */
    8458    189446304 :     gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
    8459              :                 || !DECL_ASSEMBLER_NAME_SET_P (decl));
    8460              : 
    8461    189446304 :     if (warn_cxx_compat
    8462        24690 :         && VAR_P (decl)
    8463         7556 :         && TREE_PUBLIC (decl)
    8464         2807 :         && TREE_STATIC (decl)
    8465         2358 :         && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    8466         2226 :             || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    8467    189446451 :         && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
    8468            4 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    8469              :                   "non-local variable %qD with anonymous type is "
    8470              :                   "questionable in C++", decl);
    8471              : 
    8472              :     return decl;
    8473              :   }
    8474              : }
    8475              : 
    8476              : /* Decode the parameter-list info for a function type or function definition.
    8477              :    The argument is the value returned by `get_parm_info' (or made in c-parse.c
    8478              :    if there is an identifier list instead of a parameter decl list).
    8479              :    These two functions are separate because when a function returns
    8480              :    or receives functions then each is called multiple times but the order
    8481              :    of calls is different.  The last call to `grokparms' is always the one
    8482              :    that contains the formal parameter names of a function definition.
    8483              : 
    8484              :    Return a list of arg types to use in the FUNCTION_TYPE for this function.
    8485              : 
    8486              :    FUNCDEF_FLAG is true for a function definition, false for
    8487              :    a mere declaration.  A nonempty identifier-list gets an error message
    8488              :    when FUNCDEF_FLAG is false.  */
    8489              : 
    8490              : static tree
    8491     51014234 : grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
    8492              : {
    8493     51014234 :   tree arg_types = arg_info->types;
    8494              : 
    8495     51014234 :   if (funcdef_flag && arg_info->had_vla_unspec)
    8496              :     {
    8497              :       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
    8498              :       /* C99 6.7.5.2p4 */
    8499            2 :       error ("%<[*]%> not allowed in other than function prototype scope");
    8500              :     }
    8501              : 
    8502       715841 :   if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc23
    8503     51017277 :       && !in_system_header_at (input_location))
    8504         3043 :     warning (OPT_Wstrict_prototypes,
    8505              :              "function declaration isn%'t a prototype");
    8506              : 
    8507     51014234 :   if (arg_types == error_mark_node)
    8508              :     /* Don't set TYPE_ARG_TYPES in this case.  */
    8509              :     return NULL_TREE;
    8510              : 
    8511    101253735 :   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
    8512              :     {
    8513         8684 :       if (!funcdef_flag)
    8514              :         {
    8515           13 :           permerror_opt (input_location,
    8516           13 :                          OPT_Wdeclaration_missing_parameter_type,
    8517              :                          "parameter names (without types) in "
    8518              :                          "function declaration");
    8519           13 :           arg_info->parms = NULL_TREE;
    8520              :         }
    8521              :       else
    8522         8671 :         arg_info->parms = arg_info->types;
    8523              : 
    8524         8684 :       arg_info->types = NULL_TREE;
    8525         8684 :       return NULL_TREE;
    8526              :     }
    8527              :   else
    8528              :     {
    8529     51005550 :       tree parm, type, typelt;
    8530     51005550 :       unsigned int parmno;
    8531              : 
    8532              :       /* In C23, convert () to (void).  */
    8533     51005550 :       if (flag_isoc23
    8534     41940185 :           && !arg_types
    8535       767231 :           && !arg_info->parms
    8536       767231 :           && !arg_info->no_named_args_stdarg_p)
    8537              :         {
    8538       767088 :           arg_types = arg_info->types = void_list_node;
    8539       767088 :           arg_info->c23_empty_parens = 1;
    8540              :         }
    8541              : 
    8542              :       /* If there is a parameter of incomplete type in a definition,
    8543              :          this is an error.  In a declaration this is valid, and a
    8544              :          struct or union type may be completed later, before any calls
    8545              :          or definition of the function.  In the case where the tag was
    8546              :          first declared within the parameter list, a warning has
    8547              :          already been given.  If a parameter has void type, then
    8548              :          this has already received an error (constraint violation in C2Y,
    8549              :          previously implicitly undefined behavior).  */
    8550              : 
    8551     51005550 :       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
    8552    174770372 :            parm;
    8553    123764822 :            parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
    8554              :         {
    8555    123764822 :           type = TREE_VALUE (typelt);
    8556    123764822 :           if (type == error_mark_node)
    8557           61 :             continue;
    8558              : 
    8559    123764761 :           if (!COMPLETE_TYPE_P (type))
    8560              :             {
    8561           40 :               if (funcdef_flag)
    8562              :                 {
    8563           13 :                   if (DECL_NAME (parm))
    8564           13 :                     error_at (input_location,
    8565              :                               "parameter %u (%q+D) has incomplete type",
    8566              :                               parmno, parm);
    8567              :                   else
    8568            0 :                     error_at (DECL_SOURCE_LOCATION (parm),
    8569              :                               "parameter %u has incomplete type",
    8570              :                               parmno);
    8571              : 
    8572           13 :                   TREE_VALUE (typelt) = error_mark_node;
    8573           13 :                   TREE_TYPE (parm) = error_mark_node;
    8574           13 :                   arg_types = NULL_TREE;
    8575              :                 }
    8576              :             }
    8577              : 
    8578    123764761 :           if (DECL_NAME (parm) && TREE_USED (parm))
    8579        17672 :             warn_if_shadowing (parm);
    8580              :         }
    8581              :       return arg_types;
    8582              :     }
    8583              : }
    8584              : 
    8585              : /* Allocate and initialize a c_arg_info structure from the parser's
    8586              :    obstack.  */
    8587              : 
    8588              : struct c_arg_info *
    8589     51014252 : build_arg_info (void)
    8590              : {
    8591     51014252 :   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
    8592     51014252 :   ret->parms = NULL_TREE;
    8593     51014252 :   ret->tags = NULL;
    8594     51014252 :   ret->types = NULL_TREE;
    8595     51014252 :   ret->others = NULL_TREE;
    8596     51014252 :   ret->pending_sizes = NULL;
    8597     51014252 :   ret->had_vla_unspec = 0;
    8598     51014252 :   ret->no_named_args_stdarg_p = 0;
    8599     51014252 :   ret->c23_empty_parens = 0;
    8600     51014252 :   return ret;
    8601              : }
    8602              : 
    8603              : /* Take apart the current scope and return a c_arg_info structure with
    8604              :    info on a parameter list just parsed.
    8605              : 
    8606              :    This structure is later fed to 'grokparms' and 'store_parm_decls'.
    8607              : 
    8608              :    ELLIPSIS being true means the argument list ended in '...' so don't
    8609              :    append a sentinel (void_list_node) to the end of the type-list.
    8610              : 
    8611              :    EXPR is NULL or an expression that needs to be evaluated for the
    8612              :    side effects of array size expressions in the parameters.  */
    8613              : 
    8614              : struct c_arg_info *
    8615     50230846 : get_parm_info (bool ellipsis, tree expr)
    8616              : {
    8617     50230846 :   struct c_binding *b = current_scope->bindings;
    8618     50230846 :   struct c_arg_info *arg_info = build_arg_info ();
    8619              : 
    8620     50230846 :   tree parms = NULL_TREE;
    8621     50230846 :   vec<c_arg_tag, va_gc> *tags = NULL;
    8622     50230846 :   tree types = NULL_TREE;
    8623     50230846 :   tree others = NULL_TREE;
    8624              : 
    8625     50230846 :   bool gave_void_only_once_err = false;
    8626              : 
    8627     50230846 :   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
    8628              : 
    8629              :   /* The bindings in this scope must not get put into a block.
    8630              :      We will take care of deleting the binding nodes.  */
    8631     50230846 :   current_scope->bindings = 0;
    8632              : 
    8633              :   /* This function is only called if there was *something* on the
    8634              :      parameter list.  */
    8635     50230846 :   gcc_assert (b);
    8636              : 
    8637              :   /* A parameter list consisting solely of 'void' indicates that the
    8638              :      function takes no arguments.  But if the 'void' is qualified
    8639              :      (by 'const' or 'volatile'), or has a storage class specifier
    8640              :      ('register'), then the behavior is undefined; issue an error.
    8641              :      Typedefs for 'void' are OK (see DR#157).  */
    8642     50230846 :   if (b->prev == 0                       /* one binding */
    8643     13495195 :       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
    8644     13495195 :       && !DECL_NAME (b->decl)               /* anonymous */
    8645     52096684 :       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
    8646              :     {
    8647       979403 :       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
    8648       979403 :           || C_DECL_REGISTER (b->decl))
    8649           96 :         error_at (b->locus, "%<void%> as only parameter may not be qualified");
    8650              : 
    8651              :       /* There cannot be an ellipsis.  */
    8652       979403 :       if (ellipsis)
    8653           17 :         error_at (b->locus, "%<void%> must be the only parameter");
    8654              : 
    8655       979403 :       arg_info->types = void_list_node;
    8656       979403 :       return arg_info;
    8657              :     }
    8658              : 
    8659     49251443 :   if (!ellipsis)
    8660     49036391 :     types = void_list_node;
    8661              : 
    8662              :   /* Break up the bindings list into parms, tags, types, and others;
    8663              :      apply sanity checks; purge the name-to-decl bindings.  */
    8664    173016728 :   while (b)
    8665              :     {
    8666    123765285 :       tree decl = b->decl;
    8667    123765285 :       tree type = TREE_TYPE (decl);
    8668    123765285 :       c_arg_tag tag;
    8669    123765285 :       const char *keyword;
    8670              : 
    8671    123765285 :       switch (TREE_CODE (decl))
    8672              :         {
    8673    123764945 :         case PARM_DECL:
    8674    123764945 :           if (b->id)
    8675              :             {
    8676    120105297 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8677    120105297 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8678              :             }
    8679              : 
    8680              :           /* Check for forward decls that never got their actual decl.  */
    8681    123764945 :           if (TREE_ASM_WRITTEN (decl))
    8682            4 :             error_at (b->locus,
    8683              :                       "parameter %q+D has just a forward declaration", decl);
    8684              :           /* Check for (..., void, ...) and named void parameters and issue an
    8685              :              error.  */
    8686    123764941 :           else if (VOID_TYPE_P (type))
    8687              :             {
    8688          114 :               if (!gave_void_only_once_err)
    8689              :                 {
    8690          114 :                   error_at (b->locus,
    8691              :                             "%<void%> must be the only parameter and unnamed");
    8692          114 :                   gave_void_only_once_err = true;
    8693              :                 }
    8694              :             }
    8695              :           else
    8696              :             {
    8697              :               /* Valid parameter, add it to the list.  */
    8698    123764827 :               DECL_CHAIN (decl) = parms;
    8699    123764827 :               parms = decl;
    8700              : 
    8701              :               /* Since there is a prototype, args are passed in their
    8702              :                  declared types.  The back end may override this later.  */
    8703    123764827 :               DECL_ARG_TYPE (decl) = type;
    8704    123764827 :               types = tree_cons (0, type, types);
    8705              :             }
    8706              :           break;
    8707              : 
    8708           21 :         case ENUMERAL_TYPE: keyword = "enum"; goto tag;
    8709           20 :         case UNION_TYPE:    keyword = "union"; goto tag;
    8710          101 :         case RECORD_TYPE:   keyword = "struct"; goto tag;
    8711          142 :         tag:
    8712              :           /* Types may not have tag-names, in which case the type
    8713              :              appears in the bindings list with b->id NULL.  */
    8714          142 :           if (b->id)
    8715              :             {
    8716           97 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    8717           97 :               I_TAG_BINDING (b->id) = b->shadowed;
    8718              :             }
    8719              : 
    8720              :           /* Warn about any struct, union or enum tags defined in a
    8721              :              parameter list.  The scope of such types is limited to
    8722              :              the parameter list, which is rarely if ever desirable
    8723              :              (it's impossible to call such a function with type-
    8724              :              correct arguments).  An anonymous union parm type is
    8725              :              meaningful as a GNU extension, so don't warn for that.  */
    8726          142 :           if (TREE_CODE (decl) != UNION_TYPE || b->id != NULL_TREE)
    8727              :             {
    8728          122 :               if (b->id)
    8729              :                 {
    8730              :                   /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8731           97 :                   if (!flag_isoc23 || !COMPLETE_TYPE_P (decl))
    8732           73 :                     warning_at (b->locus, 0,
    8733              :                                 "%<%s %E%> declared inside parameter list"
    8734              :                                 " will not be visible outside of this definition or"
    8735              :                                 " declaration", keyword, b->id);
    8736              :                 }
    8737              :               else
    8738              :                 /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8739           25 :                 warning_at (b->locus, 0,
    8740              :                             "anonymous %s declared inside parameter list"
    8741              :                             " will not be visible outside of this definition or"
    8742              :                             " declaration", keyword);
    8743              :             }
    8744              : 
    8745          142 :           tag.id = b->id;
    8746          142 :           tag.type = decl;
    8747          142 :           vec_safe_push (tags, tag);
    8748          142 :           break;
    8749              : 
    8750           20 :         case FUNCTION_DECL:
    8751              :           /* FUNCTION_DECLs appear when there is an implicit function
    8752              :              declaration in the parameter list.  */
    8753           20 :           gcc_assert (b->nested || seen_error ());
    8754           20 :           goto set_shadowed;
    8755              : 
    8756          144 :         case CONST_DECL:
    8757          144 :         case TYPE_DECL:
    8758              :           /* CONST_DECLs appear here when we have an embedded enum,
    8759              :              and TYPE_DECLs appear here when we have an embedded struct
    8760              :              or union.  No warnings for this - we already warned about the
    8761              :              type itself.  */
    8762              : 
    8763              :           /* When we reinsert this decl in the function body, we need
    8764              :              to reconstruct whether it was marked as nested.  */
    8765          144 :           gcc_assert (!b->nested);
    8766          144 :           DECL_CHAIN (decl) = others;
    8767          144 :           others = decl;
    8768              :           /* fall through */
    8769              : 
    8770          198 :         case ERROR_MARK:
    8771          198 :         set_shadowed:
    8772              :           /* error_mark_node appears here when we have an undeclared
    8773              :              variable.  Just throw it away.  */
    8774          198 :           if (b->id)
    8775              :             {
    8776           56 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8777           56 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8778              :             }
    8779              :           break;
    8780              : 
    8781              :           /* Other things that might be encountered.  */
    8782            0 :         case LABEL_DECL:
    8783            0 :         case VAR_DECL:
    8784            0 :         default:
    8785            0 :           gcc_unreachable ();
    8786              :         }
    8787              : 
    8788    123765285 :       b = free_binding_and_advance (b);
    8789              :     }
    8790              : 
    8791     49251443 :   arg_info->parms = parms;
    8792     49251443 :   arg_info->tags = tags;
    8793     49251443 :   arg_info->types = types;
    8794     49251443 :   arg_info->others = others;
    8795     49251443 :   arg_info->pending_sizes = expr;
    8796     49251443 :   arg_info->no_named_args_stdarg_p = ellipsis && !types;
    8797     49251443 :   return arg_info;
    8798              : }
    8799              : 
    8800              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8801              :    Define the tag as a forward-reference with location LOC if it is
    8802              :    not defined.  HAVE_STD_ATTRS says whether any standard attributes
    8803              :    were present after the struct, union or enum keyword; ATTRS are the
    8804              :    standard attributes present there.  HAS_ENUM_TYPE_SPECIFIER says
    8805              :    whether an enum type specifier (": specifier-qualifier-list") is
    8806              :    present; if so, this is called before that specifier is parsed, so
    8807              :    that the tag is in scope for that specifier.  Return a c_typespec
    8808              :    structure for the type specifier.  */
    8809              : 
    8810              : struct c_typespec
    8811      1096841 : parser_xref_tag (location_t loc, enum tree_code code, tree name,
    8812              :                  bool have_std_attrs, tree attrs, bool has_enum_type_specifier)
    8813              : {
    8814      1096841 :   struct c_typespec ret;
    8815      1096841 :   tree ref;
    8816      1096841 :   location_t refloc;
    8817              : 
    8818      1096841 :   ret.expr = NULL_TREE;
    8819      1096841 :   ret.expr_const_operands = true;
    8820      1096841 :   ret.has_enum_type_specifier = has_enum_type_specifier;
    8821              : 
    8822              :   /* If a cross reference is requested, look up the type already
    8823              :      defined for this tag and return it.  If an enum type specifier is
    8824              :      present, only a definition in the current scope is relevant.  */
    8825              : 
    8826      1096841 :   ref = lookup_tag (code, name, has_enum_type_specifier, &refloc);
    8827              : 
    8828              :   /* If the visible type is still being defined, see if there is
    8829              :      an earlier definition (which may be complete).  We do not
    8830              :      have to loop because nested redefinitions are not allowed.  */
    8831      1096841 :   if (flag_isoc23 && ref && C_TYPE_BEING_DEFINED (ref))
    8832              :     {
    8833        86652 :       tree vis = previous_tag (ref);
    8834        86652 :       if (vis)
    8835           16 :         ref = vis;
    8836              :     }
    8837              : 
    8838              :   /* If this is the right type of tag, return what we found.
    8839              :      (This reference will be shadowed by shadow_tag later if appropriate.)
    8840              :      If this is the wrong type of tag, do not return it.  If it was the
    8841              :      wrong type in the same scope, we will have had an error
    8842              :      message already; if in a different scope and declaring
    8843              :      a name, pending_xref_error will give an error message; but if in a
    8844              :      different scope and not declaring a name, this tag should
    8845              :      shadow the previous declaration of a different type of tag, and
    8846              :      this would not work properly if we return the reference found.
    8847              :      (For example, with "struct foo" in an outer scope, "union foo;"
    8848              :      must shadow that tag with a new one of union type.)  */
    8849      2193682 :   ret.kind = (ref
    8850      1096841 :               ? (have_std_attrs ? ctsk_tagref_attrs : ctsk_tagref)
    8851        95714 :               : (have_std_attrs ? ctsk_tagfirstref_attrs : ctsk_tagfirstref));
    8852      1096841 :   if (ref && TREE_CODE (ref) == code)
    8853              :     {
    8854      1001093 :       decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8855      1001093 :       if (C_TYPE_DEFINED_IN_STRUCT (ref)
    8856            5 :           && loc != UNKNOWN_LOCATION
    8857      1001098 :           && warn_cxx_compat)
    8858              :         {
    8859            5 :           auto_diagnostic_group d;
    8860            5 :           switch (code)
    8861              :             {
    8862            2 :             case ENUMERAL_TYPE:
    8863            2 :               if (warning_at (loc, OPT_Wc___compat,
    8864              :                               ("enum type defined in struct or union "
    8865              :                                "is not visible in C++")))
    8866            2 :                   inform (refloc, "enum type defined here");
    8867              :               break;
    8868            2 :             case RECORD_TYPE:
    8869            2 :               if (warning_at (loc, OPT_Wc___compat,
    8870              :                               ("struct defined in struct or union "
    8871              :                                "is not visible in C++")))
    8872            2 :                 inform (refloc, "struct defined here");
    8873              :               break;
    8874            1 :             case UNION_TYPE:
    8875            1 :               if (warning_at (loc, OPT_Wc___compat,
    8876              :                               ("union defined in struct or union "
    8877              :                                "is not visible in C++")))
    8878            1 :                 inform (refloc, "union defined here");
    8879              :               break;
    8880            0 :             default:
    8881            0 :               gcc_unreachable();
    8882              :             }
    8883            5 :         }
    8884              : 
    8885      1001093 :       ret.spec = ref;
    8886      1001093 :       return ret;
    8887              :     }
    8888              : 
    8889              :   /* If no such tag is yet defined, create a forward-reference node
    8890              :      and record it as the "definition".
    8891              :      When a real declaration of this type is found,
    8892              :      the forward-reference will be altered into a real type.  */
    8893              : 
    8894        95748 :   ref = make_node (code);
    8895        95748 :   if (flag_isoc23 || code == ENUMERAL_TYPE)
    8896        73480 :     SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8897        73480 :   if (code == ENUMERAL_TYPE)
    8898              :     {
    8899              :       /* Give the type a default layout like unsigned int
    8900              :          to avoid crashing if it does not get defined.  */
    8901          273 :       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
    8902          273 :       SET_TYPE_ALIGN (ref, TYPE_ALIGN (unsigned_type_node));
    8903          273 :       TYPE_USER_ALIGN (ref) = 0;
    8904          273 :       TYPE_UNSIGNED (ref) = 1;
    8905          273 :       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
    8906          273 :       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
    8907          273 :       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
    8908          273 :       ENUM_FIXED_UNDERLYING_TYPE_P (ref) = has_enum_type_specifier;
    8909              :     }
    8910              : 
    8911        95748 :   pushtag (loc, name, ref);
    8912        95748 :   decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8913        95748 :   if (in_underspecified_init)
    8914            9 :     error_at (loc, "%qT declared in underspecified object initializer",
    8915              :               ref);
    8916              : 
    8917        95748 :   ret.spec = ref;
    8918        95748 :   return ret;
    8919              : }
    8920              : 
    8921              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8922              :    Define the tag as a forward-reference if it is not defined.
    8923              :    Return a tree for the type.  */
    8924              : 
    8925              : tree
    8926            0 : xref_tag (enum tree_code code, tree name)
    8927              : {
    8928            0 :   return parser_xref_tag (input_location, code, name, false, NULL_TREE,
    8929            0 :                           false).spec;
    8930              : }
    8931              : 
    8932              : /* Make sure that the tag NAME is defined *in the current scope*
    8933              :    at least as a forward reference.
    8934              :    LOC is the location of the struct's definition.
    8935              :    CODE says which kind of tag NAME ought to be.
    8936              : 
    8937              :    This stores the current value of the file static STRUCT_PARSE_INFO
    8938              :    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
    8939              :    new c_struct_parse_info structure.  The old value of
    8940              :    STRUCT_PARSE_INFO is restored in finish_struct.  */
    8941              : 
    8942              : tree
    8943      1183468 : start_struct (location_t loc, enum tree_code code, tree name,
    8944              :               class c_struct_parse_info **enclosing_struct_parse_info)
    8945              : {
    8946              :   /* If there is already a tag defined at this scope
    8947              :      (as a forward reference), just return it.  */
    8948              : 
    8949      1183468 :   tree ref = NULL_TREE;
    8950      1183468 :   location_t refloc = UNKNOWN_LOCATION;
    8951              : 
    8952      1183468 :   if (name != NULL_TREE)
    8953       488473 :     ref = lookup_tag (code, name, true, &refloc);
    8954              : 
    8955              :   /* For C23, even if we already have a completed definition,
    8956              :      we do not use it. We will check for consistency later.
    8957              :      If we are in a nested redefinition the type is not
    8958              :      complete. We will then detect this below.  */
    8959      1183468 :   if (flag_isoc23 && ref && TYPE_SIZE (ref))
    8960              :     ref = NULL_TREE;
    8961              : 
    8962      1183359 :   if (ref && TREE_CODE (ref) == code)
    8963              :     {
    8964        25334 :       if (TYPE_STUB_DECL (ref))
    8965        25334 :         refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
    8966              : 
    8967        25334 :       if (TYPE_SIZE (ref))
    8968              :         {
    8969           11 :           auto_diagnostic_group d;
    8970           11 :           if (code == UNION_TYPE)
    8971            2 :             error_at (loc, "redefinition of %<union %E%>", name);
    8972              :           else
    8973            9 :             error_at (loc, "redefinition of %<struct %E%>", name);
    8974           11 :           if (refloc != UNKNOWN_LOCATION)
    8975           11 :             inform (refloc, "originally defined here");
    8976              :           /* Don't create structures using a name already in use.  */
    8977           11 :           ref = NULL_TREE;
    8978           11 :         }
    8979        25323 :       else if (C_TYPE_BEING_DEFINED (ref))
    8980              :         {
    8981           17 :           if (code == UNION_TYPE)
    8982            1 :             error_at (loc, "nested redefinition of %<union %E%>", name);
    8983              :           else
    8984           16 :             error_at (loc, "nested redefinition of %<struct %E%>", name);
    8985              :           /* Don't bother to report "originally defined here" for a
    8986              :              nested redefinition; the original definition should be
    8987              :              obvious.  */
    8988              :           /* Don't create structures that contain themselves.  */
    8989              :           ref = NULL_TREE;
    8990              :         }
    8991              :     }
    8992              : 
    8993              :   /* Otherwise create a forward-reference just so the tag is in scope.  */
    8994              : 
    8995        25320 :   if (ref == NULL_TREE || TREE_CODE (ref) != code)
    8996              :     {
    8997      1158162 :       ref = make_node (code);
    8998      1158162 :       if (flag_isoc23)
    8999       929866 :         SET_TYPE_STRUCTURAL_EQUALITY (ref);
    9000      1158162 :       pushtag (loc, name, ref);
    9001              :     }
    9002              : 
    9003      1183468 :   C_TYPE_BEING_DEFINED (ref) = 1;
    9004      2397745 :   for (tree v = TYPE_MAIN_VARIANT (ref); v; v = TYPE_NEXT_VARIANT (v))
    9005      1214277 :     TYPE_PACKED (v) = flag_pack_struct;
    9006              : 
    9007      1183468 :   *enclosing_struct_parse_info = struct_parse_info;
    9008      1183468 :   struct_parse_info = new c_struct_parse_info ();
    9009      1183468 :   struct_parse_info->refloc = refloc;
    9010              : 
    9011              :   /* FIXME: This will issue a warning for a use of a type defined
    9012              :      within a statement expr used within sizeof, et. al.  This is not
    9013              :      terribly serious as C++ doesn't permit statement exprs within
    9014              :      sizeof anyhow.  */
    9015      1183468 :   if (warn_cxx_compat
    9016          576 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
    9017           10 :     warning_at (loc, OPT_Wc___compat,
    9018              :                 "defining type in %qs expression is invalid in C++",
    9019              :                 (in_sizeof ? "sizeof"
    9020            4 :                  : in_typeof ? "typeof"
    9021            1 :                  : in_alignof ? "alignof"
    9022              :                  : "_Countof"));
    9023              : 
    9024      1183468 :   if (in_underspecified_init)
    9025           18 :     error_at (loc, "%qT defined in underspecified object initializer", ref);
    9026              : 
    9027      1183468 :   return ref;
    9028              : }
    9029              : 
    9030              : /* Process the specs, declarator and width (NULL if omitted)
    9031              :    of a structure component, returning a FIELD_DECL node.
    9032              :    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
    9033              :    DECL_ATTRS is as for grokdeclarator.
    9034              : 
    9035              :    LOC is the location of the structure component.
    9036              : 
    9037              :    This is done during the parsing of the struct declaration.
    9038              :    The FIELD_DECL nodes are chained together and the lot of them
    9039              :    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
    9040              : 
    9041              : tree
    9042      4324399 : grokfield (location_t loc,
    9043              :            struct c_declarator *declarator, struct c_declspecs *declspecs,
    9044              :            tree width, tree *decl_attrs, tree *expr)
    9045              : {
    9046      4324399 :   tree value;
    9047              : 
    9048      4324399 :   if (declarator->kind == cdk_id && declarator->u.id.id == NULL_TREE
    9049        20469 :       && width == NULL_TREE)
    9050              :     {
    9051              :       /* This is an unnamed decl.
    9052              : 
    9053              :          If we have something of the form "union { list } ;" then this
    9054              :          is the anonymous union extension.  Similarly for struct.
    9055              : 
    9056              :          If this is something of the form "struct foo;", then
    9057              :            If MS or Plan 9 extensions are enabled, this is handled as
    9058              :              an anonymous struct.
    9059              :            Otherwise this is a forward declaration of a structure tag.
    9060              : 
    9061              :          If this is something of the form "foo;" and foo is a TYPE_DECL, then
    9062              :            If foo names a structure or union without a tag, then this
    9063              :              is an anonymous struct (this is permitted by C11).
    9064              :            If MS or Plan 9 extensions are enabled and foo names a
    9065              :              structure, then again this is an anonymous struct.
    9066              :            Otherwise this is an error.
    9067              : 
    9068              :          Oh what a horrid tangled web we weave.  I wonder if MS consciously
    9069              :          took this from Plan 9 or if it was an accident of implementation
    9070              :          that took root before someone noticed the bug...  */
    9071              : 
    9072        10706 :       tree type = declspecs->type;
    9073        10706 :       bool ok = false;
    9074              : 
    9075        10706 :       if (RECORD_OR_UNION_TYPE_P (type)
    9076        10700 :           && (flag_ms_extensions
    9077        10671 :               || flag_plan9_extensions
    9078        10640 :               || !declspecs->typedef_p))
    9079              :         {
    9080        10693 :           if (flag_ms_extensions || flag_plan9_extensions)
    9081              :             ok = true;
    9082        10633 :           else if (TYPE_NAME (type) == NULL)
    9083              :             ok = true;
    9084              :           else
    9085              :             ok = false;
    9086              :         }
    9087              :       if (!ok)
    9088              :         {
    9089           29 :           pedwarn (loc, 0, "declaration does not declare anything");
    9090           29 :           return NULL_TREE;
    9091              :         }
    9092        10677 :       if (flag_isoc99)
    9093        10655 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9094              :                      "ISO C99 doesn%'t support unnamed structs/unions");
    9095              :       else
    9096           22 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9097              :                      "ISO C90 doesn%'t support unnamed structs/unions");
    9098              :     }
    9099              : 
    9100      4324370 :   value = grokdeclarator (declarator, declspecs, FIELD, false,
    9101      4324370 :                           width ? &width : NULL, decl_attrs, expr, NULL,
    9102              :                           DEPRECATED_NORMAL);
    9103              : 
    9104              :   /* When this field has name, its type is a top level type, we should
    9105              :      call verify_counted_by_for_top_anonymous_type.  */
    9106      4324370 :   if (DECL_NAME (value) != NULL_TREE
    9107      4324370 :       && declspecs->typespec_kind == ctsk_tagdef)
    9108       153675 :     verify_counted_by_for_top_anonymous_type (declspecs->type);
    9109              : 
    9110      4324370 :   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
    9111      4324370 :   DECL_INITIAL (value) = width;
    9112      4324370 :   if (width)
    9113        52797 :     SET_DECL_C_BIT_FIELD (value);
    9114              : 
    9115      4324370 :   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
    9116              :     {
    9117              :       /* If we currently have a binding for this field, set the
    9118              :          in_struct field in the binding, so that we warn about lookups
    9119              :          which find it.  */
    9120         1312 :       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
    9121         1312 :       if (b != NULL)
    9122              :         {
    9123              :           /* If the in_struct field is not yet set, push it on a list
    9124              :              to be cleared when this struct is finished.  */
    9125           93 :           if (!b->in_struct)
    9126              :             {
    9127           91 :               struct_parse_info->fields.safe_push (b);
    9128           91 :               b->in_struct = 1;
    9129              :             }
    9130              :         }
    9131              :     }
    9132              : 
    9133              :   return value;
    9134              : }
    9135              : 
    9136              : /* Subroutine of detect_field_duplicates: return whether X and Y,
    9137              :    which are both fields in the same struct, have duplicate field
    9138              :    names.  */
    9139              : 
    9140              : static bool
    9141      4316606 : is_duplicate_field (tree x, tree y)
    9142              : {
    9143      4316606 :   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
    9144              :     return true;
    9145              : 
    9146              :   /* When using -fplan9-extensions, an anonymous field whose name is a
    9147              :      typedef can duplicate a field name.  */
    9148      4316605 :   if (flag_plan9_extensions
    9149      4316605 :       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
    9150              :     {
    9151            0 :       tree xt, xn, yt, yn;
    9152              : 
    9153            0 :       xt = TREE_TYPE (x);
    9154            0 :       if (DECL_NAME (x) != NULL_TREE)
    9155            0 :         xn = DECL_NAME (x);
    9156            0 :       else if (RECORD_OR_UNION_TYPE_P (xt)
    9157            0 :                && TYPE_NAME (xt) != NULL_TREE
    9158            0 :                && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
    9159            0 :         xn = DECL_NAME (TYPE_NAME (xt));
    9160              :       else
    9161              :         xn = NULL_TREE;
    9162              : 
    9163            0 :       yt = TREE_TYPE (y);
    9164            0 :       if (DECL_NAME (y) != NULL_TREE)
    9165            0 :         yn = DECL_NAME (y);
    9166            0 :       else if (RECORD_OR_UNION_TYPE_P (yt)
    9167            0 :                && TYPE_NAME (yt) != NULL_TREE
    9168            0 :                && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
    9169            0 :         yn = DECL_NAME (TYPE_NAME (yt));
    9170              :       else
    9171              :         yn = NULL_TREE;
    9172              : 
    9173            0 :       if (xn != NULL_TREE && xn == yn)
    9174            0 :         return true;
    9175              :     }
    9176              : 
    9177              :   return false;
    9178              : }
    9179              : 
    9180              : /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
    9181              :    to HTAB, giving errors for any duplicates.  */
    9182              : 
    9183              : static void
    9184        80888 : detect_field_duplicates_hash (tree fieldlist,
    9185              :                               hash_table<nofree_ptr_hash <tree_node> > *htab)
    9186              : {
    9187        80888 :   tree x, y;
    9188        80888 :   tree_node **slot;
    9189              : 
    9190      1409175 :   for (x = fieldlist; x ; x = DECL_CHAIN (x))
    9191      1328287 :     if ((y = DECL_NAME (x)) != NULL_TREE)
    9192              :       {
    9193      1307782 :         slot = htab->find_slot (y, INSERT);
    9194      1307782 :         if (*slot)
    9195              :           {
    9196           15 :             error ("duplicate member %q+D", x);
    9197           15 :             DECL_NAME (x) = NULL_TREE;
    9198              :           }
    9199      1307782 :         *slot = y;
    9200              :       }
    9201        20505 :     else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9202              :       {
    9203        11459 :         detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
    9204              : 
    9205              :         /* When using -fplan9-extensions, an anonymous field whose
    9206              :            name is a typedef can duplicate a field name.  */
    9207        11459 :         if (flag_plan9_extensions
    9208           31 :             && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9209        11489 :             && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
    9210              :           {
    9211           10 :             tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
    9212           10 :             slot = htab->find_slot (xn, INSERT);
    9213           10 :             if (*slot)
    9214            0 :               error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
    9215           10 :             *slot = xn;
    9216              :           }
    9217              :       }
    9218        80888 : }
    9219              : 
    9220              : /* Generate an error for any duplicate field names in FIELDLIST.  Munge
    9221              :    the list such that this does not present a problem later.  */
    9222              : 
    9223              : static void
    9224      1183598 : detect_field_duplicates (tree fieldlist)
    9225              : {
    9226      1183598 :   tree x, y;
    9227      1183598 :   int timeout = 10;
    9228              : 
    9229              :   /* If the struct is the list of instance variables of an Objective-C
    9230              :      class, then we need to check all the instance variables of
    9231              :      superclasses when checking for duplicates (since you can't have
    9232              :      an instance variable in a subclass with the same name as an
    9233              :      instance variable in a superclass).  We pass on this job to the
    9234              :      Objective-C compiler.  objc_detect_field_duplicates() will return
    9235              :      false if we are not checking the list of instance variables and
    9236              :      the C frontend should proceed with the standard field duplicate
    9237              :      checks.  If we are checking the list of instance variables, the
    9238              :      ObjC frontend will do the check, emit the errors if needed, and
    9239              :      then return true.  */
    9240      1183598 :   if (c_dialect_objc ())
    9241            0 :     if (objc_detect_field_duplicates (false))
    9242              :       return;
    9243              : 
    9244              :   /* First, see if there are more than "a few" fields.
    9245              :      This is trivially true if there are zero or one fields.  */
    9246      1183598 :   if (!fieldlist || !DECL_CHAIN (fieldlist))
    9247              :     return;
    9248              :   x = fieldlist;
    9249      3488214 :   do {
    9250      3488214 :     timeout--;
    9251      3488214 :     if (DECL_NAME (x) == NULL_TREE
    9252      3488214 :         && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9253              :       timeout = 0;
    9254      3488214 :     x = DECL_CHAIN (x);
    9255      3488214 :   } while (timeout > 0 && x);
    9256              : 
    9257              :   /* If there were "few" fields and no anonymous structures or unions,
    9258              :      avoid the overhead of allocating a hash table.  Instead just do
    9259              :      the nested traversal thing.  */
    9260       977196 :   if (timeout > 0)
    9261              :     {
    9262      2828091 :       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
    9263              :         /* When using -fplan9-extensions, we can have duplicates
    9264              :            between typedef names and fields.  */
    9265      1920324 :         if (DECL_NAME (x)
    9266      1920324 :             || (flag_plan9_extensions
    9267            0 :                 && DECL_NAME (x) == NULL_TREE
    9268            0 :                 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9269            0 :                 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9270            0 :                 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
    9271              :           {
    9272      6236394 :             for (y = fieldlist; y != x; y = TREE_CHAIN (y))
    9273      4316606 :               if (is_duplicate_field (y, x))
    9274              :                 {
    9275            1 :                   error ("duplicate member %q+D", x);
    9276            1 :                   DECL_NAME (x) = NULL_TREE;
    9277              :                 }
    9278              :           }
    9279              :     }
    9280              :   else
    9281              :     {
    9282        69429 :       hash_table<nofree_ptr_hash <tree_node> > htab (37);
    9283        69429 :       detect_field_duplicates_hash (fieldlist, &htab);
    9284        69429 :     }
    9285              : }
    9286              : 
    9287              : /* Finish up struct info used by -Wc++-compat.  */
    9288              : 
    9289              : static void
    9290          577 : warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code,
    9291              :                                location_t record_loc)
    9292              : {
    9293          577 :   unsigned int ix;
    9294          577 :   tree x;
    9295          577 :   struct c_binding *b;
    9296              : 
    9297          577 :   if (fieldlist == NULL_TREE)
    9298              :     {
    9299            9 :       if (code == RECORD_TYPE)
    9300            6 :         warning_at (record_loc, OPT_Wc___compat,
    9301              :                     "empty struct has size 0 in C, size 1 in C++");
    9302              :       else
    9303            3 :         warning_at (record_loc, OPT_Wc___compat,
    9304              :                     "empty union has size 0 in C, size 1 in C++");
    9305              :     }
    9306              : 
    9307              :   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
    9308              :      the current struct.  We do this now at the end of the struct
    9309              :      because the flag is used to issue visibility warnings, and we
    9310              :      only want to issue those warnings if the type is referenced
    9311              :      outside of the struct declaration.  */
    9312          625 :   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
    9313           48 :     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
    9314              : 
    9315              :   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
    9316              :      typedefs used when declaring fields in this struct.  If the name
    9317              :      of any of the fields is also a typedef name then the struct would
    9318              :      not parse in C++, because the C++ lookup rules say that the
    9319              :      typedef name would be looked up in the context of the struct, and
    9320              :      would thus be the field rather than the typedef.  */
    9321          577 :   if (!struct_parse_info->typedefs_seen.is_empty ()
    9322           67 :       && fieldlist != NULL_TREE)
    9323              :     {
    9324              :       /* Use a hash_set<tree> using the name of the typedef.  We can use
    9325              :          a hash_set<tree> because identifiers are interned.  */
    9326           67 :       hash_set<tree> tset;
    9327              : 
    9328          254 :       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
    9329          120 :         tset.add (DECL_NAME (x));
    9330              : 
    9331          387 :       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
    9332              :         {
    9333          320 :           if (DECL_NAME (x) != NULL_TREE
    9334          320 :               && tset.contains (DECL_NAME (x)))
    9335              :             {
    9336            2 :               warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
    9337              :                           "using %qD as both field and typedef name is "
    9338              :                           "invalid in C++", x);
    9339              :               /* FIXME: It would be nice to report the location where
    9340              :                  the typedef name is used.  */
    9341              :             }
    9342              :         }
    9343           67 :     }
    9344              : 
    9345              :   /* For each field which has a binding and which was not defined in
    9346              :      an enclosing struct, clear the in_struct field.  */
    9347          668 :   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
    9348           91 :     b->in_struct = 0;
    9349          577 : }
    9350              : 
    9351              : /* Function to help qsort sort FIELD_DECLs by name order.  */
    9352              : 
    9353              : static int
    9354     20256264 : field_decl_cmp (const void *x_p, const void *y_p)
    9355              : {
    9356     20256264 :   const tree *const x = (const tree *) x_p;
    9357     20256264 :   const tree *const y = (const tree *) y_p;
    9358              : 
    9359     20256264 :   if (DECL_NAME (*x) == DECL_NAME (*y))
    9360              :     /* A nontype is "greater" than a type.  */
    9361            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
    9362     20256264 :   if (DECL_NAME (*x) == NULL_TREE)
    9363              :     return -1;
    9364     20256264 :   if (DECL_NAME (*y) == NULL_TREE)
    9365              :     return 1;
    9366     20256264 :   if (DECL_NAME (*x) < DECL_NAME (*y))
    9367      9977379 :     return -1;
    9368              :   return 1;
    9369              : }
    9370              : 
    9371              : /* If this structure or union completes the type of any previous
    9372              :    variable declaration, lay it out and output its rtl.  */
    9373              : static void
    9374      1366929 : finish_incomplete_vars (tree incomplete_vars, bool toplevel)
    9375              : {
    9376      1367078 :   for (tree x = incomplete_vars; x; x = TREE_CHAIN (x))
    9377              :     {
    9378          149 :       tree decl = TREE_VALUE (x);
    9379          149 :       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
    9380            0 :         layout_array_type (TREE_TYPE (decl));
    9381          149 :       if (TREE_CODE (decl) != TYPE_DECL)
    9382              :         {
    9383          149 :           relayout_decl (decl);
    9384          149 :           if (c_dialect_objc ())
    9385            0 :             objc_check_decl (decl);
    9386          149 :           rest_of_decl_compilation (decl, toplevel, 0);
    9387              :         }
    9388              :     }
    9389      1366929 : }
    9390              : 
    9391              : /* Determine whether the FIELD_DECL X is a flexible array member according to
    9392              :    the following info:
    9393              :   A. whether the FIELD_DECL X is the last field of the DECL_CONTEXT;
    9394              :   B. whether the FIELD_DECL is an array that is declared as "[]", "[0]",
    9395              :      or "[1]";
    9396              :   C. flag_strict_flex_arrays;
    9397              :   D. the attribute strict_flex_array that is attached to the field
    9398              :      if presenting.
    9399              :   Return TRUE when it's a flexible array member, FALSE otherwise.  */
    9400              : 
    9401              : static bool
    9402      4324521 : is_flexible_array_member_p (bool is_last_field,
    9403              :                             tree x)
    9404              : {
    9405              :   /* If not the last field, return false.  */
    9406      4324521 :   if (!is_last_field)
    9407              :     return false;
    9408              : 
    9409              :   /* If not an array field, return false.  */
    9410      1659431 :   if (TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    9411              :     return false;
    9412              : 
    9413       535973 :   bool is_zero_length_array = zero_length_array_type_p (TREE_TYPE (x));
    9414       535973 :   bool is_one_element_array = one_element_array_type_p (TREE_TYPE (x));
    9415       535973 :   bool is_flexible_array = c_flexible_array_member_type_p (TREE_TYPE (x));
    9416              : 
    9417       535973 :   unsigned int strict_flex_array_level = c_strict_flex_array_level_of (x);
    9418              : 
    9419       535973 :   switch (strict_flex_array_level)
    9420              :     {
    9421              :       case 0:
    9422              :         /* Default, all trailing arrays are flexible array members.  */
    9423              :         return true;
    9424           77 :       case 1:
    9425              :         /* Level 1: all "[1]", "[0]", and "[]" are flexible array members.  */
    9426           77 :         if (is_one_element_array)
    9427              :           return true;
    9428              :         /* FALLTHROUGH.  */
    9429          141 :       case 2:
    9430              :         /* Level 2: all "[0]", and "[]" are flexible array members.  */
    9431          141 :         if (is_zero_length_array)
    9432              :           return true;
    9433              :         /* FALLTHROUGH.  */
    9434          201 :       case 3:
    9435              :         /* Level 3: Only "[]" are flexible array members.  */
    9436          201 :         if (is_flexible_array)
    9437              :           return true;
    9438              :         break;
    9439            0 :       default:
    9440            0 :         gcc_unreachable ();
    9441              :     }
    9442              :   return false;
    9443              : }
    9444              : 
    9445              : /* Recompute TYPE_CANONICAL for variants of the type including qualified
    9446              :    versions of the type and related pointer types after an aggregate type
    9447              :    has been finalized.
    9448              :    Will not update array types, pointers to array types, function
    9449              :    types and other derived types created while the type was still
    9450              :    incomplete, those will remain TYPE_STRUCTURAL_EQUALITY_P.  */
    9451              : 
    9452              : static void
    9453      1203560 : c_update_type_canonical (tree t)
    9454              : {
    9455      1203560 :   gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t && !TYPE_QUALS (t));
    9456      2434093 :   for (tree x = t, l = NULL_TREE; x; l = x, x = TYPE_NEXT_VARIANT (x))
    9457              :     {
    9458      1230533 :       if (x != t && TYPE_STRUCTURAL_EQUALITY_P (x))
    9459              :         {
    9460        26973 :           if (!TYPE_QUALS (x))
    9461        26345 :             TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
    9462              :           else
    9463              :             {
    9464          628 :               tree
    9465          628 :                 c = c_build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
    9466          628 :               if (TYPE_STRUCTURAL_EQUALITY_P (c))
    9467              :                 {
    9468          206 :                   gcc_checking_assert (TYPE_CANONICAL (t) == t);
    9469          206 :                   if (c == x)
    9470          206 :                     TYPE_CANONICAL (x) = x;
    9471              :                   else
    9472              :                     {
    9473              :                       /* build_qualified_type for this function unhelpfully
    9474              :                          moved c from some later spot in TYPE_MAIN_VARIANT (t)
    9475              :                          chain to right after t (or created it there).  Move
    9476              :                          it right before x and process c and then x.  */
    9477            0 :                       gcc_checking_assert (TYPE_NEXT_VARIANT (t) == c);
    9478            0 :                       if (l != t)
    9479              :                         {
    9480            0 :                           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (c);
    9481            0 :                           TYPE_NEXT_VARIANT (l) = c;
    9482            0 :                           TYPE_NEXT_VARIANT (c) = x;
    9483              :                         }
    9484            0 :                       TYPE_CANONICAL (c) = c;
    9485            0 :                       x = c;
    9486              :                     }
    9487              :                 }
    9488              :               else
    9489          422 :                 TYPE_CANONICAL (x) = TYPE_CANONICAL (c);
    9490              :             }
    9491              :         }
    9492      1203560 :       else if (x != t)
    9493            0 :         continue;
    9494      1299663 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9495              :         {
    9496        69130 :           if (!TYPE_STRUCTURAL_EQUALITY_P (p))
    9497            0 :             continue;
    9498        69130 :           if (TYPE_CANONICAL (x) != x || TYPE_REF_CAN_ALIAS_ALL (p))
    9499        67022 :             TYPE_CANONICAL (p)
    9500       134044 :               = c_build_pointer_type_for_mode (TYPE_CANONICAL (x), TYPE_MODE (p),
    9501              :                                                false);
    9502              :           else
    9503         2108 :             TYPE_CANONICAL (p) = p;
    9504        69130 :           c_update_type_canonical (p);
    9505              :         }
    9506              :     }
    9507      1203560 : }
    9508              : 
    9509              : 
    9510              : /* We set C_TYPE_VARIABLY_MODIFIED for derived types.  We will not update
    9511              :    array types, pointers to array types, function types and other derived
    9512              :    types created while the type was still incomplete.  We need to update
    9513              :    at least all types for which TYPE_CANONICAL will bet set, because for
    9514              :    those we later assume (in c_variably_modified_p) that the bit is
    9515              :    up-to-date.  */
    9516              : 
    9517              : static void
    9518          734 : c_update_variably_modified (tree t)
    9519              : {
    9520         1477 :   for (tree x = t; x; x = TYPE_NEXT_VARIANT (x))
    9521              :     {
    9522          743 :       C_TYPE_VARIABLY_MODIFIED (x) = 1;
    9523          761 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9524           18 :         c_update_variably_modified (p);
    9525              :     }
    9526          734 : }
    9527              : 
    9528              : 
    9529              : /* Verify the argument of the counted_by attribute of each field of
    9530              :    the containing structure, OUTMOST_STRUCT_TYPE, including its inner
    9531              :    anonymous struct/union, Report error and remove the corresponding
    9532              :    attribute when it's not.  */
    9533              : 
    9534              : static void
    9535          531 : verify_counted_by_attribute (tree outmost_struct_type,
    9536              :                              tree cur_struct_type)
    9537              : {
    9538         1709 :   for (tree field = TYPE_FIELDS (cur_struct_type); field;
    9539         1178 :        field = TREE_CHAIN (field))
    9540              :     {
    9541         1178 :       if (c_flexible_array_member_type_p (TREE_TYPE (field))
    9542         1178 :            || TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
    9543              :         {
    9544          401 :           tree attr_counted_by = lookup_attribute ("counted_by",
    9545          401 :                                                    DECL_ATTRIBUTES (field));
    9546              : 
    9547          401 :           if (!attr_counted_by)
    9548            1 :             continue;
    9549              : 
    9550              :           /* If there is an counted_by attribute attached to the field,
    9551              :              verify it.  */
    9552              : 
    9553          400 :           tree fieldname = TREE_VALUE (TREE_VALUE (attr_counted_by));
    9554              : 
    9555              :           /* Verify the argument of the attribute is a valid field of the
    9556              :              containing structure.  */
    9557              : 
    9558          400 :           tree counted_by_field = lookup_field (outmost_struct_type,
    9559              :                                                 fieldname);
    9560              : 
    9561              :           /* Error when the field is not found in the containing structure
    9562              :              and remove the corresponding counted_by attribute from the
    9563              :              field_decl.  */
    9564          400 :           if (!counted_by_field)
    9565              :             {
    9566           24 :               error_at (DECL_SOURCE_LOCATION (field),
    9567              :                     "argument %qE to the %<counted_by%> attribute"
    9568              :                     " is not a field declaration in the same structure"
    9569              :                     " as %qD", fieldname, field);
    9570           24 :               DECL_ATTRIBUTES (field)
    9571           48 :                 = remove_attribute ("counted_by", DECL_ATTRIBUTES (field));
    9572              :             }
    9573              :           else
    9574              :           /* Error when the field is not with an integer type.  */
    9575              :             {
    9576          577 :               while (TREE_CHAIN (counted_by_field))
    9577          201 :                 counted_by_field = TREE_CHAIN (counted_by_field);
    9578          376 :               tree real_field = TREE_VALUE (counted_by_field);
    9579              : 
    9580          376 :               if (!INTEGRAL_TYPE_P (TREE_TYPE (real_field)))
    9581              :                 {
    9582            6 :                   error_at (DECL_SOURCE_LOCATION (field),
    9583              :                         "argument %qE to the %<counted_by%> attribute"
    9584              :                         " is not a field declaration with an integer type",
    9585              :                         fieldname);
    9586            6 :                   DECL_ATTRIBUTES (field)
    9587           12 :                     = remove_attribute ("counted_by",
    9588            6 :                                     DECL_ATTRIBUTES (field));
    9589              :                 }
    9590              :             }
    9591              :         }
    9592         1457 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    9593          868 :                && (DECL_NAME (field) == NULL_TREE))
    9594          188 :         verify_counted_by_attribute (outmost_struct_type, TREE_TYPE (field));
    9595              :     }
    9596          531 : }
    9597              : 
    9598              : /* Caller should make sure the TYPE is a top-level type (i.e. not being
    9599              :    nested in other structure/uniona). For such type, verify its counted_by
    9600              :    if it is an anonymous structure/union.  */
    9601              : 
    9602              : void
    9603      1356155 : verify_counted_by_for_top_anonymous_type (tree type)
    9604              : {
    9605      1356155 :   if (!RECORD_OR_UNION_TYPE_P (type))
    9606              :     return;
    9607              : 
    9608      1172831 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (type)
    9609      1172831 :       && c_type_tag (type) == NULL_TREE)
    9610           48 :     verify_counted_by_attribute (type, type);
    9611              : }
    9612              : 
    9613              : /* TYPE is a struct or union that we're applying may_alias to after the body is
    9614              :    parsed.  Fixup any POINTER_TO types.  */
    9615              : 
    9616              : static void
    9617          358 : c_fixup_may_alias (tree type)
    9618              : {
    9619          423 :   for (tree t = TYPE_POINTER_TO (type); t; t = TYPE_NEXT_PTR_TO (t))
    9620          190 :     for (tree v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    9621          125 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    9622          358 : }
    9623              : 
    9624              : /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
    9625              :    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
    9626              :    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
    9627              :    ATTRIBUTES are attributes to be applied to the structure.
    9628              : 
    9629              :    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
    9630              :    the struct was started.  */
    9631              : 
    9632              : tree
    9633      1183598 : finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
    9634              :                class c_struct_parse_info *enclosing_struct_parse_info,
    9635              :                tree *expr)
    9636              : {
    9637      1183598 :   tree x;
    9638      1183598 :   bool toplevel = file_scope == current_scope;
    9639              : 
    9640              :   /* If this type was previously laid out as a forward reference,
    9641              :      make sure we lay it out again.  */
    9642              : 
    9643      1183598 :   TYPE_SIZE (t) = NULL_TREE;
    9644              : 
    9645      1183598 :   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    9646              : 
    9647      1183598 :   if (pedantic)
    9648              :     {
    9649         6871 :       for (x = fieldlist; x; x = DECL_CHAIN (x))
    9650              :         {
    9651         6852 :           if (DECL_NAME (x) != NULL_TREE)
    9652              :             break;
    9653           25 :           if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9654              :             break;
    9655              :         }
    9656              : 
    9657         6853 :       if (x == NULL_TREE)
    9658              :         {
    9659           19 :           if (TREE_CODE (t) == UNION_TYPE)
    9660              :             {
    9661            5 :               if (fieldlist)
    9662            2 :                 pedwarn (loc, OPT_Wpedantic, "union has no named members");
    9663              :               else
    9664            3 :                 pedwarn (loc, OPT_Wpedantic, "union has no members");
    9665              :             }
    9666              :           else
    9667              :             {
    9668           14 :               if (fieldlist)
    9669            3 :                 pedwarn (loc, OPT_Wpedantic, "struct has no named members");
    9670              :               else
    9671           11 :                 pedwarn (loc, OPT_Wpedantic, "struct has no members");
    9672              :             }
    9673              :         }
    9674              :     }
    9675              : 
    9676              :   /* Install struct as DECL_CONTEXT of each field decl.
    9677              :      Also process specified field sizes, found in the DECL_INITIAL,
    9678              :      storing 0 there after the type has been changed to precision equal
    9679              :      to its width, rather than the precision of the specified standard
    9680              :      type.  (Correct layout requires the original type to have been preserved
    9681              :      until now.)  */
    9682              : 
    9683              :   bool saw_named_field = false;
    9684      5508159 :   for (x = fieldlist; x; x = DECL_CHAIN (x))
    9685              :     {
    9686              :       /* Whether this field is the last field of the structure or union.
    9687              :          for UNION, any field is the last field of it.  */
    9688      4324561 :       bool is_last_field = (DECL_CHAIN (x) == NULL_TREE)
    9689      4324561 :                             || (TREE_CODE (t) == UNION_TYPE);
    9690              : 
    9691      4324561 :       if (TREE_TYPE (x) == error_mark_node)
    9692           40 :         continue;
    9693              : 
    9694      4324521 :       DECL_CONTEXT (x) = t;
    9695              : 
    9696      4324521 :       tree t1 = strip_array_types (TREE_TYPE (x));
    9697              :       /* If any field is const, the structure type is pseudo-const.  */
    9698      4324521 :       if (TREE_READONLY (x))
    9699        64244 :         C_TYPE_FIELDS_READONLY (t) = 1;
    9700              :       else
    9701              :         {
    9702              :           /* A field that is pseudo-const makes the structure likewise.  */
    9703      4260277 :           if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1))
    9704          641 :             C_TYPE_FIELDS_READONLY (t) = 1;
    9705              :         }
    9706              : 
    9707              :       /* Any field that is volatile means variables of this type must be
    9708              :          treated in some ways as volatile.  */
    9709      4324521 :       if (TREE_THIS_VOLATILE (x))
    9710              :         {
    9711          475 :           C_TYPE_FIELDS_VOLATILE (t) = 1;
    9712          475 :           C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9713              :         }
    9714              : 
    9715              :       /* Any field that is volatile, restrict-qualified or atomic
    9716              :          means the type cannot be used for a constexpr object.  */
    9717      4324521 :       if (TYPE_QUALS (t1)
    9718      4324521 :           & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    9719         1461 :         C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9720      4323060 :       else if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_NON_CONSTEXPR (t1))
    9721          179 :             C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9722              : 
    9723              :       /* Any field of nominal variable size implies structure is too.  */
    9724      4324521 :       if (C_DECL_VARIABLE_SIZE (x))
    9725          698 :         C_TYPE_VARIABLE_SIZE (t) = 1;
    9726              : 
    9727              :       /* If any field is variably modified, record this fact. */
    9728      4324521 :       if (c_type_variably_modified_p (TREE_TYPE (x)))
    9729          777 :         C_TYPE_VARIABLY_MODIFIED (t) = 1;
    9730              : 
    9731      4324521 :       if (DECL_C_BIT_FIELD (x))
    9732              :         {
    9733        52806 :           unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
    9734        52806 :           DECL_SIZE (x) = bitsize_int (width);
    9735        52806 :           DECL_BIT_FIELD (x) = 1;
    9736              :         }
    9737              : 
    9738      4324521 :       if (TYPE_PACKED (t)
    9739      4330075 :           && (DECL_BIT_FIELD (x)
    9740         3236 :               || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
    9741         4443 :         DECL_PACKED (x) = 1;
    9742              : 
    9743              :       /* Detect flexible array member in an invalid context.  */
    9744      4324521 :       if (c_flexible_array_member_type_p (TREE_TYPE (x)))
    9745              :         {
    9746        86021 :           if (TREE_CODE (t) == UNION_TYPE)
    9747           31 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9748              :                      "flexible array member in union is a GCC extension");
    9749        85990 :           else if (!is_last_field)
    9750              :             {
    9751            3 :               error_at (DECL_SOURCE_LOCATION (x),
    9752              :                         "flexible array member not at end of struct");
    9753            3 :               TREE_TYPE (x) = error_mark_node;
    9754              :             }
    9755        85987 :           else if (!saw_named_field)
    9756           37 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9757              :                      "flexible array member in a struct with no named "
    9758              :                      "members is a GCC extension");
    9759        86021 :           if (lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9760          133 :             C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9761              :         }
    9762              : 
    9763      4324521 :       if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE
    9764      4324521 :           && lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9765          267 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9766              : 
    9767              :       /* If the field is an anonymous structure that includes a field
    9768              :          with counted_by attribute, this structure should also be marked
    9769              :          too.  */
    9770      8270868 :       if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9771       468977 :           && C_TYPE_FIELDS_HAS_COUNTED_BY (TREE_TYPE (x))
    9772           18 :           && DECL_NAME (x) == NULL_TREE
    9773      4324534 :           && c_type_tag (TREE_TYPE (x)) == NULL_TREE)
    9774           12 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9775              : 
    9776        23108 :       if (pedantic && TREE_CODE (t) == RECORD_TYPE
    9777      4343674 :           && flexible_array_type_p (TREE_TYPE (x)))
    9778           18 :         pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9779              :                  "invalid use of structure with flexible array member");
    9780              : 
    9781              :       /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x.  */
    9782      4324521 :       DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x);
    9783              : 
    9784              :       /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t.
    9785              :          when x is an array and is the last field.
    9786              :          There is only one last_field for a structure type, but there might
    9787              :          be multiple last_fields for a union type, therefore we should ORed
    9788              :          the result for multiple last_fields.  */
    9789      4324521 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    9790       693343 :         TYPE_INCLUDES_FLEXARRAY (t)
    9791      1386686 :           |= is_last_field && c_flexible_array_member_type_p (TREE_TYPE (x));
    9792              :       /* Recursively set TYPE_INCLUDES_FLEXARRAY for the context of x, t
    9793              :          when x is an union or record and is the last field.  */
    9794      3631178 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9795       468977 :         TYPE_INCLUDES_FLEXARRAY (t)
    9796       937954 :           |= is_last_field && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x));
    9797              : 
    9798      4324521 :       if (warn_flex_array_member_not_at_end
    9799           56 :           && !is_last_field
    9800           22 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9801      4324533 :           && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x)))
    9802            5 :         warning_at (DECL_SOURCE_LOCATION (x),
    9803            5 :                     OPT_Wflex_array_member_not_at_end,
    9804              :                     "structure containing a flexible array member"
    9805              :                     " is not at the end of another structure");
    9806              : 
    9807      4324521 :       if (DECL_NAME (x)
    9808      4324521 :           || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9809              :         saw_named_field = true;
    9810              : 
    9811      7955699 :       if (AGGREGATE_TYPE_P (TREE_TYPE (x))
    9812      4793498 :           && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
    9813       419279 :         TYPE_TYPELESS_STORAGE (t) = true;
    9814              :     }
    9815              : 
    9816      1183598 :   detect_field_duplicates (fieldlist);
    9817              : 
    9818              :   /* Now we have the nearly final fieldlist.  Record it,
    9819              :      then lay out the structure or union (including the fields).  */
    9820              : 
    9821      1183598 :   TYPE_FIELDS (t) = fieldlist;
    9822              : 
    9823      1183598 :   maybe_apply_pragma_scalar_storage_order (t);
    9824              : 
    9825      1183598 :   layout_type (t);
    9826              : 
    9827      1183598 :   if (TYPE_SIZE_UNIT (t)
    9828      1183598 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    9829      1182955 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    9830      2366553 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    9831            1 :     error ("type %qT is too large", t);
    9832              : 
    9833              :   /* Give bit-fields their proper types and rewrite the type of array fields
    9834              :      with scalar component if the enclosing type has reverse storage order.  */
    9835      5508159 :   for (tree field = fieldlist; field; field = DECL_CHAIN (field))
    9836              :     {
    9837      4324561 :       if (TREE_CODE (field) == FIELD_DECL
    9838      4324561 :           && DECL_INITIAL (field)
    9839      4377377 :           && TREE_TYPE (field) != error_mark_node)
    9840              :         {
    9841        52806 :           unsigned HOST_WIDE_INT width
    9842        52806 :             = tree_to_uhwi (DECL_INITIAL (field));
    9843        52806 :           tree type = TREE_TYPE (field);
    9844        52806 :           if (VECTOR_TYPE_P (type))
    9845              :             {
    9846            2 :               error_at (DECL_SOURCE_LOCATION (field),
    9847              :                         "bit-field %qD has invalid type", field);
    9848            2 :               type = TREE_TYPE (type);
    9849            2 :               TREE_TYPE (field) = type;
    9850              :             }
    9851        52806 :           if (width != TYPE_PRECISION (type))
    9852              :             {
    9853        37918 :               if (BITINT_TYPE_P (type)
    9854        38198 :                   && width >= ((TYPE_UNSIGNED (type) || flag_isoc2y) ? 1 : 2))
    9855          171 :                 TREE_TYPE (field)
    9856          342 :                   = build_bitint_type (width, TYPE_UNSIGNED (type));
    9857              :               else
    9858        37912 :                 TREE_TYPE (field)
    9859        37912 :                   = c_build_bitfield_integer_type (width,
    9860        37912 :                                                    TYPE_UNSIGNED (type));
    9861        38083 :               if (tree attr = c_hardbool_type_attr (type))
    9862          281 :                 decl_attributes (&TREE_TYPE (field),
    9863              :                                  copy_list (attr),
    9864              :                                  0, NULL_TREE);
    9865        38083 :               SET_DECL_MODE (field, TYPE_MODE (TREE_TYPE (field)));
    9866              :             }
    9867        52806 :           DECL_INITIAL (field) = NULL_TREE;
    9868              :         }
    9869      4271755 :       else if (TYPE_REVERSE_STORAGE_ORDER (t)
    9870          695 :                && TREE_CODE (field) == FIELD_DECL
    9871      4272450 :                && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
    9872              :         {
    9873          107 :           tree ftype = TREE_TYPE (field);
    9874          107 :           tree ctype = strip_array_types (ftype);
    9875          107 :           if (!RECORD_OR_UNION_TYPE_P (ctype) && TYPE_MODE (ctype) != QImode)
    9876              :             {
    9877           94 :               tree fmain_type = TYPE_MAIN_VARIANT (ftype);
    9878           94 :               tree *typep = &fmain_type;
    9879           96 :               do {
    9880           96 :                 *typep = build_distinct_type_copy (*typep);
    9881           96 :                 TYPE_REVERSE_STORAGE_ORDER (*typep) = 1;
    9882           96 :                 typep = &TREE_TYPE (*typep);
    9883           96 :               } while (TREE_CODE (*typep) == ARRAY_TYPE);
    9884           94 :               TREE_TYPE (field)
    9885          188 :                 = c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
    9886              :             }
    9887              :         }
    9888              : 
    9889              :       /* Warn on problematic type punning for storage order purposes.  */
    9890      4324561 :       if (TREE_CODE (t) == UNION_TYPE
    9891       857119 :           && TREE_CODE (field) == FIELD_DECL
    9892      5181680 :           && AGGREGATE_TYPE_P (TREE_TYPE (field)))
    9893              :         {
    9894       426460 :           tree ftype = TREE_TYPE (field);
    9895       426460 :           if (TREE_CODE (ftype) == ARRAY_TYPE)
    9896       313894 :             ftype = strip_array_types (ftype);
    9897       426460 :           if (RECORD_OR_UNION_TYPE_P (ftype)
    9898       426460 :               && TYPE_REVERSE_STORAGE_ORDER (ftype)
    9899       113060 :                  != TYPE_REVERSE_STORAGE_ORDER (t))
    9900            1 :             warning_at (DECL_SOURCE_LOCATION (field),
    9901            1 :                         OPT_Wscalar_storage_order,
    9902              :                         "type punning toggles scalar storage order");
    9903              :         }
    9904              :     }
    9905              : 
    9906              :   /* Now we have the truly final field list.
    9907              :      Store it in this type and in the variants.  */
    9908              : 
    9909      1183598 :   TYPE_FIELDS (t) = fieldlist;
    9910              : 
    9911              :   /* If there are lots of fields, sort so we can look through them fast.
    9912              :      We arbitrarily consider 16 or more elts to be "a lot".  */
    9913              : 
    9914      1183598 :   {
    9915      1183598 :     int len = 0;
    9916              : 
    9917      5064838 :     for (x = fieldlist; x; x = DECL_CHAIN (x))
    9918              :       {
    9919      3908946 :         if (len > 15 || DECL_NAME (x) == NULL)
    9920              :           break;
    9921      3881240 :         len += 1;
    9922              :       }
    9923              : 
    9924      1183598 :     if (len > 15)
    9925              :       {
    9926        22787 :         tree *field_array;
    9927        22787 :         struct lang_type *space;
    9928        22787 :         struct sorted_fields_type *space2;
    9929              : 
    9930        22787 :         len += list_length (x);
    9931              : 
    9932              :         /* Use the same allocation policy here that make_node uses, to
    9933              :            ensure that this lives as long as the rest of the struct decl.
    9934              :            All decls in an inline function need to be saved.  */
    9935              : 
    9936        22787 :         space = ((struct lang_type *)
    9937        22787 :                  ggc_internal_cleared_alloc (c_dialect_objc ()
    9938              :                                              ? sizeof (struct lang_type)
    9939              :                                              : offsetof (struct lang_type,
    9940              :                                                          info)));
    9941        22787 :         space2 = ((sorted_fields_type *)
    9942        45574 :                   ggc_internal_alloc (sizeof (struct sorted_fields_type)
    9943        22787 :                                       + len * sizeof (tree)));
    9944              : 
    9945        22787 :         len = 0;
    9946        22787 :         space->s = space2;
    9947        22787 :         field_array = &space2->elts[0];
    9948       797008 :         for (x = fieldlist; x; x = DECL_CHAIN (x))
    9949              :           {
    9950       777592 :             field_array[len++] = x;
    9951              : 
    9952              :             /* If there is anonymous struct or union, break out of the loop.  */
    9953       777592 :             if (DECL_NAME (x) == NULL)
    9954              :               break;
    9955              :           }
    9956              :         /* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
    9957        22787 :         if (x == NULL)
    9958              :           {
    9959        19416 :             TYPE_LANG_SPECIFIC (t) = space;
    9960        19416 :             TYPE_LANG_SPECIFIC (t)->s->len = len;
    9961        19416 :             field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
    9962        19416 :             qsort (field_array, len, sizeof (tree), field_decl_cmp);
    9963              :           }
    9964              :       }
    9965              :   }
    9966              : 
    9967              :   /* If this was supposed to be a transparent union, but we can't
    9968              :      make it one, warn and turn off the flag.  */
    9969      1183598 :   if (TREE_CODE (t) == UNION_TYPE
    9970       379059 :       && TYPE_TRANSPARENT_AGGR (t)
    9971      1183643 :       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
    9972              :     {
    9973           13 :       TYPE_TRANSPARENT_AGGR (t) = 0;
    9974           13 :       warning_at (loc, 0, "union cannot be made transparent");
    9975              :     }
    9976              : 
    9977      1183598 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
    9978      2398182 :   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
    9979              :     {
    9980      1214584 :       TYPE_FIELDS (x) = TYPE_FIELDS (t);
    9981      1214584 :       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
    9982      1214584 :       TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
    9983      1214584 :       TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
    9984      1214584 :       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
    9985      1214584 :       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
    9986      1214584 :       C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);
    9987      1214584 :       C_TYPE_FIELDS_HAS_COUNTED_BY (x) = C_TYPE_FIELDS_HAS_COUNTED_BY (t);
    9988      1214584 :       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
    9989      1214584 :       C_TYPE_VARIABLY_MODIFIED (x) = C_TYPE_VARIABLY_MODIFIED (t);
    9990      1214584 :       C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
    9991      1214584 :       TYPE_INCLUDES_FLEXARRAY (x) = TYPE_INCLUDES_FLEXARRAY (t);
    9992              :     }
    9993              : 
    9994              :   /* Check for consistency with previous definition.  */
    9995      1183598 :   if (flag_isoc23 && NULL != enclosing_struct_parse_info)
    9996              :     {
    9997       915749 :       tree vistype = previous_tag (t);
    9998       915749 :       if (vistype
    9999          128 :           && TREE_CODE (vistype) == TREE_CODE (t)
   10000       915877 :           && !C_TYPE_BEING_DEFINED (vistype))
   10001              :         {
   10002          108 :           TYPE_STUB_DECL (t) = TYPE_STUB_DECL (vistype);
   10003          108 :           if (c_type_variably_modified_p (t))
   10004              :             {
   10005            7 :               error ("redefinition of struct or union %qT with variably "
   10006              :                      "modified type", t);
   10007            7 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10008            7 :                 inform (struct_parse_info->refloc, "originally defined here");
   10009              :             }
   10010          101 :           else if (!comptypes_same_p (t, vistype))
   10011              :             {
   10012           38 :               error ("redefinition of struct or union %qT", t);
   10013           38 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10014           38 :                 inform (struct_parse_info->refloc, "originally defined here");
   10015              :             }
   10016              :         }
   10017              :     }
   10018              : 
   10019      1183598 :   C_TYPE_BEING_DEFINED (t) = 0;
   10020              : 
   10021      1183598 :   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
   10022          684 :     for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
   10023          358 :       c_fixup_may_alias (x);
   10024              : 
   10025              :   /* Set type canonical based on equivalence class.  */
   10026      1183598 :   if (flag_isoc23 && !C_TYPE_VARIABLE_SIZE (t))
   10027              :     {
   10028       951227 :       if (c_struct_htab == NULL)
   10029        35712 :         c_struct_htab = hash_table<c_struct_hasher>::create_ggc (61);
   10030              : 
   10031       951227 :       hashval_t hash = c_struct_hasher::hash (t);
   10032              : 
   10033       951227 :       gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
   10034       951227 :       gcc_checking_assert (!TYPE_NAME (t)
   10035              :                            || TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE);
   10036              : 
   10037       951227 :       tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT);
   10038       951227 :       if (*e)
   10039        63057 :         TYPE_CANONICAL (t) = TYPE_CANONICAL (*e);
   10040              :       else
   10041              :         {
   10042       888170 :           TYPE_CANONICAL (t) = c_type_canonical (t);
   10043       888170 :           *e = t;
   10044              :         }
   10045       951227 :       c_update_type_canonical (t);
   10046              :     }
   10047              : 
   10048              :   /* Update type location to the one of the definition, instead of e.g.
   10049              :      a forward declaration.  */
   10050      1183598 :   if (TYPE_STUB_DECL (t))
   10051      1183598 :     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
   10052              : 
   10053              :   /* Finish debugging output for this type.  */
   10054      1183598 :   rest_of_type_compilation (t, toplevel);
   10055              : 
   10056      1183598 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10057              : 
   10058              : 
   10059      1183598 :   if (c_type_variably_modified_p (t))
   10060              :     {
   10061          716 :       c_update_variably_modified (t);
   10062              :       /* Make sure a DECL_EXPR is created for structs with VLA members.
   10063              :          Because we do not know the context, we always pass expr
   10064              :          to force creation of a BIND_EXPR which is required in some
   10065              :          contexts.  */
   10066          716 :       add_decl_expr (loc, t, expr, false);
   10067              :     }
   10068              : 
   10069      1183598 :   if (warn_cxx_compat)
   10070          577 :     warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
   10071              : 
   10072      1183598 :   if (NULL != enclosing_struct_parse_info)
   10073              :     {
   10074      1142901 :       delete struct_parse_info;
   10075              : 
   10076      1142901 :       struct_parse_info = enclosing_struct_parse_info;
   10077              : 
   10078              :       /* If this struct is defined inside a struct, add it to
   10079              :          struct_types.  */
   10080      1142901 :       if (warn_cxx_compat
   10081              :           && struct_parse_info != NULL
   10082          350 :           && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10083          345 :         struct_parse_info->struct_types.safe_push (t);
   10084              :      }
   10085              : 
   10086              :   /* Only when the enclosing struct/union type is not anonymous, do more
   10087              :      verification on the fields with counted_by attributes.  */
   10088      1183598 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (t) && c_type_tag (t) != NULL_TREE)
   10089          295 :     verify_counted_by_attribute (t, t);
   10090              : 
   10091      1183598 :   return t;
   10092              : }
   10093              : 
   10094              : static struct {
   10095              :   gt_pointer_operator new_value;
   10096              :   void *cookie;
   10097              : } resort_data;
   10098              : 
   10099              : /* This routine compares two fields like field_decl_cmp but using the
   10100              : pointer operator in resort_data.  */
   10101              : 
   10102              : static int
   10103         5393 : resort_field_decl_cmp (const void *x_p, const void *y_p)
   10104              : {
   10105         5393 :   const tree *const x = (const tree *) x_p;
   10106         5393 :   const tree *const y = (const tree *) y_p;
   10107              : 
   10108         5393 :   if (DECL_NAME (*x) == DECL_NAME (*y))
   10109              :     /* A nontype is "greater" than a type.  */
   10110            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
   10111         5393 :   if (DECL_NAME (*x) == NULL_TREE)
   10112              :     return -1;
   10113         5393 :   if (DECL_NAME (*y) == NULL_TREE)
   10114              :     return 1;
   10115         5393 :   {
   10116         5393 :     tree d1 = DECL_NAME (*x);
   10117         5393 :     tree d2 = DECL_NAME (*y);
   10118         5393 :     resort_data.new_value (&d1, &d1, resort_data.cookie);
   10119         5393 :     resort_data.new_value (&d2, &d2, resort_data.cookie);
   10120         5393 :     if (d1 < d2)
   10121         2707 :       return -1;
   10122              :   }
   10123         2686 :   return 1;
   10124              : }
   10125              : 
   10126              : /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
   10127              : 
   10128              : void
   10129            6 : resort_sorted_fields (void *obj,
   10130              :                       void * ARG_UNUSED (orig_obj),
   10131              :                       gt_pointer_operator new_value,
   10132              :                       void *cookie)
   10133              : {
   10134            6 :   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
   10135            6 :   resort_data.new_value = new_value;
   10136            6 :   resort_data.cookie = cookie;
   10137            6 :   qsort (&sf->elts[0], sf->len, sizeof (tree),
   10138              :          resort_field_decl_cmp);
   10139            6 : }
   10140              : 
   10141              : /* Lay out the type T, and its element type, and so on.  */
   10142              : 
   10143              : static void
   10144            0 : layout_array_type (tree t)
   10145              : {
   10146            0 :   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   10147            0 :     layout_array_type (TREE_TYPE (t));
   10148            0 :   layout_type (t);
   10149            0 : }
   10150              : 
   10151              : /* Begin compiling the definition of an enumeration type.
   10152              :    NAME is its name (or null if anonymous).
   10153              :    LOC is the enum's location.
   10154              :    FIXED_UNDERLYING_TYPE is the (C23) underlying type specified in the
   10155              :    definition.
   10156              :    Returns the type object, as yet incomplete.
   10157              :    Also records info about it so that build_enumerator
   10158              :    may be used to declare the individual values as they are read.  */
   10159              : 
   10160              : tree
   10161       183331 : start_enum (location_t loc, struct c_enum_contents *the_enum, tree name,
   10162              :             tree fixed_underlying_type, bool potential_nesting_p)
   10163              : {
   10164       183331 :   tree enumtype = NULL_TREE;
   10165       183331 :   location_t enumloc = UNKNOWN_LOCATION;
   10166              : 
   10167              :   /* If this is the real definition for a previous forward reference,
   10168              :      fill in the contents in the same object that used to be the
   10169              :      forward reference.  */
   10170              : 
   10171       183331 :   if (name != NULL_TREE)
   10172        73056 :     enumtype = lookup_tag (ENUMERAL_TYPE, name, true, &enumloc);
   10173              : 
   10174        73056 :   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   10175              :     {
   10176              :       /* If the type is currently being defined or if we have seen an
   10177              :          incomplete version which is now complete, this is a nested
   10178              :          redefinition.  The later happens if the redefinition occurs
   10179              :          inside the enum specifier itself.  */
   10180          199 :       if (C_TYPE_BEING_DEFINED (enumtype)
   10181          199 :           || (potential_nesting_p && TYPE_VALUES (enumtype) != NULL_TREE))
   10182            9 :         error_at (loc, "nested redefinition of %<enum %E%>", name);
   10183              : 
   10184              :       /* For C23 we allow redefinitions.  We set to zero and check for
   10185              :          consistency later.  */
   10186          381 :       if (flag_isoc23 && TYPE_VALUES (enumtype) != NULL_TREE)
   10187              :         enumtype = NULL_TREE;
   10188              :     }
   10189              : 
   10190       110448 :   if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   10191              :     {
   10192       183160 :       enumtype = make_node (ENUMERAL_TYPE);
   10193       183160 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10194       183160 :       SET_TYPE_STRUCTURAL_EQUALITY (enumtype);
   10195       183160 :       pushtag (loc, name, enumtype);
   10196       183160 :       if (fixed_underlying_type != NULL_TREE)
   10197              :         {
   10198              :           /* For an enum definition with a fixed underlying type, the
   10199              :              type is complete during the definition and the
   10200              :              enumeration constants have that type.  If there was a
   10201              :              tag, the type was completed in c_parser_enum_specifier.
   10202              :              If not, it must be completed here.  */
   10203           12 :           ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = true;
   10204           12 :           TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (fixed_underlying_type);
   10205           12 :           TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (fixed_underlying_type);
   10206           12 :           TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (fixed_underlying_type);
   10207           12 :           SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (fixed_underlying_type));
   10208           12 :           TYPE_SIZE (enumtype) = NULL_TREE;
   10209           12 :           TYPE_PRECISION (enumtype) = TYPE_PRECISION (fixed_underlying_type);
   10210           12 :           ENUM_UNDERLYING_TYPE (enumtype) = fixed_underlying_type;
   10211           12 :           TYPE_CANONICAL (enumtype) = TYPE_CANONICAL (fixed_underlying_type);
   10212           12 :           c_update_type_canonical (enumtype);
   10213           12 :           layout_type (enumtype);
   10214              :         }
   10215              :     }
   10216              :   /* Update type location to the one of the definition, instead of e.g.
   10217              :      a forward declaration.  */
   10218          171 :   else if (TYPE_STUB_DECL (enumtype))
   10219              :     {
   10220          171 :       enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
   10221          171 :       DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
   10222              :     }
   10223              : 
   10224       183331 :   C_TYPE_BEING_DEFINED (enumtype) = 1;
   10225              : 
   10226       183331 :   if (TYPE_VALUES (enumtype) != NULL_TREE)
   10227              :     {
   10228              :       /* This enum is a named one that has been declared already.  */
   10229            6 :       auto_diagnostic_group d;
   10230            6 :       error_at (loc, "redeclaration of %<enum %E%>", name);
   10231            6 :       if (enumloc != UNKNOWN_LOCATION)
   10232            6 :         inform (enumloc, "originally defined here");
   10233              : 
   10234              :       /* Completely replace its old definition.
   10235              :          The old enumerators remain defined, however.  */
   10236            6 :       TYPE_VALUES (enumtype) = NULL_TREE;
   10237            6 :     }
   10238              : 
   10239       183331 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype)
   10240       183331 :       && fixed_underlying_type == NULL_TREE)
   10241              :     {
   10242            3 :       error_at (loc, "%<enum%> declared with but defined without "
   10243              :                 "fixed underlying type");
   10244            3 :       ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false;
   10245              :     }
   10246              : 
   10247       183331 :   the_enum->enum_next_value = integer_zero_node;
   10248       183331 :   the_enum->enum_type = enumtype;
   10249       183331 :   the_enum->enum_overflow = 0;
   10250              : 
   10251       183331 :   if (flag_short_enums && !ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10252          106 :     for (tree v = TYPE_MAIN_VARIANT (enumtype); v; v = TYPE_NEXT_VARIANT (v))
   10253           53 :       TYPE_PACKED (v) = 1;
   10254              : 
   10255              :   /* FIXME: This will issue a warning for a use of a type defined
   10256              :      within sizeof in a statement expr.  This is not terribly serious
   10257              :      as C++ doesn't permit statement exprs within sizeof anyhow.  */
   10258       183331 :   if (warn_cxx_compat
   10259          136 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
   10260            0 :     warning_at (loc, OPT_Wc___compat,
   10261              :                 "defining type in %qs expression is invalid in C++",
   10262              :                 (in_sizeof ? "sizeof"
   10263            0 :                  : in_typeof ? "typeof"
   10264            0 :                  : in_alignof ? "alignof"
   10265              :                  : "_Countof"));
   10266              : 
   10267       183331 :   if (in_underspecified_init)
   10268            6 :     error_at (loc, "%qT defined in underspecified object initializer",
   10269              :               enumtype);
   10270              : 
   10271       183331 :   return enumtype;
   10272              : }
   10273              : 
   10274              : /* After processing and defining all the values of an enumeration type,
   10275              :    install their decls in the enumeration type and finish it off.
   10276              :    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
   10277              :    and ATTRIBUTES are the specified attributes.
   10278              :    Returns ENUMTYPE.  */
   10279              : 
   10280              : tree
   10281       183331 : finish_enum (tree enumtype, tree values, tree attributes)
   10282              : {
   10283       183331 :   tree pair, tem;
   10284       183331 :   tree minnode = NULL_TREE, maxnode = NULL_TREE;
   10285       183331 :   int precision;
   10286       183331 :   signop sign;
   10287       183331 :   bool toplevel = (file_scope == current_scope);
   10288       183331 :   struct lang_type *lt;
   10289              : 
   10290       183331 :   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
   10291              : 
   10292              :   /* Calculate the maximum value of any enumerator in this type.  */
   10293              : 
   10294       183331 :   if (values == error_mark_node)
   10295           26 :     minnode = maxnode = integer_zero_node;
   10296              :   else
   10297              :     {
   10298       183305 :       minnode = maxnode = TREE_VALUE (values);
   10299      5752987 :       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
   10300              :         {
   10301      5569682 :           tree value = TREE_VALUE (pair);
   10302      5569682 :           if (tree_int_cst_lt (maxnode, value))
   10303      5420478 :             maxnode = value;
   10304      5569682 :           if (tree_int_cst_lt (value, minnode))
   10305        65323 :             minnode = value;
   10306              :         }
   10307              :     }
   10308              : 
   10309              :   /* Construct the final type of this enumeration.  It is the same
   10310              :      as one of the integral types - the narrowest one that fits, except
   10311              :      that normally we only go as narrow as int - and signed iff any of
   10312              :      the values are negative.  */
   10313       183331 :   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
   10314       183331 :   precision = MAX (tree_int_cst_min_precision (minnode, sign),
   10315              :                    tree_int_cst_min_precision (maxnode, sign));
   10316              : 
   10317       183331 :   bool wider_than_int =
   10318       183331 :     (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
   10319       183331 :      || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode));
   10320              : 
   10321              : 
   10322       183331 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10323              :     {
   10324              :       /* If the precision of the type was specified with an attribute and it
   10325              :          was too small, give an error.  Otherwise, use it.  */
   10326       183191 :       if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes))
   10327              :         {
   10328           23 :           if (precision > TYPE_PRECISION (enumtype))
   10329              :             {
   10330            6 :               TYPE_PRECISION (enumtype) = 0;
   10331            6 :               error ("specified mode too small for enumerated values");
   10332              :             }
   10333              :           else
   10334           17 :             precision = TYPE_PRECISION (enumtype);
   10335              :         }
   10336              :       else
   10337       183168 :         TYPE_PRECISION (enumtype) = 0;
   10338              : 
   10339       183191 :       if (TYPE_PACKED (enumtype)
   10340       183112 :           || precision > TYPE_PRECISION (integer_type_node)
   10341       363258 :           || TYPE_PRECISION (enumtype))
   10342              :         {
   10343         3251 :           tem = c_common_type_for_size (precision, sign == UNSIGNED ? 1 : 0);
   10344         3136 :           if (tem == NULL)
   10345              :             {
   10346              :               /* This should only occur when both signed and unsigned
   10347              :                  values of maximum precision occur among the
   10348              :                  enumerators.  */
   10349            3 :               pedwarn (input_location, 0,
   10350              :                        "enumeration values exceed range of largest integer");
   10351            3 :               tem = widest_integer_literal_type_node;
   10352              :             }
   10353         3133 :           else if (precision > TYPE_PRECISION (intmax_type_node)
   10354            4 :                    && !tree_int_cst_lt (minnode,
   10355            4 :                                         TYPE_MIN_VALUE (intmax_type_node))
   10356         3136 :                    && !tree_int_cst_lt (TYPE_MAX_VALUE (uintmax_type_node),
   10357              :                                         maxnode))
   10358            2 :             pedwarn (input_location, OPT_Wpedantic,
   10359              :                      "enumeration values exceed range of %qs",
   10360              :                      sign == UNSIGNED ? "uintmax_t" : "intmax_t");
   10361              :         }
   10362              :       else
   10363       180055 :         tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
   10364              : 
   10365       183191 :       TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
   10366       183191 :       TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
   10367       183191 :       TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
   10368       183191 :       SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (tem));
   10369       183191 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10370       183191 :       TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
   10371       183191 :       ENUM_UNDERLYING_TYPE (enumtype) =
   10372       183191 :         c_common_type_for_size (TYPE_PRECISION (tem), TYPE_UNSIGNED (tem));
   10373              : 
   10374       549573 :       TYPE_CANONICAL (enumtype) =
   10375       183191 :         TYPE_CANONICAL (ENUM_UNDERLYING_TYPE (enumtype));
   10376       183191 :       c_update_type_canonical (enumtype);
   10377              : 
   10378       183191 :       layout_type (enumtype);
   10379              :     }
   10380              : 
   10381       183331 :   if (values != error_mark_node)
   10382              :     {
   10383              :       /* Change the type of the enumerators to be the enum type.  We
   10384              :          need to do this irrespective of the size of the enum, for
   10385              :          proper type checking.  Replace the DECL_INITIALs of the
   10386              :          enumerators, and the value slots of the list, with copies
   10387              :          that have the enum type; they cannot be modified in place
   10388              :          because they may be shared (e.g.  integer_zero_node) Finally,
   10389              :          change the purpose slots to point to the names of the decls.  */
   10390      5936292 :       for (pair = values; pair; pair = TREE_CHAIN (pair))
   10391              :         {
   10392      5752987 :           tree enu = TREE_PURPOSE (pair);
   10393      5752987 :           tree ini = DECL_INITIAL (enu);
   10394              : 
   10395      5752987 :           TREE_TYPE (enu) = enumtype;
   10396              : 
   10397              :           /* Before C23, the ISO C Standard mandates enumerators to
   10398              :              have type int, even though the underlying type of an enum
   10399              :              type is unspecified.  However, C23 allows enumerators of
   10400              :              any integer type, and if an enumeration has any
   10401              :              enumerators wider than int, all enumerators have the
   10402              :              enumerated type after it is parsed.  Any enumerators that
   10403              :              fit in int are given type int in build_enumerator (which
   10404              :              is the correct type while the enumeration is being
   10405              :              parsed), so no conversions are needed here if all
   10406              :              enumerators fit in int.  If the enum has a fixed
   10407              :              underlying type, the correct type was also given in
   10408              :              build_enumerator.  */
   10409      5752987 :           if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) && wider_than_int)
   10410        34287 :             ini = convert (enumtype, ini);
   10411              : 
   10412      5752987 :           DECL_INITIAL (enu) = ini;
   10413      5752987 :           TREE_PURPOSE (pair) = DECL_NAME (enu);
   10414              :           /* To match the C++ FE, store the CONST_DECL rather than just its
   10415              :              value.  */
   10416      5752987 :           TREE_VALUE (pair) = enu;
   10417              :         }
   10418              : 
   10419       183305 :       TYPE_VALUES (enumtype) = values;
   10420              :     }
   10421              : 
   10422              :   /* Record the min/max values so that we can warn about bit-field
   10423              :      enumerations that are too small for the values.  */
   10424       183331 :   lt = ((struct lang_type *)
   10425       183331 :         ggc_internal_cleared_alloc (c_dialect_objc ()
   10426              :                                     ? sizeof (struct lang_type)
   10427              :                                     : offsetof (struct lang_type, info)));
   10428       183331 :   lt->enum_min = minnode;
   10429       183331 :   lt->enum_max = maxnode;
   10430       183331 :   TYPE_LANG_SPECIFIC (enumtype) = lt;
   10431              : 
   10432              :   /* Fix up all variant types of this enum type.  */
   10433       183331 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (enumtype));
   10434       366672 :   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
   10435              :     {
   10436       183341 :       C_TYPE_INCOMPLETE_VARS (tem) = NULL_TREE;
   10437       183341 :       if (tem == enumtype)
   10438       183331 :         continue;
   10439           10 :       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
   10440           10 :       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
   10441           10 :       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
   10442           10 :       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
   10443           10 :       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
   10444           10 :       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
   10445           10 :       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
   10446           10 :       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
   10447           10 :       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
   10448           10 :       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
   10449           10 :       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
   10450           10 :       ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
   10451           10 :       TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
   10452              :     }
   10453              : 
   10454              :   /* Finish debugging output for this type.  */
   10455       183331 :   rest_of_type_compilation (enumtype, toplevel);
   10456              : 
   10457       183331 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10458              : 
   10459              :   /* If this enum is defined inside a struct, add it to
   10460              :      struct_types.  */
   10461       183331 :   if (warn_cxx_compat
   10462          136 :       && struct_parse_info != NULL
   10463           46 :       && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10464           46 :     struct_parse_info->struct_types.safe_push (enumtype);
   10465              : 
   10466              :   /* Check for consistency with previous definition */
   10467       183331 :   if (flag_isoc23)
   10468              :     {
   10469       145228 :       tree vistype = previous_tag (enumtype);
   10470       145228 :       if (vistype
   10471           33 :           && TREE_CODE (vistype) == TREE_CODE (enumtype)
   10472       145257 :           && !C_TYPE_BEING_DEFINED (vistype))
   10473              :         {
   10474           29 :           TYPE_STUB_DECL (enumtype) = TYPE_STUB_DECL (vistype);
   10475           29 :           if (!comptypes_same_p (enumtype, vistype))
   10476            3 :             error("conflicting redefinition of enum %qT", enumtype);
   10477              :         }
   10478              :     }
   10479              : 
   10480       183331 :   C_TYPE_BEING_DEFINED (enumtype) = 0;
   10481              : 
   10482       183331 :   return enumtype;
   10483              : }
   10484              : 
   10485              : /* Build and install a CONST_DECL for one value of the
   10486              :    current enumeration type (one that was begun with start_enum).
   10487              :    DECL_LOC is the location of the enumerator.
   10488              :    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
   10489              :    Return a tree-list containing the CONST_DECL and its value.
   10490              :    Assignment of sequential values by default is handled here.  */
   10491              : 
   10492              : tree
   10493      5753004 : build_enumerator (location_t decl_loc, location_t loc,
   10494              :                   struct c_enum_contents *the_enum, tree name, tree value)
   10495              : {
   10496      5753004 :   tree decl;
   10497      5753004 :   tree old_decl;
   10498              : 
   10499              :   /* Validate and default VALUE.  */
   10500              : 
   10501      5753004 :   if (value != NULL_TREE)
   10502              :     {
   10503              :       /* Don't issue more errors for error_mark_node (i.e. an
   10504              :          undeclared identifier) - just ignore the value expression.  */
   10505      3572825 :       if (value == error_mark_node)
   10506              :         value = NULL_TREE;
   10507      3572160 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
   10508              :         {
   10509            6 :           error_at (loc, "enumerator value for %qE is not an integer constant",
   10510              :                     name);
   10511            6 :           value = NULL_TREE;
   10512              :         }
   10513              :       else
   10514              :         {
   10515      3572154 :           if (TREE_CODE (value) != INTEGER_CST)
   10516              :             {
   10517           97 :               value = c_fully_fold (value, false, NULL);
   10518           97 :               if (TREE_CODE (value) == INTEGER_CST)
   10519           48 :                 pedwarn (loc, OPT_Wpedantic,
   10520              :                          "enumerator value for %qE is not an integer "
   10521              :                          "constant expression", name);
   10522              :             }
   10523      3572154 :           if (TREE_CODE (value) != INTEGER_CST)
   10524              :             {
   10525           49 :               error ("enumerator value for %qE is not an integer constant",
   10526              :                      name);
   10527           49 :               value = NULL_TREE;
   10528              :             }
   10529              :           else
   10530              :             {
   10531      3572105 :               value = default_conversion (value);
   10532      3572105 :               constant_expression_warning (value);
   10533              :             }
   10534              :         }
   10535              :     }
   10536              : 
   10537              :   /* Default based on previous value.  */
   10538              :   /* It should no longer be possible to have NON_LVALUE_EXPR
   10539              :      in the default.  */
   10540      3572160 :   if (value == NULL_TREE)
   10541              :     {
   10542      2180899 :       value = the_enum->enum_next_value;
   10543      2180899 :       if (the_enum->enum_overflow)
   10544            8 :         error_at (loc, "overflow in enumeration values");
   10545              :     }
   10546      5753004 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10547              :     {
   10548              :       /* Enumeration constants must fit in the fixed underlying type.  */
   10549          205 :       if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (the_enum->enum_type)))
   10550            4 :         error_at (loc,
   10551              :                   "enumerator value outside the range of underlying type");
   10552              :       /* Enumeration constants for an enum with fixed underlying type
   10553              :          have the enum type, both inside and outside the
   10554              :          definition.  */
   10555          205 :       value = convert (the_enum->enum_type, value);
   10556              :     }
   10557      5752799 :   else if (flag_isoc23
   10558      5336032 :            && (old_decl = lookup_name_in_scope (name, current_scope))
   10559           35 :            && old_decl != error_mark_node
   10560           35 :            && TREE_TYPE (old_decl)
   10561           35 :            && TREE_TYPE (TREE_TYPE (old_decl))
   10562      5752833 :            && TREE_CODE (old_decl) == CONST_DECL)
   10563              :     {
   10564              :       /* Enumeration constants in a redeclaration have the previous type.  */
   10565           34 :       tree previous_type = TREE_TYPE (DECL_INITIAL (old_decl));
   10566           34 :       if (!int_fits_type_p (value, previous_type))
   10567              :         {
   10568            2 :           error_at (loc, "value of redeclared enumerator outside the range "
   10569              :                          "of %qT", previous_type);
   10570            2 :           locate_old_decl (old_decl);
   10571              :         }
   10572           34 :       value = convert (previous_type, value);
   10573              :     }
   10574              :   else
   10575              :     {
   10576              :       /* Even though the underlying type of an enum is unspecified, the
   10577              :          type of enumeration constants is explicitly defined as int
   10578              :          (6.4.4.3/2 in the C99 Standard).  C23 allows any integer type, and
   10579              :          GCC allows such types for older standards as an extension.  */
   10580      5752765 :       bool warned_range = false;
   10581      5752765 :       if (!int_fits_type_p (value,
   10582      5752765 :                             (TYPE_UNSIGNED (TREE_TYPE (value))
   10583              :                              ? uintmax_type_node
   10584              :                              : intmax_type_node)))
   10585              :         /* GCC does not consider its types larger than intmax_t to be
   10586              :            extended integer types (although C23 would permit such types to
   10587              :            be considered extended integer types if all the features
   10588              :            required by <stdint.h> and <inttypes.h> macros, such as support
   10589              :            for integer constants and I/O, were present), so diagnose if
   10590              :            such a wider type is used.  (If the wider type arose from a
   10591              :            constant of such a type, that will also have been diagnosed,
   10592              :            but this is the only diagnostic in the case where it arises
   10593              :            from choosing a wider type automatically when adding 1
   10594              :            overflows.)  */
   10595           11 :         warned_range = pedwarn (loc, OPT_Wpedantic,
   10596              :                                 "enumerator value outside the range of %qs",
   10597           11 :                                 TYPE_UNSIGNED (TREE_TYPE (value))
   10598              :                                 ? "uintmax_t"
   10599              :                                 : "intmax_t");
   10600      5752765 :       if (!warned_range && !int_fits_type_p (value, integer_type_node))
   10601         5253 :         pedwarn_c11 (loc, OPT_Wpedantic,
   10602              :                      "ISO C restricts enumerator values to range of %<int%> "
   10603              :                      "before C23");
   10604              : 
   10605              :       /* The ISO C Standard mandates enumerators to have type int before
   10606              :          C23, even though the underlying type of an enum type is
   10607              :          unspecified.  C23 allows enumerators of any integer type.  During
   10608              :          the parsing of the enumeration, C23 specifies that constants
   10609              :          representable in int have type int, constants not representable
   10610              :          in int have the type of the given expression if any, and
   10611              :          constants not representable in int and derived by adding 1 to the
   10612              :          previous constant have the type of that constant unless the
   10613              :          addition would overflow or wraparound, in which case a wider type
   10614              :          of the same signedness is chosen automatically; after the
   10615              :          enumeration is parsed, all the constants have the type of the
   10616              :          enumeration if any do not fit in int.  */
   10617      5752765 :       if (int_fits_type_p (value, integer_type_node))
   10618      5747508 :         value = convert (integer_type_node, value);
   10619              :     }
   10620              : 
   10621              :   /* Set basis for default for next value.  */
   10622      5753004 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10623              :     {
   10624          205 :       tree underlying_type = ENUM_UNDERLYING_TYPE (the_enum->enum_type);
   10625          205 :       if (TREE_CODE (underlying_type) == BOOLEAN_TYPE)
   10626              :         /* A value of 2 following a value of 1 overflows bool, but we
   10627              :            cannot carry out addition directly on bool without
   10628              :            promotion, and converting the result of arithmetic in a
   10629              :            wider type back to bool would not produce the right result
   10630              :            for this overflow check.  */
   10631           61 :         the_enum->enum_next_value = invert_truthvalue_loc (loc, value);
   10632              :       else
   10633          144 :         the_enum->enum_next_value
   10634          144 :           = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10635              :                              PLUS_EXPR, convert (underlying_type, value),
   10636              :                              convert (underlying_type, integer_one_node),
   10637              :                              false);
   10638              :     }
   10639              :   else
   10640              :     {
   10641              :       /* In a redeclaration the type can already be the enumeral type.  */
   10642      5752799 :       if (TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
   10643           12 :         value = convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (value)), value);
   10644      5752799 :       the_enum->enum_next_value
   10645      5752799 :         = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10646              :                            PLUS_EXPR, value, integer_one_node, false);
   10647              :     }
   10648      5753004 :   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
   10649      5753004 :   if (the_enum->enum_overflow
   10650      5753004 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10651              :     {
   10652              :       /* Choose a wider type with the same signedness if
   10653              :          available.  */
   10654         4440 :       int prec = TYPE_PRECISION (TREE_TYPE (value)) + 1;
   10655         4440 :       bool unsignedp = TYPE_UNSIGNED (TREE_TYPE (value));
   10656         4440 :       tree new_type = (unsignedp
   10657         4440 :                        ? long_unsigned_type_node
   10658              :                        : long_integer_type_node);
   10659         4440 :       if (prec > TYPE_PRECISION (new_type))
   10660         3502 :         new_type = (unsignedp
   10661         3502 :                     ? long_long_unsigned_type_node
   10662              :                     : long_long_integer_type_node);
   10663         4440 :       if (prec > TYPE_PRECISION (new_type))
   10664         2928 :         new_type = (unsignedp
   10665         2928 :                     ? widest_unsigned_literal_type_node
   10666              :                     : widest_integer_literal_type_node);
   10667         4440 :       if (prec <= TYPE_PRECISION (new_type))
   10668              :         {
   10669         4435 :           the_enum->enum_overflow = false;
   10670         4435 :           the_enum->enum_next_value
   10671         4435 :             = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10672              :                                PLUS_EXPR, convert (new_type, value),
   10673              :                                integer_one_node, false);
   10674         4435 :           gcc_assert (!tree_int_cst_lt (the_enum->enum_next_value, value));
   10675              :         }
   10676              :     }
   10677              : 
   10678              :   /* Now create a declaration for the enum value name.  */
   10679              : 
   10680      5753004 :   decl = build_decl (decl_loc, CONST_DECL, name, TREE_TYPE (value));
   10681      5753004 :   DECL_INITIAL (decl) = value;
   10682      5753004 :   DECL_CONTEXT (decl) = the_enum->enum_type;
   10683      5753004 :   pushdecl (decl);
   10684              : 
   10685      5753004 :   return tree_cons (decl, value, NULL_TREE);
   10686              : }
   10687              : 
   10688              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   10689              : 
   10690              : tree
   10691            0 : c_simulate_enum_decl (location_t loc, const char *name,
   10692              :                       vec<string_int_pair> *values_ptr)
   10693              : {
   10694            0 :   location_t saved_loc = input_location;
   10695            0 :   input_location = loc;
   10696              : 
   10697            0 :   struct c_enum_contents the_enum;
   10698            0 :   tree enumtype = start_enum (loc, &the_enum, get_identifier (name),
   10699              :                               NULL_TREE, false);
   10700              : 
   10701            0 :   tree value_chain = NULL_TREE;
   10702            0 :   string_int_pair *value;
   10703            0 :   vec<string_int_pair> values = *values_ptr;
   10704            0 :   unsigned int i;
   10705            0 :   FOR_EACH_VEC_ELT (values, i, value)
   10706              :     {
   10707            0 :       tree decl = build_enumerator (loc, loc, &the_enum,
   10708              :                                     get_identifier (value->first),
   10709              :                                     build_int_cst (integer_type_node,
   10710            0 :                                                    value->second));
   10711            0 :       TREE_CHAIN (decl) = value_chain;
   10712            0 :       value_chain = decl;
   10713              :     }
   10714              : 
   10715            0 :   finish_enum (enumtype, nreverse (value_chain), NULL_TREE);
   10716              : 
   10717            0 :   input_location = saved_loc;
   10718            0 :   return enumtype;
   10719              : }
   10720              : 
   10721              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   10722              : 
   10723              : tree
   10724            0 : c_simulate_record_decl (location_t loc, const char *name,
   10725              :                         array_slice<const tree> fields)
   10726              : {
   10727            0 :   location_t saved_loc = input_location;
   10728            0 :   input_location = loc;
   10729              : 
   10730            0 :   class c_struct_parse_info *struct_info;
   10731            0 :   tree ident = get_identifier (name);
   10732            0 :   tree type = start_struct (loc, RECORD_TYPE, ident, &struct_info);
   10733              : 
   10734            0 :   for (unsigned int i = 0; i < fields.size (); ++i)
   10735              :     {
   10736            0 :       DECL_FIELD_CONTEXT (fields[i]) = type;
   10737            0 :       if (i > 0)
   10738            0 :         DECL_CHAIN (fields[i - 1]) = fields[i];
   10739              :     }
   10740              : 
   10741            0 :   finish_struct (loc, type, fields[0], NULL_TREE, struct_info);
   10742              : 
   10743            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   10744            0 :   set_underlying_type (decl);
   10745            0 :   lang_hooks.decls.pushdecl (decl);
   10746              : 
   10747            0 :   input_location = saved_loc;
   10748            0 :   return type;
   10749              : }
   10750              : 
   10751              : /* Create the FUNCTION_DECL for a function definition.
   10752              :    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
   10753              :    the declaration; they describe the function's name and the type it returns,
   10754              :    but twisted together in a fashion that parallels the syntax of C.
   10755              : 
   10756              :    This function creates a binding context for the function body
   10757              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   10758              : 
   10759              :    Returns true on success.  If the DECLARATOR is not suitable for a function
   10760              :    (it defines a datum instead), we return false to report a parse error.  */
   10761              : 
   10762              : bool
   10763     36332413 : start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   10764              :                 tree attributes)
   10765              : {
   10766     36332413 :   tree decl1, old_decl;
   10767     36332413 :   tree restype, resdecl;
   10768     36332413 :   location_t loc;
   10769     36332413 :   location_t result_loc;
   10770     36332413 :   tree expr = NULL;
   10771              : 
   10772     36332413 :   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   10773     36332413 :   current_function_returns_null = 0;
   10774     36332413 :   current_function_returns_abnormally = 0;
   10775     36332413 :   warn_about_return_type = 0;
   10776     36332413 :   c_switch_stack = NULL;
   10777              : 
   10778              :   /* Indicate no valid break/continue context.  */
   10779     36332413 :   in_statement = 0;
   10780              : 
   10781     36332413 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
   10782              :                           &attributes, &expr, NULL, DEPRECATED_NORMAL);
   10783     36332413 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   10784              : 
   10785              :   /* If the declarator is not suitable for a function definition,
   10786              :      cause a syntax error.  */
   10787     36332413 :   if (decl1 == NULL_TREE
   10788     36332382 :       || TREE_CODE (decl1) != FUNCTION_DECL)
   10789              :     return false;
   10790              : 
   10791              :   /* Nested functions may have variably modified (return) type.
   10792              :      Make sure the size expression is evaluated at this point.  */
   10793     36332375 :   if (expr && !current_scope->parm_flag)
   10794           11 :     add_stmt (fold_convert (void_type_node, expr));
   10795              : 
   10796     36332375 :   loc = DECL_SOURCE_LOCATION (decl1);
   10797              : 
   10798              :   /* A nested function is not global.  */
   10799     36332375 :   if (current_function_decl != NULL_TREE)
   10800         1594 :     TREE_PUBLIC (decl1) = 0;
   10801              : 
   10802     36332375 :   c_decl_attributes (&decl1, attributes, 0);
   10803              : 
   10804     36332375 :   if (DECL_DECLARED_INLINE_P (decl1)
   10805     35636027 :       && DECL_UNINLINABLE (decl1)
   10806     36332386 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
   10807              :     {
   10808            3 :       auto_urlify_attributes sentinel;
   10809            3 :       warning_at (loc, OPT_Wattributes,
   10810              :                   "inline function %qD given attribute %qs",
   10811              :                   decl1, "noinline");
   10812            3 :     }
   10813              : 
   10814              :   /* Handle gnu_inline attribute.  */
   10815     36332375 :   if (declspecs->inline_p
   10816     35636030 :       && !flag_gnu89_inline
   10817     35601919 :       && TREE_CODE (decl1) == FUNCTION_DECL
   10818     71934294 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
   10819       160148 :           || current_function_decl))
   10820              :     {
   10821     35441843 :       if (declspecs->storage_class != csc_static)
   10822     35441837 :         DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
   10823              :     }
   10824              : 
   10825     36332375 :   announce_function (decl1);
   10826              : 
   10827     36332375 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
   10828              :     {
   10829            1 :       error_at (loc, "return type is an incomplete type");
   10830              :       /* Make it return void instead.  */
   10831            1 :       TREE_TYPE (decl1)
   10832            2 :         = c_build_function_type (void_type_node,
   10833            1 :                                  TYPE_ARG_TYPES (TREE_TYPE (decl1)),
   10834            1 :                                  TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl1)));
   10835              :     }
   10836              : 
   10837     36332375 :   if (warn_about_return_type)
   10838         1404 :     permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int
   10839            0 :                    : (warn_return_type > 0 ? OPT_Wreturn_type
   10840              :                       : OPT_Wimplicit_int),
   10841              :                    "return type defaults to %<int%>");
   10842              : 
   10843              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   10844              :      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
   10845     36332375 :   DECL_INITIAL (decl1) = error_mark_node;
   10846              : 
   10847              :   /* If this definition isn't a prototype and we had a prototype declaration
   10848              :      before, copy the arg type info from that prototype.  */
   10849     36332375 :   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
   10850     36332375 :   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
   10851     36102140 :     old_decl = NULL_TREE;
   10852              : 
   10853     36332375 :   current_function_prototype_locus = UNKNOWN_LOCATION;
   10854     36332375 :   current_function_prototype_built_in = false;
   10855     36332375 :   current_function_prototype_arg_types = NULL_TREE;
   10856     36332375 :   tree newtype = TREE_TYPE (decl1);
   10857     36332375 :   tree oldtype = old_decl ? TREE_TYPE (old_decl) : newtype;
   10858     36332375 :   if (!prototype_p (newtype))
   10859              :     {
   10860        13140 :       tree oldrt = TREE_TYPE (oldtype);
   10861        13140 :       tree newrt = TREE_TYPE (newtype);
   10862        13140 :       if (old_decl != NULL_TREE
   10863          317 :           && TREE_CODE (oldtype) == FUNCTION_TYPE
   10864          317 :           && comptypes (oldrt, newrt)
   10865        13438 :           && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype))
   10866              :         {
   10867          297 :           if (stdarg_p (oldtype))
   10868              :             {
   10869            1 :               auto_diagnostic_group d;
   10870            1 :               warning_at (loc, 0, "%q+D defined as variadic function "
   10871              :                           "without prototype", decl1);
   10872            1 :               locate_old_decl (old_decl);
   10873            1 :             }
   10874          297 :           TREE_TYPE (decl1) = composite_type (oldtype, newtype);
   10875          297 :           current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
   10876          297 :           current_function_prototype_built_in
   10877          297 :             = C_DECL_BUILTIN_PROTOTYPE (old_decl);
   10878          297 :           current_function_prototype_arg_types
   10879          297 :             = TYPE_ARG_TYPES (newtype);
   10880              :         }
   10881        13140 :       if (TREE_PUBLIC (decl1))
   10882              :         {
   10883              :           /* If there is an external prototype declaration of this
   10884              :              function, record its location but do not copy information
   10885              :              to this decl.  This may be an invisible declaration
   10886              :              (built-in or in a scope which has finished) or simply
   10887              :              have more refined argument types than any declaration
   10888              :              found above.  */
   10889        12725 :           struct c_binding *b;
   10890        13001 :           for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
   10891          713 :             if (B_IN_SCOPE (b, external_scope))
   10892              :               break;
   10893        12725 :           if (b)
   10894              :             {
   10895          437 :               tree ext_decl, ext_type;
   10896          437 :               ext_decl = b->decl;
   10897          437 :               ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
   10898          437 :               if (TREE_CODE (ext_type) == FUNCTION_TYPE
   10899          874 :                   && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
   10900          437 :                                 TREE_TYPE (ext_type)))
   10901              :                 {
   10902          417 :                   current_function_prototype_locus
   10903          417 :                     = DECL_SOURCE_LOCATION (ext_decl);
   10904          417 :                   current_function_prototype_built_in
   10905          417 :                     = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
   10906          417 :                   current_function_prototype_arg_types
   10907          417 :                     = TYPE_ARG_TYPES (ext_type);
   10908              :                 }
   10909              :             }
   10910              :         }
   10911              :     }
   10912              : 
   10913              :   /* Optionally warn about C23 compatibility.  */
   10914     36332375 :   if (warn_deprecated_non_prototype
   10915           34 :       && old_decl != NULL_TREE
   10916            5 :       && TREE_CODE (oldtype) == FUNCTION_TYPE
   10917            5 :       && !TYPE_ARG_TYPES (oldtype)
   10918            5 :       && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype)
   10919     36332380 :       && (TYPE_ARG_TYPES (newtype)
   10920            3 :           && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != void_type_node))
   10921              :     {
   10922            3 :       bool warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
   10923              :                                 "ISO C23 does not allow defining"
   10924              :                                 " parameters for function %qE declared"
   10925              :                                 " without parameters",
   10926              :                                 decl1);
   10927            3 :       if (warned)
   10928            3 :         inform (DECL_SOURCE_LOCATION (old_decl), "declared here");
   10929              :     }
   10930              : 
   10931              :   /* Optionally warn of old-fashioned def with no previous prototype.  */
   10932     36332375 :   if (warn_strict_prototypes
   10933       107552 :       && old_decl != error_mark_node
   10934       107552 :       && !prototype_p (TREE_TYPE (decl1))
   10935     36332376 :       && C_DECL_ISNT_PROTOTYPE (old_decl))
   10936            1 :     warning_at (loc, OPT_Wstrict_prototypes,
   10937              :                 "function declaration isn%'t a prototype");
   10938              :   /* Optionally warn of any global def with no previous prototype.  */
   10939     36332374 :   else if (warn_missing_prototypes
   10940       107253 :            && old_decl != error_mark_node
   10941       107253 :            && TREE_PUBLIC (decl1)
   10942        74080 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10943        74044 :            && C_DECL_ISNT_PROTOTYPE (old_decl)
   10944     36333015 :            && !DECL_DECLARED_INLINE_P (decl1))
   10945            4 :     warning_at (loc, OPT_Wmissing_prototypes,
   10946              :                 "no previous prototype for %qD", decl1);
   10947              :   /* Optionally warn of any def with no previous prototype
   10948              :      if the function has already been used.  */
   10949     36332370 :   else if (warn_missing_prototypes
   10950       107249 :            && old_decl != NULL_TREE
   10951        74407 :            && old_decl != error_mark_node
   10952        74407 :            && TREE_USED (old_decl)
   10953     36339475 :            && !prototype_p (TREE_TYPE (old_decl)))
   10954            0 :     warning_at (loc, OPT_Wmissing_prototypes,
   10955              :                 "%qD was used with no prototype before its definition", decl1);
   10956              :   /* Optionally warn of any global def with no previous declaration.  */
   10957     36332370 :   else if (warn_missing_declarations
   10958            4 :            && TREE_PUBLIC (decl1)
   10959            3 :            && old_decl == NULL_TREE
   10960            3 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10961     36332373 :            && !DECL_DECLARED_INLINE_P (decl1))
   10962            2 :     warning_at (loc, OPT_Wmissing_declarations,
   10963              :                 "no previous declaration for %qD",
   10964              :                 decl1);
   10965              :   /* Optionally warn of any def with no previous declaration
   10966              :      if the function has already been used.  */
   10967     36332368 :   else if (warn_missing_declarations
   10968            2 :            && old_decl != NULL_TREE
   10969            0 :            && old_decl != error_mark_node
   10970            0 :            && TREE_USED (old_decl)
   10971     36332368 :            && C_DECL_IMPLICIT (old_decl))
   10972            0 :     warning_at (loc, OPT_Wmissing_declarations,
   10973              :                 "%qD was used with no declaration before its definition", decl1);
   10974              : 
   10975              :   /* This function exists in static storage.
   10976              :      (This does not mean `static' in the C sense!)  */
   10977     36332375 :   TREE_STATIC (decl1) = 1;
   10978              : 
   10979              :   /* This is the earliest point at which we might know the assembler
   10980              :      name of the function.  Thus, if it's set before this, die horribly.  */
   10981     36332375 :   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
   10982              : 
   10983              :   /* If #pragma weak was used, mark the decl weak now.  */
   10984     36332375 :   if (current_scope == file_scope)
   10985     36330781 :     maybe_apply_pragma_weak (decl1);
   10986              : 
   10987              :   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
   10988     36332375 :   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
   10989              :     {
   10990         3338 :       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
   10991         3338 :           != integer_type_node)
   10992            5 :         pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
   10993         3333 :       else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
   10994            1 :         pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
   10995              :                  decl1);
   10996              : 
   10997         3338 :       check_main_parameter_types (decl1);
   10998              : 
   10999         3338 :       if (!TREE_PUBLIC (decl1))
   11000            0 :         pedwarn (loc, OPT_Wmain,
   11001              :                  "%qD is normally a non-static function", decl1);
   11002              :     }
   11003              : 
   11004     36332375 :   tree parms = current_function_arg_info->parms;
   11005     36332375 :   if (old_decl)
   11006              :     {
   11007       230235 :       location_t origloc = DECL_SOURCE_LOCATION (old_decl);
   11008       230235 :       warn_parms_array_mismatch (origloc, old_decl, parms);
   11009              :     }
   11010              : 
   11011              :   /* To enable versions to be created across TU's we mark and mangle all
   11012              :      non-default versioned functions.  */
   11013     36332375 :   if (TREE_CODE (decl1) == FUNCTION_DECL
   11014              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
   11015              :       && get_target_version (decl1).is_valid ())
   11016              :     {
   11017              :       maybe_mark_function_versioned (decl1);
   11018              :       if (current_scope != file_scope)
   11019              :         error ("versioned definitions are only allowed at file scope");
   11020              :     }
   11021              : 
   11022              :   /* Record the decl so that the function name is defined.
   11023              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   11024              :      use the old decl.  */
   11025              : 
   11026     36332375 :   current_function_decl = pushdecl (decl1);
   11027              : 
   11028     36332375 :   if (tree access = build_attr_access_from_parms (parms, false))
   11029        58013 :     decl_attributes (&current_function_decl, access, ATTR_FLAG_INTERNAL,
   11030              :                      old_decl);
   11031              : 
   11032     36332375 :   push_scope ();
   11033     36332375 :   declare_parm_level ();
   11034              : 
   11035              :   /* Set the result decl source location to the location of the typespec.  */
   11036      4108108 :   result_loc = (declspecs->locations[cdw_typespec] == UNKNOWN_LOCATION
   11037     36332375 :                 ? loc : declspecs->locations[cdw_typespec]);
   11038     36332375 :   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11039     36332375 :   resdecl = build_decl (result_loc, RESULT_DECL, NULL_TREE, restype);
   11040     36332375 :   DECL_ARTIFICIAL (resdecl) = 1;
   11041     36332375 :   DECL_IGNORED_P (resdecl) = 1;
   11042     36332375 :   DECL_RESULT (current_function_decl) = resdecl;
   11043              : 
   11044     36332375 :   start_fname_decls ();
   11045              : 
   11046     36332375 :   return true;
   11047              : }
   11048              : 
   11049              : /* Subroutine of store_parm_decls which handles new-style function
   11050              :    definitions (prototype format). The parms already have decls, so we
   11051              :    need only record them as in effect and complain if any redundant
   11052              :    old-style parm decls were written.  */
   11053              : static void
   11054     36319248 : store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
   11055              : {
   11056     36319248 :   tree decl;
   11057     36319248 :   c_arg_tag *tag;
   11058     36319248 :   unsigned ix;
   11059              : 
   11060     36319248 :   if (current_scope->bindings)
   11061              :     {
   11062            8 :       error_at (DECL_SOURCE_LOCATION (fndecl),
   11063              :                 "old-style parameter declarations in prototyped "
   11064              :                 "function definition");
   11065              : 
   11066              :       /* Get rid of the old-style declarations.  */
   11067            8 :       pop_scope ();
   11068            8 :       push_scope ();
   11069              :     }
   11070              :   /* Don't issue this warning for nested functions, and don't issue this
   11071              :      warning if we got here because ARG_INFO_TYPES was error_mark_node
   11072              :      (this happens when a function definition has just an ellipsis in
   11073              :      its parameter list).  */
   11074     36319240 :   else if (!in_system_header_at (input_location)
   11075       646801 :            && !current_function_scope
   11076       645355 :            && arg_info->types != error_mark_node
   11077     36964595 :            && !arg_info->c23_empty_parens)
   11078       591341 :     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
   11079              :                 "traditional C rejects ISO C style function definitions");
   11080              : 
   11081              :   /* Now make all the parameter declarations visible in the function body.
   11082              :      We can bypass most of the grunt work of pushdecl.  */
   11083    136374723 :   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
   11084              :     {
   11085    100055475 :       DECL_CONTEXT (decl) = current_function_decl;
   11086    100055475 :       if (DECL_NAME (decl))
   11087              :         {
   11088    100053935 :           bind (DECL_NAME (decl), decl, current_scope,
   11089              :                 /*invisible=*/false, /*nested=*/false,
   11090              :                 UNKNOWN_LOCATION);
   11091    100053935 :           if (!TREE_USED (decl))
   11092    100036521 :             warn_if_shadowing (decl);
   11093              :         }
   11094              :       else
   11095         1540 :         pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_name,
   11096              :                      "ISO C does not support omitting parameter names in "
   11097              :                      "function definitions before C23");
   11098              :     }
   11099              : 
   11100              :   /* Record the parameter list in the function declaration.  */
   11101     36319248 :   DECL_ARGUMENTS (fndecl) = arg_info->parms;
   11102              : 
   11103              :   /* Now make all the ancillary declarations visible, likewise.  */
   11104     36319309 :   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
   11105              :     {
   11106           61 :       DECL_CONTEXT (decl) = current_function_decl;
   11107           61 :       if (DECL_NAME (decl))
   11108            0 :         bind (DECL_NAME (decl), decl, current_scope,
   11109              :               /*invisible=*/false,
   11110            0 :               /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
   11111              :               UNKNOWN_LOCATION);
   11112              :     }
   11113              : 
   11114              :   /* And all the tag declarations.  */
   11115     36319365 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
   11116           61 :     if (tag->id)
   11117           28 :       bind (tag->id, tag->type, current_scope,
   11118              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
   11119     36319248 : }
   11120              : 
   11121              : /* Subroutine of store_parm_decls which handles old-style function
   11122              :    definitions (separate parameter list and declarations).  */
   11123              : 
   11124              : static void
   11125        13127 : store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
   11126              : {
   11127        13127 :   struct c_binding *b;
   11128        13127 :   tree parm, decl, last;
   11129        13127 :   tree parmids = arg_info->parms;
   11130        13127 :   hash_set<tree> seen_args;
   11131              : 
   11132        13127 :   if (!in_system_header_at (input_location))
   11133              :     {
   11134        13124 :       if (flag_isoc23)
   11135         1348 :         pedwarn (DECL_SOURCE_LOCATION (fndecl),
   11136         1348 :                  OPT_Wold_style_definition, "old-style function definition");
   11137              :       else
   11138        11776 :         warning_at (DECL_SOURCE_LOCATION (fndecl),
   11139        11776 :                     OPT_Wold_style_definition,
   11140              :                     "old-style function definition");
   11141              :     }
   11142              : 
   11143        13127 :   if (current_scope->had_vla_unspec)
   11144            1 :     error ("%<[*]%> not allowed in other than function prototype scope");
   11145              : 
   11146              :   /* Match each formal parameter name with its declaration.  Save each
   11147              :      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
   11148        47401 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11149              :     {
   11150        34274 :       if (TREE_VALUE (parm) == NULL_TREE)
   11151              :         {
   11152            0 :           error_at (DECL_SOURCE_LOCATION (fndecl),
   11153              :                     "parameter name missing from parameter list");
   11154            0 :           TREE_PURPOSE (parm) = NULL_TREE;
   11155            0 :           continue;
   11156              :         }
   11157              : 
   11158        34274 :       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
   11159        34274 :       if (b && B_IN_CURRENT_SCOPE (b))
   11160              :         {
   11161        22654 :           decl = b->decl;
   11162              :           /* Skip erroneous parameters.  */
   11163        22654 :           if (decl == error_mark_node)
   11164            2 :             continue;
   11165              :           /* If we got something other than a PARM_DECL it is an error.  */
   11166        22652 :           if (TREE_CODE (decl) != PARM_DECL)
   11167              :             {
   11168            7 :               error_at (DECL_SOURCE_LOCATION (decl),
   11169              :                         "%qD declared as a non-parameter", decl);
   11170            7 :               continue;
   11171              :             }
   11172              :           /* If the declaration is already marked, we have a duplicate
   11173              :              name.  Complain and ignore the duplicate.  */
   11174        22645 :           else if (seen_args.contains (decl))
   11175              :             {
   11176            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11177              :                         "multiple parameters named %qD", decl);
   11178            0 :               TREE_PURPOSE (parm) = NULL_TREE;
   11179            0 :               continue;
   11180              :             }
   11181              :           /* If the declaration says "void", complain and turn it into
   11182              :              an int.  */
   11183        22645 :           else if (VOID_TYPE_P (TREE_TYPE (decl)))
   11184              :             {
   11185            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11186              :                         "parameter %qD declared with void type", decl);
   11187            0 :               TREE_TYPE (decl) = integer_type_node;
   11188            0 :               DECL_ARG_TYPE (decl) = integer_type_node;
   11189            0 :               layout_decl (decl, 0);
   11190              :             }
   11191        22645 :           warn_if_shadowing (decl);
   11192              :         }
   11193              :       /* If no declaration found, default to int.  */
   11194              :       else
   11195              :         {
   11196              :           /* FIXME diagnostics: This should be the location of the argument,
   11197              :              not the FNDECL.  E.g., for an old-style declaration
   11198              : 
   11199              :                int f10(v) { blah; }
   11200              : 
   11201              :              We should use the location of the V, not the F10.
   11202              :              Unfortunately, the V is an IDENTIFIER_NODE which has no
   11203              :              location.  In the future we need locations for c_arg_info
   11204              :              entries.
   11205              : 
   11206              :              See gcc.dg/Wshadow-3.c for an example of this problem. */
   11207        11620 :           decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
   11208        11620 :                              PARM_DECL, TREE_VALUE (parm), integer_type_node);
   11209        11620 :           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
   11210        11620 :           pushdecl (decl);
   11211        11620 :           warn_if_shadowing (decl);
   11212              : 
   11213        11620 :           if (flag_isoc99)
   11214          118 :             permerror_opt (DECL_SOURCE_LOCATION (decl),
   11215          118 :                            OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
   11216              :                            decl);
   11217              :           else
   11218        11502 :             warning_at (DECL_SOURCE_LOCATION (decl),
   11219        11502 :                         OPT_Wmissing_parameter_type,
   11220              :                         "type of %qD defaults to %<int%>", decl);
   11221              :         }
   11222              : 
   11223        34265 :       TREE_PURPOSE (parm) = decl;
   11224        34265 :       seen_args.add (decl);
   11225              :     }
   11226              : 
   11227              :   /* Now examine the parms chain for incomplete declarations
   11228              :      and declarations with no corresponding names.  */
   11229              : 
   11230        47480 :   for (b = current_scope->bindings; b; b = b->prev)
   11231              :     {
   11232        34353 :       parm = b->decl;
   11233        34353 :       if (TREE_CODE (parm) != PARM_DECL)
   11234           79 :         continue;
   11235              : 
   11236        34274 :       if (TREE_TYPE (parm) != error_mark_node
   11237        34274 :           && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
   11238              :         {
   11239            0 :           error_at (DECL_SOURCE_LOCATION (parm),
   11240              :                     "parameter %qD has incomplete type", parm);
   11241            0 :           TREE_TYPE (parm) = error_mark_node;
   11242              :         }
   11243              : 
   11244        34274 :       if (!seen_args.contains (parm))
   11245              :         {
   11246            9 :           error_at (DECL_SOURCE_LOCATION (parm),
   11247              :                     "declaration for parameter %qD but no such parameter",
   11248              :                     parm);
   11249              : 
   11250              :           /* Pretend the parameter was not missing.
   11251              :              This gets us to a standard state and minimizes
   11252              :              further error messages.  */
   11253            9 :           parmids = chainon (parmids, tree_cons (parm, 0, 0));
   11254              :         }
   11255              :     }
   11256              : 
   11257              :   /* Chain the declarations together in the order of the list of
   11258              :      names.  Store that chain in the function decl, replacing the
   11259              :      list of names.  Update the current scope to match.  */
   11260        13127 :   DECL_ARGUMENTS (fndecl) = NULL_TREE;
   11261              : 
   11262        13135 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11263         8680 :     if (TREE_PURPOSE (parm))
   11264              :       break;
   11265        13127 :   if (parm && TREE_PURPOSE (parm))
   11266              :     {
   11267         8672 :       last = TREE_PURPOSE (parm);
   11268         8672 :       DECL_ARGUMENTS (fndecl) = last;
   11269              : 
   11270        34275 :       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
   11271        25603 :         if (TREE_PURPOSE (parm))
   11272              :           {
   11273        25602 :             DECL_CHAIN (last) = TREE_PURPOSE (parm);
   11274        25603 :             last = TREE_PURPOSE (parm);
   11275              :           }
   11276         8672 :       DECL_CHAIN (last) = NULL_TREE;
   11277              :     }
   11278              : 
   11279              :   /* If there was a previous prototype,
   11280              :      set the DECL_ARG_TYPE of each argument according to
   11281              :      the type previously specified, and report any mismatches.  */
   11282              : 
   11283        13127 :   if (current_function_prototype_arg_types)
   11284              :     {
   11285          171 :       tree type;
   11286          171 :       for (parm = DECL_ARGUMENTS (fndecl),
   11287          171 :              type = current_function_prototype_arg_types;
   11288          373 :            parm || (type != NULL_TREE
   11289          166 :                     && TREE_VALUE (type) != error_mark_node
   11290          166 :                     && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
   11291          202 :            parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
   11292              :         {
   11293          212 :           if (parm == NULL_TREE
   11294          206 :               || type == NULL_TREE
   11295          418 :               || (TREE_VALUE (type) != error_mark_node
   11296          192 :                   && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
   11297              :             {
   11298           10 :               if (current_function_prototype_built_in)
   11299            6 :                 warning_at (DECL_SOURCE_LOCATION (fndecl),
   11300            6 :                             0, "number of arguments doesn%'t match "
   11301              :                             "built-in prototype");
   11302              :               else
   11303              :                 {
   11304              :                   /* FIXME diagnostics: This should be the location of
   11305              :                      FNDECL, but there is bug when a prototype is
   11306              :                      declared inside function context, but defined
   11307              :                      outside of it (e.g., gcc.dg/pr15698-2.c).  In
   11308              :                      which case FNDECL gets the location of the
   11309              :                      prototype, not the definition.  */
   11310            4 :                   error_at (input_location,
   11311              :                             "number of arguments doesn%'t match prototype");
   11312              : 
   11313            4 :                   error_at (current_function_prototype_locus,
   11314              :                             "prototype declaration");
   11315              :                 }
   11316              :               break;
   11317              :             }
   11318              :           /* Type for passing arg must be consistent with that
   11319              :              declared for the arg.  ISO C says we take the unqualified
   11320              :              type for parameters declared with qualified type.  */
   11321          202 :           if (TREE_TYPE (parm) != error_mark_node
   11322          201 :               && TREE_VALUE (type) != error_mark_node
   11323          389 :               && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11324          187 :                    != TYPE_ATOMIC (TREE_VALUE (type)))
   11325          185 :                   || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
   11326          185 :                                  TYPE_MAIN_VARIANT (TREE_VALUE (type)))))
   11327              :             {
   11328           36 :               if ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11329           36 :                    == TYPE_ATOMIC (TREE_VALUE (type)))
   11330           36 :                   && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
   11331           34 :                       == TYPE_MAIN_VARIANT (TREE_VALUE (type))))
   11332              :                 {
   11333              :                   /* Adjust argument to match prototype.  E.g. a previous
   11334              :                      `int foo(float);' prototype causes
   11335              :                      `int foo(x) float x; {...}' to be treated like
   11336              :                      `int foo(float x) {...}'.  This is particularly
   11337              :                      useful for argument types like uid_t.  */
   11338           17 :                   DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
   11339              : 
   11340              :                   /* ??? Is it possible to get here with a
   11341              :                      built-in prototype or will it always have
   11342              :                      been diagnosed as conflicting with an
   11343              :                      old-style definition and discarded?  */
   11344           17 :                   if (current_function_prototype_built_in)
   11345            2 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11346            2 :                                 OPT_Wpedantic, "promoted argument %qD "
   11347              :                                 "doesn%'t match built-in prototype", parm);
   11348              :                   else
   11349              :                     {
   11350           15 :                       pedwarn (DECL_SOURCE_LOCATION (parm),
   11351           15 :                                OPT_Wpedantic, "promoted argument %qD "
   11352              :                                "doesn%'t match prototype", parm);
   11353           15 :                       pedwarn (current_function_prototype_locus, OPT_Wpedantic,
   11354              :                                "prototype declaration");
   11355              :                     }
   11356              :                 }
   11357              :               else
   11358              :                 {
   11359           19 :                   if (current_function_prototype_built_in)
   11360           10 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11361           10 :                                 0, "argument %qD doesn%'t match "
   11362              :                                 "built-in prototype", parm);
   11363              :                   else
   11364              :                     {
   11365            9 :                       error_at (DECL_SOURCE_LOCATION (parm),
   11366              :                                 "argument %qD doesn%'t match prototype", parm);
   11367            9 :                       error_at (current_function_prototype_locus,
   11368              :                                 "prototype declaration");
   11369              :                     }
   11370              :                 }
   11371              :             }
   11372              :         }
   11373          171 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = NULL_TREE;
   11374              :     }
   11375              : 
   11376              :   /* Otherwise, create a prototype that would match.  */
   11377              : 
   11378              :   else
   11379              :     {
   11380        12956 :       tree actual = NULL_TREE, last = NULL_TREE, type;
   11381              : 
   11382        47024 :       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   11383              :         {
   11384        34068 :           type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
   11385        34068 :           if (last)
   11386        25552 :             TREE_CHAIN (last) = type;
   11387              :           else
   11388              :             actual = type;
   11389        34068 :           last = type;
   11390              :         }
   11391        12956 :       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
   11392        12956 :       if (last)
   11393         8516 :         TREE_CHAIN (last) = type;
   11394              :       else
   11395              :         actual = type;
   11396              : 
   11397              :       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
   11398              :          of the type of this function, but we need to avoid having this
   11399              :          affect the types of other similarly-typed functions, so we must
   11400              :          first force the generation of an identical (but separate) type
   11401              :          node for the relevant function type.  The new node we create
   11402              :          will be a variant of the main variant of the original function
   11403              :          type.  */
   11404              : 
   11405        12956 :       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
   11406              : 
   11407        12956 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
   11408              :     }
   11409        13127 : }
   11410              : 
   11411              : /* Store parameter declarations passed in ARG_INFO into the current
   11412              :    function declaration.  */
   11413              : 
   11414              : void
   11415            0 : store_parm_decls_from (struct c_arg_info *arg_info)
   11416              : {
   11417            0 :   current_function_arg_info = arg_info;
   11418            0 :   store_parm_decls ();
   11419            0 : }
   11420              : 
   11421              : /* Called by walk_tree to look for and update context-less labels
   11422              :    or labels with context in the parent function.  */
   11423              : 
   11424              : static tree
   11425         8175 : set_labels_context_r (tree *tp, int *walk_subtrees, void *data)
   11426              : {
   11427         8175 :   tree ctx = static_cast<tree>(data);
   11428         8175 :   if (TREE_CODE (*tp) == LABEL_EXPR
   11429         8175 :       && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE
   11430            2 :           || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx)))
   11431              :     {
   11432           72 :       DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx;
   11433           72 :       *walk_subtrees = 0;
   11434              :     }
   11435              : 
   11436         8175 :   return NULL_TREE;
   11437              : }
   11438              : 
   11439              : /* Store the parameter declarations into the current function declaration.
   11440              :    This is called after parsing the parameter declarations, before
   11441              :    digesting the body of the function.
   11442              : 
   11443              :    For an old-style definition, construct a prototype out of the old-style
   11444              :    parameter declarations and inject it into the function's type.  */
   11445              : 
   11446              : void
   11447     36332375 : store_parm_decls (void)
   11448              : {
   11449     36332375 :   tree fndecl = current_function_decl;
   11450     36332375 :   bool proto;
   11451              : 
   11452              :   /* The argument information block for FNDECL.  */
   11453     36332375 :   struct c_arg_info *arg_info = current_function_arg_info;
   11454     36332375 :   current_function_arg_info = 0;
   11455              : 
   11456              :   /* True if this definition is written with a prototype.  In C23, an
   11457              :      empty argument list was converted to (void) in grokparms; in
   11458              :      older C standard versions, it does not give the function a type
   11459              :      with a prototype for future calls.  */
   11460     36332375 :   proto = arg_info->types != 0 || arg_info->no_named_args_stdarg_p;
   11461              : 
   11462        13127 :   if (proto)
   11463     36319248 :     store_parm_decls_newstyle (fndecl, arg_info);
   11464              :   else
   11465        13127 :     store_parm_decls_oldstyle (fndecl, arg_info);
   11466              : 
   11467              :   /* The next call to push_scope will be a function body.  */
   11468              : 
   11469     36332375 :   next_is_function_body = true;
   11470              : 
   11471              :   /* Write a record describing this function definition to the prototypes
   11472              :      file (if requested).  */
   11473              : 
   11474     36332375 :   gen_aux_info_record (fndecl, 1, 0, proto);
   11475              : 
   11476              :   /* Initialize the RTL code for the function.  */
   11477     36332375 :   allocate_struct_function (fndecl, false);
   11478              : 
   11479     36332375 :   if (warn_unused_local_typedefs)
   11480      3116772 :     cfun->language = ggc_cleared_alloc<language_function> ();
   11481              : 
   11482              :   /* Begin the statement tree for this function.  */
   11483     36332375 :   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
   11484              : 
   11485              :   /* ??? Insert the contents of the pending sizes list into the function
   11486              :      to be evaluated.  The only reason left to have this is
   11487              :         void foo(int n, int array[n++])
   11488              :      because we throw away the array type in favor of a pointer type, and
   11489              :      thus won't naturally see the SAVE_EXPR containing the increment.  All
   11490              :      other pending sizes would be handled by gimplify_parameters.  */
   11491     36332375 :   if (arg_info->pending_sizes)
   11492              :     {
   11493              :       /* In very special circumstances, e.g. for code like
   11494              :            _Atomic int i = 5;
   11495              :            void f (int a[i += 2]) {}
   11496              :          we need to execute the atomic assignment on function entry.
   11497              :          But in this case, it is not just a straight store, it has the
   11498              :          op= form, which means that build_atomic_assign has generated
   11499              :          gotos, labels, etc.  Because at that time the function decl
   11500              :          for F has not been created yet, those labels do not have any
   11501              :          function context.  But we have the fndecl now, so update the
   11502              :          labels accordingly.  gimplify_expr would crash otherwise.
   11503              :          Or with nested functions the labels could be created with parent
   11504              :          function's context, while when the statement is emitted at the
   11505              :          start of the nested function, it needs the nested function's
   11506              :          context.  */
   11507          298 :       walk_tree_without_duplicates (&arg_info->pending_sizes,
   11508              :                                     set_labels_context_r, fndecl);
   11509          298 :       add_stmt (arg_info->pending_sizes);
   11510              :     }
   11511     36332375 : }
   11512              : 
   11513              : /* Store PARM_DECLs in PARMS into scope temporarily.  Used for
   11514              :    c_finish_omp_declare_simd for function prototypes.  No diagnostics
   11515              :    should be done.  */
   11516              : 
   11517              : void
   11518          249 : temp_store_parm_decls (tree fndecl, tree parms)
   11519              : {
   11520          249 :   push_scope ();
   11521          699 :   for (tree p = parms; p; p = DECL_CHAIN (p))
   11522              :     {
   11523          450 :       DECL_CONTEXT (p) = fndecl;
   11524          450 :       if (DECL_NAME (p))
   11525          328 :         bind (DECL_NAME (p), p, current_scope,
   11526              :               /*invisible=*/false, /*nested=*/false,
   11527              :               UNKNOWN_LOCATION);
   11528              :     }
   11529          249 : }
   11530              : 
   11531              : /* Undo what temp_store_parm_decls did.  */
   11532              : 
   11533              : void
   11534          249 : temp_pop_parm_decls (void)
   11535              : {
   11536              :   /* Clear all bindings in this temporary scope, so that
   11537              :      pop_scope doesn't create a BLOCK.  */
   11538          249 :   struct c_binding *b = current_scope->bindings;
   11539          249 :   current_scope->bindings = NULL;
   11540          582 :   for (; b; b = free_binding_and_advance (b))
   11541              :     {
   11542          333 :       gcc_assert (TREE_CODE (b->decl) == PARM_DECL
   11543              :                   || b->decl == error_mark_node);
   11544          333 :       gcc_assert (I_SYMBOL_BINDING (b->id) == b);
   11545          333 :       I_SYMBOL_BINDING (b->id) = b->shadowed;
   11546          333 :       if (b->shadowed && b->shadowed->u.type)
   11547            0 :         TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
   11548              :     }
   11549          249 :   pop_scope ();
   11550          249 : }
   11551              : 
   11552              : 
   11553              : /* Finish up a function declaration and compile that function
   11554              :    all the way to assembler language output.  Then free the storage
   11555              :    for the function definition.
   11556              : 
   11557              :    This is called after parsing the body of the function definition.  */
   11558              : 
   11559              : void
   11560     36332373 : finish_function (location_t end_loc)
   11561              : {
   11562     36332373 :   tree fndecl = current_function_decl;
   11563              : 
   11564     36332373 :   if (c_dialect_objc ())
   11565            0 :     objc_finish_function ();
   11566              : 
   11567     36332373 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
   11568     36332371 :     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   11569              : 
   11570              :   /* Must mark the RESULT_DECL as being in this function.  */
   11571              : 
   11572     36332373 :   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
   11573     36332373 :     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   11574              : 
   11575     36382570 :   if (MAIN_NAME_P (DECL_NAME (fndecl)) && !TREE_THIS_VOLATILE (fndecl)
   11576        50196 :       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
   11577     36382569 :       == integer_type_node && flag_isoc99)
   11578              :     {
   11579              :       /* Hack.  We don't want the middle-end to warn that this return
   11580              :          is unreachable, so we mark its location as special.  Using
   11581              :          UNKNOWN_LOCATION has the problem that it gets clobbered in
   11582              :          annotate_one_with_locus.  A cleaner solution might be to
   11583              :          ensure ! should_carry_locus_p (stmt), but that needs a flag.
   11584              :       */
   11585        48806 :       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
   11586              :     }
   11587              : 
   11588              :   /* Tie off the statement tree for this function.  */
   11589     36332373 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   11590              : 
   11591     36332373 :   finish_fname_decls ();
   11592              : 
   11593              :   /* Complain if there's no return statement only if option specified on
   11594              :      command line.  */
   11595     36332373 :   if (warn_return_type > 0
   11596      3116795 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
   11597      2920690 :       && !current_function_returns_value && !current_function_returns_null
   11598              :       /* Don't complain if we are no-return.  */
   11599           72 :       && !current_function_returns_abnormally
   11600              :       /* Don't complain if we are declared noreturn.  */
   11601           21 :       && !TREE_THIS_VOLATILE (fndecl)
   11602              :       /* Don't warn for main().  */
   11603           18 :       && !MAIN_NAME_P (DECL_NAME (fndecl))
   11604              :       /* Or if they didn't actually specify a return type.  */
   11605           17 :       && !C_FUNCTION_IMPLICIT_INT (fndecl)
   11606              :       /* Normally, with -Wreturn-type, flow will complain, but we might
   11607              :          optimize out static functions.  */
   11608           17 :       && !TREE_PUBLIC (fndecl)
   11609            6 :       && targetm.warn_func_return (fndecl)
   11610     39449168 :       && warning (OPT_Wreturn_type,
   11611              :                   "no return statement in function returning non-void"))
   11612            5 :     suppress_warning (fndecl, OPT_Wreturn_type);
   11613              : 
   11614              :   /* Complain about parameters that are only set, but never otherwise used.  */
   11615     36332373 :   if (warn_unused_but_set_parameter)
   11616              :     {
   11617      3051567 :       tree decl;
   11618              : 
   11619      3051567 :       for (decl = DECL_ARGUMENTS (fndecl);
   11620     11400865 :            decl;
   11621      8349298 :            decl = DECL_CHAIN (decl))
   11622      8349298 :         if (TREE_USED (decl)
   11623      8288595 :             && TREE_CODE (decl) == PARM_DECL
   11624      8288595 :             && !DECL_READ_P (decl)
   11625           47 :             && DECL_NAME (decl)
   11626           47 :             && !DECL_ARTIFICIAL (decl)
   11627      8349345 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_))
   11628           47 :           warning_at (DECL_SOURCE_LOCATION (decl),
   11629           47 :                       OPT_Wunused_but_set_parameter_,
   11630              :                       "parameter %qD set but not used", decl);
   11631              :     }
   11632              : 
   11633              :   /* Complain about locally defined typedefs that are not used in this
   11634              :      function.  */
   11635     36332373 :   maybe_warn_unused_local_typedefs ();
   11636              : 
   11637              :   /* Possibly warn about unused parameters.  */
   11638     36332373 :   if (warn_unused_parameter)
   11639      2957678 :     do_warn_unused_parameter (fndecl);
   11640              : 
   11641              :   /* Store the end of the function, so that we get good line number
   11642              :      info for the epilogue.  */
   11643     36332373 :   cfun->function_end_locus = end_loc;
   11644              : 
   11645              :   /* Finalize the ELF visibility for the function.  */
   11646     36332373 :   c_determine_visibility (fndecl);
   11647              : 
   11648              :   /* For GNU C extern inline functions disregard inline limits.  */
   11649     36332373 :   if (DECL_EXTERNAL (fndecl)
   11650     35470436 :       && DECL_DECLARED_INLINE_P (fndecl)
   11651     71802806 :       && (flag_gnu89_inline
   11652     35439429 :           || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
   11653     35469951 :     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
   11654              : 
   11655              :   /* Genericize before inlining.  Delay genericizing nested functions
   11656              :      until their parent function is genericized.  Since finalizing
   11657              :      requires GENERIC, delay that as well.  */
   11658              : 
   11659     72664746 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
   11660     72664744 :       && !undef_nested_function)
   11661              :     {
   11662     36332365 :       if (!decl_function_context (fndecl))
   11663              :         {
   11664     36330771 :           invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   11665     36330771 :           c_genericize (fndecl);
   11666              : 
   11667              :           /* ??? Objc emits functions after finalizing the compilation unit.
   11668              :              This should be cleaned up later and this conditional removed.  */
   11669     36330771 :           if (symtab->global_info_ready)
   11670              :             {
   11671            0 :               cgraph_node::add_new_function (fndecl, false);
   11672            0 :               return;
   11673              :             }
   11674     36330771 :           cgraph_node::finalize_function (fndecl, false);
   11675              :         }
   11676              :       else
   11677              :         {
   11678              :           /* Register this function with cgraph just far enough to get it
   11679              :             added to our parent's nested function list.  Handy, since the
   11680              :             C front end doesn't have such a list.  */
   11681         1594 :           (void) cgraph_node::get_create (fndecl);
   11682              :         }
   11683              :     }
   11684              : 
   11685     36332373 :   if (!decl_function_context (fndecl))
   11686     36330779 :     undef_nested_function = false;
   11687              : 
   11688     36332373 :   if (cfun->language != NULL)
   11689              :     {
   11690      3116771 :       ggc_free (cfun->language);
   11691      3116771 :       cfun->language = NULL;
   11692              :     }
   11693              : 
   11694              :   /* We're leaving the context of this function, so zap cfun.
   11695              :      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
   11696              :      tree_rest_of_compilation.  */
   11697     36332373 :   set_cfun (NULL);
   11698     36332373 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, current_function_decl);
   11699     36332373 :   current_function_decl = NULL;
   11700              : }
   11701              : 
   11702              : /* Check the declarations given in a for-loop for satisfying the C99
   11703              :    constraints.  If exactly one such decl is found, return it.  LOC is
   11704              :    the location of the opening parenthesis of the for loop.  The last
   11705              :    parameter allows you to control the "for loop initial declarations
   11706              :    are only allowed in C99 mode".  Normally, you should pass
   11707              :    flag_isoc99 as that parameter.  But in some cases (Objective-C
   11708              :    foreach loop, for example) we want to run the checks in this
   11709              :    function even if not in C99 mode, so we allow the caller to turn
   11710              :    off the error about not being in C99 mode.
   11711              : */
   11712              : 
   11713              : tree
   11714        26006 : check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
   11715              : {
   11716        26006 :   struct c_binding *b;
   11717        26006 :   tree one_decl = NULL_TREE;
   11718        26006 :   int n_decls = 0;
   11719              : 
   11720        26006 :   if (!turn_off_iso_c99_error)
   11721              :     {
   11722            1 :       static bool hint = true;
   11723              :       /* If we get here, declarations have been used in a for loop without
   11724              :          the C99 for loop scope.  This doesn't make much sense, so don't
   11725              :          allow it.  */
   11726            1 :       auto_diagnostic_group d;
   11727            1 :       error_at (loc, "%<for%> loop initial declarations "
   11728              :                 "are only allowed in C99 or C11 mode");
   11729            1 :       if (hint)
   11730              :         {
   11731            1 :           inform (loc,
   11732              :                   "use option %<-std=c99%>, %<-std=gnu99%>, %<-std=c11%> or "
   11733              :                   "%<-std=gnu11%> to compile your code");
   11734            1 :           hint = false;
   11735              :         }
   11736            1 :       return NULL_TREE;
   11737            1 :     }
   11738              :   else
   11739        26005 :     pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop "
   11740              :                  "initial declarations");
   11741              : 
   11742              :   /* C99 subclause 6.8.5 paragraph 3:
   11743              : 
   11744              :        [#3]  The  declaration  part  of  a for statement shall only
   11745              :        declare identifiers for objects having storage class auto or
   11746              :        register.
   11747              : 
   11748              :      It isn't clear whether, in this sentence, "identifiers" binds to
   11749              :      "shall only declare" or to "objects" - that is, whether all identifiers
   11750              :      declared must be identifiers for objects, or whether the restriction
   11751              :      only applies to those that are.  (A question on this in comp.std.c
   11752              :      in November 2000 received no answer.)  We implement the strictest
   11753              :      interpretation, to avoid creating an extension which later causes
   11754              :      problems.
   11755              : 
   11756              :      This constraint was removed in C23.  */
   11757              : 
   11758        52090 :   for (b = current_scope->bindings; b; b = b->prev)
   11759              :     {
   11760        26085 :       tree id = b->id;
   11761        26085 :       tree decl = b->decl;
   11762              : 
   11763        26085 :       if (!id)
   11764           27 :         continue;
   11765              : 
   11766        26058 :       switch (TREE_CODE (decl))
   11767              :         {
   11768        26010 :         case VAR_DECL:
   11769        26010 :           {
   11770        26010 :             location_t decl_loc = DECL_SOURCE_LOCATION (decl);
   11771        26010 :             if (TREE_STATIC (decl))
   11772            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11773              :                            "declaration of static variable %qD in %<for%> "
   11774              :                            "loop initial declaration", decl);
   11775        26005 :             else if (DECL_EXTERNAL (decl))
   11776            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11777              :                            "declaration of %<extern%> variable %qD in %<for%> "
   11778              :                            "loop initial declaration", decl);
   11779              :           }
   11780              :           break;
   11781              : 
   11782            6 :         case RECORD_TYPE:
   11783            6 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11784              :                        "%<struct %E%> declared in %<for%> loop initial "
   11785              :                        "declaration", id);
   11786            6 :           break;
   11787            5 :         case UNION_TYPE:
   11788            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11789              :                        "%<union %E%> declared in %<for%> loop initial "
   11790              :                        "declaration",
   11791              :                        id);
   11792            5 :           break;
   11793            5 :         case ENUMERAL_TYPE:
   11794            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11795              :                        "%<enum %E%> declared in %<for%> loop "
   11796              :                        "initial declaration", id);
   11797            5 :           break;
   11798           32 :         default:
   11799           32 :           pedwarn_c11 (loc, OPT_Wpedantic, "declaration of non-variable "
   11800              :                        "%qD in %<for%> loop initial declaration", decl);
   11801              :         }
   11802              : 
   11803        26058 :       n_decls++;
   11804        26058 :       one_decl = decl;
   11805              :     }
   11806              : 
   11807        26005 :   return n_decls == 1 ? one_decl : NULL_TREE;
   11808              : }
   11809              : 
   11810              : /* Save and reinitialize the variables
   11811              :    used during compilation of a C function.  */
   11812              : 
   11813              : void
   11814         1622 : c_push_function_context (void)
   11815              : {
   11816         1622 :   struct language_function *p = cfun->language;
   11817              :   /* cfun->language might have been already allocated by the use of
   11818              :      -Wunused-local-typedefs.  In that case, just re-use it.  */
   11819         1622 :   if (p == NULL)
   11820         1566 :     cfun->language = p = ggc_cleared_alloc<language_function> ();
   11821              : 
   11822         1622 :   p->base.x_stmt_tree = c_stmt_tree;
   11823         1622 :   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
   11824         1622 :   p->x_in_statement = in_statement;
   11825         1622 :   p->x_switch_stack = c_switch_stack;
   11826         1622 :   p->loop_names = loop_names;
   11827         1622 :   loop_names = vNULL;
   11828         1622 :   p->loop_names_hash = loop_names_hash;
   11829         1622 :   loop_names_hash = NULL;
   11830         1622 :   p->arg_info = current_function_arg_info;
   11831         1622 :   p->returns_value = current_function_returns_value;
   11832         1622 :   p->returns_null = current_function_returns_null;
   11833         1622 :   p->returns_abnormally = current_function_returns_abnormally;
   11834         1622 :   p->warn_about_return_type = warn_about_return_type;
   11835              : 
   11836         1622 :   push_function_context ();
   11837         1622 : }
   11838              : 
   11839              : /* Restore the variables used during compilation of a C function.  */
   11840              : 
   11841              : void
   11842         1622 : c_pop_function_context (void)
   11843              : {
   11844         1622 :   struct language_function *p;
   11845              : 
   11846         1622 :   pop_function_context ();
   11847         1622 :   p = cfun->language;
   11848              : 
   11849              :   /* When -Wunused-local-typedefs is in effect, cfun->languages is
   11850              :      used to store data throughout the life time of the current cfun,
   11851              :      So don't deallocate it.  */
   11852         1622 :   if (!warn_unused_local_typedefs)
   11853         1566 :     cfun->language = NULL;
   11854              : 
   11855         1622 :   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
   11856         1622 :       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
   11857              :     {
   11858              :       /* Stop pointing to the local nodes about to be freed.  */
   11859              :       /* But DECL_INITIAL must remain nonzero so we know this
   11860              :          was an actual function definition.  */
   11861            0 :       DECL_INITIAL (current_function_decl) = error_mark_node;
   11862            0 :       DECL_ARGUMENTS (current_function_decl) = NULL_TREE;
   11863              :     }
   11864              : 
   11865         1622 :   c_stmt_tree = p->base.x_stmt_tree;
   11866         1622 :   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
   11867         1622 :   in_statement = p->x_in_statement;
   11868         1622 :   c_switch_stack = p->x_switch_stack;
   11869         1622 :   loop_names.release ();
   11870         1622 :   loop_names = p->loop_names;
   11871         1622 :   p->loop_names = vNULL;
   11872         1622 :   delete loop_names_hash;
   11873         1622 :   loop_names_hash = p->loop_names_hash;
   11874         1622 :   p->loop_names_hash = NULL;
   11875         1622 :   current_function_arg_info = p->arg_info;
   11876         1622 :   current_function_returns_value = p->returns_value;
   11877         1622 :   current_function_returns_null = p->returns_null;
   11878         1622 :   current_function_returns_abnormally = p->returns_abnormally;
   11879         1622 :   warn_about_return_type = p->warn_about_return_type;
   11880         1622 : }
   11881              : 
   11882              : /* The functions below are required for functionality of doing
   11883              :    function at once processing in the C front end. Currently these
   11884              :    functions are not called from anywhere in the C front end, but as
   11885              :    these changes continue, that will change.  */
   11886              : 
   11887              : /* Returns the stmt_tree (if any) to which statements are currently
   11888              :    being added.  If there is no active statement-tree, NULL is
   11889              :    returned.  */
   11890              : 
   11891              : stmt_tree
   11892    986457029 : current_stmt_tree (void)
   11893              : {
   11894    986457029 :   return &c_stmt_tree;
   11895              : }
   11896              : 
   11897              : /* Return the global value of T as a symbol.  */
   11898              : 
   11899              : tree
   11900      4117914 : identifier_global_value (tree t)
   11901              : {
   11902      4117914 :   struct c_binding *b;
   11903              : 
   11904      4118881 :   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
   11905      4111647 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11906      4110680 :       return b->decl;
   11907              : 
   11908              :   return NULL_TREE;
   11909              : }
   11910              : 
   11911              : /* Return the global value of tag T as a symbol.  */
   11912              : 
   11913              : tree
   11914           12 : identifier_global_tag (tree t)
   11915              : {
   11916           12 :   struct c_binding *b;
   11917              : 
   11918           12 :   for (b = I_TAG_BINDING (t); b; b = b->shadowed)
   11919           11 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11920           11 :       return b->decl;
   11921              : 
   11922              :   return NULL_TREE;
   11923              : }
   11924              : 
   11925              : /* Returns non-zero (result of __has_builtin) if NAME refers to a built-in
   11926              :    function or function-like operator.  */
   11927              : 
   11928              : int
   11929        25305 : names_builtin_p (const char *name)
   11930              : {
   11931        25305 :   tree id = get_identifier (name);
   11932        25305 :   if (tree decl = identifier_global_value (id))
   11933        25215 :     return TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_UNDECLARED_BUILTIN (decl);
   11934              : 
   11935              :   /* Also detect common reserved C words that aren't strictly built-in
   11936              :      functions.  */
   11937           90 :   switch (C_RID_CODE (id))
   11938              :     {
   11939              :     case RID_BUILTIN_ASSOC_BARRIER:
   11940              :     case RID_BUILTIN_CONVERTVECTOR:
   11941              :     case RID_BUILTIN_HAS_ATTRIBUTE:
   11942              :     case RID_BUILTIN_SHUFFLE:
   11943              :     case RID_BUILTIN_SHUFFLEVECTOR:
   11944              :     case RID_BUILTIN_STDC:
   11945              :     case RID_BUILTIN_COUNTED_BY_REF:
   11946              :     case RID_CHOOSE_EXPR:
   11947              :     case RID_OFFSETOF:
   11948              :     case RID_TYPES_COMPATIBLE_P:
   11949              :     case RID_C23_VA_START:
   11950              :     case RID_VA_ARG:
   11951              :       return 1;
   11952           69 :     default:
   11953           69 :       break;
   11954              :     }
   11955              : 
   11956           69 :   return 0;
   11957              : }
   11958              : 
   11959              : /* In C, the only C-linkage public declaration is at file scope.  */
   11960              : 
   11961              : tree
   11962            5 : c_linkage_bindings (tree name)
   11963              : {
   11964            5 :   return identifier_global_value (name);
   11965              : }
   11966              : 
   11967              : /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
   11968              :    otherwise the name is found in ridpointers from RID_INDEX.  */
   11969              : 
   11970              : void
   11971      3498840 : record_builtin_type (enum rid rid_index, const char *name, tree type)
   11972              : {
   11973      3498840 :   tree id, decl;
   11974      3498840 :   if (name == 0)
   11975      1632792 :     id = ridpointers[(int) rid_index];
   11976              :   else
   11977      1866048 :     id = get_identifier (name);
   11978      3498840 :   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
   11979      3498840 :   pushdecl (decl);
   11980      3498840 :   if (debug_hooks->type_decl)
   11981      3498840 :     debug_hooks->type_decl (decl, false);
   11982      3498840 : }
   11983              : 
   11984              : /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
   11985              : 
   11986              : struct c_parm *
   11987    124744511 : build_c_parm (struct c_declspecs *specs, tree attrs,
   11988              :               struct c_declarator *declarator,
   11989              :               location_t loc)
   11990              : {
   11991    124744511 :   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
   11992    124744511 :   ret->specs = specs;
   11993    124744511 :   ret->attrs = attrs;
   11994    124744511 :   ret->declarator = declarator;
   11995    124744511 :   ret->loc = loc;
   11996    124744511 :   return ret;
   11997              : }
   11998              : 
   11999              : /* Return a declarator with nested attributes.  TARGET is the inner
   12000              :    declarator to which these attributes apply.  ATTRS are the
   12001              :    attributes.  */
   12002              : 
   12003              : struct c_declarator *
   12004         6789 : build_attrs_declarator (tree attrs, struct c_declarator *target)
   12005              : {
   12006         6789 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12007         6789 :   ret->kind = cdk_attrs;
   12008         6789 :   ret->declarator = target;
   12009         6789 :   ret->u.attrs = attrs;
   12010         6789 :   return ret;
   12011              : }
   12012              : 
   12013              : /* Return a declarator for a function with arguments specified by ARGS
   12014              :    and return type specified by TARGET.  */
   12015              : 
   12016              : struct c_declarator *
   12017     51014252 : build_function_declarator (struct c_arg_info *args,
   12018              :                            struct c_declarator *target)
   12019              : {
   12020     51014252 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12021     51014252 :   ret->kind = cdk_function;
   12022     51014252 :   ret->declarator = target;
   12023     51014252 :   ret->u.arg_info = args;
   12024     51014252 :   return ret;
   12025              : }
   12026              : 
   12027              : /* Return a declarator for the identifier IDENT (which may be
   12028              :    NULL_TREE for an abstract declarator).  */
   12029              : 
   12030              : struct c_declarator *
   12031    315370288 : build_id_declarator (tree ident)
   12032              : {
   12033    315370288 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12034    315370288 :   ret->kind = cdk_id;
   12035    315370288 :   ret->declarator = 0;
   12036    315370288 :   ret->u.id.id = ident;
   12037    315370288 :   ret->u.id.attrs = NULL_TREE;
   12038              :   /* Default value - may get reset to a more precise location. */
   12039    315370288 :   ret->id_loc = input_location;
   12040    315370288 :   return ret;
   12041              : }
   12042              : 
   12043              : /* Return something to represent absolute declarators containing a *.
   12044              :    TARGET is the absolute declarator that the * contains.
   12045              :    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
   12046              :    to apply to the pointer type.  */
   12047              : 
   12048              : struct c_declarator *
   12049     18386697 : make_pointer_declarator (struct c_declspecs *type_quals_attrs,
   12050              :                          struct c_declarator *target)
   12051              : {
   12052     18386697 :   tree attrs;
   12053     18386697 :   int quals = 0;
   12054     18386697 :   struct c_declarator *itarget = target;
   12055     18386697 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12056     18386697 :   if (type_quals_attrs)
   12057              :     {
   12058     18386697 :       attrs = type_quals_attrs->attrs;
   12059     18386697 :       quals = quals_from_declspecs (type_quals_attrs);
   12060     18386697 :       if (attrs != NULL_TREE)
   12061         6517 :         itarget = build_attrs_declarator (attrs, target);
   12062              :     }
   12063     18386697 :   ret->kind = cdk_pointer;
   12064     18386697 :   ret->declarator = itarget;
   12065     18386697 :   ret->u.pointer_quals = quals;
   12066     18386697 :   return ret;
   12067              : }
   12068              : 
   12069              : /* Return a pointer to a structure for an empty list of declaration
   12070              :    specifiers.  */
   12071              : 
   12072              : struct c_declspecs *
   12073    456464437 : build_null_declspecs (void)
   12074              : {
   12075    456464437 :   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
   12076    456464437 :   memset (ret, 0, sizeof *ret);
   12077    456464437 :   ret->align_log = -1;
   12078    456464437 :   ret->typespec_word = cts_none;
   12079    456464437 :   ret->storage_class = csc_none;
   12080    456464437 :   ret->expr_const_operands = true;
   12081    456464437 :   ret->typespec_kind = ctsk_none;
   12082    456464437 :   ret->address_space = ADDR_SPACE_GENERIC;
   12083    456464437 :   return ret;
   12084              : }
   12085              : 
   12086              : /* Add the address space ADDRSPACE to the declaration specifiers
   12087              :    SPECS, returning SPECS.  */
   12088              : 
   12089              : struct c_declspecs *
   12090          177 : declspecs_add_addrspace (location_t location,
   12091              :                          struct c_declspecs *specs, addr_space_t as)
   12092              : {
   12093          177 :   specs->non_sc_seen_p = true;
   12094          177 :   specs->declspecs_seen_p = true;
   12095          177 :   specs->non_std_attrs_seen_p = true;
   12096              : 
   12097          177 :   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
   12098            0 :       && specs->address_space != as)
   12099            0 :     error ("incompatible address space qualifiers %qs and %qs",
   12100              :            c_addr_space_name (as),
   12101              :            c_addr_space_name (specs->address_space));
   12102              :   else
   12103              :     {
   12104          177 :       specs->address_space = as;
   12105          177 :       specs->locations[cdw_address_space] = location;
   12106              :     }
   12107          177 :   return specs;
   12108              : }
   12109              : 
   12110              : /* Add the type qualifier QUAL to the declaration specifiers SPECS,
   12111              :    returning SPECS.  */
   12112              : 
   12113              : struct c_declspecs *
   12114     16671616 : declspecs_add_qual (location_t loc,
   12115              :                     struct c_declspecs *specs, tree qual)
   12116              : {
   12117     16671616 :   enum rid i;
   12118     16671616 :   bool dupe = false;
   12119     16671616 :   specs->non_sc_seen_p = true;
   12120     16671616 :   specs->declspecs_seen_p = true;
   12121     16671616 :   specs->non_std_attrs_seen_p = true;
   12122     16671616 :   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
   12123              :               && C_IS_RESERVED_WORD (qual));
   12124     16671616 :   i = C_RID_CODE (qual);
   12125     16671616 :   location_t prev_loc = UNKNOWN_LOCATION;
   12126     16671616 :   switch (i)
   12127              :     {
   12128     13140328 :     case RID_CONST:
   12129     13140328 :       dupe = specs->const_p;
   12130     13140328 :       specs->const_p = true;
   12131     13140328 :       prev_loc = specs->locations[cdw_const];
   12132     13140328 :       specs->locations[cdw_const] = loc;
   12133     13140328 :       break;
   12134        96436 :     case RID_VOLATILE:
   12135        96436 :       dupe = specs->volatile_p;
   12136        96436 :       specs->volatile_p = true;
   12137        96436 :       prev_loc = specs->locations[cdw_volatile];
   12138        96436 :       specs->locations[cdw_volatile] = loc;
   12139        96436 :       break;
   12140      3414452 :     case RID_RESTRICT:
   12141      3414452 :       dupe = specs->restrict_p;
   12142      3414452 :       specs->restrict_p = true;
   12143      3414452 :       prev_loc = specs->locations[cdw_restrict];
   12144      3414452 :       specs->locations[cdw_restrict] = loc;
   12145      3414452 :       break;
   12146        20400 :     case RID_ATOMIC:
   12147        20400 :       dupe = specs->atomic_p;
   12148        20400 :       specs->atomic_p = true;
   12149        20400 :       prev_loc = specs->locations[cdw_atomic];
   12150        20400 :       specs->locations[cdw_atomic] = loc;
   12151        20400 :       break;
   12152            0 :     default:
   12153            0 :       gcc_unreachable ();
   12154              :     }
   12155     16671616 :   if (dupe)
   12156              :     {
   12157           56 :       bool warned = pedwarn_c90 (loc, OPT_Wpedantic,
   12158              :                                  "duplicate %qE declaration specifier", qual);
   12159           56 :       if (!warned
   12160           52 :           && warn_duplicate_decl_specifier
   12161           33 :           && prev_loc >= RESERVED_LOCATION_COUNT
   12162           33 :           && !from_macro_expansion_at (prev_loc)
   12163           77 :           && !from_macro_expansion_at (loc))
   12164           12 :         warning_at (loc, OPT_Wduplicate_decl_specifier,
   12165              :                     "duplicate %qE declaration specifier", qual);
   12166              :     }
   12167     16671616 :   return specs;
   12168              : }
   12169              : 
   12170              : /* Add the type specifier TYPE to the declaration specifiers SPECS,
   12171              :    returning SPECS.  */
   12172              : 
   12173              : struct c_declspecs *
   12174    333300456 : declspecs_add_type (location_t loc, struct c_declspecs *specs,
   12175              :                     struct c_typespec spec)
   12176              : {
   12177    333300456 :   tree type = spec.spec;
   12178    333300456 :   specs->non_sc_seen_p = true;
   12179    333300456 :   specs->declspecs_seen_p = true;
   12180    333300456 :   specs->non_std_attrs_seen_p = true;
   12181    333300456 :   specs->typespec_kind = spec.kind;
   12182    333300456 :   if (TREE_DEPRECATED (type))
   12183           56 :     specs->deprecated_p = true;
   12184    333300456 :   if (TREE_UNAVAILABLE (type))
   12185           40 :     specs->unavailable_p = true;
   12186              : 
   12187              :   /* As a type specifier is present, "auto" must be used as a storage
   12188              :      class specifier, not for type deduction.  */
   12189    333300456 :   if (specs->c23_auto_p)
   12190              :     {
   12191          115 :       specs->c23_auto_p = false;
   12192          115 :       if (specs->storage_class != csc_none)
   12193            1 :         error ("multiple storage classes in declaration specifiers");
   12194          114 :       else if (specs->thread_p)
   12195            1 :         error ("%qs used with %<auto%>",
   12196            1 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   12197          113 :       else if (specs->constexpr_p)
   12198              :         /* auto may only be used with another storage class specifier,
   12199              :            such as constexpr, if the type is inferred.  */
   12200            2 :         error ("%<auto%> used with %<constexpr%>");
   12201              :       else
   12202          111 :         specs->storage_class = csc_auto;
   12203              :     }
   12204              : 
   12205              :   /* Handle type specifier keywords.  */
   12206    333300456 :   if (TREE_CODE (type) == IDENTIFIER_NODE
   12207     84101407 :       && C_IS_RESERVED_WORD (type)
   12208    417401863 :       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
   12209              :     {
   12210     84101407 :       enum rid i = C_RID_CODE (type);
   12211     84101407 :       if (specs->type)
   12212              :         {
   12213           58 :           error_at (loc, "two or more data types in declaration specifiers");
   12214           58 :           return specs;
   12215              :         }
   12216     84101349 :       if ((int) i <= (int) RID_LAST_MODIFIER)
   12217              :         {
   12218              :           /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
   12219     22094179 :           bool dupe = false;
   12220     22094179 :           switch (i)
   12221              :             {
   12222     11050804 :             case RID_LONG:
   12223     11050804 :               if (specs->long_long_p)
   12224              :                 {
   12225          104 :                   error_at (loc, "%<long long long%> is too long for GCC");
   12226          104 :                   break;
   12227              :                 }
   12228     11050700 :               if (specs->long_p)
   12229              :                 {
   12230      2967973 :                   if (specs->typespec_word == cts_double)
   12231              :                     {
   12232           15 :                       error_at (loc,
   12233              :                                 "both %qs and %qs in declaration specifiers",
   12234              :                                 "long long", "double");
   12235           15 :                       break;
   12236              :                     }
   12237      2967958 :                   pedwarn_c90 (loc, OPT_Wlong_long,
   12238              :                                "ISO C90 does not support %<long long%>");
   12239      2967958 :                   specs->long_long_p = 1;
   12240      2967958 :                   specs->locations[cdw_long_long] = loc;
   12241      2967958 :                   break;
   12242              :                 }
   12243      8082727 :               if (specs->short_p)
   12244           77 :                 error_at (loc,
   12245              :                           "both %qs and %qs in declaration specifiers",
   12246              :                           "long", "short");
   12247      8082650 :               else if (specs->typespec_word == cts_auto_type)
   12248            1 :                 error_at (loc,
   12249              :                           "both %qs and %qs in declaration specifiers",
   12250              :                           "long", "__auto_type");
   12251              :               else if (specs->typespec_word == cts_void)
   12252            5 :                 error_at (loc,
   12253              :                           "both %qs and %qs in declaration specifiers",
   12254              :                           "long", "void");
   12255              :               else if (specs->typespec_word == cts_int_n)
   12256           19 :                 error_at (loc,
   12257              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12258           19 :                           "long", int_n_data[specs->u.int_n_idx].bitsize);
   12259              :               else if (specs->typespec_word == cts_bool)
   12260            3 :                 error_at (loc,
   12261              :                           "both %qs and %qs in declaration specifiers",
   12262              :                           "long", "_Bool");
   12263              :               else if (specs->typespec_word == cts_bitint)
   12264            3 :                 error_at (loc,
   12265              :                           "both %qs and %qs in declaration specifiers",
   12266              :                           "long", "_BitInt");
   12267              :               else if (specs->typespec_word == cts_char)
   12268           21 :                 error_at (loc,
   12269              :                           "both %qs and %qs in declaration specifiers",
   12270              :                           "long", "char");
   12271              :               else if (specs->typespec_word == cts_float)
   12272            7 :                 error_at (loc,
   12273              :                           "both %qs and %qs in declaration specifiers",
   12274              :                           "long", "float");
   12275              :               else if (specs->typespec_word == cts_floatn_nx)
   12276            0 :                 error_at (loc,
   12277              :                           "both %qs and %<_Float%d%s%> in declaration "
   12278              :                           "specifiers", "long",
   12279            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12280            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12281              :                           ? "x"
   12282              :                           : "");
   12283              :               else if (specs->typespec_word == cts_dfloat32)
   12284            4 :                 error_at (loc,
   12285              :                           "both %qs and %qs in declaration specifiers",
   12286              :                           "long", "_Decimal32");
   12287              :               else if (specs->typespec_word == cts_dfloat64)
   12288            4 :                 error_at (loc,
   12289              :                           "both %qs and %qs in declaration specifiers",
   12290              :                           "long", "_Decimal64");
   12291              :               else if (specs->typespec_word == cts_dfloat128)
   12292            4 :                 error_at (loc,
   12293              :                           "both %qs and %qs in declaration specifiers",
   12294              :                           "long", "_Decimal128");
   12295              :               else if (specs->typespec_word == cts_dfloat64x)
   12296            0 :                 error_at (loc,
   12297              :                           "both %qs and %qs in declaration specifiers",
   12298              :                           "long", "_Decimal64x");
   12299              :               else
   12300              :                 {
   12301      8082579 :                   specs->long_p = true;
   12302      8082579 :                   specs->locations[cdw_long] = loc;
   12303              :                 }
   12304              :               break;
   12305      1705161 :             case RID_SHORT:
   12306      1705161 :               dupe = specs->short_p;
   12307      1705161 :               if (specs->long_p)
   12308          197 :                 error_at (loc,
   12309              :                           "both %qs and %qs in declaration specifiers",
   12310              :                           "long", "short");
   12311      1704964 :               else if (specs->typespec_word == cts_auto_type)
   12312            1 :                 error_at (loc,
   12313              :                           "both %qs and %qs in declaration specifiers",
   12314              :                           "short", "__auto_type");
   12315              :               else if (specs->typespec_word == cts_void)
   12316            5 :                 error_at (loc,
   12317              :                           "both %qs and %qs in declaration specifiers",
   12318              :                           "short", "void");
   12319              :               else if (specs->typespec_word == cts_int_n)
   12320           19 :                 error_at (loc,
   12321              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12322           19 :                           "short", int_n_data[specs->u.int_n_idx].bitsize);
   12323              :               else if (specs->typespec_word == cts_bool)
   12324            3 :                 error_at (loc,
   12325              :                           "both %qs and %qs in declaration specifiers",
   12326              :                           "short", "_Bool");
   12327              :               else if (specs->typespec_word == cts_bitint)
   12328            1 :                 error_at (loc,
   12329              :                           "both %qs and %qs in declaration specifiers",
   12330              :                           "short", "_BitInt");
   12331              :               else if (specs->typespec_word == cts_char)
   12332           21 :                 error_at (loc,
   12333              :                           "both %qs and %qs in declaration specifiers",
   12334              :                           "short", "char");
   12335              :               else if (specs->typespec_word == cts_float)
   12336            7 :                 error_at (loc,
   12337              :                           "both %qs and %qs in declaration specifiers",
   12338              :                           "short", "float");
   12339              :               else if (specs->typespec_word == cts_double)
   12340            7 :                 error_at (loc,
   12341              :                           "both %qs and %qs in declaration specifiers",
   12342              :                           "short", "double");
   12343              :               else if (specs->typespec_word == cts_floatn_nx)
   12344            0 :                 error_at (loc,
   12345              :                           "both %qs and %<_Float%d%s%> in declaration "
   12346              :                           "specifiers", "short",
   12347            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12348            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12349              :                           ? "x"
   12350              :                           : "");
   12351              :               else if (specs->typespec_word == cts_dfloat32)
   12352            4 :                 error_at (loc,
   12353              :                           "both %qs and %qs in declaration specifiers",
   12354              :                           "short", "_Decimal32");
   12355              :               else if (specs->typespec_word == cts_dfloat64)
   12356            4 :                 error_at (loc,
   12357              :                           "both %qs and %qs in declaration specifiers",
   12358              :                           "short", "_Decimal64");
   12359              :               else if (specs->typespec_word == cts_dfloat128)
   12360            4 :                 error_at (loc,
   12361              :                           "both %qs and %qs in declaration specifiers",
   12362              :                           "short", "_Decimal128");
   12363              :               else if (specs->typespec_word == cts_dfloat64x)
   12364            0 :                 error_at (loc,
   12365              :                           "both %qs and %qs in declaration specifiers",
   12366              :                           "short", "_Decimal64x");
   12367              :               else
   12368              :                 {
   12369      1704888 :                   specs->short_p = true;
   12370      1704888 :                   specs->locations[cdw_short] = loc;
   12371              :                 }
   12372              :               break;
   12373       554170 :             case RID_SIGNED:
   12374       554170 :               dupe = specs->signed_p;
   12375       554170 :               if (specs->unsigned_p)
   12376          138 :                 error_at (loc,
   12377              :                           "both %qs and %qs in declaration specifiers",
   12378              :                           "signed", "unsigned");
   12379       554032 :               else if (specs->typespec_word == cts_auto_type)
   12380            1 :                 error_at (loc,
   12381              :                           "both %qs and %qs in declaration specifiers",
   12382              :                           "signed", "__auto_type");
   12383              :               else if (specs->typespec_word == cts_void)
   12384            5 :                 error_at (loc,
   12385              :                           "both %qs and %qs in declaration specifiers",
   12386              :                           "signed", "void");
   12387              :               else if (specs->typespec_word == cts_bool)
   12388            3 :                 error_at (loc,
   12389              :                           "both %qs and %qs in declaration specifiers",
   12390              :                           "signed", "_Bool");
   12391              :               else if (specs->typespec_word == cts_float)
   12392            7 :                 error_at (loc,
   12393              :                           "both %qs and %qs in declaration specifiers",
   12394              :                           "signed", "float");
   12395              :               else if (specs->typespec_word == cts_double)
   12396           21 :                 error_at (loc,
   12397              :                           "both %qs and %qs in declaration specifiers",
   12398              :                           "signed", "double");
   12399              :               else if (specs->typespec_word == cts_floatn_nx)
   12400            0 :                 error_at (loc,
   12401              :                           "both %qs and %<_Float%d%s%> in declaration "
   12402              :                           "specifiers", "signed",
   12403            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12404            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12405              :                           ? "x"
   12406              :                           : "");
   12407              :               else if (specs->typespec_word == cts_dfloat32)
   12408            4 :                 error_at (loc,
   12409              :                           "both %qs and %qs in declaration specifiers",
   12410              :                           "signed", "_Decimal32");
   12411              :               else if (specs->typespec_word == cts_dfloat64)
   12412            4 :                 error_at (loc,
   12413              :                           "both %qs and %qs in declaration specifiers",
   12414              :                           "signed", "_Decimal64");
   12415              :               else if (specs->typespec_word == cts_dfloat128)
   12416            4 :                 error_at (loc,
   12417              :                           "both %qs and %qs in declaration specifiers",
   12418              :                           "signed", "_Decimal128");
   12419              :               else if (specs->typespec_word == cts_dfloat64x)
   12420            0 :                 error_at (loc,
   12421              :                           "both %qs and %qs in declaration specifiers",
   12422              :                           "signed", "_Decimal64x");
   12423              :               else
   12424              :                 {
   12425       553983 :                   specs->signed_p = true;
   12426       553983 :                   specs->locations[cdw_signed] = loc;
   12427              :                 }
   12428              :               break;
   12429      6206218 :             case RID_UNSIGNED:
   12430      6206218 :               dupe = specs->unsigned_p;
   12431      6206218 :               if (specs->signed_p)
   12432          139 :                 error_at (loc,
   12433              :                           "both %qs and %qs in declaration specifiers",
   12434              :                           "signed", "unsigned");
   12435      6206079 :               else if (specs->typespec_word == cts_auto_type)
   12436            1 :                 error_at (loc,
   12437              :                           "both %qs and %qs in declaration specifiers",
   12438              :                           "unsigned", "__auto_type");
   12439              :               else if (specs->typespec_word == cts_void)
   12440            5 :                 error_at (loc,
   12441              :                           "both %qs and %qs in declaration specifiers",
   12442              :                           "unsigned", "void");
   12443              :               else if (specs->typespec_word == cts_bool)
   12444            3 :                 error_at (loc,
   12445              :                           "both %qs and %qs in declaration specifiers",
   12446              :                           "unsigned", "_Bool");
   12447              :               else if (specs->typespec_word == cts_float)
   12448            7 :                 error_at (loc,
   12449              :                           "both %qs and %qs in declaration specifiers",
   12450              :                           "unsigned", "float");
   12451              :               else if (specs->typespec_word == cts_double)
   12452           21 :                 error_at (loc,
   12453              :                           "both %qs and %qs in declaration specifiers",
   12454              :                           "unsigned", "double");
   12455              :               else if (specs->typespec_word == cts_floatn_nx)
   12456            0 :                 error_at (loc,
   12457              :                           "both %qs and %<_Float%d%s%> in declaration "
   12458              :                           "specifiers", "unsigned",
   12459            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12460            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12461              :                           ? "x"
   12462              :                           : "");
   12463              :               else if (specs->typespec_word == cts_dfloat32)
   12464            2 :                 error_at (loc,
   12465              :                           "both %qs and %qs in declaration specifiers",
   12466              :                           "unsigned", "_Decimal32");
   12467              :               else if (specs->typespec_word == cts_dfloat64)
   12468            2 :                 error_at (loc,
   12469              :                           "both %qs and %qs in declaration specifiers",
   12470              :                           "unsigned", "_Decimal64");
   12471              :               else if (specs->typespec_word == cts_dfloat128)
   12472            2 :                 error_at (loc,
   12473              :                           "both %qs and %qs in declaration specifiers",
   12474              :                           "unsigned", "_Decimal128");
   12475              :               else if (specs->typespec_word == cts_dfloat64x)
   12476            0 :                 error_at (loc,
   12477              :                           "both %qs and %qs in declaration specifiers",
   12478              :                           "unsigned", "_Decimal64x");
   12479              :               else
   12480              :                 {
   12481      6206036 :                   specs->unsigned_p = true;
   12482      6206036 :                   specs->locations[cdw_unsigned] = loc;
   12483              :                 }
   12484              :               break;
   12485      2577693 :             case RID_COMPLEX:
   12486      2577693 :               dupe = specs->complex_p;
   12487      2577693 :               if (!in_system_header_at (loc))
   12488        69027 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12489              :                              "ISO C90 does not support complex types");
   12490      2577693 :               if (specs->typespec_word == cts_auto_type)
   12491            1 :                 error_at (loc,
   12492              :                           "both %qs and %qs in declaration specifiers",
   12493              :                           "complex", "__auto_type");
   12494              :               else if (specs->typespec_word == cts_void)
   12495            2 :                 error_at (loc,
   12496              :                           "both %qs and %qs in declaration specifiers",
   12497              :                           "complex", "void");
   12498              :               else if (specs->typespec_word == cts_bool)
   12499            2 :                 error_at (loc,
   12500              :                           "both %qs and %qs in declaration specifiers",
   12501              :                           "complex", "_Bool");
   12502              :               else if (specs->typespec_word == cts_bitint)
   12503            1 :                 error_at (loc,
   12504              :                           "both %qs and %qs in declaration specifiers",
   12505              :                           "complex", "_BitInt");
   12506              :               else if (specs->typespec_word == cts_dfloat32)
   12507            1 :                 error_at (loc,
   12508              :                           "both %qs and %qs in declaration specifiers",
   12509              :                           "complex", "_Decimal32");
   12510              :               else if (specs->typespec_word == cts_dfloat64)
   12511            1 :                 error_at (loc,
   12512              :                           "both %qs and %qs in declaration specifiers",
   12513              :                           "complex", "_Decimal64");
   12514              :               else if (specs->typespec_word == cts_dfloat128)
   12515            1 :                 error_at (loc,
   12516              :                           "both %qs and %qs in declaration specifiers",
   12517              :                           "complex", "_Decimal128");
   12518              :               else if (specs->typespec_word == cts_dfloat64x)
   12519            0 :                 error_at (loc,
   12520              :                           "both %qs and %qs in declaration specifiers",
   12521              :                           "complex", "_Decimal64x");
   12522              :               else if (specs->typespec_word == cts_fract)
   12523            0 :                 error_at (loc,
   12524              :                           "both %qs and %qs in declaration specifiers",
   12525              :                           "complex", "_Fract");
   12526              :               else if (specs->typespec_word == cts_accum)
   12527            0 :                 error_at (loc,
   12528              :                           "both %qs and %qs in declaration specifiers",
   12529              :                           "complex", "_Accum");
   12530      2577684 :               else if (specs->saturating_p)
   12531            0 :                 error_at (loc,
   12532              :                           "both %qs and %qs in declaration specifiers",
   12533              :                           "complex", "_Sat");
   12534              :               else
   12535              :                 {
   12536      2577684 :                   specs->complex_p = true;
   12537      2577684 :                   specs->locations[cdw_complex] = loc;
   12538              :                 }
   12539              :               break;
   12540          133 :             case RID_SAT:
   12541          133 :               dupe = specs->saturating_p;
   12542          133 :               pedwarn (loc, OPT_Wpedantic,
   12543              :                        "ISO C does not support saturating types");
   12544          133 :               if (specs->typespec_word == cts_int_n)
   12545            0 :                 error_at (loc,
   12546              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12547            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12548              :               else if (specs->typespec_word == cts_auto_type)
   12549            0 :                 error_at (loc,
   12550              :                           "both %qs and %qs in declaration specifiers",
   12551              :                           "_Sat", "__auto_type");
   12552              :               else if (specs->typespec_word == cts_void)
   12553            0 :                 error_at (loc,
   12554              :                           "both %qs and %qs in declaration specifiers",
   12555              :                           "_Sat", "void");
   12556              :               else if (specs->typespec_word == cts_bool)
   12557            0 :                 error_at (loc,
   12558              :                           "both %qs and %qs in declaration specifiers",
   12559              :                           "_Sat", "_Bool");
   12560              :               else if (specs->typespec_word == cts_bitint)
   12561            0 :                 error_at (loc,
   12562              :                           "both %qs and %qs in declaration specifiers",
   12563              :                           "_Sat", "_BitInt");
   12564              :               else if (specs->typespec_word == cts_char)
   12565            0 :                 error_at (loc,
   12566              :                           "both %qs and %qs in declaration specifiers",
   12567              :                           "_Sat", "char");
   12568              :               else if (specs->typespec_word == cts_int)
   12569            0 :                 error_at (loc,
   12570              :                           "both %qs and %qs in declaration specifiers",
   12571              :                           "_Sat", "int");
   12572              :               else if (specs->typespec_word == cts_float)
   12573            0 :                 error_at (loc,
   12574              :                           "both %qs and %qs in declaration specifiers",
   12575              :                           "_Sat", "float");
   12576              :               else if (specs->typespec_word == cts_double)
   12577            0 :                 error_at (loc,
   12578              :                           "both %qs and %qs in declaration specifiers",
   12579              :                           "_Sat", "double");
   12580              :               else if (specs->typespec_word == cts_floatn_nx)
   12581            0 :                 error_at (loc,
   12582              :                           "both %qs and %<_Float%d%s%> in declaration "
   12583              :                           "specifiers", "_Sat",
   12584            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12585            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12586              :                           ? "x"
   12587              :                           : "");
   12588              :               else if (specs->typespec_word == cts_dfloat32)
   12589            0 :                 error_at (loc,
   12590              :                           "both %qs and %qs in declaration specifiers",
   12591              :                           "_Sat", "_Decimal32");
   12592              :               else if (specs->typespec_word == cts_dfloat64)
   12593            0 :                 error_at (loc,
   12594              :                           "both %qs and %qs in declaration specifiers",
   12595              :                           "_Sat", "_Decimal64");
   12596              :               else if (specs->typespec_word == cts_dfloat128)
   12597            0 :                 error_at (loc,
   12598              :                           "both %qs and %qs in declaration specifiers",
   12599              :                           "_Sat", "_Decimal128");
   12600              :               else if (specs->typespec_word == cts_dfloat64x)
   12601            0 :                 error_at (loc,
   12602              :                           "both %qs and %qs in declaration specifiers",
   12603              :                           "_Sat", "_Decimal64x");
   12604          133 :               else if (specs->complex_p)
   12605            0 :                 error_at (loc,
   12606              :                           "both %qs and %qs in declaration specifiers",
   12607              :                           "_Sat", "complex");
   12608              :               else
   12609              :                 {
   12610          133 :                   specs->saturating_p = true;
   12611          133 :                   specs->locations[cdw_saturating] = loc;
   12612              :                 }
   12613              :               break;
   12614            0 :             default:
   12615            0 :               gcc_unreachable ();
   12616              :             }
   12617              : 
   12618     22094179 :           if (dupe)
   12619          378 :             error_at (loc, "duplicate %qE", type);
   12620              : 
   12621     22094179 :           return specs;
   12622              :         }
   12623              :       else
   12624              :         {
   12625              :           /* "void", "_Bool", "char", "int", "float", "double",
   12626              :              "_FloatN", "_FloatNx", "_Decimal32", "__intN",
   12627              :              "_Decimal64", "_Decimal128", "_Fract", "_Accum", "_BitInt(N)" or
   12628              :              "__auto_type".  */
   12629     62007170 :           if (specs->typespec_word != cts_none)
   12630              :             {
   12631         2171 :               if (i == RID_BOOL)
   12632              :                 {
   12633          175 :                   auto_diagnostic_group d;
   12634          175 :                   if (specs->storage_class == csc_typedef)
   12635            4 :                     error_at (loc,
   12636              :                               "%qs cannot be defined via %<typedef%>",
   12637            2 :                               IDENTIFIER_POINTER (type));
   12638              :                   else
   12639          346 :                     error_at (loc,
   12640              :                               "%qs cannot be used here",
   12641          173 :                               IDENTIFIER_POINTER (type));
   12642          175 :                   add_note_about_new_keyword (loc, type);
   12643          175 :                 }
   12644              :               else
   12645         1996 :                 error_at (loc,
   12646              :                           "two or more data types in declaration specifiers");
   12647         2171 :               return specs;
   12648              :             }
   12649     62004999 :           switch (i)
   12650              :             {
   12651         1890 :             case RID_AUTO_TYPE:
   12652         1890 :               if (specs->long_p)
   12653            1 :                 error_at (loc,
   12654              :                           "both %qs and %qs in declaration specifiers",
   12655              :                           "long", "__auto_type");
   12656         1889 :               else if (specs->short_p)
   12657            1 :                 error_at (loc,
   12658              :                           "both %qs and %qs in declaration specifiers",
   12659              :                           "short", "__auto_type");
   12660         1888 :               else if (specs->signed_p)
   12661            1 :                 error_at (loc,
   12662              :                           "both %qs and %qs in declaration specifiers",
   12663              :                           "signed", "__auto_type");
   12664         1887 :               else if (specs->unsigned_p)
   12665            1 :                 error_at (loc,
   12666              :                           "both %qs and %qs in declaration specifiers",
   12667              :                           "unsigned", "__auto_type");
   12668         1886 :               else if (specs->complex_p)
   12669            1 :                 error_at (loc,
   12670              :                           "both %qs and %qs in declaration specifiers",
   12671              :                           "complex", "__auto_type");
   12672         1885 :               else if (specs->saturating_p)
   12673            0 :                 error_at (loc,
   12674              :                           "both %qs and %qs in declaration specifiers",
   12675              :                           "_Sat", "__auto_type");
   12676              :               else
   12677              :                 {
   12678         1885 :                   specs->typespec_word = cts_auto_type;
   12679         1885 :                   specs->locations[cdw_typespec] = loc;
   12680              :                 }
   12681         1890 :               return specs;
   12682        51944 :             case RID_INT_N_0:
   12683        51944 :             case RID_INT_N_1:
   12684        51944 :             case RID_INT_N_2:
   12685        51944 :             case RID_INT_N_3:
   12686        51944 :               specs->u.int_n_idx = i - RID_INT_N_0;
   12687        51944 :               if (!in_system_header_at (input_location)
   12688              :                   /* If the INT_N type ends in "__", and so is of the format
   12689              :                      "__intN__", don't pedwarn.  */
   12690        51944 :                   && (strncmp (IDENTIFIER_POINTER (type)
   12691        41224 :                                + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0))
   12692        41224 :                 pedwarn (loc, OPT_Wpedantic,
   12693              :                          "ISO C does not support %<__int%d%> types",
   12694        41224 :                          int_n_data[specs->u.int_n_idx].bitsize);
   12695              : 
   12696        51944 :               if (specs->long_p)
   12697           53 :                 error_at (loc,
   12698              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12699           53 :                           int_n_data[specs->u.int_n_idx].bitsize, "long");
   12700        51891 :               else if (specs->saturating_p)
   12701            0 :                 error_at (loc,
   12702              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12703            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12704        51891 :               else if (specs->short_p)
   12705           19 :                 error_at (loc,
   12706              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12707           19 :                           int_n_data[specs->u.int_n_idx].bitsize, "short");
   12708        51872 :               else if (! int_n_enabled_p[specs->u.int_n_idx])
   12709              :                 {
   12710            0 :                   specs->typespec_word = cts_int_n;
   12711            0 :                   error_at (loc,
   12712              :                             "%<__int%d%> is not supported on this target",
   12713            0 :                             int_n_data[specs->u.int_n_idx].bitsize);
   12714              :                 }
   12715              :               else
   12716              :                 {
   12717        51872 :                   specs->typespec_word = cts_int_n;
   12718        51872 :                   specs->locations[cdw_typespec] = loc;
   12719              :                 }
   12720        51944 :               return specs;
   12721      7991210 :             case RID_VOID:
   12722      7991210 :               if (specs->long_p)
   12723           44 :                 error_at (loc,
   12724              :                           "both %qs and %qs in declaration specifiers",
   12725              :                           "long", "void");
   12726      7991166 :               else if (specs->short_p)
   12727           21 :                 error_at (loc,
   12728              :                           "both %qs and %qs in declaration specifiers",
   12729              :                           "short", "void");
   12730      7991145 :               else if (specs->signed_p)
   12731            5 :                 error_at (loc,
   12732              :                           "both %qs and %qs in declaration specifiers",
   12733              :                           "signed", "void");
   12734      7991140 :               else if (specs->unsigned_p)
   12735            5 :                 error_at (loc,
   12736              :                           "both %qs and %qs in declaration specifiers",
   12737              :                           "unsigned", "void");
   12738      7991135 :               else if (specs->complex_p)
   12739            2 :                 error_at (loc,
   12740              :                           "both %qs and %qs in declaration specifiers",
   12741              :                           "complex", "void");
   12742      7991133 :               else if (specs->saturating_p)
   12743            0 :                 error_at (loc,
   12744              :                           "both %qs and %qs in declaration specifiers",
   12745              :                           "_Sat", "void");
   12746              :               else
   12747              :                 {
   12748      7991133 :                   specs->typespec_word = cts_void;
   12749      7991133 :                   specs->locations[cdw_typespec] = loc;
   12750              :                 }
   12751      7991210 :               return specs;
   12752        90528 :             case RID_BOOL:
   12753        90528 :               if (!in_system_header_at (loc))
   12754        72437 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12755              :                              "ISO C90 does not support boolean types");
   12756        90528 :               if (specs->long_p)
   12757           27 :                 error_at (loc,
   12758              :                           "both %qs and %qs in declaration specifiers",
   12759              :                           "long", "_Bool");
   12760        90501 :               else if (specs->short_p)
   12761           11 :                 error_at (loc,
   12762              :                           "both %qs and %qs in declaration specifiers",
   12763              :                           "short", "_Bool");
   12764        90490 :               else if (specs->signed_p)
   12765            3 :                 error_at (loc,
   12766              :                           "both %qs and %qs in declaration specifiers",
   12767              :                           "signed", "_Bool");
   12768        90487 :               else if (specs->unsigned_p)
   12769            3 :                 error_at (loc,
   12770              :                           "both %qs and %qs in declaration specifiers",
   12771              :                           "unsigned", "_Bool");
   12772        90484 :               else if (specs->complex_p)
   12773            2 :                 error_at (loc,
   12774              :                           "both %qs and %qs in declaration specifiers",
   12775              :                           "complex", "_Bool");
   12776        90482 :               else if (specs->saturating_p)
   12777            0 :                 error_at (loc,
   12778              :                           "both %qs and %qs in declaration specifiers",
   12779              :                           "_Sat", "_Bool");
   12780              :               else
   12781              :                 {
   12782        90482 :                   specs->typespec_word = cts_bool;
   12783        90482 :                   specs->locations[cdw_typespec] = loc;
   12784              :                 }
   12785        90528 :               return specs;
   12786      9068631 :             case RID_CHAR:
   12787      9068631 :               if (specs->long_p)
   12788           44 :                 error_at (loc,
   12789              :                           "both %qs and %qs in declaration specifiers",
   12790              :                           "long", "char");
   12791      9068587 :               else if (specs->short_p)
   12792           21 :                 error_at (loc,
   12793              :                           "both %qs and %qs in declaration specifiers",
   12794              :                           "short", "char");
   12795      9068566 :               else if (specs->saturating_p)
   12796            0 :                 error_at (loc,
   12797              :                           "both %qs and %qs in declaration specifiers",
   12798              :                           "_Sat", "char");
   12799              :               else
   12800              :                 {
   12801      9068566 :                   specs->typespec_word = cts_char;
   12802      9068566 :                   specs->locations[cdw_typespec] = loc;
   12803              :                 }
   12804      9068631 :               return specs;
   12805     24034044 :             case RID_INT:
   12806     24034044 :               if (specs->saturating_p)
   12807            0 :                 error_at (loc,
   12808              :                           "both %qs and %qs in declaration specifiers",
   12809              :                           "_Sat", "int");
   12810              :               else
   12811              :                 {
   12812     24034044 :                   specs->typespec_word = cts_int;
   12813     24034044 :                   specs->locations[cdw_typespec] = loc;
   12814              :                 }
   12815     24034044 :               return specs;
   12816      3632802 :             case RID_FLOAT:
   12817      3632802 :               if (specs->long_p)
   12818           44 :                 error_at (loc,
   12819              :                           "both %qs and %qs in declaration specifiers",
   12820              :                           "long", "float");
   12821      3632758 :               else if (specs->short_p)
   12822           21 :                 error_at (loc,
   12823              :                           "both %qs and %qs in declaration specifiers",
   12824              :                           "short", "float");
   12825      3632737 :               else if (specs->signed_p)
   12826            5 :                 error_at (loc,
   12827              :                           "both %qs and %qs in declaration specifiers",
   12828              :                           "signed", "float");
   12829      3632732 :               else if (specs->unsigned_p)
   12830            5 :                 error_at (loc,
   12831              :                           "both %qs and %qs in declaration specifiers",
   12832              :                           "unsigned", "float");
   12833      3632727 :               else if (specs->saturating_p)
   12834            0 :                 error_at (loc,
   12835              :                           "both %qs and %qs in declaration specifiers",
   12836              :                           "_Sat", "float");
   12837              :               else
   12838              :                 {
   12839      3632727 :                   specs->typespec_word = cts_float;
   12840      3632727 :                   specs->locations[cdw_typespec] = loc;
   12841              :                 }
   12842      3632802 :               return specs;
   12843      6609183 :             case RID_DOUBLE:
   12844      6609183 :               if (specs->long_long_p)
   12845           22 :                 error_at (loc,
   12846              :                           "both %qs and %qs in declaration specifiers",
   12847              :                           "long long", "double");
   12848      6609161 :               else if (specs->short_p)
   12849           21 :                 error_at (loc,
   12850              :                           "both %qs and %qs in declaration specifiers",
   12851              :                           "short", "double");
   12852      6609140 :               else if (specs->signed_p)
   12853           13 :                 error_at (loc,
   12854              :                           "both %qs and %qs in declaration specifiers",
   12855              :                           "signed", "double");
   12856      6609127 :               else if (specs->unsigned_p)
   12857           13 :                 error_at (loc,
   12858              :                           "both %qs and %qs in declaration specifiers",
   12859              :                           "unsigned", "double");
   12860      6609114 :               else if (specs->saturating_p)
   12861            0 :                 error_at (loc,
   12862              :                           "both %qs and %qs in declaration specifiers",
   12863              :                           "_Sat", "double");
   12864              :               else
   12865              :                 {
   12866      6609114 :                   specs->typespec_word = cts_double;
   12867      6609114 :                   specs->locations[cdw_typespec] = loc;
   12868              :                 }
   12869      6609183 :               return specs;
   12870     10430255 :             CASE_RID_FLOATN_NX:
   12871     10430255 :               specs->u.floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
   12872     10430255 :               if (!in_system_header_at (input_location))
   12873        53763 :                 pedwarn_c11 (loc, OPT_Wpedantic,
   12874              :                              "ISO C does not support the %<_Float%d%s%> type"
   12875              :                              " before C23",
   12876        53763 :                              floatn_nx_types[specs->u.floatn_nx_idx].n,
   12877        53763 :                              floatn_nx_types[specs->u.floatn_nx_idx].extended
   12878              :                              ? "x"
   12879              :                              : "");
   12880              : 
   12881     10430255 :               if (specs->long_p)
   12882            0 :                 error_at (loc,
   12883              :                           "both %qs and %<_Float%d%s%> in declaration "
   12884              :                           "specifiers", "long",
   12885            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12886            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12887              :                           ? "x"
   12888              :                           : "");
   12889     10430255 :               else if (specs->short_p)
   12890            0 :                 error_at (loc,
   12891              :                           "both %qs and %<_Float%d%s%> in declaration "
   12892              :                           "specifiers", "short",
   12893            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12894            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12895              :                           ? "x"
   12896              :                           : "");
   12897     10430255 :               else if (specs->signed_p)
   12898            0 :                 error_at (loc,
   12899              :                           "both %qs and %<_Float%d%s%> in declaration "
   12900              :                           "specifiers", "signed",
   12901            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12902            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12903              :                           ? "x"
   12904              :                           : "");
   12905     10430255 :               else if (specs->unsigned_p)
   12906            0 :                 error_at (loc,
   12907              :                           "both %qs and %<_Float%d%s%> in declaration "
   12908              :                           "specifiers", "unsigned",
   12909            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12910            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12911              :                           ? "x"
   12912              :                           : "");
   12913     10430255 :               else if (specs->saturating_p)
   12914            0 :                 error_at (loc,
   12915              :                           "both %qs and %<_Float%d%s%> in declaration "
   12916              :                           "specifiers", "_Sat",
   12917            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12918            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12919              :                           ? "x"
   12920              :                           : "");
   12921     10430255 :               else if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   12922              :                 {
   12923           88 :                   specs->typespec_word = cts_floatn_nx;
   12924          176 :                   error_at (loc,
   12925              :                             "%<_Float%d%s%> is not supported on this target",
   12926           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].n,
   12927           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].extended
   12928              :                             ? "x"
   12929              :                             : "");
   12930              :                 }
   12931              :               else
   12932              :                 {
   12933     10430167 :                   specs->typespec_word = cts_floatn_nx;
   12934     10430167 :                   specs->locations[cdw_typespec] = loc;
   12935              :                 }
   12936     10430255 :               return specs;
   12937        47640 :             case RID_DFLOAT32:
   12938        47640 :             case RID_DFLOAT64:
   12939        47640 :             case RID_DFLOAT128:
   12940        47640 :             case RID_DFLOAT64X:
   12941        47640 :               {
   12942        47640 :                 const char *str;
   12943        47640 :                 if (i == RID_DFLOAT32)
   12944              :                   str = "_Decimal32";
   12945              :                 else if (i == RID_DFLOAT64)
   12946              :                   str = "_Decimal64";
   12947              :                 else if (i == RID_DFLOAT128)
   12948              :                   str = "_Decimal128";
   12949              :                 else
   12950        47640 :                   str = "_Decimal64x";
   12951        47640 :                 if (specs->long_long_p)
   12952           18 :                   error_at (loc,
   12953              :                             "both %qs and %qs in declaration specifiers",
   12954              :                             "long long", str);
   12955        47640 :                 if (specs->long_p)
   12956           33 :                   error_at (loc,
   12957              :                             "both %qs and %qs in declaration specifiers",
   12958              :                             "long", str);
   12959        47607 :                 else if (specs->short_p)
   12960           18 :                   error_at (loc,
   12961              :                             "both %qs and %qs in declaration specifiers",
   12962              :                             "short", str);
   12963        47589 :                 else if (specs->signed_p)
   12964            6 :                   error_at (loc,
   12965              :                             "both %qs and %qs in declaration specifiers",
   12966              :                             "signed", str);
   12967        47583 :                 else if (specs->unsigned_p)
   12968            3 :                   error_at (loc,
   12969              :                             "both %qs and %qs in declaration specifiers",
   12970              :                             "unsigned", str);
   12971        47580 :                 else if (specs->complex_p)
   12972            3 :                   error_at (loc,
   12973              :                             "both %qs and %qs in declaration specifiers",
   12974              :                             "complex", str);
   12975        47577 :                 else if (specs->saturating_p)
   12976            0 :                   error_at (loc,
   12977              :                             "both %qs and %qs in declaration specifiers",
   12978              :                             "_Sat", str);
   12979        47577 :                 else if (i == RID_DFLOAT32)
   12980        15957 :                   specs->typespec_word = cts_dfloat32;
   12981        31620 :                 else if (i == RID_DFLOAT64)
   12982        15839 :                   specs->typespec_word = cts_dfloat64;
   12983        15781 :                 else if (i == RID_DFLOAT128)
   12984        15734 :                   specs->typespec_word = cts_dfloat128;
   12985              :                 else
   12986           47 :                   specs->typespec_word = cts_dfloat64x;
   12987        47640 :                 specs->locations[cdw_typespec] = loc;
   12988              :               }
   12989        47640 :               if (!targetm.decimal_float_supported_p ())
   12990            0 :                 error_at (loc,
   12991              :                           "decimal floating-point not supported "
   12992              :                           "for this target");
   12993        47640 :               pedwarn_c11 (loc, OPT_Wpedantic,
   12994              :                            "ISO C does not support decimal floating-point "
   12995              :                            "before C23");
   12996        47640 :               return specs;
   12997          135 :             case RID_FRACT:
   12998          135 :             case RID_ACCUM:
   12999          135 :               {
   13000          135 :                 const char *str;
   13001          135 :                 if (i == RID_FRACT)
   13002              :                   str = "_Fract";
   13003              :                 else
   13004           67 :                   str = "_Accum";
   13005          135 :                 if (specs->complex_p)
   13006            0 :                   error_at (loc,
   13007              :                             "both %qs and %qs in declaration specifiers",
   13008              :                             "complex", str);
   13009          135 :                 else if (i == RID_FRACT)
   13010           68 :                     specs->typespec_word = cts_fract;
   13011              :                 else
   13012           67 :                     specs->typespec_word = cts_accum;
   13013          135 :                 specs->locations[cdw_typespec] = loc;
   13014              :               }
   13015          135 :               if (!targetm.fixed_point_supported_p ())
   13016          135 :                 error_at (loc,
   13017              :                           "fixed-point types not supported for this target");
   13018          135 :               pedwarn (loc, OPT_Wpedantic,
   13019              :                        "ISO C does not support fixed-point types");
   13020          135 :               return specs;
   13021        46737 :             case RID_BITINT:
   13022        46737 :               if (specs->long_p)
   13023            2 :                 error_at (loc,
   13024              :                           "both %qs and %qs in declaration specifiers",
   13025              :                           "long", "_BitInt");
   13026        46735 :               else if (specs->short_p)
   13027            1 :                 error_at (loc,
   13028              :                           "both %qs and %qs in declaration specifiers",
   13029              :                           "short", "_BitInt");
   13030        46734 :               else if (specs->complex_p)
   13031            1 :                 error_at (loc,
   13032              :                           "both %qs and %qs in declaration specifiers",
   13033              :                           "complex", "_BitInt");
   13034        46733 :               else if (specs->saturating_p)
   13035            0 :                 error_at (loc,
   13036              :                           "both %qs and %qs in declaration specifiers",
   13037              :                           "_Sat", "_BitInt");
   13038              :               else
   13039              :                 {
   13040        46733 :                   specs->typespec_word = cts_bitint;
   13041        46733 :                   specs->locations[cdw_typespec] = loc;
   13042        46733 :                   specs->u.bitint_prec = -1;
   13043        46733 :                   if (error_operand_p (spec.expr))
   13044            7 :                     return specs;
   13045        46733 :                   if (TREE_CODE (spec.expr) != INTEGER_CST
   13046        46733 :                       || !INTEGRAL_TYPE_P (TREE_TYPE (spec.expr)))
   13047              :                     {
   13048            1 :                       error_at (loc, "%<_BitInt%> argument is not an integer "
   13049              :                                      "constant expression");
   13050            1 :                       return specs;
   13051              :                     }
   13052        46732 :                   if (tree_int_cst_sgn (spec.expr) <= 0)
   13053              :                     {
   13054            4 :                       error_at (loc, "%<_BitInt%> argument %qE is not a "
   13055              :                                      "positive integer constant expression",
   13056              :                                 spec.expr);
   13057            4 :                       return specs;
   13058              :                     }
   13059        46728 :                   if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1)
   13060              :                     {
   13061            2 :                       error_at (loc, "%<_BitInt%> argument %qE is larger than "
   13062              :                                      "%<BITINT_MAXWIDTH%> %qd",
   13063              :                                 spec.expr, (int) WIDE_INT_MAX_PRECISION - 1);
   13064            2 :                       return specs;
   13065              :                     }
   13066        46726 :                   specs->u.bitint_prec = tree_to_uhwi (spec.expr);
   13067        46726 :                   struct bitint_info info;
   13068        46726 :                   if (!targetm.c.bitint_type_info (specs->u.bitint_prec,
   13069              :                                                    &info))
   13070              :                     {
   13071            0 :                       sorry_at (loc, "%<_BitInt(%d)%> is not supported on "
   13072              :                                      "this target", specs->u.bitint_prec);
   13073            0 :                       specs->u.bitint_prec = -1;
   13074            0 :                       return specs;
   13075              :                     }
   13076              :                 }
   13077        46730 :               return specs;
   13078              :             default:
   13079              :               /* ObjC reserved word "id", handled below.  */
   13080              :               break;
   13081              :             }
   13082              :         }
   13083              :     }
   13084              : 
   13085              :   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
   13086              :      form of ObjC type, cases such as "int" and "long" being handled
   13087              :      above), a TYPE (struct, union, enum and typeof specifiers) or an
   13088              :      ERROR_MARK.  In none of these cases may there have previously
   13089              :      been any type specifiers.  */
   13090    249199049 :   if (specs->type || specs->typespec_word != cts_none
   13091    249199037 :       || specs->long_p || specs->short_p || specs->signed_p
   13092    249199034 :       || specs->unsigned_p || specs->complex_p)
   13093           21 :     error_at (loc, "two or more data types in declaration specifiers");
   13094    249199028 :   else if (TREE_CODE (type) == TYPE_DECL)
   13095              :     {
   13096    245901319 :       specs->type = TREE_TYPE (type);
   13097    245901319 :       if (TREE_TYPE (type) != error_mark_node)
   13098              :         {
   13099    245901304 :           mark_decl_used (type, false);
   13100    245901304 :           specs->decl_attr = DECL_ATTRIBUTES (type);
   13101    245901304 :           specs->typedef_p = true;
   13102    245901304 :           specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
   13103    245901304 :           specs->locations[cdw_typedef] = loc;
   13104              : 
   13105              :           /* If this typedef name is defined in a struct, then a C++
   13106              :              lookup would return a different value.  */
   13107    245901304 :           if (warn_cxx_compat
   13108    245901304 :               && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
   13109            2 :             warning_at (loc, OPT_Wc___compat,
   13110              :                         "C++ lookup of %qD would return a field, not a type",
   13111              :                         type);
   13112              : 
   13113              :           /* If we are parsing a struct, record that a struct field
   13114              :              used a typedef.  */
   13115    245901304 :           if (warn_cxx_compat && struct_parse_info != NULL)
   13116         1766 :             struct_parse_info->typedefs_seen.safe_push (type);
   13117              :         }
   13118              :     }
   13119      3297709 :   else if (TREE_CODE (type) == IDENTIFIER_NODE)
   13120              :     {
   13121            0 :       tree t = lookup_name (type);
   13122            0 :       if (!t || TREE_CODE (t) != TYPE_DECL)
   13123            0 :         error_at (loc, "%qE fails to be a typedef or built in type", type);
   13124            0 :       else if (TREE_TYPE (t) == error_mark_node)
   13125              :         ;
   13126              :       else
   13127              :         {
   13128            0 :           specs->type = TREE_TYPE (t);
   13129            0 :           specs->locations[cdw_typespec] = loc;
   13130              :         }
   13131              :     }
   13132              :   else
   13133              :     {
   13134      3297709 :       if (TREE_CODE (type) != ERROR_MARK)
   13135              :         {
   13136      3297503 :           if (spec.kind == ctsk_typeof)
   13137              :             {
   13138       834021 :               specs->typedef_p = true;
   13139       834021 :               specs->locations[cdw_typedef] = loc;
   13140              :             }
   13141              : 
   13142      3297503 :           if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
   13143      1068985 :               || TREE_CODE (type) == ENUMERAL_TYPE)
   13144      2472077 :             mark_decl_used (TYPE_STUB_DECL (type), false);
   13145              : 
   13146      3297503 :           if (spec.expr)
   13147              :             {
   13148          957 :               tree expr = save_expr (fold_convert (void_type_node, spec.expr));
   13149          957 :               if (specs->expr)
   13150            0 :                 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
   13151              :                                       specs->expr, expr);
   13152              :               else
   13153          957 :                 specs->expr = expr;
   13154          957 :               specs->expr_const_operands &= spec.expr_const_operands;
   13155              :             }
   13156              :         }
   13157      3297709 :       specs->type = type;
   13158      3297709 :       if (spec.has_enum_type_specifier
   13159          190 :           && spec.kind != ctsk_tagdef)
   13160           49 :         specs->enum_type_specifier_ref_p = true;
   13161              :     }
   13162              : 
   13163              :   return specs;
   13164              : }
   13165              : 
   13166              : /* Add the storage class specifier or function specifier SCSPEC to the
   13167              :    declaration specifiers SPECS, returning SPECS.  */
   13168              : 
   13169              : struct c_declspecs *
   13170     90842160 : declspecs_add_scspec (location_t loc,
   13171              :                       struct c_declspecs *specs,
   13172              :                       tree scspec)
   13173              : {
   13174     90842160 :   enum rid i;
   13175     90842160 :   enum c_storage_class n = csc_none;
   13176     90842160 :   bool dupe = false;
   13177     90842160 :   specs->declspecs_seen_p = true;
   13178     90842160 :   specs->non_std_attrs_seen_p = true;
   13179     90842160 :   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
   13180              :               && C_IS_RESERVED_WORD (scspec));
   13181     90842160 :   i = C_RID_CODE (scspec);
   13182     90842160 :   if (specs->non_sc_seen_p)
   13183         2100 :     warning (OPT_Wold_style_declaration,
   13184              :              "%qE is not at beginning of declaration", scspec);
   13185     90842160 :   switch (i)
   13186              :     {
   13187     35637082 :     case RID_INLINE:
   13188              :       /* C99 permits duplicate inline.  Although of doubtful utility,
   13189              :          it seems simplest to permit it in gnu89 mode as well, as
   13190              :          there is also little utility in maintaining this as a
   13191              :          difference between gnu89 and C99 inline.  */
   13192     35637082 :       dupe = false;
   13193     35637082 :       specs->inline_p = true;
   13194     35637082 :       specs->locations[cdw_inline] = loc;
   13195     35637082 :       break;
   13196        23317 :     case RID_NORETURN:
   13197              :       /* Duplicate _Noreturn is permitted.  */
   13198        23317 :       dupe = false;
   13199        23317 :       specs->noreturn_p = true;
   13200        23317 :       specs->locations[cdw_noreturn] = loc;
   13201        23317 :       break;
   13202         2913 :     case RID_THREAD:
   13203         2913 :       dupe = specs->thread_p;
   13204         2913 :       if (specs->storage_class == csc_auto)
   13205            2 :         error ("%qE used with %<auto%>", scspec);
   13206         2911 :       else if (specs->storage_class == csc_register)
   13207            3 :         error ("%qE used with %<register%>", scspec);
   13208         2908 :       else if (specs->storage_class == csc_typedef)
   13209            2 :         error ("%qE used with %<typedef%>", scspec);
   13210         2906 :       else if (specs->constexpr_p)
   13211            2 :         error ("%qE used with %<constexpr%>", scspec);
   13212              :       else
   13213              :         {
   13214         2904 :           specs->thread_p = true;
   13215         2904 :           specs->thread_gnu_p = (strcmp (IDENTIFIER_POINTER (scspec),
   13216         2904 :                                          "__thread") == 0);
   13217              :           /* A diagnostic is not required for the use of this
   13218              :              identifier in the implementation namespace; only diagnose
   13219              :              it for the C11 spelling because of existing code using
   13220              :              the other spelling.  */
   13221         2904 :           if (!specs->thread_gnu_p)
   13222              :             {
   13223          116 :               if (flag_isoc99)
   13224          113 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13225              :                              "ISO C99 does not support %qE", scspec);
   13226              :               else
   13227            3 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13228              :                              "ISO C90 does not support %qE", scspec);
   13229              :             }
   13230         2904 :           specs->locations[cdw_thread] = loc;
   13231              :         }
   13232              :       break;
   13233          264 :     case RID_AUTO:
   13234          264 :       if (flag_isoc23
   13235          225 :           && specs->typespec_kind == ctsk_none
   13236          214 :           && specs->storage_class != csc_typedef)
   13237              :         {
   13238              :           /* "auto" potentially used for type deduction.  */
   13239          213 :           if (specs->c23_auto_p)
   13240            2 :             error ("duplicate %qE", scspec);
   13241          213 :           specs->c23_auto_p = true;
   13242          213 :           return specs;
   13243              :         }
   13244           51 :       n = csc_auto;
   13245              :       /* auto may only be used with another storage class specifier,
   13246              :          such as constexpr, if the type is inferred.  */
   13247           51 :       if (specs->constexpr_p)
   13248            2 :         error ("%qE used with %<constexpr%>", scspec);
   13249              :       break;
   13250     50406869 :     case RID_EXTERN:
   13251     50406869 :       n = csc_extern;
   13252              :       /* Diagnose "__thread extern".  */
   13253     50406869 :       if (specs->thread_p && specs->thread_gnu_p)
   13254            2 :         error ("%<__thread%> before %<extern%>");
   13255              :       break;
   13256              :     case RID_REGISTER:
   13257              :       n = csc_register;
   13258              :       break;
   13259       428145 :     case RID_STATIC:
   13260       428145 :       n = csc_static;
   13261              :       /* Diagnose "__thread static".  */
   13262       428145 :       if (specs->thread_p && specs->thread_gnu_p)
   13263            1 :         error ("%<__thread%> before %<static%>");
   13264              :       break;
   13265      4339817 :     case RID_TYPEDEF:
   13266      4339817 :       n = csc_typedef;
   13267      4339817 :       if (specs->c23_auto_p)
   13268              :         {
   13269            1 :           error ("%<typedef%> used with %<auto%>");
   13270            1 :           specs->c23_auto_p = false;
   13271              :         }
   13272              :       break;
   13273          620 :     case RID_CONSTEXPR:
   13274          620 :       dupe = specs->constexpr_p;
   13275          620 :       if (specs->storage_class == csc_extern)
   13276            1 :         error ("%qE used with %<extern%>", scspec);
   13277          619 :       else if (specs->storage_class == csc_typedef)
   13278            1 :         error ("%qE used with %<typedef%>", scspec);
   13279          618 :       else if (specs->storage_class == csc_auto)
   13280              :         /* auto may only be used with another storage class specifier,
   13281              :            such as constexpr, if the type is inferred.  */
   13282            2 :         error ("%qE used with %<auto%>", scspec);
   13283          616 :       else if (specs->thread_p)
   13284            4 :         error ("%qE used with %qs", scspec,
   13285            2 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   13286              :       else
   13287          614 :         specs->constexpr_p = true;
   13288              :       break;
   13289            0 :     default:
   13290            0 :       gcc_unreachable ();
   13291              :     }
   13292     90841953 :   if (n != csc_none && n == specs->storage_class)
   13293              :     dupe = true;
   13294     90841939 :   if (dupe)
   13295              :     {
   13296           12 :       if (i == RID_THREAD)
   13297            2 :         error ("duplicate %<_Thread_local%> or %<__thread%>");
   13298              :       else
   13299           10 :         error ("duplicate %qE", scspec);
   13300              :     }
   13301     90841947 :   if (n != csc_none)
   13302              :     {
   13303     55178015 :       if (specs->storage_class != csc_none && n != specs->storage_class)
   13304              :         {
   13305            7 :           error ("multiple storage classes in declaration specifiers");
   13306              :         }
   13307              :       else
   13308              :         {
   13309     55178008 :           specs->storage_class = n;
   13310     55178008 :           specs->locations[cdw_storage_class] = loc;
   13311     55178008 :           if (n != csc_extern && n != csc_static && specs->thread_p)
   13312              :             {
   13313            8 :               error ("%qs used with %qE",
   13314            8 :                      specs->thread_gnu_p ? "__thread" : "_Thread_local",
   13315              :                      scspec);
   13316            8 :               specs->thread_p = false;
   13317              :             }
   13318     55178008 :           if (n != csc_auto && n != csc_register && n != csc_static
   13319     54746683 :               && specs->constexpr_p)
   13320              :             {
   13321            2 :               error ("%<constexpr%> used with %qE", scspec);
   13322            2 :               specs->constexpr_p = false;
   13323              :             }
   13324              :         }
   13325              :     }
   13326              :   return specs;
   13327              : }
   13328              : 
   13329              : /* Add the attributes ATTRS to the declaration specifiers SPECS,
   13330              :    returning SPECS.  */
   13331              : 
   13332              : struct c_declspecs *
   13333     35948175 : declspecs_add_attrs (location_t loc, struct c_declspecs *specs, tree attrs)
   13334              : {
   13335     35948175 :   specs->attrs = chainon (attrs, specs->attrs);
   13336     35948175 :   specs->locations[cdw_attributes] = loc;
   13337     35948175 :   specs->declspecs_seen_p = true;
   13338              :   /* In the case of standard attributes at the start of the
   13339              :      declaration, the caller will reset this.  */
   13340     35948175 :   specs->non_std_attrs_seen_p = true;
   13341     35948175 :   return specs;
   13342              : }
   13343              : 
   13344              : /* Add an _Alignas specifier (expression ALIGN, or type whose
   13345              :    alignment is ALIGN) to the declaration specifiers SPECS, returning
   13346              :    SPECS.  */
   13347              : struct c_declspecs *
   13348          202 : declspecs_add_alignas (location_t loc,
   13349              :                        struct c_declspecs *specs, tree align)
   13350              : {
   13351          202 :   specs->alignas_p = true;
   13352          202 :   specs->locations[cdw_alignas] = loc;
   13353          202 :   if (align == error_mark_node)
   13354              :     return specs;
   13355              : 
   13356              :   /* Only accept the alignment if it's valid and greater than
   13357              :      the current one.  Zero is invalid but by C11 required to
   13358              :      be silently ignored.  */
   13359          200 :   int align_log = check_user_alignment (align, false, /* warn_zero = */false);
   13360          200 :   if (align_log > specs->align_log)
   13361          167 :     specs->align_log = align_log;
   13362              :   return specs;
   13363              : }
   13364              : 
   13365              : /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
   13366              :    specifiers with any other type specifier to determine the resulting
   13367              :    type.  This is where ISO C checks on complex types are made, since
   13368              :    "_Complex long" is a prefix of the valid ISO C type "_Complex long
   13369              :    double".  Also apply postfix standard attributes to modify the type.  */
   13370              : 
   13371              : struct c_declspecs *
   13372    315394099 : finish_declspecs (struct c_declspecs *specs)
   13373              : {
   13374              :   /* If a type was specified as a whole, we have no modifiers and are
   13375              :      done.  */
   13376    315394099 :   if (specs->type != NULL_TREE)
   13377              :     {
   13378    249198982 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13379              :                   && !specs->signed_p && !specs->unsigned_p
   13380              :                   && !specs->complex_p && !specs->c23_auto_p);
   13381              : 
   13382              :       /* Set a dummy type.  */
   13383    249198982 :       if (TREE_CODE (specs->type) == ERROR_MARK)
   13384          184 :         specs->type = integer_type_node;
   13385    249198982 :       goto handle_postfix_attrs;
   13386              :     }
   13387              : 
   13388              :   /* If none of "void", "_Bool", "char", "int", "float" or "double"
   13389              :      has been specified, treat it as "int" unless "_Complex" is
   13390              :      present and there are no other specifiers.  If we just have
   13391              :      "_Complex", it is equivalent to "_Complex double", but e.g.
   13392              :      "_Complex short" is equivalent to "_Complex short int".  */
   13393     66195117 :   if (specs->typespec_word == cts_none)
   13394              :     {
   13395      4190596 :       if (specs->saturating_p)
   13396              :         {
   13397            1 :           error_at (specs->locations[cdw_saturating],
   13398              :                     "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
   13399            1 :           if (!targetm.fixed_point_supported_p ())
   13400            1 :             error_at (specs->locations[cdw_saturating],
   13401              :                       "fixed-point types not supported for this target");
   13402            1 :           specs->typespec_word = cts_fract;
   13403              :         }
   13404      4190595 :       else if (specs->long_p || specs->short_p
   13405       193421 :                || specs->signed_p || specs->unsigned_p)
   13406              :         {
   13407      4180150 :           specs->typespec_word = cts_int;
   13408              :         }
   13409        10445 :       else if (specs->complex_p)
   13410              :         {
   13411          131 :           specs->typespec_word = cts_double;
   13412          131 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13413              :                    "ISO C does not support plain %<complex%> meaning "
   13414              :                    "%<double complex%>");
   13415              :         }
   13416        10314 :       else if (specs->c23_auto_p)
   13417              :         {
   13418              :           /* Type to be filled in later, including applying postfix
   13419              :              attributes.  This warning only actually appears for
   13420              :              -Wc11-c23-compat in C23 mode; in older modes, there may
   13421              :              be a warning or pedwarn for implicit "int" instead, or
   13422              :              other errors for use of auto at file scope.  */
   13423           95 :           pedwarn_c11 (input_location, OPT_Wpedantic,
   13424              :                        "ISO C does not support %<auto%> type deduction "
   13425              :                        "before C23");
   13426           95 :           return specs;
   13427              :         }
   13428              :       else
   13429              :         {
   13430        10219 :           specs->typespec_word = cts_int;
   13431        10219 :           specs->default_int_p = true;
   13432              :           /* We don't diagnose this here because grokdeclarator will
   13433              :              give more specific diagnostics according to whether it is
   13434              :              a function definition.  */
   13435              :         }
   13436              :     }
   13437              : 
   13438              :   /* If "signed" was specified, record this to distinguish "int" and
   13439              :      "signed int" in the case of a bit-field with
   13440              :      -funsigned-bitfields.  */
   13441     66195022 :   specs->explicit_signed_p = specs->signed_p;
   13442              : 
   13443              :   /* Now compute the actual type.  */
   13444     66195022 :   gcc_assert (!specs->c23_auto_p);
   13445     66195022 :   switch (specs->typespec_word)
   13446              :     {
   13447         1885 :     case cts_auto_type:
   13448         1885 :       gcc_assert (!specs->long_p && !specs->short_p
   13449              :                   && !specs->signed_p && !specs->unsigned_p
   13450              :                   && !specs->complex_p);
   13451              :       /* Type to be filled in later.  */
   13452         1885 :       if (specs->postfix_attrs)
   13453            2 :         error ("%<__auto_type%> followed by %<[[]]%> attributes");
   13454              :       break;
   13455      7991133 :     case cts_void:
   13456      7991133 :       gcc_assert (!specs->long_p && !specs->short_p
   13457              :                   && !specs->signed_p && !specs->unsigned_p
   13458              :                   && !specs->complex_p);
   13459      7991133 :       specs->type = void_type_node;
   13460      7991133 :       break;
   13461        90482 :     case cts_bool:
   13462        90482 :       gcc_assert (!specs->long_p && !specs->short_p
   13463              :                   && !specs->signed_p && !specs->unsigned_p
   13464              :                   && !specs->complex_p);
   13465        90482 :       specs->type = boolean_type_node;
   13466        90482 :       break;
   13467      9068566 :     case cts_char:
   13468      9068566 :       gcc_assert (!specs->long_p && !specs->short_p);
   13469      9068566 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13470      9068566 :       if (specs->signed_p)
   13471       173255 :         specs->type = signed_char_type_node;
   13472      8895311 :       else if (specs->unsigned_p)
   13473       883864 :         specs->type = unsigned_char_type_node;
   13474              :       else
   13475      8011447 :         specs->type = char_type_node;
   13476      9068566 :       if (specs->complex_p)
   13477              :         {
   13478         3856 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13479              :                    "ISO C does not support complex integer types");
   13480         3856 :           specs->type = build_complex_type (specs->type);
   13481              :         }
   13482              :       break;
   13483        51872 :     case cts_int_n:
   13484        51872 :       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
   13485        51872 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13486        51872 :       if (! int_n_enabled_p[specs->u.int_n_idx])
   13487            0 :         specs->type = integer_type_node;
   13488              :       else
   13489        51872 :         specs->type = (specs->unsigned_p
   13490        51872 :                        ? int_n_trees[specs->u.int_n_idx].unsigned_type
   13491              :                        : int_n_trees[specs->u.int_n_idx].signed_type);
   13492        51872 :       if (specs->complex_p)
   13493              :         {
   13494          199 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13495              :                    "ISO C does not support complex integer types");
   13496          199 :           specs->type = build_complex_type (specs->type);
   13497              :         }
   13498              :       break;
   13499     28224411 :     case cts_int:
   13500     28224411 :       gcc_assert (!(specs->long_p && specs->short_p));
   13501     28224411 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13502     28224411 :       if (specs->long_long_p)
   13503      2967958 :         specs->type = (specs->unsigned_p
   13504      2967958 :                        ? long_long_unsigned_type_node
   13505              :                        : long_long_integer_type_node);
   13506     25256453 :       else if (specs->long_p)
   13507      2231558 :         specs->type = (specs->unsigned_p
   13508      2231558 :                        ? long_unsigned_type_node
   13509              :                        : long_integer_type_node);
   13510     23024895 :       else if (specs->short_p)
   13511      1704811 :         specs->type = (specs->unsigned_p
   13512      1704811 :                        ? short_unsigned_type_node
   13513              :                        : short_integer_type_node);
   13514              :       else
   13515     21320084 :         specs->type = (specs->unsigned_p
   13516     21320084 :                        ? unsigned_type_node
   13517              :                        : integer_type_node);
   13518     28224411 :       if (specs->complex_p)
   13519              :         {
   13520        14934 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13521              :                    "ISO C does not support complex integer types");
   13522        14934 :           specs->type = build_complex_type (specs->type);
   13523              :         }
   13524              :       break;
   13525      3632727 :     case cts_float:
   13526      3632727 :       gcc_assert (!specs->long_p && !specs->short_p
   13527              :                   && !specs->signed_p && !specs->unsigned_p);
   13528      7265454 :       specs->type = (specs->complex_p
   13529      3632727 :                      ? complex_float_type_node
   13530              :                      : float_type_node);
   13531      3632727 :       break;
   13532      6609245 :     case cts_double:
   13533      6609245 :       gcc_assert (!specs->long_long_p && !specs->short_p
   13534              :                   && !specs->signed_p && !specs->unsigned_p);
   13535      6609245 :       if (specs->long_p)
   13536              :         {
   13537      2883063 :           specs->type = (specs->complex_p
   13538      2883063 :                          ? complex_long_double_type_node
   13539              :                          : long_double_type_node);
   13540              :         }
   13541              :       else
   13542              :         {
   13543      3726182 :           specs->type = (specs->complex_p
   13544      3726182 :                          ? complex_double_type_node
   13545              :                          : double_type_node);
   13546              :         }
   13547              :       break;
   13548     10430255 :     case cts_floatn_nx:
   13549     10430255 :       gcc_assert (!specs->long_p && !specs->short_p
   13550              :                   && !specs->signed_p && !specs->unsigned_p);
   13551     10430255 :       if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   13552           88 :         specs->type = integer_type_node;
   13553     10430167 :       else if (specs->complex_p)
   13554      1555507 :         specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13555              :       else
   13556      8874660 :         specs->type = FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13557              :       break;
   13558        47577 :     case cts_dfloat32:
   13559        47577 :     case cts_dfloat64:
   13560        47577 :     case cts_dfloat128:
   13561        47577 :     case cts_dfloat64x:
   13562        47577 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13563              :                   && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
   13564        47577 :       if (!targetm.decimal_float_supported_p ())
   13565            0 :         specs->type = integer_type_node;
   13566        47577 :       else if (specs->typespec_word == cts_dfloat32)
   13567        15957 :         specs->type = dfloat32_type_node;
   13568        31620 :       else if (specs->typespec_word == cts_dfloat64)
   13569        15839 :         specs->type = dfloat64_type_node;
   13570        15781 :       else if (specs->typespec_word == cts_dfloat128)
   13571        15734 :         specs->type = dfloat128_type_node;
   13572              :       else
   13573           47 :         specs->type = dfloat64x_type_node;
   13574              :       break;
   13575           69 :     case cts_fract:
   13576           69 :       gcc_assert (!specs->complex_p);
   13577           69 :       if (!targetm.fixed_point_supported_p ())
   13578           69 :         specs->type = integer_type_node;
   13579            0 :       else if (specs->saturating_p)
   13580              :         {
   13581            0 :           if (specs->long_long_p)
   13582            0 :             specs->type = specs->unsigned_p
   13583            0 :                           ? sat_unsigned_long_long_fract_type_node
   13584              :                           : sat_long_long_fract_type_node;
   13585            0 :           else if (specs->long_p)
   13586            0 :             specs->type = specs->unsigned_p
   13587            0 :                           ? sat_unsigned_long_fract_type_node
   13588              :                           : sat_long_fract_type_node;
   13589            0 :           else if (specs->short_p)
   13590            0 :             specs->type = specs->unsigned_p
   13591            0 :                           ? sat_unsigned_short_fract_type_node
   13592              :                           : sat_short_fract_type_node;
   13593              :           else
   13594            0 :             specs->type = specs->unsigned_p
   13595            0 :                           ? sat_unsigned_fract_type_node
   13596              :                           : sat_fract_type_node;
   13597              :         }
   13598              :       else
   13599              :         {
   13600            0 :           if (specs->long_long_p)
   13601            0 :             specs->type = specs->unsigned_p
   13602            0 :                           ? unsigned_long_long_fract_type_node
   13603              :                           : long_long_fract_type_node;
   13604            0 :           else if (specs->long_p)
   13605            0 :             specs->type = specs->unsigned_p
   13606            0 :                           ? unsigned_long_fract_type_node
   13607              :                           : long_fract_type_node;
   13608            0 :           else if (specs->short_p)
   13609            0 :             specs->type = specs->unsigned_p
   13610            0 :                           ? unsigned_short_fract_type_node
   13611              :                           : short_fract_type_node;
   13612              :           else
   13613            0 :             specs->type = specs->unsigned_p
   13614            0 :                           ? unsigned_fract_type_node
   13615              :                           : fract_type_node;
   13616              :         }
   13617              :       break;
   13618           67 :     case cts_accum:
   13619           67 :       gcc_assert (!specs->complex_p);
   13620           67 :       if (!targetm.fixed_point_supported_p ())
   13621           67 :         specs->type = integer_type_node;
   13622            0 :       else if (specs->saturating_p)
   13623              :         {
   13624            0 :           if (specs->long_long_p)
   13625            0 :             specs->type = specs->unsigned_p
   13626            0 :                           ? sat_unsigned_long_long_accum_type_node
   13627              :                           : sat_long_long_accum_type_node;
   13628            0 :           else if (specs->long_p)
   13629            0 :             specs->type = specs->unsigned_p
   13630            0 :                           ? sat_unsigned_long_accum_type_node
   13631              :                           : sat_long_accum_type_node;
   13632            0 :           else if (specs->short_p)
   13633            0 :             specs->type = specs->unsigned_p
   13634            0 :                           ? sat_unsigned_short_accum_type_node
   13635              :                           : sat_short_accum_type_node;
   13636              :           else
   13637            0 :             specs->type = specs->unsigned_p
   13638            0 :                           ? sat_unsigned_accum_type_node
   13639              :                           : sat_accum_type_node;
   13640              :         }
   13641              :       else
   13642              :         {
   13643            0 :           if (specs->long_long_p)
   13644            0 :             specs->type = specs->unsigned_p
   13645            0 :                           ? unsigned_long_long_accum_type_node
   13646              :                           : long_long_accum_type_node;
   13647            0 :           else if (specs->long_p)
   13648            0 :             specs->type = specs->unsigned_p
   13649            0 :                           ? unsigned_long_accum_type_node
   13650              :                           : long_accum_type_node;
   13651            0 :           else if (specs->short_p)
   13652            0 :             specs->type = specs->unsigned_p
   13653            0 :                           ? unsigned_short_accum_type_node
   13654              :                           : short_accum_type_node;
   13655              :           else
   13656            0 :             specs->type = specs->unsigned_p
   13657            0 :                           ? unsigned_accum_type_node
   13658              :                           : accum_type_node;
   13659              :         }
   13660              :       break;
   13661        46733 :     case cts_bitint:
   13662        46733 :       gcc_assert (!specs->long_p && !specs->short_p
   13663              :                   && !specs->complex_p);
   13664        46733 :       if (!specs->unsigned_p && specs->u.bitint_prec == 1 && !flag_isoc2y)
   13665              :         {
   13666            2 :           error_at (specs->locations[cdw_typespec],
   13667              :                     "%<signed _BitInt%> argument must be at least 2 "
   13668              :                     "before C2Y");
   13669            2 :           specs->type = integer_type_node;
   13670            2 :           break;
   13671              :         }
   13672        46731 :       if (specs->u.bitint_prec == -1)
   13673            7 :         specs->type = integer_type_node;
   13674              :       else
   13675              :         {
   13676        69126 :           pedwarn_c11 (specs->locations[cdw_typespec], OPT_Wpedantic,
   13677              :                        "ISO C does not support %<%s_BitInt(%d)%> before C23",
   13678              :                        specs->unsigned_p ? "unsigned "
   13679        22402 :                        : specs->signed_p ? "signed " : "",
   13680              :                        specs->u.bitint_prec);
   13681        46724 :           specs->type = build_bitint_type (specs->u.bitint_prec,
   13682        46724 :                                            specs->unsigned_p);
   13683              :         }
   13684              :       break;
   13685            0 :     default:
   13686            0 :       gcc_unreachable ();
   13687              :     }
   13688    315394004 :  handle_postfix_attrs:
   13689    315394004 :   if (specs->type != NULL)
   13690              :     {
   13691    315392119 :       specs->postfix_attrs
   13692    315392119 :         = c_warn_type_attributes (specs->type, specs->postfix_attrs);
   13693    315392119 :       decl_attributes (&specs->type, specs->postfix_attrs, 0);
   13694    315392119 :       specs->postfix_attrs = NULL_TREE;
   13695              :     }
   13696              : 
   13697              :   return specs;
   13698              : }
   13699              : 
   13700              : /* Perform final processing on one file scope's declarations (or the
   13701              :    external scope's declarations), GLOBALS.  */
   13702              : 
   13703              : static void
   13704       220498 : c_write_global_declarations_1 (tree globals)
   13705              : {
   13706       220498 :   tree decl;
   13707       220498 :   bool reconsider;
   13708              : 
   13709              :   /* Process the decls in the order they were written.  */
   13710    400850410 :   for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13711              :     {
   13712              :       /* Check for used but undefined static functions using the C
   13713              :          standard's definition of "used", and set TREE_NO_WARNING so
   13714              :          that check_global_declaration doesn't repeat the check.  */
   13715    400629912 :       if (TREE_CODE (decl) == FUNCTION_DECL
   13716    382165956 :           && DECL_INITIAL (decl) == NULL_TREE
   13717    345835597 :           && DECL_EXTERNAL (decl)
   13718    345835592 :           && !TREE_PUBLIC (decl)
   13719    400630043 :           && !warning_suppressed_p (decl, OPT_Wunused))
   13720              :         {
   13721          126 :           if (C_DECL_USED (decl))
   13722              :             {
   13723           31 :               if (pedwarn (input_location, 0, "%q+F used but never defined",
   13724              :                            decl))
   13725           30 :                 suppress_warning (decl, OPT_Wunused);
   13726              :             }
   13727              :           /* For -Wunused-function warn about unused static prototypes.  */
   13728           95 :           else if (warn_unused_function
   13729            2 :                    && ! DECL_ARTIFICIAL (decl)
   13730           97 :                    && warning (OPT_Wunused_function,
   13731              :                                "%q+F declared %<static%> but never defined",
   13732              :                                decl))
   13733            2 :             suppress_warning (decl, OPT_Wunused);
   13734              :         }
   13735              : 
   13736    400629912 :       wrapup_global_declaration_1 (decl);
   13737              :     }
   13738              : 
   13739       255504 :   do
   13740              :     {
   13741       255504 :       reconsider = false;
   13742    517458431 :       for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13743    517202927 :         reconsider |= wrapup_global_declaration_2 (decl);
   13744              :     }
   13745              :   while (reconsider);
   13746       220498 : }
   13747              : 
   13748              : /* Preserve the external declarations scope across a garbage collect.  */
   13749              : static GTY(()) tree ext_block;
   13750              : 
   13751              : /* Collect all references relevant to SOURCE_FILE.  */
   13752              : 
   13753              : static void
   13754           15 : collect_all_refs (const char *source_file)
   13755              : {
   13756           15 :   tree t;
   13757           15 :   unsigned i;
   13758              : 
   13759           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13760           15 :     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
   13761              : 
   13762           15 :   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
   13763           15 : }
   13764              : 
   13765              : /* Collect source file references at global level.  */
   13766              : 
   13767              : static void
   13768           15 : collect_source_refs (void)
   13769              : {
   13770           15 :   tree t;
   13771           15 :   tree decls;
   13772           15 :   tree decl;
   13773           15 :   unsigned i;
   13774              : 
   13775           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13776              :     {
   13777           15 :       decls = DECL_INITIAL (t);
   13778           82 :       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
   13779           67 :         if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13780           67 :           collect_source_ref (DECL_SOURCE_FILE (decl));
   13781              :     }
   13782              : 
   13783        44261 :   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
   13784        44246 :     if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13785           11 :       collect_source_ref (DECL_SOURCE_FILE (decl));
   13786           15 : }
   13787              : 
   13788              : /* Free attribute access data that are not needed by the middle end. */
   13789              : 
   13790              : static void
   13791       110249 : free_attr_access_data ()
   13792              : {
   13793       110249 :   struct cgraph_node *n;
   13794              : 
   13795              :   /* Iterate over all functions declared in the translation unit.  */
   13796     36442251 :   FOR_EACH_FUNCTION (n)
   13797              :     {
   13798    136420430 :       for (tree parm = DECL_ARGUMENTS (n->decl); parm; parm = TREE_CHAIN (parm))
   13799    100088428 :         if (tree attrs = DECL_ATTRIBUTES (parm))
   13800        98018 :           attr_access::free_lang_data (attrs);
   13801              : 
   13802     36332002 :       tree fntype = TREE_TYPE (n->decl);
   13803     36332002 :       if (!fntype || fntype == error_mark_node)
   13804            0 :         continue;
   13805     36332002 :       tree attrs = TYPE_ATTRIBUTES (fntype);
   13806     36332002 :       if (!attrs)
   13807     36096004 :         continue;
   13808              : 
   13809       235998 :       attr_access::free_lang_data (attrs);
   13810              :     }
   13811       110249 : }
   13812              : 
   13813              : /* Perform any final parser cleanups and generate initial debugging
   13814              :    information.  */
   13815              : 
   13816              : void
   13817       110626 : c_parse_final_cleanups (void)
   13818              : {
   13819       110626 :   tree t;
   13820       110626 :   unsigned i;
   13821              : 
   13822              :   /* We don't want to do this if generating a PCH.  */
   13823       110626 :   if (pch_file)
   13824       110626 :     return;
   13825              : 
   13826       110249 :   timevar_stop (TV_PHASE_PARSING);
   13827       110249 :   timevar_start (TV_PHASE_DEFERRED);
   13828              : 
   13829              :   /* Do the Objective-C stuff.  This is where all the Objective-C
   13830              :      module stuff gets generated (symtab, class/protocol/selector
   13831              :      lists etc).  */
   13832       110249 :   if (c_dialect_objc ())
   13833            0 :     objc_write_global_declarations ();
   13834              : 
   13835              :   /* Close the external scope.  */
   13836       110249 :   ext_block = pop_scope ();
   13837       110249 :   external_scope = 0;
   13838       110249 :   gcc_assert (!current_scope);
   13839              : 
   13840              :   /* Handle -fdump-ada-spec[-slim]. */
   13841       110249 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
   13842              :     {
   13843              :       /* Build a table of files to generate specs for */
   13844           15 :       collect_source_ref (main_input_filename);
   13845           15 :       if (!flag_dump_ada_spec_slim)
   13846           15 :         collect_source_refs ();
   13847              : 
   13848           15 :       dump_ada_specs (collect_all_refs, NULL);
   13849              :     }
   13850              : 
   13851              :   /* Process all file scopes in this compilation, and the external_scope,
   13852              :      through wrapup_global_declarations.  */
   13853       220498 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13854       110249 :     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
   13855       110249 :   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
   13856              : 
   13857              :   /* Call this to set cpp_implicit_aliases_done on all nodes.  This is
   13858              :      important for function multiversioning aliases to get resolved.  */
   13859       110249 :   symtab->process_same_body_aliases ();
   13860              : 
   13861       110249 :   if (!in_lto_p)
   13862       110249 :     free_attr_access_data ();
   13863              : 
   13864       110249 :   timevar_stop (TV_PHASE_DEFERRED);
   13865       110249 :   timevar_start (TV_PHASE_PARSING);
   13866              : 
   13867       110249 :   ext_block = NULL;
   13868              : }
   13869              : 
   13870              : /* Register reserved keyword WORD as qualifier for address space AS.  */
   13871              : 
   13872              : void
   13873       233256 : c_register_addr_space (const char *word, addr_space_t as)
   13874              : {
   13875       233256 :   int rid = RID_FIRST_ADDR_SPACE + as;
   13876       233256 :   tree id;
   13877              : 
   13878              :   /* Address space qualifiers are only supported
   13879              :      in C with GNU extensions enabled.  */
   13880       233256 :   if (c_dialect_objc () || flag_no_asm)
   13881              :     return;
   13882              : 
   13883       220744 :   id = get_identifier (word);
   13884       220744 :   C_SET_RID_CODE (id, rid);
   13885       220744 :   C_IS_RESERVED_WORD (id) = 1;
   13886       220744 :   ridpointers [rid] = id;
   13887              : }
   13888              : 
   13889              : /* Return identifier to look up for omp declare reduction.  */
   13890              : 
   13891              : tree
   13892         3254 : c_omp_reduction_id (enum tree_code reduction_code, tree reduction_id)
   13893              : {
   13894         3254 :   const char *p = NULL;
   13895         3254 :   switch (reduction_code)
   13896              :     {
   13897              :     case PLUS_EXPR: p = "+"; break;
   13898          267 :     case MULT_EXPR: p = "*"; break;
   13899          157 :     case MINUS_EXPR: p = "-"; break;
   13900           31 :     case BIT_AND_EXPR: p = "&"; break;
   13901           14 :     case BIT_XOR_EXPR: p = "^"; break;
   13902           92 :     case BIT_IOR_EXPR: p = "|"; break;
   13903           67 :     case TRUTH_ANDIF_EXPR: p = "&&"; break;
   13904           78 :     case TRUTH_ORIF_EXPR: p = "||"; break;
   13905           46 :     case MIN_EXPR: p = "min"; break;
   13906           83 :     case MAX_EXPR: p = "max"; break;
   13907              :     default:
   13908              :       break;
   13909              :     }
   13910              : 
   13911          835 :   if (p == NULL)
   13912              :     {
   13913          213 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
   13914            0 :         return error_mark_node;
   13915          213 :       p = IDENTIFIER_POINTER (reduction_id);
   13916              :     }
   13917              : 
   13918         3254 :   const char prefix[] = "omp declare reduction ";
   13919         3254 :   size_t lenp = sizeof (prefix);
   13920         3254 :   size_t len = strlen (p);
   13921         3254 :   char *name = XALLOCAVEC (char, lenp + len);
   13922         3254 :   memcpy (name, prefix, lenp - 1);
   13923         3254 :   memcpy (name + lenp - 1, p, len + 1);
   13924         3254 :   return get_identifier (name);
   13925              : }
   13926              : 
   13927              : /* Lookup REDUCTION_ID in the current scope, or create an artificial
   13928              :    VAR_DECL, bind it into the current scope and return it.  */
   13929              : 
   13930              : tree
   13931          161 : c_omp_reduction_decl (tree reduction_id)
   13932              : {
   13933          161 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13934          161 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   13935           47 :     return b->decl;
   13936              : 
   13937          114 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   13938              :                           reduction_id, integer_type_node);
   13939          114 :   DECL_ARTIFICIAL (decl) = 1;
   13940          114 :   DECL_EXTERNAL (decl) = 1;
   13941          114 :   TREE_STATIC (decl) = 1;
   13942          114 :   TREE_PUBLIC (decl) = 0;
   13943          114 :   bind (reduction_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   13944          114 :   return decl;
   13945              : }
   13946              : 
   13947              : /* Lookup REDUCTION_ID in the first scope where it has entry for TYPE.  */
   13948              : 
   13949              : tree
   13950          273 : c_omp_reduction_lookup (tree reduction_id, tree type)
   13951              : {
   13952          273 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13953          276 :   while (b)
   13954              :     {
   13955          274 :       tree t;
   13956          294 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   13957          291 :         if (comptypes (TREE_PURPOSE (t), type))
   13958          271 :           return TREE_VALUE (t);
   13959            3 :       b = b->shadowed;
   13960              :     }
   13961            2 :   return error_mark_node;
   13962              : }
   13963              : 
   13964              : /* Helper function called via walk_tree, to diagnose invalid
   13965              :    #pragma omp declare reduction combiners or initializers.  */
   13966              : 
   13967              : tree
   13968         1401 : c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
   13969              : {
   13970         1401 :   tree *vars = (tree *) data;
   13971         1401 :   if (SSA_VAR_P (*tp)
   13972          413 :       && !DECL_ARTIFICIAL (*tp)
   13973           24 :       && *tp != vars[0]
   13974           24 :       && *tp != vars[1])
   13975              :     {
   13976           24 :       location_t loc = DECL_SOURCE_LOCATION (vars[0]);
   13977           24 :       if (strcmp (IDENTIFIER_POINTER (DECL_NAME (vars[0])), "omp_out") == 0)
   13978           10 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
   13979              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
   13980              :                   *tp);
   13981              :       else
   13982           14 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
   13983              :                        "to variable %qD which is not %<omp_priv%> nor "
   13984              :                        "%<omp_orig%>",
   13985              :                   *tp);
   13986           24 :       return *tp;
   13987              :     }
   13988              :   return NULL_TREE;
   13989              : }
   13990              : 
   13991              : /* Return identifier to look up for omp declare mapper.  */
   13992              : 
   13993              : tree
   13994          695 : c_omp_mapper_id (tree mapper_id)
   13995              : {
   13996          695 :   const char *p = NULL;
   13997              : 
   13998          695 :   const char prefix[] = "omp declare mapper ";
   13999              : 
   14000          695 :   if (mapper_id == NULL_TREE)
   14001              :     p = "<default>";
   14002           24 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
   14003           24 :     p = IDENTIFIER_POINTER (mapper_id);
   14004              :   else
   14005            0 :     return error_mark_node;
   14006              : 
   14007          695 :   size_t lenp = sizeof (prefix);
   14008          695 :   size_t len = strlen (p);
   14009          695 :   char *name = XALLOCAVEC (char, lenp + len);
   14010          695 :   memcpy (name, prefix, lenp - 1);
   14011          695 :   memcpy (name + lenp - 1, p, len + 1);
   14012          695 :   return get_identifier (name);
   14013              : }
   14014              : 
   14015              : /* Lookup MAPPER_ID in the current scope, or create an artificial
   14016              :    VAR_DECL, bind it into the current scope and return it.  */
   14017              : 
   14018              : tree
   14019           73 : c_omp_mapper_decl (tree mapper_id)
   14020              : {
   14021           73 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14022           73 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   14023           22 :     return b->decl;
   14024              : 
   14025           51 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   14026              :                           mapper_id, integer_type_node);
   14027           51 :   DECL_ARTIFICIAL (decl) = 1;
   14028           51 :   DECL_EXTERNAL (decl) = 1;
   14029           51 :   TREE_STATIC (decl) = 1;
   14030           51 :   TREE_PUBLIC (decl) = 0;
   14031           51 :   bind (mapper_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   14032           51 :   return decl;
   14033              : }
   14034              : 
   14035              : /* Lookup MAPPER_ID in the first scope where it has entry for TYPE.  */
   14036              : 
   14037              : tree
   14038         5425 : c_omp_mapper_lookup (tree mapper_id, tree type)
   14039              : {
   14040         5425 :   if (!RECORD_OR_UNION_TYPE_P (type))
   14041              :     return NULL_TREE;
   14042              : 
   14043          622 :   mapper_id = c_omp_mapper_id (mapper_id);
   14044              : 
   14045          622 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14046          628 :   while (b)
   14047              :     {
   14048          127 :       tree t;
   14049          146 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   14050          140 :         if (comptypes (TREE_PURPOSE (t), type))
   14051          121 :           return TREE_VALUE (t);
   14052            6 :       b = b->shadowed;
   14053              :     }
   14054              :   return NULL_TREE;
   14055              : }
   14056              : 
   14057              : /* For C, we record a pointer to the mapper itself without wrapping it in an
   14058              :    artificial function or similar.  So, just return it.  */
   14059              : 
   14060              : tree
   14061          113 : c_omp_extract_mapper_directive (tree mapper)
   14062              : {
   14063          113 :   return mapper;
   14064              : }
   14065              : 
   14066              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
   14067              :    nothing more complicated.  */
   14068              : 
   14069              : tree
   14070          569 : c_omp_map_array_section (location_t loc, tree t)
   14071              : {
   14072          569 :   tree low = TREE_OPERAND (t, 1);
   14073          569 :   tree len = TREE_OPERAND (t, 2);
   14074              : 
   14075          569 :   if (len && integer_onep (len))
   14076              :     {
   14077           92 :       t = TREE_OPERAND (t, 0);
   14078              : 
   14079           92 :       if (!low)
   14080           14 :         low = integer_zero_node;
   14081              : 
   14082           92 :       t = build_array_ref (loc, t, low);
   14083              :     }
   14084              : 
   14085          569 :   return t;
   14086              : }
   14087              : 
   14088              : /* Helper function for below function.  */
   14089              : 
   14090              : static tree
   14091        51829 : c_omp_scan_mapper_bindings_r (tree *tp, int *walk_subtrees, void *ptr)
   14092              : {
   14093        51829 :   tree t = *tp;
   14094        51829 :   omp_mapper_list<tree> *mlist = (omp_mapper_list<tree> *) ptr;
   14095        51829 :   tree aggr_type = NULL_TREE;
   14096              : 
   14097        51829 :   if (TREE_CODE (t) == SIZEOF_EXPR
   14098        51829 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   14099              :     {
   14100            0 :       *walk_subtrees = 0;
   14101            0 :       return NULL_TREE;
   14102              :     }
   14103              : 
   14104        51829 :   if (TREE_CODE (t) == OMP_CLAUSE)
   14105              :     return NULL_TREE;
   14106              : 
   14107        48540 :   if (TREE_CODE (t) == COMPONENT_REF
   14108        48540 :       && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   14109          370 :     aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   14110        48170 :   else if ((TREE_CODE (t) == VAR_DECL
   14111              :             || TREE_CODE (t) == PARM_DECL
   14112              :             || TREE_CODE (t) == RESULT_DECL)
   14113         5406 :            && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   14114          121 :     aggr_type = TREE_TYPE (t);
   14115              : 
   14116          491 :   if (aggr_type)
   14117              :     {
   14118          491 :       tree mapper_fn = c_omp_mapper_lookup (NULL_TREE, aggr_type);
   14119          491 :       if (mapper_fn)
   14120           76 :         mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   14121              :     }
   14122              : 
   14123              :   return NULL_TREE;
   14124              : }
   14125              : 
   14126              : /* Scan an offload region's body, and record uses of struct- or union-typed
   14127              :    variables.  Add _mapper_binding_ fake clauses to *CLAUSES_PTR.  */
   14128              : 
   14129              : void
   14130         2093 : c_omp_scan_mapper_bindings (location_t loc, tree *clauses_ptr, tree body)
   14131              : {
   14132         2093 :   hash_set<omp_name_type<tree>> seen_types;
   14133         2093 :   auto_vec<tree> mappers;
   14134         2093 :   omp_mapper_list<tree> mlist (&seen_types, &mappers);
   14135              : 
   14136         2093 :   walk_tree_without_duplicates (&body, c_omp_scan_mapper_bindings_r, &mlist);
   14137              : 
   14138         2093 :   unsigned int i;
   14139         2093 :   tree mapper;
   14140         4228 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14141           42 :     c_omp_find_nested_mappers (&mlist, mapper);
   14142              : 
   14143         2164 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14144              :     {
   14145           42 :       if (mapper == error_mark_node)
   14146            0 :         continue;
   14147           42 :       tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   14148           42 :       tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   14149              : 
   14150           42 :       tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   14151           42 :       OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   14152           42 :       OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   14153           42 :       OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper;
   14154              : 
   14155           42 :       OMP_CLAUSE_CHAIN (c) = *clauses_ptr;
   14156           42 :       *clauses_ptr = c;
   14157              :     }
   14158         2093 : }
   14159              : 
   14160              : bool
   14161          247 : c_check_in_current_scope (tree decl)
   14162              : {
   14163          247 :   struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (decl));
   14164          247 :   return b != NULL && B_IN_CURRENT_SCOPE (b);
   14165              : }
   14166              : 
   14167              : /* Search for loop or switch names.  BEFORE_LABELS is last statement before
   14168              :    possible labels and SWITCH_P true for a switch, false for loops.
   14169              :    Searches through last statements in cur_stmt_list, stops when seeing
   14170              :    BEFORE_LABELs, or statement other than LABEL_EXPR or CASE_LABEL_EXPR.
   14171              :    Returns number of loop/switch names found and if any are found, sets
   14172              :    *LAST_P to the canonical loop/switch name LABEL_DECL.  */
   14173              : 
   14174              : int
   14175       515521 : c_get_loop_names (tree before_labels, bool switch_p, tree *last_p)
   14176              : {
   14177       515521 :   *last_p = NULL_TREE;
   14178      1031042 :   if (!building_stmt_list_p ()
   14179       515521 :       || !STATEMENT_LIST_HAS_LABEL (cur_stmt_list)
   14180       536220 :       || before_labels == void_list_node)
   14181       494822 :     return 0;
   14182              : 
   14183        20699 :   int ret = 0;
   14184        20699 :   tree last = NULL_TREE;
   14185        20699 :   for (tree_stmt_iterator tsi = tsi_last (cur_stmt_list);
   14186        28931 :        !tsi_end_p (tsi); tsi_prev (&tsi))
   14187              :     {
   14188        28074 :       tree stmt = tsi_stmt (tsi);
   14189        28074 :       if (stmt == before_labels)
   14190              :         break;
   14191         8232 :       else if (TREE_CODE (stmt) == LABEL_EXPR)
   14192              :         {
   14193         1106 :           if (last == NULL_TREE)
   14194          912 :             last = LABEL_EXPR_LABEL (stmt);
   14195              :           else
   14196              :             {
   14197          194 :               loop_names.safe_push (LABEL_EXPR_LABEL (stmt));
   14198          194 :               ++ret;
   14199              :             }
   14200              :         }
   14201         7126 :       else if (TREE_CODE (stmt) != CASE_LABEL_EXPR
   14202         4802 :                && TREE_CODE (stmt) != DEBUG_BEGIN_STMT)
   14203              :         break;
   14204              :     }
   14205        20699 :   if (last)
   14206              :     {
   14207          912 :       if (switch_p)
   14208          137 :         C_DECL_SWITCH_NAME (last) = 1;
   14209              :       else
   14210          775 :         C_DECL_LOOP_NAME (last) = 1;
   14211          912 :       loop_names.safe_push (last);
   14212          912 :       ++ret;
   14213          912 :       if (loop_names.length () > 16)
   14214              :         {
   14215           20 :           unsigned int first = 0, i;
   14216           20 :           tree l, c = NULL_TREE;
   14217           20 :           if (loop_names_hash == NULL)
   14218            8 :             loop_names_hash = new decl_tree_map (ret);
   14219              :           else
   14220           12 :             first = loop_names.length () - ret;
   14221          210 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14222              :             {
   14223          170 :               if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14224           48 :                 c = l;
   14225          170 :               gcc_checking_assert (c);
   14226          170 :               loop_names_hash->put (l, c);
   14227          170 :               if (i == first)
   14228              :                 break;
   14229              :             }
   14230              :         }
   14231          912 :       *last_p = last;
   14232              :     }
   14233              :   return ret;
   14234              : }
   14235              : 
   14236              : /* Undoes what get_loop_names did when it returned NUM_NAMES.  */
   14237              : 
   14238              : void
   14239          912 : c_release_loop_names (int num_names)
   14240              : {
   14241          912 :   unsigned len = loop_names.length () - num_names;
   14242          912 :   if (loop_names_hash)
   14243              :     {
   14244           20 :       if (len <= 16)
   14245              :         {
   14246            8 :           delete loop_names_hash;
   14247            8 :           loop_names_hash = NULL;
   14248              :         }
   14249              :       else
   14250              :         {
   14251           12 :           unsigned int i;
   14252           12 :           tree l;
   14253           42 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14254              :             {
   14255           30 :               loop_names_hash->remove (l);
   14256           30 :               if (i == len)
   14257              :                 break;
   14258              :             }
   14259              :         }
   14260              :     }
   14261          912 :   loop_names.truncate (len);
   14262          912 : }
   14263              : 
   14264              : /* Finish processing of break or continue identifier operand.
   14265              :    NAME is the identifier operand of break or continue and
   14266              :    IS_BREAK is true iff it is break stmt.  Returns the operand
   14267              :    to use for BREAK_STMT or CONTINUE_STMT, either NULL_TREE or
   14268              :    canonical loop/switch name LABEL_DECL.  */
   14269              : 
   14270              : tree
   14271          316 : c_finish_bc_name (location_t loc, tree name, bool is_break)
   14272              : {
   14273          316 :   tree label = NULL_TREE, lab;
   14274          457 :   pedwarn_c23 (loc, OPT_Wpedantic,
   14275              :                "ISO C does not support %qs statement with an identifier "
   14276              :                "operand before C2Y", is_break ? "break" : "continue");
   14277              : 
   14278              :   /* If I_LABEL_DECL is NULL or not from current function, don't waste time
   14279              :      trying to find it among loop_names, it can't be there.  */
   14280          316 :   if (!loop_names.is_empty ()
   14281          296 :       && current_function_scope
   14282          296 :       && (lab = I_LABEL_DECL (name))
   14283          290 :       && DECL_CONTEXT (lab) == current_function_decl)
   14284              :     {
   14285          280 :       unsigned int i;
   14286          280 :       tree l, c = NULL_TREE;
   14287          280 :       if (loop_names_hash)
   14288              :         {
   14289           86 :           if (tree *val = loop_names_hash->get (lab))
   14290           86 :             label = *val;
   14291              :         }
   14292              :       else
   14293          565 :         FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14294              :           {
   14295          363 :             if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14296              :               c = l;
   14297          363 :             gcc_checking_assert (c);
   14298          363 :             if (l == lab)
   14299              :               {
   14300              :                 label = c;
   14301              :                 break;
   14302              :               }
   14303              :           }
   14304          280 :       if (label)
   14305          272 :         TREE_USED (lab) = 1;
   14306              :     }
   14307          272 :   if (label == NULL_TREE)
   14308              :     {
   14309           44 :       auto_vec<const char *> candidates;
   14310           44 :       unsigned int i;
   14311           44 :       tree l, c = NULL_TREE;
   14312          115 :       FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14313              :         {
   14314           28 :           if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14315              :             c = l;
   14316           28 :           gcc_checking_assert (c);
   14317           42 :           if (is_break || C_DECL_LOOP_NAME (c))
   14318           25 :             candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l)));
   14319              :         }
   14320           44 :       const char *hint = find_closest_string (IDENTIFIER_POINTER (name),
   14321              :                                               &candidates);
   14322           44 :       if (hint)
   14323              :         {
   14324           22 :           gcc_rich_location richloc (loc);
   14325           22 :           richloc.add_fixit_replace (hint);
   14326           22 :           if (is_break)
   14327           11 :             error_at (&richloc, "%<break%> statement operand %qE does not "
   14328              :                                 "refer to a named loop or %<switch%>; "
   14329              :                                 "did you mean %qs?", name, hint);
   14330              :           else
   14331           11 :             error_at (&richloc, "%<continue%> statement operand %qE does not "
   14332              :                                 "refer to a named loop; did you mean %qs?",
   14333              :                       name, hint);
   14334           22 :         }
   14335           22 :       else if (is_break)
   14336           12 :         error_at (loc, "%<break%> statement operand %qE does not refer to a "
   14337              :                        "named loop or %<switch%>", name);
   14338              :       else
   14339           10 :         error_at (loc, "%<continue%> statement operand %qE does not refer to "
   14340              :                        "a named loop", name);
   14341           44 :     }
   14342          272 :   else if (!C_DECL_LOOP_NAME (label) && !is_break)
   14343              :     {
   14344            2 :       auto_diagnostic_group d;
   14345            2 :       error_at (loc, "%<continue%> statement operand %qE refers to a named "
   14346              :                      "%<switch%>", name);
   14347            2 :       inform (DECL_SOURCE_LOCATION (label), "%<switch%> name defined here");
   14348            2 :       label = NULL_TREE;
   14349            2 :     }
   14350          270 :   else if (!C_DECL_LOOP_SWITCH_NAME_VALID (label))
   14351              :     {
   14352           18 :       auto_diagnostic_group d;
   14353           18 :       if (C_DECL_LOOP_NAME (label))
   14354              :         {
   14355           16 :           error_at (loc, "%qs statement operand %qE refers to a loop outside "
   14356              :                          "of its body", is_break ? "break" : "continue", name);
   14357           16 :           inform (DECL_SOURCE_LOCATION (label), "loop name defined here");
   14358              :         }
   14359              :       else
   14360              :         {
   14361            2 :           error_at (loc, "%<break%> statement operand %qE refers to a "
   14362              :                          "%<switch%> outside of its body", name);
   14363            2 :           inform (DECL_SOURCE_LOCATION (label),
   14364              :                   "%<switch%> name defined here");
   14365              :         }
   14366           18 :       label = NULL_TREE;
   14367           18 :     }
   14368          252 :   else if (label == loop_names.last () && (in_statement & IN_NAMED_STMT) != 0)
   14369              :     /* If it is just a fancy reference to the innermost construct, handle it
   14370              :        just like break; or continue; though tracking cheaply what is the
   14371              :        innermost loop for continue when nested in switches would require
   14372              :        another global variable and updating it.  */
   14373              :     label = NULL_TREE;
   14374              :   else
   14375           98 :     C_DECL_LOOP_SWITCH_NAME_USED (label) = 1;
   14376          316 :   return label;
   14377              : }
   14378              : 
   14379              : #include "gt-c-c-decl.h"
        

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.