LCOV - code coverage report
Current view: top level - gcc/c - c-decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 6376 5883
Test Date: 2026-11-14 16:39:50 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 invisible : 1;  /* normal lookup should ignore this binding */
     225              :   bool nested : 1;     /* do not set DECL_CONTEXT when popping */
     226              :   bool inner_comp : 1; /* incomplete array completed in inner scope */
     227              :   bool 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   4700580698 : i_symbol_binding (tree node)
     260              : {
     261   4700580698 :   struct lang_identifier *lid
     262   4700580698 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     263              : 
     264   4700580698 :   if (lid->symbol_binding == NULL
     265   1729822700 :       && c_binding_oracle != NULL
     266   4700580698 :       && !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   4700580698 :   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      4616267 : i_tag_binding (tree node)
     289              : {
     290      4616267 :   struct lang_identifier *lid
     291      4616267 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     292              : 
     293      4616267 :   if (lid->tag_binding == NULL
     294      1278127 :       && c_binding_oracle != NULL
     295      4616267 :       && !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      4616267 :   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       367000 : i_label_binding (tree node)
     318              : {
     319       367000 :   struct lang_identifier *lid
     320       367000 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     321              : 
     322       367000 :   if (lid->label_binding == NULL
     323        49570 :       && c_binding_oracle != NULL
     324       367000 :       && !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       367000 :   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 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 had_vla_unspec : 1;
     510              : 
     511              :   /* True if we parsed a list of forward parameter decls in this scope.  */
     512              :   bool 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 function_body : 1;
     519              : 
     520              :   /* True means make a BLOCK for this scope no matter what.  */
     521              :   bool keep : 1;
     522              : 
     523              :   /* True means that an unsuffixed float constant is _Decimal64.  */
     524              :   bool 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 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 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      1193399 : 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      4405900 : c_struct_hasher::hash (tree type)
     660              : {
     661      4405900 :   inchash::hash hstate;
     662              : 
     663      4405900 :   hstate.add_int (TREE_CODE (type));
     664      4405900 :   tree tag = c_type_tag (type);
     665      4405900 :   hstate.add_object (tag);
     666              : 
     667      4405900 :   return hstate.end ();
     668              : }
     669              : 
     670              : /* Compare two RECORD or UNION types.  */
     671              : bool
     672     14776846 : c_struct_hasher::equal (tree t1,  tree t2)
     673              : {
     674     14776846 :   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     96809832 : add_stmt (tree t)
     701              : {
     702     96809832 :   enum tree_code code = TREE_CODE (t);
     703              : 
     704     96809832 :   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
     705              :     {
     706     96079700 :       if (!EXPR_HAS_LOCATION (t))
     707       156540 :         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     96809832 :   if (!building_stmt_list_p ())
     713            1 :     push_stmt_list ();
     714              : 
     715     96809832 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     716      1089539 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     717              : 
     718     96809832 :   append_to_statement_list_force (t, &cur_stmt_list);
     719              : 
     720     96809832 :   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    925433642 : decl_jump_unsafe (tree decl)
     732              : {
     733    925433642 :   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    925431571 :   if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl))
     742              :     return false;
     743              : 
     744    924502333 :   if (flag_openmp
     745     13357641 :       && VAR_P (decl)
     746    924534448 :       && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
     747              :     return true;
     748              : 
     749              :   /* Always warn about crossing variably modified types.  */
     750    914378177 :   if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
     751    936806677 :       && 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    924461793 :   if (warn_jump_misses_init
     757      6204210 :       && VAR_P (decl)
     758        10336 :       && !TREE_STATIC (decl)
     759    924467345 :       && DECL_INITIAL (decl) != NULL_TREE)
     760         3886 :     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          118 : c_mark_decl_jump_unsafe_in_current_scope ()
     797              : {
     798          118 :   current_scope->has_jump_unsafe_decl = 1;
     799          118 : }
     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    925284487 : bind (tree name, tree decl, struct c_scope *scope, bool invisible,
     806              :       bool nested, location_t locus)
     807              : {
     808    925284487 :   struct c_binding *b, **here;
     809              : 
     810    925284487 :   if (binding_freelist)
     811              :     {
     812    237966758 :       b = binding_freelist;
     813    237966758 :       binding_freelist = b->prev;
     814              :     }
     815              :   else
     816    687317729 :     b = ggc_alloc<c_binding> ();
     817              : 
     818    925284487 :   b->shadowed = 0;
     819    925284487 :   b->decl = decl;
     820    925284487 :   b->id = name;
     821    925284487 :   b->depth = scope->depth;
     822    925284487 :   b->invisible = invisible;
     823    925284487 :   b->nested = nested;
     824    925284487 :   b->inner_comp = 0;
     825    925284487 :   b->in_struct = 0;
     826    925284487 :   b->locus = locus;
     827              : 
     828    925284487 :   b->u.type = NULL;
     829              : 
     830    925284487 :   b->prev = scope->bindings;
     831    925284487 :   scope->bindings = b;
     832              : 
     833    925284487 :   if (decl_jump_unsafe (decl))
     834        24236 :     scope->has_jump_unsafe_decl = 1;
     835              : 
     836    925284487 :   if (!name)
     837              :     return;
     838              : 
     839    916475062 :   switch (TREE_CODE (decl))
     840              :     {
     841        24814 :     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
     842       638392 :     case ENUMERAL_TYPE:
     843       638392 :     case UNION_TYPE:
     844       638392 :     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
     845    915811856 :     case VAR_DECL:
     846    915811856 :     case FUNCTION_DECL:
     847    915811856 :     case TYPE_DECL:
     848    915811856 :     case CONST_DECL:
     849    915811856 :     case PARM_DECL:
     850    915811856 :     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    916475106 :   while (*here && (*here)->depth > scope->depth)
     860           44 :     here = &(*here)->shadowed;
     861              : 
     862    916475062 :   b->shadowed = *here;
     863    916475062 :   *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    907097389 : free_binding_and_advance (struct c_binding *b)
     872              : {
     873    907097389 :   struct c_binding *prev = b->prev;
     874              : 
     875    907097389 :   memset (b, 0, sizeof (struct c_binding));
     876    907097389 :   b->prev = binding_freelist;
     877    907097389 :   binding_freelist = b;
     878              : 
     879    907097389 :   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        24814 : bind_label (tree name, tree label, struct c_scope *scope,
     886              :             struct c_label_vars *label_vars)
     887              : {
     888        24814 :   struct c_binding *b;
     889              : 
     890        24814 :   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
     891              :         UNKNOWN_LOCATION);
     892              : 
     893        24814 :   scope->has_label_bindings = true;
     894              : 
     895        24814 :   b = scope->bindings;
     896        24814 :   gcc_assert (b->decl == label);
     897        24814 :   label_vars->shadowed = b->u.label;
     898        24814 :   b->u.label = label_vars;
     899        24814 : }
     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         7499 : c_finish_incomplete_decl (tree decl)
     906              : {
     907         7499 :   if (VAR_P (decl))
     908              :     {
     909         7499 :       tree type = TREE_TYPE (decl);
     910         7499 :       if (type != error_mark_node
     911         7422 :           && TREE_CODE (type) == ARRAY_TYPE
     912         7227 :           && !DECL_EXTERNAL (decl)
     913         7588 :           && 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         7499 : }
     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       108466 : check_inline_statics (void)
     952              : {
     953       108466 :   struct c_inline_static *csi;
     954       108502 :   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       108466 :   c_inline_statics = NULL;
     974       108466 : }
     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       138381 : set_spot_bindings (struct c_spot_bindings *p, bool defining)
     981              : {
     982            0 :   if (defining)
     983              :     {
     984       130657 :       p->scope = current_scope;
     985        17090 :       p->bindings_in_scope = current_scope->bindings;
     986              :     }
     987              :   else
     988              :     {
     989         7724 :       p->scope = NULL;
     990         7724 :       p->bindings_in_scope = NULL;
     991              :     }
     992       138381 :   p->stmt_exprs = 0;
     993       138381 :   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    470638003 : 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       208904 :   p->scope = scope->outer;
    1013       208904 :   p->bindings_in_scope = p->scope->bindings;
    1014              : 
    1015       153514 :   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      2107351 : global_bindings_p (void)
    1052              : {
    1053      2107351 :   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        35461 : 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        35461 :   return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl));
    1065              : }
    1066              : 
    1067              : void
    1068        53023 : keep_next_level (void)
    1069              : {
    1070        53023 :   keep_next_level_flag = true;
    1071        53023 : }
    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       606177 : float_const_decimal64_p (void)
    1093              : {
    1094       606177 :   return current_scope->float_const_decimal64;
    1095              : }
    1096              : 
    1097              : /* Identify this scope as currently being filled with parameters.  */
    1098              : 
    1099              : void
    1100     90261933 : declare_parm_level (void)
    1101              : {
    1102     90261933 :   current_scope->parm_flag = true;
    1103     90261933 : }
    1104              : 
    1105              : void
    1106    133000936 : push_scope (void)
    1107              : {
    1108    133000936 :   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     37669274 :       current_scope->parm_flag         = false;
    1121     37669274 :       current_scope->function_body     = true;
    1122     37669274 :       current_scope->keep              = true;
    1123     37669274 :       current_scope->outer_function    = current_function_scope;
    1124     37669274 :       current_function_scope           = current_scope;
    1125              : 
    1126     37669274 :       keep_next_level_flag = false;
    1127     37669274 :       next_is_function_body = false;
    1128              : 
    1129              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1130     37669274 :       if (current_scope->outer)
    1131     37669274 :         current_scope->float_const_decimal64
    1132     37669274 :           = current_scope->outer->float_const_decimal64;
    1133              :       else
    1134            0 :         current_scope->float_const_decimal64 = false;
    1135              :     }
    1136              :   else
    1137              :     {
    1138     95331662 :       struct c_scope *scope;
    1139     95331662 :       if (scope_freelist)
    1140              :         {
    1141     94451176 :           scope = scope_freelist;
    1142     94451176 :           scope_freelist = scope->outer;
    1143              :         }
    1144              :       else
    1145       880486 :         scope = ggc_cleared_alloc<c_scope> ();
    1146              : 
    1147              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1148     95331662 :       if (current_scope)
    1149     95217230 :         scope->float_const_decimal64 = current_scope->float_const_decimal64;
    1150              :       else
    1151              :         scope->float_const_decimal64 = false;
    1152              : 
    1153     95331662 :       scope->keep          = keep_next_level_flag;
    1154     95331662 :       scope->outer         = current_scope;
    1155     95331662 :       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     95331662 :       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     95331662 :       current_scope        = scope;
    1166     95331662 :       keep_next_level_flag = false;
    1167              :     }
    1168    133000936 : }
    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     95324877 : update_label_decls (struct c_scope *scope)
    1177              : {
    1178     95324877 :   struct c_scope *s;
    1179              : 
    1180     95324877 :   s = scope;
    1181    341276140 :   while (s != NULL)
    1182              :     {
    1183    288482716 :       if (s->has_label_bindings)
    1184              :         {
    1185       237545 :           struct c_binding *b;
    1186              : 
    1187      2226593 :           for (b = s->bindings; b != NULL; b = b->prev)
    1188              :             {
    1189      1989048 :               struct c_label_vars *label_vars;
    1190      1989048 :               struct c_binding *b1;
    1191      1989048 :               bool hjud;
    1192      1989048 :               unsigned int ix;
    1193      1989048 :               struct c_goto_bindings *g;
    1194              : 
    1195      1989048 :               if (TREE_CODE (b->decl) != LABEL_DECL)
    1196      1471982 :                 continue;
    1197       517066 :               label_vars = b->u.label;
    1198              : 
    1199       517066 :               b1 = label_vars->label_bindings.bindings_in_scope;
    1200       517066 :               if (label_vars->label_bindings.scope == NULL)
    1201              :                 hjud = false;
    1202              :               else
    1203       202506 :                 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
    1204       517066 :               if (update_spot_bindings (scope, &label_vars->label_bindings))
    1205              :                 {
    1206              :                   /* This label is defined in this scope.  */
    1207        55390 :                   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    472408171 :               FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1224    470274451 :                 update_spot_bindings (scope, &g->goto_bindings);
    1225              :             }
    1226              :         }
    1227              : 
    1228              :       /* Don't search beyond the current function.  */
    1229    288482716 :       if (s == current_function_scope)
    1230              :         break;
    1231              : 
    1232    245951263 :       s = s->outer;
    1233              :     }
    1234     95324877 : }
    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     95324877 : pop_scope (void)
    1243              : {
    1244     95324877 :   struct c_scope *scope = current_scope;
    1245     95324877 :   tree block, context, p;
    1246     95324877 :   struct c_binding *b;
    1247              : 
    1248     95324877 :   bool functionbody = scope->function_body;
    1249     95324877 :   bool keep = functionbody || scope->keep || scope->bindings;
    1250              : 
    1251     95324877 :   update_label_decls (scope);
    1252              : 
    1253              :   /* If appropriate, create a BLOCK to record the decls for the life
    1254              :      of this function.  */
    1255     95324877 :   block = NULL_TREE;
    1256     95324877 :   if (keep)
    1257              :     {
    1258     38171595 :       block = make_node (BLOCK);
    1259     38171595 :       BLOCK_SUBBLOCKS (block) = scope->blocks;
    1260     38171595 :       TREE_USED (block) = 1;
    1261              : 
    1262              :       /* In each subblock, record that this is its superior.  */
    1263     38457649 :       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
    1264       286054 :         BLOCK_SUPERCONTEXT (p) = block;
    1265              : 
    1266     38171595 :       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     95324877 :   if (scope->function_body)
    1283     37669273 :     context = current_function_decl;
    1284     57655604 :   else if (scope == file_scope)
    1285              :     {
    1286       108135 :       tree file_decl
    1287       108135 :         = build_translation_unit_decl (get_identifier (main_input_filename));
    1288       108135 :       context = file_decl;
    1289       108135 :       debug_hooks->register_main_translation_unit (file_decl);
    1290              :     }
    1291              :   else
    1292              :     context = block;
    1293              : 
    1294              :   /* Clear all bindings in this scope.  */
    1295    875028901 :   for (b = scope->bindings; b; b = free_binding_and_advance (b))
    1296              :     {
    1297    779704024 :       p = b->decl;
    1298    779704024 :       switch (TREE_CODE (p))
    1299              :         {
    1300        24814 :         case LABEL_DECL:
    1301              :           /* Warnings for unused labels, errors for undefined labels.  */
    1302        24814 :           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        24751 :             warn_for_unused_label (p);
    1309              : 
    1310              :           /* Labels go in BLOCK_VARS.  */
    1311        24814 :           DECL_CHAIN (p) = BLOCK_VARS (block);
    1312        24814 :           BLOCK_VARS (block) = p;
    1313        24814 :           gcc_assert (I_LABEL_BINDING (b->id) == b);
    1314        24814 :           I_LABEL_BINDING (b->id) = b->shadowed;
    1315              : 
    1316              :           /* Also pop back to the shadowed label_vars.  */
    1317        24814 :           release_tree_vector (b->u.label->decls_in_scope);
    1318        24814 :           b->u.label = b->u.label->shadowed;
    1319        24814 :           break;
    1320              : 
    1321      1446099 :         case ENUMERAL_TYPE:
    1322      1446099 :         case UNION_TYPE:
    1323      1446099 :         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      1446099 :           if (b->id)
    1328              :             {
    1329       636566 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    1330       636566 :               I_TAG_BINDING (b->id) = b->shadowed;
    1331              :             }
    1332              :           break;
    1333              : 
    1334    646269287 :         case FUNCTION_DECL:
    1335              :           /* Propagate TREE_ADDRESSABLE from nested functions to their
    1336              :              containing functions.  */
    1337    646269287 :           if (!TREE_ASM_WRITTEN (p)
    1338    646269287 :               && DECL_INITIAL (p) != NULL_TREE
    1339     74972136 :               && TREE_ADDRESSABLE (p)
    1340      3733667 :               && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
    1341    646269287 :               && DECL_ABSTRACT_ORIGIN (p) != p)
    1342            0 :             TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
    1343    646269287 :           if (!TREE_PUBLIC (p)
    1344       365868 :               && !DECL_INITIAL (p)
    1345          168 :               && !b->nested
    1346          137 :               && scope != file_scope
    1347    646269295 :               && scope != external_scope)
    1348              :             {
    1349            8 :               error ("nested function %q+D declared but never defined", p);
    1350            8 :               undef_nested_function = true;
    1351              :             }
    1352    646269279 :           else if (DECL_DECLARED_INLINE_P (p)
    1353     73761254 :                    && TREE_PUBLIC (p)
    1354    719866643 :                    && !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    646269287 :           goto common_symbol;
    1368              : 
    1369     11045254 :         case VAR_DECL:
    1370              :           /* Warnings for unused variables.  */
    1371      8486468 :           if ((!TREE_USED (p) || !DECL_READ_P (p))
    1372      2590996 :               && !warning_suppressed_p (p, OPT_Wunused_but_set_variable_)
    1373      2590486 :               && !DECL_IN_SYSTEM_HEADER (p)
    1374      2509757 :               && DECL_NAME (p)
    1375      2509757 :               && !DECL_ARTIFICIAL (p)
    1376      2509367 :               && scope != file_scope
    1377     12671194 :               && scope != external_scope)
    1378              :             {
    1379       744177 :               if (!TREE_USED (p))
    1380              :                 {
    1381       736882 :                   warning (OPT_Wunused_variable, "unused variable %q+D", p);
    1382       736882 :                   suppress_warning (p, OPT_Wunused_variable);
    1383              :                 }
    1384         7295 :               else if (DECL_CONTEXT (p) == current_function_decl)
    1385         7276 :                 warning_at (DECL_SOURCE_LOCATION (p),
    1386         7276 :                             OPT_Wunused_but_set_variable_,
    1387              :                             "variable %qD set but not used", p);
    1388              :             }
    1389              : 
    1390     11045254 :           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    675021552 :         case TYPE_DECL:
    1398    675021552 :         case CONST_DECL:
    1399     11045252 :         common_symbol:
    1400              :           /* All of these go in BLOCK_VARS, but only if this is the
    1401              :              binding in the home scope.  */
    1402    675021552 :           if (!b->nested)
    1403              :             {
    1404    405853650 :               DECL_CHAIN (p) = BLOCK_VARS (block);
    1405    405853650 :               BLOCK_VARS (block) = p;
    1406              :             }
    1407    269167902 :           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        14597 :               tree extp = copy_node (p);
    1412              : 
    1413        14597 :               DECL_EXTERNAL (extp) = 1;
    1414        14597 :               TREE_STATIC (extp) = 0;
    1415        14597 :               TREE_PUBLIC (extp) = 1;
    1416        14597 :               DECL_INITIAL (extp) = NULL_TREE;
    1417        14597 :               DECL_LANG_SPECIFIC (extp) = NULL;
    1418        14597 :               DECL_CONTEXT (extp) = current_function_decl;
    1419        14597 :               if (TREE_CODE (p) == FUNCTION_DECL)
    1420              :                 {
    1421        13058 :                   DECL_RESULT (extp) = NULL_TREE;
    1422        13058 :                   DECL_SAVED_TREE (extp) = NULL_TREE;
    1423        13058 :                   DECL_STRUCT_FUNCTION (extp) = NULL;
    1424              :                 }
    1425        14597 :               if (b->locus != UNKNOWN_LOCATION)
    1426        14597 :                 DECL_SOURCE_LOCATION (extp) = b->locus;
    1427        14597 :               DECL_CHAIN (extp) = BLOCK_VARS (block);
    1428        14597 :               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    675021552 :           if (scope == file_scope)
    1434    280707965 :               DECL_CONTEXT (p) = context;
    1435              : 
    1436    778233111 :           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    778233111 :         case PARM_DECL:
    1443    778233111 :         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    778233111 :           if (b->id)
    1447              :             {
    1448    774985827 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    1449    774985827 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    1450    774985827 :               if (b->shadowed && b->shadowed->u.type)
    1451      4917450 :                 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     95324877 :   if ((scope->function_body || scope == file_scope) && context)
    1463              :     {
    1464     37777406 :       DECL_INITIAL (context) = block;
    1465     37777406 :       BLOCK_SUPERCONTEXT (block) = context;
    1466              :     }
    1467     57547471 :   else if (scope->outer)
    1468              :     {
    1469     57439336 :       if (block)
    1470       286054 :         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     57153282 :       else if (scope->blocks)
    1475       363474 :         SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
    1476              :     }
    1477              : 
    1478              :   /* Pop the current scope, and free the structure for reuse.  */
    1479     95324877 :   current_scope = scope->outer;
    1480     95324877 :   if (scope->function_body)
    1481     37669273 :     current_function_scope = scope->outer_function;
    1482              : 
    1483     95324877 :   memset (scope, 0, sizeof (struct c_scope));
    1484     95324877 :   scope->outer = scope_freelist;
    1485     95324877 :   scope_freelist = scope;
    1486              : 
    1487     95324877 :   return block;
    1488              : }
    1489              : 
    1490              : void
    1491       108621 : push_file_scope (void)
    1492              : {
    1493       108621 :   tree decl;
    1494              : 
    1495       108621 :   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       108621 :   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       108621 :   push_scope ();
    1508       108621 :   file_scope = current_scope;
    1509              : 
    1510       108621 :   start_fname_decls ();
    1511              : 
    1512    217891083 :   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
    1513    217782462 :     bind (DECL_NAME (decl), decl, file_scope,
    1514    217782462 :           /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
    1515              : }
    1516              : 
    1517              : void
    1518       108466 : pop_file_scope (void)
    1519              : {
    1520              :   /* In case there were missing closebraces, get us back to the global
    1521              :      binding level.  */
    1522       108471 :   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       108466 :   finish_fname_decls ();
    1529              : 
    1530       108466 :   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       108466 :   if (pch_file)
    1535              :     {
    1536          331 :       c_common_write_pch ();
    1537              :       /* Ensure even the callers don't try to finalize the CU.  */
    1538          331 :       flag_syntax_only = 1;
    1539          331 :       return;
    1540              :     }
    1541              : 
    1542              :   /* Pop off the file scope and close this translation unit.  */
    1543       108135 :   pop_scope ();
    1544       108135 :   file_scope = 0;
    1545              : 
    1546       108135 :   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          693 : start_underspecified_init (location_t loc, tree name)
    1563              : {
    1564          693 :   bool prev = in_underspecified_init;
    1565          693 :   bool ok;
    1566          693 :   if (name == NULL_TREE)
    1567              :     ok = true;
    1568              :   else
    1569              :     {
    1570          459 :       tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
    1571          459 :       C_DECL_UNDERSPECIFIED (decl) = 1;
    1572          459 :       struct c_scope *scope = current_scope;
    1573          459 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1574          459 :       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          455 :           bind (name, decl, scope, false, false, loc);
    1583          455 :           ok = true;
    1584              :         }
    1585              :     }
    1586          693 :   in_underspecified_init = true;
    1587          693 :   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          693 : finish_underspecified_init (tree name, unsigned int prev_state)
    1597              : {
    1598          693 :   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          455 :       struct c_scope *scope = current_scope;
    1603          455 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1604          455 :       gcc_assert (b);
    1605          455 :       gcc_assert (B_IN_SCOPE (b, scope));
    1606          455 :       gcc_assert (VAR_P (b->decl));
    1607          455 :       gcc_assert (C_DECL_UNDERSPECIFIED (b->decl));
    1608          455 :       I_SYMBOL_BINDING (name) = b->shadowed;
    1609              :       /* In erroneous cases there may be other bindings added to this
    1610              :          scope during the initializer.  */
    1611          455 :       struct c_binding **p = &scope->bindings;
    1612          510 :       while (*p != b)
    1613           55 :         p = &((*p)->prev);
    1614          455 :       *p = free_binding_and_advance (*p);
    1615              :     }
    1616          693 :   in_underspecified_init = (prev_state & (1u << 1)) >> 1;
    1617          693 : }
    1618              : 
    1619              : /* Adjust the bindings for the start of a statement expression.  */
    1620              : 
    1621              : void
    1622        35440 : c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
    1623              : {
    1624        35440 :   struct c_scope *scope;
    1625              : 
    1626       239189 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1627              :     {
    1628       203749 :       struct c_binding *b;
    1629              : 
    1630       203749 :       if (!scope->has_label_bindings)
    1631       201321 :         continue;
    1632              : 
    1633        13223 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1634              :         {
    1635        10795 :           struct c_label_vars *label_vars;
    1636        10795 :           unsigned int ix;
    1637        10795 :           struct c_goto_bindings *g;
    1638              : 
    1639        10795 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1640         1993 :             continue;
    1641         8802 :           label_vars = b->u.label;
    1642         8802 :           ++label_vars->label_bindings.stmt_exprs;
    1643        13451 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1644         1891 :             ++g->goto_bindings.stmt_exprs;
    1645              :         }
    1646              :     }
    1647              : 
    1648        35440 :   if (switch_bindings != NULL)
    1649          361 :     ++switch_bindings->stmt_exprs;
    1650        35440 : }
    1651              : 
    1652              : /* Adjust the bindings for the end of a statement expression.  */
    1653              : 
    1654              : void
    1655        35440 : c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
    1656              : {
    1657        35440 :   struct c_scope *scope;
    1658              : 
    1659       203749 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1660              :     {
    1661       168309 :       struct c_binding *b;
    1662              : 
    1663       168309 :       if (!scope->has_label_bindings)
    1664       165646 :         continue;
    1665              : 
    1666        16703 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1667              :         {
    1668        14040 :           struct c_label_vars *label_vars;
    1669        14040 :           unsigned int ix;
    1670        14040 :           struct c_goto_bindings *g;
    1671              : 
    1672        14040 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1673         2057 :             continue;
    1674        11983 :           label_vars = b->u.label;
    1675        11983 :           --label_vars->label_bindings.stmt_exprs;
    1676        11983 :           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        16688 :           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        35440 :   if (switch_bindings != NULL)
    1694              :     {
    1695          361 :       --switch_bindings->stmt_exprs;
    1696          361 :       gcc_assert (switch_bindings->stmt_exprs >= 0);
    1697              :     }
    1698        35440 : }
    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      1450056 : pushtag (location_t loc, tree name, tree type)
    1710              : {
    1711              :   /* Record the identifier as the type's name if it has none.  */
    1712      1450056 :   if (name && !TYPE_NAME (type))
    1713       638364 :     TYPE_NAME (type) = name;
    1714      1450056 :   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      1450056 :   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      1450056 :   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
    1730              : 
    1731      1450056 :   if (warn_cxx_compat && name != NULL_TREE)
    1732              :     {
    1733          643 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1734              : 
    1735          643 :       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          648 :           && (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      1450056 : }
    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       629583 : types_close_enough_to_match (tree t1, tree t2)
    1820              : {
    1821       629583 :   return (TYPE_MODE (t1) == TYPE_MODE (t2)
    1822       629135 :           && POINTER_TYPE_P (t1) == POINTER_TYPE_P (t2)
    1823      2516835 :           && 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       146065 : match_builtin_function_types (tree newtype, tree oldtype,
    1834              :                               tree *strict, unsigned *argno)
    1835              : {
    1836       146065 :   *argno = 0;
    1837       146065 :   *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       146065 :   tree oldrettype = TREE_TYPE (oldtype);
    1842       146065 :   tree newrettype = TREE_TYPE (newtype);
    1843              : 
    1844       146065 :   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       145709 :   if (!comptypes (TYPE_MAIN_VARIANT (oldrettype),
    1850       145709 :                   TYPE_MAIN_VARIANT (newrettype)))
    1851           46 :     *strict = oldrettype;
    1852              : 
    1853       145709 :   tree oldargs = TYPE_ARG_TYPES (oldtype);
    1854       145709 :   tree newargs = TYPE_ARG_TYPES (newtype);
    1855       145709 :   tree tryargs = newargs;
    1856              : 
    1857       145709 :   const unsigned nlst = ARRAY_SIZE (last_structptr_types);
    1858       145709 :   const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
    1859              : 
    1860       145709 :   gcc_checking_assert (nlst == nbst);
    1861              : 
    1862       629031 :   for (unsigned i = 1; oldargs || newargs; ++i)
    1863              :     {
    1864       483577 :       if (!oldargs
    1865       483577 :           || !newargs
    1866       483522 :           || !TREE_VALUE (oldargs)
    1867       967099 :           || !TREE_VALUE (newargs))
    1868              :         return NULL_TREE;
    1869              : 
    1870       483522 :       tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
    1871       483522 :       tree newtype = TREE_VALUE (newargs);
    1872       483522 :       if (newtype == error_mark_node)
    1873              :        return NULL_TREE;
    1874       483518 :       newtype = TYPE_MAIN_VARIANT (newtype);
    1875              : 
    1876       483518 :       if (!types_close_enough_to_match (oldtype, newtype))
    1877              :         return NULL_TREE;
    1878              : 
    1879       483375 :       unsigned j = nbst;
    1880       483375 :       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       987147 :         for (j = 0; j < nbst; ++j)
    1885              :           {
    1886       869789 :             if (TREE_VALUE (oldargs) != builtin_structptr_types[j].node)
    1887       724550 :               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       145239 :             if (last_structptr_types[j])
    1893              :               {
    1894       127449 :                 if (!comptypes (last_structptr_types[j], newtype))
    1895              :                   {
    1896            2 :                     *argno = i;
    1897            2 :                     *strict = last_structptr_types[j];
    1898              :                   }
    1899              :               }
    1900              :             else
    1901        17790 :               last_structptr_types[j] = newtype;
    1902              :             break;
    1903              :           }
    1904              : 
    1905       483375 :       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       483322 :       oldargs = TREE_CHAIN (oldargs);
    1927       483322 :       newargs = TREE_CHAIN (newargs);
    1928              :     }
    1929              : 
    1930       145454 :   tree trytype = c_build_function_type (newrettype, tryargs);
    1931              : 
    1932              :   /* Allow declaration to change transaction_safe attribute.  */
    1933       145454 :   tree oldattrs = TYPE_ATTRIBUTES (oldtype);
    1934       145454 :   tree oldtsafe = lookup_attribute ("transaction_safe", oldattrs);
    1935       145454 :   tree newattrs = TYPE_ATTRIBUTES (newtype);
    1936       145454 :   tree newtsafe = lookup_attribute ("transaction_safe", newattrs);
    1937       145454 :   if (oldtsafe && !newtsafe)
    1938            0 :     oldattrs = remove_attribute ("transaction_safe", oldattrs);
    1939       145454 :   else if (newtsafe && !oldtsafe)
    1940            7 :     oldattrs = tree_cons (get_identifier ("transaction_safe"),
    1941              :                           NULL_TREE, oldattrs);
    1942              : 
    1943       145454 :   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              :     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      1160113 : previous_tag (tree type)
    2091              : {
    2092      1160113 :   struct c_binding *b = NULL;
    2093      1160113 :   tree name = c_type_tag (type);
    2094              : 
    2095      1160113 :   if (name)
    2096       578107 :     b = I_TAG_BINDING (name);
    2097              : 
    2098       578107 :   if (b)
    2099       578107 :     b = b->shadowed;
    2100              : 
    2101      1160113 :   if (b && B_IN_CURRENT_SCOPE (b))
    2102          180 :     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      5251170 : diagnose_mismatched_decls (tree newdecl, tree olddecl,
    2146              :                            tree *newtypep, tree *oldtypep)
    2147              : {
    2148      5251170 :   tree newtype, oldtype;
    2149      5251170 :   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      5251170 :   if (olddecl == error_mark_node || newdecl == error_mark_node)
    2157              :     return false;
    2158      5251150 :   *oldtypep = oldtype = TREE_TYPE (olddecl);
    2159      5251150 :   *newtypep = newtype = TREE_TYPE (newdecl);
    2160      5251150 :   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      5251142 :   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              :       return false;
    2183              :     }
    2184              : 
    2185              :   /* Enumerators have no linkage, so may only be declared once in a
    2186              :      given scope.  */
    2187      5251113 :   if (TREE_CODE (olddecl) == CONST_DECL)
    2188              :     {
    2189           50 :       if (flag_isoc23
    2190           49 :           && TYPE_NAME (DECL_CONTEXT (newdecl))
    2191           47 :           && DECL_CONTEXT (newdecl) != DECL_CONTEXT (olddecl)
    2192           95 :           && TYPE_NAME (DECL_CONTEXT (newdecl)) == TYPE_NAME (DECL_CONTEXT (olddecl)))
    2193              :         {
    2194           42 :           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              :       return false;
    2208              :     }
    2209              : 
    2210      5251063 :   bool pedwarned = false;
    2211      5251063 :   bool warned = false;
    2212      5251063 :   bool enum_and_int_p = false;
    2213      5251063 :   auto_diagnostic_group d;
    2214              : 
    2215      5251063 :   bool comptypes_result = comptypes_check_enum_int (oldtype, newtype,
    2216              :                                                     &enum_and_int_p);
    2217      5251063 :   if (!comptypes_result)
    2218              :     {
    2219       146274 :       if (TREE_CODE (olddecl) == FUNCTION_DECL
    2220       146194 :           && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL)
    2221       292340 :           && !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       146065 :           tree mismatch_expect;
    2228       146065 :           unsigned mismatch_argno;
    2229              : 
    2230       146065 :           tree trytype = match_builtin_function_types (newtype, oldtype,
    2231              :                                                        &mismatch_expect,
    2232              :                                                        &mismatch_argno);
    2233              : 
    2234       146065 :           if (trytype && comptypes (newtype, trytype))
    2235       145454 :             *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          611 :               const char *header = header_for_builtin_fn (olddecl);
    2242          611 :               location_t loc = DECL_SOURCE_LOCATION (newdecl);
    2243         1011 :               if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    2244              :                               "conflicting types for built-in function %q+D; "
    2245              :                               "expected %qT",
    2246              :                               newdecl, oldtype)
    2247          611 :                   && header)
    2248              :                 {
    2249              :                   /* Suggest the right header to include as the preferred
    2250              :                      solution rather than the spelling of the declaration.  */
    2251          211 :                   rich_location richloc (line_table, loc);
    2252          211 :                   maybe_add_include_fixit (&richloc, header, true);
    2253          211 :                   inform (&richloc,
    2254              :                           "%qD is declared in header %qs", olddecl, header);
    2255          211 :                 }
    2256          611 :               return false;
    2257              :             }
    2258              : 
    2259       145454 :           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 :           auto new_quals = TYPE_QUALS (newtype);
    2324          185 :           auto old_quals = TYPE_QUALS (oldtype);
    2325              : 
    2326          185 :           if (new_quals != old_quals)
    2327              :             {
    2328           21 :               addr_space_t new_addr, old_addr;
    2329           21 :               cv_qualifier new_cv, old_cv;
    2330           21 :               std::tie (new_cv, new_addr) = new_quals.split ();
    2331           21 :               std::tie (old_cv, old_addr) = old_quals.split ();
    2332           21 :               if (new_addr != old_addr)
    2333              :                 {
    2334            0 :                   if (ADDR_SPACE_GENERIC_P (new_addr))
    2335            0 :                     error ("conflicting named address spaces (generic vs %s) "
    2336              :                            "for %q+D",
    2337              :                            c_addr_space_name (old_addr), newdecl);
    2338            0 :                   else if (ADDR_SPACE_GENERIC_P (old_addr))
    2339            0 :                     error ("conflicting named address spaces (%s vs generic) "
    2340              :                            "for %q+D",
    2341              :                            c_addr_space_name (new_addr), newdecl);
    2342              :                   else
    2343            0 :                     error ("conflicting named address spaces (%s vs %s) "
    2344              :                            "for %q+D",
    2345              :                            c_addr_space_name (new_addr),
    2346              :                            c_addr_space_name (old_addr),
    2347              :                            newdecl);
    2348              :                 }
    2349              : 
    2350           21 :               if (new_cv != old_cv)
    2351           21 :                 error ("conflicting type qualifiers for %q+D", newdecl);
    2352              :             }
    2353              :           else
    2354              :             {
    2355          164 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2356              :                 {
    2357           93 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl));
    2358           93 :                   if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl)))
    2359              :                     {
    2360              :                       /* Similar to the C++ front-end, for FUNCTION_DECL,
    2361              :                          if OLDDECL has attributes and NEWDECL doesn't,
    2362              :                          try the type with OLDDECL attributes.  */
    2363           12 :                       tree rettype = TREE_TYPE (newtype);
    2364           12 :                       tree tryargs = TYPE_ARG_TYPES (newtype);
    2365           12 :                       tree trytype = c_build_function_type (rettype,
    2366              :                                                             tryargs);
    2367           12 :                       trytype = c_build_type_attribute_variant (trytype,
    2368              :                                                                 attrs);
    2369           12 :                       if (comptypes (oldtype, trytype))
    2370              :                         {
    2371            7 :                           *newtypep = newtype = trytype;
    2372            7 :                           comptypes_result = true;
    2373              :                         }
    2374              :                     }
    2375              :                 }
    2376              : 
    2377            7 :               if (!comptypes_result)
    2378          157 :                 error ("conflicting types for %q+D; have %qT", newdecl,
    2379              :                        newtype);
    2380              :             }
    2381          178 :           if (!comptypes_result)
    2382              :             {
    2383          178 :               diagnose_arglist_conflict (newdecl, olddecl, newtype,
    2384              :                                          oldtype);
    2385          178 :               locate_old_decl (olddecl);
    2386          178 :               return false;
    2387              :             }
    2388              :         }
    2389              :     }
    2390              :   /* Warn about enum/integer type mismatches.  They are compatible types
    2391              :      (C23 6.7.2.2/5), but may pose portability problems.  */
    2392      5104789 :   else if (enum_and_int_p
    2393          192 :            && TREE_CODE (newdecl) != TYPE_DECL
    2394              :            /* Don't warn about acc_on_device built-in redeclaration,
    2395              :               the built-in is declared with int rather than enum because
    2396              :               the enum isn't intrinsic.  */
    2397      5104977 :            && !(TREE_CODE (olddecl) == FUNCTION_DECL
    2398          151 :                 && fndecl_built_in_p (olddecl, BUILT_IN_ACC_ON_DEVICE)
    2399          121 :                 && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2400           67 :     warned = warning_at (DECL_SOURCE_LOCATION (newdecl),
    2401           67 :                          OPT_Wenum_int_mismatch,
    2402              :                          "conflicting types for %q+D due to enum/integer "
    2403              :                          "mismatch; have %qT", newdecl, newtype);
    2404              : 
    2405              :   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
    2406              :      but silently ignore the redeclaration if either is in a system
    2407              :      header.  (Conflicting redeclarations were handled above.)  This
    2408              :      is allowed for C11 if the types are the same, not just
    2409              :      compatible.  */
    2410      5250274 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2411              :     {
    2412        46303 :       if (!comptypes_same_p (oldtype, newtype))
    2413              :         {
    2414           11 :           error ("redefinition of typedef %q+D with different type", newdecl);
    2415           11 :           locate_old_decl (olddecl);
    2416           11 :           return false;
    2417              :         }
    2418              : 
    2419        46292 :       if (DECL_IN_SYSTEM_HEADER (newdecl)
    2420         2497 :           || DECL_IN_SYSTEM_HEADER (olddecl)
    2421         2275 :           || warning_suppressed_p (newdecl, OPT_Wpedantic)
    2422        48567 :           || warning_suppressed_p (olddecl, OPT_Wpedantic))
    2423              :         return true;  /* Allow OLDDECL to continue in use.  */
    2424              : 
    2425         2275 :       if (c_type_variably_modified_p (newtype))
    2426              :         {
    2427            3 :           error ("redefinition of typedef %q+D with variably modified type",
    2428              :                  newdecl);
    2429            3 :           locate_old_decl (olddecl);
    2430              :         }
    2431         2272 :       else if (pedwarn_c99 (input_location, OPT_Wpedantic,
    2432              :                             "redefinition of typedef %q+D", newdecl))
    2433            8 :         locate_old_decl (olddecl);
    2434              : 
    2435              :       return true;
    2436              :     }
    2437              : 
    2438              :   /* Function declarations can either be 'static' or 'extern' (no
    2439              :      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
    2440              :      can never conflict with each other on account of linkage
    2441              :      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
    2442              :      gnu89 mode permits two definitions if one is 'extern inline' and
    2443              :      one is not.  The non- extern-inline definition supersedes the
    2444              :      extern-inline definition.  */
    2445              : 
    2446      5203971 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2447              :     {
    2448              :       /* If you declare a built-in function name as static, or
    2449              :          define the built-in with an old-style definition (so we
    2450              :          can't validate the argument list) the built-in definition is
    2451              :          overridden, but optionally warn this was a bad choice of name.  */
    2452      5185277 :       if (fndecl_built_in_p (olddecl)
    2453      9251642 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2454              :         {
    2455      3800932 :           if (!TREE_PUBLIC (newdecl)
    2456      3800932 :               || (DECL_INITIAL (newdecl)
    2457         4862 :                   && !prototype_p (TREE_TYPE (newdecl))))
    2458              :             {
    2459          104 :               warning_at (DECL_SOURCE_LOCATION (newdecl),
    2460          104 :                           OPT_Wshadow, "declaration of %qD shadows "
    2461              :                           "a built-in function", newdecl);
    2462              :               /* Discard the old built-in function.  */
    2463          104 :               return false;
    2464              :             }
    2465              : 
    2466      3800828 :           if (!prototype_p (TREE_TYPE (newdecl)))
    2467              :             {
    2468              :               /* Set for built-ins that take no arguments.  */
    2469          350 :               bool func_void_args = false;
    2470          350 :               if (tree at = TYPE_ARG_TYPES (oldtype))
    2471          350 :                 func_void_args = VOID_TYPE_P (TREE_VALUE (at));
    2472              : 
    2473          350 :               if (extra_warnings && !func_void_args)
    2474           47 :                 warning_at (DECL_SOURCE_LOCATION (newdecl),
    2475           47 :                             OPT_Wbuiltin_declaration_mismatch,
    2476              :                             "declaration of built-in function %qD without "
    2477              :                             "a prototype; expected %qT",
    2478           47 :                             newdecl, TREE_TYPE (olddecl));
    2479              :             }
    2480              :         }
    2481              : 
    2482      5185173 :       if (DECL_INITIAL (newdecl))
    2483              :         {
    2484       234554 :           if (DECL_INITIAL (olddecl))
    2485              :             {
    2486              :               /* If the new declaration isn't overriding an extern inline
    2487              :                  reject the new decl. In c99, no overriding is allowed
    2488              :                  in the same translation unit.  */
    2489          209 :               if (!DECL_EXTERN_INLINE (olddecl)
    2490           91 :                   || DECL_EXTERN_INLINE (newdecl)
    2491          204 :                   || (!flag_gnu89_inline
    2492           15 :                       && (!DECL_DECLARED_INLINE_P (olddecl)
    2493           15 :                           || !lookup_attribute ("gnu_inline",
    2494           15 :                                                 DECL_ATTRIBUTES (olddecl)))
    2495            0 :                       && (!DECL_DECLARED_INLINE_P (newdecl)
    2496            0 :                           || !lookup_attribute ("gnu_inline",
    2497            0 :                                                 DECL_ATTRIBUTES (newdecl)))))
    2498              :                 {
    2499           26 :                   auto_diagnostic_group d;
    2500           26 :                   error ("redefinition of %q+D", newdecl);
    2501           26 :                   locate_old_decl (olddecl);
    2502           26 :                   return false;
    2503           26 :                 }
    2504              :             }
    2505              :         }
    2506              :       /* If we have a prototype after an old-style function definition,
    2507              :          the argument types must be checked specially.  */
    2508      4950619 :       else if (DECL_INITIAL (olddecl)
    2509          825 :                && !prototype_p (oldtype) && prototype_p (newtype)
    2510      4950639 :                && TYPE_ACTUAL_ARG_TYPES (oldtype))
    2511              :         {
    2512           19 :           auto_diagnostic_group d;
    2513           19 :           if (!validate_proto_after_old_defn (newdecl, newtype, oldtype))
    2514              :             {
    2515           10 :               locate_old_decl (olddecl);
    2516           10 :               return false;
    2517              :             }
    2518           19 :         }
    2519              :       /* A non-static declaration (even an "extern") followed by a
    2520              :          static declaration is undefined behavior per C99 6.2.2p3-5,7.
    2521              :          The same is true for a static forward declaration at block
    2522              :          scope followed by a non-static declaration/definition at file
    2523              :          scope.  Static followed by non-static at the same scope is
    2524              :          not undefined behavior, and is the most convenient way to get
    2525              :          some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
    2526              :          the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
    2527              :          we do diagnose it if -Wtraditional.  */
    2528      5185137 :       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
    2529              :         {
    2530              :           /* Two exceptions to the rule.  If olddecl is an extern
    2531              :              inline, or a predeclared function that isn't actually
    2532              :              built in, newdecl silently overrides olddecl.  The latter
    2533              :              occur only in Objective C; see also above.  (FIXME: Make
    2534              :              Objective C use normal builtins.)  */
    2535           19 :           if (!DECL_IS_UNDECLARED_BUILTIN (olddecl)
    2536           38 :               && !DECL_EXTERN_INLINE (olddecl))
    2537              :             {
    2538            5 :               auto_diagnostic_group d;
    2539            5 :               error ("static declaration of %q+D follows "
    2540              :                      "non-static declaration", newdecl);
    2541            5 :               locate_old_decl (olddecl);
    2542            5 :             }
    2543              :           return false;
    2544              :         }
    2545      5185118 :       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
    2546              :         {
    2547         2330 :           if (DECL_CONTEXT (olddecl))
    2548              :             {
    2549            0 :               auto_diagnostic_group d;
    2550            0 :               error ("non-static declaration of %q+D follows "
    2551              :                      "static declaration", newdecl);
    2552            0 :               locate_old_decl (olddecl);
    2553            0 :               return false;
    2554            0 :             }
    2555         2330 :           else if (warn_traditional)
    2556              :             {
    2557            2 :               warned |= warning (OPT_Wtraditional,
    2558              :                                  "non-static declaration of %q+D "
    2559              :                                  "follows static declaration", newdecl);
    2560              :             }
    2561              :         }
    2562              : 
    2563              :       /* Make sure gnu_inline attribute is either not present, or
    2564              :          present on all inline decls.  */
    2565      5185118 :       if (DECL_DECLARED_INLINE_P (olddecl)
    2566      5186221 :           && DECL_DECLARED_INLINE_P (newdecl))
    2567              :         {
    2568          847 :           bool newa = lookup_attribute ("gnu_inline",
    2569          847 :                                         DECL_ATTRIBUTES (newdecl)) != NULL;
    2570          847 :           bool olda = lookup_attribute ("gnu_inline",
    2571          847 :                                         DECL_ATTRIBUTES (olddecl)) != NULL;
    2572          847 :           if (newa != olda)
    2573              :             {
    2574            0 :               auto_diagnostic_group d;
    2575            0 :               error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
    2576              :                         newa ? newdecl : olddecl);
    2577            0 :               error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
    2578              :                         "but not here");
    2579            0 :             }
    2580              :         }
    2581              :       /* Check if these are unmergeable overlapping FMV declarations.  */
    2582              :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2583              :           && diagnose_versioned_decls (olddecl, newdecl))
    2584              :         return false;
    2585              :     }
    2586        18694 :   else if (VAR_P (newdecl))
    2587              :     {
    2588              :       /* Only variables can be thread-local, and all declarations must
    2589              :          agree on this property.  */
    2590        18657 :       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
    2591              :         {
    2592              :           /* Nothing to check.  Since OLDDECL is marked threadprivate
    2593              :              and NEWDECL does not have a thread-local attribute, we
    2594              :              will merge the threadprivate attribute into NEWDECL.  */
    2595              :           ;
    2596              :         }
    2597        55748 :       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
    2598              :         {
    2599            6 :           auto_diagnostic_group d;
    2600            6 :           if (DECL_THREAD_LOCAL_P (newdecl))
    2601            3 :             error ("thread-local declaration of %q+D follows "
    2602              :                    "non-thread-local declaration", newdecl);
    2603              :           else
    2604            3 :             error ("non-thread-local declaration of %q+D follows "
    2605              :                    "thread-local declaration", newdecl);
    2606              : 
    2607            6 :           locate_old_decl (olddecl);
    2608            6 :           return false;
    2609            6 :         }
    2610              : 
    2611              :       /* Multiple initialized definitions are not allowed (6.9p3,5).
    2612              :          For this purpose, C23 makes it clear that thread-local
    2613              :          declarations without extern are definitions, not tentative
    2614              :          definitions, whether or not they have initializers.  The
    2615              :          wording before C23 was unclear; literally it would have made
    2616              :          uninitialized thread-local declarations into tentative
    2617              :          definitions only if they also used static, but without saying
    2618              :          explicitly whether or not other cases count as
    2619              :          definitions at all.  */
    2620        19224 :       if ((DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
    2621        19223 :           || (flag_isoc23
    2622         6483 :               && DECL_THREAD_LOCAL_P (newdecl)
    2623           30 :               && !DECL_EXTERNAL (newdecl)
    2624           21 :               && !DECL_EXTERNAL (olddecl)))
    2625              :         {
    2626            7 :           auto_diagnostic_group d;
    2627            7 :           error ("redefinition of %q+D", newdecl);
    2628            7 :           locate_old_decl (olddecl);
    2629            7 :           return false;
    2630            7 :         }
    2631              : 
    2632              :       /* Objects declared at file scope: if the first declaration had
    2633              :          external linkage (even if it was an external reference) the
    2634              :          second must have external linkage as well, or the behavior is
    2635              :          undefined.  If the first declaration had internal linkage, then
    2636              :          the second must too, or else be an external reference (in which
    2637              :          case the composite declaration still has internal linkage).
    2638              :          As for function declarations, we warn about the static-then-
    2639              :          extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
    2640        18661 :       if (DECL_FILE_SCOPE_P (newdecl)
    2641        18644 :           && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
    2642              :         {
    2643          147 :           if (DECL_EXTERNAL (newdecl))
    2644              :             {
    2645          144 :               if (!DECL_FILE_SCOPE_P (olddecl))
    2646              :                 {
    2647            2 :                   auto_diagnostic_group d;
    2648            2 :                   error ("extern declaration of %q+D follows "
    2649              :                          "declaration with no linkage", newdecl);
    2650            2 :                   locate_old_decl (olddecl);
    2651            2 :                   return false;
    2652            2 :                 }
    2653          142 :               else if (warn_traditional)
    2654              :                 {
    2655            0 :                   warned |= warning (OPT_Wtraditional,
    2656              :                                      "non-static declaration of %q+D "
    2657              :                                      "follows static declaration", newdecl);
    2658              :                 }
    2659              :             }
    2660              :           else
    2661              :             {
    2662            3 :               auto_diagnostic_group d;
    2663            3 :               if (TREE_PUBLIC (newdecl))
    2664            2 :                 error ("non-static declaration of %q+D follows "
    2665              :                        "static declaration", newdecl);
    2666              :               else
    2667            1 :                 error ("static declaration of %q+D follows "
    2668              :                        "non-static declaration", newdecl);
    2669              : 
    2670            3 :               locate_old_decl (olddecl);
    2671            3 :               return false;
    2672            3 :             }
    2673              :         }
    2674              :       /* Two objects with the same name declared at the same block
    2675              :          scope must both be external references (6.7p3).  */
    2676        18497 :       else if (!DECL_FILE_SCOPE_P (newdecl))
    2677              :         {
    2678           17 :           if (DECL_EXTERNAL (newdecl))
    2679              :             {
    2680              :               /* Extern with initializer at block scope, which will
    2681              :                  already have received an error.  */
    2682              :             }
    2683           15 :           else if (DECL_EXTERNAL (olddecl))
    2684              :             {
    2685            4 :               auto_diagnostic_group d;
    2686            4 :               error ("declaration of %q+D with no linkage follows "
    2687              :                      "extern declaration", newdecl);
    2688            4 :               locate_old_decl (olddecl);
    2689            4 :             }
    2690              :           else
    2691              :             {
    2692           11 :               auto_diagnostic_group d;
    2693           11 :               error ("redeclaration of %q+D with no linkage", newdecl);
    2694           11 :               locate_old_decl (olddecl);
    2695           11 :             }
    2696              : 
    2697              :           return false;
    2698              :         }
    2699              : 
    2700              :       /* C++ does not permit a decl to appear multiple times at file
    2701              :          scope.  */
    2702        18622 :       if (warn_cxx_compat
    2703           72 :           && DECL_FILE_SCOPE_P (newdecl)
    2704           72 :           && !DECL_EXTERNAL (newdecl)
    2705        18640 :           && !DECL_EXTERNAL (olddecl))
    2706            5 :         warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
    2707            5 :                               OPT_Wc___compat,
    2708              :                               "duplicate declaration of %qD is "
    2709              :                               "invalid in C++", newdecl);
    2710              :     }
    2711              : 
    2712              :   /* warnings */
    2713              :   /* All decls must agree on a visibility.  */
    2714      5203777 :   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
    2715      5203740 :       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
    2716      5204533 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2717              :     {
    2718            1 :       warned |= warning (0, "redeclaration of %q+D with different visibility "
    2719              :                          "(old visibility preserved)", newdecl);
    2720              :     }
    2721              : 
    2722      5203777 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2723      5185118 :     warned |= diagnose_mismatched_attributes (olddecl, newdecl);
    2724              :   else /* PARM_DECL, VAR_DECL */
    2725              :     {
    2726              :       /* Redeclaration of a parameter is a constraint violation (this is
    2727              :          not explicitly stated, but follows from C99 6.7p3 [no more than
    2728              :          one declaration of the same identifier with no linkage in the
    2729              :          same scope, except type tags] and 6.2.2p6 [parameters have no
    2730              :          linkage]).  We must check for a forward parameter declaration,
    2731              :          indicated by TREE_ASM_WRITTEN on the old declaration - this is
    2732              :          an extension, the mandatory diagnostic for which is handled by
    2733              :          mark_forward_parm_decls.  */
    2734              : 
    2735        18659 :       if (TREE_CODE (newdecl) == PARM_DECL
    2736           37 :           && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
    2737              :         {
    2738            2 :           auto_diagnostic_group d;
    2739            2 :           error ("redefinition of parameter %q+D", newdecl);
    2740            2 :           locate_old_decl (olddecl);
    2741            2 :           return false;
    2742            2 :         }
    2743              :     }
    2744              : 
    2745              :   /* Optional warning for completely redundant decls.  */
    2746      5203775 :   if (!warned && !pedwarned
    2747      5203701 :       && warn_redundant_decls
    2748              :       /* Don't warn about a function declaration followed by a
    2749              :          definition.  */
    2750           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2751            2 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
    2752              :       /* Don't warn about redundant redeclarations of builtins.  */
    2753           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2754            2 :            && !fndecl_built_in_p (newdecl)
    2755            2 :            && fndecl_built_in_p (olddecl)
    2756            2 :            && !C_DECL_DECLARED_BUILTIN (olddecl))
    2757              :       /* Don't warn about an extern followed by a definition.  */
    2758           17 :       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
    2759              :       /* Don't warn about forward parameter decls.  */
    2760           17 :       && !(TREE_CODE (newdecl) == PARM_DECL
    2761            6 :            && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2762              :       /* Don't warn about a variable definition following a declaration.  */
    2763      5203786 :       && !(VAR_P (newdecl)
    2764           10 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
    2765              :     {
    2766            6 :       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
    2767              :                         newdecl);
    2768              :     }
    2769              : 
    2770              :   /* Report location of previous decl/defn.  */
    2771      5203775 :   if (warned || pedwarned)
    2772           80 :     locate_old_decl (olddecl);
    2773              : 
    2774              : #undef DECL_EXTERN_INLINE
    2775              : 
    2776              :   return retval;
    2777      5251063 : }
    2778              : 
    2779              : /* Subroutine of duplicate_decls.  NEWDECL has been found to be
    2780              :    consistent with OLDDECL, but carries new information.  Merge the
    2781              :    new information into OLDDECL.  This function issues no
    2782              :    diagnostics.  */
    2783              : 
    2784              : static void
    2785      5250067 : merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
    2786              : {
    2787      5250067 :   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
    2788      5250067 :                             && DECL_INITIAL (newdecl) != NULL_TREE);
    2789      5250067 :   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
    2790      5250067 :                            && prototype_p (TREE_TYPE (newdecl)));
    2791      5250067 :   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
    2792      5250067 :                            && prototype_p (TREE_TYPE (olddecl)));
    2793              : 
    2794              :   /* For real parm decl following a forward decl, rechain the old decl
    2795              :      in its new location and clear TREE_ASM_WRITTEN (it's not a
    2796              :      forward decl anymore).  */
    2797      5250067 :   if (TREE_CODE (newdecl) == PARM_DECL
    2798           35 :       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2799              :     {
    2800           35 :       struct c_binding *b, **here;
    2801              : 
    2802           54 :       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
    2803           54 :         if ((*here)->decl == olddecl)
    2804           35 :           goto found;
    2805            0 :       gcc_unreachable ();
    2806              : 
    2807           35 :     found:
    2808           35 :       b = *here;
    2809           35 :       *here = b->prev;
    2810           35 :       b->prev = current_scope->bindings;
    2811           35 :       current_scope->bindings = b;
    2812              : 
    2813           35 :       TREE_ASM_WRITTEN (olddecl) = 0;
    2814              :     }
    2815              : 
    2816      5250067 :   DECL_ATTRIBUTES (newdecl)
    2817      5250067 :     = targetm.merge_decl_attributes (olddecl, newdecl);
    2818              : 
    2819              :   /* For typedefs use the old type, as the new type's DECL_NAME points
    2820              :      at newdecl, which will be ggc_freed.  */
    2821      5250067 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2822              :     {
    2823              :       /* But NEWTYPE might have an attribute, honor that.  */
    2824        46292 :       tree tem = newtype;
    2825        46292 :       newtype = oldtype;
    2826              : 
    2827        46292 :       if (TYPE_USER_ALIGN (tem))
    2828              :         {
    2829           15 :           if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2830            6 :             SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2831           15 :           TYPE_USER_ALIGN (newtype) = true;
    2832              :         }
    2833              : 
    2834              :       /* And remove the new type from the variants list.  */
    2835        46292 :       if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2836              :         {
    2837           15 :           tree remove = TREE_TYPE (newdecl);
    2838           15 :           if (TYPE_MAIN_VARIANT (remove) == remove)
    2839              :             {
    2840            2 :               gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2841              :               /* If remove is the main variant, no need to remove that
    2842              :                  from the list.  One of the DECL_ORIGINAL_TYPE
    2843              :                  variants, e.g. created for aligned attribute, might still
    2844              :                  refer to the newdecl TYPE_DECL though, so remove that one
    2845              :                  in that case.  */
    2846            2 :               if (DECL_ORIGINAL_TYPE (newdecl)
    2847            2 :                   && DECL_ORIGINAL_TYPE (newdecl) != remove)
    2848            2 :                 for (tree t = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (newdecl));
    2849            2 :                      t; t = TYPE_MAIN_VARIANT (t))
    2850            2 :                   if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2851              :                     {
    2852            4 :                       TYPE_NEXT_VARIANT (t)
    2853            2 :                         = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2854            2 :                       break;
    2855              :                     }
    2856              :             }
    2857              :           else
    2858           13 :             for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2859            0 :                  t = TYPE_NEXT_VARIANT (t))
    2860           13 :               if (TYPE_NEXT_VARIANT (t) == remove)
    2861              :                 {
    2862           13 :                   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2863           13 :                   break;
    2864              :                 }
    2865              :         }
    2866              : 
    2867              :       /* Make sure we refer to the same type as the olddecl.  */
    2868        46292 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2869              :     }
    2870              : 
    2871              :   /* Merge the data types specified in the two decls.  */
    2872     10500134 :   TREE_TYPE (newdecl)
    2873      5250067 :     = TREE_TYPE (olddecl)
    2874     10500134 :     = composite_type (newtype, oldtype);
    2875              : 
    2876              :   /* Lay the type out, unless already done.  */
    2877      5250067 :   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
    2878              :     {
    2879            0 :       if (TREE_TYPE (newdecl) != error_mark_node)
    2880            0 :         layout_type (TREE_TYPE (newdecl));
    2881            0 :       if (TREE_CODE (newdecl) != FUNCTION_DECL
    2882              :           && TREE_CODE (newdecl) != TYPE_DECL
    2883              :           && TREE_CODE (newdecl) != CONST_DECL)
    2884            0 :         layout_decl (newdecl, 0);
    2885              :     }
    2886              :   else
    2887              :     {
    2888              :       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
    2889      5250067 :       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
    2890      5250067 :       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
    2891      5250067 :       SET_DECL_MODE (newdecl, DECL_MODE (olddecl));
    2892      5250067 :       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    2893              :         {
    2894           44 :           SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    2895           44 :           DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    2896              :         }
    2897      5250023 :       else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    2898      5250023 :                && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    2899            3 :         DECL_USER_ALIGN (newdecl) = 1;
    2900     10500134 :       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    2901      5250067 :           > DECL_WARN_IF_NOT_ALIGN (newdecl))
    2902            0 :         SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    2903              :                                     DECL_WARN_IF_NOT_ALIGN (olddecl));
    2904              :     }
    2905              : 
    2906              :   /* Keep the old rtl since we can safely use it.  */
    2907      5250067 :   if (HAS_RTL_P (olddecl))
    2908      5250067 :     COPY_DECL_RTL (olddecl, newdecl);
    2909              : 
    2910              :   /* Merge the type qualifiers.  */
    2911      5250067 :   if (TREE_READONLY (newdecl))
    2912       416825 :     TREE_READONLY (olddecl) = 1;
    2913              : 
    2914      5250067 :   if (TREE_THIS_VOLATILE (newdecl))
    2915        50116 :     TREE_THIS_VOLATILE (olddecl) = 1;
    2916              : 
    2917              :   /* Merge deprecatedness.  */
    2918      5250067 :   if (TREE_DEPRECATED (newdecl))
    2919          387 :     TREE_DEPRECATED (olddecl) = 1;
    2920              : 
    2921              :   /* Merge unavailability.  */
    2922      5250067 :   if (TREE_UNAVAILABLE (newdecl))
    2923            2 :     TREE_UNAVAILABLE (olddecl) = 1;
    2924              : 
    2925              :   /* If a decl is in a system header and the other isn't, keep the one on the
    2926              :      system header. Otherwise, keep source location of definition rather than
    2927              :      declaration and of prototype rather than non-prototype unless that
    2928              :      prototype is built-in.  */
    2929      5250067 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2930      5250032 :       && DECL_IN_SYSTEM_HEADER (olddecl)
    2931      6013960 :       && !DECL_IN_SYSTEM_HEADER (newdecl) )
    2932         1048 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2933      5249019 :   else if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2934      5248984 :            && DECL_IN_SYSTEM_HEADER (newdecl)
    2935      9759448 :            && !DECL_IN_SYSTEM_HEADER (olddecl))
    2936      3747584 :     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
    2937      1501435 :   else if ((DECL_INITIAL (newdecl) == NULL_TREE
    2938      1266403 :             && DECL_INITIAL (olddecl) != NULL_TREE)
    2939      2766916 :            || (old_is_prototype && !new_is_prototype
    2940          380 :                && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
    2941          950 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2942              : 
    2943              :   /* Merge the initialization information.  */
    2944      5250067 :    if (DECL_INITIAL (newdecl) == NULL_TREE)
    2945      5014963 :     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2946              : 
    2947              :   /* Merge 'constexpr' information.  */
    2948      5250067 :   if (VAR_P (olddecl) && VAR_P (newdecl))
    2949              :     {
    2950        18622 :       if (C_DECL_DECLARED_CONSTEXPR (olddecl))
    2951            2 :         C_DECL_DECLARED_CONSTEXPR (newdecl) = 1;
    2952        18620 :       else if (C_DECL_DECLARED_CONSTEXPR (newdecl))
    2953            1 :         C_DECL_DECLARED_CONSTEXPR (olddecl) = 1;
    2954              :     }
    2955              : 
    2956              :   /* Merge the threadprivate attribute.  */
    2957      5250067 :   if (VAR_P (olddecl) && C_DECL_THREADPRIVATE_P (olddecl))
    2958            7 :     C_DECL_THREADPRIVATE_P (newdecl) = 1;
    2959              : 
    2960      5250067 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl))
    2961              :     {
    2962              :       /* Copy the assembler name.
    2963              :          Currently, it can only be defined in the prototype.  */
    2964      5250032 :       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2965              : 
    2966              :       /* Use visibility of whichever declaration had it specified */
    2967      5250032 :       if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2968              :         {
    2969         4896 :           DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2970         4896 :           DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2971              :         }
    2972              : 
    2973      5250032 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2974              :         {
    2975      5185118 :           DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
    2976      5185118 :           DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2977      5185118 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2978      5185118 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2979      5185118 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2980      5185118 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2981      5185118 :           DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    2982      5185118 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2983            0 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2984      5185118 :           if (DECL_IS_OPERATOR_DELETE_P (olddecl))
    2985            0 :             DECL_SET_IS_OPERATOR_DELETE (newdecl, true);
    2986      5185118 :           TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    2987      5185118 :           DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    2988      5185118 :           DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    2989              :         }
    2990              : 
    2991              :       /* Merge the storage class information.  */
    2992      5250032 :       merge_weak (newdecl, olddecl);
    2993              : 
    2994              :       /* For functions, static overrides non-static.  */
    2995      5250032 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2996              :         {
    2997      5185118 :           TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
    2998              :           /* This is since we don't automatically
    2999              :              copy the attributes of NEWDECL into OLDDECL.  */
    3000      5185118 :           TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3001              :           /* If this clears `static', clear it in the identifier too.  */
    3002      5185118 :           if (!TREE_PUBLIC (olddecl))
    3003         7825 :             TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
    3004              :         }
    3005              :     }
    3006              : 
    3007              :   /* In c99, 'extern' declaration before (or after) 'inline' means this
    3008              :      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
    3009              :      is present.  */
    3010      5250067 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3011      5185118 :       && !flag_gnu89_inline
    3012      5160533 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3013      4968995 :           || DECL_DECLARED_INLINE_P (olddecl))
    3014       191733 :       && (!DECL_DECLARED_INLINE_P (newdecl)
    3015       191538 :           || !DECL_DECLARED_INLINE_P (olddecl)
    3016          834 :           || !DECL_EXTERNAL (olddecl))
    3017       190917 :       && DECL_EXTERNAL (newdecl)
    3018       190709 :       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
    3019      5250165 :       && !current_function_decl)
    3020           81 :     DECL_EXTERNAL (newdecl) = 0;
    3021              : 
    3022              :   /* An inline definition following a static declaration is not
    3023              :      DECL_EXTERNAL.  */
    3024      5250067 :   if (new_is_definition
    3025       234511 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3026        42739 :           || DECL_DECLARED_INLINE_P (olddecl))
    3027      5442053 :       && !TREE_PUBLIC (olddecl))
    3028          927 :     DECL_EXTERNAL (newdecl) = 0;
    3029              : 
    3030      5250067 :   if (DECL_EXTERNAL (newdecl))
    3031              :     {
    3032      5157782 :       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
    3033      5157782 :       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
    3034              : 
    3035              :       /* An extern decl does not override previous storage class.  */
    3036      5157782 :       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3037      5157782 :       if (!DECL_EXTERNAL (newdecl))
    3038              :         {
    3039         1438 :           DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    3040         1438 :           DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3041              :         }
    3042              :     }
    3043              :   else
    3044              :     {
    3045        92285 :       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
    3046        92285 :       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3047              :     }
    3048              : 
    3049      5250067 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3050              :     {
    3051      5185118 :       if (DECL_FUNCTION_VERSIONED (olddecl)
    3052      5185118 :           || DECL_FUNCTION_VERSIONED (newdecl))
    3053              :         {
    3054            0 :           maybe_mark_function_versioned (olddecl);
    3055            0 :           maybe_mark_function_versioned (newdecl);
    3056              :         }
    3057              :       /* If we're redefining a function previously defined as extern
    3058              :          inline, make sure we emit debug info for the inline before we
    3059              :          throw it away, in case it was inlined into a function that
    3060              :          hasn't been written out yet.  */
    3061      5185118 :       if (new_is_definition && DECL_INITIAL (olddecl))
    3062              :         /* The new defn must not be inline.  */
    3063           75 :         DECL_UNINLINABLE (newdecl) = 1;
    3064              :       else
    3065              :         {
    3066              :           /* If either decl says `inline', this fn is inline, unless
    3067              :              its definition was passed already.  */
    3068      5185043 :           if (DECL_DECLARED_INLINE_P (newdecl)
    3069     10178262 :               || DECL_DECLARED_INLINE_P (olddecl))
    3070       192010 :             DECL_DECLARED_INLINE_P (newdecl) = 1;
    3071              : 
    3072     15555129 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3073     10371733 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3074              : 
    3075     10370086 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3076      5185043 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3077      5185043 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3078     10369947 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3079              :         }
    3080              : 
    3081      5185118 :       if (fndecl_built_in_p (olddecl))
    3082              :         {
    3083              :           /* If redeclaring a builtin function, it stays built in.
    3084              :              But it gets tagged as having been declared.  */
    3085      4066261 :           copy_decl_built_in_function (newdecl, olddecl);
    3086      4066261 :           C_DECL_DECLARED_BUILTIN (newdecl) = 1;
    3087      4066261 :           if (new_is_prototype)
    3088              :             {
    3089      4065894 :               C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
    3090      4065894 :               if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3091              :                 {
    3092      4065894 :                   enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3093      4065894 :                   switch (fncode)
    3094              :                     {
    3095              :                       /* If a compatible prototype of these builtin functions
    3096              :                          is seen, assume the runtime implements it with the
    3097              :                          expected semantics.  */
    3098         8473 :                     case BUILT_IN_STPCPY:
    3099         8473 :                       if (builtin_decl_explicit_p (fncode))
    3100         8473 :                         set_builtin_decl_implicit_p (fncode, true);
    3101              :                       break;
    3102      4057421 :                     default:
    3103      4057421 :                       if (builtin_decl_explicit_p (fncode))
    3104      4057421 :                         set_builtin_decl_declared_p (fncode, true);
    3105              :                       break;
    3106              :                     }
    3107              : 
    3108      4065894 :                   copy_attributes_to_builtin (newdecl);
    3109              :                 }
    3110              :             }
    3111              :           else
    3112          734 :             C_DECL_BUILTIN_PROTOTYPE (newdecl)
    3113          734 :               = C_DECL_BUILTIN_PROTOTYPE (olddecl);
    3114              :         }
    3115              : 
    3116              :       /* Preserve function specific target and optimization options */
    3117      5185118 :       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3118      5185624 :           && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3119          470 :         DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3120          470 :           = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3121              : 
    3122      5185118 :       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3123      5210352 :           && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3124            9 :         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3125            9 :           = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3126              : 
    3127              :       /* Also preserve various other info from the definition.  */
    3128      5185118 :       if (!new_is_definition)
    3129              :         {
    3130      4950607 :           tree t;
    3131      4950607 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3132      4950607 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3133      4950607 :           DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3134      4950607 :           DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3135      4950607 :           DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
    3136      7762944 :           for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
    3137      2812337 :             DECL_CONTEXT (t) = newdecl;
    3138              : 
    3139              :           /* See if we've got a function to instantiate from.  */
    3140      4950607 :           if (DECL_SAVED_TREE (olddecl))
    3141         1622 :             DECL_ABSTRACT_ORIGIN (newdecl)
    3142          811 :               = DECL_ABSTRACT_ORIGIN (olddecl);
    3143              :         }
    3144              :     }
    3145              : 
    3146              :   /* Merge the USED information.  */
    3147      5250067 :   if (TREE_USED (olddecl))
    3148       718165 :     TREE_USED (newdecl) = 1;
    3149      4531902 :   else if (TREE_USED (newdecl))
    3150            4 :     TREE_USED (olddecl) = 1;
    3151      5250067 :   if (VAR_P (olddecl) || TREE_CODE (olddecl) == PARM_DECL)
    3152        18657 :     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
    3153      5250067 :   if (DECL_PRESERVE_P (olddecl))
    3154           25 :     DECL_PRESERVE_P (newdecl) = 1;
    3155      5250042 :   else if (DECL_PRESERVE_P (newdecl))
    3156            4 :     DECL_PRESERVE_P (olddecl) = 1;
    3157              : 
    3158              :   /* Merge DECL_COMMON */
    3159        18622 :   if (VAR_P (olddecl) && VAR_P (newdecl)
    3160        18622 :       && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl))
    3161      5268687 :       && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl)))
    3162        37236 :     DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl);
    3163              : 
    3164              :   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
    3165              :      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
    3166              :      DECL_ARGUMENTS (if appropriate).  */
    3167      5250067 :   {
    3168      5250067 :     unsigned olddecl_uid = DECL_UID (olddecl);
    3169      5250067 :     tree olddecl_context = DECL_CONTEXT (olddecl);
    3170      5250067 :     tree olddecl_arguments = NULL;
    3171      5250067 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3172      5185118 :       olddecl_arguments = DECL_ARGUMENTS (olddecl);
    3173              : 
    3174      5250067 :     memcpy ((char *) olddecl + sizeof (struct tree_common),
    3175              :             (char *) newdecl + sizeof (struct tree_common),
    3176              :             sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3177      5250067 :     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3178      5250067 :     switch (TREE_CODE (olddecl))
    3179              :       {
    3180      5203740 :       case FUNCTION_DECL:
    3181      5203740 :       case VAR_DECL:
    3182      5203740 :         {
    3183      5203740 :           struct symtab_node *snode = olddecl->decl_with_vis.symtab_node;
    3184              : 
    3185     10407480 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3186              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3187      5203740 :                   tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3188      5203740 :           olddecl->decl_with_vis.symtab_node = snode;
    3189              : 
    3190      5203740 :           if ((DECL_EXTERNAL (olddecl)
    3191        47396 :                || TREE_PUBLIC (olddecl)
    3192         8098 :                || TREE_STATIC (olddecl))
    3193      5251129 :               && DECL_SECTION_NAME (newdecl) != NULL)
    3194            8 :             set_decl_section_name (olddecl, newdecl);
    3195              : 
    3196              :           /* This isn't quite correct for something like
    3197              :                 int __thread x attribute ((tls_model ("local-exec")));
    3198              :                 extern int __thread x;
    3199              :              as we'll lose the "local-exec" model.  */
    3200      5203740 :           if (VAR_P (olddecl) && DECL_THREAD_LOCAL_P (newdecl))
    3201              :             {
    3202           94 :               set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3203              :               /* NEWDECL's model was chosen for NEWDECL alone, which may not
    3204              :                  have been weak until merge_weak.  */
    3205           94 :               if (DECL_WEAK (olddecl))
    3206            5 :                 weak_decl_tls_model (olddecl);
    3207              :             }
    3208              :           break;
    3209              :         }
    3210              : 
    3211        46327 :       case FIELD_DECL:
    3212        46327 :       case PARM_DECL:
    3213        46327 :       case LABEL_DECL:
    3214        46327 :       case RESULT_DECL:
    3215        46327 :       case CONST_DECL:
    3216        46327 :       case TYPE_DECL:
    3217        92654 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3218              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3219        46327 :                 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3220        46327 :         break;
    3221              : 
    3222            0 :       default:
    3223              : 
    3224            0 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3225              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3226              :                 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
    3227              :       }
    3228      5250067 :     DECL_UID (olddecl) = olddecl_uid;
    3229      5250067 :     DECL_CONTEXT (olddecl) = olddecl_context;
    3230      5250067 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3231      5185118 :       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
    3232              :   }
    3233              : 
    3234              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3235              :      so that encode_section_info has a chance to look at the new decl
    3236              :      flags and attributes.  */
    3237      5250067 :   if (DECL_RTL_SET_P (olddecl)
    3238      5250073 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3239            6 :           || (VAR_P (olddecl) && TREE_STATIC (olddecl))))
    3240            6 :     make_decl_rtl (olddecl);
    3241      5250067 : }
    3242              : 
    3243              : /* Handle when a new declaration NEWDECL has the same name as an old
    3244              :    one OLDDECL in the same binding contour.  Prints an error message
    3245              :    if appropriate.
    3246              : 
    3247              :    If safely possible, alter OLDDECL to look like NEWDECL, and return
    3248              :    true.  Otherwise, return false.  */
    3249              : 
    3250              : static bool
    3251      5251170 : duplicate_decls (tree newdecl, tree olddecl)
    3252              : {
    3253      5251170 :   tree newtype = NULL, oldtype = NULL;
    3254              : 
    3255      5251170 :   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
    3256              :     {
    3257              :       /* Avoid `unused variable' and other warnings for OLDDECL.  */
    3258         1103 :       suppress_warning (olddecl, OPT_Wunused);
    3259              :       /* If the types are completely different, poison them both with
    3260              :          error_mark_node.  */
    3261         1103 :       if (TREE_CODE (TREE_TYPE (newdecl)) != TREE_CODE (TREE_TYPE (olddecl))
    3262          108 :           && olddecl != error_mark_node
    3263         1191 :           && seen_error ())
    3264              :         {
    3265           63 :           if (TREE_CODE (olddecl) != FUNCTION_DECL)
    3266           51 :             TREE_TYPE (olddecl) = error_mark_node;
    3267           63 :           if (TREE_CODE (newdecl) != FUNCTION_DECL)
    3268           59 :             TREE_TYPE (newdecl) = error_mark_node;
    3269              :         }
    3270              :       return false;
    3271              :     }
    3272              : 
    3273      5250067 :   merge_decls (newdecl, olddecl, newtype, oldtype);
    3274              : 
    3275              :   /* The NEWDECL will no longer be needed.
    3276              : 
    3277              :      Before releasing the node, be sure to remove function from symbol
    3278              :      table that might have been inserted there to record comdat group.
    3279              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3280              :      structure is shared in between NEWDECL and OLDECL.  */
    3281      5250067 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3282      5185118 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3283      5250067 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3284              :     {
    3285      5203740 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3286      5203740 :       if (snode)
    3287          109 :         snode->remove ();
    3288              :     }
    3289      5250067 :   ggc_free (newdecl);
    3290      5250067 :   return true;
    3291              : }
    3292              : 
    3293              : 
    3294              : /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
    3295              : static void
    3296    175761085 : warn_if_shadowing (tree new_decl)
    3297              : {
    3298    175761085 :   struct c_binding *b;
    3299              : 
    3300              :   /* Shadow warnings wanted?  */
    3301    351521254 :   if (!(warn_shadow
    3302    175760349 :         || warn_shadow_local
    3303    175760169 :         || warn_shadow_compatible_local)
    3304              :       /* No shadow warnings for internally generated vars.  */
    3305    175761328 :       || DECL_IS_UNDECLARED_BUILTIN (new_decl))
    3306              :     return;
    3307              : 
    3308              :   /* Is anything being shadowed?  Invisible decls do not count.  */
    3309          253 :   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
    3310          157 :     if (b->decl && b->decl != new_decl && !b->invisible
    3311          214 :         && (b->decl == error_mark_node
    3312           43 :             || diagnostic_report_warnings_p (global_dc,
    3313              :                                              DECL_SOURCE_LOCATION (b->decl))))
    3314              :       {
    3315           57 :         tree old_decl = b->decl;
    3316              : 
    3317           57 :         if (old_decl == error_mark_node)
    3318              :           {
    3319           14 :             warning (OPT_Wshadow, "declaration of %q+D shadows previous "
    3320              :                      "non-variable", new_decl);
    3321           50 :             break;
    3322              :           }
    3323              : 
    3324           43 :         bool warned = false;
    3325           43 :         auto_diagnostic_group d;
    3326           43 :         if (TREE_CODE (old_decl) == PARM_DECL)
    3327              :           {
    3328            5 :             enum opt_code warning_code;
    3329              : 
    3330              :             /* If '-Wshadow=compatible-local' is specified without other
    3331              :                -Wshadow= flags, we will warn only when the types of the
    3332              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3333              :                (old_decl) are compatible.  */
    3334            5 :             if (warn_shadow)
    3335              :               warning_code = OPT_Wshadow;
    3336            2 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3337              :               warning_code = OPT_Wshadow_compatible_local;
    3338              :             else
    3339            2 :               warning_code = OPT_Wshadow_local;
    3340            5 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3341              :                                  "declaration of %qD shadows a parameter",
    3342              :                                  new_decl);
    3343              :           }
    3344           38 :         else if (DECL_FILE_SCOPE_P (old_decl))
    3345              :           {
    3346              :             /* Do not warn if a variable shadows a function, unless
    3347              :                the variable is a function or a pointer-to-function.  */
    3348           34 :             if (TREE_CODE (old_decl) == FUNCTION_DECL
    3349           11 :                 && TREE_CODE (new_decl) != FUNCTION_DECL
    3350           36 :                 && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
    3351            7 :                 continue;
    3352              : 
    3353           20 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
    3354              :                                  "declaration of %qD shadows a global "
    3355              :                                  "declaration",
    3356              :                                  new_decl);
    3357              :           }
    3358           11 :         else if (TREE_CODE (old_decl) == FUNCTION_DECL
    3359           11 :                  && fndecl_built_in_p (old_decl))
    3360              :           {
    3361            0 :             warning (OPT_Wshadow, "declaration of %q+D shadows "
    3362              :                      "a built-in function", new_decl);
    3363            0 :             break;
    3364              :           }
    3365              :         else
    3366              :           {
    3367           11 :             enum opt_code warning_code;
    3368              : 
    3369              :             /* If '-Wshadow=compatible-local' is specified without other
    3370              :                -Wshadow= flags, we will warn only when the types of the
    3371              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3372              :                (old_decl) are compatible.  */
    3373           11 :             if (warn_shadow)
    3374              :               warning_code = OPT_Wshadow;
    3375            8 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3376              :               warning_code = OPT_Wshadow_compatible_local;
    3377              :             else
    3378            2 :               warning_code = OPT_Wshadow_local;
    3379           11 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3380              :                                  "declaration of %qD shadows a previous local",
    3381              :                                  new_decl);
    3382              :           }
    3383              : 
    3384           36 :         if (warned)
    3385           26 :           inform (DECL_SOURCE_LOCATION (old_decl),
    3386              :                   "shadowed declaration is here");
    3387              : 
    3388              :         break;
    3389           43 :       }
    3390              : }
    3391              : 
    3392              : /* Record a decl-node X as belonging to the current lexical scope.
    3393              :    Check for errors (such as an incompatible declaration for the same
    3394              :    name already seen in the same scope).
    3395              : 
    3396              :    Returns either X or an old decl for the same name.
    3397              :    If an old decl is returned, it may have been smashed
    3398              :    to agree with what X says.  */
    3399              : 
    3400              : tree
    3401    209522078 : pushdecl (tree x)
    3402              : {
    3403    209522078 :   tree name = DECL_NAME (x);
    3404    209522078 :   struct c_scope *scope = current_scope;
    3405    209522078 :   struct c_binding *b;
    3406    209522078 :   bool nested = false;
    3407    209522078 :   location_t locus = DECL_SOURCE_LOCATION (x);
    3408              : 
    3409              :   /* Must set DECL_CONTEXT for everything not at file scope or
    3410              :      DECL_FILE_SCOPE_P won't work.  Local externs don't count
    3411              :      unless they have initializers (which generate code).  We
    3412              :      also exclude CONST_DECLs because enumerators will get the
    3413              :      type of the enum as context.  */
    3414    209522078 :   if (current_function_decl
    3415      9234169 :       && TREE_CODE (x) != CONST_DECL
    3416    218597533 :       && (!VAR_OR_FUNCTION_DECL_P (x)
    3417      8796251 :           || DECL_INITIAL (x) || !TREE_PUBLIC (x)))
    3418      9063426 :     DECL_CONTEXT (x) = current_function_decl;
    3419              : 
    3420              :   /* Anonymous decls are just inserted in the scope.  */
    3421    209522078 :   if (!name)
    3422              :     {
    3423      7997733 :       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
    3424              :             locus);
    3425      7997733 :       return x;
    3426              :     }
    3427              : 
    3428              :   /* First, see if there is another declaration with the same name in
    3429              :      the current scope.  If there is, duplicate_decls may do all the
    3430              :      work for us.  If duplicate_decls returns false, that indicates
    3431              :      two incompatible decls in the same scope; we are to silently
    3432              :      replace the old one (duplicate_decls has issued all appropriate
    3433              :      diagnostics).  In particular, we should not consider possible
    3434              :      duplicates in the external scope, or shadowing.  */
    3435    201524345 :   b = I_SYMBOL_BINDING (name);
    3436    201524345 :   if (b && B_IN_SCOPE (b, scope))
    3437              :     {
    3438      1469831 :       struct c_binding *b_ext, *b_use;
    3439      1469831 :       tree type = TREE_TYPE (x);
    3440      1469831 :       tree visdecl = b->decl;
    3441      1469831 :       tree vistype = TREE_TYPE (visdecl);
    3442      1469831 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    3443      1469831 :           && COMPLETE_TYPE_P (TREE_TYPE (x)))
    3444         1372 :         b->inner_comp = false;
    3445      1469831 :       b_use = b;
    3446      1469831 :       b_ext = b;
    3447              :       /* If this is an external linkage declaration, we should check
    3448              :          for compatibility with the type in the external scope before
    3449              :          setting the type at this scope based on the visible
    3450              :          information only.  */
    3451      1469831 :       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
    3452              :         {
    3453      2830604 :           while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    3454      1415312 :             b_ext = b_ext->shadowed;
    3455      1415292 :           if (b_ext)
    3456              :             {
    3457      1415283 :               b_use = b_ext;
    3458      1415283 :               if (b_use->u.type)
    3459       277209 :                 TREE_TYPE (b_use->decl) = b_use->u.type;
    3460              :             }
    3461              :         }
    3462              : 
    3463              :       /* Check if x is part of a FMV set with b_use.
    3464              :          FMV is only supported in c for targets with target_version
    3465              :          attributes.  */
    3466      1469831 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    3467              :           && b_use && TREE_CODE (b_use->decl) == FUNCTION_DECL
    3468              :           && TREE_CODE (x) == FUNCTION_DECL && DECL_FILE_SCOPE_P (b_use->decl)
    3469              :           && DECL_FILE_SCOPE_P (x)
    3470              :           && disjoint_version_decls (x, b_use->decl)
    3471              :           && comptypes (vistype, type))
    3472              :         {
    3473              :           maybe_mark_function_versioned (b_use->decl);
    3474              :           maybe_mark_function_versioned (b->decl);
    3475              :           maybe_mark_function_versioned (x);
    3476              : 
    3477              :           cgraph_node *b_node = cgraph_node::get_create (b_use->decl);
    3478              :           cgraph_function_version_info *b_v = b_node->function_version ();
    3479              :           if (!b_v)
    3480              :             b_v = b_node->insert_new_function_version ();
    3481              : 
    3482              :           /* Check if this new node conflicts with any previous functions
    3483              :              in the set.  */
    3484              :           cgraph_function_version_info *version = b_v;
    3485              :           for (; version; version = version->next)
    3486              :             if (!disjoint_version_decls (version->this_node->decl, x))
    3487              :               {
    3488              :                 /* The decls define overlapping version, so attempt to merge
    3489              :                    or diagnose the conflict.  */
    3490              :                 if (duplicate_decls (x, version->this_node->decl))
    3491              :                   return version->this_node->decl;
    3492              :                 else
    3493              :                   return error_mark_node;
    3494              :               }
    3495              : 
    3496              :           /* This is a new version to be added to FMV structure.  */
    3497              :           cgraph_node::add_function_version (b_v, x);
    3498              : 
    3499              :           /* Get the first node from the structure.  */
    3500              :           cgraph_function_version_info *default_v = b_v;
    3501              :           while (default_v->prev)
    3502              :             default_v = default_v->prev;
    3503              :           /* Always use the default node for the bindings.  */
    3504              :           b_use->decl = default_v->this_node->decl;
    3505              :           b->decl = default_v->this_node->decl;
    3506              : 
    3507              :           /* Node is not a duplicate, so no need to do the rest of the
    3508              :              checks.  */
    3509              :           return x;
    3510              :         }
    3511              : 
    3512      1469831 :       if (duplicate_decls (x, b_use->decl))
    3513              :         {
    3514      1469455 :           if (b_use != b)
    3515              :             {
    3516              :               /* Save the updated type in the external scope and
    3517              :                  restore the proper type for this scope.  */
    3518      1415077 :               tree thistype;
    3519      1415077 :               if (comptypes (vistype, type))
    3520      1415035 :                 thistype = composite_type (vistype, type);
    3521              :               else
    3522           42 :                 thistype = TREE_TYPE (b_use->decl);
    3523      1415077 :               b_use->u.type = TREE_TYPE (b_use->decl);
    3524      1415077 :               if (TREE_CODE (b_use->decl) == FUNCTION_DECL
    3525      1415077 :                   && fndecl_built_in_p (b_use->decl))
    3526       287386 :                 thistype
    3527       287386 :                   = c_build_type_attribute_variant (thistype,
    3528       287386 :                                                     TYPE_ATTRIBUTES
    3529              :                                                     (b_use->u.type));
    3530      1415077 :               TREE_TYPE (b_use->decl) = thistype;
    3531              :             }
    3532      1469455 :           return b_use->decl;
    3533              :         }
    3534              :       else
    3535          376 :         goto skip_external_and_shadow_checks;
    3536              :     }
    3537              : 
    3538              :   /* All declarations with external linkage, and all external
    3539              :      references, go in the external scope, no matter what scope is
    3540              :      current.  However, the binding in that scope is ignored for
    3541              :      purposes of normal name lookup.  A separate binding structure is
    3542              :      created in the requested scope; this governs the normal
    3543              :      visibility of the symbol.
    3544              : 
    3545              :      The binding in the externals scope is used exclusively for
    3546              :      detecting duplicate declarations of the same object, no matter
    3547              :      what scope they are in; this is what we do here.  (C99 6.2.7p2:
    3548              :      All declarations that refer to the same object or function shall
    3549              :      have compatible type; otherwise, the behavior is undefined.)
    3550              :      However, in Objective-C, we also want to detect declarations
    3551              :      conflicting with those of the basic types.  */
    3552    349183826 :   if ((DECL_EXTERNAL (x) || scope == file_scope)
    3553    211729877 :       && (VAR_OR_FUNCTION_DECL_P (x) || c_dialect_objc ()))
    3554              :     {
    3555     52739323 :       tree type = TREE_TYPE (x);
    3556     52739323 :       tree vistype = NULL_TREE;
    3557     52739323 :       tree visdecl = NULL_TREE;
    3558     52739323 :       bool type_saved = false;
    3559      3781366 :       if (b && !B_IN_EXTERNAL_SCOPE (b)
    3560         1038 :           && VAR_OR_FUNCTION_DECL_P (b->decl)
    3561     52740352 :           && DECL_FILE_SCOPE_P (b->decl))
    3562              :         {
    3563          803 :           visdecl = b->decl;
    3564          803 :           vistype = TREE_TYPE (visdecl);
    3565              :         }
    3566     52739323 :       if (scope != file_scope
    3567     52739323 :           && !DECL_IN_SYSTEM_HEADER (x))
    3568        11479 :         warning_at (locus, OPT_Wnested_externs,
    3569              :                     "nested extern declaration of %qD", x);
    3570              : 
    3571     52740747 :       while (b && !B_IN_EXTERNAL_SCOPE (b))
    3572              :         {
    3573              :           /* If this decl might be modified, save its type.  This is
    3574              :              done here rather than when the decl is first bound
    3575              :              because the type may change after first binding, through
    3576              :              being completed or through attributes being added.  If we
    3577              :              encounter multiple such decls, only the first should have
    3578              :              its type saved; the others will already have had their
    3579              :              proper types saved and the types will not have changed as
    3580              :              their scopes will not have been re-entered.  */
    3581         1424 :           if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
    3582              :             {
    3583         1022 :               b->u.type = TREE_TYPE (b->decl);
    3584         1022 :               type_saved = true;
    3585              :             }
    3586         1424 :           if (B_IN_FILE_SCOPE (b)
    3587         1012 :               && VAR_P (b->decl)
    3588          572 :               && TREE_STATIC (b->decl)
    3589          281 :               && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
    3590          138 :               && !TYPE_DOMAIN (TREE_TYPE (b->decl))
    3591           47 :               && TREE_CODE (type) == ARRAY_TYPE
    3592           47 :               && TYPE_DOMAIN (type)
    3593           28 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    3594         1452 :               && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
    3595              :             {
    3596              :               /* Array type completed in inner scope, which should be
    3597              :                  diagnosed if the completion does not have size 1 and
    3598              :                  it does not get completed in the file scope.  */
    3599            6 :               b->inner_comp = true;
    3600              :             }
    3601         1424 :           b = b->shadowed;
    3602              :         }
    3603              : 
    3604              :       /* If a matching external declaration has been found, set its
    3605              :          type to the composite of all the types of that declaration.
    3606              :          After the consistency checks, it will be reset to the
    3607              :          composite of the visible types only.  */
    3608     52739323 :       if (b && b->u.type)
    3609          768 :         TREE_TYPE (b->decl) = b->u.type;
    3610              : 
    3611              :       /* the static does not go in the externals scope.  */
    3612      3781222 :       if (b && duplicate_decls (x, b->decl))
    3613              :         {
    3614      3780495 :           tree thistype;
    3615      3780495 :           if (vistype)
    3616              :             {
    3617          675 :               if (comptypes (vistype, type))
    3618          638 :                 thistype = composite_type (vistype, type);
    3619              :               else
    3620           37 :                 thistype = TREE_TYPE (b->decl);
    3621              :             }
    3622              :           else
    3623              :             thistype = type;
    3624      3780495 :           b->u.type = TREE_TYPE (b->decl);
    3625              :           /* Propagate the type attributes to the decl.  */
    3626      3780495 :           thistype
    3627      3780495 :             = c_build_type_attribute_variant (thistype,
    3628      3780495 :                                               TYPE_ATTRIBUTES (b->u.type));
    3629      3780495 :           TREE_TYPE (b->decl) = thistype;
    3630      3780495 :           bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
    3631              :                 locus);
    3632      3780495 :           return b->decl;
    3633              :         }
    3634     48958828 :       else if (TREE_PUBLIC (x))
    3635              :         {
    3636     48576878 :           if (visdecl && !b && duplicate_decls (x, visdecl))
    3637              :             {
    3638              :               /* An external declaration at block scope referring to a
    3639              :                  visible entity with internal linkage.  The composite
    3640              :                  type will already be correct for this scope, so we
    3641              :                  just need to fall through to make the declaration in
    3642              :                  this scope.  */
    3643              :               nested = true;
    3644              :               x = visdecl;
    3645              :             }
    3646              :           else
    3647              :             {
    3648     48576761 :               bind (name, x, external_scope, /*invisible=*/true,
    3649              :                     /*nested=*/false, locus);
    3650     48576761 :               nested = true;
    3651              :             }
    3652              :         }
    3653              :     }
    3654              : 
    3655    196274019 :   if (TREE_CODE (x) != PARM_DECL)
    3656     72550633 :     warn_if_shadowing (x);
    3657              : 
    3658    123723386 :  skip_external_and_shadow_checks:
    3659    196274395 :   if (TREE_CODE (x) == TYPE_DECL)
    3660              :     {
    3661              :       /* So this is a typedef, set its underlying type.  */
    3662      9918281 :       set_underlying_type (x);
    3663              : 
    3664              :       /* If X is a typedef defined in the current function, record it
    3665              :          for the purpose of implementing the -Wunused-local-typedefs
    3666              :          warning.  */
    3667      9918281 :       record_locally_defined_typedef (x);
    3668              :     }
    3669              : 
    3670    196274395 :   bind (name, x, scope, /*invisible=*/false, nested, locus);
    3671              : 
    3672              :   /* If x's type is incomplete because it's based on a
    3673              :      structure or union which has not yet been fully declared,
    3674              :      attach it to that structure or union type, so we can go
    3675              :      back and complete the variable declaration later, if the
    3676              :      structure or union gets fully declared.
    3677              : 
    3678              :      If the input is erroneous, we can have error_mark in the type
    3679              :      slot (e.g. "f(void a, ...)") - that doesn't count as an
    3680              :      incomplete type.  */
    3681    196274395 :   if (TREE_TYPE (x) != error_mark_node
    3682    196274395 :       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
    3683              :     {
    3684       188219 :       tree element = TREE_TYPE (x);
    3685              : 
    3686       208894 :       while (TREE_CODE (element) == ARRAY_TYPE)
    3687        20675 :         element = TREE_TYPE (element);
    3688       188219 :       element = TYPE_MAIN_VARIANT (element);
    3689              : 
    3690       188219 :       if ((RECORD_OR_UNION_TYPE_P (element)
    3691       143921 :            || TREE_CODE (element) == ENUMERAL_TYPE)
    3692        44369 :           && (TREE_CODE (x) != TYPE_DECL
    3693        40891 :               || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    3694       191707 :           && !COMPLETE_TYPE_P (element))
    3695          321 :         C_TYPE_INCOMPLETE_VARS (element)
    3696          642 :           = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
    3697              :     }
    3698              :   return x;
    3699              : }
    3700              : 
    3701              : 
    3702              : /* Issue a permerror about implicit function declaration.  ID is the function
    3703              :    identifier, OLDDECL is a declaration of the function in a different scope,
    3704              :    or NULL_TREE.  */
    3705              : 
    3706              : static void
    3707         3777 : implicit_decl_permerror (location_t loc, tree id, tree olddecl)
    3708              : {
    3709         3777 :   if (!warn_implicit_function_declaration)
    3710         2617 :     return;
    3711              : 
    3712         1160 :   bool warned;
    3713         1160 :   auto_diagnostic_group d;
    3714         1160 :   name_hint hint;
    3715         1160 :   if (!olddecl)
    3716          554 :     hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc);
    3717              : 
    3718         1160 :   if (flag_isoc99)
    3719              :     {
    3720         1154 :       if (const char *suggestion = hint.suggestion ())
    3721              :         {
    3722          107 :           gcc_rich_location richloc (loc);
    3723          107 :           richloc.add_fixit_replace (suggestion);
    3724          107 :           warned = permerror_opt (&richloc, OPT_Wimplicit_function_declaration,
    3725              :                                   "implicit declaration of function %qE;"
    3726              :                                   " did you mean %qs?",
    3727              :                                   id, suggestion);
    3728          107 :         }
    3729              :       else
    3730         1047 :         warned = permerror_opt (loc, OPT_Wimplicit_function_declaration,
    3731              :                                 "implicit declaration of function %qE", id);
    3732              :     }
    3733            6 :   else if (const char *suggestion = hint.suggestion ())
    3734              :     {
    3735            2 :       gcc_rich_location richloc (loc);
    3736            2 :       richloc.add_fixit_replace (suggestion);
    3737            2 :       warned = warning_at
    3738            2 :         (&richloc, OPT_Wimplicit_function_declaration,
    3739              :          G_("implicit declaration of function %qE; did you mean %qs?"),
    3740              :          id, suggestion);
    3741            2 :     }
    3742              :   else
    3743            4 :     warned = warning_at (loc, OPT_Wimplicit_function_declaration,
    3744              :                          G_("implicit declaration of function %qE"), id);
    3745              : 
    3746         1160 :   if (warned)
    3747              :     {
    3748              :       /* Whether the olddecl is an undeclared builtin function.
    3749              :          locate_old_decl will not generate a diagnostic for those,
    3750              :          so in that case we want to look elsewhere.  */
    3751           91 :       bool undeclared_builtin = (olddecl
    3752           28 :                                  && TREE_CODE (olddecl) == FUNCTION_DECL
    3753           28 :                                  && fndecl_built_in_p (olddecl)
    3754          118 :                                  && !C_DECL_DECLARED_BUILTIN (olddecl));
    3755           91 :       if (undeclared_builtin)
    3756              :         {
    3757           27 :           const char *header = header_for_builtin_fn (olddecl);
    3758           27 :           if (header)
    3759              :             {
    3760           20 :               rich_location richloc (line_table, loc);
    3761           20 :               maybe_add_include_fixit (&richloc, header, true);
    3762           20 :               inform (&richloc,
    3763              :                       "include %qs or provide a declaration of %qE",
    3764              :                       header, id);
    3765           20 :             }
    3766              :         }
    3767           64 :       else if (olddecl)
    3768            1 :         locate_old_decl (olddecl);
    3769              :     }
    3770              : 
    3771              :   if (!warned)
    3772         1160 :     hint.suppress ();
    3773         1160 : }
    3774              : 
    3775              : /* Return the name of the header file that declares built-in function
    3776              :    FNDECL, or null if either we don't know or don't expect to see an
    3777              :    explicit declaration.  */
    3778              : 
    3779              : static const char *
    3780         3171 : header_for_builtin_fn (tree fndecl)
    3781              : {
    3782         3171 :   if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
    3783              :     return NULL;
    3784              : 
    3785         3171 :   switch (DECL_FUNCTION_CODE (fndecl))
    3786              :     {
    3787              :     CASE_FLT_FN (BUILT_IN_ACOS):
    3788              :     CASE_FLT_FN (BUILT_IN_ACOSH):
    3789              :     CASE_FLT_FN (BUILT_IN_ASIN):
    3790              :     CASE_FLT_FN (BUILT_IN_ASINH):
    3791              :     CASE_FLT_FN (BUILT_IN_ATAN):
    3792              :     CASE_FLT_FN (BUILT_IN_ATANH):
    3793              :     CASE_FLT_FN (BUILT_IN_ATAN2):
    3794              :     CASE_FLT_FN (BUILT_IN_CBRT):
    3795              :     CASE_FLT_FN (BUILT_IN_CEIL):
    3796              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
    3797              :     CASE_FLT_FN (BUILT_IN_COPYSIGN):
    3798              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
    3799              :     CASE_FLT_FN (BUILT_IN_COS):
    3800              :     CASE_FLT_FN (BUILT_IN_COSH):
    3801              :     CASE_FLT_FN (BUILT_IN_ERF):
    3802              :     CASE_FLT_FN (BUILT_IN_ERFC):
    3803              :     CASE_FLT_FN (BUILT_IN_EXP):
    3804              :     CASE_FLT_FN (BUILT_IN_EXP2):
    3805              :     CASE_FLT_FN (BUILT_IN_EXPM1):
    3806              :     CASE_FLT_FN (BUILT_IN_FABS):
    3807              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
    3808              :     CASE_FLT_FN (BUILT_IN_FDIM):
    3809              :     CASE_FLT_FN (BUILT_IN_FLOOR):
    3810              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
    3811              :     CASE_FLT_FN (BUILT_IN_FMA):
    3812              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
    3813              :     CASE_FLT_FN (BUILT_IN_FMAX):
    3814              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
    3815              :     CASE_FLT_FN (BUILT_IN_FMIN):
    3816              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
    3817              :     CASE_FLT_FN (BUILT_IN_FMOD):
    3818              :     CASE_FLT_FN (BUILT_IN_FREXP):
    3819              :     CASE_FLT_FN (BUILT_IN_HYPOT):
    3820              :     CASE_FLT_FN (BUILT_IN_ILOGB):
    3821              :     CASE_FLT_FN (BUILT_IN_LDEXP):
    3822              :     CASE_FLT_FN (BUILT_IN_LGAMMA):
    3823              :     CASE_FLT_FN (BUILT_IN_LLRINT):
    3824              :     CASE_FLT_FN (BUILT_IN_LLROUND):
    3825              :     CASE_FLT_FN (BUILT_IN_LOG):
    3826              :     CASE_FLT_FN (BUILT_IN_LOG10):
    3827              :     CASE_FLT_FN (BUILT_IN_LOG1P):
    3828              :     CASE_FLT_FN (BUILT_IN_LOG2):
    3829              :     CASE_FLT_FN (BUILT_IN_LOGB):
    3830              :     CASE_FLT_FN (BUILT_IN_LRINT):
    3831              :     CASE_FLT_FN (BUILT_IN_LROUND):
    3832              :     CASE_FLT_FN (BUILT_IN_MODF):
    3833              :     CASE_FLT_FN (BUILT_IN_NAN):
    3834              :     CASE_FLT_FN (BUILT_IN_NEARBYINT):
    3835              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
    3836              :     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
    3837              :     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
    3838              :     CASE_FLT_FN (BUILT_IN_POW):
    3839              :     CASE_FLT_FN (BUILT_IN_REMAINDER):
    3840              :     CASE_FLT_FN (BUILT_IN_REMQUO):
    3841              :     CASE_FLT_FN (BUILT_IN_RINT):
    3842              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
    3843              :     CASE_FLT_FN (BUILT_IN_ROUND):
    3844              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
    3845              :     CASE_FLT_FN (BUILT_IN_SCALBLN):
    3846              :     CASE_FLT_FN (BUILT_IN_SCALBN):
    3847              :     CASE_FLT_FN (BUILT_IN_SIN):
    3848              :     CASE_FLT_FN (BUILT_IN_SINH):
    3849              :     CASE_FLT_FN (BUILT_IN_SINCOS):
    3850              :     CASE_FLT_FN (BUILT_IN_SQRT):
    3851              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
    3852              :     CASE_FLT_FN (BUILT_IN_TAN):
    3853              :     CASE_FLT_FN (BUILT_IN_TANH):
    3854              :     CASE_FLT_FN (BUILT_IN_TGAMMA):
    3855              :     CASE_FLT_FN (BUILT_IN_TRUNC):
    3856              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
    3857              :     case BUILT_IN_ISINF:
    3858              :     case BUILT_IN_ISNAN:
    3859              :       return "<math.h>";
    3860           29 :     CASE_FLT_FN (BUILT_IN_CABS):
    3861           29 :     CASE_FLT_FN (BUILT_IN_CACOS):
    3862           29 :     CASE_FLT_FN (BUILT_IN_CACOSH):
    3863           29 :     CASE_FLT_FN (BUILT_IN_CARG):
    3864           29 :     CASE_FLT_FN (BUILT_IN_CASIN):
    3865           29 :     CASE_FLT_FN (BUILT_IN_CASINH):
    3866           29 :     CASE_FLT_FN (BUILT_IN_CATAN):
    3867           29 :     CASE_FLT_FN (BUILT_IN_CATANH):
    3868           29 :     CASE_FLT_FN (BUILT_IN_CCOS):
    3869           29 :     CASE_FLT_FN (BUILT_IN_CCOSH):
    3870           29 :     CASE_FLT_FN (BUILT_IN_CEXP):
    3871           29 :     CASE_FLT_FN (BUILT_IN_CIMAG):
    3872           29 :     CASE_FLT_FN (BUILT_IN_CLOG):
    3873           29 :     CASE_FLT_FN (BUILT_IN_CONJ):
    3874           29 :     CASE_FLT_FN (BUILT_IN_CPOW):
    3875           29 :     CASE_FLT_FN (BUILT_IN_CPROJ):
    3876           29 :     CASE_FLT_FN (BUILT_IN_CREAL):
    3877           29 :     CASE_FLT_FN (BUILT_IN_CSIN):
    3878           29 :     CASE_FLT_FN (BUILT_IN_CSINH):
    3879           29 :     CASE_FLT_FN (BUILT_IN_CSQRT):
    3880           29 :     CASE_FLT_FN (BUILT_IN_CTAN):
    3881           29 :     CASE_FLT_FN (BUILT_IN_CTANH):
    3882           29 :       return "<complex.h>";
    3883          222 :     case BUILT_IN_MEMCHR:
    3884          222 :     case BUILT_IN_MEMCMP:
    3885          222 :     case BUILT_IN_MEMCPY:
    3886          222 :     case BUILT_IN_MEMMOVE:
    3887          222 :     case BUILT_IN_MEMSET:
    3888          222 :     case BUILT_IN_STRCAT:
    3889          222 :     case BUILT_IN_STRCHR:
    3890          222 :     case BUILT_IN_STRCMP:
    3891          222 :     case BUILT_IN_STRCPY:
    3892          222 :     case BUILT_IN_STRCSPN:
    3893          222 :     case BUILT_IN_STRLEN:
    3894          222 :     case BUILT_IN_STRNCAT:
    3895          222 :     case BUILT_IN_STRNCMP:
    3896          222 :     case BUILT_IN_STRNCPY:
    3897          222 :     case BUILT_IN_STRPBRK:
    3898          222 :     case BUILT_IN_STRRCHR:
    3899          222 :     case BUILT_IN_STRSPN:
    3900          222 :     case BUILT_IN_STRSTR:
    3901          222 :       return "<string.h>";
    3902          544 :     case BUILT_IN_FPRINTF:
    3903          544 :     case BUILT_IN_PUTC:
    3904          544 :     case BUILT_IN_FPUTC:
    3905          544 :     case BUILT_IN_FPUTS:
    3906          544 :     case BUILT_IN_FSCANF:
    3907          544 :     case BUILT_IN_FWRITE:
    3908          544 :     case BUILT_IN_PRINTF:
    3909          544 :     case BUILT_IN_PUTCHAR:
    3910          544 :     case BUILT_IN_PUTS:
    3911          544 :     case BUILT_IN_SCANF:
    3912          544 :     case BUILT_IN_SNPRINTF:
    3913          544 :     case BUILT_IN_SPRINTF:
    3914          544 :     case BUILT_IN_SSCANF:
    3915          544 :     case BUILT_IN_VFPRINTF:
    3916          544 :     case BUILT_IN_VFSCANF:
    3917          544 :     case BUILT_IN_VPRINTF:
    3918          544 :     case BUILT_IN_VSCANF:
    3919          544 :     case BUILT_IN_VSNPRINTF:
    3920          544 :     case BUILT_IN_VSPRINTF:
    3921          544 :     case BUILT_IN_VSSCANF:
    3922          544 :       return "<stdio.h>";
    3923            2 :     case BUILT_IN_ISALNUM:
    3924            2 :     case BUILT_IN_ISALPHA:
    3925            2 :     case BUILT_IN_ISBLANK:
    3926            2 :     case BUILT_IN_ISCNTRL:
    3927            2 :     case BUILT_IN_ISDIGIT:
    3928            2 :     case BUILT_IN_ISGRAPH:
    3929            2 :     case BUILT_IN_ISLOWER:
    3930            2 :     case BUILT_IN_ISPRINT:
    3931            2 :     case BUILT_IN_ISPUNCT:
    3932            2 :     case BUILT_IN_ISSPACE:
    3933            2 :     case BUILT_IN_ISUPPER:
    3934            2 :     case BUILT_IN_ISXDIGIT:
    3935            2 :     case BUILT_IN_TOLOWER:
    3936            2 :     case BUILT_IN_TOUPPER:
    3937            2 :       return "<ctype.h>";
    3938            0 :     case BUILT_IN_ISWALNUM:
    3939            0 :     case BUILT_IN_ISWALPHA:
    3940            0 :     case BUILT_IN_ISWBLANK:
    3941            0 :     case BUILT_IN_ISWCNTRL:
    3942            0 :     case BUILT_IN_ISWDIGIT:
    3943            0 :     case BUILT_IN_ISWGRAPH:
    3944            0 :     case BUILT_IN_ISWLOWER:
    3945            0 :     case BUILT_IN_ISWPRINT:
    3946            0 :     case BUILT_IN_ISWPUNCT:
    3947            0 :     case BUILT_IN_ISWSPACE:
    3948            0 :     case BUILT_IN_ISWUPPER:
    3949            0 :     case BUILT_IN_ISWXDIGIT:
    3950            0 :     case BUILT_IN_TOWLOWER:
    3951            0 :     case BUILT_IN_TOWUPPER:
    3952            0 :       return "<wctype.h>";
    3953         1818 :     case BUILT_IN_ABORT:
    3954         1818 :     case BUILT_IN_ABS:
    3955         1818 :     case BUILT_IN_CALLOC:
    3956         1818 :     case BUILT_IN_EXIT:
    3957         1818 :     case BUILT_IN_FREE:
    3958         1818 :     case BUILT_IN_LABS:
    3959         1818 :     case BUILT_IN_LLABS:
    3960         1818 :     case BUILT_IN_MALLOC:
    3961         1818 :     case BUILT_IN_REALLOC:
    3962         1818 :     case BUILT_IN__EXIT2:
    3963         1818 :     case BUILT_IN_ALIGNED_ALLOC:
    3964         1818 :       return "<stdlib.h>";
    3965            1 :     case BUILT_IN_IMAXABS:
    3966            1 :       return "<inttypes.h>";
    3967            3 :     case BUILT_IN_STRFTIME:
    3968            3 :       return "<time.h>";
    3969              :     default:
    3970              :       return NULL;
    3971              :     }
    3972              : }
    3973              : 
    3974              : /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
    3975              :    function of type int ().  */
    3976              : 
    3977              : tree
    3978         4730 : implicitly_declare (location_t loc, tree functionid)
    3979              : {
    3980         4730 :   struct c_binding *b;
    3981         4730 :   tree decl = NULL_TREE;
    3982         4730 :   tree asmspec_tree;
    3983              : 
    3984         4744 :   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
    3985              :     {
    3986         3158 :       if (B_IN_SCOPE (b, external_scope))
    3987              :         {
    3988         3144 :           decl = b->decl;
    3989         3144 :           break;
    3990              :         }
    3991              :     }
    3992              : 
    3993         4730 :   if (decl)
    3994              :     {
    3995         3144 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    3996              :         return decl;
    3997              : 
    3998              :       /* FIXME: Objective-C has weird not-really-builtin functions
    3999              :          which are supposed to be visible automatically.  They wind up
    4000              :          in the external scope because they're pushed before the file
    4001              :          scope gets created.  Catch this here and rebind them into the
    4002              :          file scope.  */
    4003         3137 :       if (!fndecl_built_in_p (decl) && DECL_IS_UNDECLARED_BUILTIN (decl))
    4004              :         {
    4005            0 :           bind (functionid, decl, file_scope,
    4006              :                 /*invisible=*/false, /*nested=*/true,
    4007            0 :                 DECL_SOURCE_LOCATION (decl));
    4008            0 :           return decl;
    4009              :         }
    4010              :       else
    4011              :         {
    4012         3137 :           tree newtype = default_function_type;
    4013         3137 :           if (b->u.type)
    4014          753 :             TREE_TYPE (decl) = b->u.type;
    4015              :           /* Implicit declaration of a function already declared
    4016              :              (somehow) in a different scope, or as a built-in.
    4017              :              If this is the first time this has happened, warn;
    4018              :              then recycle the old declaration but with the new type.  */
    4019         3137 :           if (!C_DECL_IMPLICIT (decl))
    4020              :             {
    4021         2191 :               implicit_decl_permerror (loc, functionid, decl);
    4022         2191 :               C_DECL_IMPLICIT (decl) = 1;
    4023              :             }
    4024         3137 :           if (fndecl_built_in_p (decl))
    4025              :             {
    4026         2705 :               newtype = c_build_type_attribute_variant (newtype,
    4027         2705 :                                                         TYPE_ATTRIBUTES
    4028              :                                                         (TREE_TYPE (decl)));
    4029         2705 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4030              :                 {
    4031         2528 :                   auto_diagnostic_group d;
    4032         2528 :                   bool warned = warning_at (loc,
    4033         2528 :                                             OPT_Wbuiltin_declaration_mismatch,
    4034              :                                             "incompatible implicit "
    4035              :                                             "declaration of built-in "
    4036              :                                             "function %qD", decl);
    4037              :                   /* See if we can hint which header to include.  */
    4038         2528 :                   const char *header = header_for_builtin_fn (decl);
    4039         2528 :                   if (header != NULL && warned)
    4040              :                     {
    4041          133 :                       rich_location richloc (line_table, loc);
    4042          133 :                       maybe_add_include_fixit (&richloc, header, true);
    4043          133 :                       inform (&richloc,
    4044              :                               "include %qs or provide a declaration of %qD",
    4045              :                               header, decl);
    4046          133 :                     }
    4047         2528 :                   newtype = TREE_TYPE (decl);
    4048         2528 :                 }
    4049              :             }
    4050              :           else
    4051              :             {
    4052          432 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4053              :                 {
    4054            2 :                   auto_diagnostic_group d;
    4055            2 :                   error_at (loc, "incompatible implicit declaration of "
    4056              :                             "function %qD", decl);
    4057            2 :                   locate_old_decl (decl);
    4058            2 :                 }
    4059              :             }
    4060         3137 :           b->u.type = TREE_TYPE (decl);
    4061         3137 :           TREE_TYPE (decl) = newtype;
    4062         3137 :           bind (functionid, decl, current_scope,
    4063              :                 /*invisible=*/false, /*nested=*/true,
    4064         3137 :                 DECL_SOURCE_LOCATION (decl));
    4065         3137 :           return decl;
    4066              :         }
    4067              :     }
    4068              : 
    4069              :   /* Not seen before.  */
    4070         1586 :   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
    4071         1586 :   DECL_EXTERNAL (decl) = 1;
    4072         1586 :   TREE_PUBLIC (decl) = 1;
    4073         1586 :   C_DECL_IMPLICIT (decl) = 1;
    4074         1586 :   implicit_decl_permerror (loc, functionid, 0);
    4075         1586 :   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
    4076         1586 :   if (asmspec_tree)
    4077            1 :     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
    4078              : 
    4079              :   /* C89 says implicit declarations are in the innermost block.
    4080              :      So we record the decl in the standard fashion.  */
    4081         1586 :   decl = pushdecl (decl);
    4082              : 
    4083              :   /* No need to call objc_check_decl here - it's a function type.  */
    4084         1586 :   rest_of_decl_compilation (decl, 0, 0);
    4085              : 
    4086              :   /* Write a record describing this implicit function declaration
    4087              :      to the prototypes file (if requested).  */
    4088         1586 :   gen_aux_info_record (decl, 0, 1, 0);
    4089              : 
    4090              :   /* Possibly apply some default attributes to this implicit declaration.  */
    4091         1586 :   decl_attributes (&decl, NULL_TREE, 0);
    4092              : 
    4093         1586 :   return decl;
    4094              : }
    4095              : 
    4096              : /* Issue an error message for a reference to an undeclared variable
    4097              :    ID, including a reference to a builtin outside of function-call
    4098              :    context.  Establish a binding of the identifier to error_mark_node
    4099              :    in an appropriate scope, which will suppress further errors for the
    4100              :    same identifier.  The error message should be given location LOC.  */
    4101              : void
    4102         1262 : undeclared_variable (location_t loc, tree id)
    4103              : {
    4104         1262 :   static bool already = false;
    4105         1262 :   struct c_scope *scope;
    4106              : 
    4107         1262 :   auto_diagnostic_group d;
    4108         1262 :   if (current_function_decl == NULL_TREE)
    4109              :     {
    4110          436 :       name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4111          436 :       if (const char *suggestion = guessed_id.suggestion ())
    4112              :         {
    4113           86 :           gcc_rich_location richloc (loc);
    4114           86 :           richloc.add_fixit_replace (suggestion);
    4115           86 :           error_at (&richloc,
    4116              :                     "%qE undeclared here (not in a function);"
    4117              :                     " did you mean %qs?",
    4118              :                     id, suggestion);
    4119           86 :         }
    4120              :       else
    4121          350 :         error_at (loc, "%qE undeclared here (not in a function)", id);
    4122          436 :       scope = current_scope;
    4123          436 :     }
    4124              :   else
    4125              :     {
    4126          826 :       if (!objc_diagnose_private_ivar (id))
    4127              :         {
    4128          826 :           name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4129          826 :           if (const char *suggestion = guessed_id.suggestion ())
    4130              :             {
    4131           39 :               gcc_rich_location richloc (loc);
    4132           39 :               richloc.add_fixit_replace (suggestion);
    4133           39 :               error_at (&richloc,
    4134              :                         "%qE undeclared (first use in this function);"
    4135              :                         " did you mean %qs?",
    4136              :                         id, suggestion);
    4137           39 :             }
    4138              :           else
    4139          787 :             error_at (loc, "%qE undeclared (first use in this function)", id);
    4140          826 :         }
    4141          826 :       if (!already)
    4142              :         {
    4143          203 :           inform (loc, "each undeclared identifier is reported only"
    4144              :                   " once for each function it appears in");
    4145          203 :           already = true;
    4146              :         }
    4147              : 
    4148              :       /* If we are parsing old-style parameter decls, current_function_decl
    4149              :          will be nonnull but current_function_scope will be null.  */
    4150          826 :       scope = current_function_scope ? current_function_scope : current_scope;
    4151              :     }
    4152         1262 :   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
    4153              :         UNKNOWN_LOCATION);
    4154         1262 : }
    4155              : 
    4156              : /* Subroutine of lookup_label, declare_label, define_label: construct a
    4157              :    LABEL_DECL with all the proper frills.  Also create a struct
    4158              :    c_label_vars initialized for the current scope.  */
    4159              : 
    4160              : static tree
    4161        24814 : make_label (location_t location, tree name, bool defining,
    4162              :             struct c_label_vars **p_label_vars)
    4163              : {
    4164        24814 :   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
    4165        24814 :   DECL_CONTEXT (label) = current_function_decl;
    4166        24814 :   SET_DECL_MODE (label, VOIDmode);
    4167              : 
    4168        24814 :   c_label_vars *label_vars = ggc_alloc<c_label_vars> ();
    4169        24814 :   label_vars->shadowed = NULL;
    4170        24814 :   set_spot_bindings (&label_vars->label_bindings, defining);
    4171        24814 :   label_vars->decls_in_scope = make_tree_vector ();
    4172        24814 :   label_vars->gotos = NULL;
    4173        24814 :   *p_label_vars = label_vars;
    4174              : 
    4175        24814 :   return label;
    4176              : }
    4177              : 
    4178              : /* Get the LABEL_DECL corresponding to identifier NAME as a label.
    4179              :    Create one if none exists so far for the current function.
    4180              :    This is called when a label is used in a goto expression or
    4181              :    has its address taken.  */
    4182              : 
    4183              : tree
    4184        86566 : lookup_label (tree name)
    4185              : {
    4186        86566 :   tree label;
    4187        86566 :   struct c_label_vars *label_vars;
    4188              : 
    4189        86566 :   if (current_function_scope == 0)
    4190              :     {
    4191            2 :       error ("label %qE referenced outside of any function", name);
    4192            2 :       return NULL_TREE;
    4193              :     }
    4194              : 
    4195              :   /* Use a label already defined or ref'd with this name, but not if
    4196              :      it is inherited from a containing function and wasn't declared
    4197              :      using __label__.  */
    4198        86564 :   label = I_LABEL_DECL (name);
    4199        80076 :   if (label && (DECL_CONTEXT (label) == current_function_decl
    4200          626 :                 || C_DECLARED_LABEL_FLAG (label)))
    4201              :     {
    4202              :       /* If the label has only been declared, update its apparent
    4203              :          location to point here, for better diagnostics if it
    4204              :          turns out not to have been defined.  */
    4205        80069 :       if (DECL_INITIAL (label) == NULL_TREE)
    4206        62946 :         DECL_SOURCE_LOCATION (label) = input_location;
    4207              :       return label;
    4208              :     }
    4209              : 
    4210              :   /* No label binding for that identifier; make one.  */
    4211         6495 :   label = make_label (input_location, name, false, &label_vars);
    4212              : 
    4213              :   /* Ordinary labels go in the current function scope.  */
    4214         6495 :   bind_label (name, label, current_function_scope, label_vars);
    4215              : 
    4216         6495 :   return label;
    4217              : }
    4218              : 
    4219              : /* Issue a warning about DECL for a goto statement at GOTO_LOC going
    4220              :    to LABEL.  */
    4221              : 
    4222              : static void
    4223         1490 : warn_about_goto (location_t goto_loc, tree label, tree decl)
    4224              : {
    4225         1490 :   auto_diagnostic_group d;
    4226         1490 :   if (c_type_variably_modified_p (TREE_TYPE (decl)))
    4227         1484 :     error_at (goto_loc,
    4228              :               "jump into scope of identifier with variably modified type");
    4229            6 :   else if (flag_openmp
    4230            6 :            && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
    4231            2 :     error_at (goto_loc, "jump skips OpenMP %<allocate%> allocation");
    4232              :   else
    4233            4 :     if (!warning_at (goto_loc, OPT_Wjump_misses_init,
    4234              :                      "jump skips variable initialization"))
    4235            0 :       return;
    4236         1490 :   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4237         1490 :   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
    4238         1490 : }
    4239              : 
    4240              : /* Look up a label because of a goto statement.  This is like
    4241              :    lookup_label, but also issues any appropriate warnings.  */
    4242              : 
    4243              : tree
    4244        84554 : lookup_label_for_goto (location_t loc, tree name)
    4245              : {
    4246        84554 :   tree label;
    4247        84554 :   struct c_label_vars *label_vars;
    4248        84554 :   unsigned int ix;
    4249        84554 :   tree decl;
    4250              : 
    4251        84554 :   label = lookup_label (name);
    4252        84554 :   if (label == NULL_TREE)
    4253              :     return NULL_TREE;
    4254              : 
    4255              :   /* If we are jumping to a different function, we can't issue any
    4256              :      useful warnings.  */
    4257        84554 :   if (DECL_CONTEXT (label) != current_function_decl)
    4258              :     {
    4259          540 :       gcc_assert (C_DECLARED_LABEL_FLAG (label));
    4260              :       return label;
    4261              :     }
    4262              : 
    4263        84014 :   label_vars = I_LABEL_BINDING (name)->u.label;
    4264              : 
    4265              :   /* If the label has not yet been defined, then push this goto on a
    4266              :      list for possible later warnings.  */
    4267        84014 :   if (label_vars->label_bindings.scope == NULL)
    4268              :     {
    4269        67117 :       c_goto_bindings *g = ggc_alloc<c_goto_bindings> ();
    4270              : 
    4271        67117 :       g->loc = loc;
    4272        67117 :       set_spot_bindings (&g->goto_bindings, true);
    4273        67117 :       vec_safe_push (label_vars->gotos, g);
    4274        67117 :       return label;
    4275              :     }
    4276              : 
    4277              :   /* If there are any decls in label_vars->decls_in_scope, then this
    4278              :      goto has missed the declaration of the decl.  This happens for a
    4279              :      case like
    4280              :        int i = 1;
    4281              :       lab:
    4282              :        ...
    4283              :        goto lab;
    4284              :      Issue a warning or error.  */
    4285        17672 :   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
    4286          775 :     warn_about_goto (loc, label, decl);
    4287              : 
    4288        16897 :   if (label_vars->label_bindings.left_stmt_expr)
    4289              :     {
    4290          120 :       auto_diagnostic_group d;
    4291          120 :       error_at (loc, "jump into statement expression");
    4292          120 :       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4293          120 :     }
    4294              : 
    4295              :   return label;
    4296              : }
    4297              : 
    4298              : /* Make a label named NAME in the current function, shadowing silently
    4299              :    any that may be inherited from containing functions or containing
    4300              :    scopes.  This is called for __label__ declarations.  */
    4301              : 
    4302              : tree
    4303         1231 : declare_label (tree name)
    4304              : {
    4305         1231 :   struct c_binding *b = I_LABEL_BINDING (name);
    4306         1231 :   tree label;
    4307         1231 :   struct c_label_vars *label_vars;
    4308              : 
    4309              :   /* Check to make sure that the label hasn't already been declared
    4310              :      at this scope */
    4311         1231 :   if (b && B_IN_CURRENT_SCOPE (b))
    4312              :     {
    4313            2 :       auto_diagnostic_group d;
    4314            2 :       error ("duplicate label declaration %qE", name);
    4315            2 :       locate_old_decl (b->decl);
    4316              : 
    4317              :       /* Just use the previous declaration.  */
    4318            2 :       return b->decl;
    4319            2 :     }
    4320              : 
    4321         1229 :   label = make_label (input_location, name, false, &label_vars);
    4322         1229 :   C_DECLARED_LABEL_FLAG (label) = 1;
    4323              : 
    4324              :   /* Declared labels go in the current scope.  */
    4325         1229 :   bind_label (name, label, current_scope, label_vars);
    4326              : 
    4327         1229 :   return label;
    4328              : }
    4329              : 
    4330              : /* When we define a label, issue any appropriate warnings if there are
    4331              :    any gotos earlier in the function which jump to this label.  */
    4332              : 
    4333              : static void
    4334         7644 : check_earlier_gotos (tree label, struct c_label_vars* label_vars)
    4335              : {
    4336         7644 :   unsigned int ix;
    4337         7644 :   struct c_goto_bindings *g;
    4338              : 
    4339        74695 :   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    4340              :     {
    4341        67051 :       struct c_binding *b;
    4342        67051 :       struct c_scope *scope;
    4343              : 
    4344              :       /* We have a goto to this label.  The goto is going forward.  In
    4345              :          g->scope, the goto is going to skip any binding which was
    4346              :          defined after g->bindings_in_scope.  */
    4347        67051 :       if (g->goto_bindings.scope->has_jump_unsafe_decl)
    4348              :         {
    4349          255 :           for (b = g->goto_bindings.scope->bindings;
    4350          593 :                b != g->goto_bindings.bindings_in_scope;
    4351          338 :                b = b->prev)
    4352              :             {
    4353          338 :               if (decl_jump_unsafe (b->decl))
    4354          176 :                 warn_about_goto (g->loc, label, b->decl);
    4355              :             }
    4356              :         }
    4357              : 
    4358              :       /* We also need to warn about decls defined in any scopes
    4359              :          between the scope of the label and the scope of the goto.  */
    4360        67051 :       for (scope = label_vars->label_bindings.scope;
    4361        69917 :            scope != g->goto_bindings.scope;
    4362         2866 :            scope = scope->outer)
    4363              :         {
    4364         2866 :           gcc_assert (scope != NULL);
    4365         2866 :           if (scope->has_jump_unsafe_decl)
    4366              :             {
    4367          325 :               if (scope == label_vars->label_bindings.scope)
    4368          249 :                 b = label_vars->label_bindings.bindings_in_scope;
    4369              :               else
    4370           76 :                 b = scope->bindings;
    4371          864 :               for (; b != NULL; b = b->prev)
    4372              :                 {
    4373          539 :                   if (decl_jump_unsafe (b->decl))
    4374          539 :                     warn_about_goto (g->loc, label, b->decl);
    4375              :                 }
    4376              :             }
    4377              :         }
    4378              : 
    4379        67051 :       if (g->goto_bindings.stmt_exprs > 0)
    4380              :         {
    4381          100 :           auto_diagnostic_group d;
    4382          100 :           error_at (g->loc, "jump into statement expression");
    4383          100 :           inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
    4384              :                   label);
    4385          100 :         }
    4386              :     }
    4387              : 
    4388              :   /* Now that the label is defined, we will issue warnings about
    4389              :      subsequent gotos to this label when we see them.  */
    4390         7644 :   vec_safe_truncate (label_vars->gotos, 0);
    4391         7644 :   label_vars->gotos = NULL;
    4392         7644 : }
    4393              : 
    4394              : /* Define a label, specifying the location in the source file.
    4395              :    Return the LABEL_DECL node for the label, if the definition is valid.
    4396              :    Otherwise return NULL_TREE.  */
    4397              : 
    4398              : tree
    4399        24763 : define_label (location_t location, tree name)
    4400              : {
    4401              :   /* Find any preexisting label with this name.  It is an error
    4402              :      if that label has already been defined in this function, or
    4403              :      if there is a containing function with a declared label with
    4404              :      the same name.  */
    4405        24763 :   tree label = I_LABEL_DECL (name);
    4406              : 
    4407         7680 :   if (label
    4408         7680 :       && ((DECL_CONTEXT (label) == current_function_decl
    4409         7666 :            && DECL_INITIAL (label) != NULL_TREE)
    4410         7658 :           || (DECL_CONTEXT (label) != current_function_decl
    4411           14 :               && C_DECLARED_LABEL_FLAG (label))))
    4412              :     {
    4413           29 :       auto_diagnostic_group d;
    4414           29 :       error_at (location, "duplicate label %qD", label);
    4415           29 :       locate_old_decl (label);
    4416           29 :       return NULL_TREE;
    4417           29 :     }
    4418        24734 :   else if (label && DECL_CONTEXT (label) == current_function_decl)
    4419              :     {
    4420         7644 :       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
    4421              : 
    4422              :       /* The label has been used or declared already in this function,
    4423              :          but not defined.  Update its location to point to this
    4424              :          definition.  */
    4425         7644 :       DECL_SOURCE_LOCATION (label) = location;
    4426         7644 :       set_spot_bindings (&label_vars->label_bindings, true);
    4427              : 
    4428              :       /* Issue warnings as required about any goto statements from
    4429              :          earlier in the function.  */
    4430         7644 :       check_earlier_gotos (label, label_vars);
    4431              :     }
    4432              :   else
    4433              :     {
    4434        17090 :       struct c_label_vars *label_vars;
    4435              : 
    4436              :       /* No label binding for that identifier; make one.  */
    4437        17090 :       label = make_label (location, name, true, &label_vars);
    4438              : 
    4439              :       /* Ordinary labels go in the current function scope.  */
    4440        17090 :       bind_label (name, label, current_function_scope, label_vars);
    4441              :     }
    4442              : 
    4443        24734 :   if (!in_system_header_at (input_location) && lookup_name (name))
    4444          143 :     warning_at (location, OPT_Wtraditional,
    4445              :                 "traditional C lacks a separate namespace "
    4446              :                 "for labels, identifier %qE conflicts", name);
    4447              : 
    4448              :   /* Mark label as having been defined.  */
    4449        24734 :   DECL_INITIAL (label) = error_mark_node;
    4450        24734 :   return label;
    4451              : }
    4452              : 
    4453              : /* Get the bindings for a new switch statement.  This is used to issue
    4454              :    warnings as appropriate for jumps from the switch to case or
    4455              :    default labels.  */
    4456              : 
    4457              : struct c_spot_bindings *
    4458        38806 : c_get_switch_bindings (void)
    4459              : {
    4460        38806 :   struct c_spot_bindings *switch_bindings;
    4461              : 
    4462        38806 :   switch_bindings = XNEW (struct c_spot_bindings);
    4463        38806 :   set_spot_bindings (switch_bindings, true);
    4464        38806 :   return switch_bindings;
    4465              : }
    4466              : 
    4467              : void
    4468        38806 : c_release_switch_bindings (struct c_spot_bindings *bindings)
    4469              : {
    4470        38806 :   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
    4471        38806 :   XDELETE (bindings);
    4472        38806 : }
    4473              : 
    4474              : /* This is called at the point of a case or default label to issue
    4475              :    warnings about decls as needed.  It returns true if it found an
    4476              :    error, not just a warning.  */
    4477              : 
    4478              : bool
    4479      1039315 : c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
    4480              :                               location_t switch_loc, location_t case_loc)
    4481              : {
    4482      1039315 :   bool saw_error;
    4483      1039315 :   struct c_scope *scope;
    4484              : 
    4485      1039315 :   saw_error = false;
    4486      1039315 :   for (scope = current_scope;
    4487      3117842 :        scope != switch_bindings->scope;
    4488      2078527 :        scope = scope->outer)
    4489              :     {
    4490      2078527 :       struct c_binding *b;
    4491              : 
    4492      2078527 :       gcc_assert (scope != NULL);
    4493              : 
    4494      2078527 :       if (!scope->has_jump_unsafe_decl)
    4495      2078516 :         continue;
    4496              : 
    4497           22 :       for (b = scope->bindings; b != NULL; b = b->prev)
    4498              :         {
    4499           11 :           if (decl_jump_unsafe (b->decl))
    4500              :             {
    4501           11 :               auto_diagnostic_group d;
    4502           11 :               bool emitted;
    4503           11 :               if (c_type_variably_modified_p (TREE_TYPE (b->decl)))
    4504              :                 {
    4505            6 :                   saw_error = true;
    4506            6 :                   error_at (case_loc,
    4507              :                             "switch jumps into scope of identifier with "
    4508              :                             "variably modified type");
    4509            6 :                   emitted = true;
    4510              :                 }
    4511            5 :               else if (flag_openmp
    4512            7 :                        && lookup_attribute ("omp allocate",
    4513            2 :                                             DECL_ATTRIBUTES (b->decl)))
    4514              :                 {
    4515            2 :                   saw_error = true;
    4516            2 :                   error_at (case_loc,
    4517              :                             "switch jumps over OpenMP %<allocate%> allocation");
    4518            2 :                   emitted = true;
    4519              :                 }
    4520              :               else
    4521            3 :                 emitted
    4522            3 :                   = warning_at (case_loc, OPT_Wjump_misses_init,
    4523              :                                 "switch jumps over variable initialization");
    4524           11 :               if (emitted)
    4525              :                 {
    4526           11 :                   inform (switch_loc, "switch starts here");
    4527           11 :                   inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
    4528              :                           b->decl);
    4529              :                 }
    4530           11 :             }
    4531              :         }
    4532              :     }
    4533              : 
    4534      1039315 :   if (switch_bindings->stmt_exprs > 0)
    4535              :     {
    4536            4 :       saw_error = true;
    4537            4 :       auto_diagnostic_group d;
    4538            4 :       error_at (case_loc, "switch jumps into statement expression");
    4539            4 :       inform (switch_loc, "switch starts here");
    4540            4 :     }
    4541              : 
    4542      1039315 :   return saw_error;
    4543              : }
    4544              : 
    4545              : /* Given NAME, an IDENTIFIER_NODE,
    4546              :    return the structure (or union or enum) definition for that name.
    4547              :    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
    4548              :    CODE says which kind of type the caller wants;
    4549              :    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
    4550              :    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
    4551              :    location where the tag was defined.
    4552              :    If the wrong kind of type is found, an error is reported.  */
    4553              : 
    4554              : static tree
    4555      2124236 : lookup_tag (enum tree_code code, tree name, bool thislevel_only,
    4556              :             location_t *ploc)
    4557              : {
    4558      2124236 :   struct c_binding *b = I_TAG_BINDING (name);
    4559      2124236 :   bool thislevel = false;
    4560              : 
    4561      2124236 :   if (!b || !b->decl)
    4562              :     return NULL_TREE;
    4563              : 
    4564              :   /* We only care about whether it's in this level if
    4565              :      thislevel_only was set or it might be a type clash.  */
    4566      1486253 :   if (thislevel_only || TREE_CODE (b->decl) != code)
    4567              :     {
    4568              :       /* For our purposes, a tag in the external scope is the same as
    4569              :          a tag in the file scope.  (Primarily relevant to Objective-C
    4570              :          and its builtin structure tags, which get pushed before the
    4571              :          file scope is created.)  */
    4572       476329 :       if (B_IN_CURRENT_SCOPE (b)
    4573          196 :           || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    4574      1486253 :         thislevel = true;
    4575              :     }
    4576              : 
    4577      1486253 :   if (thislevel_only && !thislevel)
    4578              :     return NULL_TREE;
    4579              : 
    4580      1486078 :   if (TREE_CODE (b->decl) != code)
    4581              :     {
    4582              :       /* Definition isn't the kind we were looking for.  */
    4583           39 :       pending_invalid_xref = name;
    4584           39 :       pending_invalid_xref_location = input_location;
    4585              : 
    4586              :       /* If in the same binding level as a declaration as a tag
    4587              :          of a different type, this must not be allowed to
    4588              :          shadow that tag, so give the error immediately.
    4589              :          (For example, "struct foo; union foo;" is invalid.)  */
    4590           39 :       if (thislevel)
    4591           18 :         pending_xref_error ();
    4592              :     }
    4593              : 
    4594      1486078 :   if (ploc != NULL)
    4595      1035801 :     *ploc = b->locus;
    4596              : 
    4597      1486078 :   return b->decl;
    4598              : }
    4599              : 
    4600              : /* Return true if a definition exists for NAME with code CODE.  */
    4601              : 
    4602              : bool
    4603          366 : tag_exists_p (enum tree_code code, tree name)
    4604              : {
    4605          366 :   struct c_binding *b = I_TAG_BINDING (name);
    4606              : 
    4607          366 :   if (b == NULL || b->decl == NULL_TREE)
    4608              :     return false;
    4609           18 :   return TREE_CODE (b->decl) == code;
    4610              : }
    4611              : 
    4612              : /* Print an error message now
    4613              :    for a recent invalid struct, union or enum cross reference.
    4614              :    We don't print them immediately because they are not invalid
    4615              :    when used in the `struct foo;' construct for shadowing.  */
    4616              : 
    4617              : void
    4618    325082251 : pending_xref_error (void)
    4619              : {
    4620    325082251 :   if (pending_invalid_xref != NULL_TREE)
    4621           27 :     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
    4622              :               pending_invalid_xref);
    4623    325082251 :   pending_invalid_xref = NULL_TREE;
    4624    325082251 : }
    4625              : 
    4626              : 
    4627              : /* Look up NAME in the current scope and its superiors
    4628              :    in the namespace of variables, functions and typedefs.
    4629              :    Return a ..._DECL node of some kind representing its definition,
    4630              :    or return NULL_TREE if it is undefined.  */
    4631              : 
    4632              : tree
    4633   1310921929 : lookup_name (tree name)
    4634              : {
    4635   1310921929 :   struct c_binding *b = I_SYMBOL_BINDING (name);
    4636              :   /* Do not resolve non-default function versions.  */
    4637   1310921929 :   if (b
    4638    886111017 :       && TREE_CODE (b->decl) == FUNCTION_DECL
    4639    122005968 :       && DECL_FUNCTION_VERSIONED (b->decl)
    4640   1310921929 :       && !is_function_default_version (b->decl))
    4641              :     return NULL_TREE;
    4642   1310921929 :   if (b && !b->invisible)
    4643              :     {
    4644    874746268 :       maybe_record_typedef_use (b->decl);
    4645    874746268 :       return b->decl;
    4646              :     }
    4647              :   return NULL_TREE;
    4648              : }
    4649              : 
    4650              : /* Similar to `lookup_name' but look only at the indicated scope.  */
    4651              : 
    4652              : static tree
    4653    135497162 : lookup_name_in_scope (tree name, struct c_scope *scope)
    4654              : {
    4655    135497162 :   struct c_binding *b;
    4656              : 
    4657    135500395 :   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
    4658      7794238 :     if (B_IN_SCOPE (b, scope))
    4659      7791005 :       return b->decl;
    4660              :   return NULL_TREE;
    4661              : }
    4662              : 
    4663              : /* Look for the closest match for NAME within the currently valid
    4664              :    scopes.
    4665              : 
    4666              :    This finds the identifier with the lowest Levenshtein distance to
    4667              :    NAME.  If there are multiple candidates with equal minimal distance,
    4668              :    the first one found is returned.  Scopes are searched from innermost
    4669              :    outwards, and within a scope in reverse order of declaration, thus
    4670              :    benefiting candidates "near" to the current scope.
    4671              : 
    4672              :    The function also looks for similar macro names to NAME, since a
    4673              :    misspelled macro name will not be expanded, and hence looks like an
    4674              :    identifier to the C frontend.
    4675              : 
    4676              :    It also looks for start_typename keywords, to detect "singed" vs "signed"
    4677              :    typos.
    4678              : 
    4679              :    Use LOC for any deferred diagnostics.  */
    4680              : 
    4681              : name_hint
    4682         2062 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    4683              : {
    4684         2062 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    4685              : 
    4686              :   /* Look up function-like macros first; maybe misusing them. */
    4687         4124 :   auto cpp_node = cpp_lookup (parse_in,
    4688         2062 :                               (const unsigned char*)IDENTIFIER_POINTER (name),
    4689         2062 :                               IDENTIFIER_LENGTH (name));
    4690         2062 :   if (cpp_node && cpp_fun_like_macro_p (cpp_node))
    4691            5 :     return name_hint
    4692              :       (nullptr,
    4693            5 :        std::make_unique<macro_like_function_used> (loc,
    4694           10 :                                                    IDENTIFIER_POINTER (name)));
    4695              : 
    4696              :   /* Next, try some well-known names in the C standard library, in case
    4697              :      the user forgot a #include.  */
    4698         2057 :   const char *header_hint
    4699         2057 :     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    4700              : 
    4701         2057 :   if (header_hint)
    4702           56 :     return name_hint
    4703              :       (nullptr,
    4704           56 :        std::make_unique<suggest_missing_header> (loc,
    4705          112 :                                                  IDENTIFIER_POINTER (name),
    4706           56 :                                                  header_hint));
    4707              : 
    4708              :   /* Next, look for exact matches for builtin defines that would have been
    4709              :      defined if the user had passed a command-line option (e.g. -fopenmp
    4710              :      for "_OPENMP").  */
    4711         2001 :   diagnostics::option_id option_id
    4712         2001 :     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
    4713         2001 :   if (option_id.m_idx > 0)
    4714            2 :     return name_hint
    4715              :       (nullptr,
    4716            2 :        std::make_unique<suggest_missing_option> (loc,
    4717            4 :                                                  IDENTIFIER_POINTER (name),
    4718            2 :                                                  option_id));
    4719              : 
    4720              :   /* Only suggest names reserved for the implementation if NAME begins
    4721              :      with an underscore.  */
    4722         1999 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    4723              : 
    4724         1999 :   best_match<tree, tree> bm (name);
    4725              : 
    4726              :   /* Look within currently valid scopes.  */
    4727         9099 :   for (c_scope *scope = current_scope; scope; scope = scope->outer)
    4728     11389768 :     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
    4729              :       {
    4730     11382668 :         if (!binding->id || binding->invisible)
    4731      6432102 :           continue;
    4732      4950566 :         if (binding->decl == error_mark_node)
    4733          374 :           continue;
    4734              :         /* Don't use bindings from implicitly declared functions,
    4735              :            as they were likely misspellings themselves.  */
    4736      4950192 :         if (TREE_CODE (binding->decl) == FUNCTION_DECL)
    4737      4546588 :           if (C_DECL_IMPLICIT (binding->decl))
    4738          229 :             continue;
    4739              :         /* Don't suggest names that are reserved for use by the
    4740              :            implementation, unless NAME began with an underscore.  */
    4741      4949963 :         if (!consider_implementation_names)
    4742              :           {
    4743      2344775 :             const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
    4744      2344775 :             if (name_reserved_for_implementation_p (suggestion_str))
    4745      2284741 :               continue;
    4746              :           }
    4747      2665222 :         switch (kind)
    4748              :           {
    4749        23982 :           case FUZZY_LOOKUP_TYPENAME:
    4750        23982 :             if (TREE_CODE (binding->decl) != TYPE_DECL)
    4751        16847 :               continue;
    4752              :             break;
    4753              : 
    4754       129882 :           case FUZZY_LOOKUP_FUNCTION_NAME:
    4755       129882 :             if (TREE_CODE (binding->decl) != FUNCTION_DECL)
    4756              :               {
    4757              :                 /* Allow function pointers.  */
    4758        27001 :                 if ((VAR_P (binding->decl)
    4759        22476 :                      || TREE_CODE (binding->decl) == PARM_DECL)
    4760         5403 :                     && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
    4761        28283 :                     && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
    4762              :                         == FUNCTION_TYPE))
    4763              :                   break;
    4764        26982 :                 continue;
    4765              :               }
    4766              :             break;
    4767              : 
    4768              :           default:
    4769              :             break;
    4770              :           }
    4771      2621393 :         bm.consider (binding->id);
    4772              :       }
    4773              : 
    4774              :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    4775              :      as:
    4776              :        x = SOME_OTHER_MACRO (y);
    4777              :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    4778              :      as a misspelled identifier.
    4779              : 
    4780              :      Use the best distance so far so that a candidate is only set if
    4781              :      a macro is better than anything so far.  This allows early rejection
    4782              :      (without calculating the edit distance) of macro names that must have
    4783              :      distance >= bm.get_best_distance (), and means that we only get a
    4784              :      non-NULL result for best_macro_match if it's better than any of
    4785              :      the identifiers already checked, which avoids needless creation
    4786              :      of identifiers for macro hashnodes.  */
    4787         1999 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    4788         1999 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    4789              :   /* If a macro is the closest so far to NAME, use it, creating an
    4790              :      identifier tree node for it.  */
    4791         1999 :   if (best_macro)
    4792              :     {
    4793           11 :       const char *id = (const char *)best_macro->ident.str;
    4794           11 :       tree macro_as_identifier
    4795           11 :         = get_identifier_with_length (id, best_macro->ident.len);
    4796           11 :       bm.set_best_so_far (macro_as_identifier,
    4797              :                           bmm.get_best_distance (),
    4798              :                           bmm.get_best_candidate_length ());
    4799              :     }
    4800              : 
    4801              :   /* Try the "start_typename" keywords to detect
    4802              :      "singed" vs "signed" typos.  */
    4803         1999 :   if (kind == FUZZY_LOOKUP_TYPENAME)
    4804              :     {
    4805        54988 :       for (unsigned i = 0; i < num_c_common_reswords; i++)
    4806              :         {
    4807        54755 :           const c_common_resword *resword = &c_common_reswords[i];
    4808        54755 :           if (!c_keyword_starts_typename (resword->rid))
    4809        41940 :             continue;
    4810        12815 :           tree resword_identifier = ridpointers [resword->rid];
    4811        12815 :           if (!resword_identifier)
    4812           30 :             continue;
    4813        12785 :           gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    4814        12785 :           bm.consider (resword_identifier);
    4815              :         }
    4816              :     }
    4817              : 
    4818         1999 :   tree best = bm.get_best_meaningful_candidate ();
    4819         1999 :   if (best)
    4820          276 :     return name_hint (IDENTIFIER_POINTER (best), NULL);
    4821              :   else
    4822         1723 :     return name_hint (NULL, NULL);
    4823              : }
    4824              : 
    4825              : 
    4826              : /* Handle the standard [[nodiscard]] attribute.  */
    4827              : 
    4828              : static tree
    4829           34 : handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
    4830              :                             int /*flags*/, bool *no_add_attrs)
    4831              : {
    4832           34 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4833              :     {
    4834           18 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
    4835            1 :         warning_at (DECL_SOURCE_LOCATION (*node),
    4836            1 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    4837              :                     "return type", name, *node);
    4838              :     }
    4839           16 :   else if (RECORD_OR_UNION_TYPE_P (*node)
    4840           12 :            || TREE_CODE (*node) == ENUMERAL_TYPE)
    4841              :     /* OK */;
    4842              :   else
    4843              :     {
    4844           10 :       pedwarn (input_location,
    4845           10 :                OPT_Wattributes, "%qE attribute can only be applied to "
    4846              :                "functions or to structure, union or enumeration types", name);
    4847           10 :       *no_add_attrs = true;
    4848              :     }
    4849           34 :   return NULL_TREE;
    4850              : }
    4851              : 
    4852              : /* Handle the standard [[noreturn]] attribute.  */
    4853              : 
    4854              : static tree
    4855           44 : handle_std_noreturn_attribute (tree *node, tree name, tree args,
    4856              :                                int flags, bool *no_add_attrs)
    4857              : {
    4858              :   /* Unlike GNU __attribute__ ((noreturn)), the standard [[noreturn]]
    4859              :      only applies to functions, not function pointers.  */
    4860           44 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4861           22 :     return handle_noreturn_attribute (node, name, args, flags, no_add_attrs);
    4862              :   else
    4863              :     {
    4864           22 :       pedwarn (input_location, OPT_Wattributes,
    4865              :                "standard %qE attribute can only be applied to functions",
    4866              :                name);
    4867           22 :       *no_add_attrs = true;
    4868           22 :       return NULL_TREE;
    4869              :     }
    4870              : }
    4871              : 
    4872              : /* Handle the standard [[unsequenced]] attribute.  */
    4873              : 
    4874              : static tree
    4875           68 : handle_std_unsequenced_attribute (tree *node, tree name, tree args,
    4876              :                                   int flags, bool *no_add_attrs)
    4877              : {
    4878              :   /* Unlike GNU __attribute__ ((unsequenced)), the standard [[unsequenced]]
    4879              :      should be only applied to function declarators or type specifiers which
    4880              :      have function type.  */
    4881           68 :   if (node[2])
    4882              :     {
    4883            8 :       auto_diagnostic_group d;
    4884            8 :       if (pedwarn (input_location, OPT_Wattributes,
    4885              :                    "standard %qE attribute can only be applied to function "
    4886              :                    "declarators or type specifiers with function type", name))
    4887            8 :         inform (input_location, "did you mean to specify it after %<)%> "
    4888              :                                 "following function parameters?");
    4889            8 :       *no_add_attrs = true;
    4890            8 :       return NULL_TREE;
    4891            8 :     }
    4892           60 :   return handle_unsequenced_attribute (node, name, args, flags, no_add_attrs);
    4893              : }
    4894              : 
    4895              : /* Handle the standard [[reproducible]] attribute.  */
    4896              : 
    4897              : static tree
    4898           34 : handle_std_reproducible_attribute (tree *node, tree name, tree args,
    4899              :                                    int flags, bool *no_add_attrs)
    4900              : {
    4901           34 :   return handle_std_unsequenced_attribute (node, name, args, flags,
    4902           34 :                                            no_add_attrs);
    4903              : }
    4904              : 
    4905              : /* Table of supported standard (C23) attributes.  */
    4906              : static const attribute_spec std_attributes[] =
    4907              : {
    4908              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    4909              :        affects_type_identity, handler, exclude } */
    4910              :   { "_Noreturn", 0, 0, false, false, false, false,
    4911              :     handle_std_noreturn_attribute, NULL },
    4912              :   { "deprecated", 0, 1, false, false, false, false,
    4913              :     handle_deprecated_attribute, NULL },
    4914              :   { "fallthrough", 0, 0, false, false, false, false,
    4915              :     handle_fallthrough_attribute, NULL },
    4916              :   { "maybe_unused", 0, 0, false, false, false, false,
    4917              :     handle_unused_attribute, NULL },
    4918              :   { "nodiscard", 0, 1, false, false, false, false,
    4919              :     handle_nodiscard_attribute, NULL },
    4920              :   { "noreturn", 0, 0, false, false, false, false,
    4921              :     handle_std_noreturn_attribute, NULL },
    4922              :   { "reproducible", 0, 0, false, true, true, false,
    4923              :     handle_std_reproducible_attribute, NULL },
    4924              :   { "unsequenced", 0, 0, false, true, true, false,
    4925              :     handle_std_unsequenced_attribute, NULL }
    4926              : };
    4927              : 
    4928              : const scoped_attribute_specs std_attribute_table =
    4929              : {
    4930              :   nullptr, { std_attributes }
    4931              : };
    4932              : 
    4933              : /* Create the predefined scalar types of C,
    4934              :    and some nodes representing standard constants (0, 1, (void *) 0).
    4935              :    Initialize the global scope.
    4936              :    Make definitions for built-in primitive functions.  */
    4937              : 
    4938              : void
    4939       114432 : c_init_decl_processing (void)
    4940              : {
    4941       114432 :   location_t save_loc = input_location;
    4942              : 
    4943              :   /* Initialize reserved words for parser.  */
    4944       114432 :   c_parse_init ();
    4945              : 
    4946       114432 :   current_function_decl = NULL_TREE;
    4947              : 
    4948       114432 :   gcc_obstack_init (&parser_obstack);
    4949              : 
    4950              :   /* Make the externals scope.  */
    4951       114432 :   push_scope ();
    4952       114432 :   external_scope = current_scope;
    4953              : 
    4954              :   /* Declarations from c_common_nodes_and_builtins must not be associated
    4955              :      with this input file, lest we get differences between using and not
    4956              :      using preprocessed headers.  */
    4957       114432 :   input_location = BUILTINS_LOCATION;
    4958              : 
    4959       114432 :   c_common_nodes_and_builtins ();
    4960              : 
    4961              :   /* In C, comparisons and TRUTH_* expressions have type int.  */
    4962       114432 :   truthvalue_type_node = integer_type_node;
    4963       114432 :   truthvalue_true_node = integer_one_node;
    4964       114432 :   truthvalue_false_node = integer_zero_node;
    4965              : 
    4966              :   /* Even in C99, which has a real boolean type.  */
    4967       114432 :   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL,
    4968       114432 :                         get_identifier (flag_isoc23 ? "bool" : "_Bool"),
    4969              :                         boolean_type_node));
    4970              : 
    4971              :   /* C-specific nullptr initialization.  */
    4972       114432 :   record_builtin_type (RID_MAX, "typeof (nullptr)", nullptr_type_node);
    4973              :   /* The size and alignment of nullptr_t is the same as for a pointer to
    4974              :      character type.  */
    4975       114432 :   SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4976              : 
    4977       114432 :   input_location = save_loc;
    4978              : 
    4979       114432 :   make_fname_decl = c_make_fname_decl;
    4980       114432 :   start_fname_decls ();
    4981              : 
    4982       114432 :   if (warn_keyword_macro)
    4983              :     {
    4984         1180 :       for (unsigned int i = 0; i < num_c_common_reswords; ++i)
    4985              :         /* For C register keywords which don't start with underscore
    4986              :            or start with just single underscore.  Don't complain about
    4987              :            ObjC or Transactional Memory keywords.  */
    4988         1175 :         if (c_common_reswords[i].word[0] == '_'
    4989          545 :             && c_common_reswords[i].word[1] == '_')
    4990          405 :           continue;
    4991          995 :         else if (c_common_reswords[i].disable
    4992          770 :                  & (D_TRANSMEM | D_OBJC | D_CXX_OBJC))
    4993          225 :           continue;
    4994              :         else
    4995              :           {
    4996          545 :             tree id = get_identifier (c_common_reswords[i].word);
    4997          545 :             if (C_IS_RESERVED_WORD (id)
    4998          545 :                 && C_RID_CODE (id) != RID_CXX_COMPAT_WARN)
    4999          332 :               cpp_warn (parse_in, IDENTIFIER_POINTER (id),
    5000          332 :                         IDENTIFIER_LENGTH (id));
    5001              :           }
    5002              :     }
    5003       114432 : }
    5004              : 
    5005              : /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
    5006              :    give the decl, NAME is the initialization string and TYPE_DEP
    5007              :    indicates whether NAME depended on the type of the function.  As we
    5008              :    don't yet implement delayed emission of static data, we mark the
    5009              :    decl as emitted so it is not placed in the output.  Anything using
    5010              :    it must therefore pull out the STRING_CST initializer directly.
    5011              :    FIXME.  */
    5012              : 
    5013              : static tree
    5014         2969 : c_make_fname_decl (location_t loc, tree id, int type_dep)
    5015              : {
    5016         2969 :   const char *name = fname_as_string (type_dep);
    5017         2969 :   tree decl, type, init;
    5018         2969 :   size_t length = strlen (name);
    5019              : 
    5020         2969 :   type = c_build_array_type (char_type_node,
    5021         2969 :                              build_index_type (size_int (length)));
    5022         2969 :   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
    5023              : 
    5024         2969 :   decl = build_decl (loc, VAR_DECL, id, type);
    5025              : 
    5026         2969 :   TREE_STATIC (decl) = 1;
    5027         2969 :   TREE_READONLY (decl) = 1;
    5028         2969 :   DECL_ARTIFICIAL (decl) = 1;
    5029              : 
    5030         2969 :   init = build_string (length + 1, name);
    5031         2969 :   free (const_cast<char *> (name));
    5032         2969 :   TREE_TYPE (init) = type;
    5033         2969 :   DECL_INITIAL (decl) = init;
    5034              : 
    5035         2969 :   TREE_USED (decl) = 1;
    5036              : 
    5037         2969 :   if (current_function_decl
    5038              :       /* For invalid programs like this:
    5039              : 
    5040              :          void foo()
    5041              :          const char* p = __FUNCTION__;
    5042              : 
    5043              :          the __FUNCTION__ is believed to appear in K&R style function
    5044              :          parameter declarator.  In that case we still don't have
    5045              :          function_scope.  */
    5046         2962 :       && current_function_scope)
    5047              :     {
    5048         2954 :       DECL_CONTEXT (decl) = current_function_decl;
    5049         2954 :       bind (id, decl, current_function_scope,
    5050              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
    5051              :     }
    5052              : 
    5053         2969 :   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
    5054              : 
    5055         2969 :   return decl;
    5056              : }
    5057              : 
    5058              : tree
    5059    335370564 : c_builtin_function (tree decl)
    5060              : {
    5061    335370564 :   tree type = TREE_TYPE (decl);
    5062    335370564 :   tree   id = DECL_NAME (decl);
    5063              : 
    5064    335370564 :   const char *name = IDENTIFIER_POINTER (id);
    5065    335370564 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5066              : 
    5067              :   /* Should never be called on a symbol with a preexisting meaning.  */
    5068    335370564 :   gcc_assert (!I_SYMBOL_BINDING (id));
    5069              : 
    5070    335370564 :   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
    5071              :         UNKNOWN_LOCATION);
    5072              : 
    5073              :   /* Builtins in the implementation namespace are made visible without
    5074              :      needing to be explicitly declared.  See push_file_scope.  */
    5075    335370564 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5076              :     {
    5077    229170560 :       DECL_CHAIN (decl) = visible_builtins;
    5078    229170560 :       visible_builtins = decl;
    5079              :     }
    5080              : 
    5081    335370564 :   return decl;
    5082              : }
    5083              : 
    5084              : tree
    5085     11035932 : c_builtin_function_ext_scope (tree decl)
    5086              : {
    5087     11035932 :   tree type = TREE_TYPE (decl);
    5088     11035932 :   tree   id = DECL_NAME (decl);
    5089              : 
    5090     11035932 :   const char *name = IDENTIFIER_POINTER (id);
    5091     11035932 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5092              : 
    5093     11035932 :   if (external_scope)
    5094     10842941 :     bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
    5095              :           UNKNOWN_LOCATION);
    5096              : 
    5097              :   /* Builtins in the implementation namespace are made visible without
    5098              :      needing to be explicitly declared.  See push_file_scope.  */
    5099     11035932 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5100              :     {
    5101     11035932 :       DECL_CHAIN (decl) = visible_builtins;
    5102     11035932 :       visible_builtins = decl;
    5103              :     }
    5104              : 
    5105     11035932 :   return decl;
    5106              : }
    5107              : 
    5108              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5109              : 
    5110              : tree
    5111            0 : c_simulate_builtin_function_decl (tree decl)
    5112              : {
    5113            0 :   tree type = TREE_TYPE (decl);
    5114            0 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5115            0 :   return pushdecl (decl);
    5116              : }
    5117              : 
    5118              : /* Warn about attributes in a context where they are unused
    5119              :    (attribute-declarations, except for the "fallthrough" case, and
    5120              :    attributes on statements).  */
    5121              : 
    5122              : void
    5123     43068506 : c_warn_unused_attributes (tree attrs)
    5124              : {
    5125     43068551 :   for (tree t = attrs; t != NULL_TREE; t = TREE_CHAIN (t))
    5126           45 :     if (get_attribute_namespace (t) == NULL_TREE)
    5127              :       /* The specifications of standard attributes mean this is a
    5128              :          constraint violation.  */
    5129           29 :       pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5130              :                get_attribute_name (t));
    5131           16 :     else if (!attribute_ignored_p (t))
    5132           12 :       warning (OPT_Wattributes, "%qE attribute ignored",
    5133              :                get_attribute_name (t));
    5134     43068506 : }
    5135              : 
    5136              : /* Warn for standard attributes being applied to a type that is not
    5137              :    being defined, where that is a constraint violation, and return a
    5138              :    list of attributes with them removed.  */
    5139              : 
    5140              : tree
    5141    452044201 : c_warn_type_attributes (tree type, tree attrs)
    5142              : {
    5143    452044201 :   tree *attr_ptr = &attrs;
    5144    452067710 :   while (*attr_ptr)
    5145        23509 :     if (get_attribute_namespace (*attr_ptr) == NULL_TREE)
    5146              :       {
    5147           89 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    5148              :           {
    5149           65 :             tree name = get_attribute_name (*attr_ptr);
    5150              :             /* [[unsequenced]] and [[reproducible]] is fine on function
    5151              :                types that aren't being defined.  */
    5152           65 :             if (is_attribute_p ("unsequenced", name)
    5153           65 :                 || is_attribute_p ("reproducible", name))
    5154              :               {
    5155           60 :                 attr_ptr = &TREE_CHAIN (*attr_ptr);
    5156           60 :                 continue;
    5157              :               }
    5158              :           }
    5159           29 :         pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5160              :                  get_attribute_name (*attr_ptr));
    5161           29 :         *attr_ptr = TREE_CHAIN (*attr_ptr);
    5162              :       }
    5163              :     else
    5164        23420 :       attr_ptr = &TREE_CHAIN (*attr_ptr);
    5165    452044201 :   return attrs;
    5166              : }
    5167              : 
    5168              : /* Called when a declaration is seen that contains no names to declare.
    5169              :    If its type is a reference to a structure, union or enum inherited
    5170              :    from a containing scope, shadow that tag name for the current scope
    5171              :    with a forward reference.
    5172              :    If its type defines a new named structure or union
    5173              :    or defines an enum, it is valid but we need not do anything here.
    5174              :    Otherwise, it is an error.  */
    5175              : 
    5176              : void
    5177       512811 : shadow_tag (const struct c_declspecs *declspecs)
    5178              : {
    5179       512811 :   shadow_tag_warned (declspecs, 0);
    5180       512811 : }
    5181              : 
    5182              : /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
    5183              :    but no pedwarn.  */
    5184              : void
    5185       512881 : shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
    5186              : {
    5187       512881 :   bool found_tag = false;
    5188              : 
    5189       512881 :   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
    5190              :     {
    5191       512767 :       tree value = declspecs->type;
    5192       512767 :       enum tree_code code = TREE_CODE (value);
    5193              : 
    5194       512767 :       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
    5195              :         /* Used to test also that TYPE_SIZE (value) != 0.
    5196              :            That caused warning for `struct foo;' at top level in the file.  */
    5197              :         {
    5198       512716 :           tree name = TYPE_NAME (value);
    5199       512716 :           tree t;
    5200              : 
    5201       512716 :           found_tag = true;
    5202              : 
    5203       512716 :           if (declspecs->restrict_p)
    5204              :             {
    5205            2 :               error ("invalid use of %<restrict%>");
    5206            2 :               warned = 1;
    5207              :             }
    5208              : 
    5209       512716 :           if (in_underspecified_init)
    5210              :             {
    5211              :               /* This can only occur with extensions such as statement
    5212              :                  expressions, but is still appropriate as an error to
    5213              :                  avoid types declared in such a context escaping to
    5214              :                  the type of an auto variable.  */
    5215            1 :               error ("%qT declared in underspecified object initializer",
    5216              :                      value);
    5217            1 :               warned = 1;
    5218              :             }
    5219              : 
    5220       512716 :           if (name == NULL_TREE)
    5221              :             {
    5222        62428 :               if (warned != 1 && code != ENUMERAL_TYPE)
    5223              :                 /* Empty unnamed enum OK */
    5224              :                 {
    5225           19 :                   pedwarn (input_location, 0,
    5226              :                            "unnamed struct/union that defines no instances");
    5227           19 :                   warned = 1;
    5228              :                 }
    5229              :             }
    5230       450288 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5231        89053 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5232        26447 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5233        26439 :                    && declspecs->storage_class != csc_none)
    5234              :             {
    5235            2 :               if (warned != 1)
    5236            2 :                 pedwarn (input_location, 0,
    5237              :                          "empty declaration with storage class specifier "
    5238              :                          "does not redeclare tag");
    5239            2 :               warned = 1;
    5240            2 :               pending_xref_error ();
    5241              :             }
    5242       450286 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5243        89051 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5244        26445 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5245        26437 :                    && (declspecs->const_p
    5246        26434 :                        || declspecs->volatile_p
    5247        26434 :                        || declspecs->atomic_p
    5248        26434 :                        || declspecs->restrict_p
    5249        26434 :                        || declspecs->address_space))
    5250              :             {
    5251            3 :               if (warned != 1)
    5252            3 :                 pedwarn (input_location, 0,
    5253              :                          "empty declaration with type qualifier "
    5254              :                           "does not redeclare tag");
    5255            3 :               warned = 1;
    5256            3 :               pending_xref_error ();
    5257              :             }
    5258       450283 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5259        89048 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5260        26442 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5261        26434 :                    && declspecs->alignas_p)
    5262              :             {
    5263            1 :               if (warned != 1)
    5264            1 :                 pedwarn (input_location, 0,
    5265              :                          "empty declaration with %<_Alignas%> "
    5266              :                           "does not redeclare tag");
    5267            1 :               warned = 1;
    5268            1 :               pending_xref_error ();
    5269              :             }
    5270       450282 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5271        89047 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5272        26441 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5273        26433 :                    && code == ENUMERAL_TYPE
    5274           15 :                    && !declspecs->enum_type_specifier_ref_p)
    5275              :             {
    5276            3 :               bool warned_enum = false;
    5277            3 :               if (warned != 1)
    5278            3 :                 warned_enum = pedwarn (input_location, OPT_Wpedantic,
    5279              :                                        "empty declaration of %<enum%> type "
    5280              :                                        "does not redeclare tag");
    5281            3 :               if (warned_enum)
    5282            2 :                 warned = 1;
    5283            3 :               pending_xref_error ();
    5284            3 :             }
    5285              :           else
    5286              :             {
    5287       450279 :               pending_invalid_xref = NULL_TREE;
    5288       450279 :               t = lookup_tag (code, name, true, NULL);
    5289              : 
    5290       450279 :               if (t == NULL_TREE)
    5291              :                 {
    5292            2 :                   t = make_node (code);
    5293            2 :                   if (flag_isoc23 || code == ENUMERAL_TYPE)
    5294            1 :                     SET_TYPE_STRUCTURAL_EQUALITY (t);
    5295            2 :                   pushtag (input_location, name, t);
    5296              :                 }
    5297              :             }
    5298              :         }
    5299              :       else
    5300              :         {
    5301           51 :           if (warned != 1 && !in_system_header_at (input_location))
    5302              :             {
    5303           44 :               pedwarn (input_location, 0,
    5304              :                        "useless type name in empty declaration");
    5305           44 :               warned = 1;
    5306              :             }
    5307              :         }
    5308              :     }
    5309           71 :   else if (warned != 1 && !in_system_header_at (input_location)
    5310          185 :            && declspecs->typedef_p)
    5311              :     {
    5312           11 :       pedwarn (input_location, 0, "useless type name in empty declaration");
    5313           11 :       warned = 1;
    5314              :     }
    5315              : 
    5316       512881 :   pending_invalid_xref = NULL_TREE;
    5317              : 
    5318       512881 :   if (declspecs->inline_p)
    5319              :     {
    5320            5 :       error ("%<inline%> in empty declaration");
    5321            5 :       warned = 1;
    5322              :     }
    5323              : 
    5324       512881 :   if (declspecs->noreturn_p)
    5325              :     {
    5326            2 :       error ("%<_Noreturn%> in empty declaration");
    5327            2 :       warned = 1;
    5328              :     }
    5329              : 
    5330       512881 :   if (declspecs->constexpr_p)
    5331              :     {
    5332            7 :       error ("%<constexpr%> in empty declaration");
    5333            7 :       warned = 1;
    5334              :     }
    5335              : 
    5336       512881 :   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
    5337              :     {
    5338            2 :       error ("%<auto%> in file-scope empty declaration");
    5339            2 :       warned = 1;
    5340              :     }
    5341              : 
    5342       512881 :   if (current_scope == file_scope && declspecs->storage_class == csc_register)
    5343              :     {
    5344            2 :       error ("%<register%> in file-scope empty declaration");
    5345            2 :       warned = 1;
    5346              :     }
    5347              : 
    5348       512881 :   if (declspecs->enum_type_specifier_ref_p && !warned)
    5349              :     {
    5350           39 :       if (declspecs->storage_class != csc_none)
    5351              :         {
    5352            1 :           error ("storage class specifier in empty declaration with %<enum%> "
    5353              :                  "underlying type");
    5354            1 :           warned = 1;
    5355              :         }
    5356           38 :       else if (declspecs->thread_p)
    5357              :         {
    5358            2 :           error ("%qs in empty declaration with %<enum%> underlying type",
    5359            1 :                  declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5360            1 :           warned = 1;
    5361              :         }
    5362           37 :       else if (declspecs->const_p
    5363           36 :                || declspecs->volatile_p
    5364           36 :                || declspecs->atomic_p
    5365           36 :                || declspecs->restrict_p
    5366           36 :                || declspecs->address_space)
    5367              :         {
    5368            1 :           error ("type qualifier in empty declaration with %<enum%> "
    5369              :                  "underlying type");
    5370            1 :           warned = 1;
    5371              :         }
    5372           36 :       else if (declspecs->alignas_p)
    5373              :         {
    5374            1 :           error ("%<alignas%> in empty declaration with %<enum%> "
    5375              :                  "underlying type");
    5376            1 :           warned = 1;
    5377              :         }
    5378              :     }
    5379              : 
    5380       512713 :   if (!warned && !in_system_header_at (input_location)
    5381       633668 :       && declspecs->storage_class != csc_none)
    5382              :     {
    5383           12 :       warning (0, "useless storage class specifier in empty declaration");
    5384           12 :       warned = 2;
    5385              :     }
    5386              : 
    5387       512881 :   if (!warned && !in_system_header_at (input_location) && declspecs->thread_p)
    5388              :     {
    5389            3 :       warning (0, "useless %qs in empty declaration",
    5390            3 :                declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5391            3 :       warned = 2;
    5392              :     }
    5393              : 
    5394            3 :   if (!warned
    5395       512694 :       && !in_system_header_at (input_location)
    5396       633658 :       && (declspecs->const_p
    5397       120772 :           || declspecs->volatile_p
    5398       120772 :           || declspecs->atomic_p
    5399       120772 :           || declspecs->restrict_p
    5400       120772 :           || declspecs->address_space))
    5401              :     {
    5402            8 :       warning (0, "useless type qualifier in empty declaration");
    5403            8 :       warned = 2;
    5404              :     }
    5405              : 
    5406       512694 :   if (!warned && !in_system_header_at (input_location)
    5407       633645 :       && declspecs->alignas_p)
    5408              :     {
    5409            4 :       warning (0, "useless %<_Alignas%> in empty declaration");
    5410            4 :       warned = 2;
    5411              :     }
    5412              : 
    5413       512881 :   if (found_tag
    5414       512881 :       && warned == 2
    5415           23 :       && (declspecs->typespec_kind == ctsk_tagref_attrs
    5416           23 :           || declspecs->typespec_kind == ctsk_tagfirstref_attrs))
    5417              :     {
    5418              :       /* Standard attributes after the "struct" or "union" keyword are
    5419              :          only permitted when the contents of the type are defined, or
    5420              :          in the form "struct-or-union attribute-specifier-sequence
    5421              :          identifier;".  If the ';' was not present, attributes were
    5422              :          diagnosed in the parser.  Here, ensure that any other useless
    5423              :          elements of the declaration result in a pedwarn, not just a
    5424              :          warning.  Forward declarations of enum types are not part of
    5425              :          standard C, but handle them the same.  */
    5426            2 :       pedwarn (input_location, 0,
    5427              :                "invalid use of attributes in empty declaration");
    5428            2 :       warned = 1;
    5429              :     }
    5430              : 
    5431       512881 :   if (warned != 1)
    5432              :     {
    5433       512707 :       if (declspecs->declspecs_seen_p
    5434       512707 :           && !declspecs->non_std_attrs_seen_p)
    5435              :         /* An attribute declaration (but not a fallthrough attribute
    5436              :            declaration, which was handled separately); warn if there
    5437              :            are any attributes being ignored (but not if the attributes
    5438              :            were empty).  */
    5439           48 :         c_warn_unused_attributes (declspecs->attrs);
    5440       512659 :       else if (!found_tag)
    5441           10 :         pedwarn (input_location, 0, "empty declaration");
    5442              :     }
    5443       512881 : }
    5444              : 
    5445              : 
    5446              : /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
    5447              :    bits.  SPECS represents declaration specifiers that the grammar
    5448              :    only permits to contain type qualifiers and attributes.  */
    5449              : 
    5450              : qualifier_set
    5451     18791558 : quals_from_declspecs (const struct c_declspecs *specs)
    5452              : {
    5453     37583116 :   auto cv_quals = cv_qualifier ((specs->const_p ? TYPE_QUAL_CONST : 0)
    5454     37149647 :                                 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
    5455     18791558 :                                 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
    5456     18791558 :                                 | (specs->atomic_p ? TYPE_QUAL_ATOMIC : 0));
    5457     18791558 :   gcc_assert (!specs->type
    5458              :               && !specs->decl_attr
    5459              :               && specs->typespec_word == cts_none
    5460              :               && specs->storage_class == csc_none
    5461              :               && !specs->typedef_p
    5462              :               && !specs->explicit_signed_p
    5463              :               && !specs->deprecated_p
    5464              :               && !specs->unavailable_p
    5465              :               && !specs->long_p
    5466              :               && !specs->long_long_p
    5467              :               && !specs->short_p
    5468              :               && !specs->signed_p
    5469              :               && !specs->unsigned_p
    5470              :               && !specs->complex_p
    5471              :               && !specs->inline_p
    5472              :               && !specs->noreturn_p
    5473              :               && !specs->thread_p);
    5474     18791558 :   return {cv_quals, specs->address_space};
    5475              : }
    5476              : 
    5477              : /* Construct an array declarator.  LOC is the location of the
    5478              :    beginning of the array (usually the opening brace).  EXPR is the
    5479              :    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
    5480              :    inside the [] (to be applied to the pointer to which a parameter
    5481              :    array is converted).  STATIC_P is true if "static" is inside the
    5482              :    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
    5483              :    VLA of unspecified length which is nevertheless a complete type,
    5484              :    false otherwise.  The field for the contained declarator is left to
    5485              :    be filled in by set_array_declarator_inner.  */
    5486              : 
    5487              : struct c_declarator *
    5488      1152677 : build_array_declarator (location_t loc,
    5489              :                         tree expr, struct c_declspecs *quals, bool static_p,
    5490              :                         bool vla_unspec_p)
    5491              : {
    5492      1152677 :   struct c_declarator *declarator = XOBNEW (&parser_obstack,
    5493              :                                             struct c_declarator);
    5494      1152677 :   declarator->id_loc = loc;
    5495      1152677 :   declarator->kind = cdk_array;
    5496      1152677 :   declarator->declarator = 0;
    5497      1152677 :   declarator->u.array.dimen = expr;
    5498      1152677 :   if (quals)
    5499              :     {
    5500          966 :       declarator->u.array.attrs = quals->attrs;
    5501          966 :       declarator->u.array.quals = quals_from_declspecs (quals);
    5502              :     }
    5503              :   else
    5504              :     {
    5505      1151711 :       declarator->u.array.attrs = NULL_TREE;
    5506      1151711 :       declarator->u.array.quals = qualifier_set {};
    5507              :     }
    5508      1152677 :   declarator->u.array.static_p = static_p;
    5509      1152677 :   declarator->u.array.vla_unspec_p = vla_unspec_p;
    5510      1152677 :   if (static_p || quals != NULL)
    5511         1069 :     pedwarn_c90 (loc, OPT_Wpedantic,
    5512              :                  "ISO C90 does not support %<static%> or type "
    5513              :                  "qualifiers in parameter array declarators");
    5514      1152677 :   if (vla_unspec_p)
    5515              :     {
    5516          152 :       pedwarn_c90 (loc, OPT_Wpedantic,
    5517              :                    "ISO C90 does not support %<[*]%> array declarators");
    5518          152 :       if (current_scope->parm_flag)
    5519          144 :         current_scope->had_vla_unspec = true;
    5520              :     }
    5521      1152677 :   return declarator;
    5522              : }
    5523              : 
    5524              : /* Set the contained declarator of an array declarator.  DECL is the
    5525              :    declarator, as constructed by build_array_declarator; INNER is what
    5526              :    appears on the left of the [].  */
    5527              : 
    5528              : struct c_declarator *
    5529      1152677 : set_array_declarator_inner (struct c_declarator *decl,
    5530              :                             struct c_declarator *inner)
    5531              : {
    5532      1152677 :   decl->declarator = inner;
    5533      1152677 :   return decl;
    5534              : }
    5535              : 
    5536              : /* Determine whether TYPE is a one-element array type "[1]".  */
    5537              : static bool
    5538       540148 : one_element_array_type_p (const_tree type)
    5539              : {
    5540       540148 :   if (TREE_CODE (type) != ARRAY_TYPE)
    5541              :     return false;
    5542       540148 :   return integer_zerop (array_type_nelts_minus_one (type));
    5543              : }
    5544              : 
    5545              : /* Determine whether TYPE is a zero-length array type "[0]".  */
    5546              : bool
    5547      1484628 : zero_length_array_type_p (const_tree type)
    5548              : {
    5549      1484628 :   if (TREE_CODE (type) == ARRAY_TYPE
    5550      1484628 :       && COMPLETE_TYPE_P (type)
    5551      1397577 :       && TYPE_DOMAIN (type) != NULL_TREE
    5552      2882205 :       && (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
    5553      1395023 :           || integer_all_onesp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))))
    5554         2691 :     return true;
    5555              :   return false;
    5556              : }
    5557              : 
    5558              : /* INIT is a constructor that forms DECL's initializer.  If the final
    5559              :    element initializes a flexible array field, adjust the size of the
    5560              :    DECL with the initializer based on whether the DECL is a union or
    5561              :    a structure.  */
    5562              : 
    5563              : static void
    5564       107476 : add_flexible_array_elts_to_size (tree decl, tree init)
    5565              : {
    5566       107476 :   tree elt, type;
    5567              : 
    5568       107476 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    5569         1628 :     return;
    5570              : 
    5571       105848 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    5572       105848 :   type = TREE_TYPE (elt);
    5573       105848 :   if (flexible_array_member_type_p (type))
    5574              :     {
    5575          227 :       complete_array_type (&type, elt, false);
    5576              :       /* For a structure, add the size of the initializer to the DECL's
    5577              :          size.  */
    5578          227 :       if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    5579              :         {
    5580          217 :           DECL_SIZE (decl)
    5581          217 :             = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5582          217 :           DECL_SIZE_UNIT (decl)
    5583          434 :             = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    5584              :                           TYPE_SIZE_UNIT (type));
    5585              :         }
    5586              :       /* For a union, the DECL's size is the maximum of the current size
    5587              :          and the size of the initializer.  */
    5588              :       else
    5589              :         {
    5590           10 :           DECL_SIZE (decl)
    5591           10 :             = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5592           10 :           DECL_SIZE_UNIT (decl)
    5593           20 :             = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    5594              :                           TYPE_SIZE_UNIT (type));
    5595              :         }
    5596              :     }
    5597              : }
    5598              : 
    5599              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.
    5600              :    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
    5601              :    before the type name, and set *EXPR_CONST_OPERANDS, if
    5602              :    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
    5603              :    appear in a constant expression.  */
    5604              : 
    5605              : tree
    5606    126426755 : groktypename (struct c_type_name *type_name, tree *expr,
    5607              :               bool *expr_const_operands)
    5608              : {
    5609    126426755 :   tree type;
    5610    126426755 :   tree attrs = type_name->specs->attrs;
    5611              : 
    5612    126426755 :   type_name->specs->attrs = NULL_TREE;
    5613              : 
    5614    126426755 :   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
    5615              :                          false, NULL, &attrs, expr, expr_const_operands,
    5616              :                          DEPRECATED_NORMAL);
    5617              : 
    5618              :   /* Apply attributes.  */
    5619    126426755 :   attrs = c_warn_type_attributes (type, attrs);
    5620    126426755 :   decl_attributes (&type, attrs, 0);
    5621              : 
    5622    126426755 :   return type;
    5623              : }
    5624              : 
    5625              : 
    5626              : /* Decode a "typename", such as "int **", returning a ..._TYPE node,
    5627              :    as for groktypename but setting the context to GENERIC_ASSOC.  */
    5628              : 
    5629              : tree
    5630         1535 : grokgenassoc (struct c_type_name *type_name)
    5631              : {
    5632         1535 :   tree type;
    5633         1535 :   tree attrs = type_name->specs->attrs;
    5634              : 
    5635         1535 :   type_name->specs->attrs = NULL_TREE;
    5636              : 
    5637         1535 :   type = grokdeclarator (type_name->declarator, type_name->specs, GENERIC_ASSOC,
    5638              :                          false, NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
    5639              : 
    5640              :   /* Apply attributes.  */
    5641         1535 :   attrs = c_warn_type_attributes (type, attrs);
    5642         1535 :   decl_attributes (&type, attrs, 0);
    5643              : 
    5644         1535 :   return type;
    5645              : }
    5646              : 
    5647              : 
    5648              : /* Looks up the most recent pushed declaration corresponding to DECL.  */
    5649              : 
    5650              : static tree
    5651     95148521 : lookup_last_decl (tree decl)
    5652              : {
    5653     95148521 :   tree last_decl = lookup_name (DECL_NAME (decl));
    5654     95148521 :   if (!last_decl)
    5655     92427609 :     last_decl = lookup_name_in_scope (DECL_NAME (decl), external_scope);
    5656     95148521 :   return last_decl;
    5657              : }
    5658              : 
    5659              : /* Wrapper for decl_attributes that adds some implicit attributes
    5660              :    to VAR_DECLs or FUNCTION_DECLs.  */
    5661              : 
    5662              : static tree
    5663     66408898 : c_decl_attributes (tree *node, tree attributes, int flags)
    5664              : {
    5665              :   /* Add implicit "omp declare target" attribute if requested.  */
    5666     66408898 :   if (vec_safe_length (current_omp_declare_target_attribute)
    5667         9170 :       && ((VAR_P (*node) && is_global_var (*node))
    5668         2729 :           || TREE_CODE (*node) == FUNCTION_DECL))
    5669              :     {
    5670         1132 :       if (VAR_P (*node) && !omp_mappable_type (TREE_TYPE (*node)))
    5671           13 :         attributes = tree_cons (get_identifier ("omp declare target implicit"),
    5672              :                                 NULL_TREE, attributes);
    5673              :       else
    5674         1119 :         attributes = tree_cons (get_identifier ("omp declare target"),
    5675              :                                 NULL_TREE, attributes);
    5676         1132 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5677              :         {
    5678         1001 :           int device_type
    5679         1001 :             = current_omp_declare_target_attribute->last ().device_type;
    5680         1001 :           device_type = MAX (device_type, 0);
    5681         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    5682         1001 :               && !lookup_attribute ("omp declare target host", attributes))
    5683            2 :             attributes
    5684            2 :               = tree_cons (get_identifier ("omp declare target host"),
    5685              :                            NULL_TREE, attributes);
    5686         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    5687         1001 :               && !lookup_attribute ("omp declare target nohost", attributes))
    5688            2 :             attributes
    5689            2 :               = tree_cons (get_identifier ("omp declare target nohost"),
    5690              :                            NULL_TREE, attributes);
    5691              : 
    5692         1001 :           int indirect
    5693         1001 :             = current_omp_declare_target_attribute->last ().indirect;
    5694         1001 :           if (indirect && !lookup_attribute ("omp declare target indirect",
    5695              :                                              attributes))
    5696           10 :             attributes
    5697           10 :               = tree_cons (get_identifier ("omp declare target indirect"),
    5698              :                            NULL_TREE, attributes);
    5699              :         }
    5700              :     }
    5701              : 
    5702     66408898 :   if (flag_openmp || flag_openmp_simd)
    5703              :     {
    5704              :       bool diagnosed = false;
    5705      1476653 :       for (tree *pa = &attributes; *pa; )
    5706              :         {
    5707       948791 :           if (is_attribute_namespace_p ("omp", *pa))
    5708              :             {
    5709           65 :               tree name = get_attribute_name (*pa);
    5710           65 :               if (is_attribute_p ("directive", name)
    5711            0 :                   || is_attribute_p ("sequence", name)
    5712           65 :                   || is_attribute_p ("decl", name))
    5713              :                 {
    5714           65 :                   const char *p = NULL;
    5715           65 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    5716           12 :                     p = IDENTIFIER_POINTER (name);
    5717          118 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    5718              :                     {
    5719           53 :                       tree d = TREE_VALUE (a);
    5720           53 :                       gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
    5721           96 :                       if (TREE_PUBLIC (d)
    5722           43 :                           && (VAR_P (*node)
    5723            2 :                               || TREE_CODE (*node) == FUNCTION_DECL)
    5724           96 :                           && c_maybe_parse_omp_decl (*node, d))
    5725           43 :                         continue;
    5726           10 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    5727              :                     }
    5728           65 :                   if (p && !diagnosed)
    5729              :                     {
    5730           22 :                       error ("%<omp::%s%> not allowed to be specified in "
    5731              :                              "this context", p);
    5732           22 :                       diagnosed = true;
    5733              :                     }
    5734           65 :                   if (p)
    5735              :                     {
    5736           22 :                       *pa = TREE_CHAIN (*pa);
    5737           22 :                       continue;
    5738              :                     }
    5739              :                 }
    5740              :             }
    5741       948769 :           pa = &TREE_CHAIN (*pa);
    5742              :         }
    5743              :     }
    5744              : 
    5745              :   /* Look up the current declaration with all the attributes merged
    5746              :      so far so that attributes on the current declaration that's
    5747              :      about to be pushed that conflict with the former can be detected,
    5748              :      diagnosed, and rejected as appropriate.  To match the C++ FE, do
    5749              :      not pass an error_mark_node when we found an undeclared variable.  */
    5750     66408898 :   tree last_decl = lookup_last_decl (*node);
    5751     66408898 :   if (last_decl == error_mark_node)
    5752           20 :     last_decl = NULL_TREE;
    5753     66408898 :   tree attr = decl_attributes (node, attributes, flags, last_decl);
    5754     66408897 :   if (VAR_P (*node) && DECL_THREAD_LOCAL_P (*node))
    5755              :     {
    5756              :       // tls_model attribute can set a stronger TLS access model.
    5757         2868 :       tls_model model = DECL_TLS_MODEL (*node);
    5758         2868 :       tls_model default_model = decl_default_tls_model (*node);
    5759         2868 :       if (default_model > model)
    5760         1605 :         set_decl_tls_model (*node, default_model);
    5761              :     }
    5762     66408897 :   return attr;
    5763              : }
    5764              : 
    5765              : 
    5766              : /* Decode a declarator in an ordinary declaration or data definition.
    5767              :    This is called as soon as the type information and variable name
    5768              :    have been parsed, before parsing the initializer if any.
    5769              :    Here we create the ..._DECL node, fill in its type,
    5770              :    and (if DO_PUSH) put it on the list of decls for the current context.
    5771              :    When nonnull, set *LASTLOC to the location of the prior declaration
    5772              :    of the same entity if one exists.
    5773              :    The ..._DECL node is returned as the value.
    5774              : 
    5775              :    Exception: for arrays where the length is not specified,
    5776              :    the type is left null, to be filled in by `finish_decl'.
    5777              : 
    5778              :    Function definitions do not come here; they go to start_function
    5779              :    instead.  However, external and forward declarations of functions
    5780              :    do go through here.  Structure field declarations are done by
    5781              :    grokfield and not through here.  */
    5782              : 
    5783              : tree
    5784     28739647 : start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
    5785              :             bool initialized, tree attributes, bool do_push /* = true */,
    5786              :             location_t *lastloc /* = NULL */)
    5787              : {
    5788     28739647 :   tree decl;
    5789     28739647 :   tree old_decl;
    5790     28739647 :   tree tem;
    5791     28739647 :   tree expr = NULL_TREE;
    5792     28739647 :   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
    5793              : 
    5794              :   /* An object declared as __attribute__((unavailable)) suppresses
    5795              :      warnings and errors from __attribute__((deprecated/unavailable))
    5796              :      components.
    5797              :      An object declared as __attribute__((deprecated)) suppresses
    5798              :      warnings of uses of other deprecated items.  */
    5799     28739647 :   if (lookup_attribute ("unavailable", attributes))
    5800              :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
    5801     28739623 :   else if (lookup_attribute ("deprecated", attributes))
    5802        30568 :     deprecated_state = DEPRECATED_SUPPRESS;
    5803              : 
    5804     28739647 :   decl = grokdeclarator (declarator, declspecs,
    5805              :                          NORMAL, initialized, NULL, &attributes, &expr, NULL,
    5806              :                          deprecated_state);
    5807     28739647 :   if (!decl || decl == error_mark_node)
    5808              :     return NULL_TREE;
    5809              : 
    5810     28739623 :   old_decl = lookup_last_decl (decl);
    5811              : 
    5812     28739623 :   if (tree lastdecl = lastloc ? old_decl : NULL_TREE)
    5813      5019123 :     if (lastdecl != error_mark_node)
    5814      5019114 :       *lastloc = DECL_SOURCE_LOCATION (lastdecl);
    5815              : 
    5816              :   /* Make sure the size expression is evaluated at this point.  */
    5817     28739623 :   if (expr && !current_scope->parm_flag)
    5818        12982 :     add_stmt (fold_convert (void_type_node, expr));
    5819              : 
    5820     13403608 :   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))
    5821     28739625 :       && TREE_PUBLIC (decl))
    5822            1 :     warning (OPT_Wmain, "%q+D is usually a function", decl);
    5823              : 
    5824           14 :   if (warn_missing_variable_declarations && VAR_P (decl)
    5825     28739636 :       && !DECL_EXTERNAL (decl) && TREE_PUBLIC (decl) && old_decl == NULL_TREE)
    5826            5 :     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_variable_declarations,
    5827              :                 "no previous declaration for %qD", decl);
    5828              : 
    5829     28739623 :   if (initialized)
    5830              :     /* Is it valid for this decl to have an initializer at all?
    5831              :        If not, set INITIALIZED to zero, which will indirectly
    5832              :        tell 'finish_decl' to ignore the initializer once it is parsed.  */
    5833      6420402 :     switch (TREE_CODE (decl))
    5834              :       {
    5835            6 :       case TYPE_DECL:
    5836            6 :         error ("typedef %qD is initialized (use %<__typeof__%> instead)", decl);
    5837            6 :         initialized = false;
    5838            6 :         break;
    5839              : 
    5840            9 :       case FUNCTION_DECL:
    5841            9 :         error ("function %qD is initialized like a variable", decl);
    5842            9 :         initialized = false;
    5843            9 :         break;
    5844              : 
    5845           49 :       case PARM_DECL:
    5846              :         /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
    5847           49 :         error ("parameter %qD is initialized", decl);
    5848           49 :         initialized = false;
    5849           49 :         break;
    5850              : 
    5851      6420338 :       default:
    5852              :         /* Don't allow initializations for incomplete types except for
    5853              :            arrays which might be completed by the initialization.  */
    5854              : 
    5855              :         /* This can happen if the array size is an undefined macro.
    5856              :            We already gave a warning, so we don't need another one.  */
    5857      6420338 :         if (TREE_TYPE (decl) == error_mark_node)
    5858              :           initialized = false;
    5859      6420316 :         else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
    5860              :           {
    5861              :             /* A complete type is ok if size is fixed.  If the size is
    5862              :                variable, an empty initializer is OK and nonempty
    5863              :                initializers will be diagnosed in the parser.  */
    5864              :           }
    5865        12883 :         else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
    5866              :           {
    5867            3 :             error ("variable %qD has initializer but incomplete type", decl);
    5868            3 :             initialized = false;
    5869              :           }
    5870              :       }
    5871              : 
    5872           67 :   if (initialized)
    5873              :     {
    5874      6420313 :       if (current_scope == file_scope)
    5875       157356 :         TREE_STATIC (decl) = 1;
    5876              : 
    5877              :       /* Tell 'pushdecl' this is an initialized decl
    5878              :          even though we don't yet have the initializer expression.
    5879              :          Also tell 'finish_decl' it may store the real initializer.  */
    5880      6420313 :       DECL_INITIAL (decl) = error_mark_node;
    5881              :     }
    5882              : 
    5883              :   /* If this is a function declaration, write a record describing it to the
    5884              :      prototypes file (if requested).  */
    5885              : 
    5886     28739623 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5887     15336015 :     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
    5888              : 
    5889              :   /* ANSI specifies that a tentative definition which is not merged with
    5890              :      a non-tentative definition behaves exactly like a definition with an
    5891              :      initializer equal to zero.  (Section 3.7.2)
    5892              : 
    5893              :      -fno-common gives strict ANSI behavior, though this tends to break
    5894              :      a large body of code that grew up without this rule.
    5895              : 
    5896              :      Thread-local variables are never common, since there's no entrenched
    5897              :      body of code to break, and it allows more efficient variable references
    5898              :      in the presence of dynamic linking.  */
    5899              : 
    5900     28739623 :   if (VAR_P (decl)
    5901      9005353 :       && !initialized
    5902      2585040 :       && TREE_PUBLIC (decl)
    5903       991076 :       && !DECL_THREAD_LOCAL_P (decl)
    5904     29728307 :       && !flag_no_common)
    5905          128 :     DECL_COMMON (decl) = 1;
    5906              : 
    5907              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5908     28739623 :   c_decl_attributes (&decl, attributes, 0);
    5909              : 
    5910              :   /* Handle gnu_inline attribute.  */
    5911     28739622 :   if (declspecs->inline_p
    5912         1056 :       && !flag_gnu89_inline
    5913         1024 :       && TREE_CODE (decl) == FUNCTION_DECL
    5914     28740638 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
    5915          993 :           || current_function_decl))
    5916              :     {
    5917           46 :       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
    5918              :         ;
    5919           37 :       else if (declspecs->storage_class != csc_static)
    5920           37 :         DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
    5921              :     }
    5922              : 
    5923     28739622 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5924     15336014 :       && DECL_DECLARED_INLINE_P (decl)
    5925         1046 :       && DECL_UNINLINABLE (decl)
    5926     28739624 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5927              :     {
    5928            2 :       auto_urlify_attributes sentinel;
    5929            2 :       warning (OPT_Wattributes, "inline function %q+D given attribute %qs",
    5930              :                decl, "noinline");
    5931            2 :     }
    5932              : 
    5933              :   /* C99 6.7.4p3: An inline definition of a function with external
    5934              :      linkage shall not contain a definition of a modifiable object
    5935              :      with static storage duration...  */
    5936     28739622 :   if (VAR_P (decl)
    5937      9005353 :       && current_scope != file_scope
    5938      7849712 :       && TREE_STATIC (decl)
    5939        79634 :       && !TREE_READONLY (decl)
    5940        76325 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    5941     28739692 :       && DECL_EXTERNAL (current_function_decl))
    5942            7 :     record_inline_static (input_location, current_function_decl,
    5943              :                           decl, csi_modifiable);
    5944              : 
    5945     28739622 :   if (c_dialect_objc ()
    5946            0 :       && VAR_OR_FUNCTION_DECL_P (decl))
    5947            0 :       objc_check_global_decl (decl);
    5948              : 
    5949              :   /* To enable versions to be created across TU's we mark and mangle all
    5950              :      non-default versioned functions.  */
    5951     28739622 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5952              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
    5953              :       && get_target_version (decl).is_valid ())
    5954              :     {
    5955              :       maybe_mark_function_versioned (decl);
    5956              :       if (current_scope != file_scope)
    5957              :         error ("versioned declarations are only allowed at file scope");
    5958              :     }
    5959              : 
    5960              :   /* Add this decl to the current scope.
    5961              :      TEM may equal DECL or it may be a previous decl of the same name.  */
    5962     28739622 :   if (do_push)
    5963              :     {
    5964     28739244 :       tem = pushdecl (decl);
    5965              : 
    5966     28739244 :       if (initialized && DECL_EXTERNAL (tem))
    5967              :         {
    5968           27 :           DECL_EXTERNAL (tem) = 0;
    5969           27 :           TREE_STATIC (tem) = 1;
    5970              :         }
    5971              : 
    5972              :       return tem;
    5973              :     }
    5974              :   else
    5975          378 :     return decl;
    5976              : }
    5977              : 
    5978              : /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
    5979              :    DECL or the non-array element type if DECL is an uninitialized array.
    5980              :    If that type has a const member, diagnose this. */
    5981              : 
    5982              : static void
    5983            7 : diagnose_uninitialized_cst_member (tree decl, tree type)
    5984              : {
    5985            7 :   tree field;
    5986           17 :   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
    5987              :     {
    5988           10 :       tree field_type;
    5989           10 :       if (TREE_CODE (field) != FIELD_DECL)
    5990            0 :         continue;
    5991           10 :       field_type = strip_array_types (TREE_TYPE (field));
    5992              : 
    5993           10 :       if (TYPE_QUALS (field_type).has (TYPE_QUAL_CONST))
    5994              :         {
    5995            5 :           auto_diagnostic_group d;
    5996            5 :           if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    5997              :                           "uninitialized const member in %qT is invalid in C++",
    5998            5 :                           strip_array_types (TREE_TYPE (decl))))
    5999            5 :             inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
    6000            5 :         }
    6001              : 
    6002           10 :       if (RECORD_OR_UNION_TYPE_P (field_type))
    6003            2 :         diagnose_uninitialized_cst_member (decl, field_type);
    6004              :     }
    6005            7 : }
    6006              : 
    6007              : /* Finish processing of a declaration;
    6008              :    install its initial value.
    6009              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    6010              :    If the length of an array type is not known before,
    6011              :    it must be determined now, from the initial value, or it is an error.
    6012              : 
    6013              :    INIT_LOC is the location of the initial value.  */
    6014              : 
    6015              : void
    6016    161489711 : finish_decl (tree decl, location_t init_loc, tree init,
    6017              :              tree origtype, tree asmspec_tree)
    6018              : {
    6019    161489711 :   tree type;
    6020    161489711 :   bool was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
    6021    161489711 :   const char *asmspec = 0;
    6022              : 
    6023              :   /* If a name was specified, get the string.  */
    6024    152481335 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6025    176825725 :       && DECL_FILE_SCOPE_P (decl))
    6026     16493172 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    6027    161489711 :   if (asmspec_tree)
    6028       879888 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    6029              : 
    6030    161489711 :   if (VAR_P (decl)
    6031      9008376 :       && TREE_STATIC (decl)
    6032    162557509 :       && global_bindings_p ())
    6033              :     /* So decl is a global variable. Record the types it uses
    6034              :        so that we can decide later to emit debug info for them.  */
    6035       984925 :     record_types_used_by_current_var_decl (decl);
    6036              : 
    6037              :   /* If `start_decl' didn't like having an initialization, ignore it now.  */
    6038    161489711 :   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
    6039              :     init = NULL_TREE;
    6040              : 
    6041              :   /* Don't crash if parm is initialized.  */
    6042    161489711 :   if (TREE_CODE (decl) == PARM_DECL)
    6043              :     init = NULL_TREE;
    6044              : 
    6045     33081801 :   if (init)
    6046      6423337 :     store_init_value (init_loc, decl, init, origtype);
    6047              : 
    6048    161489711 :   if (c_dialect_objc () && (VAR_OR_FUNCTION_DECL_P (decl)
    6049            0 :                             || TREE_CODE (decl) == FIELD_DECL))
    6050            0 :     objc_check_decl (decl);
    6051              : 
    6052    161489711 :   type = TREE_TYPE (decl);
    6053              : 
    6054              :   /* Deduce size of array from initialization, if not already known.
    6055              :      This is only needed for an initialization in the current scope;
    6056              :      it must not be done for a file-scope initialization of a
    6057              :      declaration with external linkage, redeclared in an inner scope
    6058              :      with the outer declaration shadowed in an intermediate scope.  */
    6059    161489711 :   if (TREE_CODE (type) == ARRAY_TYPE
    6060       864383 :       && TYPE_DOMAIN (type) == NULL_TREE
    6061        20512 :       && TREE_CODE (decl) != TYPE_DECL
    6062    161510125 :       && !(TREE_PUBLIC (decl) && current_scope != file_scope))
    6063              :     {
    6064        20227 :       bool do_default
    6065        20227 :         = !TREE_STATIC (decl) && !DECL_EXTERNAL (decl);
    6066        20227 :       int failure
    6067        20227 :         = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
    6068              :                                do_default);
    6069              : 
    6070              :       /* Get the completed type made by complete_array_type.  */
    6071        20227 :       type = TREE_TYPE (decl);
    6072              : 
    6073        20227 :       switch (failure)
    6074              :         {
    6075            0 :         case 1:
    6076            0 :           error ("initializer fails to determine size of %q+D", decl);
    6077            0 :           break;
    6078              : 
    6079         7372 :         case 2:
    6080         7372 :           if (do_default)
    6081            1 :             error ("array size missing in %q+D", decl);
    6082         7371 :           else if (!TREE_PUBLIC (decl))
    6083           37 :             pedwarn_c23 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    6084              :                          "array size missing in %q+D", decl);
    6085              :           break;
    6086              : 
    6087            3 :         case 3:
    6088            3 :           error ("zero or negative size array %q+D", decl);
    6089            3 :           break;
    6090              : 
    6091        12852 :         case 0:
    6092              :           /* For global variables, update the copy of the type that
    6093              :              exists in the binding.  */
    6094        12852 :           if (TREE_PUBLIC (decl))
    6095              :             {
    6096         3844 :               struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
    6097         7688 :               while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    6098         3844 :                 b_ext = b_ext->shadowed;
    6099         3844 :               if (b_ext && TREE_CODE (decl) == TREE_CODE (b_ext->decl))
    6100              :                 {
    6101         3844 :                   if (b_ext->u.type && comptypes (b_ext->u.type, type))
    6102          176 :                     b_ext->u.type = composite_type (b_ext->u.type, type);
    6103              :                   else
    6104         3668 :                     b_ext->u.type = type;
    6105              :                 }
    6106              :             }
    6107              :           break;
    6108              : 
    6109            0 :         default:
    6110            0 :           gcc_unreachable ();
    6111              :         }
    6112              : 
    6113        20227 :       if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
    6114        11983 :         TREE_TYPE (DECL_INITIAL (decl)) = type;
    6115              : 
    6116        20227 :       relayout_decl (decl);
    6117              :     }
    6118              : 
    6119              :   /* Look for braced array initializers for character arrays and
    6120              :      recursively convert them into STRING_CSTs.  */
    6121    161489711 :   if (tree init = DECL_INITIAL (decl))
    6122    134833679 :     DECL_INITIAL (decl) = braced_lists_to_strings (type, init);
    6123              : 
    6124    161489711 :   if (VAR_P (decl))
    6125              :     {
    6126      9008376 :       if (init && TREE_CODE (init) == CONSTRUCTOR)
    6127       107476 :         add_flexible_array_elts_to_size (decl, init);
    6128              : 
    6129      9008376 :       complete_flexible_array_elts (DECL_INITIAL (decl));
    6130              : 
    6131      9008376 :       if (is_global_var (decl))
    6132              :         {
    6133      1239822 :           type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    6134      1239822 :                                        ? TCTX_THREAD_STORAGE
    6135              :                                        : TCTX_STATIC_STORAGE);
    6136      1239822 :           if (!verify_type_context (input_location, context, TREE_TYPE (decl)))
    6137            0 :             TREE_TYPE (decl) = error_mark_node;
    6138              :         }
    6139              : 
    6140      9016490 :       if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node
    6141      9016387 :           && COMPLETE_TYPE_P (TREE_TYPE (decl)))
    6142          107 :         layout_decl (decl, 0);
    6143              : 
    6144      9008376 :       if (DECL_SIZE (decl) == NULL_TREE
    6145              :           /* Don't give an error if we already gave one earlier.  */
    6146         8007 :           && TREE_TYPE (decl) != error_mark_node
    6147      9016280 :           && (TREE_STATIC (decl)
    6148              :               /* A static variable with an incomplete type
    6149              :                  is an error if it is initialized.
    6150              :                  Also if it is not file scope.
    6151              :                  Also if it is thread-local (in C23).
    6152              :                  Otherwise, let it through, but if it is not `extern'
    6153              :                  then it may cause an error message later.  */
    6154          309 :               ? (DECL_INITIAL (decl) != NULL_TREE
    6155          309 :                  || !DECL_FILE_SCOPE_P (decl)
    6156          306 :                  || (flag_isoc23 && DECL_THREAD_LOCAL_P (decl)))
    6157              :               /* An automatic variable with an incomplete type
    6158              :                  is an error.  */
    6159         7595 :               : !DECL_EXTERNAL (decl)))
    6160              :          {
    6161           19 :            error ("storage size of %q+D isn%'t known", decl);
    6162           19 :            TREE_TYPE (decl) = error_mark_node;
    6163              :          }
    6164              : 
    6165     17831526 :       if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    6166      8738209 :           || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    6167       284862 :           && DECL_SIZE (decl) == NULL_TREE
    6168      9008664 :           && TREE_STATIC (decl))
    6169          135 :         incomplete_record_decls.safe_push (decl);
    6170              : 
    6171      9008376 :       if (is_global_var (decl)
    6172      1239822 :           && DECL_SIZE (decl) != NULL_TREE
    6173     10240234 :           && TREE_TYPE (decl) != error_mark_node)
    6174              :         {
    6175      1231838 :           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    6176      1231835 :             constant_expression_warning (DECL_SIZE (decl));
    6177              :           else
    6178              :             {
    6179            3 :               error ("storage size of %q+D isn%'t constant", decl);
    6180            3 :               TREE_TYPE (decl) = error_mark_node;
    6181              :             }
    6182              :         }
    6183              : 
    6184      9008376 :       if (TREE_USED (type))
    6185              :         {
    6186            4 :           TREE_USED (decl) = 1;
    6187            4 :           DECL_READ_P (decl) = 1;
    6188              :         }
    6189              :     }
    6190              : 
    6191              :   /* If this is a function and an assembler name is specified, reset DECL_RTL
    6192              :      so we can give it its new name.  Also, update builtin_decl if it
    6193              :      was a normal built-in.  */
    6194    161489711 :   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
    6195              :     {
    6196       866692 :       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
    6197        72610 :         set_builtin_user_assembler_name (decl, asmspec);
    6198       866692 :       set_user_assembler_name (decl, asmspec);
    6199              :     }
    6200              : 
    6201              :   /* If #pragma weak was used, mark the decl weak now.  */
    6202    161489711 :   maybe_apply_pragma_weak (decl);
    6203              : 
    6204              :   /* Output the assembler code and/or RTL code for variables and functions,
    6205              :      unless the type is an undefined structure or union.
    6206              :      If not, it will get done when the type is completed.  */
    6207              : 
    6208    161489711 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    6209              :     {
    6210              :       /* Determine the ELF visibility.  */
    6211     24344390 :       if (TREE_PUBLIC (decl))
    6212     16467788 :         c_determine_visibility (decl);
    6213              : 
    6214              :       /* This is a no-op in c-lang.cc or something real in objc-act.cc.  */
    6215     24344390 :       if (c_dialect_objc ())
    6216            0 :         objc_check_decl (decl);
    6217              : 
    6218     24344390 :       if (asmspec)
    6219              :         {
    6220              :           /* If this is not a static variable, issue a warning.
    6221              :              It doesn't make any sense to give an ASMSPEC for an
    6222              :              ordinary, non-register local variable.  Historically,
    6223              :              GCC has accepted -- but ignored -- the ASMSPEC in
    6224              :              this case.  */
    6225       880934 :           if (!DECL_FILE_SCOPE_P (decl)
    6226         1046 :               && VAR_P (decl)
    6227         1046 :               && !C_DECL_REGISTER (decl)
    6228       879896 :               && !TREE_STATIC (decl))
    6229            1 :             warning (0, "ignoring %<asm%> specifier for non-static local "
    6230              :                      "variable %q+D", decl);
    6231              :           else
    6232       879887 :             set_user_assembler_name (decl, asmspec);
    6233              :         }
    6234              : 
    6235     24344390 :       if (DECL_FILE_SCOPE_P (decl))
    6236              :         {
    6237     16493172 :           if (DECL_INITIAL (decl) == NULL_TREE
    6238     16493172 :               || DECL_INITIAL (decl) == error_mark_node)
    6239              :             /* Don't output anything
    6240              :                when a tentative file-scope definition is seen.
    6241              :                But at end of compilation, do output code for them.  */
    6242     16335621 :             DECL_DEFER_OUTPUT (decl) = 1;
    6243     16493172 :           if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl))
    6244           69 :             DECL_HARD_REGISTER (decl) = 1;
    6245     16493172 :           rest_of_decl_compilation (decl, true, 0);
    6246              : 
    6247     16493172 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6248              :             {
    6249     15335947 :               tree parms = DECL_ARGUMENTS (decl);
    6250     15335947 :               const bool builtin = fndecl_built_in_p (decl);
    6251     15335947 :               if (tree access = build_attr_access_from_parms (parms, !builtin))
    6252       348858 :                 decl_attributes (&decl, access, 0);
    6253              :             }
    6254              :         }
    6255              :       else
    6256              :         {
    6257              :           /* In conjunction with an ASMSPEC, the `register'
    6258              :              keyword indicates that we should place the variable
    6259              :              in a particular register.  */
    6260      7851218 :           if (asmspec && C_DECL_REGISTER (decl))
    6261              :             {
    6262         1038 :               DECL_HARD_REGISTER (decl) = 1;
    6263              :               /* This cannot be done for a structure with volatile
    6264              :                  fields, on which DECL_REGISTER will have been
    6265              :                  reset.  */
    6266         1038 :               if (!DECL_REGISTER (decl))
    6267            1 :                 error ("cannot put object with volatile field into register");
    6268              :             }
    6269              : 
    6270      7851218 :           if (TREE_CODE (decl) != FUNCTION_DECL)
    6271              :             {
    6272              :               /* If we're building a variable sized type, and we might be
    6273              :                  reachable other than via the top of the current binding
    6274              :                  level, then create a new BIND_EXPR so that we deallocate
    6275              :                  the object at the right time.  */
    6276              :               /* Note that DECL_SIZE can be null due to errors.  */
    6277      7851151 :               if (DECL_SIZE (decl)
    6278      7851105 :                   && !TREE_CONSTANT (DECL_SIZE (decl))
    6279      7858542 :                   && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    6280              :                 {
    6281         1337 :                   tree bind;
    6282         1337 :                   bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    6283         1337 :                   TREE_SIDE_EFFECTS (bind) = 1;
    6284         1337 :                   add_stmt (bind);
    6285         1337 :                   BIND_EXPR_BODY (bind) = push_stmt_list ();
    6286              :                 }
    6287      7851151 :               add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
    6288              :                                     DECL_EXPR, decl));
    6289              :             }
    6290              :         }
    6291              : 
    6292              : 
    6293     24344390 :       if (!DECL_FILE_SCOPE_P (decl))
    6294              :         {
    6295              :           /* Recompute the RTL of a local array now
    6296              :              if it used to be an incomplete type.  */
    6297      7851218 :           if (was_incomplete && !is_global_var (decl))
    6298              :             {
    6299              :               /* If we used it already as memory, it must stay in memory.  */
    6300         5433 :               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    6301              :               /* If it's still incomplete now, no init will save it.  */
    6302         5433 :               if (DECL_SIZE (decl) == NULL_TREE)
    6303          109 :                 DECL_INITIAL (decl) = NULL_TREE;
    6304              :             }
    6305              :         }
    6306              :     }
    6307              : 
    6308    161489711 :   if (TREE_CODE (decl) == TYPE_DECL)
    6309              :     {
    6310      4503903 :       if (!DECL_FILE_SCOPE_P (decl)
    6311      4503903 :           && c_type_variably_modified_p (TREE_TYPE (decl)))
    6312         5321 :         add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6313              : 
    6314      8622876 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
    6315              :     }
    6316              : 
    6317              :   /* Install a cleanup (aka destructor) if one was given.  */
    6318    161489711 :   if (VAR_P (decl) && !TREE_STATIC (decl))
    6319              :     {
    6320      7940575 :       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
    6321      7940575 :       if (attr)
    6322              :         {
    6323          140 :           tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
    6324          140 :           tree cleanup_decl = lookup_name (cleanup_id);
    6325          140 :           tree cleanup;
    6326          140 :           vec<tree, va_gc> *v;
    6327              : 
    6328              :           /* Build "cleanup(&decl)" for the destructor.  */
    6329          140 :           cleanup = build_unary_op (input_location, ADDR_EXPR, decl, false);
    6330          140 :           vec_alloc (v, 1);
    6331          140 :           v->quick_push (cleanup);
    6332          140 :           cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
    6333          140 :                                                vNULL, cleanup_decl, v, NULL);
    6334          140 :           vec_free (v);
    6335              : 
    6336              :           /* Don't warn about decl unused; the cleanup uses it.  */
    6337          140 :           TREE_USED (decl) = 1;
    6338          140 :           TREE_USED (cleanup_decl) = 1;
    6339          140 :           DECL_READ_P (decl) = 1;
    6340              : 
    6341          140 :           push_cleanup (decl, cleanup, false);
    6342              :         }
    6343              :     }
    6344              : 
    6345    161489711 :   if (warn_cxx_compat
    6346        22777 :       && VAR_P (decl)
    6347         7659 :       && !DECL_EXTERNAL (decl)
    6348    161496913 :       && DECL_INITIAL (decl) == NULL_TREE)
    6349              :     {
    6350         2412 :       type = strip_array_types (type);
    6351         2412 :       if (TREE_READONLY (decl))
    6352            6 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    6353              :                     "uninitialized %<const %D%> is invalid in C++", decl);
    6354         2406 :       else if (RECORD_OR_UNION_TYPE_P (type)
    6355         2406 :                && C_TYPE_FIELDS_READONLY (type))
    6356            5 :         diagnose_uninitialized_cst_member (decl, type);
    6357              :     }
    6358              : 
    6359    161489711 :   if (flag_openmp
    6360       524338 :       && VAR_P (decl)
    6361    161514310 :       && lookup_attribute ("omp declare target implicit",
    6362        24599 :                            DECL_ATTRIBUTES (decl)))
    6363              :     {
    6364           13 :       DECL_ATTRIBUTES (decl)
    6365           13 :         = remove_attribute ("omp declare target implicit",
    6366           13 :                             DECL_ATTRIBUTES (decl));
    6367           13 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    6368            9 :         error ("%q+D in declare target directive does not have mappable type",
    6369              :                decl);
    6370            4 :       else if (!lookup_attribute ("omp declare target",
    6371            4 :                                   DECL_ATTRIBUTES (decl))
    6372            8 :                && !lookup_attribute ("omp declare target link",
    6373            4 :                                      DECL_ATTRIBUTES (decl)))
    6374              :         {
    6375            4 :           DECL_ATTRIBUTES (decl)
    6376            4 :             = tree_cons (get_identifier ("omp declare target"),
    6377            4 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    6378            4 :             symtab_node *node = symtab_node::get (decl);
    6379            4 :             if (node != NULL)
    6380              :               {
    6381            4 :                 node->offloadable = 1;
    6382            4 :                 if (ENABLE_OFFLOADING)
    6383              :                   {
    6384              :                     g->have_offload = true;
    6385              :                     if (is_a <varpool_node *> (node))
    6386              :                       vec_safe_push (offload_vars, decl);
    6387              :                   }
    6388              :               }
    6389              :         }
    6390              :     }
    6391              : 
    6392              :   /* This is the last point we can lower alignment so give the target the
    6393              :      chance to do so.  */
    6394    161489711 :   if (VAR_P (decl)
    6395      9008376 :       && !is_global_var (decl)
    6396    169258265 :       && !DECL_HARD_REGISTER (decl))
    6397      7767516 :     targetm.lower_local_decl_alignment (decl);
    6398              : 
    6399    161489711 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    6400    161489711 : }
    6401              : 
    6402              : /* Given a parsed parameter declaration, decode it into a PARM_DECL.
    6403              :    EXPR is NULL or a pointer to an expression that needs to be
    6404              :    evaluated for the side effects of array size expressions in the
    6405              :    parameters.  */
    6406              : 
    6407              : tree
    6408            0 : grokparm (const struct c_parm *parm, tree *expr)
    6409              : {
    6410            0 :   tree attrs = parm->attrs;
    6411            0 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
    6412            0 :                               NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
    6413              : 
    6414            0 :   decl_attributes (&decl, attrs, 0);
    6415              : 
    6416            0 :   return decl;
    6417              : }
    6418              : 
    6419              : 
    6420              : 
    6421              : /* Given a parsed parameter declaration, decode it into a PARM_DECL
    6422              :    and push that on the current scope.  EXPR is a pointer to an
    6423              :    expression that needs to be evaluated for the side effects of array
    6424              :    size expressions in the parameters.  */
    6425              : 
    6426              : void
    6427    128385248 : push_parm_decl (const struct c_parm *parm, tree *expr)
    6428              : {
    6429    128385248 :   tree attrs = parm->attrs;
    6430    128385248 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
    6431    128385248 :                               &attrs, expr, NULL, DEPRECATED_NORMAL);
    6432    128385248 :   if (decl && DECL_P (decl))
    6433    128385248 :     DECL_SOURCE_LOCATION (decl) = parm->loc;
    6434              : 
    6435    128385248 :   decl_attributes (&decl, attrs, 0);
    6436              : 
    6437    128385248 :   decl = pushdecl (decl);
    6438              : 
    6439    128385248 :   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
    6440    128385248 : }
    6441              : 
    6442              : /* Mark all the parameter declarations to date as forward decls.
    6443              :    Also diagnose use of this extension.  */
    6444              : 
    6445              : void
    6446           42 : mark_forward_parm_decls (void)
    6447              : {
    6448           42 :   struct c_binding *b;
    6449              : 
    6450           42 :   if (current_scope->had_forward_parm_decls)
    6451           12 :     warning_at (input_location, OPT_Wmultiple_parameter_fwd_decl_lists,
    6452              :                 "more than one list of forward declarations of parameters");
    6453           42 :   if (pedantic && !current_scope->had_forward_parm_decls)
    6454            4 :     pedwarn (input_location, OPT_Wpedantic,
    6455              :              "ISO C forbids forward parameter declarations");
    6456              : 
    6457           42 :   current_scope->had_forward_parm_decls = true;
    6458              : 
    6459           95 :   for (b = current_scope->bindings; b; b = b->prev)
    6460           53 :     if (TREE_CODE (b->decl) == PARM_DECL)
    6461           53 :       TREE_ASM_WRITTEN (b->decl) = 1;
    6462           42 : }
    6463              : 
    6464              : /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
    6465              :    literal, which may be an incomplete array type completed by the
    6466              :    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
    6467              :    literal.  NON_CONST is true if the initializers contain something
    6468              :    that cannot occur in a constant expression.  If ALIGNAS_ALIGN is nonzero,
    6469              :    it is the (valid) alignment for this compound literal, as specified
    6470              :    with _Alignas.  SCSPECS are the storage class specifiers (C23) from the
    6471              :    compound literal.  */
    6472              : 
    6473              : tree
    6474       929316 : build_compound_literal (location_t loc, tree type, tree init, bool non_const,
    6475              :                         unsigned int alignas_align,
    6476              :                         struct c_declspecs *scspecs)
    6477              : {
    6478              :   /* We do not use start_decl here because we have a type, not a declarator;
    6479              :      and do not use finish_decl because the decl should be stored inside
    6480              :      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
    6481       929316 :   tree decl;
    6482       929316 :   tree complit;
    6483       929316 :   tree stmt;
    6484       929316 :   bool threadp = scspecs ? scspecs->thread_p : false;
    6485          307 :   enum c_storage_class storage_class = (scspecs
    6486              :                                         ? scspecs->storage_class
    6487              :                                         : csc_none);
    6488              : 
    6489       929316 :   if (type == error_mark_node
    6490       929309 :       || init == error_mark_node)
    6491              :     return error_mark_node;
    6492              : 
    6493       929256 :   if (current_scope == file_scope && storage_class == csc_register)
    6494              :     {
    6495            1 :       error_at (loc, "file-scope compound literal specifies %<register%>");
    6496            1 :       storage_class = csc_none;
    6497              :     }
    6498              : 
    6499       929256 :   if (current_scope != file_scope && threadp && storage_class == csc_none)
    6500              :     {
    6501            6 :       error_at (loc, "compound literal implicitly auto and declared %qs",
    6502            3 :                 scspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    6503            3 :       threadp = false;
    6504              :     }
    6505              : 
    6506       929256 :   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
    6507       929256 :   DECL_EXTERNAL (decl) = 0;
    6508       929256 :   TREE_PUBLIC (decl) = 0;
    6509      1858512 :   TREE_STATIC (decl) = (current_scope == file_scope
    6510       929256 :                         || storage_class == csc_static);
    6511       929256 :   DECL_CONTEXT (decl) = current_function_decl;
    6512       929256 :   TREE_USED (decl) = 1;
    6513       929256 :   DECL_READ_P (decl) = 1;
    6514       929256 :   DECL_ARTIFICIAL (decl) = 1;
    6515       929256 :   DECL_IGNORED_P (decl) = 1;
    6516       929256 :   C_DECL_COMPOUND_LITERAL_P (decl) = 1;
    6517       929256 :   C_DECL_DECLARED_CONSTEXPR (decl) = scspecs && scspecs->constexpr_p;
    6518       929256 :   TREE_TYPE (decl) = type;
    6519       929256 :   if (threadp)
    6520           16 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    6521       929256 :   if (storage_class == csc_register)
    6522              :     {
    6523           25 :       C_DECL_REGISTER (decl) = 1;
    6524           25 :       DECL_REGISTER (decl) = 1;
    6525              :     }
    6526       929256 :   c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl);
    6527       929256 :   if (alignas_align)
    6528              :     {
    6529            3 :       SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    6530            3 :       DECL_USER_ALIGN (decl) = 1;
    6531              :     }
    6532       929256 :   store_init_value (loc, decl, init, NULL_TREE);
    6533       929256 :   if (current_scope != file_scope
    6534       929005 :       && TREE_STATIC (decl)
    6535           28 :       && !TREE_READONLY (decl)
    6536           17 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    6537       929262 :       && DECL_EXTERNAL (current_function_decl))
    6538            4 :     record_inline_static (input_location, current_function_decl,
    6539              :                           decl, csi_modifiable);
    6540              : 
    6541       929256 :   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
    6542              :     {
    6543          274 :       int failure = complete_array_type (&TREE_TYPE (decl),
    6544          274 :                                          DECL_INITIAL (decl), true);
    6545              :       /* If complete_array_type returns 3, it means that the initial value of
    6546              :          the compound literal is empty.  Allow it with a pedwarn; in pre-C23
    6547              :          modes, the empty initializer itself has been diagnosed if pedantic so
    6548              :          does not need to be diagnosed again here.  */
    6549          274 :       gcc_assert (failure == 0 || failure == 3);
    6550          274 :       if (failure == 3 && flag_isoc23)
    6551            1 :         pedwarn (loc, OPT_Wpedantic,
    6552              :                  "array of unknown size with empty initializer");
    6553              : 
    6554          274 :       type = TREE_TYPE (decl);
    6555          274 :       TREE_TYPE (DECL_INITIAL (decl)) = type;
    6556          274 :       relayout_decl (decl);
    6557              :     }
    6558              : 
    6559       929256 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    6560              :     {
    6561           19 :       c_incomplete_type_error (loc, NULL_TREE, type);
    6562           19 :       return error_mark_node;
    6563              :     }
    6564              : 
    6565       928958 :   if ((TREE_STATIC (decl) || C_DECL_DECLARED_CONSTEXPR (decl))
    6566       929458 :       && C_TYPE_VARIABLE_SIZE (type))
    6567            2 :     error_at (loc, "storage size isn%'t constant");
    6568              : 
    6569       929237 :   if (TREE_STATIC (decl)
    6570       929237 :       && !verify_type_context (loc, TCTX_STATIC_STORAGE, type))
    6571            0 :     return error_mark_node;
    6572              : 
    6573       929237 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
    6574       929237 :   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
    6575       929237 :   TREE_SIDE_EFFECTS (complit) = 1;
    6576              : 
    6577       929237 :   layout_decl (decl, 0);
    6578              : 
    6579       929237 :   if (TREE_STATIC (decl))
    6580              :     {
    6581              :       /* This decl needs a name for the assembler output.  */
    6582          279 :       set_compound_literal_name (decl);
    6583          279 :       DECL_DEFER_OUTPUT (decl) = 1;
    6584          279 :       DECL_COMDAT (decl) = 1;
    6585          279 :       pushdecl (decl);
    6586          279 :       rest_of_decl_compilation (decl, 1, 0);
    6587              :     }
    6588       928958 :   else if (current_function_decl && !current_scope->parm_flag)
    6589       928949 :     pushdecl (decl);
    6590              : 
    6591       929237 :   if (non_const)
    6592              :     {
    6593          221 :       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
    6594          221 :       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
    6595              :     }
    6596              : 
    6597              :   return complit;
    6598              : }
    6599              : 
    6600              : /* Check the type of a compound literal.  Here we just check that it
    6601              :    is valid for C++.  */
    6602              : 
    6603              : void
    6604       929313 : check_compound_literal_type (location_t loc, struct c_type_name *type_name)
    6605              : {
    6606       929313 :   if (warn_cxx_compat
    6607          169 :       && (type_name->specs->typespec_kind == ctsk_tagdef
    6608          168 :           || type_name->specs->typespec_kind == ctsk_tagfirstref
    6609          167 :           || type_name->specs->typespec_kind == ctsk_tagfirstref_attrs))
    6610            2 :     warning_at (loc, OPT_Wc___compat,
    6611              :                 "defining a type in a compound literal is invalid in C++");
    6612       929313 : }
    6613              : 
    6614              : /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
    6615              :    replacing with appropriate values if they are invalid.  */
    6616              : 
    6617              : static void
    6618        55124 : check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
    6619              :                                tree orig_name)
    6620              : {
    6621        55124 :   tree type_mv;
    6622        55124 :   unsigned int max_width;
    6623        55124 :   unsigned HOST_WIDE_INT w;
    6624        55124 :   const char *name = (orig_name
    6625        98627 :                       ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
    6626        11621 :                       : _("<anonymous>"));
    6627              : 
    6628              :   /* Detect and ignore out of range field width and process valid
    6629              :      field widths.  */
    6630        55124 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
    6631              :     {
    6632            8 :       error_at (loc, "bit-field %qs width not an integer constant", name);
    6633            8 :       *width = integer_one_node;
    6634              :     }
    6635              :   else
    6636              :     {
    6637        55116 :       if (TREE_CODE (*width) != INTEGER_CST)
    6638              :         {
    6639           12 :           *width = c_fully_fold (*width, false, NULL);
    6640           12 :           if (TREE_CODE (*width) == INTEGER_CST)
    6641            6 :             pedwarn (loc, OPT_Wpedantic,
    6642              :                      "bit-field %qs width not an integer constant expression",
    6643              :                      name);
    6644              :         }
    6645        55116 :       if (TREE_CODE (*width) != INTEGER_CST)
    6646              :         {
    6647            6 :           error_at (loc, "bit-field %qs width not an integer constant", name);
    6648            6 :           *width = integer_one_node;
    6649              :         }
    6650        55116 :       constant_expression_warning (*width);
    6651        55116 :       if (tree_int_cst_sgn (*width) < 0)
    6652              :         {
    6653            2 :           error_at (loc, "negative width in bit-field %qs", name);
    6654            2 :           *width = integer_one_node;
    6655              :         }
    6656        55114 :       else if (integer_zerop (*width) && orig_name)
    6657              :         {
    6658            4 :           error_at (loc, "zero width for bit-field %qs", name);
    6659            4 :           *width = integer_one_node;
    6660              :         }
    6661              :     }
    6662              : 
    6663              :   /* Detect invalid bit-field type.  */
    6664        55124 :   if (TREE_CODE (*type) != INTEGER_TYPE
    6665              :       && TREE_CODE (*type) != BOOLEAN_TYPE
    6666              :       && TREE_CODE (*type) != ENUMERAL_TYPE
    6667        55124 :       && TREE_CODE (*type) != BITINT_TYPE)
    6668              :     {
    6669            8 :       error_at (loc, "bit-field %qs has invalid type", name);
    6670            8 :       *type = unsigned_type_node;
    6671              :     }
    6672              : 
    6673        55124 :   if (TYPE_WARN_IF_NOT_ALIGN (*type))
    6674              :     {
    6675            1 :       error_at (loc, "cannot declare bit-field %qs with %<warn_if_not_aligned%> type",
    6676              :                 name);
    6677            1 :       *type = unsigned_type_node;
    6678              :     }
    6679              : 
    6680        55124 :   type_mv = TYPE_MAIN_VARIANT (*type);
    6681        55124 :   if (!in_system_header_at (input_location)
    6682        29788 :       && type_mv != integer_type_node
    6683        26968 :       && type_mv != unsigned_type_node
    6684        67860 :       && type_mv != boolean_type_node)
    6685        12153 :     pedwarn_c90 (loc, OPT_Wpedantic,
    6686              :                  "type of bit-field %qs is a GCC extension", name);
    6687              : 
    6688        55124 :   max_width = TYPE_PRECISION (*type);
    6689              : 
    6690        55124 :   if (compare_tree_int (*width, max_width) > 0)
    6691              :     {
    6692            4 :       error_at (loc, "width of %qs exceeds its type", name);
    6693            4 :       w = max_width;
    6694            4 :       *width = build_int_cst (integer_type_node, w);
    6695              :     }
    6696              :   else
    6697        55120 :     w = tree_to_uhwi (*width);
    6698              : 
    6699              :   /* Truncation of hardbool false and true representation values is always safe:
    6700              :      either the values remain different, or we'll report a problem when creating
    6701              :      the narrower type.  */
    6702        55124 :   if (c_hardbool_type_attr (*type))
    6703        55124 :     return;
    6704              : 
    6705        54843 :   if (TREE_CODE (*type) == ENUMERAL_TYPE)
    6706              :     {
    6707         4144 :       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
    6708         4144 :       if (!lt
    6709         4134 :           || w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
    6710         8274 :           || w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
    6711           15 :         warning_at (loc, 0, "%qs is narrower than values of its type", name);
    6712              :     }
    6713              : }
    6714              : 
    6715              : 
    6716              : 
    6717              : /* Print warning about variable length array if necessary.  */
    6718              : 
    6719              : static void
    6720        22503 : warn_variable_length_array (tree name, tree size)
    6721              : {
    6722        22503 :   if (TREE_CONSTANT (size))
    6723              :     {
    6724          181 :       if (name)
    6725          168 :         pedwarn_c90 (input_location, OPT_Wvla,
    6726              :                      "ISO C90 forbids array %qE whose size "
    6727              :                      "cannot be evaluated", name);
    6728              :       else
    6729           13 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
    6730              :                      "whose size cannot be evaluated");
    6731              :     }
    6732              :   else
    6733              :     {
    6734        22322 :       if (name)
    6735        13838 :         pedwarn_c90 (input_location, OPT_Wvla,
    6736              :                      "ISO C90 forbids variable length array %qE", name);
    6737              :       else
    6738         8484 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
    6739              :                      "length array");
    6740              :     }
    6741        22503 : }
    6742              : 
    6743              : /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
    6744              :    considering only those c_declspec_words found in LIST, which
    6745              :    must be terminated by cdw_number_of_elements.  */
    6746              : 
    6747              : static location_t
    6748          235 : smallest_type_quals_location (const location_t *locations,
    6749              :                               const c_declspec_word *list)
    6750              : {
    6751          235 :   location_t loc = UNKNOWN_LOCATION;
    6752         1410 :   while (*list != cdw_number_of_elements)
    6753              :     {
    6754         1175 :       location_t newloc = locations[*list];
    6755         1175 :       if (loc == UNKNOWN_LOCATION
    6756          288 :           || (newloc != UNKNOWN_LOCATION && newloc < loc))
    6757          887 :         loc = newloc;
    6758         1175 :       list++;
    6759              :     }
    6760              : 
    6761          235 :   return loc;
    6762              : }
    6763              : 
    6764              : 
    6765              : /* We attach an artificial TYPE_DECL to pointed-to type
    6766              :    and arrange for it to be included in a DECL_EXPR.  This
    6767              :    forces the sizes evaluation at a safe point and ensures it
    6768              :    is not deferred until e.g. within a deeper conditional context.
    6769              : 
    6770              :    PARM contexts have no enclosing statement list that
    6771              :    can hold the DECL_EXPR, so we need to use a BIND_EXPR
    6772              :    instead, and add it to the list of expressions that
    6773              :    need to be evaluated.
    6774              : 
    6775              :    TYPENAME contexts do have an enclosing statement list,
    6776              :    but it would be incorrect to use it, as the size should
    6777              :    only be evaluated if the containing expression is
    6778              :    evaluated.  We might also be in the middle of an
    6779              :    expression with side effects on the pointed-to type size
    6780              :    "arguments" prior to the pointer declaration point and
    6781              :    the fake TYPE_DECL in the enclosing context would force
    6782              :    the size evaluation prior to the side effects.  We therefore
    6783              :    use BIND_EXPRs in TYPENAME contexts too.  */
    6784              : static void
    6785         7043 : add_decl_expr (location_t loc, tree type, tree *expr, bool set_name_p)
    6786              : {
    6787         7043 :   tree bind = NULL_TREE;
    6788         7043 :   if (expr)
    6789              :     {
    6790         1600 :       bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, NULL_TREE,
    6791              :                      NULL_TREE);
    6792         1600 :       TREE_SIDE_EFFECTS (bind) = 1;
    6793         1600 :       BIND_EXPR_BODY (bind) = push_stmt_list ();
    6794         1600 :       push_scope ();
    6795              :     }
    6796              : 
    6797         7043 :   tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
    6798         7043 :   pushdecl (decl);
    6799         7043 :   DECL_ARTIFICIAL (decl) = 1;
    6800         7043 :   add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6801         7043 :   if (set_name_p)
    6802         6326 :     TYPE_NAME (type) = decl;
    6803              : 
    6804         7043 :   if (bind)
    6805              :     {
    6806         1600 :       pop_scope ();
    6807         1600 :       BIND_EXPR_BODY (bind) = pop_stmt_list (BIND_EXPR_BODY (bind));
    6808         1600 :       if (*expr)
    6809         1478 :         *expr = build2 (COMPOUND_EXPR, void_type_node, *expr, bind);
    6810              :       else
    6811          122 :         *expr = bind;
    6812              :     }
    6813         7043 : }
    6814              : 
    6815              : 
    6816              : /* Add attribute "arg spec" to ATTRS corresponding to an array/VLA parameter
    6817              :    declared with type TYPE.  The attribute has two arguments.  The first is
    6818              :    a string that encodes the presence of the static keyword.  The second is
    6819              :    the declared type of the array before adjustment, i.e. as an array type
    6820              :    including the outermost bound.  */
    6821              : 
    6822              : static tree
    6823       441947 : build_arg_spec_attribute (tree type, bool static_p, tree attrs)
    6824              : {
    6825       441947 :   tree vbchain = tree_cons (NULL_TREE, type, NULL_TREE);
    6826       441947 :   tree acsstr = static_p ? build_string (7, "static") :
    6827       441825 :                            build_string (1, "");
    6828       441947 :   tree args = tree_cons (NULL_TREE, acsstr, vbchain);
    6829       441947 :   tree name = get_identifier ("arg spec");
    6830       441947 :   return tree_cons (name, args, attrs);
    6831              : }
    6832              : 
    6833              : 
    6834              : /* Given declspecs and a declarator,
    6835              :    determine the name and type of the object declared
    6836              :    and construct a ..._DECL node for it.
    6837              :    (In one case we can return a ..._TYPE node instead.
    6838              :     For invalid input we sometimes return NULL_TREE.)
    6839              : 
    6840              :    DECLSPECS is a c_declspecs structure for the declaration specifiers.
    6841              : 
    6842              :    DECL_CONTEXT says which syntactic context this declaration is in:
    6843              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
    6844              :      FUNCDEF for a function definition.  Like NORMAL but a few different
    6845              :       error messages in each case.  Return value may be zero meaning
    6846              :       this definition is too screwy to try to parse.
    6847              :      PARM for a parameter declaration (either within a function prototype
    6848              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
    6849              :      TYPENAME if for a typename (in a cast or sizeof).
    6850              :       Don't make a DECL node; just return the ..._TYPE node.
    6851              :      GENERIC_ASSOC for typenames in a generic association.
    6852              :      FIELD for a struct or union field; make a FIELD_DECL.
    6853              :    INITIALIZED is true if the decl has an initializer.
    6854              :    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
    6855              :    representing the width of the bit-field.
    6856              :    DECL_ATTRS points to the list of attributes that should be added to this
    6857              :      decl.  Any nested attributes that belong on the decl itself will be
    6858              :      added to this list.
    6859              :    If EXPR is not NULL, any expressions that need to be evaluated as
    6860              :      part of evaluating variably modified types will be stored in *EXPR.
    6861              :    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
    6862              :      set to indicate whether operands in *EXPR can be used in constant
    6863              :      expressions.
    6864              :    DEPRECATED_STATE is a deprecated_states value indicating whether
    6865              :    deprecation/unavailability warnings should be suppressed.
    6866              : 
    6867              :    In the TYPENAME case, DECLARATOR is really an absolute declarator.
    6868              :    It may also be so in the PARM case, for a prototype where the
    6869              :    argument type is specified but not the name.
    6870              : 
    6871              :    This function is where the complicated C meanings of `static'
    6872              :    and `extern' are interpreted.  */
    6873              : 
    6874              : static tree
    6875    325584123 : grokdeclarator (const struct c_declarator *declarator,
    6876              :                 struct c_declspecs *declspecs,
    6877              :                 enum decl_context decl_context, bool initialized, tree *width,
    6878              :                 tree *decl_attrs, tree *expr, bool *expr_const_operands,
    6879              :                 enum deprecated_states deprecated_state)
    6880              : {
    6881    325584123 :   tree type = declspecs->type;
    6882    325584123 :   bool threadp = declspecs->thread_p;
    6883    325584123 :   bool constexprp = declspecs->constexpr_p;
    6884    325584123 :   enum c_storage_class storage_class = declspecs->storage_class;
    6885    325584123 :   int constp;
    6886    325584123 :   int restrictp;
    6887    325584123 :   int volatilep;
    6888    325584123 :   int atomicp;
    6889    325584123 :   qualifier_set type_quals {};
    6890    325584123 :   tree name = NULL_TREE;
    6891    325584123 :   bool funcdef_flag = false;
    6892    325584123 :   bool funcdef_syntax = false;
    6893    325584123 :   bool size_varies = false;
    6894    325584123 :   bool size_error = false;
    6895    325584123 :   tree decl_attr = declspecs->decl_attr;
    6896    325584123 :   qualifier_set array_ptr_quals {};
    6897    325584123 :   tree array_ptr_attrs = NULL_TREE;
    6898    325584123 :   bool array_parm_static = false;
    6899    325584123 :   bool array_parm_vla_unspec_p = false;
    6900    325584123 :   tree returned_attrs = NULL_TREE;
    6901    325584123 :   tree decl_id_attrs = NULL_TREE;
    6902    325584123 :   bool bitfield = width != NULL;
    6903    325584123 :   tree element_type;
    6904    325584123 :   tree orig_qual_type = NULL;
    6905    325584123 :   size_t orig_qual_indirect = 0;
    6906    325584123 :   struct c_arg_info *arg_info = 0;
    6907    325584123 :   addr_space_t as1, as2, address_space;
    6908    325584123 :   location_t loc = UNKNOWN_LOCATION;
    6909    325584123 :   tree expr_dummy;
    6910    325584123 :   bool expr_const_operands_dummy;
    6911    325584123 :   enum c_declarator_kind first_non_attr_kind;
    6912    325584123 :   unsigned int alignas_align = 0;
    6913              : 
    6914    325584123 :   if (type == NULL_TREE)
    6915              :     {
    6916              :       /* This can occur for auto on a parameter in C23 mode.  Set a
    6917              :          dummy type here so subsequent code can give diagnostics for
    6918              :          this case.  */
    6919            2 :       gcc_assert (declspecs->c23_auto_p);
    6920            2 :       gcc_assert (decl_context == PARM);
    6921            2 :       type = declspecs->type = integer_type_node;
    6922              :     }
    6923    325584123 :   if (TREE_CODE (type) == ERROR_MARK)
    6924           29 :     return error_mark_node;
    6925    325584094 :   if (expr == NULL)
    6926              :     {
    6927        38626 :       expr = &expr_dummy;
    6928        38626 :       expr_dummy = NULL_TREE;
    6929              :     }
    6930    325584094 :   if (expr_const_operands == NULL)
    6931    199216711 :     expr_const_operands = &expr_const_operands_dummy;
    6932              : 
    6933    325584094 :   if (declspecs->expr)
    6934              :     {
    6935          954 :       if (*expr)
    6936            7 :         *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
    6937              :                         declspecs->expr);
    6938              :       else
    6939          947 :         *expr = declspecs->expr;
    6940              :     }
    6941    325584094 :   *expr_const_operands = declspecs->expr_const_operands;
    6942              : 
    6943    325584094 :   if (decl_context == FUNCDEF)
    6944     37669311 :     funcdef_flag = true, decl_context = NORMAL;
    6945              : 
    6946              :   /* Look inside a declarator for the name being declared
    6947              :      and get it as an IDENTIFIER_NODE, for an error message.  */
    6948    325584094 :   {
    6949    325584094 :     const struct c_declarator *decl = declarator;
    6950              : 
    6951    325584094 :     first_non_attr_kind = cdk_attrs;
    6952    398126619 :     while (decl)
    6953    398126619 :       switch (decl->kind)
    6954              :         {
    6955      1152677 :         case cdk_array:
    6956      1152677 :           loc = decl->id_loc;
    6957              :           /* FALL THRU.  */
    6958              : 
    6959     72535647 :         case cdk_function:
    6960     72535647 :         case cdk_pointer:
    6961     72535647 :           funcdef_syntax = (decl->kind == cdk_function);
    6962     72535647 :           if (first_non_attr_kind == cdk_attrs)
    6963     70303990 :             first_non_attr_kind = decl->kind;
    6964     72535647 :           decl = decl->declarator;
    6965     72535647 :           break;
    6966              : 
    6967         6878 :         case cdk_attrs:
    6968         6878 :           decl = decl->declarator;
    6969         6878 :           break;
    6970              : 
    6971    325584094 :         case cdk_id:
    6972    325584094 :           loc = decl->id_loc;
    6973    325584094 :           if (decl->u.id.id)
    6974              :             name = decl->u.id.id;
    6975    325584094 :           decl_id_attrs = decl->u.id.attrs;
    6976    325584094 :           if (first_non_attr_kind == cdk_attrs)
    6977    255280104 :             first_non_attr_kind = decl->kind;
    6978              :           decl = 0;
    6979              :           break;
    6980              : 
    6981            0 :         default:
    6982            0 :           gcc_unreachable ();
    6983              :         }
    6984    325584094 :     if (name == NULL_TREE)
    6985              :       {
    6986    131146821 :         gcc_assert (decl_context == PARM
    6987              :                     || decl_context == TYPENAME
    6988              :                     || decl_context == GENERIC_ASSOC
    6989              :                     || (decl_context == FIELD
    6990              :                         && declarator->kind == cdk_id));
    6991    131146821 :         gcc_assert (!initialized);
    6992              :       }
    6993              :   }
    6994              : 
    6995              :   /* An enum type specifier (": specifier-qualifier-list") may only be
    6996              :      specified when the enum is being defined or in an empty
    6997              :      declaration of the form "enum identifier enum-type-specifier;".
    6998              :      Except for the case of an empty declaration that has additional
    6999              :      declaration specifiers, all invalid contexts (declarations that
    7000              :      aren't empty, type names, parameter declarations, member
    7001              :      declarations) pass through grokdeclarator.  */
    7002    325584094 :   if (declspecs->enum_type_specifier_ref_p)
    7003            6 :     error_at (loc, "%<enum%> underlying type may not be specified here");
    7004              : 
    7005              :   /* A function definition's declarator must have the form of
    7006              :      a function declarator.  */
    7007              : 
    7008    325584094 :   if (funcdef_flag && !funcdef_syntax)
    7009              :     return NULL_TREE;
    7010              : 
    7011              :   /* If this looks like a function definition, make it one,
    7012              :      even if it occurs where parms are expected.
    7013              :      Then store_parm_decls will reject it and not use it as a parm.  */
    7014    325584065 :   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
    7015        22662 :     decl_context = PARM;
    7016              : 
    7017    325584065 :   if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    7018              :     {
    7019    325584041 :       if (declspecs->unavailable_p)
    7020           28 :         error_unavailable_use (declspecs->type, declspecs->decl_attr);
    7021    325584013 :       else if (declspecs->deprecated_p
    7022           46 :                 && deprecated_state != DEPRECATED_SUPPRESS)
    7023           38 :         warn_deprecated_use (declspecs->type, declspecs->decl_attr);
    7024              :     }
    7025              : 
    7026    325584065 :   if ((decl_context == NORMAL || decl_context == FIELD)
    7027     70747882 :       && current_scope == file_scope
    7028    388180185 :       && c_type_variably_modified_p (type))
    7029              :     {
    7030            3 :       if (name)
    7031            3 :         error_at (loc, "variably modified %qE at file scope", name);
    7032              :       else
    7033            0 :         error_at (loc, "variably modified field at file scope");
    7034            3 :       type = integer_type_node;
    7035              :     }
    7036              : 
    7037    325584065 :   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
    7038              : 
    7039              :   /* Diagnose defaulting to "int".  */
    7040              : 
    7041    325584065 :   if (declspecs->default_int_p)
    7042              :     {
    7043              :       /* Issue a warning if this is an ISO C 99 program or if
    7044              :          -Wreturn-type and this is a function, or if -Wimplicit;
    7045              :          prefer the former warning since it is more explicit.  */
    7046         9764 :       if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99)
    7047         1229 :           && funcdef_flag)
    7048          702 :         warn_about_return_type = 1;
    7049              :       else
    7050              :         {
    7051         9062 :           if (name)
    7052         9052 :             permerror_opt (loc, OPT_Wimplicit_int,
    7053              :                            "type defaults to %<int%> in declaration "
    7054              :                            "of %qE", name);
    7055              :           else
    7056           10 :             permerror_opt (loc, OPT_Wimplicit_int,
    7057              :                            "type defaults to %<int%> in type name");
    7058              :         }
    7059              :     }
    7060              : 
    7061              :   /* Adjust the type if a bit-field is being declared,
    7062              :      -funsigned-bitfields applied and the type is not explicitly
    7063              :      "signed".  */
    7064    325584065 :   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
    7065           40 :       && TREE_CODE (type) == INTEGER_TYPE)
    7066           38 :     type = c_common_unsigned_type (type);
    7067              : 
    7068              :   /* Figure out the type qualifiers for the declaration.  There are
    7069              :      two ways a declaration can become qualified.  One is something
    7070              :      like `const int i' where the `const' is explicit.  Another is
    7071              :      something like `typedef const int CI; CI i' where the type of the
    7072              :      declaration contains the `const'.  A third possibility is that
    7073              :      there is a type qualifier on the element type of a typedefed
    7074              :      array type, in which case we should extract that qualifier so
    7075              :      that c_apply_type_quals_to_decl receives the full list of
    7076              :      qualifiers to work with (C90 is not entirely clear about whether
    7077              :      duplicate qualifiers should be diagnosed in this case, but it
    7078              :      seems most appropriate to do so).  */
    7079    325584065 :   element_type = strip_array_types (type);
    7080    325584065 :   constp = declspecs->const_p + TYPE_READONLY (element_type);
    7081    325584065 :   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
    7082    325584065 :   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
    7083    325584065 :   atomicp = declspecs->atomic_p + TYPE_ATOMIC (element_type);
    7084    325584065 :   as1 = declspecs->address_space;
    7085    325584065 :   as2 = TYPE_ADDR_SPACE (element_type);
    7086    325584065 :   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
    7087              : 
    7088    325584065 :   if (constp > 1)
    7089           25 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>");
    7090    325584065 :   if (restrictp > 1)
    7091            6 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>");
    7092    325584065 :   if (volatilep > 1)
    7093           15 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>");
    7094    325584065 :   if (atomicp > 1)
    7095            9 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>");
    7096              : 
    7097    325584065 :   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
    7098            0 :     error_at (loc, "conflicting named address spaces (%s vs %s)",
    7099              :               c_addr_space_name (as1), c_addr_space_name (as2));
    7100              : 
    7101    325584065 :   if ((TREE_CODE (type) == ARRAY_TYPE
    7102    325406558 :        || first_non_attr_kind == cdk_array)
    7103    326668065 :       && TYPE_QUALS (element_type))
    7104              :     {
    7105           73 :       orig_qual_type = type;
    7106           73 :       type = c_build_qualified_type (type, TYPE_UNQUALIFIED);
    7107              :     }
    7108    651168130 :   type_quals = {(constp ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
    7109              :                 | (restrictp ? TYPE_QUAL_RESTRICT : TYPE_UNQUALIFIED)
    7110              :                 | (volatilep ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED)
    7111              :                 | (atomicp ? TYPE_QUAL_ATOMIC : TYPE_UNQUALIFIED),
    7112   1614564094 :                 address_space};
    7113    637839873 :   if (type_quals != TYPE_QUALS (element_type))
    7114    325584065 :     orig_qual_type = NULL_TREE;
    7115              : 
    7116              :   /* Applying the _Atomic qualifier to an array type (through the use
    7117              :      of typedefs or typeof) must be detected here.  If the qualifier
    7118              :      is introduced later, any appearance of applying it to an array is
    7119              :      actually applying it to an element of that array.  */
    7120    325584065 :   if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
    7121            6 :     error_at (loc, "%<_Atomic%>-qualified array type");
    7122              : 
    7123              :   /* Warn about storage classes that are invalid for certain
    7124              :      kinds of declarations (parameters, typenames, etc.).  */
    7125              : 
    7126    325584065 :   if (funcdef_flag
    7127     37669282 :       && (threadp
    7128     37669282 :           || constexprp
    7129     37669280 :           || storage_class == csc_auto
    7130     37669280 :           || storage_class == csc_register
    7131     37669235 :           || storage_class == csc_typedef))
    7132              :     {
    7133           47 :       if (storage_class == csc_auto)
    7134           42 :         pedwarn (loc,
    7135           81 :                  (current_scope == file_scope) ? 0 : OPT_Wpedantic,
    7136              :                  "function definition declared %<auto%>");
    7137           50 :       if (storage_class == csc_register)
    7138            3 :         error_at (loc, "function definition declared %<register%>");
    7139           50 :       if (storage_class == csc_typedef)
    7140            3 :         error_at (loc, "function definition declared %<typedef%>");
    7141           50 :       if (threadp)
    7142            2 :         error_at (loc, "function definition declared %qs",
    7143            2 :                   declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7144           50 :       threadp = false;
    7145              :       /* The parser ensures a constexpr function definition never
    7146              :          reaches here.  */
    7147           50 :       gcc_assert (!constexprp);
    7148           50 :       if (storage_class == csc_auto
    7149           50 :           || storage_class == csc_register
    7150              :           || storage_class == csc_typedef)
    7151    325584065 :         storage_class = csc_none;
    7152              :     }
    7153    325584015 :   else if (decl_context != NORMAL && (storage_class != csc_none
    7154    259197810 :                                       || threadp
    7155    259197227 :                                       || constexprp
    7156    259197225 :                                       || declspecs->c23_auto_p))
    7157              :     {
    7158          587 :       if (decl_context == PARM
    7159          587 :           && storage_class == csc_register
    7160          568 :           && !constexprp
    7161          566 :           && !declspecs->c23_auto_p)
    7162              :         ;
    7163              :       else
    7164              :         {
    7165           21 :           switch (decl_context)
    7166              :             {
    7167            0 :             case FIELD:
    7168            0 :               if (name)
    7169            0 :                 error_at (loc, "storage class specified for structure "
    7170              :                           "field %qE", name);
    7171              :               else
    7172            0 :                 error_at (loc, "storage class specified for structure field");
    7173              :               break;
    7174           21 :             case PARM:
    7175           21 :               if (name)
    7176            7 :                 error_at (loc, "storage class specified for parameter %qE",
    7177              :                           name);
    7178              :               else
    7179           14 :                 error_at (loc, "storage class specified for unnamed parameter");
    7180              :               break;
    7181            0 :             default:
    7182            0 :               error_at (loc, "storage class specified for typename");
    7183            0 :               break;
    7184              :             }
    7185    325584065 :           storage_class = csc_none;
    7186    325584065 :           threadp = false;
    7187    325584065 :           constexprp = false;
    7188              :         }
    7189              :     }
    7190    325583428 :   else if (storage_class == csc_extern
    7191    325583428 :            && initialized
    7192     36796542 :            && !funcdef_flag)
    7193              :     {
    7194              :       /* 'extern' with initialization is invalid if not at file scope.  */
    7195           28 :        if (current_scope == file_scope)
    7196              :          {
    7197              :            /* It is fine to have 'extern const' when compiling at C
    7198              :               and C++ intersection.  */
    7199           19 :            if (!(warn_cxx_compat && constp))
    7200           18 :              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
    7201              :                          name);
    7202              :          }
    7203              :       else
    7204            9 :         error_at (loc, "%qE has both %<extern%> and initializer", name);
    7205              :     }
    7206    325583400 :   else if (current_scope == file_scope)
    7207              :     {
    7208     63472218 :       if (storage_class == csc_auto)
    7209            7 :         error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
    7210              :                   name);
    7211     63472218 :       if (pedantic && storage_class == csc_register)
    7212            4 :         pedwarn (input_location, OPT_Wpedantic,
    7213              :                  "file-scope declaration of %qE specifies %<register%>", name);
    7214              :     }
    7215              :   else
    7216              :     {
    7217    262111182 :       if (storage_class == csc_extern && funcdef_flag)
    7218            3 :         error_at (loc, "nested function %qE declared %<extern%>", name);
    7219    262111179 :       else if (threadp && storage_class == csc_none)
    7220              :         {
    7221           14 :           error_at (loc, "function-scope %qE implicitly auto and declared "
    7222              :                     "%qs", name,
    7223            7 :                     declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7224            7 :           threadp = false;
    7225              :         }
    7226              :     }
    7227              : 
    7228              :   /* Now figure out the structure of the declarator proper.
    7229              :      Descend through it, creating more complex types, until we reach
    7230              :      the declared identifier (or NULL_TREE, in an absolute declarator).
    7231              :      At each stage we maintain an unqualified version of the type
    7232              :      together with any qualifiers that should be applied to it with
    7233              :      c_build_qualified_type; this way, array types including
    7234              :      multidimensional array types are first built up in unqualified
    7235              :      form and then the qualified form is created with
    7236              :      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
    7237              : 
    7238    398126589 :   while (declarator && declarator->kind != cdk_id)
    7239              :     {
    7240     72542524 :       if (type == error_mark_node)
    7241              :         {
    7242           39 :           declarator = declarator->declarator;
    7243           39 :           continue;
    7244              :         }
    7245              : 
    7246              :       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
    7247              :          a cdk_pointer (for *...),
    7248              :          a cdk_function (for ...(...)),
    7249              :          a cdk_attrs (for nested attributes),
    7250              :          or a cdk_id (for the name being declared
    7251              :          or the place in an absolute declarator
    7252              :          where the name was omitted).
    7253              :          For the last case, we have just exited the loop.
    7254              : 
    7255              :          At this point, TYPE is the type of elements of an array,
    7256              :          or for a function to return, or for a pointer to point to.
    7257              :          After this sequence of ifs, TYPE is the type of the
    7258              :          array or function or pointer, and DECLARATOR has had its
    7259              :          outermost layer removed.  */
    7260              : 
    7261     72542485 :       if (array_ptr_quals != TYPE_UNQUALIFIED
    7262     72542485 :           || array_ptr_attrs != NULL_TREE
    7263     72542485 :           || array_parm_static)
    7264              :         {
    7265              :           /* Only the innermost declarator (making a parameter be of
    7266              :              array type which is converted to pointer type)
    7267              :              may have static or type qualifiers.  */
    7268            1 :           error_at (loc, "static or type qualifiers in non-parameter array declarator");
    7269            1 :           array_ptr_quals = TYPE_UNQUALIFIED;
    7270            1 :           array_ptr_attrs = NULL_TREE;
    7271            1 :           array_parm_static = false;
    7272              :         }
    7273              : 
    7274     72542485 :       switch (declarator->kind)
    7275              :         {
    7276         6878 :         case cdk_attrs:
    7277         6878 :           {
    7278              :             /* A declarator with embedded attributes.  */
    7279         6878 :             tree attrs = declarator->u.attrs;
    7280         6878 :             const struct c_declarator *inner_decl;
    7281         6878 :             int attr_flags = 0;
    7282         6878 :             declarator = declarator->declarator;
    7283              :             /* Standard attribute syntax precisely defines what entity
    7284              :                an attribute in each position appertains to, so only
    7285              :                apply laxity about positioning to GNU attribute syntax.
    7286              :                Standard attributes applied to a function or array
    7287              :                declarator apply exactly to that type; standard
    7288              :                attributes applied to the identifier apply to the
    7289              :                declaration rather than to the type, and are specified
    7290              :                using a cdk_id declarator rather than using
    7291              :                cdk_attrs.  */
    7292         6878 :             inner_decl = declarator;
    7293         6878 :             while (inner_decl->kind == cdk_attrs)
    7294            0 :               inner_decl = inner_decl->declarator;
    7295         6878 :             if (!cxx11_attribute_p (attrs))
    7296              :               {
    7297         6740 :                 if (inner_decl->kind == cdk_id)
    7298              :                   attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
    7299              :                 else if (inner_decl->kind == cdk_function)
    7300              :                   attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
    7301              :                 else if (inner_decl->kind == cdk_array)
    7302         6878 :                   attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
    7303              :               }
    7304         6878 :             attrs = c_warn_type_attributes (type, attrs);
    7305         6878 :             returned_attrs = decl_attributes (&type,
    7306              :                                               chainon (returned_attrs, attrs),
    7307              :                                               attr_flags);
    7308         6878 :             break;
    7309              :           }
    7310      1152667 :         case cdk_array:
    7311      1152667 :           {
    7312      1152667 :             tree itype = NULL_TREE;
    7313      1152667 :             tree size = declarator->u.array.dimen;
    7314              :             /* The index is a signed object `sizetype' bits wide.  */
    7315      1152667 :             tree index_type = c_common_signed_type (sizetype);
    7316              : 
    7317      1152667 :             array_ptr_quals = declarator->u.array.quals;
    7318      1152667 :             array_ptr_attrs = declarator->u.array.attrs;
    7319      1152667 :             array_parm_static = declarator->u.array.static_p;
    7320      1152667 :             array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
    7321              : 
    7322      1152667 :             declarator = declarator->declarator;
    7323              : 
    7324      1152667 :             bool flexible_array_member = false;
    7325              : 
    7326              :             /* Check for some types that there cannot be arrays of.  */
    7327              : 
    7328      1152667 :             if (VOID_TYPE_P (type))
    7329              :               {
    7330           11 :                 if (name)
    7331            9 :                   error_at (loc, "declaration of %qE as array of voids", name);
    7332              :                 else
    7333            2 :                   error_at (loc, "declaration of type name as array of voids");
    7334           11 :                 type = error_mark_node;
    7335              :               }
    7336              : 
    7337      1152667 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7338              :               {
    7339            3 :                 if (name)
    7340            2 :                   error_at (loc, "declaration of %qE as array of functions",
    7341              :                             name);
    7342              :                 else
    7343            1 :                   error_at (loc, "declaration of type name as array of "
    7344              :                             "functions");
    7345            3 :                 type = error_mark_node;
    7346              :               }
    7347              : 
    7348        21390 :             if (pedantic && !in_system_header_at (input_location)
    7349      1167739 :                 && flexible_array_type_p (type))
    7350           20 :               pedwarn (loc, OPT_Wpedantic,
    7351              :                        "invalid use of structure with flexible array member");
    7352              : 
    7353      1152667 :             if (size == error_mark_node)
    7354          119 :               type = error_mark_node;
    7355              : 
    7356      1152667 :             if (type == error_mark_node)
    7357          133 :               continue;
    7358              : 
    7359      1152534 :             if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, type))
    7360              :               {
    7361            0 :                 type = error_mark_node;
    7362            0 :                 continue;
    7363              :               }
    7364              : 
    7365              :             /* If size was specified, set ITYPE to a range-type for
    7366              :                that size.  Otherwise, ITYPE remains null.  finish_decl
    7367              :                may figure it out from an initial value.  */
    7368              : 
    7369      1152534 :             if (size)
    7370              :               {
    7371       979903 :                 bool size_maybe_const = true;
    7372       979903 :                 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
    7373       979903 :                                        && !TREE_OVERFLOW (size));
    7374       979903 :                 bool this_size_varies = false;
    7375              : 
    7376              :                 /* Strip NON_LVALUE_EXPRs since we aren't using as an
    7377              :                    lvalue.  */
    7378       979912 :                 STRIP_TYPE_NOPS (size);
    7379              : 
    7380       979903 :                 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
    7381              :                   {
    7382           16 :                     if (name)
    7383           14 :                       error_at (loc, "size of array %qE has non-integer type",
    7384              :                                 name);
    7385              :                     else
    7386            2 :                       error_at (loc,
    7387              :                                 "size of unnamed array has non-integer type");
    7388           16 :                     size = integer_one_node;
    7389           16 :                     size_int_const = true;
    7390           16 :                     size_error = true;
    7391              :                   }
    7392              :                 /* This can happen with enum forward declaration.  */
    7393       979887 :                 else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
    7394              :                   {
    7395            0 :                     if (name)
    7396            0 :                       error_at (loc, "size of array %qE has incomplete type",
    7397              :                                 name);
    7398              :                     else
    7399            0 :                       error_at (loc, "size of unnamed array has incomplete "
    7400              :                                 "type");
    7401            0 :                     size = integer_one_node;
    7402            0 :                     size_int_const = true;
    7403            0 :                     size_error = true;
    7404              :                   }
    7405              : 
    7406       979903 :                 size = c_fully_fold (size, false, &size_maybe_const);
    7407              : 
    7408       979903 :                 if (pedantic && size_maybe_const && integer_zerop (size))
    7409              :                   {
    7410            3 :                     if (name)
    7411            3 :                       pedwarn (loc, OPT_Wpedantic,
    7412              :                                "ISO C forbids zero-size array %qE", name);
    7413              :                     else
    7414            0 :                       pedwarn (loc, OPT_Wpedantic,
    7415              :                                "ISO C forbids zero-size array");
    7416              :                   }
    7417              : 
    7418       979903 :                 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
    7419              :                   {
    7420       957534 :                     constant_expression_warning (size);
    7421       957534 :                     if (tree_int_cst_sgn (size) < 0)
    7422              :                       {
    7423          466 :                         if (name)
    7424          463 :                           error_at (loc, "size of array %qE is negative", name);
    7425              :                         else
    7426            3 :                           error_at (loc, "size of unnamed array is negative");
    7427          466 :                         size = integer_one_node;
    7428          466 :                         size_int_const = true;
    7429          466 :                         size_error = true;
    7430              :                       }
    7431              :                     /* Handle a size folded to an integer constant but
    7432              :                        not an integer constant expression.  */
    7433       957534 :                     if (!size_int_const)
    7434              :                       {
    7435              :                         /* If this is a file scope declaration of an
    7436              :                            ordinary identifier, this is invalid code;
    7437              :                            diagnosing it here and not subsequently
    7438              :                            treating the type as variable-length avoids
    7439              :                            more confusing diagnostics later.  */
    7440          155 :                         if ((decl_context == NORMAL || decl_context == FIELD)
    7441          142 :                             && current_scope == file_scope)
    7442           14 :                           pedwarn (input_location, 0,
    7443              :                                    "variably modified %qE at file scope",
    7444              :                                    name);
    7445              :                         else
    7446              :                           this_size_varies = size_varies = true;
    7447          155 :                         warn_variable_length_array (name, size);
    7448              :                       }
    7449              :                   }
    7450        22369 :                 else if ((decl_context == NORMAL || decl_context == FIELD)
    7451        13267 :                          && current_scope == file_scope)
    7452              :                   {
    7453           21 :                     error_at (loc, "variably modified %qE at file scope", name);
    7454           21 :                     size = integer_one_node;
    7455              :                   }
    7456              :                 else
    7457              :                   {
    7458              :                     /* Make sure the array size remains visibly
    7459              :                        nonconstant even if it is (eg) a const variable
    7460              :                        with known value.  */
    7461        22348 :                     this_size_varies = size_varies = true;
    7462        22348 :                     warn_variable_length_array (name, size);
    7463        22348 :                     if (sanitize_flags_p (SANITIZE_VLA)
    7464          181 :                         && current_function_decl != NULL_TREE
    7465        22511 :                         && decl_context == NORMAL)
    7466              :                       {
    7467              :                         /* Evaluate the array size only once.  */
    7468          155 :                         size = save_expr (size);
    7469          155 :                         size = c_fully_fold (size, false, NULL);
    7470          155 :                         size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7471              :                                             ubsan_instrument_vla (loc, size),
    7472              :                                             size);
    7473              :                       }
    7474              :                   }
    7475              : 
    7476       979903 :                 if (integer_zerop (size) && !this_size_varies)
    7477              :                   {
    7478              :                     /* A zero-length array cannot be represented with
    7479              :                        an unsigned index type, which is what we'll
    7480              :                        get with build_index_type.  Create an
    7481              :                        open-ended range instead.  */
    7482         2619 :                     itype = build_index_type (NULL_TREE);
    7483              :                   }
    7484              :                 else
    7485              :                   {
    7486              :                     /* Arrange for the SAVE_EXPR on the inside of the
    7487              :                        MINUS_EXPR, which allows the -1 to get folded
    7488              :                        with the +1 that happens when building TYPE_SIZE.  */
    7489       977284 :                     if (size_varies)
    7490        22864 :                       size = save_expr (size);
    7491       977284 :                     if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
    7492          141 :                       size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7493              :                                      integer_zero_node, size);
    7494              : 
    7495              :                     /* Compute the maximum valid index, that is, size
    7496              :                        - 1.  Do the calculation in index_type, so that
    7497              :                        if it is a variable the computations will be
    7498              :                        done in the proper mode.  */
    7499       977284 :                     itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
    7500              :                                              convert (index_type, size),
    7501              :                                              convert (index_type,
    7502              :                                                       size_one_node));
    7503              : 
    7504              :                     /* The above overflows when size does not fit
    7505              :                        in index_type.
    7506              :                        ???  While a size of INT_MAX+1 technically shouldn't
    7507              :                        cause an overflow (because we subtract 1), handling
    7508              :                        this case seems like an unnecessary complication.  */
    7509       977284 :                     if (TREE_CODE (size) == INTEGER_CST
    7510       954795 :                         && !int_fits_type_p (size, index_type))
    7511              :                       {
    7512            6 :                         if (name)
    7513            5 :                           error_at (loc, "size of array %qE is too large",
    7514              :                                     name);
    7515              :                         else
    7516            1 :                           error_at (loc, "size of unnamed array is too large");
    7517            6 :                         type = error_mark_node;
    7518            6 :                         continue;
    7519              :                       }
    7520              : 
    7521       977278 :                     itype = build_index_type (itype);
    7522              :                   }
    7523       979897 :                 if (this_size_varies)
    7524              :                   {
    7525        22489 :                     if (TREE_SIDE_EFFECTS (size))
    7526              :                       {
    7527        22125 :                         if (*expr)
    7528         8178 :                           *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7529              :                                           *expr, size);
    7530              :                         else
    7531        13947 :                           *expr = size;
    7532              :                       }
    7533        22489 :                     *expr_const_operands &= size_maybe_const;
    7534              :                   }
    7535              :               }
    7536       172631 :             else if (decl_context == FIELD)
    7537              :               {
    7538        86068 :                 if (array_parm_vla_unspec_p)
    7539              :                   /* Field names can in fact have function prototype
    7540              :                      scope so [*] is disallowed here through making
    7541              :                      the field variably modified, not through being
    7542              :                      something other than a declaration with function
    7543              :                      prototype scope.  */
    7544              :                   size_varies = true;
    7545              :                 else
    7546              :                   {
    7547              :                     const struct c_declarator *t = declarator;
    7548        86065 :                     while (t->kind == cdk_attrs)
    7549            0 :                       t = t->declarator;
    7550        86065 :                     flexible_array_member = (t->kind == cdk_id);
    7551              :                   }
    7552        86065 :                 if (flexible_array_member
    7553        86065 :                     && !in_system_header_at (input_location))
    7554        85033 :                   pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    7555              :                                "support flexible array members");
    7556              : 
    7557              :                 /* ISO C99 Flexible array members are effectively
    7558              :                    identical to GCC's zero-length array extension.  */
    7559        86068 :                 if (flexible_array_member)
    7560        86045 :                   itype = build_index_type (NULL_TREE);
    7561              :               }
    7562              : 
    7563              :             /* Complain about arrays of incomplete types.  */
    7564      1152528 :             if (!COMPLETE_TYPE_P (type))
    7565              :               {
    7566           58 :                 auto_diagnostic_group d;
    7567           58 :                 error_at (loc, "array type has incomplete element type %qT",
    7568              :                           type);
    7569              :                 /* See if we can be more helpful.  */
    7570           58 :                 if (TREE_CODE (type) == ARRAY_TYPE)
    7571              :                   {
    7572           29 :                     if (name)
    7573           24 :                       inform (loc, "declaration of %qE as multidimensional "
    7574              :                               "array must have bounds for all dimensions "
    7575              :                               "except the first", name);
    7576              :                     else
    7577            5 :                       inform (loc, "declaration of multidimensional array "
    7578              :                               "must have bounds for all dimensions except "
    7579              :                               "the first");
    7580              :                   }
    7581           58 :                 type = error_mark_node;
    7582           58 :               }
    7583              :             else
    7584              :             /* When itype is NULL, a shared incomplete array type is
    7585              :                returned for all array of a given type.  Elsewhere we
    7586              :                make sure we don't complete that type before copying
    7587              :                it, but here we want to make sure we don't ever
    7588              :                modify the shared type, so we gcc_assert (itype)
    7589              :                below.  */
    7590              :               {
    7591      1152470 :                 addr_space_t as = type_quals.addr_space ();
    7592      1152470 :                 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
    7593            0 :                   type = c_build_qualified_type (type,
    7594              :                                                  {TYPE_UNQUALIFIED, as});
    7595      1152470 :                 if (array_parm_vla_unspec_p)
    7596          151 :                   type = c_build_array_type_unspecified (type);
    7597              :                 /* The GCC extension for zero-length arrays differs from
    7598              :                    ISO flexible array members in that sizeof yields
    7599              :                    zero.  */
    7600      1152319 :                 else if (size && integer_zerop (size))
    7601         2612 :                   type = c_build_array_type_zero_size (type);
    7602              :                 else
    7603      1149707 :                   type = c_build_array_type (type, itype);
    7604              : 
    7605      1152470 :                 if (!valid_array_size_p (loc, type, name))
    7606           33 :                   type = error_mark_node;
    7607              :               }
    7608              : 
    7609      1152528 :             if (array_parm_vla_unspec_p)
    7610              :               {
    7611              :                 /* C99 6.7.5.2p4 */
    7612          151 :                 if (decl_context == TYPENAME)
    7613            6 :                   warning (0, "%<[*]%> not in a declaration");
    7614          145 :                 else if (decl_context != GENERIC_ASSOC
    7615          145 :                          && decl_context != PARM
    7616            7 :                          && decl_context != FIELD)
    7617              :                   {
    7618            4 :                     error ("%<[*]%> not allowed in other than function prototype scope "
    7619              :                            "or generic association");
    7620            4 :                     type = error_mark_node;
    7621              :                   }
    7622              :                 size_varies = true;
    7623              :               }
    7624              : 
    7625              : 
    7626      1152528 :             gcc_assert (type == error_mark_node
    7627              :                         || flexible_array_member
    7628              :                            == flexible_array_member_type_p (type));
    7629              : 
    7630      1152528 :             if (decl_context != PARM
    7631      1152528 :                 && (array_ptr_quals != TYPE_UNQUALIFIED
    7632       830013 :                     || array_ptr_attrs != NULL_TREE
    7633       830013 :                     || array_parm_static))
    7634              :               {
    7635            2 :                 error_at (loc, "static or type qualifiers in non-parameter "
    7636              :                           "array declarator");
    7637            2 :                 array_ptr_quals = TYPE_UNQUALIFIED;
    7638            2 :                 array_ptr_attrs = NULL_TREE;
    7639            2 :                 array_parm_static = false;
    7640              :               }
    7641      1152528 :             orig_qual_indirect++;
    7642      1152528 :             break;
    7643              :           }
    7644     52592532 :         case cdk_function:
    7645     52592532 :           {
    7646              :             /* Say it's a definition only for the declarator closest
    7647              :                to the identifier, apart possibly from some
    7648              :                attributes.  */
    7649     52592532 :             bool really_funcdef = false;
    7650     52592532 :             tree arg_types;
    7651     52592532 :             orig_qual_type = NULL_TREE;
    7652     52592532 :             if (funcdef_flag)
    7653              :               {
    7654     37669305 :                 const struct c_declarator *t = declarator->declarator;
    7655     37669355 :                 while (t->kind == cdk_attrs)
    7656           50 :                   t = t->declarator;
    7657     37669305 :                 really_funcdef = (t->kind == cdk_id);
    7658              :               }
    7659              : 
    7660              :             /* Declaring a function type.  Make sure we have a valid
    7661              :                type for the function to return.  */
    7662     52592532 :             if (type == error_mark_node)
    7663            0 :               continue;
    7664              : 
    7665     52592532 :             size_varies = false;
    7666              : 
    7667              :             /* Warn about some types functions can't return.  */
    7668     52592532 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7669              :               {
    7670            0 :                 if (name)
    7671            0 :                   error_at (loc, "%qE declared as function returning a "
    7672              :                                  "function", name);
    7673              :                 else
    7674            0 :                   error_at (loc, "type name declared as function "
    7675              :                             "returning a function");
    7676            0 :                 type = integer_type_node;
    7677              :               }
    7678     52592532 :             if (TREE_CODE (type) == ARRAY_TYPE)
    7679              :               {
    7680            0 :                 if (name)
    7681            0 :                   error_at (loc, "%qE declared as function returning an array",
    7682              :                             name);
    7683              :                 else
    7684            0 :                   error_at (loc, "type name declared as function returning "
    7685              :                             "an array");
    7686            0 :                 type = integer_type_node;
    7687              :               }
    7688              : 
    7689              :             /* Construct the function type and go to the next
    7690              :                inner layer of declarator.  */
    7691     52592532 :             arg_info = declarator->u.arg_info;
    7692     52592532 :             arg_types = grokparms (arg_info, really_funcdef);
    7693              : 
    7694              :             /* Type qualifiers before the return type of the function
    7695              :                qualify the return type, not the function type.  */
    7696     52592532 :             if (type_quals)
    7697              :               {
    7698          235 :                 const enum c_declspec_word ignored_quals_list[] =
    7699              :                   {
    7700              :                     cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
    7701              :                     cdw_atomic, cdw_number_of_elements
    7702              :                   };
    7703          235 :                 location_t specs_loc
    7704          235 :                   = smallest_type_quals_location (declspecs->locations,
    7705              :                                                   ignored_quals_list);
    7706          235 :                 if (specs_loc == UNKNOWN_LOCATION)
    7707          139 :                   specs_loc = declspecs->locations[cdw_typedef];
    7708          139 :                 if (specs_loc == UNKNOWN_LOCATION)
    7709           15 :                   specs_loc = loc;
    7710              : 
    7711              :                 /* Type qualifiers on a function return type are
    7712              :                    normally permitted by the standard but have no
    7713              :                    effect, so give a warning at -Wreturn-type.
    7714              :                    Qualifiers on a void return type are banned on
    7715              :                    function definitions in ISO C; GCC used to used
    7716              :                    them for noreturn functions.  The resolution of C11
    7717              :                    DR#423 means qualifiers (other than _Atomic) are
    7718              :                    actually removed from the return type when
    7719              :                    determining the function type.  For C23, _Atomic is
    7720              :                    removed as well.  */
    7721          235 :                 auto quals_used = type_quals;
    7722          235 :                 if (flag_isoc23)
    7723              :                   quals_used = qualifier_set {};
    7724           65 :                 else if (flag_isoc11)
    7725           31 :                   quals_used = quals_used.intersect (TYPE_QUAL_ATOMIC);
    7726          235 :                 if (quals_used && VOID_TYPE_P (type) && really_funcdef)
    7727            5 :                   pedwarn (specs_loc, 0,
    7728              :                            "function definition has qualified void "
    7729              :                            "return type");
    7730              :                 else
    7731          230 :                   warning_at (specs_loc, OPT_Wignored_qualifiers,
    7732              :                               "type qualifiers ignored on function "
    7733              :                               "return type");
    7734              : 
    7735              :                 /* Ensure an error for restrict on invalid types; the
    7736              :                    DR#423 resolution is not entirely clear about
    7737              :                    this.  */
    7738          235 :                 if (flag_isoc11
    7739          201 :                     && (type_quals.has (TYPE_QUAL_RESTRICT))
    7740          241 :                     && (!POINTER_TYPE_P (type)
    7741            4 :                         || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
    7742            4 :                   error_at (loc, "invalid use of %<restrict%>");
    7743          235 :                 type = c_build_qualified_type (type, quals_used);
    7744              :               }
    7745     52592532 :             type_quals = TYPE_UNQUALIFIED;
    7746              : 
    7747     52592532 :             type = c_build_function_type (type, arg_types,
    7748              :                                           arg_info->no_named_args_stdarg_p);
    7749     52592532 :             declarator = declarator->declarator;
    7750              : 
    7751              :             /* Set the TYPE_CONTEXTs for each tagged type which is local to
    7752              :                the formal parameter list of this FUNCTION_TYPE to point to
    7753              :                the FUNCTION_TYPE node itself.  */
    7754     52592532 :             {
    7755     52592532 :               c_arg_tag *tag;
    7756     52592532 :               unsigned ix;
    7757              : 
    7758    450719400 :               FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
    7759          142 :                 TYPE_CONTEXT (tag->type) = type;
    7760              :             }
    7761              :             break;
    7762              :           }
    7763     18790408 :         case cdk_pointer:
    7764     18790408 :           {
    7765              :             /* Merge any constancy or volatility into the target type
    7766              :                for the pointer.  */
    7767     18790408 :             if (type_quals.has (TYPE_QUAL_ATOMIC)
    7768     18790408 :                 && TREE_CODE (type) == FUNCTION_TYPE)
    7769              :               {
    7770            2 :                 error_at (loc,
    7771              :                           "%<_Atomic%>-qualified function type");
    7772            2 :                 type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    7773              :               }
    7774       251917 :             else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7775     18790406 :                      && type_quals)
    7776            0 :               pedwarn (loc, OPT_Wpedantic,
    7777              :                        "ISO C forbids qualified function types");
    7778     18790408 :             if (type_quals)
    7779      6233108 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7780              :                                              orig_qual_indirect);
    7781     18790408 :             orig_qual_type = NULL_TREE;
    7782     18790408 :             size_varies = false;
    7783              : 
    7784              :             /* When the pointed-to type involves components of variable size,
    7785              :                care must be taken to ensure that the size evaluation code is
    7786              :                emitted early enough to dominate all the possible later uses
    7787              :                and late enough for the variables on which it depends to have
    7788              :                been assigned.
    7789              : 
    7790              :                This is expected to happen automatically when the pointed-to
    7791              :                type has a name/declaration of it's own, but special attention
    7792              :                is required if the type is anonymous. */
    7793     18790408 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    7794              :               {
    7795         5951 :                 bool bind_p = decl_context == TYPENAME
    7796              :                               || decl_context == FIELD
    7797         5951 :                               || decl_context == PARM;
    7798        11394 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    7799              :               }
    7800              : 
    7801     18790408 :             type = c_build_pointer_type (type);
    7802              : 
    7803              :             /* Process type qualifiers (such as const or volatile)
    7804              :                that were given inside the `*'.  */
    7805     18790408 :             type_quals = declarator->u.pointer_quals;
    7806              : 
    7807     18790408 :             declarator = declarator->declarator;
    7808     18790408 :             break;
    7809              :           }
    7810            0 :         default:
    7811            0 :           gcc_unreachable ();
    7812              :         }
    7813              :     }
    7814    325584065 :   *decl_attrs = chainon (returned_attrs, *decl_attrs);
    7815    325584065 :   *decl_attrs = chainon (decl_id_attrs, *decl_attrs);
    7816              : 
    7817              :   /* Now TYPE has the actual type, apart from any qualifiers in
    7818              :      TYPE_QUALS.  */
    7819              : 
    7820              :   /* Warn about address space used for things other than static memory or
    7821              :      pointers.  */
    7822    325584065 :   address_space = type_quals.addr_space ();
    7823    325584065 :   if (!ADDR_SPACE_GENERIC_P (address_space))
    7824              :     {
    7825           10 :       if (decl_context == NORMAL)
    7826              :         {
    7827           10 :           switch (storage_class)
    7828              :             {
    7829            0 :             case csc_auto:
    7830            0 :               error ("%qs combined with %<auto%> qualifier for %qE",
    7831              :                      c_addr_space_name (address_space), name);
    7832            0 :               break;
    7833            0 :             case csc_register:
    7834            0 :               error ("%qs combined with %<register%> qualifier for %qE",
    7835              :                      c_addr_space_name (address_space), name);
    7836            0 :               break;
    7837            6 :             case csc_none:
    7838            6 :               if (current_function_scope)
    7839              :                 {
    7840            0 :                   error ("%qs specified for auto variable %qE",
    7841              :                          c_addr_space_name (address_space), name);
    7842            0 :                   break;
    7843              :                 }
    7844              :               break;
    7845              :             case csc_static:
    7846              :             case csc_extern:
    7847              :             case csc_typedef:
    7848              :               break;
    7849            0 :             default:
    7850            0 :               gcc_unreachable ();
    7851              :             }
    7852              :         }
    7853            0 :       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
    7854              :         {
    7855            0 :           if (name)
    7856            0 :             error ("%qs specified for parameter %qE",
    7857              :                    c_addr_space_name (address_space), name);
    7858              :           else
    7859            0 :             error ("%qs specified for unnamed parameter",
    7860              :                    c_addr_space_name (address_space));
    7861              :         }
    7862            0 :       else if (decl_context == FIELD)
    7863              :         {
    7864            0 :           if (name)
    7865            0 :             error ("%qs specified for structure field %qE",
    7866              :                    c_addr_space_name (address_space), name);
    7867              :           else
    7868            0 :             error ("%qs specified for structure field",
    7869              :                    c_addr_space_name (address_space));
    7870              :         }
    7871              :     }
    7872              : 
    7873              :   /* Check the type and width of a bit-field.  */
    7874    325584065 :   if (bitfield)
    7875              :     {
    7876        55124 :       check_bitfield_type_and_width (loc, &type, width, name);
    7877              :       /* C11 makes it implementation-defined (6.7.2.1#5) whether
    7878              :          atomic types are permitted for bit-fields; we have no code to
    7879              :          make bit-field accesses atomic, so disallow them.  */
    7880        55124 :       if (type_quals.has (TYPE_QUAL_ATOMIC))
    7881              :         {
    7882            2 :           if (name)
    7883            1 :             error_at (loc, "bit-field %qE has atomic type", name);
    7884              :           else
    7885            1 :             error_at (loc, "bit-field has atomic type");
    7886            2 :           type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    7887              :         }
    7888              :     }
    7889              : 
    7890              :   /* Reject invalid uses of _Alignas.  */
    7891    325584065 :   if (declspecs->alignas_p)
    7892              :     {
    7893          190 :       if (storage_class == csc_typedef)
    7894            1 :         error_at (loc, "alignment specified for typedef %qE", name);
    7895          189 :       else if (storage_class == csc_register)
    7896            1 :         error_at (loc, "alignment specified for %<register%> object %qE",
    7897              :                   name);
    7898          188 :       else if (decl_context == PARM)
    7899              :         {
    7900            2 :           if (name)
    7901            1 :             error_at (loc, "alignment specified for parameter %qE", name);
    7902              :           else
    7903            1 :             error_at (loc, "alignment specified for unnamed parameter");
    7904              :         }
    7905          186 :       else if (bitfield)
    7906              :         {
    7907            0 :           if (name)
    7908            0 :             error_at (loc, "alignment specified for bit-field %qE", name);
    7909              :           else
    7910            0 :             error_at (loc, "alignment specified for unnamed bit-field");
    7911              :         }
    7912          186 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
    7913            1 :         error_at (loc, "alignment specified for function %qE", name);
    7914          185 :       else if (declspecs->align_log != -1 && TYPE_P (type))
    7915              :         {
    7916          158 :           alignas_align = 1U << declspecs->align_log;
    7917          158 :           if (alignas_align < min_align_of_type (type))
    7918              :             {
    7919           26 :               if (name)
    7920           25 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7921              :                           "alignment of %qE", name);
    7922              :               else
    7923            1 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7924              :                           "alignment of unnamed field");
    7925              :               alignas_align = 0;
    7926              :             }
    7927              :         }
    7928              :     }
    7929              : 
    7930              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
    7931              : 
    7932    325584065 :   if (storage_class == csc_typedef)
    7933              :     {
    7934      4375593 :       tree decl;
    7935      4375593 :       if ((type_quals.has (TYPE_QUAL_ATOMIC))
    7936      4375593 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7937              :         {
    7938            0 :           error_at (loc,
    7939              :                     "%<_Atomic%>-qualified function type");
    7940            0 :           type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    7941              :         }
    7942       133642 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7943      4375593 :                && type_quals)
    7944            0 :         pedwarn (loc, OPT_Wpedantic,
    7945              :                  "ISO C forbids qualified function types");
    7946      4375593 :       if (type_quals)
    7947        32005 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7948              :                                        orig_qual_indirect);
    7949      8751186 :       decl = build_decl (declarator->id_loc,
    7950      4375593 :                          TYPE_DECL, declarator->u.id.id, type);
    7951      4375593 :       if (declspecs->explicit_signed_p)
    7952       358192 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
    7953      4375593 :       if (declspecs->inline_p)
    7954            4 :         pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
    7955      4375593 :       if (declspecs->noreturn_p)
    7956            1 :         pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
    7957              : 
    7958      4375593 :       if (warn_cxx_compat && declarator->u.id.id != NULL_TREE)
    7959              :         {
    7960         1828 :           struct c_binding *b = I_TAG_BINDING (declarator->u.id.id);
    7961              : 
    7962         1828 :           if (b != NULL
    7963           40 :               && b->decl != NULL_TREE
    7964           40 :               && (B_IN_CURRENT_SCOPE (b)
    7965            4 :                   || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    7966         1864 :               && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
    7967              :             {
    7968            7 :               auto_diagnostic_group d;
    7969            8 :               if (warning_at (declarator->id_loc, OPT_Wc___compat,
    7970              :                               "using %qD as both a typedef and a tag is "
    7971              :                               "invalid in C++", decl)
    7972            7 :                   && b->locus != UNKNOWN_LOCATION)
    7973            6 :                 inform (b->locus, "originally defined here");
    7974            7 :             }
    7975              :         }
    7976              : 
    7977              :       return decl;
    7978              :     }
    7979              : 
    7980              :   /* If this is a type name (such as, in a cast or sizeof),
    7981              :      compute the type and return it now.  */
    7982              : 
    7983    321208472 :   if (decl_context == TYPENAME || decl_context == GENERIC_ASSOC)
    7984              :     {
    7985              :       /* Note that the grammar rejects storage classes in typenames
    7986              :          and fields.  */
    7987    126428273 :       gcc_assert (storage_class == csc_none && !threadp
    7988              :                   && !declspecs->inline_p && !declspecs->noreturn_p);
    7989    126428273 :       if (type_quals.has (TYPE_QUAL_ATOMIC)
    7990    126428273 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7991              :         {
    7992            0 :           error_at (loc,
    7993              :                     "%<_Atomic%>-qualified function type");
    7994            0 :           type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    7995              :         }
    7996       308144 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7997    126428273 :                && type_quals)
    7998            0 :         pedwarn (loc, OPT_Wpedantic,
    7999              :                  "ISO C forbids const or volatile function types");
    8000    126428273 :       if (type_quals)
    8001        43083 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8002              :                                        orig_qual_indirect);
    8003    126428273 :       return type;
    8004              :     }
    8005              : 
    8006       396825 :   if (pedantic && decl_context == FIELD
    8007    194802848 :       && c_type_variably_modified_p (type))
    8008              :     {
    8009              :       /* C99 6.7.2.1p8 */
    8010            7 :       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
    8011              :                "have a variably modified type");
    8012              :     }
    8013              : 
    8014              :   /* Aside from typedefs and type names (handle above),
    8015              :      `void' at top level (not within pointer)
    8016              :      is allowed only in public variables.
    8017              :      We don't complain about parms either, but that is because
    8018              :      a better error message can be made later.  */
    8019              : 
    8020    194780199 :   if (VOID_TYPE_P (type) && decl_context != PARM
    8021           64 :       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
    8022              :             && (storage_class == csc_extern
    8023           27 :                 || (current_scope == file_scope
    8024           18 :                     && !(storage_class == csc_static
    8025              :                          || storage_class == csc_register)))))
    8026              :     {
    8027           15 :       error_at (loc, "variable or field %qE declared void", name);
    8028           15 :       type = integer_type_node;
    8029              :     }
    8030              : 
    8031              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
    8032              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
    8033              : 
    8034    193787231 :   {
    8035    193787231 :     tree decl;
    8036              : 
    8037    193787231 :     if (decl_context == PARM)
    8038              :       {
    8039    128407910 :         tree promoted_type;
    8040    128407910 :         bool array_parameter_p = false;
    8041              : 
    8042              :         /* A parameter declared as an array of T is really a pointer to T.
    8043              :            One declared as a function is really a pointer to a function.  */
    8044              : 
    8045    128407910 :         if (TREE_CODE (type) == ARRAY_TYPE)
    8046              :           {
    8047       441961 :             if (!size_error)
    8048       441947 :               *decl_attrs = build_arg_spec_attribute (type, array_parm_static,
    8049              :                                                       *decl_attrs);
    8050              : 
    8051              :             /* Transfer const-ness of array into that of type pointed to.  */
    8052       441961 :             type = TREE_TYPE (type);
    8053       441961 :             if (orig_qual_type != NULL_TREE)
    8054              :               {
    8055            7 :                 if (orig_qual_indirect == 0)
    8056            5 :                   orig_qual_type = TREE_TYPE (orig_qual_type);
    8057              :                 else
    8058            2 :                   orig_qual_indirect--;
    8059              :               }
    8060       441961 :             if (type_quals)
    8061        48451 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8062              :                                              orig_qual_indirect);
    8063              : 
    8064              :             /* The pointed-to type may need a decl expr (see above).  */
    8065       441961 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    8066              :               {
    8067          375 :                 bool bind_p = decl_context == TYPENAME
    8068              :                               || decl_context == FIELD
    8069              :                               || decl_context == PARM;
    8070          375 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    8071              :               }
    8072              : 
    8073       441961 :             type = c_build_pointer_type (type);
    8074       441961 :             type_quals = array_ptr_quals;
    8075       441961 :             if (type_quals)
    8076          965 :               type = c_build_qualified_type (type, type_quals);
    8077              : 
    8078              :             /* We don't yet implement attributes in this context.  */
    8079       441961 :             if (array_ptr_attrs != NULL_TREE)
    8080            0 :               warning_at (loc, OPT_Wattributes,
    8081              :                           "attributes in parameter array declarator ignored");
    8082              : 
    8083              :             size_varies = false;
    8084              :             array_parameter_p = true;
    8085              :           }
    8086    127965949 :         else if (TREE_CODE (type) == FUNCTION_TYPE)
    8087              :           {
    8088          301 :             if (type_quals.has (TYPE_QUAL_ATOMIC))
    8089              :               {
    8090            1 :                 error_at (loc,
    8091              :                           "%<_Atomic%>-qualified function type");
    8092            1 :                 type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    8093              :               }
    8094          300 :             else if (type_quals)
    8095            0 :               pedwarn (loc, OPT_Wpedantic,
    8096              :                        "ISO C forbids qualified function types");
    8097          301 :             if (type_quals)
    8098            0 :               type = c_build_qualified_type (type, type_quals);
    8099          301 :             type = c_build_pointer_type (type);
    8100          301 :             type_quals = TYPE_UNQUALIFIED;
    8101              :           }
    8102    127965648 :         else if (type_quals)
    8103     10291637 :           type = c_build_qualified_type (type, type_quals);
    8104              : 
    8105    256815820 :         decl = build_decl (declarator->id_loc,
    8106    128407910 :                            PARM_DECL, declarator->u.id.id, type);
    8107    128407910 :         if (size_varies)
    8108           42 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8109    128407910 :         C_ARRAY_PARAMETER (decl) = array_parameter_p;
    8110              : 
    8111              :         /* Compute the type actually passed in the parmlist,
    8112              :            for the case where there is no prototype.
    8113              :            (For example, shorts and chars are passed as ints.)
    8114              :            When there is a prototype, this is overridden later.  */
    8115              : 
    8116    128407910 :         if (type == error_mark_node)
    8117              :           promoted_type = type;
    8118              :         else
    8119    128407826 :           promoted_type = c_type_promotes_to (type);
    8120              : 
    8121    128407910 :         DECL_ARG_TYPE (decl) = promoted_type;
    8122    128407910 :         if (declspecs->inline_p)
    8123            4 :           pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
    8124    128407910 :         if (declspecs->noreturn_p)
    8125            1 :           pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
    8126              :       }
    8127     66372289 :     else if (decl_context == FIELD)
    8128              :       {
    8129              :         /* Note that the grammar rejects storage classes in typenames
    8130              :            and fields.  */
    8131      4361627 :         gcc_assert (storage_class == csc_none && !threadp
    8132              :                     && !declspecs->inline_p && !declspecs->noreturn_p);
    8133              : 
    8134              :         /* Structure field.  It may not be a function.  */
    8135              : 
    8136      4361627 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8137              :           {
    8138            0 :             error_at (loc, "field %qE declared as a function", name);
    8139            0 :             type = c_build_pointer_type (type);
    8140              :           }
    8141      4361627 :         else if (TREE_CODE (type) != ERROR_MARK
    8142      4361627 :                  && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
    8143              :           {
    8144           24 :             if (name)
    8145           17 :               error_at (loc, "field %qE has incomplete type", name);
    8146              :             else
    8147            7 :               error_at (loc, "unnamed field has incomplete type");
    8148           24 :             type = error_mark_node;
    8149              :           }
    8150      4361603 :         else if (TREE_CODE (type) == ARRAY_TYPE
    8151      4361603 :                  && TYPE_DOMAIN (type) == NULL_TREE)
    8152              :           {
    8153              :             /* We have a flexible array member through a typedef.
    8154              :                Set suitable range.  Whether this is a correct position
    8155              :                for a flexible array member will be determined elsewhere.  */
    8156           14 :             if (!in_system_header_at (input_location))
    8157           14 :               pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    8158              :                            "support flexible array members");
    8159           14 :             type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    8160           14 :             TYPE_DOMAIN (type) = build_index_type (NULL_TREE);
    8161           14 :             if (orig_qual_indirect == 0)
    8162      4361627 :               orig_qual_type = NULL_TREE;
    8163              :           }
    8164      4361627 :         if (type != error_mark_node
    8165      4361627 :             && !verify_type_context (loc, TCTX_FIELD, type))
    8166            0 :           type = error_mark_node;
    8167              : 
    8168      4361627 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8169              :                                        orig_qual_indirect);
    8170      8723254 :         decl = build_decl (declarator->id_loc,
    8171      4361627 :                            FIELD_DECL, declarator->u.id.id, type);
    8172      4361627 :         DECL_NONADDRESSABLE_P (decl) = bitfield;
    8173      4361627 :         if (bitfield && !declarator->u.id.id)
    8174        11621 :           DECL_PADDING_P (decl) = 1;
    8175              : 
    8176      4361627 :         if (size_varies)
    8177          669 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8178              :       }
    8179     62010662 :     else if (TREE_CODE (type) == FUNCTION_TYPE)
    8180              :       {
    8181     53005302 :         if (storage_class == csc_register || threadp || constexprp)
    8182              :           {
    8183           12 :             error_at (loc, "invalid storage class for function %qE", name);
    8184              :           }
    8185     53005290 :         else if (current_scope != file_scope)
    8186              :           {
    8187              :             /* Function declaration not at file scope.  Storage
    8188              :                classes other than `extern' are not allowed, C99
    8189              :                6.7.1p5, and `extern' makes no difference.  However,
    8190              :                GCC allows 'auto', perhaps with 'inline', to support
    8191              :                nested functions.  */
    8192        10587 :             if (storage_class == csc_auto)
    8193           66 :                 pedwarn (loc, OPT_Wpedantic,
    8194              :                          "invalid storage class for function %qE", name);
    8195        10521 :             else if (storage_class == csc_static)
    8196              :               {
    8197           20 :                 error_at (loc, "invalid storage class for function %qE", name);
    8198           20 :                 if (funcdef_flag)
    8199            8 :                   storage_class = declspecs->storage_class = csc_none;
    8200              :                 else
    8201              :                   return NULL_TREE;
    8202              :               }
    8203              :           }
    8204              : 
    8205    106010580 :         decl = build_decl (declarator->id_loc,
    8206     53005290 :                            FUNCTION_DECL, declarator->u.id.id, type);
    8207     53005290 :         decl = build_decl_attribute_variant (decl, decl_attr);
    8208              : 
    8209     53005290 :         if (type_quals.has (TYPE_QUAL_ATOMIC))
    8210              :           {
    8211            2 :             error_at (loc,
    8212              :                       "%<_Atomic%>-qualified function type");
    8213            2 :             type_quals = type_quals.without (TYPE_QUAL_ATOMIC);
    8214              :           }
    8215     53005297 :         else if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
    8216            9 :           pedwarn (loc, OPT_Wpedantic,
    8217              :                    "ISO C forbids qualified function types");
    8218              : 
    8219              :         /* Every function declaration is an external reference
    8220              :            (DECL_EXTERNAL) except for those which are not at file
    8221              :            scope and are explicitly declared "auto".  This is
    8222              :            forbidden by standard C (C99 6.7.1p5) and is interpreted by
    8223              :            GCC to signify a forward declaration of a nested function.  */
    8224     53005290 :         if (storage_class == csc_auto && current_scope != file_scope)
    8225           66 :           DECL_EXTERNAL (decl) = 0;
    8226              :         /* In C99, a function which is declared 'inline' with 'extern'
    8227              :            is not an external reference (which is confusing).  It
    8228              :            means that the later definition of the function must be output
    8229              :            in this file, C99 6.7.4p6.  In GNU C89, a function declared
    8230              :            'extern inline' is an external reference.  */
    8231     53005224 :         else if (declspecs->inline_p && storage_class != csc_static)
    8232     36800231 :           DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
    8233     36800231 :                                   == flag_gnu89_inline);
    8234              :         else
    8235     16204993 :           DECL_EXTERNAL (decl) = !initialized;
    8236              : 
    8237              :         /* Record absence of global scope for `static' or `auto'.  */
    8238     53005290 :         TREE_PUBLIC (decl)
    8239     53005290 :           = !(storage_class == csc_static || storage_class == csc_auto);
    8240              : 
    8241              :         /* For a function definition, record the argument information
    8242              :            block where store_parm_decls will look for it.  */
    8243     53005290 :         if (funcdef_flag)
    8244     37669275 :           current_function_arg_info = arg_info;
    8245              : 
    8246     53005290 :         if (declspecs->default_int_p)
    8247         9220 :           C_FUNCTION_IMPLICIT_INT (decl) = 1;
    8248              : 
    8249              :         /* Record presence of `inline' and `_Noreturn', if it is
    8250              :            reasonable.  */
    8251     53005290 :         if (flag_hosted && MAIN_NAME_P (declarator->u.id.id))
    8252              :           {
    8253        49406 :             if (declspecs->inline_p)
    8254            5 :               pedwarn (loc, 0, "cannot inline function %<main%>");
    8255        49406 :             if (declspecs->noreturn_p)
    8256            1 :               pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
    8257              :           }
    8258              :         else
    8259              :           {
    8260     52955884 :             if (declspecs->inline_p)
    8261              :               /* Record that the function is declared `inline'.  */
    8262     36965289 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8263     52955884 :             if (declspecs->noreturn_p)
    8264              :               {
    8265        23307 :                 if (flag_isoc99)
    8266        23304 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8267              :                                "ISO C99 does not support %<_Noreturn%>");
    8268              :                 else
    8269            3 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8270              :                                "ISO C90 does not support %<_Noreturn%>");
    8271        23307 :                 TREE_THIS_VOLATILE (decl) = 1;
    8272              :               }
    8273              :           }
    8274              : 
    8275              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8276              :            behavior) to create an 'extern' declaration for a
    8277              :            function if there is a global declaration that is
    8278              :            'static' and the global declaration is not visible.
    8279              :            (If the static declaration _is_ currently visible,
    8280              :            the 'extern' declaration is taken to refer to that decl.) */
    8281     53005290 :         if (!initialized
    8282     15336006 :             && TREE_PUBLIC (decl)
    8283     15328053 :             && current_scope != file_scope)
    8284              :           {
    8285         8890 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8286         8890 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8287              : 
    8288         8890 :             if (global_decl
    8289         8890 :                 && global_decl != visible_decl
    8290         1713 :                 && VAR_OR_FUNCTION_DECL_P (global_decl)
    8291         1713 :                 && !TREE_PUBLIC (global_decl))
    8292            2 :               error_at (loc, "function previously declared %<static%> "
    8293              :                         "redeclared %<extern%>");
    8294              :           }
    8295              :       }
    8296              :     else
    8297              :       {
    8298              :         /* It's a variable.  */
    8299              :         /* An uninitialized decl with `extern' is a reference.  */
    8300      9005360 :         int extern_ref = !initialized && storage_class == csc_extern;
    8301              : 
    8302      9005360 :         if (constexprp)
    8303              :           {
    8304              :             /* The type of a constexpr variable must not be variably
    8305              :                modified, volatile, atomic or restrict qualified or
    8306              :                have a member with such a qualifier.  const
    8307              :                qualification is implicitly added, and, at file scope,
    8308              :                has internal linkage.  */
    8309          386 :             if (c_type_variably_modified_p (type))
    8310            1 :               error_at (loc, "%<constexpr%> object has variably modified "
    8311              :                         "type");
    8312          386 :             if (type_quals.has
    8313          386 :                 (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    8314            9 :               error_at (loc, "invalid qualifiers for %<constexpr%> object");
    8315              :             else
    8316              :               {
    8317          377 :                 tree type_no_array = strip_array_types (type);
    8318          377 :                 if (RECORD_OR_UNION_TYPE_P (type_no_array)
    8319          377 :                     && C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array))
    8320            8 :                   error_at (loc, "invalid qualifiers for field of "
    8321              :                             "%<constexpr%> object");
    8322              :               }
    8323          386 :             type_quals |= TYPE_QUAL_CONST;
    8324          386 :             if (current_scope == file_scope)
    8325          296 :               storage_class = csc_static;
    8326              :           }
    8327              : 
    8328      9005360 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8329              :                                        orig_qual_indirect);
    8330              : 
    8331              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8332              :            behavior) to create an 'extern' declaration for a
    8333              :            variable if there is a global declaration that is
    8334              :            'static' and the global declaration is not visible.
    8335              :            (If the static declaration _is_ currently visible,
    8336              :            the 'extern' declaration is taken to refer to that decl.) */
    8337      9005360 :         if (extern_ref && current_scope != file_scope)
    8338              :           {
    8339         1571 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8340         1571 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8341              : 
    8342         1571 :             if (global_decl
    8343         1571 :                 && global_decl != visible_decl
    8344          282 :                 && VAR_P (global_decl)
    8345          282 :                 && !TREE_PUBLIC (global_decl))
    8346            8 :               error_at (loc, "variable previously declared %<static%> "
    8347              :                         "redeclared %<extern%>");
    8348              :           }
    8349              : 
    8350     18010720 :         decl = build_decl (declarator->id_loc,
    8351      9005360 :                            VAR_DECL, declarator->u.id.id, type);
    8352      9005360 :         if (size_varies)
    8353         7451 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8354      9005360 :         if (constexprp)
    8355          386 :           C_DECL_DECLARED_CONSTEXPR (decl) = 1;
    8356              : 
    8357      9005360 :         if (declspecs->inline_p)
    8358            4 :           pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
    8359      9005360 :         if (declspecs->noreturn_p)
    8360            1 :           pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
    8361              : 
    8362              :         /* At file scope, an initialized extern declaration may follow
    8363              :            a static declaration.  In that case, DECL_EXTERNAL will be
    8364              :            reset later in start_decl.  */
    8365      9005360 :         DECL_EXTERNAL (decl) = (storage_class == csc_extern);
    8366              : 
    8367              :         /* At file scope, the presence of a `static' or `register' storage
    8368              :            class specifier, or the absence of all storage class specifiers
    8369              :            makes this declaration a definition (perhaps tentative).  Also,
    8370              :            the absence of `static' makes it public.  */
    8371      9005360 :         if (current_scope == file_scope)
    8372              :           {
    8373      1155648 :             TREE_PUBLIC (decl) = storage_class != csc_static;
    8374      1155648 :             TREE_STATIC (decl) = !extern_ref;
    8375              :           }
    8376              :         /* Not at file scope, only `static' makes a static definition.  */
    8377              :         else
    8378              :           {
    8379      7849712 :             TREE_STATIC (decl) = (storage_class == csc_static);
    8380      7849712 :             TREE_PUBLIC (decl) = extern_ref;
    8381              :           }
    8382              : 
    8383              :         // NB: Set a tentative TLS model to avoid tls_model attribute
    8384              :         // warnings due to lack of thread storage duration.  It will
    8385              :         // be updated by c_decl_attributes later.
    8386      9005360 :         if (threadp)
    8387         2853 :           set_decl_tls_model (decl, TLS_MODEL_REAL);
    8388              :       }
    8389              : 
    8390    194780187 :     if ((storage_class == csc_extern
    8391    142792573 :          || (storage_class == csc_none
    8392    142321833 :              && TREE_CODE (type) == FUNCTION_TYPE
    8393       820345 :              && !funcdef_flag))
    8394    195089979 :         && c_type_variably_modified_p (type))
    8395              :       {
    8396              :         /* C99 6.7.5.2p2 */
    8397            6 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8398            4 :           error_at (loc, "non-nested function with variably modified type");
    8399              :         else
    8400            2 :           error_at (loc, "object with variably modified type must have "
    8401              :                     "no linkage");
    8402              :       }
    8403              : 
    8404              :     /* For nested functions disqualify ones taking VLAs by value
    8405              :        from inlining since the middle-end cannot deal with this.
    8406              :        ???  We should arrange for those to be passed by reference
    8407              :        with emitting the copy on the caller side in the frontend.  */
    8408    194780187 :     if (storage_class == csc_none
    8409    142321833 :         && TREE_CODE (type) == FUNCTION_TYPE)
    8410      4216308 :       for (tree al = TYPE_ARG_TYPES (type); al; al = TREE_CHAIN (al))
    8411              :         {
    8412      3396003 :           tree arg = TREE_VALUE (al);
    8413      3396003 :           if (arg != error_mark_node
    8414      3396003 :               && C_TYPE_VARIABLE_SIZE (arg))
    8415              :             {
    8416           40 :               DECL_UNINLINABLE (decl) = 1;
    8417           40 :               break;
    8418              :             }
    8419              :         }
    8420              : 
    8421              :     /* Record `register' declaration for warnings on &
    8422              :        and in case doing stupid register allocation.  */
    8423              : 
    8424    194780187 :     if (storage_class == csc_register
    8425         3650 :         && TREE_CODE (type) != FUNCTION_TYPE)
    8426              :       {
    8427         3644 :         C_DECL_REGISTER (decl) = 1;
    8428         3644 :         DECL_REGISTER (decl) = 1;
    8429              :       }
    8430              : 
    8431              :     /* Record constancy and volatility.  */
    8432    194780187 :     c_apply_type_quals_to_decl (type_quals, decl);
    8433              : 
    8434              :     /* Apply _Alignas specifiers.  */
    8435    194780187 :     if (alignas_align)
    8436              :       {
    8437          123 :         SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    8438          123 :         DECL_USER_ALIGN (decl) = 1;
    8439              :       }
    8440              : 
    8441              :     /* If a type has volatile components, it should be stored in memory.
    8442              :        Otherwise, the fact that those components are volatile
    8443              :        will be ignored, and would even crash the compiler.
    8444              :        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
    8445    194780187 :     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
    8446    194780187 :         && (VAR_P (decl) ||  TREE_CODE (decl) == PARM_DECL
    8447              :           || TREE_CODE (decl) == RESULT_DECL))
    8448              :       {
    8449              :         /* It is not an error for a structure with volatile fields to
    8450              :            be declared register, but reset DECL_REGISTER since it
    8451              :            cannot actually go in a register.  */
    8452          186 :         int was_reg = C_DECL_REGISTER (decl);
    8453          186 :         C_DECL_REGISTER (decl) = 0;
    8454          186 :         DECL_REGISTER (decl) = 0;
    8455          186 :         c_mark_addressable (decl);
    8456          186 :         C_DECL_REGISTER (decl) = was_reg;
    8457              :       }
    8458              : 
    8459              :   /* This is the earliest point at which we might know the assembler
    8460              :      name of a variable.  Thus, if it's known before this, die horribly.  */
    8461    194780187 :     gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
    8462              :                 || !DECL_ASSEMBLER_NAME_SET_P (decl));
    8463              : 
    8464    194780187 :     if (warn_cxx_compat
    8465        25047 :         && VAR_P (decl)
    8466         7658 :         && TREE_PUBLIC (decl)
    8467         2828 :         && TREE_STATIC (decl)
    8468         2365 :         && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    8469         2233 :             || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    8470    194780334 :         && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
    8471            4 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    8472              :                   "non-local variable %qD with anonymous type is "
    8473              :                   "questionable in C++", decl);
    8474              : 
    8475              :     return decl;
    8476              :   }
    8477              : }
    8478              : 
    8479              : /* Decode the parameter-list info for a function type or function definition.
    8480              :    The argument is the value returned by `get_parm_info' (or made in c-parse.c
    8481              :    if there is an identifier list instead of a parameter decl list).
    8482              :    These two functions are separate because when a function returns
    8483              :    or receives functions then each is called multiple times but the order
    8484              :    of calls is different.  The last call to `grokparms' is always the one
    8485              :    that contains the formal parameter names of a function definition.
    8486              : 
    8487              :    Return a list of arg types to use in the FUNCTION_TYPE for this function.
    8488              : 
    8489              :    FUNCDEF_FLAG is true for a function definition, false for
    8490              :    a mere declaration.  A nonempty identifier-list gets an error message
    8491              :    when FUNCDEF_FLAG is false.  */
    8492              : 
    8493              : static tree
    8494     52592532 : grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
    8495              : {
    8496     52592532 :   tree arg_types = arg_info->types;
    8497              : 
    8498     52592532 :   if (funcdef_flag && arg_info->had_vla_unspec)
    8499              :     {
    8500              :       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
    8501              :       /* C99 6.7.5.2p4 */
    8502            2 :       error ("%<[*]%> not allowed in other than function prototype scope");
    8503              :     }
    8504              : 
    8505       715885 :   if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc23
    8506     52595593 :       && !in_system_header_at (input_location))
    8507         3061 :     warning (OPT_Wstrict_prototypes,
    8508              :              "function declaration isn%'t a prototype");
    8509              : 
    8510     52592532 :   if (arg_types == error_mark_node)
    8511              :     /* Don't set TYPE_ARG_TYPES in this case.  */
    8512              :     return NULL_TREE;
    8513              : 
    8514    104395423 :   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
    8515              :     {
    8516         8684 :       if (!funcdef_flag)
    8517              :         {
    8518           13 :           permerror_opt (input_location,
    8519           13 :                          OPT_Wdeclaration_missing_parameter_type,
    8520              :                          "parameter names (without types) in "
    8521              :                          "function declaration");
    8522           13 :           arg_info->parms = NULL_TREE;
    8523              :         }
    8524              :       else
    8525         8671 :         arg_info->parms = arg_info->types;
    8526              : 
    8527         8684 :       arg_info->types = NULL_TREE;
    8528         8684 :       return NULL_TREE;
    8529              :     }
    8530              :   else
    8531              :     {
    8532     52583848 :       tree parm, type, typelt;
    8533     52583848 :       unsigned int parmno;
    8534              : 
    8535              :       /* In C23, convert () to (void).  */
    8536     52583848 :       if (flag_isoc23
    8537     43304759 :           && !arg_types
    8538       781996 :           && !arg_info->parms
    8539       781996 :           && !arg_info->no_named_args_stdarg_p)
    8540              :         {
    8541       781853 :           arg_types = arg_info->types = void_list_node;
    8542       781853 :           arg_info->c23_empty_parens = 1;
    8543              :         }
    8544              : 
    8545              :       /* If there is a parameter of incomplete type in a definition,
    8546              :          this is an error.  In a declaration this is valid, and a
    8547              :          struct or union type may be completed later, before any calls
    8548              :          or definition of the function.  In the case where the tag was
    8549              :          first declared within the parameter list, a warning has
    8550              :          already been given.  If a parameter has void type, then
    8551              :          this has already received an error (constraint violation in C2Y,
    8552              :          previously implicitly undefined behavior).  */
    8553              : 
    8554     52583848 :       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
    8555    179975956 :            parm;
    8556    127392108 :            parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
    8557              :         {
    8558    127392108 :           type = TREE_VALUE (typelt);
    8559    127392108 :           if (type == error_mark_node)
    8560           61 :             continue;
    8561              : 
    8562    127392047 :           if (!COMPLETE_TYPE_P (type))
    8563              :             {
    8564           40 :               if (funcdef_flag)
    8565              :                 {
    8566           13 :                   if (DECL_NAME (parm))
    8567           13 :                     error_at (input_location,
    8568              :                               "parameter %u (%q+D) has incomplete type",
    8569              :                               parmno, parm);
    8570              :                   else
    8571            0 :                     error_at (DECL_SOURCE_LOCATION (parm),
    8572              :                               "parameter %u has incomplete type",
    8573              :                               parmno);
    8574              : 
    8575           13 :                   TREE_VALUE (typelt) = error_mark_node;
    8576           13 :                   TREE_TYPE (parm) = error_mark_node;
    8577           13 :                   arg_types = NULL_TREE;
    8578              :                 }
    8579              :             }
    8580              : 
    8581    127392047 :           if (DECL_NAME (parm) && TREE_USED (parm))
    8582        17739 :             warn_if_shadowing (parm);
    8583              :         }
    8584              :       return arg_types;
    8585              :     }
    8586              : }
    8587              : 
    8588              : /* Allocate and initialize a c_arg_info structure from the parser's
    8589              :    obstack.  */
    8590              : 
    8591              : struct c_arg_info *
    8592     52592550 : build_arg_info (void)
    8593              : {
    8594     52592550 :   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
    8595     52592550 :   ret->parms = NULL_TREE;
    8596     52592550 :   ret->tags = NULL;
    8597     52592550 :   ret->types = NULL_TREE;
    8598     52592550 :   ret->others = NULL_TREE;
    8599     52592550 :   ret->pending_sizes = NULL;
    8600     52592550 :   ret->had_vla_unspec = 0;
    8601     52592550 :   ret->no_named_args_stdarg_p = 0;
    8602     52592550 :   ret->c23_empty_parens = 0;
    8603     52592550 :   return ret;
    8604              : }
    8605              : 
    8606              : /* Take apart the current scope and return a c_arg_info structure with
    8607              :    info on a parameter list just parsed.
    8608              : 
    8609              :    This structure is later fed to 'grokparms' and 'store_parm_decls'.
    8610              : 
    8611              :    ELLIPSIS being true means the argument list ended in '...' so don't
    8612              :    append a sentinel (void_list_node) to the end of the type-list.
    8613              : 
    8614              :    EXPR is NULL or an expression that needs to be evaluated for the
    8615              :    side effects of array size expressions in the parameters.  */
    8616              : 
    8617              : struct c_arg_info *
    8618     51794236 : get_parm_info (bool ellipsis, tree expr)
    8619              : {
    8620     51794236 :   struct c_binding *b = current_scope->bindings;
    8621     51794236 :   struct c_arg_info *arg_info = build_arg_info ();
    8622              : 
    8623     51794236 :   tree parms = NULL_TREE;
    8624     51794236 :   vec<c_arg_tag, va_gc> *tags = NULL;
    8625     51794236 :   tree types = NULL_TREE;
    8626     51794236 :   tree others = NULL_TREE;
    8627              : 
    8628     51794236 :   bool gave_void_only_once_err = false;
    8629              : 
    8630     51794236 :   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
    8631              : 
    8632              :   /* The bindings in this scope must not get put into a block.
    8633              :      We will take care of deleting the binding nodes.  */
    8634     51794236 :   current_scope->bindings = 0;
    8635              : 
    8636              :   /* This function is only called if there was *something* on the
    8637              :      parameter list.  */
    8638     51794236 :   gcc_assert (b);
    8639              : 
    8640              :   /* A parameter list consisting solely of 'void' indicates that the
    8641              :      function takes no arguments.  But if the 'void' is qualified
    8642              :      (by 'const' or 'volatile'), or has a storage class specifier
    8643              :      ('register'), then the behavior is undefined; issue an error.
    8644              :      Typedefs for 'void' are OK (see DR#157).  */
    8645     51794236 :   if (b->prev == 0                       /* one binding */
    8646     13873007 :       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
    8647     13873007 :       && !DECL_NAME (b->decl)               /* anonymous */
    8648     53683237 :       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
    8649              :     {
    8650       992854 :       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
    8651       992780 :           || C_DECL_REGISTER (b->decl))
    8652           96 :         error_at (b->locus, "%<void%> as only parameter may not be qualified");
    8653              : 
    8654              :       /* There cannot be an ellipsis.  */
    8655       992854 :       if (ellipsis)
    8656           17 :         error_at (b->locus, "%<void%> must be the only parameter");
    8657              : 
    8658       992854 :       arg_info->types = void_list_node;
    8659       992854 :       return arg_info;
    8660              :     }
    8661              : 
    8662     50801382 :   if (!ellipsis)
    8663     50586618 :     types = void_list_node;
    8664              : 
    8665              :   /* Break up the bindings list into parms, tags, types, and others;
    8666              :      apply sanity checks; purge the name-to-decl bindings.  */
    8667    178193953 :   while (b)
    8668              :     {
    8669    127392571 :       tree decl = b->decl;
    8670    127392571 :       tree type = TREE_TYPE (decl);
    8671    127392571 :       c_arg_tag tag;
    8672    127392571 :       const char *keyword;
    8673              : 
    8674    127392571 :       switch (TREE_CODE (decl))
    8675              :         {
    8676    127392231 :         case PARM_DECL:
    8677    127392231 :           if (b->id)
    8678              :             {
    8679    123688997 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8680    123688997 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8681              :             }
    8682              : 
    8683              :           /* Check for forward decls that never got their actual decl.  */
    8684    127392231 :           if (TREE_ASM_WRITTEN (decl))
    8685            4 :             error_at (b->locus,
    8686              :                       "parameter %q+D has just a forward declaration", decl);
    8687              :           /* Check for (..., void, ...) and named void parameters and issue an
    8688              :              error.  */
    8689    127392227 :           else if (VOID_TYPE_P (type))
    8690              :             {
    8691          114 :               if (!gave_void_only_once_err)
    8692              :                 {
    8693          114 :                   error_at (b->locus,
    8694              :                             "%<void%> must be the only parameter and unnamed");
    8695          114 :                   gave_void_only_once_err = true;
    8696              :                 }
    8697              :             }
    8698              :           else
    8699              :             {
    8700              :               /* Valid parameter, add it to the list.  */
    8701    127392113 :               DECL_CHAIN (decl) = parms;
    8702    127392113 :               parms = decl;
    8703              : 
    8704              :               /* Since there is a prototype, args are passed in their
    8705              :                  declared types.  The back end may override this later.  */
    8706    127392113 :               DECL_ARG_TYPE (decl) = type;
    8707    127392113 :               types = tree_cons (0, type, types);
    8708              :             }
    8709              :           break;
    8710              : 
    8711           21 :         case ENUMERAL_TYPE: keyword = "enum"; goto tag;
    8712           20 :         case UNION_TYPE:    keyword = "union"; goto tag;
    8713          101 :         case RECORD_TYPE:   keyword = "struct"; goto tag;
    8714          142 :         tag:
    8715              :           /* Types may not have tag-names, in which case the type
    8716              :              appears in the bindings list with b->id NULL.  */
    8717          142 :           if (b->id)
    8718              :             {
    8719           97 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    8720           97 :               I_TAG_BINDING (b->id) = b->shadowed;
    8721              :             }
    8722              : 
    8723              :           /* Warn about any struct, union or enum tags defined in a
    8724              :              parameter list.  The scope of such types is limited to
    8725              :              the parameter list, which is rarely if ever desirable
    8726              :              (it's impossible to call such a function with type-
    8727              :              correct arguments).  An anonymous union parm type is
    8728              :              meaningful as a GNU extension, so don't warn for that.  */
    8729          142 :           if (TREE_CODE (decl) != UNION_TYPE || b->id != NULL_TREE)
    8730              :             {
    8731          122 :               if (b->id)
    8732              :                 {
    8733              :                   /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8734           97 :                   if (!flag_isoc23 || !COMPLETE_TYPE_P (decl))
    8735           73 :                     warning_at (b->locus, 0,
    8736              :                                 "%<%s %E%> declared inside parameter list"
    8737              :                                 " will not be visible outside of this definition or"
    8738              :                                 " declaration", keyword, b->id);
    8739              :                 }
    8740              :               else
    8741              :                 /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8742           25 :                 warning_at (b->locus, 0,
    8743              :                             "anonymous %s declared inside parameter list"
    8744              :                             " will not be visible outside of this definition or"
    8745              :                             " declaration", keyword);
    8746              :             }
    8747              : 
    8748          142 :           tag.id = b->id;
    8749          142 :           tag.type = decl;
    8750          142 :           vec_safe_push (tags, tag);
    8751          142 :           break;
    8752              : 
    8753           20 :         case FUNCTION_DECL:
    8754              :           /* FUNCTION_DECLs appear when there is an implicit function
    8755              :              declaration in the parameter list.  */
    8756           20 :           gcc_assert (b->nested || seen_error ());
    8757           20 :           goto set_shadowed;
    8758              : 
    8759          144 :         case CONST_DECL:
    8760          144 :         case TYPE_DECL:
    8761              :           /* CONST_DECLs appear here when we have an embedded enum,
    8762              :              and TYPE_DECLs appear here when we have an embedded struct
    8763              :              or union.  No warnings for this - we already warned about the
    8764              :              type itself.  */
    8765              : 
    8766              :           /* When we reinsert this decl in the function body, we need
    8767              :              to reconstruct whether it was marked as nested.  */
    8768          144 :           gcc_assert (!b->nested);
    8769          144 :           DECL_CHAIN (decl) = others;
    8770          144 :           others = decl;
    8771              :           /* fall through */
    8772              : 
    8773          198 :         case ERROR_MARK:
    8774          198 :         set_shadowed:
    8775              :           /* error_mark_node appears here when we have an undeclared
    8776              :              variable.  Just throw it away.  */
    8777          198 :           if (b->id)
    8778              :             {
    8779           56 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8780           56 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8781              :             }
    8782              :           break;
    8783              : 
    8784              :           /* Other things that might be encountered.  */
    8785            0 :         case LABEL_DECL:
    8786            0 :         case VAR_DECL:
    8787            0 :         default:
    8788            0 :           gcc_unreachable ();
    8789              :         }
    8790              : 
    8791    127392571 :       b = free_binding_and_advance (b);
    8792              :     }
    8793              : 
    8794     50801382 :   arg_info->parms = parms;
    8795     50801382 :   arg_info->tags = tags;
    8796     50801382 :   arg_info->types = types;
    8797     50801382 :   arg_info->others = others;
    8798     50801382 :   arg_info->pending_sizes = expr;
    8799     50801382 :   arg_info->no_named_args_stdarg_p = ellipsis && !types;
    8800     50801382 :   return arg_info;
    8801              : }
    8802              : 
    8803              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8804              :    Define the tag as a forward-reference with location LOC if it is
    8805              :    not defined.  HAVE_STD_ATTRS says whether any standard attributes
    8806              :    were present after the struct, union or enum keyword; ATTRS are the
    8807              :    standard attributes present there.  HAS_ENUM_TYPE_SPECIFIER says
    8808              :    whether an enum type specifier (": specifier-qualifier-list") is
    8809              :    present; if so, this is called before that specifier is parsed, so
    8810              :    that the tag is in scope for that specifier.  Return a c_typespec
    8811              :    structure for the type specifier.  */
    8812              : 
    8813              : struct c_typespec
    8814      1105759 : parser_xref_tag (location_t loc, enum tree_code code, tree name,
    8815              :                  bool have_std_attrs, tree attrs, bool has_enum_type_specifier)
    8816              : {
    8817      1105759 :   struct c_typespec ret;
    8818      1105759 :   tree ref;
    8819      1105759 :   location_t refloc;
    8820              : 
    8821      1105759 :   ret.expr = NULL_TREE;
    8822      1105759 :   ret.expr_const_operands = true;
    8823      1105759 :   ret.has_enum_type_specifier = has_enum_type_specifier;
    8824              : 
    8825              :   /* If a cross reference is requested, look up the type already
    8826              :      defined for this tag and return it.  If an enum type specifier is
    8827              :      present, only a definition in the current scope is relevant.  */
    8828              : 
    8829      1105759 :   ref = lookup_tag (code, name, has_enum_type_specifier, &refloc);
    8830              : 
    8831              :   /* If the visible type is still being defined, see if there is
    8832              :      an earlier definition (which may be complete).  We do not
    8833              :      have to loop because nested redefinitions are not allowed.  */
    8834      1105759 :   if (flag_isoc23 && ref && C_TYPE_BEING_DEFINED (ref))
    8835              :     {
    8836        87189 :       tree vis = previous_tag (ref);
    8837        87189 :       if (vis)
    8838           17 :         ref = vis;
    8839              :     }
    8840              : 
    8841              :   /* If this is the right type of tag, return what we found.
    8842              :      (This reference will be shadowed by shadow_tag later if appropriate.)
    8843              :      If this is the wrong type of tag, do not return it.  If it was the
    8844              :      wrong type in the same scope, we will have had an error
    8845              :      message already; if in a different scope and declaring
    8846              :      a name, pending_xref_error will give an error message; but if in a
    8847              :      different scope and not declaring a name, this tag should
    8848              :      shadow the previous declaration of a different type of tag, and
    8849              :      this would not work properly if we return the reference found.
    8850              :      (For example, with "struct foo" in an outer scope, "union foo;"
    8851              :      must shadow that tag with a new one of union type.)  */
    8852      2211518 :   ret.kind = (ref
    8853      1105759 :               ? (have_std_attrs ? ctsk_tagref_attrs : ctsk_tagref)
    8854        95782 :               : (have_std_attrs ? ctsk_tagfirstref_attrs : ctsk_tagfirstref));
    8855      1105759 :   if (ref && TREE_CODE (ref) == code)
    8856              :     {
    8857      1009943 :       decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8858      1009943 :       if (C_TYPE_DEFINED_IN_STRUCT (ref)
    8859            5 :           && loc != UNKNOWN_LOCATION
    8860      1009948 :           && warn_cxx_compat)
    8861              :         {
    8862            5 :           auto_diagnostic_group d;
    8863            5 :           switch (code)
    8864              :             {
    8865            2 :             case ENUMERAL_TYPE:
    8866            2 :               if (warning_at (loc, OPT_Wc___compat,
    8867              :                               ("enum type defined in struct or union "
    8868              :                                "is not visible in C++")))
    8869            2 :                   inform (refloc, "enum type defined here");
    8870              :               break;
    8871            2 :             case RECORD_TYPE:
    8872            2 :               if (warning_at (loc, OPT_Wc___compat,
    8873              :                               ("struct defined in struct or union "
    8874              :                                "is not visible in C++")))
    8875            2 :                 inform (refloc, "struct defined here");
    8876              :               break;
    8877            1 :             case UNION_TYPE:
    8878            1 :               if (warning_at (loc, OPT_Wc___compat,
    8879              :                               ("union defined in struct or union "
    8880              :                                "is not visible in C++")))
    8881            1 :                 inform (refloc, "union defined here");
    8882              :               break;
    8883            0 :             default:
    8884            0 :               gcc_unreachable();
    8885              :             }
    8886            5 :         }
    8887              : 
    8888      1009943 :       ret.spec = ref;
    8889      1009943 :       return ret;
    8890              :     }
    8891              : 
    8892              :   /* If no such tag is yet defined, create a forward-reference node
    8893              :      and record it as the "definition".
    8894              :      When a real declaration of this type is found,
    8895              :      the forward-reference will be altered into a real type.  */
    8896              : 
    8897        95816 :   ref = make_node (code);
    8898        95816 :   if (flag_isoc23 || code == ENUMERAL_TYPE)
    8899        73539 :     SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8900        73539 :   if (code == ENUMERAL_TYPE)
    8901              :     {
    8902              :       /* Give the type a default layout like unsigned int
    8903              :          to avoid crashing if it does not get defined.  */
    8904          277 :       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
    8905          277 :       SET_TYPE_ALIGN (ref, TYPE_ALIGN (unsigned_type_node));
    8906          277 :       TYPE_USER_ALIGN (ref) = 0;
    8907          277 :       TYPE_UNSIGNED (ref) = 1;
    8908          277 :       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
    8909          277 :       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
    8910          277 :       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
    8911          277 :       ENUM_FIXED_UNDERLYING_TYPE_P (ref) = has_enum_type_specifier;
    8912              :     }
    8913              : 
    8914        95816 :   pushtag (loc, name, ref);
    8915        95816 :   decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8916        95816 :   if (in_underspecified_init)
    8917            9 :     error_at (loc, "%qT declared in underspecified object initializer",
    8918              :               ref);
    8919              : 
    8920        95816 :   ret.spec = ref;
    8921        95816 :   return ret;
    8922              : }
    8923              : 
    8924              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8925              :    Define the tag as a forward-reference if it is not defined.
    8926              :    Return a tree for the type.  */
    8927              : 
    8928              : tree
    8929            0 : xref_tag (enum tree_code code, tree name)
    8930              : {
    8931            0 :   return parser_xref_tag (input_location, code, name, false, NULL_TREE,
    8932            0 :                           false).spec;
    8933              : }
    8934              : 
    8935              : /* Make sure that the tag NAME is defined *in the current scope*
    8936              :    at least as a forward reference.
    8937              :    LOC is the location of the struct's definition.
    8938              :    CODE says which kind of tag NAME ought to be.
    8939              : 
    8940              :    This stores the current value of the file static STRUCT_PARSE_INFO
    8941              :    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
    8942              :    new c_struct_parse_info structure.  The old value of
    8943              :    STRUCT_PARSE_INFO is restored in finish_struct.  */
    8944              : 
    8945              : tree
    8946      1193399 : start_struct (location_t loc, enum tree_code code, tree name,
    8947              :               class c_struct_parse_info **enclosing_struct_parse_info)
    8948              : {
    8949              :   /* If there is already a tag defined at this scope
    8950              :      (as a forward reference), just return it.  */
    8951              : 
    8952      1193399 :   tree ref = NULL_TREE;
    8953      1193399 :   location_t refloc = UNKNOWN_LOCATION;
    8954              : 
    8955      1193399 :   if (name != NULL_TREE)
    8956       492931 :     ref = lookup_tag (code, name, true, &refloc);
    8957              : 
    8958              :   /* For C23, even if we already have a completed definition,
    8959              :      we do not use it. We will check for consistency later.
    8960              :      If we are in a nested redefinition the type is not
    8961              :      complete. We will then detect this below.  */
    8962      1193399 :   if (flag_isoc23 && ref && TYPE_SIZE (ref))
    8963              :     ref = NULL_TREE;
    8964              : 
    8965      1193290 :   if (ref && TREE_CODE (ref) == code)
    8966              :     {
    8967        25505 :       if (TYPE_STUB_DECL (ref))
    8968        25505 :         refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
    8969              : 
    8970        25505 :       if (TYPE_SIZE (ref))
    8971              :         {
    8972           11 :           auto_diagnostic_group d;
    8973           11 :           if (code == UNION_TYPE)
    8974            2 :             error_at (loc, "redefinition of %<union %E%>", name);
    8975              :           else
    8976            9 :             error_at (loc, "redefinition of %<struct %E%>", name);
    8977           11 :           if (refloc != UNKNOWN_LOCATION)
    8978           11 :             inform (refloc, "originally defined here");
    8979              :           /* Don't create structures using a name already in use.  */
    8980           11 :           ref = NULL_TREE;
    8981           11 :         }
    8982        25494 :       else if (C_TYPE_BEING_DEFINED (ref))
    8983              :         {
    8984           17 :           if (code == UNION_TYPE)
    8985            1 :             error_at (loc, "nested redefinition of %<union %E%>", name);
    8986              :           else
    8987           16 :             error_at (loc, "nested redefinition of %<struct %E%>", name);
    8988              :           /* Don't bother to report "originally defined here" for a
    8989              :              nested redefinition; the original definition should be
    8990              :              obvious.  */
    8991              :           /* Don't create structures that contain themselves.  */
    8992              :           ref = NULL_TREE;
    8993              :         }
    8994              :     }
    8995              : 
    8996              :   /* Otherwise create a forward-reference just so the tag is in scope.  */
    8997              : 
    8998        25508 :   if (ref == NULL_TREE || TREE_CODE (ref) != code)
    8999              :     {
    9000      1167922 :       ref = make_node (code);
    9001      1167922 :       if (flag_isoc23)
    9002       939216 :         SET_TYPE_STRUCTURAL_EQUALITY (ref);
    9003      1167922 :       pushtag (loc, name, ref);
    9004              :     }
    9005              : 
    9006      1193399 :   C_TYPE_BEING_DEFINED (ref) = 1;
    9007      2417680 :   for (tree v = TYPE_MAIN_VARIANT (ref); v; v = TYPE_NEXT_VARIANT (v))
    9008      1224281 :     TYPE_PACKED (v) = flag_pack_struct;
    9009              : 
    9010      1193399 :   *enclosing_struct_parse_info = struct_parse_info;
    9011      1193399 :   struct_parse_info = new c_struct_parse_info ();
    9012      1193399 :   struct_parse_info->refloc = refloc;
    9013              : 
    9014              :   /* FIXME: This will issue a warning for a use of a type defined
    9015              :      within a statement expr used within sizeof, et. al.  This is not
    9016              :      terribly serious as C++ doesn't permit statement exprs within
    9017              :      sizeof anyhow.  */
    9018      1193399 :   if (warn_cxx_compat
    9019          577 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
    9020           10 :     warning_at (loc, OPT_Wc___compat,
    9021              :                 "defining type in %qs expression is invalid in C++",
    9022              :                 (in_sizeof ? "sizeof"
    9023            4 :                  : in_typeof ? "typeof"
    9024            1 :                  : in_alignof ? "alignof"
    9025              :                  : "_Countof"));
    9026              : 
    9027      1193399 :   if (in_underspecified_init)
    9028           18 :     error_at (loc, "%qT defined in underspecified object initializer", ref);
    9029              : 
    9030      1193399 :   return ref;
    9031              : }
    9032              : 
    9033              : /* Process the specs, declarator and width (NULL if omitted)
    9034              :    of a structure component, returning a FIELD_DECL node.
    9035              :    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
    9036              :    DECL_ATTRS is as for grokdeclarator.
    9037              : 
    9038              :    LOC is the location of the structure component.
    9039              : 
    9040              :    This is done during the parsing of the struct declaration.
    9041              :    The FIELD_DECL nodes are chained together and the lot of them
    9042              :    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
    9043              : 
    9044              : tree
    9045      4361656 : grokfield (location_t loc,
    9046              :            struct c_declarator *declarator, struct c_declspecs *declspecs,
    9047              :            tree width, tree *decl_attrs, tree *expr)
    9048              : {
    9049      4361656 :   tree value;
    9050              : 
    9051      4361656 :   if (declarator->kind == cdk_id && declarator->u.id.id == NULL_TREE
    9052        22478 :       && width == NULL_TREE)
    9053              :     {
    9054              :       /* This is an unnamed decl.
    9055              : 
    9056              :          If we have something of the form "union { list } ;" then this
    9057              :          is the anonymous union extension.  Similarly for struct.
    9058              : 
    9059              :          If this is something of the form "struct foo;", then
    9060              :            If MS or Plan 9 extensions are enabled, this is handled as
    9061              :              an anonymous struct.
    9062              :            Otherwise this is a forward declaration of a structure tag.
    9063              : 
    9064              :          If this is something of the form "foo;" and foo is a TYPE_DECL, then
    9065              :            If foo names a structure or union without a tag, then this
    9066              :              is an anonymous struct (this is permitted by C11).
    9067              :            If MS or Plan 9 extensions are enabled and foo names a
    9068              :              structure, then again this is an anonymous struct.
    9069              :            Otherwise this is an error.
    9070              : 
    9071              :          Oh what a horrid tangled web we weave.  I wonder if MS consciously
    9072              :          took this from Plan 9 or if it was an accident of implementation
    9073              :          that took root before someone noticed the bug...  */
    9074              : 
    9075        10857 :       tree type = declspecs->type;
    9076        10857 :       bool ok = false;
    9077              : 
    9078        10857 :       if (RECORD_OR_UNION_TYPE_P (type)
    9079        10851 :           && (flag_ms_extensions
    9080        10822 :               || flag_plan9_extensions
    9081        10791 :               || !declspecs->typedef_p))
    9082              :         {
    9083        10844 :           if (flag_ms_extensions || flag_plan9_extensions)
    9084              :             ok = true;
    9085        10784 :           else if (TYPE_NAME (type) == NULL)
    9086              :             ok = true;
    9087              :           else
    9088              :             ok = false;
    9089              :         }
    9090              :       if (!ok)
    9091              :         {
    9092           29 :           pedwarn (loc, 0, "declaration does not declare anything");
    9093           29 :           return NULL_TREE;
    9094              :         }
    9095        10828 :       if (flag_isoc99)
    9096        10806 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9097              :                      "ISO C99 doesn%'t support unnamed structs/unions");
    9098              :       else
    9099           22 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9100              :                      "ISO C90 doesn%'t support unnamed structs/unions");
    9101              :     }
    9102              : 
    9103      4361627 :   value = grokdeclarator (declarator, declspecs, FIELD, false,
    9104      4361627 :                           width ? &width : NULL, decl_attrs, expr, NULL,
    9105              :                           DEPRECATED_NORMAL);
    9106              : 
    9107              :   /* When this field has name, its type is a top level type, we should
    9108              :      call verify_counted_by_for_top_anonymous_type.  */
    9109      4361627 :   if (DECL_NAME (value) != NULL_TREE
    9110      4361627 :       && declspecs->typespec_kind == ctsk_tagdef)
    9111       155477 :     verify_counted_by_for_top_anonymous_type (declspecs->type);
    9112              : 
    9113      4361627 :   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
    9114      4361627 :   DECL_INITIAL (value) = width;
    9115      4361627 :   if (width)
    9116        55124 :     SET_DECL_C_BIT_FIELD (value);
    9117              : 
    9118      4361627 :   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
    9119              :     {
    9120              :       /* If we currently have a binding for this field, set the
    9121              :          in_struct field in the binding, so that we warn about lookups
    9122              :          which find it.  */
    9123         1313 :       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
    9124         1313 :       if (b != NULL)
    9125              :         {
    9126              :           /* If the in_struct field is not yet set, push it on a list
    9127              :              to be cleared when this struct is finished.  */
    9128           94 :           if (!b->in_struct)
    9129              :             {
    9130           92 :               struct_parse_info->fields.safe_push (b);
    9131           92 :               b->in_struct = 1;
    9132              :             }
    9133              :         }
    9134              :     }
    9135              : 
    9136              :   return value;
    9137              : }
    9138              : 
    9139              : /* Subroutine of detect_field_duplicates: return whether X and Y,
    9140              :    which are both fields in the same struct, have duplicate field
    9141              :    names.  */
    9142              : 
    9143              : static bool
    9144      4352203 : is_duplicate_field (tree x, tree y)
    9145              : {
    9146      4352203 :   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
    9147              :     return true;
    9148              : 
    9149              :   /* When using -fplan9-extensions, an anonymous field whose name is a
    9150              :      typedef can duplicate a field name.  */
    9151      4352202 :   if (flag_plan9_extensions
    9152      4352202 :       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
    9153              :     {
    9154            0 :       tree xt, xn, yt, yn;
    9155              : 
    9156            0 :       xt = TREE_TYPE (x);
    9157            0 :       if (DECL_NAME (x) != NULL_TREE)
    9158            0 :         xn = DECL_NAME (x);
    9159            0 :       else if (RECORD_OR_UNION_TYPE_P (xt)
    9160            0 :                && TYPE_NAME (xt) != NULL_TREE
    9161            0 :                && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
    9162            0 :         xn = DECL_NAME (TYPE_NAME (xt));
    9163              :       else
    9164              :         xn = NULL_TREE;
    9165              : 
    9166            0 :       yt = TREE_TYPE (y);
    9167            0 :       if (DECL_NAME (y) != NULL_TREE)
    9168            0 :         yn = DECL_NAME (y);
    9169            0 :       else if (RECORD_OR_UNION_TYPE_P (yt)
    9170            0 :                && TYPE_NAME (yt) != NULL_TREE
    9171            0 :                && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
    9172            0 :         yn = DECL_NAME (TYPE_NAME (yt));
    9173              :       else
    9174              :         yn = NULL_TREE;
    9175              : 
    9176            0 :       if (xn != NULL_TREE && xn == yn)
    9177              :         return true;
    9178              :     }
    9179              : 
    9180              :   return false;
    9181              : }
    9182              : 
    9183              : /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
    9184              :    to HTAB, giving errors for any duplicates.  */
    9185              : 
    9186              : static void
    9187        81733 : detect_field_duplicates_hash (tree fieldlist,
    9188              :                               hash_table<nofree_ptr_hash <tree_node> > *htab)
    9189              : {
    9190        81733 :   tree x, y;
    9191        81733 :   tree_node **slot;
    9192              : 
    9193      1421129 :   for (x = fieldlist; x ; x = DECL_CHAIN (x))
    9194      1339396 :     if ((y = DECL_NAME (x)) != NULL_TREE)
    9195              :       {
    9196      1318415 :         slot = htab->find_slot (y, INSERT);
    9197      1318415 :         if (*slot)
    9198              :           {
    9199           15 :             error ("duplicate member %q+D", x);
    9200           15 :             DECL_NAME (x) = NULL_TREE;
    9201              :           }
    9202      1318415 :         *slot = y;
    9203              :       }
    9204        20981 :     else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9205              :       {
    9206        11625 :         detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
    9207              : 
    9208              :         /* When using -fplan9-extensions, an anonymous field whose
    9209              :            name is a typedef can duplicate a field name.  */
    9210        11625 :         if (flag_plan9_extensions
    9211           31 :             && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9212        11655 :             && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
    9213              :           {
    9214           10 :             tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
    9215           10 :             slot = htab->find_slot (xn, INSERT);
    9216           10 :             if (*slot)
    9217            0 :               error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
    9218           10 :             *slot = xn;
    9219              :           }
    9220              :       }
    9221        81733 : }
    9222              : 
    9223              : /* Generate an error for any duplicate field names in FIELDLIST.  Munge
    9224              :    the list such that this does not present a problem later.  */
    9225              : 
    9226              : static void
    9227      1193529 : detect_field_duplicates (tree fieldlist)
    9228              : {
    9229      1193529 :   tree x, y;
    9230      1193529 :   int timeout = 10;
    9231              : 
    9232              :   /* If the struct is the list of instance variables of an Objective-C
    9233              :      class, then we need to check all the instance variables of
    9234              :      superclasses when checking for duplicates (since you can't have
    9235              :      an instance variable in a subclass with the same name as an
    9236              :      instance variable in a superclass).  We pass on this job to the
    9237              :      Objective-C compiler.  objc_detect_field_duplicates() will return
    9238              :      false if we are not checking the list of instance variables and
    9239              :      the C frontend should proceed with the standard field duplicate
    9240              :      checks.  If we are checking the list of instance variables, the
    9241              :      ObjC frontend will do the check, emit the errors if needed, and
    9242              :      then return true.  */
    9243      1193529 :   if (c_dialect_objc ())
    9244            0 :     if (objc_detect_field_duplicates (false))
    9245              :       return;
    9246              : 
    9247              :   /* First, see if there are more than "a few" fields.
    9248              :      This is trivially true if there are zero or one fields.  */
    9249      1193529 :   if (!fieldlist || !DECL_CHAIN (fieldlist))
    9250              :     return;
    9251              :   x = fieldlist;
    9252      3519803 :   do {
    9253      3519803 :     timeout--;
    9254      3519803 :     if (DECL_NAME (x) == NULL_TREE
    9255      3519803 :         && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9256              :       timeout = 0;
    9257      3519803 :     x = DECL_CHAIN (x);
    9258      3519803 :   } while (timeout > 0 && x);
    9259              : 
    9260              :   /* If there were "few" fields and no anonymous structures or unions,
    9261              :      avoid the overhead of allocating a hash table.  Instead just do
    9262              :      the nested traversal thing.  */
    9263       985541 :   if (timeout > 0)
    9264              :     {
    9265      2853062 :       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
    9266              :         /* When using -fplan9-extensions, we can have duplicates
    9267              :            between typedef names and fields.  */
    9268      1937629 :         if (DECL_NAME (x)
    9269      1937629 :             || (flag_plan9_extensions
    9270            0 :                 && DECL_NAME (x) == NULL_TREE
    9271            0 :                 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9272            0 :                 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9273            0 :                 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
    9274              :           {
    9275      6287755 :             for (y = fieldlist; y != x; y = TREE_CHAIN (y))
    9276      4352203 :               if (is_duplicate_field (y, x))
    9277              :                 {
    9278            1 :                   error ("duplicate member %q+D", x);
    9279            1 :                   DECL_NAME (x) = NULL_TREE;
    9280              :                 }
    9281              :           }
    9282              :     }
    9283              :   else
    9284              :     {
    9285        70108 :       hash_table<nofree_ptr_hash <tree_node> > htab (37);
    9286        70108 :       detect_field_duplicates_hash (fieldlist, &htab);
    9287        70108 :     }
    9288              : }
    9289              : 
    9290              : /* Finish up struct info used by -Wc++-compat.  */
    9291              : 
    9292              : static void
    9293          578 : warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code,
    9294              :                                location_t record_loc)
    9295              : {
    9296          578 :   unsigned int ix;
    9297          578 :   tree x;
    9298          578 :   struct c_binding *b;
    9299              : 
    9300          578 :   if (fieldlist == NULL_TREE)
    9301              :     {
    9302            9 :       if (code == RECORD_TYPE)
    9303            6 :         warning_at (record_loc, OPT_Wc___compat,
    9304              :                     "empty struct has size 0 in C, size 1 in C++");
    9305              :       else
    9306            3 :         warning_at (record_loc, OPT_Wc___compat,
    9307              :                     "empty union has size 0 in C, size 1 in C++");
    9308              :     }
    9309              : 
    9310              :   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
    9311              :      the current struct.  We do this now at the end of the struct
    9312              :      because the flag is used to issue visibility warnings, and we
    9313              :      only want to issue those warnings if the type is referenced
    9314              :      outside of the struct declaration.  */
    9315          626 :   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
    9316           48 :     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
    9317              : 
    9318              :   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
    9319              :      typedefs used when declaring fields in this struct.  If the name
    9320              :      of any of the fields is also a typedef name then the struct would
    9321              :      not parse in C++, because the C++ lookup rules say that the
    9322              :      typedef name would be looked up in the context of the struct, and
    9323              :      would thus be the field rather than the typedef.  */
    9324          578 :   if (!struct_parse_info->typedefs_seen.is_empty ()
    9325           67 :       && fieldlist != NULL_TREE)
    9326              :     {
    9327              :       /* Use a hash_set<tree> using the name of the typedef.  We can use
    9328              :          a hash_set<tree> because identifiers are interned.  */
    9329           67 :       hash_set<tree> tset;
    9330              : 
    9331          254 :       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
    9332          120 :         tset.add (DECL_NAME (x));
    9333              : 
    9334          387 :       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
    9335              :         {
    9336          320 :           if (DECL_NAME (x) != NULL_TREE
    9337          320 :               && tset.contains (DECL_NAME (x)))
    9338              :             {
    9339            2 :               warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
    9340              :                           "using %qD as both field and typedef name is "
    9341              :                           "invalid in C++", x);
    9342              :               /* FIXME: It would be nice to report the location where
    9343              :                  the typedef name is used.  */
    9344              :             }
    9345              :         }
    9346           67 :     }
    9347              : 
    9348              :   /* For each field which has a binding and which was not defined in
    9349              :      an enclosing struct, clear the in_struct field.  */
    9350          670 :   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
    9351           92 :     b->in_struct = 0;
    9352          578 : }
    9353              : 
    9354              : /* Function to help qsort sort FIELD_DECLs by name order.  */
    9355              : 
    9356              : static int
    9357     20290790 : field_decl_cmp (const void *x_p, const void *y_p)
    9358              : {
    9359     20290790 :   const tree *const x = (const tree *) x_p;
    9360     20290790 :   const tree *const y = (const tree *) y_p;
    9361              : 
    9362     20290790 :   if (DECL_NAME (*x) == DECL_NAME (*y))
    9363              :     /* A nontype is "greater" than a type.  */
    9364            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
    9365     20290790 :   if (DECL_NAME (*x) == NULL_TREE)
    9366              :     return -1;
    9367     20290790 :   if (DECL_NAME (*y) == NULL_TREE)
    9368              :     return 1;
    9369     20290790 :   if (DECL_NAME (*x) < DECL_NAME (*y))
    9370      9997257 :     return -1;
    9371              :   return 1;
    9372              : }
    9373              : 
    9374              : /* If this structure or union completes the type of any previous
    9375              :    variable declaration, lay it out and output its rtl.  */
    9376              : static void
    9377      1380020 : finish_incomplete_vars (tree incomplete_vars, bool toplevel)
    9378              : {
    9379      1380169 :   for (tree x = incomplete_vars; x; x = TREE_CHAIN (x))
    9380              :     {
    9381          149 :       tree decl = TREE_VALUE (x);
    9382          149 :       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
    9383            0 :         layout_array_type (TREE_TYPE (decl));
    9384          149 :       if (TREE_CODE (decl) != TYPE_DECL)
    9385              :         {
    9386          149 :           relayout_decl (decl);
    9387          149 :           if (c_dialect_objc ())
    9388            0 :             objc_check_decl (decl);
    9389          149 :           rest_of_decl_compilation (decl, toplevel, 0);
    9390              :         }
    9391              :     }
    9392      1380020 : }
    9393              : 
    9394              : /* Determine whether the FIELD_DECL X is a flexible array member according to
    9395              :    the following info:
    9396              :   A. whether the FIELD_DECL X is the last field of the DECL_CONTEXT;
    9397              :   B. whether the FIELD_DECL is an array that is declared as "[]", "[0]",
    9398              :      or "[1]";
    9399              :   C. flag_strict_flex_arrays;
    9400              :   D. the attribute strict_flex_array that is attached to the field
    9401              :      if presenting.
    9402              :   Return TRUE when it's a flexible array member, FALSE otherwise.  */
    9403              : 
    9404              : static bool
    9405      4361778 : is_flexible_array_member_p (bool is_last_field,
    9406              :                             tree x)
    9407              : {
    9408              :   /* If not the last field, return false.  */
    9409      4361778 :   if (!is_last_field)
    9410              :     return false;
    9411              : 
    9412              :   /* If not an array field, return false.  */
    9413      1673735 :   if (TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    9414              :     return false;
    9415              : 
    9416       540148 :   bool is_zero_length_array = zero_length_array_type_p (TREE_TYPE (x));
    9417       540148 :   bool is_one_element_array = one_element_array_type_p (TREE_TYPE (x));
    9418       540148 :   bool is_flexible_array = flexible_array_member_type_p (TREE_TYPE (x));
    9419              : 
    9420       540148 :   unsigned int strict_flex_array_level = c_strict_flex_array_level_of (x);
    9421              : 
    9422       540148 :   switch (strict_flex_array_level)
    9423              :     {
    9424              :       case 0:
    9425              :         /* Default, all trailing arrays are flexible array members.  */
    9426              :         return true;
    9427           77 :       case 1:
    9428              :         /* Level 1: all "[1]", "[0]", and "[]" are flexible array members.  */
    9429           77 :         if (is_one_element_array)
    9430              :           return true;
    9431              :         /* FALLTHROUGH.  */
    9432          141 :       case 2:
    9433              :         /* Level 2: all "[0]", and "[]" are flexible array members.  */
    9434          141 :         if (is_zero_length_array)
    9435              :           return true;
    9436              :         /* FALLTHROUGH.  */
    9437          201 :       case 3:
    9438              :         /* Level 3: Only "[]" are flexible array members.  */
    9439          201 :         if (is_flexible_array)
    9440              :           return true;
    9441              :         break;
    9442            0 :       default:
    9443            0 :         gcc_unreachable ();
    9444              :     }
    9445              :   return false;
    9446              : }
    9447              : 
    9448              : /* Recompute TYPE_CANONICAL for variants of the type including qualified
    9449              :    versions of the type and related pointer types after an aggregate type
    9450              :    has been finalized.
    9451              :    Will not update array types, pointers to array types, function
    9452              :    types and other derived types created while the type was still
    9453              :    incomplete, those will remain TYPE_STRUCTURAL_EQUALITY_P.  */
    9454              : 
    9455              : static void
    9456      1216792 : c_update_type_canonical (tree t)
    9457              : {
    9458      1216792 :   gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t && !TYPE_QUALS (t));
    9459      2460683 :   for (tree x = t, l = NULL_TREE; x; l = x, x = TYPE_NEXT_VARIANT (x))
    9460              :     {
    9461      1243891 :       if (x != t && TYPE_STRUCTURAL_EQUALITY_P (x))
    9462              :         {
    9463        27099 :           if (!TYPE_QUALS (x))
    9464        26464 :             TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
    9465              :           else
    9466              :             {
    9467          635 :               tree
    9468          635 :                 c = c_build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
    9469          635 :               if (TYPE_STRUCTURAL_EQUALITY_P (c))
    9470              :                 {
    9471          206 :                   gcc_checking_assert (TYPE_CANONICAL (t) == t);
    9472          206 :                   if (c == x)
    9473          206 :                     TYPE_CANONICAL (x) = x;
    9474              :                   else
    9475              :                     {
    9476              :                       /* build_qualified_type for this function unhelpfully
    9477              :                          moved c from some later spot in TYPE_MAIN_VARIANT (t)
    9478              :                          chain to right after t (or created it there).  Move
    9479              :                          it right before x and process c and then x.  */
    9480            0 :                       gcc_checking_assert (TYPE_NEXT_VARIANT (t) == c);
    9481            0 :                       if (l != t)
    9482              :                         {
    9483            0 :                           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (c);
    9484            0 :                           TYPE_NEXT_VARIANT (l) = c;
    9485            0 :                           TYPE_NEXT_VARIANT (c) = x;
    9486              :                         }
    9487            0 :                       TYPE_CANONICAL (c) = c;
    9488            0 :                       x = c;
    9489              :                     }
    9490              :                 }
    9491              :               else
    9492          429 :                 TYPE_CANONICAL (x) = TYPE_CANONICAL (c);
    9493              :             }
    9494              :         }
    9495      1216792 :       else if (x != t)
    9496            0 :         continue;
    9497      1313576 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9498              :         {
    9499        69685 :           if (!TYPE_STRUCTURAL_EQUALITY_P (p))
    9500            0 :             continue;
    9501        69685 :           if (TYPE_CANONICAL (x) != x || TYPE_REF_CAN_ALIAS_ALL (p))
    9502        67555 :             TYPE_CANONICAL (p)
    9503       135110 :               = c_build_pointer_type_for_mode (TYPE_CANONICAL (x), TYPE_MODE (p),
    9504              :                                                false);
    9505              :           else
    9506         2130 :             TYPE_CANONICAL (p) = p;
    9507        69685 :           c_update_type_canonical (p);
    9508              :         }
    9509              :     }
    9510      1216792 : }
    9511              : 
    9512              : 
    9513              : /* We set C_TYPE_VARIABLY_MODIFIED for derived types.  We will not update
    9514              :    array types, pointers to array types, function types and other derived
    9515              :    types created while the type was still incomplete.  We need to update
    9516              :    at least all types for which TYPE_CANONICAL will bet set, because for
    9517              :    those we later assume (in c_variably_modified_p) that the bit is
    9518              :    up-to-date.  */
    9519              : 
    9520              : static void
    9521          735 : c_update_variably_modified (tree t)
    9522              : {
    9523         1479 :   for (tree x = t; x; x = TYPE_NEXT_VARIANT (x))
    9524              :     {
    9525          744 :       C_TYPE_VARIABLY_MODIFIED (x) = 1;
    9526          762 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9527           18 :         c_update_variably_modified (p);
    9528              :     }
    9529          735 : }
    9530              : 
    9531              : 
    9532              : /* Verify the argument of the counted_by attribute of each field of
    9533              :    the containing structure, OUTMOST_STRUCT_TYPE, including its inner
    9534              :    anonymous struct/union, Report error and remove the corresponding
    9535              :    attribute when it's not.  */
    9536              : 
    9537              : static void
    9538          532 : verify_counted_by_attribute (tree outmost_struct_type,
    9539              :                              tree cur_struct_type)
    9540              : {
    9541         1712 :   for (tree field = TYPE_FIELDS (cur_struct_type); field;
    9542         1180 :        field = TREE_CHAIN (field))
    9543              :     {
    9544         1180 :       if (flexible_array_member_type_p (TREE_TYPE (field))
    9545         1180 :            || TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
    9546              :         {
    9547          402 :           tree attr_counted_by = lookup_attribute ("counted_by",
    9548          402 :                                                    DECL_ATTRIBUTES (field));
    9549              : 
    9550          402 :           if (!attr_counted_by)
    9551            1 :             continue;
    9552              : 
    9553              :           /* If there is an counted_by attribute attached to the field,
    9554              :              verify it.  */
    9555              : 
    9556          401 :           tree fieldname = TREE_VALUE (TREE_VALUE (attr_counted_by));
    9557              : 
    9558              :           /* Verify the argument of the attribute is a valid field of the
    9559              :              containing structure.  */
    9560              : 
    9561          401 :           tree counted_by_field = lookup_field (outmost_struct_type,
    9562              :                                                 fieldname);
    9563              : 
    9564              :           /* Error when the field is not found in the containing structure
    9565              :              and remove the corresponding counted_by attribute from the
    9566              :              field_decl.  */
    9567          401 :           if (!counted_by_field)
    9568              :             {
    9569           24 :               error_at (DECL_SOURCE_LOCATION (field),
    9570              :                     "argument %qE to the %<counted_by%> attribute"
    9571              :                     " is not a field declaration in the same structure"
    9572              :                     " as %qD", fieldname, field);
    9573           24 :               DECL_ATTRIBUTES (field)
    9574           48 :                 = remove_attribute ("counted_by", DECL_ATTRIBUTES (field));
    9575              :             }
    9576              :           else
    9577              :           /* Error when the field is not with an integer type.  */
    9578              :             {
    9579          578 :               while (TREE_CHAIN (counted_by_field))
    9580          201 :                 counted_by_field = TREE_CHAIN (counted_by_field);
    9581          377 :               tree real_field = TREE_VALUE (counted_by_field);
    9582              : 
    9583          377 :               if (!INTEGRAL_TYPE_P (TREE_TYPE (real_field)))
    9584              :                 {
    9585            6 :                   error_at (DECL_SOURCE_LOCATION (field),
    9586              :                         "argument %qE to the %<counted_by%> attribute"
    9587              :                         " is not a field declaration with an integer type",
    9588              :                         fieldname);
    9589            6 :                   DECL_ATTRIBUTES (field)
    9590           12 :                     = remove_attribute ("counted_by",
    9591            6 :                                     DECL_ATTRIBUTES (field));
    9592              :                 }
    9593              :             }
    9594              :         }
    9595         1459 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    9596          869 :                && (DECL_NAME (field) == NULL_TREE))
    9597          188 :         verify_counted_by_attribute (outmost_struct_type, TREE_TYPE (field));
    9598              :     }
    9599          532 : }
    9600              : 
    9601              : /* Caller should make sure the TYPE is a top-level type (i.e. not being
    9602              :    nested in other structure/uniona). For such type, verify its counted_by
    9603              :    if it is an anonymous structure/union.  */
    9604              : 
    9605              : void
    9606      1369095 : verify_counted_by_for_top_anonymous_type (tree type)
    9607              : {
    9608      1369095 :   if (!RECORD_OR_UNION_TYPE_P (type))
    9609              :     return;
    9610              : 
    9611      1182611 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (type)
    9612      1182611 :       && c_type_tag (type) == NULL_TREE)
    9613           48 :     verify_counted_by_attribute (type, type);
    9614              : }
    9615              : 
    9616              : /* TYPE is a struct or union that we're applying may_alias to after the body is
    9617              :    parsed.  Fixup any POINTER_TO types.  */
    9618              : 
    9619              : static void
    9620          363 : c_fixup_may_alias (tree type)
    9621              : {
    9622          428 :   for (tree t = TYPE_POINTER_TO (type); t; t = TYPE_NEXT_PTR_TO (t))
    9623          190 :     for (tree v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    9624          125 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    9625          363 : }
    9626              : 
    9627              : /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
    9628              :    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
    9629              :    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
    9630              :    ATTRIBUTES are attributes to be applied to the structure.
    9631              : 
    9632              :    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
    9633              :    the struct was started.  */
    9634              : 
    9635              : tree
    9636      1193529 : finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
    9637              :                class c_struct_parse_info *enclosing_struct_parse_info,
    9638              :                tree *expr)
    9639              : {
    9640      1193529 :   tree x;
    9641      1193529 :   bool toplevel = file_scope == current_scope;
    9642              : 
    9643              :   /* If this type was previously laid out as a forward reference,
    9644              :      make sure we lay it out again.  */
    9645              : 
    9646      1193529 :   TYPE_SIZE (t) = NULL_TREE;
    9647              : 
    9648      1193529 :   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    9649              : 
    9650      1193529 :   if (pedantic)
    9651              :     {
    9652         6903 :       for (x = fieldlist; x; x = DECL_CHAIN (x))
    9653              :         {
    9654         6884 :           if (DECL_NAME (x) != NULL_TREE)
    9655              :             break;
    9656           25 :           if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9657              :             break;
    9658              :         }
    9659              : 
    9660         6885 :       if (x == NULL_TREE)
    9661              :         {
    9662           19 :           if (TREE_CODE (t) == UNION_TYPE)
    9663              :             {
    9664            5 :               if (fieldlist)
    9665            2 :                 pedwarn (loc, OPT_Wpedantic, "union has no named members");
    9666              :               else
    9667            3 :                 pedwarn (loc, OPT_Wpedantic, "union has no members");
    9668              :             }
    9669              :           else
    9670              :             {
    9671           14 :               if (fieldlist)
    9672            3 :                 pedwarn (loc, OPT_Wpedantic, "struct has no named members");
    9673              :               else
    9674           11 :                 pedwarn (loc, OPT_Wpedantic, "struct has no members");
    9675              :             }
    9676              :         }
    9677              :     }
    9678              : 
    9679              :   /* Install struct as DECL_CONTEXT of each field decl.
    9680              :      Also process specified field sizes, found in the DECL_INITIAL,
    9681              :      storing 0 there after the type has been changed to precision equal
    9682              :      to its width, rather than the precision of the specified standard
    9683              :      type.  (Correct layout requires the original type to have been preserved
    9684              :      until now.)  */
    9685              : 
    9686      1193529 :   bool saw_named_field = false;
    9687      5555347 :   for (x = fieldlist; x; x = DECL_CHAIN (x))
    9688              :     {
    9689              :       /* Whether this field is the last field of the structure or union.
    9690              :          for UNION, any field is the last field of it.  */
    9691      4361818 :       bool is_last_field = (DECL_CHAIN (x) == NULL_TREE)
    9692      4361818 :                             || (TREE_CODE (t) == UNION_TYPE);
    9693              : 
    9694      4361818 :       if (TREE_TYPE (x) == error_mark_node)
    9695           40 :         continue;
    9696              : 
    9697      4361778 :       DECL_CONTEXT (x) = t;
    9698              : 
    9699      4361778 :       tree t1 = strip_array_types (TREE_TYPE (x));
    9700              :       /* If any field is const, the structure type is pseudo-const.  */
    9701      4361778 :       if (TREE_READONLY (x))
    9702        64248 :         C_TYPE_FIELDS_READONLY (t) = 1;
    9703              :       else
    9704              :         {
    9705              :           /* A field that is pseudo-const makes the structure likewise.  */
    9706      4297530 :           if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1))
    9707          641 :             C_TYPE_FIELDS_READONLY (t) = 1;
    9708              :         }
    9709              : 
    9710              :       /* Any field that is volatile means variables of this type must be
    9711              :          treated in some ways as volatile.  */
    9712      4361778 :       if (TREE_THIS_VOLATILE (x))
    9713              :         {
    9714          659 :           C_TYPE_FIELDS_VOLATILE (t) = 1;
    9715          659 :           C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9716              :         }
    9717              : 
    9718              :       /* Any field that is volatile, restrict-qualified or atomic
    9719              :          means the type cannot be used for a constexpr object.  */
    9720      4361778 :       if (TYPE_QUALS (t1)
    9721      4361778 :           .has (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    9722         1652 :         C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9723      4360126 :       else if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_NON_CONSTEXPR (t1))
    9724          179 :             C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9725              : 
    9726              :       /* Any field of nominal variable size implies structure is too.  */
    9727      4361778 :       if (C_DECL_VARIABLE_SIZE (x))
    9728          698 :         C_TYPE_VARIABLE_SIZE (t) = 1;
    9729              : 
    9730              :       /* If any field is variably modified, record this fact. */
    9731      4361778 :       if (c_type_variably_modified_p (TREE_TYPE (x)))
    9732          778 :         C_TYPE_VARIABLY_MODIFIED (t) = 1;
    9733              : 
    9734      4361778 :       if (DECL_C_BIT_FIELD (x))
    9735              :         {
    9736        55133 :           unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
    9737        55133 :           DECL_SIZE (x) = bitsize_int (width);
    9738        55133 :           DECL_BIT_FIELD (x) = 1;
    9739              :         }
    9740              : 
    9741      4361778 :       if (TYPE_PACKED (t)
    9742      4367390 :           && (DECL_BIT_FIELD (x)
    9743         3236 :               || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
    9744         4501 :         DECL_PACKED (x) = 1;
    9745              : 
    9746              :       /* Detect flexible array member in an invalid context.  */
    9747      4361778 :       if (flexible_array_member_type_p (TREE_TYPE (x)))
    9748              :         {
    9749        86060 :           if (TREE_CODE (t) == UNION_TYPE)
    9750           31 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9751              :                      "flexible array member in union is a GCC extension");
    9752        86029 :           else if (!is_last_field)
    9753              :             {
    9754            3 :               error_at (DECL_SOURCE_LOCATION (x),
    9755              :                         "flexible array member not at end of struct");
    9756            3 :               TREE_TYPE (x) = error_mark_node;
    9757              :             }
    9758        86026 :           else if (!saw_named_field)
    9759           39 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9760              :                      "flexible array member in a struct with no named "
    9761              :                      "members is a GCC extension");
    9762        86060 :           if (lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9763          134 :             C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9764              :         }
    9765              : 
    9766      4361778 :       if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE
    9767      4361778 :           && lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9768          267 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9769              : 
    9770              :       /* If the field is an anonymous structure that includes a field
    9771              :          with counted_by attribute, this structure should also be marked
    9772              :          too.  */
    9773      8342297 :       if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9774       473176 :           && C_TYPE_FIELDS_HAS_COUNTED_BY (TREE_TYPE (x))
    9775           18 :           && DECL_NAME (x) == NULL_TREE
    9776      4361791 :           && c_type_tag (TREE_TYPE (x)) == NULL_TREE)
    9777           12 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9778              : 
    9779        23159 :       if (pedantic && TREE_CODE (t) == RECORD_TYPE
    9780      4380960 :           && flexible_array_type_p (TREE_TYPE (x)))
    9781           18 :         pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9782              :                  "invalid use of structure with flexible array member");
    9783              : 
    9784              :       /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x.  */
    9785      4361778 :       DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x);
    9786              : 
    9787              :       /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t.
    9788              :          when x is an array and is the last field.
    9789              :          There is only one last_field for a structure type, but there might
    9790              :          be multiple last_fields for a union type, therefore we should ORed
    9791              :          the result for multiple last_fields.  */
    9792      4361778 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    9793       698802 :         TYPE_INCLUDES_FLEXARRAY (t)
    9794      1397604 :           |= is_last_field && flexible_array_member_type_p (TREE_TYPE (x));
    9795              :       /* Recursively set TYPE_INCLUDES_FLEXARRAY for the context of x, t
    9796              :          when x is an union or record and is the last field.  */
    9797      3662976 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9798       473176 :         TYPE_INCLUDES_FLEXARRAY (t)
    9799       946352 :           |= is_last_field && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x));
    9800              : 
    9801      4361778 :       if (warn_flex_array_member_not_at_end
    9802           56 :           && !is_last_field
    9803           22 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9804      4361790 :           && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x)))
    9805            5 :         warning_at (DECL_SOURCE_LOCATION (x),
    9806            5 :                     OPT_Wflex_array_member_not_at_end,
    9807              :                     "structure containing a flexible array member"
    9808              :                     " is not at the end of another structure");
    9809              : 
    9810      4361778 :       if (DECL_NAME (x)
    9811      4361778 :           || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9812              :         saw_named_field = true;
    9813              : 
    9814      8024754 :       if (AGGREGATE_TYPE_P (TREE_TYPE (x))
    9815      4834954 :           && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
    9816       422625 :         TYPE_TYPELESS_STORAGE (t) = true;
    9817              :     }
    9818              : 
    9819      1193529 :   detect_field_duplicates (fieldlist);
    9820              : 
    9821              :   /* Now we have the nearly final fieldlist.  Record it,
    9822              :      then lay out the structure or union (including the fields).  */
    9823              : 
    9824      1193529 :   TYPE_FIELDS (t) = fieldlist;
    9825              : 
    9826      1193529 :   maybe_apply_pragma_scalar_storage_order (t);
    9827              : 
    9828      1193529 :   layout_type (t);
    9829              : 
    9830      1193529 :   if (TYPE_SIZE_UNIT (t)
    9831      1193529 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    9832      1192886 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    9833      2386415 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    9834            1 :     error ("type %qT is too large", t);
    9835              : 
    9836              :   /* Give bit-fields their proper types and rewrite the type of array fields
    9837              :      with scalar component if the enclosing type has reverse storage order.  */
    9838      5555347 :   for (tree field = fieldlist; field; field = DECL_CHAIN (field))
    9839              :     {
    9840      4361818 :       if (TREE_CODE (field) == FIELD_DECL
    9841      4361818 :           && DECL_INITIAL (field)
    9842      4416961 :           && TREE_TYPE (field) != error_mark_node)
    9843              :         {
    9844        55133 :           unsigned HOST_WIDE_INT width
    9845        55133 :             = tree_to_uhwi (DECL_INITIAL (field));
    9846        55133 :           tree type = TREE_TYPE (field);
    9847        55133 :           if (VECTOR_TYPE_P (type))
    9848              :             {
    9849            2 :               error_at (DECL_SOURCE_LOCATION (field),
    9850              :                         "bit-field %qD has invalid type", field);
    9851            2 :               type = TREE_TYPE (type);
    9852            2 :               TREE_TYPE (field) = type;
    9853              :             }
    9854        55133 :           if (width != TYPE_PRECISION (type))
    9855              :             {
    9856        38384 :               if (BITINT_TYPE_P (type)
    9857        38692 :                   && width >= ((TYPE_UNSIGNED (type) || flag_isoc2y) ? 1 : 2))
    9858          186 :                 TREE_TYPE (field)
    9859          372 :                   = build_bitint_type (width, TYPE_UNSIGNED (type));
    9860              :               else
    9861        38374 :                 TREE_TYPE (field)
    9862        38374 :                   = c_build_bitfield_integer_type (width,
    9863        38374 :                                                    TYPE_UNSIGNED (type));
    9864        38560 :               if (tree attr = c_hardbool_type_attr (type))
    9865          281 :                 decl_attributes (&TREE_TYPE (field),
    9866              :                                  copy_list (attr),
    9867              :                                  0, NULL_TREE);
    9868        38560 :               SET_DECL_MODE (field, TYPE_MODE (TREE_TYPE (field)));
    9869              :             }
    9870        55133 :           DECL_INITIAL (field) = NULL_TREE;
    9871              :         }
    9872      4306685 :       else if (TYPE_REVERSE_STORAGE_ORDER (t)
    9873          735 :                && TREE_CODE (field) == FIELD_DECL
    9874      4307420 :                && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
    9875              :         {
    9876          113 :           tree ftype = TREE_TYPE (field);
    9877          113 :           tree ctype = strip_array_types (ftype);
    9878          113 :           if (!RECORD_OR_UNION_TYPE_P (ctype) && TYPE_MODE (ctype) != QImode)
    9879              :             {
    9880          100 :               tree fmain_type = TYPE_MAIN_VARIANT (ftype);
    9881          100 :               tree *typep = &fmain_type;
    9882          102 :               do {
    9883          102 :                 *typep = build_distinct_type_copy (*typep);
    9884          102 :                 TYPE_REVERSE_STORAGE_ORDER (*typep) = 1;
    9885          102 :                 typep = &TREE_TYPE (*typep);
    9886          102 :               } while (TREE_CODE (*typep) == ARRAY_TYPE);
    9887          100 :               TREE_TYPE (field)
    9888          200 :                 = c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
    9889              :             }
    9890              :         }
    9891              : 
    9892              :       /* Warn on problematic type punning for storage order purposes.  */
    9893      4361818 :       if (TREE_CODE (t) == UNION_TYPE
    9894       864739 :           && TREE_CODE (field) == FIELD_DECL
    9895      5226557 :           && AGGREGATE_TYPE_P (TREE_TYPE (field)))
    9896              :         {
    9897       430434 :           tree ftype = TREE_TYPE (field);
    9898       430434 :           if (TREE_CODE (ftype) == ARRAY_TYPE)
    9899       316298 :             ftype = strip_array_types (ftype);
    9900       430434 :           if (RECORD_OR_UNION_TYPE_P (ftype)
    9901       430434 :               && TYPE_REVERSE_STORAGE_ORDER (ftype)
    9902       114638 :                  != TYPE_REVERSE_STORAGE_ORDER (t))
    9903            1 :             warning_at (DECL_SOURCE_LOCATION (field),
    9904            1 :                         OPT_Wscalar_storage_order,
    9905              :                         "type punning toggles scalar storage order");
    9906              :         }
    9907              :     }
    9908              : 
    9909              :   /* Now we have the truly final field list.
    9910              :      Store it in this type and in the variants.  */
    9911              : 
    9912      1193529 :   TYPE_FIELDS (t) = fieldlist;
    9913              : 
    9914              :   /* If there are lots of fields, sort so we can look through them fast.
    9915              :      We arbitrarily consider 16 or more elts to be "a lot".  */
    9916              : 
    9917      1193529 :   {
    9918      1193529 :     int len = 0;
    9919              : 
    9920      5105774 :     for (x = fieldlist; x; x = DECL_CHAIN (x))
    9921              :       {
    9922      3941567 :         if (len > 15 || DECL_NAME (x) == NULL)
    9923              :           break;
    9924      3912245 :         len += 1;
    9925              :       }
    9926              : 
    9927      1193529 :     if (len > 15)
    9928              :       {
    9929        22687 :         tree *field_array;
    9930        22687 :         struct lang_type *space;
    9931        22687 :         struct sorted_fields_type *space2;
    9932              : 
    9933        22687 :         len += list_length (x);
    9934              : 
    9935              :         /* Use the same allocation policy here that make_node uses, to
    9936              :            ensure that this lives as long as the rest of the struct decl.
    9937              :            All decls in an inline function need to be saved.  */
    9938              : 
    9939        22687 :         space = ((struct lang_type *)
    9940        22687 :                  ggc_internal_cleared_alloc (c_dialect_objc ()
    9941              :                                              ? sizeof (struct lang_type)
    9942              :                                              : offsetof (struct lang_type,
    9943              :                                                          info)));
    9944        22687 :         space2 = ((sorted_fields_type *)
    9945        45374 :                   ggc_internal_alloc (sizeof (struct sorted_fields_type)
    9946        22687 :                                       + len * sizeof (tree)));
    9947              : 
    9948        22687 :         len = 0;
    9949        22687 :         space->s = space2;
    9950        22687 :         field_array = &space2->elts[0];
    9951       797666 :         for (x = fieldlist; x; x = DECL_CHAIN (x))
    9952              :           {
    9953       778369 :             field_array[len++] = x;
    9954              : 
    9955              :             /* If there is anonymous struct or union, break out of the loop.  */
    9956       778369 :             if (DECL_NAME (x) == NULL)
    9957              :               break;
    9958              :           }
    9959              :         /* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
    9960        22687 :         if (x == NULL)
    9961              :           {
    9962        19297 :             TYPE_LANG_SPECIFIC (t) = space;
    9963        19297 :             TYPE_LANG_SPECIFIC (t)->s->len = len;
    9964        19297 :             field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
    9965        19297 :             qsort (field_array, len, sizeof (tree), field_decl_cmp);
    9966              :           }
    9967              :       }
    9968              :   }
    9969              : 
    9970              :   /* If this was supposed to be a transparent union, but we can't
    9971              :      make it one, warn and turn off the flag.  */
    9972      1193529 :   if (TREE_CODE (t) == UNION_TYPE
    9973       382277 :       && TYPE_TRANSPARENT_AGGR (t)
    9974      1193574 :       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
    9975              :     {
    9976           13 :       TYPE_TRANSPARENT_AGGR (t) = 0;
    9977           13 :       warning_at (loc, 0, "union cannot be made transparent");
    9978              :     }
    9979              : 
    9980      1193529 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
    9981      2418117 :   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
    9982              :     {
    9983      1224588 :       TYPE_FIELDS (x) = TYPE_FIELDS (t);
    9984      1224588 :       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
    9985      1224588 :       TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
    9986      1224588 :       TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
    9987      1224588 :       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
    9988      1224588 :       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
    9989      1224588 :       C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);
    9990      1224588 :       C_TYPE_FIELDS_HAS_COUNTED_BY (x) = C_TYPE_FIELDS_HAS_COUNTED_BY (t);
    9991      1224588 :       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
    9992      1224588 :       C_TYPE_VARIABLY_MODIFIED (x) = C_TYPE_VARIABLY_MODIFIED (t);
    9993      1224588 :       C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
    9994      1224588 :       TYPE_INCLUDES_FLEXARRAY (x) = TYPE_INCLUDES_FLEXARRAY (t);
    9995              :     }
    9996              : 
    9997              :   /* Check for consistency with previous definition.  */
    9998      1193529 :   if (flag_isoc23 && NULL != enclosing_struct_parse_info)
    9999              :     {
   10000       924668 :       tree vistype = previous_tag (t);
   10001       924668 :       if (vistype
   10002          128 :           && TREE_CODE (vistype) == TREE_CODE (t)
   10003       924796 :           && !C_TYPE_BEING_DEFINED (vistype))
   10004              :         {
   10005          108 :           TYPE_STUB_DECL (t) = TYPE_STUB_DECL (vistype);
   10006          108 :           if (c_type_variably_modified_p (t))
   10007              :             {
   10008            7 :               error ("redefinition of struct or union %qT with variably "
   10009              :                      "modified type", t);
   10010            7 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10011            7 :                 inform (struct_parse_info->refloc, "originally defined here");
   10012              :             }
   10013          101 :           else if (!comptypes_same_p (t, vistype))
   10014              :             {
   10015           38 :               error ("redefinition of struct or union %qT", t);
   10016           38 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10017           38 :                 inform (struct_parse_info->refloc, "originally defined here");
   10018              :             }
   10019              :         }
   10020              :     }
   10021              : 
   10022      1193529 :   C_TYPE_BEING_DEFINED (t) = 0;
   10023              : 
   10024      1193529 :   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
   10025          694 :     for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
   10026          363 :       c_fixup_may_alias (x);
   10027              : 
   10028              :   /* Set type canonical based on equivalence class.  */
   10029      1193529 :   if (flag_isoc23 && !C_TYPE_VARIABLE_SIZE (t))
   10030              :     {
   10031       960748 :       if (c_struct_htab == NULL)
   10032        36314 :         c_struct_htab = hash_table<c_struct_hasher>::create_ggc (61);
   10033              : 
   10034       960748 :       hashval_t hash = c_struct_hasher::hash (t);
   10035              : 
   10036       960748 :       gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
   10037       960748 :       gcc_checking_assert (!TYPE_NAME (t)
   10038              :                            || TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE);
   10039              : 
   10040       960748 :       tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT);
   10041       960748 :       if (*e)
   10042        63578 :         TYPE_CANONICAL (t) = TYPE_CANONICAL (*e);
   10043              :       else
   10044              :         {
   10045       897170 :           TYPE_CANONICAL (t) = c_type_canonical (t);
   10046       897170 :           *e = t;
   10047              :         }
   10048       960748 :       c_update_type_canonical (t);
   10049              :     }
   10050              : 
   10051              :   /* Update type location to the one of the definition, instead of e.g.
   10052              :      a forward declaration.  */
   10053      1193529 :   if (TYPE_STUB_DECL (t))
   10054      1193529 :     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
   10055              : 
   10056              :   /* Finish debugging output for this type.  */
   10057      1193529 :   rest_of_type_compilation (t, toplevel);
   10058              : 
   10059      1193529 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10060              : 
   10061              : 
   10062      1193529 :   if (c_type_variably_modified_p (t))
   10063              :     {
   10064          717 :       c_update_variably_modified (t);
   10065              :       /* Make sure a DECL_EXPR is created for structs with VLA members.
   10066              :          Because we do not know the context, we always pass expr
   10067              :          to force creation of a BIND_EXPR which is required in some
   10068              :          contexts.  */
   10069          717 :       add_decl_expr (loc, t, expr, false);
   10070              :     }
   10071              : 
   10072      1193529 :   if (warn_cxx_compat)
   10073          578 :     warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
   10074              : 
   10075      1193529 :   if (NULL != enclosing_struct_parse_info)
   10076              :     {
   10077      1152204 :       delete struct_parse_info;
   10078              : 
   10079      1152204 :       struct_parse_info = enclosing_struct_parse_info;
   10080              : 
   10081              :       /* If this struct is defined inside a struct, add it to
   10082              :          struct_types.  */
   10083      1152204 :       if (warn_cxx_compat
   10084              :           && struct_parse_info != NULL
   10085          350 :           && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10086          345 :         struct_parse_info->struct_types.safe_push (t);
   10087              :      }
   10088              : 
   10089              :   /* Only when the enclosing struct/union type is not anonymous, do more
   10090              :      verification on the fields with counted_by attributes.  */
   10091      1193529 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (t) && c_type_tag (t) != NULL_TREE)
   10092          296 :     verify_counted_by_attribute (t, t);
   10093              : 
   10094      1193529 :   return t;
   10095              : }
   10096              : 
   10097              : static struct {
   10098              :   gt_pointer_operator new_value;
   10099              :   void *cookie;
   10100              : } resort_data;
   10101              : 
   10102              : /* This routine compares two fields like field_decl_cmp but using the
   10103              : pointer operator in resort_data.  */
   10104              : 
   10105              : static int
   10106         5410 : resort_field_decl_cmp (const void *x_p, const void *y_p)
   10107              : {
   10108         5410 :   const tree *const x = (const tree *) x_p;
   10109         5410 :   const tree *const y = (const tree *) y_p;
   10110              : 
   10111         5410 :   if (DECL_NAME (*x) == DECL_NAME (*y))
   10112              :     /* A nontype is "greater" than a type.  */
   10113            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
   10114         5410 :   if (DECL_NAME (*x) == NULL_TREE)
   10115              :     return -1;
   10116         5410 :   if (DECL_NAME (*y) == NULL_TREE)
   10117              :     return 1;
   10118         5410 :   {
   10119         5410 :     tree d1 = DECL_NAME (*x);
   10120         5410 :     tree d2 = DECL_NAME (*y);
   10121         5410 :     resort_data.new_value (&d1, &d1, resort_data.cookie);
   10122         5410 :     resort_data.new_value (&d2, &d2, resort_data.cookie);
   10123         5410 :     if (d1 < d2)
   10124         2732 :       return -1;
   10125              :   }
   10126         2678 :   return 1;
   10127              : }
   10128              : 
   10129              : /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
   10130              : 
   10131              : void
   10132            6 : resort_sorted_fields (void *obj,
   10133              :                       void * ARG_UNUSED (orig_obj),
   10134              :                       gt_pointer_operator new_value,
   10135              :                       void *cookie)
   10136              : {
   10137            6 :   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
   10138            6 :   resort_data.new_value = new_value;
   10139            6 :   resort_data.cookie = cookie;
   10140            6 :   qsort (&sf->elts[0], sf->len, sizeof (tree),
   10141              :          resort_field_decl_cmp);
   10142            6 : }
   10143              : 
   10144              : /* Lay out the type T, and its element type, and so on.  */
   10145              : 
   10146              : static void
   10147            0 : layout_array_type (tree t)
   10148              : {
   10149            0 :   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   10150            0 :     layout_array_type (TREE_TYPE (t));
   10151            0 :   layout_type (t);
   10152            0 : }
   10153              : 
   10154              : /* Begin compiling the definition of an enumeration type.
   10155              :    NAME is its name (or null if anonymous).
   10156              :    LOC is the enum's location.
   10157              :    FIXED_UNDERLYING_TYPE is the (C23) underlying type specified in the
   10158              :    definition.
   10159              :    Returns the type object, as yet incomplete.
   10160              :    Also records info about it so that build_enumerator
   10161              :    may be used to declare the individual values as they are read.  */
   10162              : 
   10163              : tree
   10164       186491 : start_enum (location_t loc, struct c_enum_contents *the_enum, tree name,
   10165              :             tree fixed_underlying_type, bool potential_nesting_p)
   10166              : {
   10167       186491 :   tree enumtype = NULL_TREE;
   10168       186491 :   location_t enumloc = UNKNOWN_LOCATION;
   10169              : 
   10170              :   /* If this is the real definition for a previous forward reference,
   10171              :      fill in the contents in the same object that used to be the
   10172              :      forward reference.  */
   10173              : 
   10174       186491 :   if (name != NULL_TREE)
   10175        75267 :     enumtype = lookup_tag (ENUMERAL_TYPE, name, true, &enumloc);
   10176              : 
   10177        75267 :   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   10178              :     {
   10179              :       /* If the type is currently being defined or if we have seen an
   10180              :          incomplete version which is now complete, this is a nested
   10181              :          redefinition.  The later happens if the redefinition occurs
   10182              :          inside the enum specifier itself.  */
   10183          205 :       if (C_TYPE_BEING_DEFINED (enumtype)
   10184          205 :           || (potential_nesting_p && TYPE_VALUES (enumtype) != NULL_TREE))
   10185            9 :         error_at (loc, "nested redefinition of %<enum %E%>", name);
   10186              : 
   10187              :       /* For C23 we allow redefinitions.  We set to zero and check for
   10188              :          consistency later.  */
   10189          393 :       if (flag_isoc23 && TYPE_VALUES (enumtype) != NULL_TREE)
   10190              :         enumtype = NULL_TREE;
   10191              :     }
   10192              : 
   10193       111401 :   if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   10194              :     {
   10195       186316 :       enumtype = make_node (ENUMERAL_TYPE);
   10196       186316 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10197       186316 :       SET_TYPE_STRUCTURAL_EQUALITY (enumtype);
   10198       186316 :       pushtag (loc, name, enumtype);
   10199       186316 :       if (fixed_underlying_type != NULL_TREE)
   10200              :         {
   10201              :           /* For an enum definition with a fixed underlying type, the
   10202              :              type is complete during the definition and the
   10203              :              enumeration constants have that type.  If there was a
   10204              :              tag, the type was completed in c_parser_enum_specifier.
   10205              :              If not, it must be completed here.  */
   10206           12 :           ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = true;
   10207           12 :           TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (fixed_underlying_type);
   10208           12 :           TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (fixed_underlying_type);
   10209           12 :           TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (fixed_underlying_type);
   10210           12 :           SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (fixed_underlying_type));
   10211           12 :           TYPE_SIZE (enumtype) = NULL_TREE;
   10212           12 :           TYPE_PRECISION (enumtype) = TYPE_PRECISION (fixed_underlying_type);
   10213           12 :           ENUM_UNDERLYING_TYPE (enumtype) = fixed_underlying_type;
   10214           12 :           TYPE_CANONICAL (enumtype) = TYPE_CANONICAL (fixed_underlying_type);
   10215           12 :           c_update_type_canonical (enumtype);
   10216           12 :           layout_type (enumtype);
   10217              :         }
   10218              :     }
   10219              :   /* Update type location to the one of the definition, instead of e.g.
   10220              :      a forward declaration.  */
   10221          175 :   else if (TYPE_STUB_DECL (enumtype))
   10222              :     {
   10223          175 :       enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
   10224          175 :       DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
   10225              :     }
   10226              : 
   10227       186491 :   C_TYPE_BEING_DEFINED (enumtype) = 1;
   10228              : 
   10229       186491 :   if (TYPE_VALUES (enumtype) != NULL_TREE)
   10230              :     {
   10231              :       /* This enum is a named one that has been declared already.  */
   10232            6 :       auto_diagnostic_group d;
   10233            6 :       error_at (loc, "redeclaration of %<enum %E%>", name);
   10234            6 :       if (enumloc != UNKNOWN_LOCATION)
   10235            6 :         inform (enumloc, "originally defined here");
   10236              : 
   10237              :       /* Completely replace its old definition.
   10238              :          The old enumerators remain defined, however.  */
   10239            6 :       TYPE_VALUES (enumtype) = NULL_TREE;
   10240            6 :     }
   10241              : 
   10242       186491 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype)
   10243       186491 :       && fixed_underlying_type == NULL_TREE)
   10244              :     {
   10245            3 :       error_at (loc, "%<enum%> declared with but defined without "
   10246              :                 "fixed underlying type");
   10247            3 :       ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false;
   10248              :     }
   10249              : 
   10250       186491 :   the_enum->enum_next_value = integer_zero_node;
   10251       186491 :   the_enum->enum_type = enumtype;
   10252       186491 :   the_enum->enum_overflow = 0;
   10253              : 
   10254       186491 :   if (flag_short_enums && !ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10255          106 :     for (tree v = TYPE_MAIN_VARIANT (enumtype); v; v = TYPE_NEXT_VARIANT (v))
   10256           53 :       TYPE_PACKED (v) = 1;
   10257              : 
   10258              :   /* FIXME: This will issue a warning for a use of a type defined
   10259              :      within sizeof in a statement expr.  This is not terribly serious
   10260              :      as C++ doesn't permit statement exprs within sizeof anyhow.  */
   10261       186491 :   if (warn_cxx_compat
   10262          138 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
   10263            0 :     warning_at (loc, OPT_Wc___compat,
   10264              :                 "defining type in %qs expression is invalid in C++",
   10265              :                 (in_sizeof ? "sizeof"
   10266            0 :                  : in_typeof ? "typeof"
   10267            0 :                  : in_alignof ? "alignof"
   10268              :                  : "_Countof"));
   10269              : 
   10270       186491 :   if (in_underspecified_init)
   10271            6 :     error_at (loc, "%qT defined in underspecified object initializer",
   10272              :               enumtype);
   10273              : 
   10274       186491 :   return enumtype;
   10275              : }
   10276              : 
   10277              : /* After processing and defining all the values of an enumeration type,
   10278              :    install their decls in the enumeration type and finish it off.
   10279              :    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
   10280              :    and ATTRIBUTES are the specified attributes.
   10281              :    Returns ENUMTYPE.  */
   10282              : 
   10283              : tree
   10284       186491 : finish_enum (tree enumtype, tree values, tree attributes)
   10285              : {
   10286       186491 :   tree pair, tem;
   10287       186491 :   tree minnode = NULL_TREE, maxnode = NULL_TREE;
   10288       186491 :   int precision;
   10289       186491 :   signop sign;
   10290       186491 :   bool toplevel = (file_scope == current_scope);
   10291       186491 :   struct lang_type *lt;
   10292              : 
   10293       186491 :   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
   10294              : 
   10295              :   /* Calculate the maximum value of any enumerator in this type.  */
   10296              : 
   10297       186491 :   if (values == error_mark_node)
   10298           26 :     minnode = maxnode = integer_zero_node;
   10299              :   else
   10300              :     {
   10301       186465 :       minnode = maxnode = TREE_VALUE (values);
   10302      5818366 :       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
   10303              :         {
   10304      5631901 :           tree value = TREE_VALUE (pair);
   10305      5631901 :           if (tree_int_cst_lt (maxnode, value))
   10306      5479468 :             maxnode = value;
   10307      5631901 :           if (tree_int_cst_lt (value, minnode))
   10308        66813 :             minnode = value;
   10309              :         }
   10310              :     }
   10311              : 
   10312              :   /* Construct the final type of this enumeration.  It is the same
   10313              :      as one of the integral types - the narrowest one that fits, except
   10314              :      that normally we only go as narrow as int - and signed iff any of
   10315              :      the values are negative.  */
   10316       186491 :   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
   10317       186491 :   precision = MAX (tree_int_cst_min_precision (minnode, sign),
   10318              :                    tree_int_cst_min_precision (maxnode, sign));
   10319              : 
   10320       186491 :   bool wider_than_int =
   10321       186491 :     (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
   10322       186491 :      || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode));
   10323              : 
   10324              : 
   10325       186491 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10326              :     {
   10327              :       /* If the precision of the type was specified with an attribute and it
   10328              :          was too small, give an error.  Otherwise, use it.  */
   10329       186347 :       if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes))
   10330              :         {
   10331           23 :           if (precision > TYPE_PRECISION (enumtype))
   10332              :             {
   10333            6 :               TYPE_PRECISION (enumtype) = 0;
   10334            6 :               error ("specified mode too small for enumerated values");
   10335              :             }
   10336              :           else
   10337           17 :             precision = TYPE_PRECISION (enumtype);
   10338              :         }
   10339              :       else
   10340       186324 :         TYPE_PRECISION (enumtype) = 0;
   10341              : 
   10342       186347 :       if (TYPE_PACKED (enumtype)
   10343       186268 :           || precision > TYPE_PRECISION (integer_type_node)
   10344       369297 :           || TYPE_PRECISION (enumtype))
   10345              :         {
   10346         3524 :           tem = c_common_type_for_size (precision, sign == UNSIGNED ? 1 : 0);
   10347         3409 :           if (tem == NULL)
   10348              :             {
   10349              :               /* This should only occur when both signed and unsigned
   10350              :                  values of maximum precision occur among the
   10351              :                  enumerators.  */
   10352            3 :               pedwarn (input_location, 0,
   10353              :                        "enumeration values exceed range of largest integer");
   10354            3 :               tem = widest_integer_literal_type_node;
   10355              :             }
   10356         3406 :           else if (precision > TYPE_PRECISION (intmax_type_node)
   10357            4 :                    && !tree_int_cst_lt (minnode,
   10358            4 :                                         TYPE_MIN_VALUE (intmax_type_node))
   10359         3409 :                    && !tree_int_cst_lt (TYPE_MAX_VALUE (uintmax_type_node),
   10360              :                                         maxnode))
   10361            2 :             pedwarn (input_location, OPT_Wpedantic,
   10362              :                      "enumeration values exceed range of %qs",
   10363              :                      sign == UNSIGNED ? "uintmax_t" : "intmax_t");
   10364              :         }
   10365              :       else
   10366       182938 :         tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
   10367              : 
   10368       186347 :       TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
   10369       186347 :       TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
   10370       186347 :       TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
   10371       186347 :       SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (tem));
   10372       186347 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10373       186347 :       TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
   10374       186347 :       ENUM_UNDERLYING_TYPE (enumtype) =
   10375       186347 :         c_common_type_for_size (TYPE_PRECISION (tem), TYPE_UNSIGNED (tem));
   10376              : 
   10377       559041 :       TYPE_CANONICAL (enumtype) =
   10378       186347 :         TYPE_CANONICAL (ENUM_UNDERLYING_TYPE (enumtype));
   10379       186347 :       c_update_type_canonical (enumtype);
   10380              : 
   10381       186347 :       layout_type (enumtype);
   10382              :     }
   10383              : 
   10384       186491 :   if (values != error_mark_node)
   10385              :     {
   10386              :       /* Change the type of the enumerators to be the enum type.  We
   10387              :          need to do this irrespective of the size of the enum, for
   10388              :          proper type checking.  Replace the DECL_INITIALs of the
   10389              :          enumerators, and the value slots of the list, with copies
   10390              :          that have the enum type; they cannot be modified in place
   10391              :          because they may be shared (e.g.  integer_zero_node) Finally,
   10392              :          change the purpose slots to point to the names of the decls.  */
   10393      6004831 :       for (pair = values; pair; pair = TREE_CHAIN (pair))
   10394              :         {
   10395      5818366 :           tree enu = TREE_PURPOSE (pair);
   10396      5818366 :           tree ini = DECL_INITIAL (enu);
   10397              : 
   10398      5818366 :           TREE_TYPE (enu) = enumtype;
   10399              : 
   10400              :           /* Before C23, the ISO C Standard mandates enumerators to
   10401              :              have type int, even though the underlying type of an enum
   10402              :              type is unspecified.  However, C23 allows enumerators of
   10403              :              any integer type, and if an enumeration has any
   10404              :              enumerators wider than int, all enumerators have the
   10405              :              enumerated type after it is parsed.  Any enumerators that
   10406              :              fit in int are given type int in build_enumerator (which
   10407              :              is the correct type while the enumeration is being
   10408              :              parsed), so no conversions are needed here if all
   10409              :              enumerators fit in int.  If the enum has a fixed
   10410              :              underlying type, the correct type was also given in
   10411              :              build_enumerator.  */
   10412      5818366 :           if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) && wider_than_int)
   10413        36937 :             ini = convert (enumtype, ini);
   10414              : 
   10415      5818366 :           DECL_INITIAL (enu) = ini;
   10416      5818366 :           TREE_PURPOSE (pair) = DECL_NAME (enu);
   10417              :           /* To match the C++ FE, store the CONST_DECL rather than just its
   10418              :              value.  */
   10419      5818366 :           TREE_VALUE (pair) = enu;
   10420              :         }
   10421              : 
   10422       186465 :       TYPE_VALUES (enumtype) = values;
   10423              :     }
   10424              : 
   10425              :   /* Record the min/max values so that we can warn about bit-field
   10426              :      enumerations that are too small for the values.  */
   10427       186491 :   lt = ((struct lang_type *)
   10428       186491 :         ggc_internal_cleared_alloc (c_dialect_objc ()
   10429              :                                     ? sizeof (struct lang_type)
   10430              :                                     : offsetof (struct lang_type, info)));
   10431       186491 :   lt->enum_min = minnode;
   10432       186491 :   lt->enum_max = maxnode;
   10433       186491 :   TYPE_LANG_SPECIFIC (enumtype) = lt;
   10434              : 
   10435              :   /* Fix up all variant types of this enum type.  */
   10436       186491 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (enumtype));
   10437       372992 :   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
   10438              :     {
   10439       186501 :       C_TYPE_INCOMPLETE_VARS (tem) = NULL_TREE;
   10440       186501 :       if (tem == enumtype)
   10441       186491 :         continue;
   10442           10 :       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
   10443           10 :       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
   10444           10 :       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
   10445           10 :       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
   10446           10 :       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
   10447           10 :       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
   10448           10 :       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
   10449           10 :       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
   10450           10 :       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
   10451           10 :       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
   10452           10 :       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
   10453           10 :       ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
   10454           10 :       TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
   10455              :     }
   10456              : 
   10457              :   /* Finish debugging output for this type.  */
   10458       186491 :   rest_of_type_compilation (enumtype, toplevel);
   10459              : 
   10460       186491 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10461              : 
   10462              :   /* If this enum is defined inside a struct, add it to
   10463              :      struct_types.  */
   10464       186491 :   if (warn_cxx_compat
   10465          138 :       && struct_parse_info != NULL
   10466           48 :       && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10467           48 :     struct_parse_info->struct_types.safe_push (enumtype);
   10468              : 
   10469              :   /* Check for consistency with previous definition */
   10470       186491 :   if (flag_isoc23)
   10471              :     {
   10472       148256 :       tree vistype = previous_tag (enumtype);
   10473       148256 :       if (vistype
   10474           35 :           && TREE_CODE (vistype) == TREE_CODE (enumtype)
   10475       148287 :           && !C_TYPE_BEING_DEFINED (vistype))
   10476              :         {
   10477           31 :           TYPE_STUB_DECL (enumtype) = TYPE_STUB_DECL (vistype);
   10478           31 :           if (!comptypes_same_p (enumtype, vistype))
   10479            3 :             error("conflicting redefinition of enum %qT", enumtype);
   10480              :         }
   10481              :     }
   10482              : 
   10483       186491 :   C_TYPE_BEING_DEFINED (enumtype) = 0;
   10484              : 
   10485       186491 :   return enumtype;
   10486              : }
   10487              : 
   10488              : /* Build and install a CONST_DECL for one value of the
   10489              :    current enumeration type (one that was begun with start_enum).
   10490              :    DECL_LOC is the location of the enumerator.
   10491              :    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
   10492              :    Return a tree-list containing the CONST_DECL and its value.
   10493              :    Assignment of sequential values by default is handled here.  */
   10494              : 
   10495              : tree
   10496      5818383 : build_enumerator (location_t decl_loc, location_t loc,
   10497              :                   struct c_enum_contents *the_enum, tree name, tree value)
   10498              : {
   10499      5818383 :   tree decl;
   10500      5818383 :   tree old_decl;
   10501              : 
   10502              :   /* Validate and default VALUE.  */
   10503              : 
   10504      5818383 :   if (value != NULL_TREE)
   10505              :     {
   10506              :       /* Don't issue more errors for error_mark_node (i.e. an
   10507              :          undeclared identifier) - just ignore the value expression.  */
   10508      3640112 :       if (value == error_mark_node)
   10509              :         value = NULL_TREE;
   10510      3639447 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
   10511              :         {
   10512            6 :           error_at (loc, "enumerator value for %qE is not an integer constant",
   10513              :                     name);
   10514            6 :           value = NULL_TREE;
   10515              :         }
   10516              :       else
   10517              :         {
   10518      3639441 :           if (TREE_CODE (value) != INTEGER_CST)
   10519              :             {
   10520           97 :               value = c_fully_fold (value, false, NULL);
   10521           97 :               if (TREE_CODE (value) == INTEGER_CST)
   10522           48 :                 pedwarn (loc, OPT_Wpedantic,
   10523              :                          "enumerator value for %qE is not an integer "
   10524              :                          "constant expression", name);
   10525              :             }
   10526      3639441 :           if (TREE_CODE (value) != INTEGER_CST)
   10527              :             {
   10528           49 :               error ("enumerator value for %qE is not an integer constant",
   10529              :                      name);
   10530           49 :               value = NULL_TREE;
   10531              :             }
   10532              :           else
   10533              :             {
   10534      3639392 :               value = default_conversion (value);
   10535      3639392 :               constant_expression_warning (value);
   10536              :             }
   10537              :         }
   10538              :     }
   10539              : 
   10540              :   /* Default based on previous value.  */
   10541              :   /* It should no longer be possible to have NON_LVALUE_EXPR
   10542              :      in the default.  */
   10543      3639447 :   if (value == NULL_TREE)
   10544              :     {
   10545      2178991 :       value = the_enum->enum_next_value;
   10546      2178991 :       if (the_enum->enum_overflow)
   10547            8 :         error_at (loc, "overflow in enumeration values");
   10548              :     }
   10549      5818383 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10550              :     {
   10551              :       /* Enumeration constants must fit in the fixed underlying type.  */
   10552          213 :       if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (the_enum->enum_type)))
   10553            4 :         error_at (loc,
   10554              :                   "enumerator value outside the range of underlying type");
   10555              :       /* Enumeration constants for an enum with fixed underlying type
   10556              :          have the enum type, both inside and outside the
   10557              :          definition.  */
   10558          213 :       value = convert (the_enum->enum_type, value);
   10559              :     }
   10560      5818170 :   else if (flag_isoc23
   10561      5400278 :            && (old_decl = lookup_name_in_scope (name, current_scope))
   10562           39 :            && old_decl != error_mark_node
   10563           39 :            && TREE_TYPE (old_decl)
   10564           39 :            && TREE_TYPE (TREE_TYPE (old_decl))
   10565      5818208 :            && TREE_CODE (old_decl) == CONST_DECL)
   10566              :     {
   10567              :       /* Enumeration constants in a redeclaration have the previous type.  */
   10568           38 :       tree previous_type = TREE_TYPE (DECL_INITIAL (old_decl));
   10569           38 :       if (!int_fits_type_p (value, previous_type))
   10570              :         {
   10571            2 :           error_at (loc, "value of redeclared enumerator outside the range "
   10572              :                          "of %qT", previous_type);
   10573            2 :           locate_old_decl (old_decl);
   10574              :         }
   10575           38 :       value = convert (previous_type, value);
   10576              :     }
   10577              :   else
   10578              :     {
   10579              :       /* Even though the underlying type of an enum is unspecified, the
   10580              :          type of enumeration constants is explicitly defined as int
   10581              :          (6.4.4.3/2 in the C99 Standard).  C23 allows any integer type, and
   10582              :          GCC allows such types for older standards as an extension.  */
   10583      5818132 :       bool warned_range = false;
   10584      5818132 :       if (!int_fits_type_p (value,
   10585      5818132 :                             (TYPE_UNSIGNED (TREE_TYPE (value))
   10586              :                              ? uintmax_type_node
   10587              :                              : intmax_type_node)))
   10588              :         /* GCC does not consider its types larger than intmax_t to be
   10589              :            extended integer types (although C23 would permit such types to
   10590              :            be considered extended integer types if all the features
   10591              :            required by <stdint.h> and <inttypes.h> macros, such as support
   10592              :            for integer constants and I/O, were present), so diagnose if
   10593              :            such a wider type is used.  (If the wider type arose from a
   10594              :            constant of such a type, that will also have been diagnosed,
   10595              :            but this is the only diagnostic in the case where it arises
   10596              :            from choosing a wider type automatically when adding 1
   10597              :            overflows.)  */
   10598           11 :         warned_range = pedwarn (loc, OPT_Wpedantic,
   10599              :                                 "enumerator value outside the range of %qs",
   10600           11 :                                 TYPE_UNSIGNED (TREE_TYPE (value))
   10601              :                                 ? "uintmax_t"
   10602              :                                 : "intmax_t");
   10603      5818132 :       if (!warned_range && !int_fits_type_p (value, integer_type_node))
   10604         5599 :         pedwarn_c11 (loc, OPT_Wpedantic,
   10605              :                      "ISO C restricts enumerator values to range of %<int%> "
   10606              :                      "before C23");
   10607              : 
   10608              :       /* The ISO C Standard mandates enumerators to have type int before
   10609              :          C23, even though the underlying type of an enum type is
   10610              :          unspecified.  C23 allows enumerators of any integer type.  During
   10611              :          the parsing of the enumeration, C23 specifies that constants
   10612              :          representable in int have type int, constants not representable
   10613              :          in int have the type of the given expression if any, and
   10614              :          constants not representable in int and derived by adding 1 to the
   10615              :          previous constant have the type of that constant unless the
   10616              :          addition would overflow or wraparound, in which case a wider type
   10617              :          of the same signedness is chosen automatically; after the
   10618              :          enumeration is parsed, all the constants have the type of the
   10619              :          enumeration if any do not fit in int.  */
   10620      5818132 :       if (int_fits_type_p (value, integer_type_node))
   10621      5812529 :         value = convert (integer_type_node, value);
   10622              :     }
   10623              : 
   10624              :   /* Set basis for default for next value.  */
   10625      5818383 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10626              :     {
   10627          213 :       tree underlying_type = ENUM_UNDERLYING_TYPE (the_enum->enum_type);
   10628          213 :       if (TREE_CODE (underlying_type) == BOOLEAN_TYPE)
   10629              :         /* A value of 2 following a value of 1 overflows bool, but we
   10630              :            cannot carry out addition directly on bool without
   10631              :            promotion, and converting the result of arithmetic in a
   10632              :            wider type back to bool would not produce the right result
   10633              :            for this overflow check.  */
   10634           61 :         the_enum->enum_next_value = invert_truthvalue_loc (loc, value);
   10635              :       else
   10636          152 :         the_enum->enum_next_value
   10637          152 :           = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10638              :                              PLUS_EXPR, convert (underlying_type, value),
   10639              :                              convert (underlying_type, integer_one_node),
   10640              :                              false);
   10641              :     }
   10642              :   else
   10643              :     {
   10644      5818170 :       tree tmp = value;
   10645              : 
   10646              :       /* In a redeclaration the type can already be the enumeral type.  */
   10647      5818170 :       if (TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
   10648           14 :         tmp = convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (tmp)), tmp);
   10649              : 
   10650      5818170 :       the_enum->enum_next_value
   10651      5818170 :         = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10652              :                            PLUS_EXPR, tmp, integer_one_node, false);
   10653              :     }
   10654      5818383 :   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
   10655      5818383 :   if (the_enum->enum_overflow
   10656      5818383 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10657              :     {
   10658              :       /* Choose a wider type with the same signedness if
   10659              :          available.  */
   10660         4786 :       int prec = TYPE_PRECISION (TREE_TYPE (value)) + 1;
   10661         4786 :       bool unsignedp = TYPE_UNSIGNED (TREE_TYPE (value));
   10662         4786 :       tree new_type = (unsignedp
   10663         4786 :                        ? long_unsigned_type_node
   10664              :                        : long_integer_type_node);
   10665         4786 :       if (prec > TYPE_PRECISION (new_type))
   10666         3787 :         new_type = (unsignedp
   10667         3787 :                     ? long_long_unsigned_type_node
   10668              :                     : long_long_integer_type_node);
   10669         4786 :       if (prec > TYPE_PRECISION (new_type))
   10670         3201 :         new_type = (unsignedp
   10671         3201 :                     ? widest_unsigned_literal_type_node
   10672              :                     : widest_integer_literal_type_node);
   10673         4786 :       if (prec <= TYPE_PRECISION (new_type))
   10674              :         {
   10675         4781 :           the_enum->enum_overflow = false;
   10676         4781 :           the_enum->enum_next_value
   10677         4781 :             = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10678              :                                PLUS_EXPR, convert (new_type, value),
   10679              :                                integer_one_node, false);
   10680         4781 :           gcc_assert (!tree_int_cst_lt (the_enum->enum_next_value, value));
   10681              :         }
   10682              :     }
   10683              : 
   10684              :   /* Now create a declaration for the enum value name.  */
   10685              : 
   10686      5818383 :   decl = build_decl (decl_loc, CONST_DECL, name, TREE_TYPE (value));
   10687      5818383 :   DECL_INITIAL (decl) = value;
   10688      5818383 :   DECL_CONTEXT (decl) = the_enum->enum_type;
   10689      5818383 :   pushdecl (decl);
   10690              : 
   10691      5818383 :   return tree_cons (decl, value, NULL_TREE);
   10692              : }
   10693              : 
   10694              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   10695              : 
   10696              : tree
   10697            0 : c_simulate_enum_decl (location_t loc, const char *name,
   10698              :                       vec<string_int_pair> *values_ptr)
   10699              : {
   10700            0 :   location_t saved_loc = input_location;
   10701            0 :   input_location = loc;
   10702              : 
   10703            0 :   struct c_enum_contents the_enum;
   10704            0 :   tree enumtype = start_enum (loc, &the_enum, get_identifier (name),
   10705              :                               NULL_TREE, false);
   10706              : 
   10707            0 :   tree value_chain = NULL_TREE;
   10708            0 :   string_int_pair *value;
   10709            0 :   vec<string_int_pair> values = *values_ptr;
   10710            0 :   unsigned int i;
   10711            0 :   FOR_EACH_VEC_ELT (values, i, value)
   10712              :     {
   10713            0 :       tree decl = build_enumerator (loc, loc, &the_enum,
   10714              :                                     get_identifier (value->first),
   10715              :                                     build_int_cst (integer_type_node,
   10716            0 :                                                    value->second));
   10717            0 :       TREE_CHAIN (decl) = value_chain;
   10718            0 :       value_chain = decl;
   10719              :     }
   10720              : 
   10721            0 :   finish_enum (enumtype, nreverse (value_chain), NULL_TREE);
   10722              : 
   10723            0 :   input_location = saved_loc;
   10724            0 :   return enumtype;
   10725              : }
   10726              : 
   10727              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   10728              : 
   10729              : tree
   10730            0 : c_simulate_record_decl (location_t loc, const char *name,
   10731              :                         array_slice<const tree> fields)
   10732              : {
   10733            0 :   location_t saved_loc = input_location;
   10734            0 :   input_location = loc;
   10735              : 
   10736            0 :   class c_struct_parse_info *struct_info;
   10737            0 :   tree ident = get_identifier (name);
   10738            0 :   tree type = start_struct (loc, RECORD_TYPE, ident, &struct_info);
   10739              : 
   10740            0 :   for (unsigned int i = 0; i < fields.size (); ++i)
   10741              :     {
   10742            0 :       DECL_FIELD_CONTEXT (fields[i]) = type;
   10743            0 :       if (i > 0)
   10744            0 :         DECL_CHAIN (fields[i - 1]) = fields[i];
   10745              :     }
   10746              : 
   10747            0 :   finish_struct (loc, type, fields[0], NULL_TREE, struct_info);
   10748              : 
   10749            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   10750            0 :   set_underlying_type (decl);
   10751            0 :   lang_hooks.decls.pushdecl (decl);
   10752              : 
   10753            0 :   input_location = saved_loc;
   10754            0 :   return type;
   10755              : }
   10756              : 
   10757              : /* Create the FUNCTION_DECL for a function definition.
   10758              :    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
   10759              :    the declaration; they describe the function's name and the type it returns,
   10760              :    but twisted together in a fashion that parallels the syntax of C.
   10761              : 
   10762              :    This function creates a binding context for the function body
   10763              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   10764              : 
   10765              :    Returns true on success.  If the DECLARATOR is not suitable for a function
   10766              :    (it defines a datum instead), we return false to report a parse error.  */
   10767              : 
   10768              : bool
   10769     37669311 : start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   10770              :                 tree attributes)
   10771              : {
   10772     37669311 :   tree decl1, old_decl;
   10773     37669311 :   tree restype, resdecl;
   10774     37669311 :   location_t loc;
   10775     37669311 :   location_t result_loc;
   10776     37669311 :   tree expr = NULL;
   10777              : 
   10778     37669311 :   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   10779     37669311 :   current_function_returns_null = 0;
   10780     37669311 :   current_function_returns_abnormally = 0;
   10781     37669311 :   warn_about_return_type = 0;
   10782     37669311 :   c_switch_stack = NULL;
   10783              : 
   10784              :   /* Indicate no valid break/continue context.  */
   10785     37669311 :   in_statement = 0;
   10786              : 
   10787     37669311 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
   10788              :                           &attributes, &expr, NULL, DEPRECATED_NORMAL);
   10789     37669311 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   10790              : 
   10791              :   /* If the declarator is not suitable for a function definition,
   10792              :      cause a syntax error.  */
   10793     37669311 :   if (decl1 == NULL_TREE
   10794     37669282 :       || TREE_CODE (decl1) != FUNCTION_DECL)
   10795              :     return false;
   10796              : 
   10797              :   /* Nested functions may have variably modified (return) type.
   10798              :      Make sure the size expression is evaluated at this point.  */
   10799     37669275 :   if (expr && !current_scope->parm_flag)
   10800           11 :     add_stmt (fold_convert (void_type_node, expr));
   10801              : 
   10802     37669275 :   loc = DECL_SOURCE_LOCATION (decl1);
   10803              : 
   10804              :   /* A nested function is not global.  */
   10805     37669275 :   if (current_function_decl != NULL_TREE)
   10806         1618 :     TREE_PUBLIC (decl1) = 0;
   10807              : 
   10808     37669275 :   c_decl_attributes (&decl1, attributes, 0);
   10809              : 
   10810     37669275 :   if (DECL_DECLARED_INLINE_P (decl1)
   10811     36964243 :       && DECL_UNINLINABLE (decl1)
   10812     37669286 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
   10813              :     {
   10814            3 :       auto_urlify_attributes sentinel;
   10815            3 :       warning_at (loc, OPT_Wattributes,
   10816              :                   "inline function %qD given attribute %qs",
   10817              :                   decl1, "noinline");
   10818            3 :     }
   10819              : 
   10820              :   /* Handle gnu_inline attribute.  */
   10821     37669275 :   if (declspecs->inline_p
   10822     36964246 :       && !flag_gnu89_inline
   10823     36921567 :       && TREE_CODE (decl1) == FUNCTION_DECL
   10824     74590842 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
   10825       163634 :           || current_function_decl))
   10826              :     {
   10827     36758005 :       if (declspecs->storage_class != csc_static)
   10828     36757999 :         DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
   10829              :     }
   10830              : 
   10831     37669275 :   announce_function (decl1);
   10832              : 
   10833     37669275 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
   10834              :     {
   10835            1 :       error_at (loc, "return type is an incomplete type");
   10836              :       /* Make it return void instead.  */
   10837            1 :       TREE_TYPE (decl1)
   10838            2 :         = c_build_function_type (void_type_node,
   10839            1 :                                  TYPE_ARG_TYPES (TREE_TYPE (decl1)),
   10840            1 :                                  TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl1)));
   10841              :     }
   10842              : 
   10843     37669275 :   if (warn_about_return_type)
   10844         1404 :     permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int
   10845            0 :                    : (warn_return_type > 0 ? OPT_Wreturn_type
   10846              :                       : OPT_Wimplicit_int),
   10847              :                    "return type defaults to %<int%>");
   10848              : 
   10849              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   10850              :      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
   10851     37669275 :   DECL_INITIAL (decl1) = error_mark_node;
   10852              : 
   10853              :   /* If this definition isn't a prototype and we had a prototype declaration
   10854              :      before, copy the arg type info from that prototype.  */
   10855     37669275 :   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
   10856     37669275 :   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
   10857     37437939 :     old_decl = NULL_TREE;
   10858              : 
   10859     37669275 :   current_function_prototype_locus = UNKNOWN_LOCATION;
   10860     37669275 :   current_function_prototype_built_in = false;
   10861     37669275 :   current_function_prototype_arg_types = NULL_TREE;
   10862     37669275 :   tree newtype = TREE_TYPE (decl1);
   10863     37669275 :   tree oldtype = old_decl ? TREE_TYPE (old_decl) : newtype;
   10864     37669275 :   if (!prototype_p (newtype))
   10865              :     {
   10866        13265 :       tree oldrt = TREE_TYPE (oldtype);
   10867        13265 :       tree newrt = TREE_TYPE (newtype);
   10868        13265 :       if (old_decl != NULL_TREE
   10869          317 :           && TREE_CODE (oldtype) == FUNCTION_TYPE
   10870          317 :           && comptypes (oldrt, newrt)
   10871        13563 :           && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype))
   10872              :         {
   10873          297 :           if (stdarg_p (oldtype))
   10874              :             {
   10875            1 :               auto_diagnostic_group d;
   10876            1 :               warning_at (loc, 0, "%q+D defined as variadic function "
   10877              :                           "without prototype", decl1);
   10878            1 :               locate_old_decl (old_decl);
   10879            1 :             }
   10880          297 :           TREE_TYPE (decl1) = composite_type (oldtype, newtype);
   10881          297 :           current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
   10882          297 :           current_function_prototype_built_in
   10883          297 :             = C_DECL_BUILTIN_PROTOTYPE (old_decl);
   10884          297 :           current_function_prototype_arg_types
   10885          297 :             = TYPE_ARG_TYPES (newtype);
   10886              :         }
   10887        13265 :       if (TREE_PUBLIC (decl1))
   10888              :         {
   10889              :           /* If there is an external prototype declaration of this
   10890              :              function, record its location but do not copy information
   10891              :              to this decl.  This may be an invisible declaration
   10892              :              (built-in or in a scope which has finished) or simply
   10893              :              have more refined argument types than any declaration
   10894              :              found above.  */
   10895        12850 :           struct c_binding *b;
   10896        13126 :           for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
   10897          713 :             if (B_IN_SCOPE (b, external_scope))
   10898              :               break;
   10899        12850 :           if (b)
   10900              :             {
   10901          437 :               tree ext_decl, ext_type;
   10902          437 :               ext_decl = b->decl;
   10903          437 :               ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
   10904          437 :               if (TREE_CODE (ext_type) == FUNCTION_TYPE
   10905          874 :                   && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
   10906          437 :                                 TREE_TYPE (ext_type)))
   10907              :                 {
   10908          417 :                   current_function_prototype_locus
   10909          417 :                     = DECL_SOURCE_LOCATION (ext_decl);
   10910          417 :                   current_function_prototype_built_in
   10911          417 :                     = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
   10912          417 :                   current_function_prototype_arg_types
   10913          417 :                     = TYPE_ARG_TYPES (ext_type);
   10914              :                 }
   10915              :             }
   10916              :         }
   10917              :     }
   10918              : 
   10919              :   /* Optionally warn about C23 compatibility.  */
   10920     37669275 :   if (warn_deprecated_non_prototype
   10921           34 :       && old_decl != NULL_TREE
   10922            5 :       && TREE_CODE (oldtype) == FUNCTION_TYPE
   10923            5 :       && !TYPE_ARG_TYPES (oldtype)
   10924            5 :       && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype)
   10925     37669280 :       && (TYPE_ARG_TYPES (newtype)
   10926            3 :           && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != void_type_node))
   10927              :     {
   10928            3 :       bool warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
   10929              :                                 "ISO C23 does not allow defining"
   10930              :                                 " parameters for function %qE declared"
   10931              :                                 " without parameters",
   10932              :                                 decl1);
   10933            3 :       if (warned)
   10934            3 :         inform (DECL_SOURCE_LOCATION (old_decl), "declared here");
   10935              :     }
   10936              : 
   10937              :   /* Optionally warn of old-fashioned def with no previous prototype.  */
   10938     37669275 :   if (warn_strict_prototypes
   10939       107960 :       && old_decl != error_mark_node
   10940       107960 :       && !prototype_p (TREE_TYPE (decl1))
   10941     37669276 :       && C_DECL_ISNT_PROTOTYPE (old_decl))
   10942            1 :     warning_at (loc, OPT_Wstrict_prototypes,
   10943              :                 "function declaration isn%'t a prototype");
   10944              :   /* Optionally warn of any global def with no previous prototype.  */
   10945     37669274 :   else if (warn_missing_prototypes
   10946       107661 :            && old_decl != error_mark_node
   10947       107661 :            && TREE_PUBLIC (decl1)
   10948        74130 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10949        74093 :            && C_DECL_ISNT_PROTOTYPE (old_decl)
   10950     37669915 :            && !DECL_DECLARED_INLINE_P (decl1))
   10951            4 :     warning_at (loc, OPT_Wmissing_prototypes,
   10952              :                 "no previous prototype for %qD", decl1);
   10953              :   /* Optionally warn of any def with no previous prototype
   10954              :      if the function has already been used.  */
   10955     37669270 :   else if (warn_missing_prototypes
   10956       107657 :            && old_decl != NULL_TREE
   10957        74467 :            && old_decl != error_mark_node
   10958        74467 :            && TREE_USED (old_decl)
   10959     37676394 :            && !prototype_p (TREE_TYPE (old_decl)))
   10960            0 :     warning_at (loc, OPT_Wmissing_prototypes,
   10961              :                 "%qD was used with no prototype before its definition", decl1);
   10962              :   /* Optionally warn of any global def with no previous declaration.  */
   10963     37669270 :   else if (warn_missing_declarations
   10964            4 :            && TREE_PUBLIC (decl1)
   10965            3 :            && old_decl == NULL_TREE
   10966            3 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10967     37669273 :            && !DECL_DECLARED_INLINE_P (decl1))
   10968            2 :     warning_at (loc, OPT_Wmissing_declarations,
   10969              :                 "no previous declaration for %qD",
   10970              :                 decl1);
   10971              :   /* Optionally warn of any def with no previous declaration
   10972              :      if the function has already been used.  */
   10973     37669268 :   else if (warn_missing_declarations
   10974            2 :            && old_decl != NULL_TREE
   10975            0 :            && old_decl != error_mark_node
   10976            0 :            && TREE_USED (old_decl)
   10977     37669268 :            && C_DECL_IMPLICIT (old_decl))
   10978            0 :     warning_at (loc, OPT_Wmissing_declarations,
   10979              :                 "%qD was used with no declaration before its definition", decl1);
   10980              : 
   10981              :   /* This function exists in static storage.
   10982              :      (This does not mean `static' in the C sense!)  */
   10983     37669275 :   TREE_STATIC (decl1) = 1;
   10984              : 
   10985              :   /* This is the earliest point at which we might know the assembler
   10986              :      name of the function.  Thus, if it's set before this, die horribly.  */
   10987     37669275 :   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
   10988              : 
   10989              :   /* If #pragma weak was used, mark the decl weak now.  */
   10990     37669275 :   if (current_scope == file_scope)
   10991     37667657 :     maybe_apply_pragma_weak (decl1);
   10992              : 
   10993              :   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
   10994     37669275 :   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
   10995              :     {
   10996         3352 :       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
   10997         3352 :           != integer_type_node)
   10998            5 :         pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
   10999         3347 :       else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
   11000            1 :         pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
   11001              :                  decl1);
   11002              : 
   11003         3352 :       check_main_parameter_types (decl1);
   11004              : 
   11005         3352 :       if (!TREE_PUBLIC (decl1))
   11006            0 :         pedwarn (loc, OPT_Wmain,
   11007              :                  "%qD is normally a non-static function", decl1);
   11008              :     }
   11009              : 
   11010     37669275 :   tree parms = current_function_arg_info->parms;
   11011     37669275 :   if (old_decl)
   11012              :     {
   11013       231336 :       location_t origloc = DECL_SOURCE_LOCATION (old_decl);
   11014       231336 :       warn_parms_array_mismatch (origloc, old_decl, parms);
   11015              :     }
   11016              : 
   11017              :   /* To enable versions to be created across TU's we mark and mangle all
   11018              :      non-default versioned functions.  */
   11019     37669275 :   if (TREE_CODE (decl1) == FUNCTION_DECL
   11020              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
   11021              :       && get_target_version (decl1).is_valid ())
   11022              :     {
   11023              :       maybe_mark_function_versioned (decl1);
   11024              :       if (current_scope != file_scope)
   11025              :         error ("versioned definitions are only allowed at file scope");
   11026              :     }
   11027              : 
   11028              :   /* Record the decl so that the function name is defined.
   11029              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   11030              :      use the old decl.  */
   11031              : 
   11032     37669275 :   current_function_decl = pushdecl (decl1);
   11033              : 
   11034     37669275 :   if (tree access = build_attr_access_from_parms (parms, false))
   11035        58350 :     decl_attributes (&current_function_decl, access, ATTR_FLAG_INTERNAL,
   11036              :                      old_decl);
   11037              : 
   11038     37669275 :   push_scope ();
   11039     37669275 :   declare_parm_level ();
   11040              : 
   11041              :   /* Set the result decl source location to the location of the typespec.  */
   11042      4268373 :   result_loc = (declspecs->locations[cdw_typespec] == UNKNOWN_LOCATION
   11043     37669275 :                 ? loc : declspecs->locations[cdw_typespec]);
   11044     37669275 :   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11045     37669275 :   resdecl = build_decl (result_loc, RESULT_DECL, NULL_TREE, restype);
   11046     37669275 :   DECL_ARTIFICIAL (resdecl) = 1;
   11047     37669275 :   DECL_IGNORED_P (resdecl) = 1;
   11048     37669275 :   DECL_RESULT (current_function_decl) = resdecl;
   11049              : 
   11050     37669275 :   start_fname_decls ();
   11051              : 
   11052     37669275 :   return true;
   11053              : }
   11054              : 
   11055              : /* Subroutine of store_parm_decls which handles new-style function
   11056              :    definitions (prototype format). The parms already have decls, so we
   11057              :    need only record them as in effect and complain if any redundant
   11058              :    old-style parm decls were written.  */
   11059              : static void
   11060     37656023 : store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
   11061              : {
   11062     37656023 :   tree decl;
   11063     37656023 :   c_arg_tag *tag;
   11064     37656023 :   unsigned ix;
   11065              : 
   11066     37656023 :   if (current_scope->bindings)
   11067              :     {
   11068            8 :       error_at (DECL_SOURCE_LOCATION (fndecl),
   11069              :                 "old-style parameter declarations in prototyped "
   11070              :                 "function definition");
   11071              : 
   11072              :       /* Get rid of the old-style declarations.  */
   11073            8 :       pop_scope ();
   11074            8 :       push_scope ();
   11075              :     }
   11076              :   /* Don't issue this warning for nested functions, and don't issue this
   11077              :      warning if we got here because ARG_INFO_TYPES was error_mark_node
   11078              :      (this happens when a function definition has just an ellipsis in
   11079              :      its parameter list).  */
   11080     37656015 :   else if (!in_system_header_at (input_location)
   11081       656523 :            && !current_function_scope
   11082       655053 :            && arg_info->types != error_mark_node
   11083     38311068 :            && !arg_info->c23_empty_parens)
   11084       600802 :     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
   11085              :                 "traditional C rejects ISO C style function definitions");
   11086              : 
   11087              :   /* Now make all the parameter declarations visible in the function body.
   11088              :      We can bypass most of the grunt work of pushdecl.  */
   11089    140833507 :   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
   11090              :     {
   11091    103177484 :       DECL_CONTEXT (decl) = current_function_decl;
   11092    103177484 :       if (DECL_NAME (decl))
   11093              :         {
   11094    103175929 :           bind (DECL_NAME (decl), decl, current_scope,
   11095              :                 /*invisible=*/false, /*nested=*/false,
   11096              :                 UNKNOWN_LOCATION);
   11097    103175929 :           if (!TREE_USED (decl))
   11098    103158448 :             warn_if_shadowing (decl);
   11099              :         }
   11100              :       else
   11101         1555 :         pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_name,
   11102              :                      "ISO C does not support omitting parameter names in "
   11103              :                      "function definitions before C23");
   11104              :     }
   11105              : 
   11106              :   /* Record the parameter list in the function declaration.  */
   11107     37656023 :   DECL_ARGUMENTS (fndecl) = arg_info->parms;
   11108              : 
   11109              :   /* Now make all the ancillary declarations visible, likewise.  */
   11110     37656084 :   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
   11111              :     {
   11112           61 :       DECL_CONTEXT (decl) = current_function_decl;
   11113           61 :       if (DECL_NAME (decl))
   11114            0 :         bind (DECL_NAME (decl), decl, current_scope,
   11115              :               /*invisible=*/false,
   11116            0 :               /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
   11117              :               UNKNOWN_LOCATION);
   11118              :     }
   11119              : 
   11120              :   /* And all the tag declarations.  */
   11121     37656140 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
   11122           61 :     if (tag->id)
   11123           28 :       bind (tag->id, tag->type, current_scope,
   11124              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
   11125     37656023 : }
   11126              : 
   11127              : /* Subroutine of store_parm_decls which handles old-style function
   11128              :    definitions (separate parameter list and declarations).  */
   11129              : 
   11130              : static void
   11131        13252 : store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
   11132              : {
   11133        13252 :   struct c_binding *b;
   11134        13252 :   tree parm, decl, last;
   11135        13252 :   tree parmids = arg_info->parms;
   11136        13252 :   hash_set<tree> seen_args;
   11137              : 
   11138        13252 :   if (!in_system_header_at (input_location))
   11139              :     {
   11140        13159 :       if (flag_isoc23)
   11141         1348 :         pedwarn (DECL_SOURCE_LOCATION (fndecl),
   11142         1348 :                  OPT_Wold_style_definition, "old-style function definition");
   11143              :       else
   11144        11811 :         warning_at (DECL_SOURCE_LOCATION (fndecl),
   11145        11811 :                     OPT_Wold_style_definition,
   11146              :                     "old-style function definition");
   11147              :     }
   11148              : 
   11149        13252 :   if (current_scope->had_vla_unspec)
   11150            1 :     error ("%<[*]%> not allowed in other than function prototype scope");
   11151              : 
   11152              :   /* Match each formal parameter name with its declaration.  Save each
   11153              :      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
   11154        47526 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11155              :     {
   11156        34274 :       if (TREE_VALUE (parm) == NULL_TREE)
   11157              :         {
   11158            0 :           error_at (DECL_SOURCE_LOCATION (fndecl),
   11159              :                     "parameter name missing from parameter list");
   11160            0 :           TREE_PURPOSE (parm) = NULL_TREE;
   11161            0 :           continue;
   11162              :         }
   11163              : 
   11164        34274 :       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
   11165        34274 :       if (b && B_IN_CURRENT_SCOPE (b))
   11166              :         {
   11167        22654 :           decl = b->decl;
   11168              :           /* Skip erroneous parameters.  */
   11169        22654 :           if (decl == error_mark_node)
   11170            2 :             continue;
   11171              :           /* If we got something other than a PARM_DECL it is an error.  */
   11172        22652 :           if (TREE_CODE (decl) != PARM_DECL)
   11173              :             {
   11174            7 :               error_at (DECL_SOURCE_LOCATION (decl),
   11175              :                         "%qD declared as a non-parameter", decl);
   11176            7 :               continue;
   11177              :             }
   11178              :           /* If the declaration is already marked, we have a duplicate
   11179              :              name.  Complain and ignore the duplicate.  */
   11180        22645 :           else if (seen_args.contains (decl))
   11181              :             {
   11182            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11183              :                         "multiple parameters named %qD", decl);
   11184            0 :               TREE_PURPOSE (parm) = NULL_TREE;
   11185            0 :               continue;
   11186              :             }
   11187              :           /* If the declaration says "void", complain and turn it into
   11188              :              an int.  */
   11189        22645 :           else if (VOID_TYPE_P (TREE_TYPE (decl)))
   11190              :             {
   11191            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11192              :                         "parameter %qD declared with void type", decl);
   11193            0 :               TREE_TYPE (decl) = integer_type_node;
   11194            0 :               DECL_ARG_TYPE (decl) = integer_type_node;
   11195            0 :               layout_decl (decl, 0);
   11196              :             }
   11197        22645 :           warn_if_shadowing (decl);
   11198              :         }
   11199              :       /* If no declaration found, default to int.  */
   11200              :       else
   11201              :         {
   11202              :           /* FIXME diagnostics: This should be the location of the argument,
   11203              :              not the FNDECL.  E.g., for an old-style declaration
   11204              : 
   11205              :                int f10(v) { blah; }
   11206              : 
   11207              :              We should use the location of the V, not the F10.
   11208              :              Unfortunately, the V is an IDENTIFIER_NODE which has no
   11209              :              location.  In the future we need locations for c_arg_info
   11210              :              entries.
   11211              : 
   11212              :              See gcc.dg/Wshadow-3.c for an example of this problem. */
   11213        11620 :           decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
   11214        11620 :                              PARM_DECL, TREE_VALUE (parm), integer_type_node);
   11215        11620 :           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
   11216        11620 :           pushdecl (decl);
   11217        11620 :           warn_if_shadowing (decl);
   11218              : 
   11219        11620 :           if (flag_isoc99)
   11220          118 :             permerror_opt (DECL_SOURCE_LOCATION (decl),
   11221          118 :                            OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
   11222              :                            decl);
   11223              :           else
   11224        11502 :             warning_at (DECL_SOURCE_LOCATION (decl),
   11225        11502 :                         OPT_Wmissing_parameter_type,
   11226              :                         "type of %qD defaults to %<int%>", decl);
   11227              :         }
   11228              : 
   11229        34265 :       TREE_PURPOSE (parm) = decl;
   11230        34265 :       seen_args.add (decl);
   11231              :     }
   11232              : 
   11233              :   /* Now examine the parms chain for incomplete declarations
   11234              :      and declarations with no corresponding names.  */
   11235              : 
   11236        47605 :   for (b = current_scope->bindings; b; b = b->prev)
   11237              :     {
   11238        34353 :       parm = b->decl;
   11239        34353 :       if (TREE_CODE (parm) != PARM_DECL)
   11240           79 :         continue;
   11241              : 
   11242        34274 :       if (TREE_TYPE (parm) != error_mark_node
   11243        34274 :           && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
   11244              :         {
   11245            0 :           error_at (DECL_SOURCE_LOCATION (parm),
   11246              :                     "parameter %qD has incomplete type", parm);
   11247            0 :           TREE_TYPE (parm) = error_mark_node;
   11248              :         }
   11249              : 
   11250        34274 :       if (!seen_args.contains (parm))
   11251              :         {
   11252            9 :           error_at (DECL_SOURCE_LOCATION (parm),
   11253              :                     "declaration for parameter %qD but no such parameter",
   11254              :                     parm);
   11255              : 
   11256              :           /* Pretend the parameter was not missing.
   11257              :              This gets us to a standard state and minimizes
   11258              :              further error messages.  */
   11259            9 :           parmids = chainon (parmids, tree_cons (parm, 0, 0));
   11260              :         }
   11261              :     }
   11262              : 
   11263              :   /* Chain the declarations together in the order of the list of
   11264              :      names.  Store that chain in the function decl, replacing the
   11265              :      list of names.  Update the current scope to match.  */
   11266        13252 :   DECL_ARGUMENTS (fndecl) = NULL_TREE;
   11267              : 
   11268        13260 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11269         8680 :     if (TREE_PURPOSE (parm))
   11270              :       break;
   11271        13252 :   if (parm && TREE_PURPOSE (parm))
   11272              :     {
   11273         8672 :       last = TREE_PURPOSE (parm);
   11274         8672 :       DECL_ARGUMENTS (fndecl) = last;
   11275              : 
   11276        34275 :       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
   11277        25603 :         if (TREE_PURPOSE (parm))
   11278              :           {
   11279        25602 :             DECL_CHAIN (last) = TREE_PURPOSE (parm);
   11280        25603 :             last = TREE_PURPOSE (parm);
   11281              :           }
   11282         8672 :       DECL_CHAIN (last) = NULL_TREE;
   11283              :     }
   11284              : 
   11285              :   /* If there was a previous prototype,
   11286              :      set the DECL_ARG_TYPE of each argument according to
   11287              :      the type previously specified, and report any mismatches.  */
   11288              : 
   11289        13252 :   if (current_function_prototype_arg_types)
   11290              :     {
   11291          171 :       tree type;
   11292          171 :       for (parm = DECL_ARGUMENTS (fndecl),
   11293          171 :              type = current_function_prototype_arg_types;
   11294          373 :            parm || (type != NULL_TREE
   11295          166 :                     && TREE_VALUE (type) != error_mark_node
   11296          166 :                     && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
   11297          202 :            parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
   11298              :         {
   11299          212 :           if (parm == NULL_TREE
   11300          206 :               || type == NULL_TREE
   11301          418 :               || (TREE_VALUE (type) != error_mark_node
   11302          192 :                   && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
   11303              :             {
   11304           10 :               if (current_function_prototype_built_in)
   11305            6 :                 warning_at (DECL_SOURCE_LOCATION (fndecl),
   11306            6 :                             0, "number of arguments doesn%'t match "
   11307              :                             "built-in prototype");
   11308              :               else
   11309              :                 {
   11310              :                   /* FIXME diagnostics: This should be the location of
   11311              :                      FNDECL, but there is bug when a prototype is
   11312              :                      declared inside function context, but defined
   11313              :                      outside of it (e.g., gcc.dg/pr15698-2.c).  In
   11314              :                      which case FNDECL gets the location of the
   11315              :                      prototype, not the definition.  */
   11316            4 :                   error_at (input_location,
   11317              :                             "number of arguments doesn%'t match prototype");
   11318              : 
   11319            4 :                   error_at (current_function_prototype_locus,
   11320              :                             "prototype declaration");
   11321              :                 }
   11322              :               break;
   11323              :             }
   11324              :           /* Type for passing arg must be consistent with that
   11325              :              declared for the arg.  ISO C says we take the unqualified
   11326              :              type for parameters declared with qualified type.  */
   11327          202 :           if (TREE_TYPE (parm) != error_mark_node
   11328          201 :               && TREE_VALUE (type) != error_mark_node
   11329          389 :               && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11330          187 :                    != TYPE_ATOMIC (TREE_VALUE (type)))
   11331          185 :                   || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
   11332          185 :                                  TYPE_MAIN_VARIANT (TREE_VALUE (type)))))
   11333              :             {
   11334           36 :               if ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11335           36 :                    == TYPE_ATOMIC (TREE_VALUE (type)))
   11336           36 :                   && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
   11337           34 :                       == TYPE_MAIN_VARIANT (TREE_VALUE (type))))
   11338              :                 {
   11339              :                   /* Adjust argument to match prototype.  E.g. a previous
   11340              :                      `int foo(float);' prototype causes
   11341              :                      `int foo(x) float x; {...}' to be treated like
   11342              :                      `int foo(float x) {...}'.  This is particularly
   11343              :                      useful for argument types like uid_t.  */
   11344           17 :                   DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
   11345              : 
   11346              :                   /* ??? Is it possible to get here with a
   11347              :                      built-in prototype or will it always have
   11348              :                      been diagnosed as conflicting with an
   11349              :                      old-style definition and discarded?  */
   11350           17 :                   if (current_function_prototype_built_in)
   11351            2 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11352            2 :                                 OPT_Wpedantic, "promoted argument %qD "
   11353              :                                 "doesn%'t match built-in prototype", parm);
   11354              :                   else
   11355              :                     {
   11356           15 :                       pedwarn (DECL_SOURCE_LOCATION (parm),
   11357           15 :                                OPT_Wpedantic, "promoted argument %qD "
   11358              :                                "doesn%'t match prototype", parm);
   11359           15 :                       pedwarn (current_function_prototype_locus, OPT_Wpedantic,
   11360              :                                "prototype declaration");
   11361              :                     }
   11362              :                 }
   11363              :               else
   11364              :                 {
   11365           19 :                   if (current_function_prototype_built_in)
   11366           10 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11367           10 :                                 0, "argument %qD doesn%'t match "
   11368              :                                 "built-in prototype", parm);
   11369              :                   else
   11370              :                     {
   11371            9 :                       error_at (DECL_SOURCE_LOCATION (parm),
   11372              :                                 "argument %qD doesn%'t match prototype", parm);
   11373            9 :                       error_at (current_function_prototype_locus,
   11374              :                                 "prototype declaration");
   11375              :                     }
   11376              :                 }
   11377              :             }
   11378              :         }
   11379          171 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = NULL_TREE;
   11380              :     }
   11381              : 
   11382              :   /* Otherwise, create a prototype that would match.  */
   11383              : 
   11384              :   else
   11385              :     {
   11386        13081 :       tree actual = NULL_TREE, last = NULL_TREE, type;
   11387              : 
   11388        47149 :       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   11389              :         {
   11390        34068 :           type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
   11391        34068 :           if (last)
   11392        25552 :             TREE_CHAIN (last) = type;
   11393              :           else
   11394              :             actual = type;
   11395        34068 :           last = type;
   11396              :         }
   11397        13081 :       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
   11398        13081 :       if (last)
   11399         8516 :         TREE_CHAIN (last) = type;
   11400              :       else
   11401              :         actual = type;
   11402              : 
   11403              :       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
   11404              :          of the type of this function, but we need to avoid having this
   11405              :          affect the types of other similarly-typed functions, so we must
   11406              :          first force the generation of an identical (but separate) type
   11407              :          node for the relevant function type.  The new node we create
   11408              :          will be a variant of the main variant of the original function
   11409              :          type.  */
   11410              : 
   11411        13081 :       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
   11412              : 
   11413        13081 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
   11414              :     }
   11415        13252 : }
   11416              : 
   11417              : /* Store parameter declarations passed in ARG_INFO into the current
   11418              :    function declaration.  */
   11419              : 
   11420              : void
   11421            0 : store_parm_decls_from (struct c_arg_info *arg_info)
   11422              : {
   11423            0 :   current_function_arg_info = arg_info;
   11424            0 :   store_parm_decls ();
   11425            0 : }
   11426              : 
   11427              : /* Called by walk_tree to look for and update context-less labels
   11428              :    or labels with context in the parent function.  */
   11429              : 
   11430              : static tree
   11431         8175 : set_labels_context_r (tree *tp, int *walk_subtrees, void *data)
   11432              : {
   11433         8175 :   tree ctx = static_cast<tree>(data);
   11434         8175 :   if (TREE_CODE (*tp) == LABEL_EXPR
   11435         8175 :       && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE
   11436            2 :           || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx)))
   11437              :     {
   11438           72 :       DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx;
   11439           72 :       *walk_subtrees = 0;
   11440              :     }
   11441              : 
   11442         8175 :   return NULL_TREE;
   11443              : }
   11444              : 
   11445              : /* Store the parameter declarations into the current function declaration.
   11446              :    This is called after parsing the parameter declarations, before
   11447              :    digesting the body of the function.
   11448              : 
   11449              :    For an old-style definition, construct a prototype out of the old-style
   11450              :    parameter declarations and inject it into the function's type.  */
   11451              : 
   11452              : void
   11453     37669275 : store_parm_decls (void)
   11454              : {
   11455     37669275 :   tree fndecl = current_function_decl;
   11456     37669275 :   bool proto;
   11457              : 
   11458              :   /* The argument information block for FNDECL.  */
   11459     37669275 :   struct c_arg_info *arg_info = current_function_arg_info;
   11460     37669275 :   current_function_arg_info = 0;
   11461              : 
   11462              :   /* True if this definition is written with a prototype.  In C23, an
   11463              :      empty argument list was converted to (void) in grokparms; in
   11464              :      older C standard versions, it does not give the function a type
   11465              :      with a prototype for future calls.  */
   11466     37669275 :   proto = arg_info->types != 0 || arg_info->no_named_args_stdarg_p;
   11467              : 
   11468        13252 :   if (proto)
   11469     37656023 :     store_parm_decls_newstyle (fndecl, arg_info);
   11470              :   else
   11471        13252 :     store_parm_decls_oldstyle (fndecl, arg_info);
   11472              : 
   11473              :   /* The next call to push_scope will be a function body.  */
   11474              : 
   11475     37669275 :   next_is_function_body = true;
   11476              : 
   11477              :   /* Write a record describing this function definition to the prototypes
   11478              :      file (if requested).  */
   11479              : 
   11480     37669275 :   gen_aux_info_record (fndecl, 1, 0, proto);
   11481              : 
   11482              :   /* Initialize the RTL code for the function.  */
   11483     37669275 :   allocate_struct_function (fndecl, false);
   11484              : 
   11485     37669275 :   if (warn_unused_local_typedefs)
   11486      3197841 :     cfun->language = ggc_cleared_alloc<language_function> ();
   11487              : 
   11488              :   /* Begin the statement tree for this function.  */
   11489     37669275 :   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
   11490              : 
   11491              :   /* ??? Insert the contents of the pending sizes list into the function
   11492              :      to be evaluated.  The only reason left to have this is
   11493              :         void foo(int n, int array[n++])
   11494              :      because we throw away the array type in favor of a pointer type, and
   11495              :      thus won't naturally see the SAVE_EXPR containing the increment.  All
   11496              :      other pending sizes would be handled by gimplify_parameters.  */
   11497     37669275 :   if (arg_info->pending_sizes)
   11498              :     {
   11499              :       /* In very special circumstances, e.g. for code like
   11500              :            _Atomic int i = 5;
   11501              :            void f (int a[i += 2]) {}
   11502              :          we need to execute the atomic assignment on function entry.
   11503              :          But in this case, it is not just a straight store, it has the
   11504              :          op= form, which means that build_atomic_assign has generated
   11505              :          gotos, labels, etc.  Because at that time the function decl
   11506              :          for F has not been created yet, those labels do not have any
   11507              :          function context.  But we have the fndecl now, so update the
   11508              :          labels accordingly.  gimplify_expr would crash otherwise.
   11509              :          Or with nested functions the labels could be created with parent
   11510              :          function's context, while when the statement is emitted at the
   11511              :          start of the nested function, it needs the nested function's
   11512              :          context.  */
   11513          298 :       walk_tree_without_duplicates (&arg_info->pending_sizes,
   11514              :                                     set_labels_context_r, fndecl);
   11515          298 :       add_stmt (arg_info->pending_sizes);
   11516              :     }
   11517     37669275 : }
   11518              : 
   11519              : /* Store PARM_DECLs in PARMS into scope temporarily.  Used for
   11520              :    c_finish_omp_declare_simd for function prototypes.  No diagnostics
   11521              :    should be done.  */
   11522              : 
   11523              : void
   11524          267 : temp_store_parm_decls (tree fndecl, tree parms)
   11525              : {
   11526          267 :   push_scope ();
   11527         1004 :   for (tree p = parms; p; p = DECL_CHAIN (p))
   11528              :     {
   11529          470 :       DECL_CONTEXT (p) = fndecl;
   11530          470 :       if (DECL_NAME (p))
   11531          334 :         bind (DECL_NAME (p), p, current_scope,
   11532              :               /*invisible=*/false, /*nested=*/false,
   11533              :               UNKNOWN_LOCATION);
   11534              :     }
   11535          267 : }
   11536              : 
   11537              : /* Undo what temp_store_parm_decls did.  */
   11538              : 
   11539              : void
   11540          267 : temp_pop_parm_decls (void)
   11541              : {
   11542              :   /* Clear all bindings in this temporary scope, so that
   11543              :      pop_scope doesn't create a BLOCK.  */
   11544          267 :   struct c_binding *b = current_scope->bindings;
   11545          267 :   current_scope->bindings = NULL;
   11546          606 :   for (; b; b = free_binding_and_advance (b))
   11547              :     {
   11548          339 :       gcc_assert (TREE_CODE (b->decl) == PARM_DECL
   11549              :                   || b->decl == error_mark_node);
   11550          339 :       gcc_assert (I_SYMBOL_BINDING (b->id) == b);
   11551          339 :       I_SYMBOL_BINDING (b->id) = b->shadowed;
   11552          339 :       if (b->shadowed && b->shadowed->u.type)
   11553            0 :         TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
   11554              :     }
   11555          267 :   pop_scope ();
   11556          267 : }
   11557              : 
   11558              : 
   11559              : /* Finish up a function declaration and compile that function
   11560              :    all the way to assembler language output.  Then free the storage
   11561              :    for the function definition.
   11562              : 
   11563              :    This is called after parsing the body of the function definition.  */
   11564              : 
   11565              : void
   11566     37669273 : finish_function (location_t end_loc)
   11567              : {
   11568     37669273 :   tree fndecl = current_function_decl;
   11569              : 
   11570     37669273 :   if (c_dialect_objc ())
   11571            0 :     objc_finish_function ();
   11572              : 
   11573     37669273 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
   11574     37669271 :     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   11575              : 
   11576              :   /* Must mark the RESULT_DECL as being in this function.  */
   11577              : 
   11578     37669273 :   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
   11579     37669273 :     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   11580              : 
   11581     37718650 :   if (MAIN_NAME_P (DECL_NAME (fndecl)) && !TREE_THIS_VOLATILE (fndecl)
   11582        49376 :       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
   11583     37718649 :       == integer_type_node && flag_isoc99)
   11584              :     {
   11585              :       /* Hack.  We don't want the middle-end to warn that this return
   11586              :          is unreachable, so we mark its location as special.  Using
   11587              :          UNKNOWN_LOCATION has the problem that it gets clobbered in
   11588              :          annotate_one_with_locus.  A cleaner solution might be to
   11589              :          ensure ! should_carry_locus_p (stmt), but that needs a flag.
   11590              :       */
   11591        47982 :       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
   11592              :     }
   11593              : 
   11594              :   /* Tie off the statement tree for this function.  */
   11595     37669273 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   11596              : 
   11597     37669273 :   finish_fname_decls ();
   11598              : 
   11599              :   /* Complain if there's no return statement only if option specified on
   11600              :      command line.  */
   11601     37669273 :   if (warn_return_type > 0
   11602      3197864 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
   11603      2992944 :       && !current_function_returns_value && !current_function_returns_null
   11604              :       /* Don't complain if we are no-return.  */
   11605           72 :       && !current_function_returns_abnormally
   11606              :       /* Don't complain if we are declared noreturn.  */
   11607           21 :       && !TREE_THIS_VOLATILE (fndecl)
   11608              :       /* Don't warn for main().  */
   11609           18 :       && !MAIN_NAME_P (DECL_NAME (fndecl))
   11610              :       /* Or if they didn't actually specify a return type.  */
   11611           17 :       && !C_FUNCTION_IMPLICIT_INT (fndecl)
   11612              :       /* Normally, with -Wreturn-type, flow will complain, but we might
   11613              :          optimize out static functions.  */
   11614           17 :       && !TREE_PUBLIC (fndecl)
   11615            6 :       && targetm.warn_func_return (fndecl)
   11616     40867137 :       && warning (OPT_Wreturn_type,
   11617              :                   "no return statement in function returning non-void"))
   11618            5 :     suppress_warning (fndecl, OPT_Wreturn_type);
   11619              : 
   11620              :   /* Complain about parameters that are only set, but never otherwise used.  */
   11621     37669273 :   if (warn_unused_but_set_parameter)
   11622              :     {
   11623      3129211 :       tree decl;
   11624              : 
   11625      3129211 :       for (decl = DECL_ARGUMENTS (fndecl);
   11626     11647462 :            decl;
   11627      8518251 :            decl = DECL_CHAIN (decl))
   11628      8518251 :         if (TREE_USED (decl)
   11629      8457548 :             && TREE_CODE (decl) == PARM_DECL
   11630      8457548 :             && !DECL_READ_P (decl)
   11631           47 :             && DECL_NAME (decl)
   11632           47 :             && !DECL_ARTIFICIAL (decl)
   11633      8518298 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_))
   11634           47 :           warning_at (DECL_SOURCE_LOCATION (decl),
   11635           47 :                       OPT_Wunused_but_set_parameter_,
   11636              :                       "parameter %qD set but not used", decl);
   11637              :     }
   11638              : 
   11639              :   /* Complain about locally defined typedefs that are not used in this
   11640              :      function.  */
   11641     37669273 :   maybe_warn_unused_local_typedefs ();
   11642              : 
   11643              :   /* Possibly warn about unused parameters.  */
   11644     37669273 :   if (warn_unused_parameter)
   11645      3035322 :     do_warn_unused_parameter (fndecl);
   11646              : 
   11647              :   /* Store the end of the function, so that we get good line number
   11648              :      info for the epilogue.  */
   11649     37669273 :   cfun->function_end_locus = end_loc;
   11650              : 
   11651              :   /* Finalize the ELF visibility for the function.  */
   11652     37669273 :   c_determine_visibility (fndecl);
   11653              : 
   11654              :   /* For GNU C extern inline functions disregard inline limits.  */
   11655     37669273 :   if (DECL_EXTERNAL (fndecl)
   11656     36795165 :       && DECL_DECLARED_INLINE_P (fndecl)
   11657     74464435 :       && (flag_gnu89_inline
   11658     36755592 :           || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
   11659     36794679 :     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
   11660              : 
   11661              :   /* Genericize before inlining.  Delay genericizing nested functions
   11662              :      until their parent function is genericized.  Since finalizing
   11663              :      requires GENERIC, delay that as well.  */
   11664              : 
   11665     75338546 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
   11666     75338544 :       && !undef_nested_function)
   11667              :     {
   11668     37669265 :       if (!decl_function_context (fndecl))
   11669              :         {
   11670     37667647 :           invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   11671     37667647 :           c_genericize (fndecl);
   11672              : 
   11673              :           /* ??? Objc emits functions after finalizing the compilation unit.
   11674              :              This should be cleaned up later and this conditional removed.  */
   11675     37667647 :           if (symtab->global_info_ready)
   11676              :             {
   11677            0 :               cgraph_node::add_new_function (fndecl, false);
   11678            0 :               return;
   11679              :             }
   11680     37667647 :           cgraph_node::finalize_function (fndecl, false);
   11681              :         }
   11682              :       else
   11683              :         {
   11684              :           /* Register this function with cgraph just far enough to get it
   11685              :             added to our parent's nested function list.  Handy, since the
   11686              :             C front end doesn't have such a list.  */
   11687         1618 :           (void) cgraph_node::get_create (fndecl);
   11688              :         }
   11689              :     }
   11690              : 
   11691     37669273 :   if (!decl_function_context (fndecl))
   11692     37667655 :     undef_nested_function = false;
   11693              : 
   11694     37669273 :   if (cfun->language != NULL)
   11695              :     {
   11696      3197840 :       ggc_free (cfun->language);
   11697      3197840 :       cfun->language = NULL;
   11698              :     }
   11699              : 
   11700              :   /* We're leaving the context of this function, so zap cfun.
   11701              :      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
   11702              :      tree_rest_of_compilation.  */
   11703     37669273 :   set_cfun (NULL);
   11704     37669273 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, current_function_decl);
   11705     37669273 :   current_function_decl = NULL;
   11706              : }
   11707              : 
   11708              : /* Check the declarations given in a for-loop for satisfying the C99
   11709              :    constraints.  If exactly one such decl is found, return it.  LOC is
   11710              :    the location of the opening parenthesis of the for loop.  The last
   11711              :    parameter allows you to control the "for loop initial declarations
   11712              :    are only allowed in C99 mode".  Normally, you should pass
   11713              :    flag_isoc99 as that parameter.  But in some cases (Objective-C
   11714              :    foreach loop, for example) we want to run the checks in this
   11715              :    function even if not in C99 mode, so we allow the caller to turn
   11716              :    off the error about not being in C99 mode.
   11717              : */
   11718              : 
   11719              : tree
   11720        29262 : check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
   11721              : {
   11722        29262 :   struct c_binding *b;
   11723        29262 :   tree one_decl = NULL_TREE;
   11724        29262 :   int n_decls = 0;
   11725              : 
   11726        29262 :   if (!turn_off_iso_c99_error)
   11727              :     {
   11728            1 :       static bool hint = true;
   11729              :       /* If we get here, declarations have been used in a for loop without
   11730              :          the C99 for loop scope.  This doesn't make much sense, so don't
   11731              :          allow it.  */
   11732            1 :       auto_diagnostic_group d;
   11733            1 :       error_at (loc, "%<for%> loop initial declarations "
   11734              :                 "are only allowed in C99 or C11 mode");
   11735            1 :       if (hint)
   11736              :         {
   11737            1 :           inform (loc,
   11738              :                   "use option %<-std=c99%>, %<-std=gnu99%>, %<-std=c11%> or "
   11739              :                   "%<-std=gnu11%> to compile your code");
   11740            1 :           hint = false;
   11741              :         }
   11742            1 :       return NULL_TREE;
   11743            1 :     }
   11744              :   else
   11745        29261 :     pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop "
   11746              :                  "initial declarations");
   11747              : 
   11748              :   /* C99 subclause 6.8.5 paragraph 3:
   11749              : 
   11750              :        [#3]  The  declaration  part  of  a for statement shall only
   11751              :        declare identifiers for objects having storage class auto or
   11752              :        register.
   11753              : 
   11754              :      It isn't clear whether, in this sentence, "identifiers" binds to
   11755              :      "shall only declare" or to "objects" - that is, whether all identifiers
   11756              :      declared must be identifiers for objects, or whether the restriction
   11757              :      only applies to those that are.  (A question on this in comp.std.c
   11758              :      in November 2000 received no answer.)  We implement the strictest
   11759              :      interpretation, to avoid creating an extension which later causes
   11760              :      problems.
   11761              : 
   11762              :      This constraint was removed in C23.  */
   11763              : 
   11764        58610 :   for (b = current_scope->bindings; b; b = b->prev)
   11765              :     {
   11766        29349 :       tree id = b->id;
   11767        29349 :       tree decl = b->decl;
   11768              : 
   11769        29349 :       if (!id)
   11770           27 :         continue;
   11771              : 
   11772        29322 :       switch (TREE_CODE (decl))
   11773              :         {
   11774        29274 :         case VAR_DECL:
   11775        29274 :           {
   11776        29274 :             location_t decl_loc = DECL_SOURCE_LOCATION (decl);
   11777        29274 :             if (TREE_STATIC (decl))
   11778            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11779              :                            "declaration of static variable %qD in %<for%> "
   11780              :                            "loop initial declaration", decl);
   11781        29269 :             else if (DECL_EXTERNAL (decl))
   11782            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11783              :                            "declaration of %<extern%> variable %qD in %<for%> "
   11784              :                            "loop initial declaration", decl);
   11785              :           }
   11786              :           break;
   11787              : 
   11788            6 :         case RECORD_TYPE:
   11789            6 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11790              :                        "%<struct %E%> declared in %<for%> loop initial "
   11791              :                        "declaration", id);
   11792            6 :           break;
   11793            5 :         case UNION_TYPE:
   11794            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11795              :                        "%<union %E%> declared in %<for%> loop initial "
   11796              :                        "declaration",
   11797              :                        id);
   11798            5 :           break;
   11799            5 :         case ENUMERAL_TYPE:
   11800            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11801              :                        "%<enum %E%> declared in %<for%> loop "
   11802              :                        "initial declaration", id);
   11803            5 :           break;
   11804           32 :         default:
   11805           32 :           pedwarn_c11 (loc, OPT_Wpedantic, "declaration of non-variable "
   11806              :                        "%qD in %<for%> loop initial declaration", decl);
   11807              :         }
   11808              : 
   11809        29322 :       n_decls++;
   11810        29322 :       one_decl = decl;
   11811              :     }
   11812              : 
   11813        29261 :   return n_decls == 1 ? one_decl : NULL_TREE;
   11814              : }
   11815              : 
   11816              : /* Save and reinitialize the variables
   11817              :    used during compilation of a C function.  */
   11818              : 
   11819              : void
   11820         1646 : c_push_function_context (void)
   11821              : {
   11822         1646 :   struct language_function *p = cfun->language;
   11823              :   /* cfun->language might have been already allocated by the use of
   11824              :      -Wunused-local-typedefs.  In that case, just re-use it.  */
   11825         1646 :   if (p == NULL)
   11826         1590 :     cfun->language = p = ggc_cleared_alloc<language_function> ();
   11827              : 
   11828         1646 :   p->base.x_stmt_tree = c_stmt_tree;
   11829         1646 :   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
   11830         1646 :   p->x_in_statement = in_statement;
   11831         1646 :   p->x_switch_stack = c_switch_stack;
   11832         1646 :   p->loop_names = loop_names;
   11833         1646 :   loop_names = vNULL;
   11834         1646 :   p->loop_names_hash = loop_names_hash;
   11835         1646 :   loop_names_hash = NULL;
   11836         1646 :   p->arg_info = current_function_arg_info;
   11837         1646 :   p->returns_value = current_function_returns_value;
   11838         1646 :   p->returns_null = current_function_returns_null;
   11839         1646 :   p->returns_abnormally = current_function_returns_abnormally;
   11840         1646 :   p->warn_about_return_type = warn_about_return_type;
   11841              : 
   11842         1646 :   push_function_context ();
   11843         1646 : }
   11844              : 
   11845              : /* Restore the variables used during compilation of a C function.  */
   11846              : 
   11847              : void
   11848         1646 : c_pop_function_context (void)
   11849              : {
   11850         1646 :   struct language_function *p;
   11851              : 
   11852         1646 :   pop_function_context ();
   11853         1646 :   p = cfun->language;
   11854              : 
   11855              :   /* When -Wunused-local-typedefs is in effect, cfun->languages is
   11856              :      used to store data throughout the life time of the current cfun,
   11857              :      So don't deallocate it.  */
   11858         1646 :   if (!warn_unused_local_typedefs)
   11859         1590 :     cfun->language = NULL;
   11860              : 
   11861         1646 :   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
   11862         1646 :       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
   11863              :     {
   11864              :       /* Stop pointing to the local nodes about to be freed.  */
   11865              :       /* But DECL_INITIAL must remain nonzero so we know this
   11866              :          was an actual function definition.  */
   11867            0 :       DECL_INITIAL (current_function_decl) = error_mark_node;
   11868            0 :       DECL_ARGUMENTS (current_function_decl) = NULL_TREE;
   11869              :     }
   11870              : 
   11871         1646 :   c_stmt_tree = p->base.x_stmt_tree;
   11872         1646 :   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
   11873         1646 :   in_statement = p->x_in_statement;
   11874         1646 :   c_switch_stack = p->x_switch_stack;
   11875         1646 :   loop_names.release ();
   11876         1646 :   loop_names = p->loop_names;
   11877         1646 :   p->loop_names = vNULL;
   11878         1646 :   delete loop_names_hash;
   11879         1646 :   loop_names_hash = p->loop_names_hash;
   11880         1646 :   p->loop_names_hash = NULL;
   11881         1646 :   current_function_arg_info = p->arg_info;
   11882         1646 :   current_function_returns_value = p->returns_value;
   11883         1646 :   current_function_returns_null = p->returns_null;
   11884         1646 :   current_function_returns_abnormally = p->returns_abnormally;
   11885         1646 :   warn_about_return_type = p->warn_about_return_type;
   11886         1646 : }
   11887              : 
   11888              : /* The functions below are required for functionality of doing
   11889              :    function at once processing in the C front end. Currently these
   11890              :    functions are not called from anywhere in the C front end, but as
   11891              :    these changes continue, that will change.  */
   11892              : 
   11893              : /* Returns the stmt_tree (if any) to which statements are currently
   11894              :    being added.  If there is no active statement-tree, NULL is
   11895              :    returned.  */
   11896              : 
   11897              : stmt_tree
   11898   1018847255 : current_stmt_tree (void)
   11899              : {
   11900   1018847255 :   return &c_stmt_tree;
   11901              : }
   11902              : 
   11903              : /* Return the global value of T as a symbol.  */
   11904              : 
   11905              : tree
   11906      4041280 : identifier_global_value (tree t)
   11907              : {
   11908      4041280 :   struct c_binding *b;
   11909              : 
   11910      4042247 :   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
   11911      4035008 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11912      4034041 :       return b->decl;
   11913              : 
   11914              :   return NULL_TREE;
   11915              : }
   11916              : 
   11917              : /* Return the global value of tag T as a symbol.  */
   11918              : 
   11919              : tree
   11920           12 : identifier_global_tag (tree t)
   11921              : {
   11922           12 :   struct c_binding *b;
   11923              : 
   11924           12 :   for (b = I_TAG_BINDING (t); b; b = b->shadowed)
   11925           11 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11926           11 :       return b->decl;
   11927              : 
   11928              :   return NULL_TREE;
   11929              : }
   11930              : 
   11931              : /* Returns non-zero (result of __has_builtin) if NAME refers to a built-in
   11932              :    function or function-like operator.  */
   11933              : 
   11934              : int
   11935        25520 : names_builtin_p (const char *name)
   11936              : {
   11937        25520 :   tree id = get_identifier (name);
   11938        25520 :   if (tree decl = identifier_global_value (id))
   11939        25429 :     return TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_UNDECLARED_BUILTIN (decl);
   11940              : 
   11941              :   /* Also detect common reserved C words that aren't strictly built-in
   11942              :      functions.  */
   11943           91 :   switch (C_RID_CODE (id))
   11944              :     {
   11945              :     case RID_BUILTIN_ASSOC_BARRIER:
   11946              :     case RID_BUILTIN_BITREVERSEG:
   11947              :     case RID_BUILTIN_BSWAPG:
   11948              :     case RID_BUILTIN_CLMULG:
   11949              :     case RID_BUILTIN_CONVERTVECTOR:
   11950              :     case RID_BUILTIN_HAS_ATTRIBUTE:
   11951              :     case RID_BUILTIN_SHUFFLE:
   11952              :     case RID_BUILTIN_SHUFFLEVECTOR:
   11953              :     case RID_BUILTIN_STDC:
   11954              :     case RID_BUILTIN_COUNTED_BY_REF:
   11955              :     case RID_CHOOSE_EXPR:
   11956              :     case RID_OFFSETOF:
   11957              :     case RID_TYPES_COMPATIBLE_P:
   11958              :     case RID_C23_VA_START:
   11959              :     case RID_VA_ARG:
   11960              :       return 1;
   11961           66 :     default:
   11962           66 :       break;
   11963              :     }
   11964              : 
   11965           66 :   return 0;
   11966              : }
   11967              : 
   11968              : /* In C, the only C-linkage public declaration is at file scope.  */
   11969              : 
   11970              : tree
   11971            5 : c_linkage_bindings (tree name)
   11972              : {
   11973            5 :   return identifier_global_value (name);
   11974              : }
   11975              : 
   11976              : /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
   11977              :    otherwise the name is found in ridpointers from RID_INDEX.  */
   11978              : 
   11979              : void
   11980      3432960 : record_builtin_type (enum rid rid_index, const char *name, tree type)
   11981              : {
   11982      3432960 :   tree id, decl;
   11983      3432960 :   if (name == 0)
   11984      1602048 :     id = ridpointers[(int) rid_index];
   11985              :   else
   11986      1830912 :     id = get_identifier (name);
   11987      3432960 :   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
   11988      3432960 :   pushdecl (decl);
   11989      3432960 :   if (debug_hooks->type_decl)
   11990      3432960 :     debug_hooks->type_decl (decl, false);
   11991      3432960 : }
   11992              : 
   11993              : /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
   11994              : 
   11995              : struct c_parm *
   11996    128385248 : build_c_parm (struct c_declspecs *specs, tree attrs,
   11997              :               struct c_declarator *declarator,
   11998              :               location_t loc)
   11999              : {
   12000    128385248 :   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
   12001    128385248 :   ret->specs = specs;
   12002    128385248 :   ret->attrs = attrs;
   12003    128385248 :   ret->declarator = declarator;
   12004    128385248 :   ret->loc = loc;
   12005    128385248 :   return ret;
   12006              : }
   12007              : 
   12008              : /* Return a declarator with nested attributes.  TARGET is the inner
   12009              :    declarator to which these attributes apply.  ATTRS are the
   12010              :    attributes.  */
   12011              : 
   12012              : struct c_declarator *
   12013         6878 : build_attrs_declarator (tree attrs, struct c_declarator *target)
   12014              : {
   12015         6878 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12016         6878 :   ret->kind = cdk_attrs;
   12017         6878 :   ret->declarator = target;
   12018         6878 :   ret->u.attrs = attrs;
   12019         6878 :   return ret;
   12020              : }
   12021              : 
   12022              : /* Return a declarator for a function with arguments specified by ARGS
   12023              :    and return type specified by TARGET.  */
   12024              : 
   12025              : struct c_declarator *
   12026     52592550 : build_function_declarator (struct c_arg_info *args,
   12027              :                            struct c_declarator *target)
   12028              : {
   12029     52592550 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12030     52592550 :   ret->kind = cdk_function;
   12031     52592550 :   ret->declarator = target;
   12032     52592550 :   ret->u.arg_info = args;
   12033     52592550 :   return ret;
   12034              : }
   12035              : 
   12036              : /* Return a declarator for the identifier IDENT (which may be
   12037              :    NULL_TREE for an abstract declarator).  */
   12038              : 
   12039              : struct c_declarator *
   12040    325586489 : build_id_declarator (tree ident)
   12041              : {
   12042    325586489 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12043    325586489 :   ret->kind = cdk_id;
   12044    325586489 :   ret->declarator = 0;
   12045    325586489 :   ret->u.id.id = ident;
   12046    325586489 :   ret->u.id.attrs = NULL_TREE;
   12047              :   /* Default value - may get reset to a more precise location. */
   12048    325586489 :   ret->id_loc = input_location;
   12049    325586489 :   return ret;
   12050              : }
   12051              : 
   12052              : /* Return something to represent absolute declarators containing a *.
   12053              :    TARGET is the absolute declarator that the * contains.
   12054              :    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
   12055              :    to apply to the pointer type.  */
   12056              : 
   12057              : struct c_declarator *
   12058     18790592 : make_pointer_declarator (struct c_declspecs *type_quals_attrs,
   12059              :                          struct c_declarator *target)
   12060              : {
   12061     18790592 :   tree attrs;
   12062     18790592 :   qualifier_set quals {};
   12063     18790592 :   struct c_declarator *itarget = target;
   12064     18790592 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12065     18790592 :   if (type_quals_attrs)
   12066              :     {
   12067     18790592 :       attrs = type_quals_attrs->attrs;
   12068     18790592 :       quals = quals_from_declspecs (type_quals_attrs);
   12069     18790592 :       if (attrs != NULL_TREE)
   12070         6566 :         itarget = build_attrs_declarator (attrs, target);
   12071              :     }
   12072     18790592 :   ret->kind = cdk_pointer;
   12073     18790592 :   ret->declarator = itarget;
   12074     18790592 :   ret->u.pointer_quals = quals;
   12075     18790592 :   return ret;
   12076              : }
   12077              : 
   12078              : /* Return a pointer to a structure for an empty list of declaration
   12079              :    specifiers.  */
   12080              : 
   12081              : struct c_declspecs *
   12082    471939083 : build_null_declspecs (void)
   12083              : {
   12084    471939083 :   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
   12085    471939083 :   memset (ret, 0, sizeof *ret);
   12086    471939083 :   ret->align_log = -1;
   12087    471939083 :   ret->typespec_word = cts_none;
   12088    471939083 :   ret->storage_class = csc_none;
   12089    471939083 :   ret->expr_const_operands = true;
   12090    471939083 :   ret->typespec_kind = ctsk_none;
   12091    471939083 :   ret->address_space = ADDR_SPACE_GENERIC;
   12092    471939083 :   return ret;
   12093              : }
   12094              : 
   12095              : /* Add the address space ADDRSPACE to the declaration specifiers
   12096              :    SPECS, returning SPECS.  */
   12097              : 
   12098              : struct c_declspecs *
   12099          178 : declspecs_add_addrspace (location_t location,
   12100              :                          struct c_declspecs *specs, addr_space_t as)
   12101              : {
   12102          178 :   specs->non_sc_seen_p = true;
   12103          178 :   specs->declspecs_seen_p = true;
   12104          178 :   specs->non_std_attrs_seen_p = true;
   12105              : 
   12106          178 :   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
   12107            0 :       && specs->address_space != as)
   12108            0 :     error ("incompatible address space qualifiers %qs and %qs",
   12109              :            c_addr_space_name (as),
   12110              :            c_addr_space_name (specs->address_space));
   12111              :   else
   12112              :     {
   12113          178 :       specs->address_space = as;
   12114          178 :       specs->locations[cdw_address_space] = location;
   12115              :     }
   12116          178 :   return specs;
   12117              : }
   12118              : 
   12119              : /* Add the type qualifier QUAL to the declaration specifiers SPECS,
   12120              :    returning SPECS.  */
   12121              : 
   12122              : struct c_declspecs *
   12123     17217017 : declspecs_add_qual (location_t loc,
   12124              :                     struct c_declspecs *specs, tree qual)
   12125              : {
   12126     17217017 :   enum rid i;
   12127     17217017 :   bool dupe = false;
   12128     17217017 :   specs->non_sc_seen_p = true;
   12129     17217017 :   specs->declspecs_seen_p = true;
   12130     17217017 :   specs->non_std_attrs_seen_p = true;
   12131     17217017 :   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
   12132              :               && C_IS_RESERVED_WORD (qual));
   12133     17217017 :   i = C_RID_CODE (qual);
   12134     17217017 :   location_t prev_loc = UNKNOWN_LOCATION;
   12135     17217017 :   switch (i)
   12136              :     {
   12137     13598894 :     case RID_CONST:
   12138     13598894 :       dupe = specs->const_p;
   12139     13598894 :       specs->const_p = true;
   12140     13598894 :       prev_loc = specs->locations[cdw_const];
   12141     13598894 :       specs->locations[cdw_const] = loc;
   12142     13598894 :       break;
   12143       102575 :     case RID_VOLATILE:
   12144       102575 :       dupe = specs->volatile_p;
   12145       102575 :       specs->volatile_p = true;
   12146       102575 :       prev_loc = specs->locations[cdw_volatile];
   12147       102575 :       specs->locations[cdw_volatile] = loc;
   12148       102575 :       break;
   12149      3495034 :     case RID_RESTRICT:
   12150      3495034 :       dupe = specs->restrict_p;
   12151      3495034 :       specs->restrict_p = true;
   12152      3495034 :       prev_loc = specs->locations[cdw_restrict];
   12153      3495034 :       specs->locations[cdw_restrict] = loc;
   12154      3495034 :       break;
   12155        20514 :     case RID_ATOMIC:
   12156        20514 :       dupe = specs->atomic_p;
   12157        20514 :       specs->atomic_p = true;
   12158        20514 :       prev_loc = specs->locations[cdw_atomic];
   12159        20514 :       specs->locations[cdw_atomic] = loc;
   12160        20514 :       break;
   12161            0 :     default:
   12162            0 :       gcc_unreachable ();
   12163              :     }
   12164     17217017 :   if (dupe)
   12165              :     {
   12166           56 :       bool warned = pedwarn_c90 (loc, OPT_Wpedantic,
   12167              :                                  "duplicate %qE declaration specifier", qual);
   12168           56 :       if (!warned
   12169           52 :           && warn_duplicate_decl_specifier
   12170           33 :           && prev_loc >= RESERVED_LOCATION_COUNT
   12171           33 :           && !from_macro_expansion_at (prev_loc)
   12172           77 :           && !from_macro_expansion_at (loc))
   12173           12 :         warning_at (loc, OPT_Wduplicate_decl_specifier,
   12174              :                     "duplicate %qE declaration specifier", qual);
   12175              :     }
   12176     17217017 :   return specs;
   12177              : }
   12178              : 
   12179              : /* Add the type specifier TYPE to the declaration specifiers SPECS,
   12180              :    returning SPECS.  */
   12181              : 
   12182              : struct c_declspecs *
   12183    343782934 : declspecs_add_type (location_t loc, struct c_declspecs *specs,
   12184              :                     struct c_typespec spec)
   12185              : {
   12186    343782934 :   tree type = spec.spec;
   12187    343782934 :   specs->non_sc_seen_p = true;
   12188    343782934 :   specs->declspecs_seen_p = true;
   12189    343782934 :   specs->non_std_attrs_seen_p = true;
   12190    343782934 :   specs->typespec_kind = spec.kind;
   12191    343782934 :   if (TREE_DEPRECATED (type))
   12192           56 :     specs->deprecated_p = true;
   12193    343782934 :   if (TREE_UNAVAILABLE (type))
   12194           40 :     specs->unavailable_p = true;
   12195              : 
   12196              :   /* As a type specifier is present, "auto" must be used as a storage
   12197              :      class specifier, not for type deduction.  */
   12198    343782934 :   if (specs->c23_auto_p)
   12199              :     {
   12200          115 :       specs->c23_auto_p = false;
   12201          115 :       if (specs->storage_class != csc_none)
   12202            1 :         error ("multiple storage classes in declaration specifiers");
   12203          114 :       else if (specs->thread_p)
   12204            1 :         error ("%qs used with %<auto%>",
   12205            1 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   12206          113 :       else if (specs->constexpr_p)
   12207              :         /* auto may only be used with another storage class specifier,
   12208              :            such as constexpr, if the type is inferred.  */
   12209            2 :         error ("%<auto%> used with %<constexpr%>");
   12210              :       else
   12211          111 :         specs->storage_class = csc_auto;
   12212              :     }
   12213              : 
   12214              :   /* Handle type specifier keywords.  */
   12215    343782934 :   if (TREE_CODE (type) == IDENTIFIER_NODE
   12216     85842466 :       && C_IS_RESERVED_WORD (type)
   12217    429625400 :       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
   12218              :     {
   12219     85842466 :       enum rid i = C_RID_CODE (type);
   12220     85842466 :       if (specs->type)
   12221              :         {
   12222           58 :           error_at (loc, "two or more data types in declaration specifiers");
   12223           58 :           return specs;
   12224              :         }
   12225     85842408 :       if ((int) i <= (int) RID_LAST_MODIFIER)
   12226              :         {
   12227              :           /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
   12228     22455737 :           bool dupe = false;
   12229     22455737 :           switch (i)
   12230              :             {
   12231     11253809 :             case RID_LONG:
   12232     11253809 :               if (specs->long_long_p)
   12233              :                 {
   12234          104 :                   error_at (loc, "%<long long long%> is too long for GCC");
   12235          104 :                   break;
   12236              :                 }
   12237     11253705 :               if (specs->long_p)
   12238              :                 {
   12239      3040087 :                   if (specs->typespec_word == cts_double)
   12240              :                     {
   12241           15 :                       error_at (loc,
   12242              :                                 "both %qs and %qs in declaration specifiers",
   12243              :                                 "long long", "double");
   12244           15 :                       break;
   12245              :                     }
   12246      3040072 :                   pedwarn_c90 (loc, OPT_Wlong_long,
   12247              :                                "ISO C90 does not support %<long long%>");
   12248      3040072 :                   specs->long_long_p = 1;
   12249      3040072 :                   specs->locations[cdw_long_long] = loc;
   12250      3040072 :                   break;
   12251              :                 }
   12252      8213618 :               if (specs->short_p)
   12253           77 :                 error_at (loc,
   12254              :                           "both %qs and %qs in declaration specifiers",
   12255              :                           "long", "short");
   12256      8213541 :               else if (specs->typespec_word == cts_auto_type)
   12257            1 :                 error_at (loc,
   12258              :                           "both %qs and %qs in declaration specifiers",
   12259              :                           "long", "__auto_type");
   12260              :               else if (specs->typespec_word == cts_void)
   12261            5 :                 error_at (loc,
   12262              :                           "both %qs and %qs in declaration specifiers",
   12263              :                           "long", "void");
   12264              :               else if (specs->typespec_word == cts_int_n)
   12265           19 :                 error_at (loc,
   12266              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12267           19 :                           "long", int_n_data[specs->u.int_n_idx].bitsize);
   12268              :               else if (specs->typespec_word == cts_bool)
   12269            3 :                 error_at (loc,
   12270              :                           "both %qs and %qs in declaration specifiers",
   12271              :                           "long", "_Bool");
   12272              :               else if (specs->typespec_word == cts_bitint)
   12273            3 :                 error_at (loc,
   12274              :                           "both %qs and %qs in declaration specifiers",
   12275              :                           "long", "_BitInt");
   12276              :               else if (specs->typespec_word == cts_char)
   12277           21 :                 error_at (loc,
   12278              :                           "both %qs and %qs in declaration specifiers",
   12279              :                           "long", "char");
   12280              :               else if (specs->typespec_word == cts_float)
   12281            7 :                 error_at (loc,
   12282              :                           "both %qs and %qs in declaration specifiers",
   12283              :                           "long", "float");
   12284              :               else if (specs->typespec_word == cts_floatn_nx)
   12285            0 :                 error_at (loc,
   12286              :                           "both %qs and %<_Float%d%s%> in declaration "
   12287              :                           "specifiers", "long",
   12288            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12289            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12290              :                           ? "x"
   12291              :                           : "");
   12292              :               else if (specs->typespec_word == cts_dfloat32)
   12293            4 :                 error_at (loc,
   12294              :                           "both %qs and %qs in declaration specifiers",
   12295              :                           "long", "_Decimal32");
   12296              :               else if (specs->typespec_word == cts_dfloat64)
   12297            4 :                 error_at (loc,
   12298              :                           "both %qs and %qs in declaration specifiers",
   12299              :                           "long", "_Decimal64");
   12300              :               else if (specs->typespec_word == cts_dfloat128)
   12301            4 :                 error_at (loc,
   12302              :                           "both %qs and %qs in declaration specifiers",
   12303              :                           "long", "_Decimal128");
   12304              :               else if (specs->typespec_word == cts_dfloat64x)
   12305            0 :                 error_at (loc,
   12306              :                           "both %qs and %qs in declaration specifiers",
   12307              :                           "long", "_Decimal64x");
   12308              :               else
   12309              :                 {
   12310      8213470 :                   specs->long_p = true;
   12311      8213470 :                   specs->locations[cdw_long] = loc;
   12312              :                 }
   12313              :               break;
   12314      1721071 :             case RID_SHORT:
   12315      1721071 :               dupe = specs->short_p;
   12316      1721071 :               if (specs->long_p)
   12317          197 :                 error_at (loc,
   12318              :                           "both %qs and %qs in declaration specifiers",
   12319              :                           "long", "short");
   12320      1720874 :               else if (specs->typespec_word == cts_auto_type)
   12321            1 :                 error_at (loc,
   12322              :                           "both %qs and %qs in declaration specifiers",
   12323              :                           "short", "__auto_type");
   12324              :               else if (specs->typespec_word == cts_void)
   12325            5 :                 error_at (loc,
   12326              :                           "both %qs and %qs in declaration specifiers",
   12327              :                           "short", "void");
   12328              :               else if (specs->typespec_word == cts_int_n)
   12329           19 :                 error_at (loc,
   12330              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12331           19 :                           "short", int_n_data[specs->u.int_n_idx].bitsize);
   12332              :               else if (specs->typespec_word == cts_bool)
   12333            3 :                 error_at (loc,
   12334              :                           "both %qs and %qs in declaration specifiers",
   12335              :                           "short", "_Bool");
   12336              :               else if (specs->typespec_word == cts_bitint)
   12337            1 :                 error_at (loc,
   12338              :                           "both %qs and %qs in declaration specifiers",
   12339              :                           "short", "_BitInt");
   12340              :               else if (specs->typespec_word == cts_char)
   12341           21 :                 error_at (loc,
   12342              :                           "both %qs and %qs in declaration specifiers",
   12343              :                           "short", "char");
   12344              :               else if (specs->typespec_word == cts_float)
   12345            7 :                 error_at (loc,
   12346              :                           "both %qs and %qs in declaration specifiers",
   12347              :                           "short", "float");
   12348              :               else if (specs->typespec_word == cts_double)
   12349            7 :                 error_at (loc,
   12350              :                           "both %qs and %qs in declaration specifiers",
   12351              :                           "short", "double");
   12352              :               else if (specs->typespec_word == cts_floatn_nx)
   12353            0 :                 error_at (loc,
   12354              :                           "both %qs and %<_Float%d%s%> in declaration "
   12355              :                           "specifiers", "short",
   12356            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12357            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12358              :                           ? "x"
   12359              :                           : "");
   12360              :               else if (specs->typespec_word == cts_dfloat32)
   12361            4 :                 error_at (loc,
   12362              :                           "both %qs and %qs in declaration specifiers",
   12363              :                           "short", "_Decimal32");
   12364              :               else if (specs->typespec_word == cts_dfloat64)
   12365            4 :                 error_at (loc,
   12366              :                           "both %qs and %qs in declaration specifiers",
   12367              :                           "short", "_Decimal64");
   12368              :               else if (specs->typespec_word == cts_dfloat128)
   12369            4 :                 error_at (loc,
   12370              :                           "both %qs and %qs in declaration specifiers",
   12371              :                           "short", "_Decimal128");
   12372              :               else if (specs->typespec_word == cts_dfloat64x)
   12373            0 :                 error_at (loc,
   12374              :                           "both %qs and %qs in declaration specifiers",
   12375              :                           "short", "_Decimal64x");
   12376              :               else
   12377              :                 {
   12378      1720798 :                   specs->short_p = true;
   12379      1720798 :                   specs->locations[cdw_short] = loc;
   12380              :                 }
   12381              :               break;
   12382       556513 :             case RID_SIGNED:
   12383       556513 :               dupe = specs->signed_p;
   12384       556513 :               if (specs->unsigned_p)
   12385          138 :                 error_at (loc,
   12386              :                           "both %qs and %qs in declaration specifiers",
   12387              :                           "signed", "unsigned");
   12388       556375 :               else if (specs->typespec_word == cts_auto_type)
   12389            1 :                 error_at (loc,
   12390              :                           "both %qs and %qs in declaration specifiers",
   12391              :                           "signed", "__auto_type");
   12392              :               else if (specs->typespec_word == cts_void)
   12393            5 :                 error_at (loc,
   12394              :                           "both %qs and %qs in declaration specifiers",
   12395              :                           "signed", "void");
   12396              :               else if (specs->typespec_word == cts_bool)
   12397            3 :                 error_at (loc,
   12398              :                           "both %qs and %qs in declaration specifiers",
   12399              :                           "signed", "_Bool");
   12400              :               else if (specs->typespec_word == cts_float)
   12401            7 :                 error_at (loc,
   12402              :                           "both %qs and %qs in declaration specifiers",
   12403              :                           "signed", "float");
   12404              :               else if (specs->typespec_word == cts_double)
   12405           21 :                 error_at (loc,
   12406              :                           "both %qs and %qs in declaration specifiers",
   12407              :                           "signed", "double");
   12408              :               else if (specs->typespec_word == cts_floatn_nx)
   12409            0 :                 error_at (loc,
   12410              :                           "both %qs and %<_Float%d%s%> in declaration "
   12411              :                           "specifiers", "signed",
   12412            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12413            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12414              :                           ? "x"
   12415              :                           : "");
   12416              :               else if (specs->typespec_word == cts_dfloat32)
   12417            4 :                 error_at (loc,
   12418              :                           "both %qs and %qs in declaration specifiers",
   12419              :                           "signed", "_Decimal32");
   12420              :               else if (specs->typespec_word == cts_dfloat64)
   12421            4 :                 error_at (loc,
   12422              :                           "both %qs and %qs in declaration specifiers",
   12423              :                           "signed", "_Decimal64");
   12424              :               else if (specs->typespec_word == cts_dfloat128)
   12425            4 :                 error_at (loc,
   12426              :                           "both %qs and %qs in declaration specifiers",
   12427              :                           "signed", "_Decimal128");
   12428              :               else if (specs->typespec_word == cts_dfloat64x)
   12429            0 :                 error_at (loc,
   12430              :                           "both %qs and %qs in declaration specifiers",
   12431              :                           "signed", "_Decimal64x");
   12432              :               else
   12433              :                 {
   12434       556326 :                   specs->signed_p = true;
   12435       556326 :                   specs->locations[cdw_signed] = loc;
   12436              :                 }
   12437              :               break;
   12438      6341922 :             case RID_UNSIGNED:
   12439      6341922 :               dupe = specs->unsigned_p;
   12440      6341922 :               if (specs->signed_p)
   12441          139 :                 error_at (loc,
   12442              :                           "both %qs and %qs in declaration specifiers",
   12443              :                           "signed", "unsigned");
   12444      6341783 :               else if (specs->typespec_word == cts_auto_type)
   12445            1 :                 error_at (loc,
   12446              :                           "both %qs and %qs in declaration specifiers",
   12447              :                           "unsigned", "__auto_type");
   12448              :               else if (specs->typespec_word == cts_void)
   12449            5 :                 error_at (loc,
   12450              :                           "both %qs and %qs in declaration specifiers",
   12451              :                           "unsigned", "void");
   12452              :               else if (specs->typespec_word == cts_bool)
   12453            3 :                 error_at (loc,
   12454              :                           "both %qs and %qs in declaration specifiers",
   12455              :                           "unsigned", "_Bool");
   12456              :               else if (specs->typespec_word == cts_float)
   12457            7 :                 error_at (loc,
   12458              :                           "both %qs and %qs in declaration specifiers",
   12459              :                           "unsigned", "float");
   12460              :               else if (specs->typespec_word == cts_double)
   12461           21 :                 error_at (loc,
   12462              :                           "both %qs and %qs in declaration specifiers",
   12463              :                           "unsigned", "double");
   12464              :               else if (specs->typespec_word == cts_floatn_nx)
   12465            0 :                 error_at (loc,
   12466              :                           "both %qs and %<_Float%d%s%> in declaration "
   12467              :                           "specifiers", "unsigned",
   12468            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12469            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12470              :                           ? "x"
   12471              :                           : "");
   12472              :               else if (specs->typespec_word == cts_dfloat32)
   12473            2 :                 error_at (loc,
   12474              :                           "both %qs and %qs in declaration specifiers",
   12475              :                           "unsigned", "_Decimal32");
   12476              :               else if (specs->typespec_word == cts_dfloat64)
   12477            2 :                 error_at (loc,
   12478              :                           "both %qs and %qs in declaration specifiers",
   12479              :                           "unsigned", "_Decimal64");
   12480              :               else if (specs->typespec_word == cts_dfloat128)
   12481            2 :                 error_at (loc,
   12482              :                           "both %qs and %qs in declaration specifiers",
   12483              :                           "unsigned", "_Decimal128");
   12484              :               else if (specs->typespec_word == cts_dfloat64x)
   12485            0 :                 error_at (loc,
   12486              :                           "both %qs and %qs in declaration specifiers",
   12487              :                           "unsigned", "_Decimal64x");
   12488              :               else
   12489              :                 {
   12490      6341740 :                   specs->unsigned_p = true;
   12491      6341740 :                   specs->locations[cdw_unsigned] = loc;
   12492              :                 }
   12493              :               break;
   12494      2582361 :             case RID_COMPLEX:
   12495      2582361 :               dupe = specs->complex_p;
   12496      2582361 :               if (!in_system_header_at (loc))
   12497        69917 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12498              :                              "ISO C90 does not support complex types");
   12499      2582361 :               if (specs->typespec_word == cts_auto_type)
   12500            1 :                 error_at (loc,
   12501              :                           "both %qs and %qs in declaration specifiers",
   12502              :                           "complex", "__auto_type");
   12503              :               else if (specs->typespec_word == cts_void)
   12504            2 :                 error_at (loc,
   12505              :                           "both %qs and %qs in declaration specifiers",
   12506              :                           "complex", "void");
   12507              :               else if (specs->typespec_word == cts_bool)
   12508            2 :                 error_at (loc,
   12509              :                           "both %qs and %qs in declaration specifiers",
   12510              :                           "complex", "_Bool");
   12511              :               else if (specs->typespec_word == cts_bitint)
   12512            1 :                 error_at (loc,
   12513              :                           "both %qs and %qs in declaration specifiers",
   12514              :                           "complex", "_BitInt");
   12515              :               else if (specs->typespec_word == cts_dfloat32)
   12516            1 :                 error_at (loc,
   12517              :                           "both %qs and %qs in declaration specifiers",
   12518              :                           "complex", "_Decimal32");
   12519              :               else if (specs->typespec_word == cts_dfloat64)
   12520            1 :                 error_at (loc,
   12521              :                           "both %qs and %qs in declaration specifiers",
   12522              :                           "complex", "_Decimal64");
   12523              :               else if (specs->typespec_word == cts_dfloat128)
   12524            1 :                 error_at (loc,
   12525              :                           "both %qs and %qs in declaration specifiers",
   12526              :                           "complex", "_Decimal128");
   12527              :               else if (specs->typespec_word == cts_dfloat64x)
   12528            0 :                 error_at (loc,
   12529              :                           "both %qs and %qs in declaration specifiers",
   12530              :                           "complex", "_Decimal64x");
   12531              :               else if (specs->typespec_word == cts_fract)
   12532            0 :                 error_at (loc,
   12533              :                           "both %qs and %qs in declaration specifiers",
   12534              :                           "complex", "_Fract");
   12535              :               else if (specs->typespec_word == cts_accum)
   12536            0 :                 error_at (loc,
   12537              :                           "both %qs and %qs in declaration specifiers",
   12538              :                           "complex", "_Accum");
   12539      2582352 :               else if (specs->saturating_p)
   12540            0 :                 error_at (loc,
   12541              :                           "both %qs and %qs in declaration specifiers",
   12542              :                           "complex", "_Sat");
   12543              :               else
   12544              :                 {
   12545      2582352 :                   specs->complex_p = true;
   12546      2582352 :                   specs->locations[cdw_complex] = loc;
   12547              :                 }
   12548              :               break;
   12549           61 :             case RID_SAT:
   12550           61 :               dupe = specs->saturating_p;
   12551           61 :               pedwarn (loc, OPT_Wpedantic,
   12552              :                        "ISO C does not support saturating types");
   12553           61 :               if (specs->typespec_word == cts_int_n)
   12554            0 :                 error_at (loc,
   12555              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12556            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12557              :               else if (specs->typespec_word == cts_auto_type)
   12558            0 :                 error_at (loc,
   12559              :                           "both %qs and %qs in declaration specifiers",
   12560              :                           "_Sat", "__auto_type");
   12561              :               else if (specs->typespec_word == cts_void)
   12562            0 :                 error_at (loc,
   12563              :                           "both %qs and %qs in declaration specifiers",
   12564              :                           "_Sat", "void");
   12565              :               else if (specs->typespec_word == cts_bool)
   12566            0 :                 error_at (loc,
   12567              :                           "both %qs and %qs in declaration specifiers",
   12568              :                           "_Sat", "_Bool");
   12569              :               else if (specs->typespec_word == cts_bitint)
   12570            0 :                 error_at (loc,
   12571              :                           "both %qs and %qs in declaration specifiers",
   12572              :                           "_Sat", "_BitInt");
   12573              :               else if (specs->typespec_word == cts_char)
   12574            0 :                 error_at (loc,
   12575              :                           "both %qs and %qs in declaration specifiers",
   12576              :                           "_Sat", "char");
   12577              :               else if (specs->typespec_word == cts_int)
   12578            0 :                 error_at (loc,
   12579              :                           "both %qs and %qs in declaration specifiers",
   12580              :                           "_Sat", "int");
   12581              :               else if (specs->typespec_word == cts_float)
   12582            0 :                 error_at (loc,
   12583              :                           "both %qs and %qs in declaration specifiers",
   12584              :                           "_Sat", "float");
   12585              :               else if (specs->typespec_word == cts_double)
   12586            0 :                 error_at (loc,
   12587              :                           "both %qs and %qs in declaration specifiers",
   12588              :                           "_Sat", "double");
   12589              :               else if (specs->typespec_word == cts_floatn_nx)
   12590            0 :                 error_at (loc,
   12591              :                           "both %qs and %<_Float%d%s%> in declaration "
   12592              :                           "specifiers", "_Sat",
   12593            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12594            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12595              :                           ? "x"
   12596              :                           : "");
   12597              :               else if (specs->typespec_word == cts_dfloat32)
   12598            0 :                 error_at (loc,
   12599              :                           "both %qs and %qs in declaration specifiers",
   12600              :                           "_Sat", "_Decimal32");
   12601              :               else if (specs->typespec_word == cts_dfloat64)
   12602            0 :                 error_at (loc,
   12603              :                           "both %qs and %qs in declaration specifiers",
   12604              :                           "_Sat", "_Decimal64");
   12605              :               else if (specs->typespec_word == cts_dfloat128)
   12606            0 :                 error_at (loc,
   12607              :                           "both %qs and %qs in declaration specifiers",
   12608              :                           "_Sat", "_Decimal128");
   12609              :               else if (specs->typespec_word == cts_dfloat64x)
   12610            0 :                 error_at (loc,
   12611              :                           "both %qs and %qs in declaration specifiers",
   12612              :                           "_Sat", "_Decimal64x");
   12613           61 :               else if (specs->complex_p)
   12614            0 :                 error_at (loc,
   12615              :                           "both %qs and %qs in declaration specifiers",
   12616              :                           "_Sat", "complex");
   12617              :               else
   12618              :                 {
   12619           61 :                   specs->saturating_p = true;
   12620           61 :                   specs->locations[cdw_saturating] = loc;
   12621              :                 }
   12622              :               break;
   12623            0 :             default:
   12624            0 :               gcc_unreachable ();
   12625              :             }
   12626              : 
   12627     22455737 :           if (dupe)
   12628          378 :             error_at (loc, "duplicate %qE", type);
   12629              : 
   12630              :           return specs;
   12631              :         }
   12632              :       else
   12633              :         {
   12634              :           /* "void", "_Bool", "char", "int", "float", "double",
   12635              :              "_FloatN", "_FloatNx", "_Decimal32", "__intN",
   12636              :              "_Decimal64", "_Decimal128", "_Fract", "_Accum", "_BitInt(N)" or
   12637              :              "__auto_type".  */
   12638     63386671 :           if (specs->typespec_word != cts_none)
   12639              :             {
   12640         2171 :               if (i == RID_BOOL)
   12641              :                 {
   12642          175 :                   auto_diagnostic_group d;
   12643          175 :                   if (specs->storage_class == csc_typedef)
   12644            4 :                     error_at (loc,
   12645              :                               "%qs cannot be defined via %<typedef%>",
   12646            2 :                               IDENTIFIER_POINTER (type));
   12647              :                   else
   12648          346 :                     error_at (loc,
   12649              :                               "%qs cannot be used here",
   12650          173 :                               IDENTIFIER_POINTER (type));
   12651          175 :                   add_note_about_new_keyword (loc, type);
   12652          175 :                 }
   12653              :               else
   12654         1996 :                 error_at (loc,
   12655              :                           "two or more data types in declaration specifiers");
   12656              :               return specs;
   12657              :             }
   12658     63384500 :           switch (i)
   12659              :             {
   12660         1897 :             case RID_AUTO_TYPE:
   12661         1897 :               if (specs->long_p)
   12662            1 :                 error_at (loc,
   12663              :                           "both %qs and %qs in declaration specifiers",
   12664              :                           "long", "__auto_type");
   12665         1896 :               else if (specs->short_p)
   12666            1 :                 error_at (loc,
   12667              :                           "both %qs and %qs in declaration specifiers",
   12668              :                           "short", "__auto_type");
   12669         1895 :               else if (specs->signed_p)
   12670            1 :                 error_at (loc,
   12671              :                           "both %qs and %qs in declaration specifiers",
   12672              :                           "signed", "__auto_type");
   12673         1894 :               else if (specs->unsigned_p)
   12674            1 :                 error_at (loc,
   12675              :                           "both %qs and %qs in declaration specifiers",
   12676              :                           "unsigned", "__auto_type");
   12677         1893 :               else if (specs->complex_p)
   12678            1 :                 error_at (loc,
   12679              :                           "both %qs and %qs in declaration specifiers",
   12680              :                           "complex", "__auto_type");
   12681         1892 :               else if (specs->saturating_p)
   12682            0 :                 error_at (loc,
   12683              :                           "both %qs and %qs in declaration specifiers",
   12684              :                           "_Sat", "__auto_type");
   12685              :               else
   12686              :                 {
   12687         1892 :                   specs->typespec_word = cts_auto_type;
   12688         1892 :                   specs->locations[cdw_typespec] = loc;
   12689              :                 }
   12690              :               return specs;
   12691        52137 :             case RID_INT_N_0:
   12692        52137 :             case RID_INT_N_1:
   12693        52137 :             case RID_INT_N_2:
   12694        52137 :             case RID_INT_N_3:
   12695        52137 :               specs->u.int_n_idx = i - RID_INT_N_0;
   12696        52137 :               if (!in_system_header_at (input_location)
   12697              :                   /* If the INT_N type ends in "__", and so is of the format
   12698              :                      "__intN__", don't pedwarn.  */
   12699        52137 :                   && (strncmp (IDENTIFIER_POINTER (type)
   12700        41391 :                                + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0))
   12701        41391 :                 pedwarn (loc, OPT_Wpedantic,
   12702              :                          "ISO C does not support %<__int%d%> types",
   12703        41391 :                          int_n_data[specs->u.int_n_idx].bitsize);
   12704              : 
   12705        52137 :               if (specs->long_p)
   12706           53 :                 error_at (loc,
   12707              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12708           53 :                           int_n_data[specs->u.int_n_idx].bitsize, "long");
   12709        52084 :               else if (specs->saturating_p)
   12710            0 :                 error_at (loc,
   12711              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12712            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12713        52084 :               else if (specs->short_p)
   12714           19 :                 error_at (loc,
   12715              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12716           19 :                           int_n_data[specs->u.int_n_idx].bitsize, "short");
   12717        52065 :               else if (! int_n_enabled_p[specs->u.int_n_idx])
   12718              :                 {
   12719            0 :                   specs->typespec_word = cts_int_n;
   12720            0 :                   error_at (loc,
   12721              :                             "%<__int%d%> is not supported on this target",
   12722            0 :                             int_n_data[specs->u.int_n_idx].bitsize);
   12723              :                 }
   12724              :               else
   12725              :                 {
   12726        52065 :                   specs->typespec_word = cts_int_n;
   12727        52065 :                   specs->locations[cdw_typespec] = loc;
   12728              :                 }
   12729              :               return specs;
   12730      8265836 :             case RID_VOID:
   12731      8265836 :               if (specs->long_p)
   12732           44 :                 error_at (loc,
   12733              :                           "both %qs and %qs in declaration specifiers",
   12734              :                           "long", "void");
   12735      8265792 :               else if (specs->short_p)
   12736           21 :                 error_at (loc,
   12737              :                           "both %qs and %qs in declaration specifiers",
   12738              :                           "short", "void");
   12739      8265771 :               else if (specs->signed_p)
   12740            5 :                 error_at (loc,
   12741              :                           "both %qs and %qs in declaration specifiers",
   12742              :                           "signed", "void");
   12743      8265766 :               else if (specs->unsigned_p)
   12744            5 :                 error_at (loc,
   12745              :                           "both %qs and %qs in declaration specifiers",
   12746              :                           "unsigned", "void");
   12747      8265761 :               else if (specs->complex_p)
   12748            2 :                 error_at (loc,
   12749              :                           "both %qs and %qs in declaration specifiers",
   12750              :                           "complex", "void");
   12751      8265759 :               else if (specs->saturating_p)
   12752            0 :                 error_at (loc,
   12753              :                           "both %qs and %qs in declaration specifiers",
   12754              :                           "_Sat", "void");
   12755              :               else
   12756              :                 {
   12757      8265759 :                   specs->typespec_word = cts_void;
   12758      8265759 :                   specs->locations[cdw_typespec] = loc;
   12759              :                 }
   12760              :               return specs;
   12761        95269 :             case RID_BOOL:
   12762        95269 :               if (!in_system_header_at (loc))
   12763        76998 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12764              :                              "ISO C90 does not support boolean types");
   12765        95269 :               if (specs->long_p)
   12766           27 :                 error_at (loc,
   12767              :                           "both %qs and %qs in declaration specifiers",
   12768              :                           "long", "_Bool");
   12769        95242 :               else if (specs->short_p)
   12770           11 :                 error_at (loc,
   12771              :                           "both %qs and %qs in declaration specifiers",
   12772              :                           "short", "_Bool");
   12773        95231 :               else if (specs->signed_p)
   12774            3 :                 error_at (loc,
   12775              :                           "both %qs and %qs in declaration specifiers",
   12776              :                           "signed", "_Bool");
   12777        95228 :               else if (specs->unsigned_p)
   12778            3 :                 error_at (loc,
   12779              :                           "both %qs and %qs in declaration specifiers",
   12780              :                           "unsigned", "_Bool");
   12781        95225 :               else if (specs->complex_p)
   12782            2 :                 error_at (loc,
   12783              :                           "both %qs and %qs in declaration specifiers",
   12784              :                           "complex", "_Bool");
   12785        95223 :               else if (specs->saturating_p)
   12786            0 :                 error_at (loc,
   12787              :                           "both %qs and %qs in declaration specifiers",
   12788              :                           "_Sat", "_Bool");
   12789              :               else
   12790              :                 {
   12791        95223 :                   specs->typespec_word = cts_bool;
   12792        95223 :                   specs->locations[cdw_typespec] = loc;
   12793              :                 }
   12794              :               return specs;
   12795      9299181 :             case RID_CHAR:
   12796      9299181 :               if (specs->long_p)
   12797           44 :                 error_at (loc,
   12798              :                           "both %qs and %qs in declaration specifiers",
   12799              :                           "long", "char");
   12800      9299137 :               else if (specs->short_p)
   12801           21 :                 error_at (loc,
   12802              :                           "both %qs and %qs in declaration specifiers",
   12803              :                           "short", "char");
   12804      9299116 :               else if (specs->saturating_p)
   12805            0 :                 error_at (loc,
   12806              :                           "both %qs and %qs in declaration specifiers",
   12807              :                           "_Sat", "char");
   12808              :               else
   12809              :                 {
   12810      9299116 :                   specs->typespec_word = cts_char;
   12811      9299116 :                   specs->locations[cdw_typespec] = loc;
   12812              :                 }
   12813              :               return specs;
   12814     24656763 :             case RID_INT:
   12815     24656763 :               if (specs->saturating_p)
   12816            0 :                 error_at (loc,
   12817              :                           "both %qs and %qs in declaration specifiers",
   12818              :                           "_Sat", "int");
   12819              :               else
   12820              :                 {
   12821     24656763 :                   specs->typespec_word = cts_int;
   12822     24656763 :                   specs->locations[cdw_typespec] = loc;
   12823              :                 }
   12824              :               return specs;
   12825      3675885 :             case RID_FLOAT:
   12826      3675885 :               if (specs->long_p)
   12827           44 :                 error_at (loc,
   12828              :                           "both %qs and %qs in declaration specifiers",
   12829              :                           "long", "float");
   12830      3675841 :               else if (specs->short_p)
   12831           21 :                 error_at (loc,
   12832              :                           "both %qs and %qs in declaration specifiers",
   12833              :                           "short", "float");
   12834      3675820 :               else if (specs->signed_p)
   12835            5 :                 error_at (loc,
   12836              :                           "both %qs and %qs in declaration specifiers",
   12837              :                           "signed", "float");
   12838      3675815 :               else if (specs->unsigned_p)
   12839            5 :                 error_at (loc,
   12840              :                           "both %qs and %qs in declaration specifiers",
   12841              :                           "unsigned", "float");
   12842      3675810 :               else if (specs->saturating_p)
   12843            0 :                 error_at (loc,
   12844              :                           "both %qs and %qs in declaration specifiers",
   12845              :                           "_Sat", "float");
   12846              :               else
   12847              :                 {
   12848      3675810 :                   specs->typespec_word = cts_float;
   12849      3675810 :                   specs->locations[cdw_typespec] = loc;
   12850              :                 }
   12851              :               return specs;
   12852      6689284 :             case RID_DOUBLE:
   12853      6689284 :               if (specs->long_long_p)
   12854           22 :                 error_at (loc,
   12855              :                           "both %qs and %qs in declaration specifiers",
   12856              :                           "long long", "double");
   12857      6689262 :               else if (specs->short_p)
   12858           21 :                 error_at (loc,
   12859              :                           "both %qs and %qs in declaration specifiers",
   12860              :                           "short", "double");
   12861      6689241 :               else if (specs->signed_p)
   12862           13 :                 error_at (loc,
   12863              :                           "both %qs and %qs in declaration specifiers",
   12864              :                           "signed", "double");
   12865      6689228 :               else if (specs->unsigned_p)
   12866           13 :                 error_at (loc,
   12867              :                           "both %qs and %qs in declaration specifiers",
   12868              :                           "unsigned", "double");
   12869      6689215 :               else if (specs->saturating_p)
   12870            0 :                 error_at (loc,
   12871              :                           "both %qs and %qs in declaration specifiers",
   12872              :                           "_Sat", "double");
   12873              :               else
   12874              :                 {
   12875      6689215 :                   specs->typespec_word = cts_double;
   12876      6689215 :                   specs->locations[cdw_typespec] = loc;
   12877              :                 }
   12878              :               return specs;
   12879     10552377 :             CASE_RID_FLOATN_NX:
   12880     10552377 :               specs->u.floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
   12881     10552377 :               if (!in_system_header_at (input_location))
   12882        53967 :                 pedwarn_c11 (loc, OPT_Wpedantic,
   12883              :                              "ISO C does not support the %<_Float%d%s%> type"
   12884              :                              " before C23",
   12885        53967 :                              floatn_nx_types[specs->u.floatn_nx_idx].n,
   12886        53967 :                              floatn_nx_types[specs->u.floatn_nx_idx].extended
   12887              :                              ? "x"
   12888              :                              : "");
   12889              : 
   12890     10552377 :               if (specs->long_p)
   12891            0 :                 error_at (loc,
   12892              :                           "both %qs and %<_Float%d%s%> in declaration "
   12893              :                           "specifiers", "long",
   12894            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12895            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12896              :                           ? "x"
   12897              :                           : "");
   12898     10552377 :               else if (specs->short_p)
   12899            0 :                 error_at (loc,
   12900              :                           "both %qs and %<_Float%d%s%> in declaration "
   12901              :                           "specifiers", "short",
   12902            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12903            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12904              :                           ? "x"
   12905              :                           : "");
   12906     10552377 :               else if (specs->signed_p)
   12907            0 :                 error_at (loc,
   12908              :                           "both %qs and %<_Float%d%s%> in declaration "
   12909              :                           "specifiers", "signed",
   12910            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12911            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12912              :                           ? "x"
   12913              :                           : "");
   12914     10552377 :               else if (specs->unsigned_p)
   12915            0 :                 error_at (loc,
   12916              :                           "both %qs and %<_Float%d%s%> in declaration "
   12917              :                           "specifiers", "unsigned",
   12918            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12919            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12920              :                           ? "x"
   12921              :                           : "");
   12922     10552377 :               else if (specs->saturating_p)
   12923            0 :                 error_at (loc,
   12924              :                           "both %qs and %<_Float%d%s%> in declaration "
   12925              :                           "specifiers", "_Sat",
   12926            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12927            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12928              :                           ? "x"
   12929              :                           : "");
   12930     10552377 :               else if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   12931              :                 {
   12932           88 :                   specs->typespec_word = cts_floatn_nx;
   12933          176 :                   error_at (loc,
   12934              :                             "%<_Float%d%s%> is not supported on this target",
   12935           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].n,
   12936           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].extended
   12937              :                             ? "x"
   12938              :                             : "");
   12939              :                 }
   12940              :               else
   12941              :                 {
   12942     10552289 :                   specs->typespec_word = cts_floatn_nx;
   12943     10552289 :                   specs->locations[cdw_typespec] = loc;
   12944              :                 }
   12945              :               return specs;
   12946        47644 :             case RID_DFLOAT32:
   12947        47644 :             case RID_DFLOAT64:
   12948        47644 :             case RID_DFLOAT128:
   12949        47644 :             case RID_DFLOAT64X:
   12950        47644 :               {
   12951        47644 :                 const char *str;
   12952        47644 :                 if (i == RID_DFLOAT32)
   12953              :                   str = "_Decimal32";
   12954              :                 else if (i == RID_DFLOAT64)
   12955              :                   str = "_Decimal64";
   12956              :                 else if (i == RID_DFLOAT128)
   12957              :                   str = "_Decimal128";
   12958              :                 else
   12959        47644 :                   str = "_Decimal64x";
   12960        47644 :                 if (specs->long_long_p)
   12961           18 :                   error_at (loc,
   12962              :                             "both %qs and %qs in declaration specifiers",
   12963              :                             "long long", str);
   12964        47644 :                 if (specs->long_p)
   12965           33 :                   error_at (loc,
   12966              :                             "both %qs and %qs in declaration specifiers",
   12967              :                             "long", str);
   12968        47611 :                 else if (specs->short_p)
   12969           18 :                   error_at (loc,
   12970              :                             "both %qs and %qs in declaration specifiers",
   12971              :                             "short", str);
   12972        47593 :                 else if (specs->signed_p)
   12973            6 :                   error_at (loc,
   12974              :                             "both %qs and %qs in declaration specifiers",
   12975              :                             "signed", str);
   12976        47587 :                 else if (specs->unsigned_p)
   12977            3 :                   error_at (loc,
   12978              :                             "both %qs and %qs in declaration specifiers",
   12979              :                             "unsigned", str);
   12980        47584 :                 else if (specs->complex_p)
   12981            3 :                   error_at (loc,
   12982              :                             "both %qs and %qs in declaration specifiers",
   12983              :                             "complex", str);
   12984        47581 :                 else if (specs->saturating_p)
   12985            0 :                   error_at (loc,
   12986              :                             "both %qs and %qs in declaration specifiers",
   12987              :                             "_Sat", str);
   12988        47581 :                 else if (i == RID_DFLOAT32)
   12989        15961 :                   specs->typespec_word = cts_dfloat32;
   12990        31620 :                 else if (i == RID_DFLOAT64)
   12991        15839 :                   specs->typespec_word = cts_dfloat64;
   12992        15781 :                 else if (i == RID_DFLOAT128)
   12993        15734 :                   specs->typespec_word = cts_dfloat128;
   12994              :                 else
   12995           47 :                   specs->typespec_word = cts_dfloat64x;
   12996        47644 :                 specs->locations[cdw_typespec] = loc;
   12997              :               }
   12998        47644 :               if (!targetm.decimal_float_supported_p ())
   12999            0 :                 error_at (loc,
   13000              :                           "decimal floating-point not supported "
   13001              :                           "for this target");
   13002        47644 :               pedwarn_c11 (loc, OPT_Wpedantic,
   13003              :                            "ISO C does not support decimal floating-point "
   13004              :                            "before C23");
   13005        47644 :               return specs;
   13006           63 :             case RID_FRACT:
   13007           63 :             case RID_ACCUM:
   13008           63 :               {
   13009           63 :                 const char *str;
   13010           63 :                 if (i == RID_FRACT)
   13011              :                   str = "_Fract";
   13012              :                 else
   13013           31 :                   str = "_Accum";
   13014           63 :                 if (specs->complex_p)
   13015            0 :                   error_at (loc,
   13016              :                             "both %qs and %qs in declaration specifiers",
   13017              :                             "complex", str);
   13018           63 :                 else if (i == RID_FRACT)
   13019           32 :                     specs->typespec_word = cts_fract;
   13020              :                 else
   13021           31 :                     specs->typespec_word = cts_accum;
   13022           63 :                 specs->locations[cdw_typespec] = loc;
   13023              :               }
   13024           63 :               if (!targetm.fixed_point_supported_p ())
   13025           63 :                 error_at (loc,
   13026              :                           "fixed-point types not supported for this target");
   13027           63 :               pedwarn (loc, OPT_Wpedantic,
   13028              :                        "ISO C does not support fixed-point types");
   13029           63 :               return specs;
   13030        48164 :             case RID_BITINT:
   13031        48164 :               if (specs->long_p)
   13032            2 :                 error_at (loc,
   13033              :                           "both %qs and %qs in declaration specifiers",
   13034              :                           "long", "_BitInt");
   13035        48162 :               else if (specs->short_p)
   13036            1 :                 error_at (loc,
   13037              :                           "both %qs and %qs in declaration specifiers",
   13038              :                           "short", "_BitInt");
   13039        48161 :               else if (specs->complex_p)
   13040            1 :                 error_at (loc,
   13041              :                           "both %qs and %qs in declaration specifiers",
   13042              :                           "complex", "_BitInt");
   13043        48160 :               else if (specs->saturating_p)
   13044            0 :                 error_at (loc,
   13045              :                           "both %qs and %qs in declaration specifiers",
   13046              :                           "_Sat", "_BitInt");
   13047              :               else
   13048              :                 {
   13049        48160 :                   specs->typespec_word = cts_bitint;
   13050        48160 :                   specs->locations[cdw_typespec] = loc;
   13051        48160 :                   specs->u.bitint_prec = -1;
   13052        48160 :                   if (error_operand_p (spec.expr))
   13053            7 :                     return specs;
   13054        48160 :                   if (TREE_CODE (spec.expr) != INTEGER_CST
   13055        48160 :                       || !INTEGRAL_TYPE_P (TREE_TYPE (spec.expr)))
   13056              :                     {
   13057            1 :                       error_at (loc, "%<_BitInt%> argument is not an integer "
   13058              :                                      "constant expression");
   13059            1 :                       return specs;
   13060              :                     }
   13061        48159 :                   if (tree_int_cst_sgn (spec.expr) <= 0)
   13062              :                     {
   13063            4 :                       error_at (loc, "%<_BitInt%> argument %qE is not a "
   13064              :                                      "positive integer constant expression",
   13065              :                                 spec.expr);
   13066            4 :                       return specs;
   13067              :                     }
   13068        48155 :                   if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1)
   13069              :                     {
   13070            2 :                       error_at (loc, "%<_BitInt%> argument %qE is larger than "
   13071              :                                      "%<BITINT_MAXWIDTH%> %qd",
   13072              :                                 spec.expr, (int) WIDE_INT_MAX_PRECISION - 1);
   13073            2 :                       return specs;
   13074              :                     }
   13075        48153 :                   specs->u.bitint_prec = tree_to_uhwi (spec.expr);
   13076        48153 :                   struct bitint_info info;
   13077        48153 :                   if (!targetm.c.bitint_type_info (specs->u.bitint_prec,
   13078              :                                                    &info))
   13079              :                     {
   13080            0 :                       sorry_at (loc, "%<_BitInt(%d)%> is not supported on "
   13081              :                                      "this target", specs->u.bitint_prec);
   13082            0 :                       specs->u.bitint_prec = -1;
   13083            0 :                       return specs;
   13084              :                     }
   13085              :                 }
   13086              :               return specs;
   13087              :             default:
   13088              :               /* ObjC reserved word "id", handled below.  */
   13089              :               break;
   13090              :             }
   13091              :         }
   13092              :     }
   13093              : 
   13094              :   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
   13095              :      form of ObjC type, cases such as "int" and "long" being handled
   13096              :      above), a TYPE (struct, union, enum and typeof specifiers) or an
   13097              :      ERROR_MARK.  In none of these cases may there have previously
   13098              :      been any type specifiers.  */
   13099    257940468 :   if (specs->type || specs->typespec_word != cts_none
   13100    257940456 :       || specs->long_p || specs->short_p || specs->signed_p
   13101    257940453 :       || specs->unsigned_p || specs->complex_p)
   13102           21 :     error_at (loc, "two or more data types in declaration specifiers");
   13103    257940447 :   else if (TREE_CODE (type) == TYPE_DECL)
   13104              :     {
   13105    254619154 :       specs->type = TREE_TYPE (type);
   13106    254619154 :       if (TREE_TYPE (type) != error_mark_node)
   13107              :         {
   13108    254619139 :           mark_decl_used (type, false);
   13109    254619139 :           specs->decl_attr = DECL_ATTRIBUTES (type);
   13110    254619139 :           specs->typedef_p = true;
   13111    254619139 :           specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
   13112    254619139 :           specs->locations[cdw_typedef] = loc;
   13113              : 
   13114              :           /* If this typedef name is defined in a struct, then a C++
   13115              :              lookup would return a different value.  */
   13116    254619139 :           if (warn_cxx_compat
   13117    254619139 :               && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
   13118            2 :             warning_at (loc, OPT_Wc___compat,
   13119              :                         "C++ lookup of %qD would return a field, not a type",
   13120              :                         type);
   13121              : 
   13122              :           /* If we are parsing a struct, record that a struct field
   13123              :              used a typedef.  */
   13124    254619139 :           if (warn_cxx_compat && struct_parse_info != NULL)
   13125         1766 :             struct_parse_info->typedefs_seen.safe_push (type);
   13126              :         }
   13127              :     }
   13128      3321293 :   else if (TREE_CODE (type) == IDENTIFIER_NODE)
   13129              :     {
   13130            0 :       tree t = lookup_name (type);
   13131            0 :       if (!t || TREE_CODE (t) != TYPE_DECL)
   13132            0 :         error_at (loc, "%qE fails to be a typedef or built in type", type);
   13133            0 :       else if (TREE_TYPE (t) == error_mark_node)
   13134              :         ;
   13135              :       else
   13136              :         {
   13137            0 :           specs->type = TREE_TYPE (t);
   13138            0 :           specs->locations[cdw_typespec] = loc;
   13139              :         }
   13140              :     }
   13141              :   else
   13142              :     {
   13143      3321293 :       if (TREE_CODE (type) != ERROR_MARK)
   13144              :         {
   13145      3321094 :           if (spec.kind == ctsk_typeof)
   13146              :             {
   13147       835607 :               specs->typedef_p = true;
   13148       835607 :               specs->locations[cdw_typedef] = loc;
   13149              :             }
   13150              : 
   13151      3321094 :           if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
   13152      1075271 :               || TREE_CODE (type) == ENUMERAL_TYPE)
   13153      2494094 :             mark_decl_used (TYPE_STUB_DECL (type), false);
   13154              : 
   13155      3321094 :           if (spec.expr)
   13156              :             {
   13157          958 :               tree expr = save_expr (fold_convert (void_type_node, spec.expr));
   13158          958 :               if (specs->expr)
   13159            0 :                 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
   13160              :                                       specs->expr, expr);
   13161              :               else
   13162              :                 specs->expr = expr;
   13163          958 :               specs->expr_const_operands &= spec.expr_const_operands;
   13164              :             }
   13165              :         }
   13166      3321293 :       specs->type = type;
   13167      3321293 :       if (spec.has_enum_type_specifier
   13168          194 :           && spec.kind != ctsk_tagdef)
   13169           49 :         specs->enum_type_specifier_ref_p = true;
   13170              :     }
   13171              : 
   13172              :   return specs;
   13173              : }
   13174              : 
   13175              : /* Add the storage class specifier or function specifier SCSPEC to the
   13176              :    declaration specifiers SPECS, returning SPECS.  */
   13177              : 
   13178              : struct c_declspecs *
   13179     93778228 : declspecs_add_scspec (location_t loc,
   13180              :                       struct c_declspecs *specs,
   13181              :                       tree scspec)
   13182              : {
   13183     93778228 :   enum rid i;
   13184     93778228 :   enum c_storage_class n = csc_none;
   13185     93778228 :   bool dupe = false;
   13186     93778228 :   specs->declspecs_seen_p = true;
   13187     93778228 :   specs->non_std_attrs_seen_p = true;
   13188     93778228 :   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
   13189              :               && C_IS_RESERVED_WORD (scspec));
   13190     93778228 :   i = C_RID_CODE (scspec);
   13191     93778228 :   if (specs->non_sc_seen_p)
   13192         2152 :     warning (OPT_Wold_style_declaration,
   13193              :              "%qE is not at beginning of declaration", scspec);
   13194     93778228 :   switch (i)
   13195              :     {
   13196     36965313 :     case RID_INLINE:
   13197              :       /* C99 permits duplicate inline.  Although of doubtful utility,
   13198              :          it seems simplest to permit it in gnu89 mode as well, as
   13199              :          there is also little utility in maintaining this as a
   13200              :          difference between gnu89 and C99 inline.  */
   13201     36965313 :       dupe = false;
   13202     36965313 :       specs->inline_p = true;
   13203     36965313 :       specs->locations[cdw_inline] = loc;
   13204     36965313 :       break;
   13205        23317 :     case RID_NORETURN:
   13206              :       /* Duplicate _Noreturn is permitted.  */
   13207        23317 :       dupe = false;
   13208        23317 :       specs->noreturn_p = true;
   13209        23317 :       specs->locations[cdw_noreturn] = loc;
   13210        23317 :       break;
   13211         2894 :     case RID_THREAD:
   13212         2894 :       dupe = specs->thread_p;
   13213         2894 :       if (specs->storage_class == csc_auto)
   13214            2 :         error ("%qE used with %<auto%>", scspec);
   13215         2892 :       else if (specs->storage_class == csc_register)
   13216            3 :         error ("%qE used with %<register%>", scspec);
   13217         2889 :       else if (specs->storage_class == csc_typedef)
   13218            2 :         error ("%qE used with %<typedef%>", scspec);
   13219         2887 :       else if (specs->constexpr_p)
   13220            2 :         error ("%qE used with %<constexpr%>", scspec);
   13221              :       else
   13222              :         {
   13223         2885 :           specs->thread_p = true;
   13224         2885 :           specs->thread_gnu_p = (strcmp (IDENTIFIER_POINTER (scspec),
   13225         2885 :                                          "__thread") == 0);
   13226              :           /* A diagnostic is not required for the use of this
   13227              :              identifier in the implementation namespace; only diagnose
   13228              :              it for the C11 spelling because of existing code using
   13229              :              the other spelling.  */
   13230         2885 :           if (!specs->thread_gnu_p)
   13231              :             {
   13232          116 :               if (flag_isoc99)
   13233          113 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13234              :                              "ISO C99 does not support %qE", scspec);
   13235              :               else
   13236            3 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13237              :                              "ISO C90 does not support %qE", scspec);
   13238              :             }
   13239         2885 :           specs->locations[cdw_thread] = loc;
   13240              :         }
   13241              :       break;
   13242          264 :     case RID_AUTO:
   13243          264 :       if (flag_isoc23
   13244          225 :           && specs->typespec_kind == ctsk_none
   13245          214 :           && specs->storage_class != csc_typedef)
   13246              :         {
   13247              :           /* "auto" potentially used for type deduction.  */
   13248          213 :           if (specs->c23_auto_p)
   13249            2 :             error ("duplicate %qE", scspec);
   13250          213 :           specs->c23_auto_p = true;
   13251          213 :           return specs;
   13252              :         }
   13253           51 :       n = csc_auto;
   13254              :       /* auto may only be used with another storage class specifier,
   13255              :          such as constexpr, if the type is inferred.  */
   13256           51 :       if (specs->constexpr_p)
   13257            2 :         error ("%qE used with %<constexpr%>", scspec);
   13258              :       break;
   13259     51972229 :     case RID_EXTERN:
   13260     51972229 :       n = csc_extern;
   13261              :       /* Diagnose "__thread extern".  */
   13262     51972229 :       if (specs->thread_p && specs->thread_gnu_p)
   13263            2 :         error ("%<__thread%> before %<extern%>");
   13264              :       break;
   13265              :     case RID_REGISTER:
   13266              :       n = csc_register;
   13267              :       break;
   13268       435044 :     case RID_STATIC:
   13269       435044 :       n = csc_static;
   13270              :       /* Diagnose "__thread static".  */
   13271       435044 :       if (specs->thread_p && specs->thread_gnu_p)
   13272            1 :         error ("%<__thread%> before %<static%>");
   13273              :       break;
   13274      4375347 :     case RID_TYPEDEF:
   13275      4375347 :       n = csc_typedef;
   13276      4375347 :       if (specs->c23_auto_p)
   13277              :         {
   13278            1 :           error ("%<typedef%> used with %<auto%>");
   13279            1 :           specs->c23_auto_p = false;
   13280              :         }
   13281              :       break;
   13282          646 :     case RID_CONSTEXPR:
   13283          646 :       dupe = specs->constexpr_p;
   13284          646 :       if (specs->storage_class == csc_extern)
   13285            1 :         error ("%qE used with %<extern%>", scspec);
   13286          645 :       else if (specs->storage_class == csc_typedef)
   13287            1 :         error ("%qE used with %<typedef%>", scspec);
   13288          644 :       else if (specs->storage_class == csc_auto)
   13289              :         /* auto may only be used with another storage class specifier,
   13290              :            such as constexpr, if the type is inferred.  */
   13291            2 :         error ("%qE used with %<auto%>", scspec);
   13292          642 :       else if (specs->thread_p)
   13293            4 :         error ("%qE used with %qs", scspec,
   13294            2 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   13295              :       else
   13296          640 :         specs->constexpr_p = true;
   13297              :       break;
   13298            0 :     default:
   13299            0 :       gcc_unreachable ();
   13300              :     }
   13301     93778015 :   if (n != csc_none && n == specs->storage_class)
   13302              :     dupe = true;
   13303     93778007 :   if (dupe)
   13304              :     {
   13305           12 :       if (i == RID_THREAD)
   13306            2 :         error ("duplicate %<_Thread_local%> or %<__thread%>");
   13307              :       else
   13308           10 :         error ("duplicate %qE", scspec);
   13309              :     }
   13310     93778015 :   if (n != csc_none)
   13311              :     {
   13312     56785845 :       if (specs->storage_class != csc_none && n != specs->storage_class)
   13313              :         {
   13314            7 :           error ("multiple storage classes in declaration specifiers");
   13315              :         }
   13316              :       else
   13317              :         {
   13318     56785838 :           specs->storage_class = n;
   13319     56785838 :           specs->locations[cdw_storage_class] = loc;
   13320     56785838 :           if (n != csc_extern && n != csc_static && specs->thread_p)
   13321              :             {
   13322            8 :               error ("%qs used with %qE",
   13323            8 :                      specs->thread_gnu_p ? "__thread" : "_Thread_local",
   13324              :                      scspec);
   13325            8 :               specs->thread_p = false;
   13326              :             }
   13327     56785838 :           if (n != csc_auto && n != csc_register && n != csc_static
   13328     56347573 :               && specs->constexpr_p)
   13329              :             {
   13330            2 :               error ("%<constexpr%> used with %qE", scspec);
   13331            2 :               specs->constexpr_p = false;
   13332              :             }
   13333              :         }
   13334              :     }
   13335              :   return specs;
   13336              : }
   13337              : 
   13338              : /* Add the attributes ATTRS to the declaration specifiers SPECS,
   13339              :    returning SPECS.  */
   13340              : 
   13341              : struct c_declspecs *
   13342     37280483 : declspecs_add_attrs (location_t loc, struct c_declspecs *specs, tree attrs)
   13343              : {
   13344     37280483 :   specs->attrs = chainon (attrs, specs->attrs);
   13345     37280483 :   specs->locations[cdw_attributes] = loc;
   13346     37280483 :   specs->declspecs_seen_p = true;
   13347              :   /* In the case of standard attributes at the start of the
   13348              :      declaration, the caller will reset this.  */
   13349     37280483 :   specs->non_std_attrs_seen_p = true;
   13350     37280483 :   return specs;
   13351              : }
   13352              : 
   13353              : /* Add an _Alignas specifier (expression ALIGN, or type whose
   13354              :    alignment is ALIGN) to the declaration specifiers SPECS, returning
   13355              :    SPECS.  */
   13356              : struct c_declspecs *
   13357          202 : declspecs_add_alignas (location_t loc,
   13358              :                        struct c_declspecs *specs, tree align)
   13359              : {
   13360          202 :   specs->alignas_p = true;
   13361          202 :   specs->locations[cdw_alignas] = loc;
   13362          202 :   if (align == error_mark_node)
   13363              :     return specs;
   13364              : 
   13365              :   /* Only accept the alignment if it's valid and greater than
   13366              :      the current one.  Zero is invalid but by C11 required to
   13367              :      be silently ignored.  */
   13368          200 :   int align_log = check_user_alignment (align, false, /* warn_zero = */false);
   13369          200 :   if (align_log > specs->align_log)
   13370          167 :     specs->align_log = align_log;
   13371              :   return specs;
   13372              : }
   13373              : 
   13374              : /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
   13375              :    specifiers with any other type specifier to determine the resulting
   13376              :    type.  This is where ISO C checks on complex types are made, since
   13377              :    "_Complex long" is a prefix of the valid ISO C type "_Complex long
   13378              :    double".  Also apply postfix standard attributes to modify the type.  */
   13379              : 
   13380              : struct c_declspecs *
   13381    325611018 : finish_declspecs (struct c_declspecs *specs)
   13382              : {
   13383              :   /* If a type was specified as a whole, we have no modifiers and are
   13384              :      done.  */
   13385    325611018 :   if (specs->type != NULL_TREE)
   13386              :     {
   13387    257940403 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13388              :                   && !specs->signed_p && !specs->unsigned_p
   13389              :                   && !specs->complex_p && !specs->c23_auto_p);
   13390              : 
   13391              :       /* Set a dummy type.  */
   13392    257940403 :       if (TREE_CODE (specs->type) == ERROR_MARK)
   13393          179 :         specs->type = integer_type_node;
   13394    257940403 :       goto handle_postfix_attrs;
   13395              :     }
   13396              : 
   13397              :   /* If none of "void", "_Bool", "char", "int", "float" or "double"
   13398              :      has been specified, treat it as "int" unless "_Complex" is
   13399              :      present and there are no other specifiers.  If we just have
   13400              :      "_Complex", it is equivalent to "_Complex double", but e.g.
   13401              :      "_Complex short" is equivalent to "_Complex short int".  */
   13402     67670615 :   if (specs->typespec_word == cts_none)
   13403              :     {
   13404      4286593 :       if (specs->saturating_p)
   13405              :         {
   13406            1 :           error_at (specs->locations[cdw_saturating],
   13407              :                     "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
   13408            1 :           if (!targetm.fixed_point_supported_p ())
   13409            1 :             error_at (specs->locations[cdw_saturating],
   13410              :                       "fixed-point types not supported for this target");
   13411            1 :           specs->typespec_word = cts_fract;
   13412              :         }
   13413      4286592 :       else if (specs->long_p || specs->short_p
   13414       208355 :                || specs->signed_p || specs->unsigned_p)
   13415              :         {
   13416      4276145 :           specs->typespec_word = cts_int;
   13417              :         }
   13418        10447 :       else if (specs->complex_p)
   13419              :         {
   13420          132 :           specs->typespec_word = cts_double;
   13421          132 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13422              :                    "ISO C does not support plain %<complex%> meaning "
   13423              :                    "%<double complex%>");
   13424              :         }
   13425        10315 :       else if (specs->c23_auto_p)
   13426              :         {
   13427              :           /* Type to be filled in later, including applying postfix
   13428              :              attributes.  This warning only actually appears for
   13429              :              -Wc11-c23-compat in C23 mode; in older modes, there may
   13430              :              be a warning or pedwarn for implicit "int" instead, or
   13431              :              other errors for use of auto at file scope.  */
   13432           95 :           pedwarn_c11 (input_location, OPT_Wpedantic,
   13433              :                        "ISO C does not support %<auto%> type deduction "
   13434              :                        "before C23");
   13435           95 :           return specs;
   13436              :         }
   13437              :       else
   13438              :         {
   13439        10220 :           specs->typespec_word = cts_int;
   13440        10220 :           specs->default_int_p = true;
   13441              :           /* We don't diagnose this here because grokdeclarator will
   13442              :              give more specific diagnostics according to whether it is
   13443              :              a function definition.  */
   13444              :         }
   13445              :     }
   13446              : 
   13447              :   /* If "signed" was specified, record this to distinguish "int" and
   13448              :      "signed int" in the case of a bit-field with
   13449              :      -funsigned-bitfields.  */
   13450     67670520 :   specs->explicit_signed_p = specs->signed_p;
   13451              : 
   13452              :   /* Now compute the actual type.  */
   13453     67670520 :   gcc_assert (!specs->c23_auto_p);
   13454     67670520 :   switch (specs->typespec_word)
   13455              :     {
   13456         1892 :     case cts_auto_type:
   13457         1892 :       gcc_assert (!specs->long_p && !specs->short_p
   13458              :                   && !specs->signed_p && !specs->unsigned_p
   13459              :                   && !specs->complex_p);
   13460              :       /* Type to be filled in later.  */
   13461         1892 :       if (specs->postfix_attrs)
   13462            2 :         error ("%<__auto_type%> followed by %<[[]]%> attributes");
   13463              :       break;
   13464      8265759 :     case cts_void:
   13465      8265759 :       gcc_assert (!specs->long_p && !specs->short_p
   13466              :                   && !specs->signed_p && !specs->unsigned_p
   13467              :                   && !specs->complex_p);
   13468      8265759 :       specs->type = void_type_node;
   13469      8265759 :       break;
   13470        95223 :     case cts_bool:
   13471        95223 :       gcc_assert (!specs->long_p && !specs->short_p
   13472              :                   && !specs->signed_p && !specs->unsigned_p
   13473              :                   && !specs->complex_p);
   13474        95223 :       specs->type = boolean_type_node;
   13475        95223 :       break;
   13476      9299116 :     case cts_char:
   13477      9299116 :       gcc_assert (!specs->long_p && !specs->short_p);
   13478      9299116 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13479      9299116 :       if (specs->signed_p)
   13480       174836 :         specs->type = signed_char_type_node;
   13481      9124280 :       else if (specs->unsigned_p)
   13482       892064 :         specs->type = unsigned_char_type_node;
   13483              :       else
   13484      8232216 :         specs->type = char_type_node;
   13485      9299116 :       if (specs->complex_p)
   13486              :         {
   13487         3856 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13488              :                    "ISO C does not support complex integer types");
   13489         3856 :           specs->type = build_complex_type (specs->type);
   13490              :         }
   13491              :       break;
   13492        52065 :     case cts_int_n:
   13493        52065 :       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
   13494        52065 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13495        52065 :       if (! int_n_enabled_p[specs->u.int_n_idx])
   13496            0 :         specs->type = integer_type_node;
   13497              :       else
   13498        52065 :         specs->type = (specs->unsigned_p
   13499        52065 :                        ? int_n_trees[specs->u.int_n_idx].unsigned_type
   13500              :                        : int_n_trees[specs->u.int_n_idx].signed_type);
   13501        52065 :       if (specs->complex_p)
   13502              :         {
   13503          202 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13504              :                    "ISO C does not support complex integer types");
   13505          202 :           specs->type = build_complex_type (specs->type);
   13506              :         }
   13507              :       break;
   13508     28943126 :     case cts_int:
   13509     28943126 :       gcc_assert (!(specs->long_p && specs->short_p));
   13510     28943126 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13511     28943126 :       if (specs->long_long_p)
   13512      3040072 :         specs->type = (specs->unsigned_p
   13513      3040072 :                        ? long_long_unsigned_type_node
   13514              :                        : long_long_integer_type_node);
   13515     25903054 :       else if (specs->long_p)
   13516      2253991 :         specs->type = (specs->unsigned_p
   13517      2253991 :                        ? long_unsigned_type_node
   13518              :                        : long_integer_type_node);
   13519     23649063 :       else if (specs->short_p)
   13520      1720721 :         specs->type = (specs->unsigned_p
   13521      1720721 :                        ? short_unsigned_type_node
   13522              :                        : short_integer_type_node);
   13523              :       else
   13524     21928342 :         specs->type = (specs->unsigned_p
   13525     21928342 :                        ? unsigned_type_node
   13526              :                        : integer_type_node);
   13527     28943126 :       if (specs->complex_p)
   13528              :         {
   13529        15763 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13530              :                    "ISO C does not support complex integer types");
   13531        15763 :           specs->type = build_complex_type (specs->type);
   13532              :         }
   13533              :       break;
   13534      3675810 :     case cts_float:
   13535      3675810 :       gcc_assert (!specs->long_p && !specs->short_p
   13536              :                   && !specs->signed_p && !specs->unsigned_p);
   13537      7351620 :       specs->type = (specs->complex_p
   13538      3675810 :                      ? complex_float_type_node
   13539              :                      : float_type_node);
   13540      3675810 :       break;
   13541      6689347 :     case cts_double:
   13542      6689347 :       gcc_assert (!specs->long_long_p && !specs->short_p
   13543              :                   && !specs->signed_p && !specs->unsigned_p);
   13544      6689347 :       if (specs->long_p)
   13545              :         {
   13546      2919407 :           specs->type = (specs->complex_p
   13547      2919407 :                          ? complex_long_double_type_node
   13548              :                          : long_double_type_node);
   13549              :         }
   13550              :       else
   13551              :         {
   13552      3769940 :           specs->type = (specs->complex_p
   13553      3769940 :                          ? complex_double_type_node
   13554              :                          : double_type_node);
   13555              :         }
   13556              :       break;
   13557     10552377 :     case cts_floatn_nx:
   13558     10552377 :       gcc_assert (!specs->long_p && !specs->short_p
   13559              :                   && !specs->signed_p && !specs->unsigned_p);
   13560     10552377 :       if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   13561           88 :         specs->type = integer_type_node;
   13562     10552289 :       else if (specs->complex_p)
   13563      1557518 :         specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13564              :       else
   13565      8994771 :         specs->type = FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13566              :       break;
   13567        47581 :     case cts_dfloat32:
   13568        47581 :     case cts_dfloat64:
   13569        47581 :     case cts_dfloat128:
   13570        47581 :     case cts_dfloat64x:
   13571        47581 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13572              :                   && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
   13573        47581 :       if (!targetm.decimal_float_supported_p ())
   13574            0 :         specs->type = integer_type_node;
   13575        47581 :       else if (specs->typespec_word == cts_dfloat32)
   13576        15961 :         specs->type = dfloat32_type_node;
   13577        31620 :       else if (specs->typespec_word == cts_dfloat64)
   13578        15839 :         specs->type = dfloat64_type_node;
   13579        15781 :       else if (specs->typespec_word == cts_dfloat128)
   13580        15734 :         specs->type = dfloat128_type_node;
   13581              :       else
   13582           47 :         specs->type = dfloat64x_type_node;
   13583              :       break;
   13584           33 :     case cts_fract:
   13585           33 :       gcc_assert (!specs->complex_p);
   13586           33 :       if (!targetm.fixed_point_supported_p ())
   13587           33 :         specs->type = integer_type_node;
   13588            0 :       else if (specs->saturating_p)
   13589              :         {
   13590            0 :           if (specs->long_long_p)
   13591            0 :             specs->type = specs->unsigned_p
   13592            0 :                           ? sat_unsigned_long_long_fract_type_node
   13593              :                           : sat_long_long_fract_type_node;
   13594            0 :           else if (specs->long_p)
   13595            0 :             specs->type = specs->unsigned_p
   13596            0 :                           ? sat_unsigned_long_fract_type_node
   13597              :                           : sat_long_fract_type_node;
   13598            0 :           else if (specs->short_p)
   13599            0 :             specs->type = specs->unsigned_p
   13600            0 :                           ? sat_unsigned_short_fract_type_node
   13601              :                           : sat_short_fract_type_node;
   13602              :           else
   13603            0 :             specs->type = specs->unsigned_p
   13604            0 :                           ? sat_unsigned_fract_type_node
   13605              :                           : sat_fract_type_node;
   13606              :         }
   13607              :       else
   13608              :         {
   13609            0 :           if (specs->long_long_p)
   13610            0 :             specs->type = specs->unsigned_p
   13611            0 :                           ? unsigned_long_long_fract_type_node
   13612              :                           : long_long_fract_type_node;
   13613            0 :           else if (specs->long_p)
   13614            0 :             specs->type = specs->unsigned_p
   13615            0 :                           ? unsigned_long_fract_type_node
   13616              :                           : long_fract_type_node;
   13617            0 :           else if (specs->short_p)
   13618            0 :             specs->type = specs->unsigned_p
   13619            0 :                           ? unsigned_short_fract_type_node
   13620              :                           : short_fract_type_node;
   13621              :           else
   13622            0 :             specs->type = specs->unsigned_p
   13623            0 :                           ? unsigned_fract_type_node
   13624              :                           : fract_type_node;
   13625              :         }
   13626              :       break;
   13627           31 :     case cts_accum:
   13628           31 :       gcc_assert (!specs->complex_p);
   13629           31 :       if (!targetm.fixed_point_supported_p ())
   13630           31 :         specs->type = integer_type_node;
   13631            0 :       else if (specs->saturating_p)
   13632              :         {
   13633            0 :           if (specs->long_long_p)
   13634            0 :             specs->type = specs->unsigned_p
   13635            0 :                           ? sat_unsigned_long_long_accum_type_node
   13636              :                           : sat_long_long_accum_type_node;
   13637            0 :           else if (specs->long_p)
   13638            0 :             specs->type = specs->unsigned_p
   13639            0 :                           ? sat_unsigned_long_accum_type_node
   13640              :                           : sat_long_accum_type_node;
   13641            0 :           else if (specs->short_p)
   13642            0 :             specs->type = specs->unsigned_p
   13643            0 :                           ? sat_unsigned_short_accum_type_node
   13644              :                           : sat_short_accum_type_node;
   13645              :           else
   13646            0 :             specs->type = specs->unsigned_p
   13647            0 :                           ? sat_unsigned_accum_type_node
   13648              :                           : sat_accum_type_node;
   13649              :         }
   13650              :       else
   13651              :         {
   13652            0 :           if (specs->long_long_p)
   13653            0 :             specs->type = specs->unsigned_p
   13654            0 :                           ? unsigned_long_long_accum_type_node
   13655              :                           : long_long_accum_type_node;
   13656            0 :           else if (specs->long_p)
   13657            0 :             specs->type = specs->unsigned_p
   13658            0 :                           ? unsigned_long_accum_type_node
   13659              :                           : long_accum_type_node;
   13660            0 :           else if (specs->short_p)
   13661            0 :             specs->type = specs->unsigned_p
   13662            0 :                           ? unsigned_short_accum_type_node
   13663              :                           : short_accum_type_node;
   13664              :           else
   13665            0 :             specs->type = specs->unsigned_p
   13666            0 :                           ? unsigned_accum_type_node
   13667              :                           : accum_type_node;
   13668              :         }
   13669              :       break;
   13670        48160 :     case cts_bitint:
   13671        48160 :       gcc_assert (!specs->long_p && !specs->short_p
   13672              :                   && !specs->complex_p);
   13673        48160 :       if (!specs->unsigned_p && specs->u.bitint_prec == 1 && !flag_isoc2y)
   13674              :         {
   13675            2 :           error_at (specs->locations[cdw_typespec],
   13676              :                     "%<signed _BitInt%> argument must be at least 2 "
   13677              :                     "before C2Y");
   13678            2 :           specs->type = integer_type_node;
   13679            2 :           break;
   13680              :         }
   13681        48158 :       if (specs->u.bitint_prec == -1)
   13682            7 :         specs->type = integer_type_node;
   13683              :       else
   13684              :         {
   13685        71186 :           pedwarn_c11 (specs->locations[cdw_typespec], OPT_Wpedantic,
   13686              :                        "ISO C does not support %<%s_BitInt(%d)%> before C23",
   13687              :                        specs->unsigned_p ? "unsigned "
   13688        23035 :                        : specs->signed_p ? "signed " : "",
   13689              :                        specs->u.bitint_prec);
   13690        48151 :           specs->type = build_bitint_type (specs->u.bitint_prec,
   13691        48151 :                                            specs->unsigned_p);
   13692              :         }
   13693              :       break;
   13694            0 :     default:
   13695            0 :       gcc_unreachable ();
   13696              :     }
   13697    325610923 :  handle_postfix_attrs:
   13698    325610923 :   if (specs->type != NULL)
   13699              :     {
   13700    325609031 :       specs->postfix_attrs
   13701    325609031 :         = c_warn_type_attributes (specs->type, specs->postfix_attrs);
   13702    325609031 :       decl_attributes (&specs->type, specs->postfix_attrs, 0);
   13703    325609031 :       specs->postfix_attrs = NULL_TREE;
   13704              :     }
   13705              : 
   13706              :   return specs;
   13707              : }
   13708              : 
   13709              : /* Perform final processing on one file scope's declarations (or the
   13710              :    external scope's declarations), GLOBALS.  */
   13711              : 
   13712              : static void
   13713       216270 : c_write_global_declarations_1 (tree globals)
   13714              : {
   13715       216270 :   tree decl;
   13716       216270 :   bool reconsider;
   13717              : 
   13718              :   /* Process the decls in the order they were written.  */
   13719    396895490 :   for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13720              :     {
   13721              :       /* Check for used but undefined static functions using the C
   13722              :          standard's definition of "used", and set TREE_NO_WARNING so
   13723              :          that check_global_declaration doesn't repeat the check.  */
   13724    396679220 :       if (TREE_CODE (decl) == FUNCTION_DECL
   13725    378221192 :           && DECL_INITIAL (decl) == NULL_TREE
   13726    340553907 :           && DECL_EXTERNAL (decl)
   13727    340553902 :           && !TREE_PUBLIC (decl)
   13728    396679349 :           && !warning_suppressed_p (decl, OPT_Wunused))
   13729              :         {
   13730          124 :           if (C_DECL_USED (decl))
   13731              :             {
   13732           31 :               if (pedwarn (input_location, 0, "%q+F used but never defined",
   13733              :                            decl))
   13734           30 :                 suppress_warning (decl, OPT_Wunused);
   13735              :             }
   13736              :           /* For -Wunused-function warn about unused static prototypes.  */
   13737           93 :           else if (warn_unused_function
   13738            2 :                    && ! DECL_ARTIFICIAL (decl)
   13739           95 :                    && warning (OPT_Wunused_function,
   13740              :                                "%q+F declared %<static%> but never defined",
   13741              :                                decl))
   13742            2 :             suppress_warning (decl, OPT_Wunused);
   13743              :         }
   13744              : 
   13745    396679220 :       wrapup_global_declaration_1 (decl);
   13746              :     }
   13747              : 
   13748       251500 :   do
   13749              :     {
   13750       251500 :       reconsider = false;
   13751    514948028 :       for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13752    514696528 :         reconsider |= wrapup_global_declaration_2 (decl);
   13753              :     }
   13754              :   while (reconsider);
   13755       216270 : }
   13756              : 
   13757              : /* Preserve the external declarations scope across a garbage collect.  */
   13758              : static GTY(()) tree ext_block;
   13759              : 
   13760              : /* Collect all references relevant to SOURCE_FILE.  */
   13761              : 
   13762              : static void
   13763           15 : collect_all_refs (const char *source_file)
   13764              : {
   13765           15 :   tree t;
   13766           15 :   unsigned i;
   13767              : 
   13768           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13769           15 :     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
   13770              : 
   13771           15 :   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
   13772           15 : }
   13773              : 
   13774              : /* Collect source file references at global level.  */
   13775              : 
   13776              : static void
   13777           15 : collect_source_refs (void)
   13778              : {
   13779           15 :   tree t;
   13780           15 :   tree decls;
   13781           15 :   tree decl;
   13782           15 :   unsigned i;
   13783              : 
   13784           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13785              :     {
   13786           15 :       decls = DECL_INITIAL (t);
   13787           82 :       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
   13788           67 :         if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13789           67 :           collect_source_ref (DECL_SOURCE_FILE (decl));
   13790              :     }
   13791              : 
   13792        44321 :   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
   13793        44306 :     if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13794           11 :       collect_source_ref (DECL_SOURCE_FILE (decl));
   13795           15 : }
   13796              : 
   13797              : /* Free attribute access data that are not needed by the middle end. */
   13798              : 
   13799              : static void
   13800       108135 : free_attr_access_data ()
   13801              : {
   13802       108135 :   struct cgraph_node *n;
   13803              : 
   13804              :   /* Iterate over all functions declared in the translation unit.  */
   13805     37777097 :   FOR_EACH_FUNCTION (n)
   13806              :     {
   13807    140879401 :       for (tree parm = DECL_ARGUMENTS (n->decl); parm; parm = TREE_CHAIN (parm))
   13808    103210439 :         if (tree attrs = DECL_ATTRIBUTES (parm))
   13809        98617 :           attr_access::free_lang_data (attrs);
   13810              : 
   13811     37668962 :       tree fntype = TREE_TYPE (n->decl);
   13812     37668962 :       if (!fntype || fntype == error_mark_node)
   13813            0 :         continue;
   13814     37668962 :       tree attrs = TYPE_ATTRIBUTES (fntype);
   13815     37668962 :       if (!attrs)
   13816     37431740 :         continue;
   13817              : 
   13818       237222 :       attr_access::free_lang_data (attrs);
   13819              :     }
   13820       108135 : }
   13821              : 
   13822              : /* Perform any final parser cleanups and generate initial debugging
   13823              :    information.  */
   13824              : 
   13825              : void
   13826       108466 : c_parse_final_cleanups (void)
   13827              : {
   13828       108466 :   tree t;
   13829       108466 :   unsigned i;
   13830              : 
   13831              :   /* We don't want to do this if generating a PCH.  */
   13832       108466 :   if (pch_file)
   13833       108466 :     return;
   13834              : 
   13835       108135 :   timevar_stop (TV_PHASE_PARSING);
   13836       108135 :   timevar_start (TV_PHASE_DEFERRED);
   13837              : 
   13838              :   /* Do the Objective-C stuff.  This is where all the Objective-C
   13839              :      module stuff gets generated (symtab, class/protocol/selector
   13840              :      lists etc).  */
   13841       108135 :   if (c_dialect_objc ())
   13842            0 :     objc_write_global_declarations ();
   13843              : 
   13844              :   /* Close the external scope.  */
   13845       108135 :   ext_block = pop_scope ();
   13846       108135 :   external_scope = 0;
   13847       108135 :   gcc_assert (!current_scope);
   13848              : 
   13849              :   /* Handle -fdump-ada-spec[-slim]. */
   13850       108135 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
   13851              :     {
   13852              :       /* Build a table of files to generate specs for */
   13853           15 :       collect_source_ref (main_input_filename);
   13854           15 :       if (!flag_dump_ada_spec_slim)
   13855           15 :         collect_source_refs ();
   13856              : 
   13857           15 :       dump_ada_specs (collect_all_refs, NULL);
   13858              :     }
   13859              : 
   13860              :   /* Process all file scopes in this compilation, and the external_scope,
   13861              :      through wrapup_global_declarations.  */
   13862       216270 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13863       108135 :     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
   13864       108135 :   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
   13865              : 
   13866              :   /* Call this to set cpp_implicit_aliases_done on all nodes.  This is
   13867              :      important for function multiversioning aliases to get resolved.  */
   13868       108135 :   symtab->process_same_body_aliases ();
   13869              : 
   13870       108135 :   if (!in_lto_p)
   13871       108135 :     free_attr_access_data ();
   13872              : 
   13873       108135 :   timevar_stop (TV_PHASE_DEFERRED);
   13874       108135 :   timevar_start (TV_PHASE_PARSING);
   13875              : 
   13876       108135 :   ext_block = NULL;
   13877              : }
   13878              : 
   13879              : /* Register reserved keyword WORD as qualifier for address space AS.  */
   13880              : 
   13881              : void
   13882       228864 : c_register_addr_space (const char *word, addr_space_t as)
   13883              : {
   13884       228864 :   int rid = RID_FIRST_ADDR_SPACE + as;
   13885       228864 :   tree id;
   13886              : 
   13887              :   /* Address space qualifiers are only supported
   13888              :      in C with GNU extensions enabled.  */
   13889       228864 :   if (c_dialect_objc () || flag_no_asm)
   13890              :     return;
   13891              : 
   13892       216154 :   id = get_identifier (word);
   13893       216154 :   C_SET_RID_CODE (id, rid);
   13894       216154 :   C_IS_RESERVED_WORD (id) = 1;
   13895       216154 :   ridpointers [rid] = id;
   13896              : }
   13897              : 
   13898              : /* Return identifier to look up for omp declare reduction.  */
   13899              : 
   13900              : tree
   13901         3272 : c_omp_reduction_id (enum tree_code reduction_code, tree reduction_id)
   13902              : {
   13903         3272 :   const char *p = NULL;
   13904         3272 :   switch (reduction_code)
   13905              :     {
   13906              :     case PLUS_EXPR: p = "+"; break;
   13907          267 :     case MULT_EXPR: p = "*"; break;
   13908          157 :     case MINUS_EXPR: p = "-"; break;
   13909           31 :     case BIT_AND_EXPR: p = "&"; break;
   13910           14 :     case BIT_XOR_EXPR: p = "^"; break;
   13911           92 :     case BIT_IOR_EXPR: p = "|"; break;
   13912           67 :     case TRUTH_ANDIF_EXPR: p = "&&"; break;
   13913           78 :     case TRUTH_ORIF_EXPR: p = "||"; break;
   13914           46 :     case MIN_EXPR: p = "min"; break;
   13915           83 :     case MAX_EXPR: p = "max"; break;
   13916              :     default:
   13917              :       break;
   13918              :     }
   13919              : 
   13920          835 :   if (p == NULL)
   13921              :     {
   13922          213 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
   13923            0 :         return error_mark_node;
   13924          213 :       p = IDENTIFIER_POINTER (reduction_id);
   13925              :     }
   13926              : 
   13927         3272 :   const char prefix[] = "omp declare reduction ";
   13928         3272 :   size_t lenp = sizeof (prefix);
   13929         3272 :   size_t len = strlen (p);
   13930         3272 :   char *name = XALLOCAVEC (char, lenp + len);
   13931         3272 :   memcpy (name, prefix, lenp - 1);
   13932         3272 :   memcpy (name + lenp - 1, p, len + 1);
   13933         3272 :   return get_identifier (name);
   13934              : }
   13935              : 
   13936              : /* Lookup REDUCTION_ID in the current scope, or create an artificial
   13937              :    VAR_DECL, bind it into the current scope and return it.  */
   13938              : 
   13939              : tree
   13940          162 : c_omp_reduction_decl (tree reduction_id)
   13941              : {
   13942          162 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13943          162 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   13944           47 :     return b->decl;
   13945              : 
   13946          115 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   13947              :                           reduction_id, integer_type_node);
   13948          115 :   DECL_ARTIFICIAL (decl) = 1;
   13949          115 :   DECL_EXTERNAL (decl) = 1;
   13950          115 :   TREE_STATIC (decl) = 1;
   13951          115 :   TREE_PUBLIC (decl) = 0;
   13952          115 :   bind (reduction_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   13953          115 :   return decl;
   13954              : }
   13955              : 
   13956              : /* Lookup REDUCTION_ID in the first scope where it has entry for TYPE.  */
   13957              : 
   13958              : tree
   13959          276 : c_omp_reduction_lookup (tree reduction_id, tree type)
   13960              : {
   13961          276 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13962          279 :   while (b)
   13963              :     {
   13964          277 :       tree t;
   13965          297 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   13966          294 :         if (comptypes (TREE_PURPOSE (t), type))
   13967          274 :           return TREE_VALUE (t);
   13968            3 :       b = b->shadowed;
   13969              :     }
   13970            2 :   return error_mark_node;
   13971              : }
   13972              : 
   13973              : /* Helper function called via walk_tree, to diagnose invalid
   13974              :    #pragma omp declare reduction combiners or initializers.  */
   13975              : 
   13976              : tree
   13977         1416 : c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
   13978              : {
   13979         1416 :   tree *vars = (tree *) data;
   13980         1416 :   if (SSA_VAR_P (*tp)
   13981          416 :       && !DECL_ARTIFICIAL (*tp)
   13982           24 :       && *tp != vars[0]
   13983           24 :       && *tp != vars[1])
   13984              :     {
   13985           24 :       location_t loc = DECL_SOURCE_LOCATION (vars[0]);
   13986           24 :       if (strcmp (IDENTIFIER_POINTER (DECL_NAME (vars[0])), "omp_out") == 0)
   13987           10 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
   13988              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
   13989              :                   *tp);
   13990              :       else
   13991           14 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
   13992              :                        "to variable %qD which is not %<omp_priv%> nor "
   13993              :                        "%<omp_orig%>",
   13994              :                   *tp);
   13995           24 :       return *tp;
   13996              :     }
   13997              :   return NULL_TREE;
   13998              : }
   13999              : 
   14000              : /* Return identifier to look up for omp declare mapper.  */
   14001              : 
   14002              : tree
   14003          714 : c_omp_mapper_id (tree mapper_id)
   14004              : {
   14005          714 :   const char *p = NULL;
   14006              : 
   14007          714 :   const char prefix[] = "omp declare mapper ";
   14008              : 
   14009          714 :   if (mapper_id == NULL_TREE)
   14010              :     p = "<default>";
   14011           27 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
   14012           27 :     p = IDENTIFIER_POINTER (mapper_id);
   14013              :   else
   14014            0 :     return error_mark_node;
   14015              : 
   14016          714 :   size_t lenp = sizeof (prefix);
   14017          714 :   size_t len = strlen (p);
   14018          714 :   char *name = XALLOCAVEC (char, lenp + len);
   14019          714 :   memcpy (name, prefix, lenp - 1);
   14020          714 :   memcpy (name + lenp - 1, p, len + 1);
   14021          714 :   return get_identifier (name);
   14022              : }
   14023              : 
   14024              : /* Lookup MAPPER_ID in the current scope, or create an artificial
   14025              :    VAR_DECL, bind it into the current scope and return it.  */
   14026              : 
   14027              : tree
   14028           74 : c_omp_mapper_decl (tree mapper_id)
   14029              : {
   14030           74 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14031           74 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   14032           22 :     return b->decl;
   14033              : 
   14034           52 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   14035              :                           mapper_id, integer_type_node);
   14036           52 :   DECL_ARTIFICIAL (decl) = 1;
   14037           52 :   DECL_EXTERNAL (decl) = 1;
   14038           52 :   TREE_STATIC (decl) = 1;
   14039           52 :   TREE_PUBLIC (decl) = 0;
   14040           52 :   bind (mapper_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   14041           52 :   return decl;
   14042              : }
   14043              : 
   14044              : /* Lookup MAPPER_ID in the first scope where it has entry for TYPE.  */
   14045              : 
   14046              : tree
   14047         5544 : c_omp_mapper_lookup (tree mapper_id, tree type)
   14048              : {
   14049         5544 :   if (!RECORD_OR_UNION_TYPE_P (type))
   14050              :     return NULL_TREE;
   14051              : 
   14052          640 :   mapper_id = c_omp_mapper_id (mapper_id);
   14053              : 
   14054          640 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14055          646 :   while (b)
   14056              :     {
   14057          129 :       tree t;
   14058          148 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   14059          142 :         if (comptypes (TREE_PURPOSE (t), type))
   14060          123 :           return TREE_VALUE (t);
   14061            6 :       b = b->shadowed;
   14062              :     }
   14063              :   return NULL_TREE;
   14064              : }
   14065              : 
   14066              : /* For C, we record a pointer to the mapper itself without wrapping it in an
   14067              :    artificial function or similar.  So, just return it.  */
   14068              : 
   14069              : tree
   14070          115 : c_omp_extract_mapper_directive (tree mapper)
   14071              : {
   14072          115 :   return mapper;
   14073              : }
   14074              : 
   14075              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
   14076              :    nothing more complicated.  */
   14077              : 
   14078              : tree
   14079          587 : c_omp_map_array_section (location_t loc, tree t)
   14080              : {
   14081          587 :   tree low = TREE_OPERAND (t, 1);
   14082          587 :   tree len = TREE_OPERAND (t, 2);
   14083              : 
   14084          587 :   if (len && integer_onep (len))
   14085              :     {
   14086          102 :       t = TREE_OPERAND (t, 0);
   14087              : 
   14088          102 :       if (!low)
   14089           16 :         low = integer_zero_node;
   14090              : 
   14091          102 :       t = build_array_ref (loc, t, low);
   14092              :     }
   14093              : 
   14094          587 :   return t;
   14095              : }
   14096              : 
   14097              : /* Helper function for below function.  */
   14098              : 
   14099              : static tree
   14100        52737 : c_omp_scan_mapper_bindings_r (tree *tp, int *walk_subtrees, void *ptr)
   14101              : {
   14102        52737 :   tree t = *tp;
   14103        52737 :   omp_mapper_list<tree> *mlist = (omp_mapper_list<tree> *) ptr;
   14104        52737 :   tree aggr_type = NULL_TREE;
   14105              : 
   14106        52737 :   if (TREE_CODE (t) == SIZEOF_EXPR
   14107        52737 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   14108              :     {
   14109            0 :       *walk_subtrees = 0;
   14110            0 :       return NULL_TREE;
   14111              :     }
   14112              : 
   14113        52737 :   if (TREE_CODE (t) == OMP_CLAUSE)
   14114              :     return NULL_TREE;
   14115              : 
   14116        49430 :   if (TREE_CODE (t) == COMPONENT_REF
   14117        49430 :       && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   14118          378 :     aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   14119        49052 :   else if ((TREE_CODE (t) == VAR_DECL
   14120              :             || TREE_CODE (t) == PARM_DECL
   14121              :             || TREE_CODE (t) == RESULT_DECL)
   14122         5508 :            && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   14123          125 :     aggr_type = TREE_TYPE (t);
   14124              : 
   14125          503 :   if (aggr_type)
   14126              :     {
   14127          503 :       tree mapper_fn = c_omp_mapper_lookup (NULL_TREE, aggr_type);
   14128          503 :       if (mapper_fn)
   14129           76 :         mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   14130              :     }
   14131              : 
   14132              :   return NULL_TREE;
   14133              : }
   14134              : 
   14135              : /* Scan an offload region's body, and record uses of struct- or union-typed
   14136              :    variables.  Add _mapper_binding_ fake clauses to *CLAUSES_PTR.  */
   14137              : 
   14138              : void
   14139         2159 : c_omp_scan_mapper_bindings (location_t loc, tree *clauses_ptr, tree body)
   14140              : {
   14141         2159 :   hash_set<omp_name_type<tree>> seen_types;
   14142         2159 :   auto_vec<tree> mappers;
   14143         2159 :   omp_mapper_list<tree> mlist (&seen_types, &mappers);
   14144              : 
   14145         2159 :   walk_tree_without_duplicates (&body, c_omp_scan_mapper_bindings_r, &mlist);
   14146              : 
   14147         2159 :   unsigned int i;
   14148         2159 :   tree mapper;
   14149         4360 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14150           42 :     c_omp_find_nested_mappers (&mlist, mapper);
   14151              : 
   14152         2230 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14153              :     {
   14154           42 :       if (mapper == error_mark_node)
   14155            0 :         continue;
   14156           42 :       tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   14157           42 :       tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   14158              : 
   14159           42 :       tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   14160           42 :       OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   14161           42 :       OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   14162           42 :       OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper;
   14163              : 
   14164           42 :       OMP_CLAUSE_CHAIN (c) = *clauses_ptr;
   14165           42 :       *clauses_ptr = c;
   14166              :     }
   14167         2159 : }
   14168              : 
   14169              : bool
   14170          329 : c_check_in_current_scope (tree decl)
   14171              : {
   14172          329 :   struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (decl));
   14173          329 :   return b != NULL && B_IN_CURRENT_SCOPE (b);
   14174              : }
   14175              : 
   14176              : /* Search for loop or switch names.  BEFORE_LABELS is last statement before
   14177              :    possible labels and SWITCH_P true for a switch, false for loops.
   14178              :    Searches through last statements in cur_stmt_list, stops when seeing
   14179              :    BEFORE_LABELs, or statement other than LABEL_EXPR or CASE_LABEL_EXPR.
   14180              :    Returns number of loop/switch names found and if any are found, sets
   14181              :    *LAST_P to the canonical loop/switch name LABEL_DECL.  */
   14182              : 
   14183              : int
   14184       529210 : c_get_loop_names (tree before_labels, bool switch_p, tree *last_p)
   14185              : {
   14186       529210 :   *last_p = NULL_TREE;
   14187      1058420 :   if (!building_stmt_list_p ()
   14188       529210 :       || !STATEMENT_LIST_HAS_LABEL (cur_stmt_list)
   14189       550020 :       || before_labels == void_list_node)
   14190              :     return 0;
   14191              : 
   14192        20810 :   int ret = 0;
   14193        20810 :   tree last = NULL_TREE;
   14194        20810 :   for (tree_stmt_iterator tsi = tsi_last (cur_stmt_list);
   14195        29156 :        !tsi_end_p (tsi); tsi_prev (&tsi))
   14196              :     {
   14197        28291 :       tree stmt = tsi_stmt (tsi);
   14198        28291 :       if (stmt == before_labels)
   14199              :         break;
   14200         8346 :       else if (TREE_CODE (stmt) == LABEL_EXPR)
   14201              :         {
   14202         1175 :           if (last == NULL_TREE)
   14203          981 :             last = LABEL_EXPR_LABEL (stmt);
   14204              :           else
   14205              :             {
   14206          194 :               loop_names.safe_push (LABEL_EXPR_LABEL (stmt));
   14207          194 :               ++ret;
   14208              :             }
   14209              :         }
   14210         7171 :       else if (TREE_CODE (stmt) != CASE_LABEL_EXPR
   14211         4840 :                && TREE_CODE (stmt) != DEBUG_BEGIN_STMT)
   14212              :         break;
   14213              :     }
   14214        20810 :   if (last)
   14215              :     {
   14216          981 :       if (switch_p)
   14217          160 :         C_DECL_SWITCH_NAME (last) = 1;
   14218              :       else
   14219          821 :         C_DECL_LOOP_NAME (last) = 1;
   14220          981 :       loop_names.safe_push (last);
   14221          981 :       ++ret;
   14222          981 :       if (loop_names.length () > 16)
   14223              :         {
   14224           20 :           unsigned int first = 0, i;
   14225           20 :           tree l, c = NULL_TREE;
   14226           20 :           if (loop_names_hash == NULL)
   14227            8 :             loop_names_hash = new decl_tree_map (ret);
   14228              :           else
   14229           12 :             first = loop_names.length () - ret;
   14230          210 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14231              :             {
   14232          170 :               if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14233           48 :                 c = l;
   14234          170 :               gcc_checking_assert (c);
   14235          170 :               loop_names_hash->put (l, c);
   14236          170 :               if (i == first)
   14237              :                 break;
   14238              :             }
   14239              :         }
   14240          981 :       *last_p = last;
   14241              :     }
   14242              :   return ret;
   14243              : }
   14244              : 
   14245              : /* Undoes what get_loop_names did when it returned NUM_NAMES.  */
   14246              : 
   14247              : void
   14248          981 : c_release_loop_names (int num_names)
   14249              : {
   14250          981 :   unsigned len = loop_names.length () - num_names;
   14251          981 :   if (loop_names_hash)
   14252              :     {
   14253           20 :       if (len <= 16)
   14254              :         {
   14255            8 :           delete loop_names_hash;
   14256            8 :           loop_names_hash = NULL;
   14257              :         }
   14258              :       else
   14259              :         {
   14260           12 :           unsigned int i;
   14261           12 :           tree l;
   14262           42 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14263              :             {
   14264           30 :               loop_names_hash->remove (l);
   14265           30 :               if (i == len)
   14266              :                 break;
   14267              :             }
   14268              :         }
   14269              :     }
   14270          981 :   loop_names.truncate (len);
   14271          981 : }
   14272              : 
   14273              : /* Finish processing of break or continue identifier operand.
   14274              :    NAME is the identifier operand of break or continue and
   14275              :    IS_BREAK is true iff it is break stmt.  Returns the operand
   14276              :    to use for BREAK_STMT or CONTINUE_STMT, either NULL_TREE or
   14277              :    canonical loop/switch name LABEL_DECL.  */
   14278              : 
   14279              : tree
   14280          316 : c_finish_bc_name (location_t loc, tree name, bool is_break)
   14281              : {
   14282          316 :   tree label = NULL_TREE, lab;
   14283          457 :   pedwarn_c23 (loc, OPT_Wpedantic,
   14284              :                "ISO C does not support %qs statement with an identifier "
   14285              :                "operand before C2Y", is_break ? "break" : "continue");
   14286              : 
   14287              :   /* If I_LABEL_DECL is NULL or not from current function, don't waste time
   14288              :      trying to find it among loop_names, it can't be there.  */
   14289          316 :   if (!loop_names.is_empty ()
   14290          296 :       && current_function_scope
   14291          296 :       && (lab = I_LABEL_DECL (name))
   14292          290 :       && DECL_CONTEXT (lab) == current_function_decl)
   14293              :     {
   14294          280 :       unsigned int i;
   14295          280 :       tree l, c = NULL_TREE;
   14296          280 :       if (loop_names_hash)
   14297              :         {
   14298           86 :           if (tree *val = loop_names_hash->get (lab))
   14299           86 :             label = *val;
   14300              :         }
   14301              :       else
   14302          565 :         FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14303              :           {
   14304          363 :             if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14305              :               c = l;
   14306          363 :             gcc_checking_assert (c);
   14307          363 :             if (l == lab)
   14308              :               {
   14309              :                 label = c;
   14310              :                 break;
   14311              :               }
   14312              :           }
   14313          280 :       if (label)
   14314          272 :         TREE_USED (lab) = 1;
   14315              :     }
   14316          272 :   if (label == NULL_TREE)
   14317              :     {
   14318           44 :       auto_vec<const char *> candidates;
   14319           44 :       unsigned int i;
   14320           44 :       tree l, c = NULL_TREE;
   14321          115 :       FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14322              :         {
   14323           28 :           if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14324              :             c = l;
   14325           28 :           gcc_checking_assert (c);
   14326           42 :           if (is_break || C_DECL_LOOP_NAME (c))
   14327           25 :             candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l)));
   14328              :         }
   14329           44 :       const char *hint = find_closest_string (IDENTIFIER_POINTER (name),
   14330              :                                               &candidates);
   14331           44 :       if (hint)
   14332              :         {
   14333           22 :           gcc_rich_location richloc (loc);
   14334           22 :           richloc.add_fixit_replace (hint);
   14335           22 :           if (is_break)
   14336           11 :             error_at (&richloc, "%<break%> statement operand %qE does not "
   14337              :                                 "refer to a named loop or %<switch%>; "
   14338              :                                 "did you mean %qs?", name, hint);
   14339              :           else
   14340           11 :             error_at (&richloc, "%<continue%> statement operand %qE does not "
   14341              :                                 "refer to a named loop; did you mean %qs?",
   14342              :                       name, hint);
   14343           22 :         }
   14344           22 :       else if (is_break)
   14345           12 :         error_at (loc, "%<break%> statement operand %qE does not refer to a "
   14346              :                        "named loop or %<switch%>", name);
   14347              :       else
   14348           10 :         error_at (loc, "%<continue%> statement operand %qE does not refer to "
   14349              :                        "a named loop", name);
   14350           44 :     }
   14351          272 :   else if (!C_DECL_LOOP_NAME (label) && !is_break)
   14352              :     {
   14353            2 :       auto_diagnostic_group d;
   14354            2 :       error_at (loc, "%<continue%> statement operand %qE refers to a named "
   14355              :                      "%<switch%>", name);
   14356            2 :       inform (DECL_SOURCE_LOCATION (label), "%<switch%> name defined here");
   14357            2 :       label = NULL_TREE;
   14358            2 :     }
   14359          270 :   else if (!C_DECL_LOOP_SWITCH_NAME_VALID (label))
   14360              :     {
   14361           18 :       auto_diagnostic_group d;
   14362           18 :       if (C_DECL_LOOP_NAME (label))
   14363              :         {
   14364           16 :           error_at (loc, "%qs statement operand %qE refers to a loop outside "
   14365              :                          "of its body", is_break ? "break" : "continue", name);
   14366           16 :           inform (DECL_SOURCE_LOCATION (label), "loop name defined here");
   14367              :         }
   14368              :       else
   14369              :         {
   14370            2 :           error_at (loc, "%<break%> statement operand %qE refers to a "
   14371              :                          "%<switch%> outside of its body", name);
   14372            2 :           inform (DECL_SOURCE_LOCATION (label),
   14373              :                   "%<switch%> name defined here");
   14374              :         }
   14375           18 :       label = NULL_TREE;
   14376           18 :     }
   14377          252 :   else if (label == loop_names.last () && (in_statement & IN_NAMED_STMT) != 0)
   14378              :     /* If it is just a fancy reference to the innermost construct, handle it
   14379              :        just like break; or continue; though tracking cheaply what is the
   14380              :        innermost loop for continue when nested in switches would require
   14381              :        another global variable and updating it.  */
   14382              :     label = NULL_TREE;
   14383              :   else
   14384           98 :     C_DECL_LOOP_SWITCH_NAME_USED (label) = 1;
   14385          316 :   return label;
   14386              : }
   14387              : 
   14388              : #include "gt-c-c-decl.h"
        

Generated by: LCOV version 2.5.0-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.