LCOV - code coverage report
Current view: top level - gcc/c - c-decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 6398 5904
Test Date: 2026-05-30 15:37:04 Functions: 93.1 % 188 175
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for C compiler.
       2              :    Copyright (C) 1988-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : /* Process declarations and symbol lookup for C front end.
      21              :    Also constructs types; the standard scalar types at initialization,
      22              :    and structure, union, array and enum types when they are declared.  */
      23              : 
      24              : /* ??? not all decl nodes are given the most useful possible
      25              :    line numbers.  For example, the CONST_DECLs for enum values.  */
      26              : 
      27              : #include "config.h"
      28              : #define INCLUDE_STRING
      29              : #include "system.h"
      30              : #include "coretypes.h"
      31              : #include "target.h"
      32              : #include "function.h"
      33              : #include "c-tree.h"
      34              : #include "timevar.h"
      35              : #include "stringpool.h"
      36              : #include "cgraph.h"
      37              : #include "intl.h"
      38              : #include "print-tree.h"
      39              : #include "stor-layout.h"
      40              : #include "varasm.h"
      41              : #include "attribs.h"
      42              : #include "toplev.h"
      43              : #include "debug.h"
      44              : #include "c-family/c-objc.h"
      45              : #include "c-family/c-pragma.h"
      46              : #include "c-family/c-ubsan.h"
      47              : #include "c-lang.h"
      48              : #include "langhooks.h"
      49              : #include "tree-iterator.h"
      50              : #include "dumpfile.h"
      51              : #include "plugin.h"
      52              : #include "c-family/c-ada-spec.h"
      53              : #include "builtins.h"
      54              : #include "spellcheck-tree.h"
      55              : #include "gcc-rich-location.h"
      56              : #include "asan.h"
      57              : #include "c-family/name-hint.h"
      58              : #include "c-family/known-headers.h"
      59              : #include "c-family/c-spellcheck.h"
      60              : #include "context.h"  /* For 'g'.  */
      61              : #include "omp-general.h"
      62              : #include "omp-offload.h"  /* For offload_vars.  */
      63              : #include "c-parser.h"
      64              : #include "gcc-urlifier.h"
      65              : 
      66              : #include "tree-pretty-print.h"
      67              : 
      68              : /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
      69              : enum decl_context
      70              : { NORMAL,                       /* Ordinary declaration */
      71              :   FUNCDEF,                      /* Function definition */
      72              :   PARM,                         /* Declaration of parm before function body */
      73              :   FIELD,                        /* Declaration inside struct or union */
      74              :   TYPENAME,                     /* Typename (inside cast or sizeof)  */
      75              :   GENERIC_ASSOC };              /* Typename in generic association  */
      76              : 
      77              : /* States indicating how grokdeclarator() should handle declspecs marked
      78              :    with __attribute__((deprecated)) or __attribute__((unavailable)).
      79              :    An object declared as __attribute__((unavailable)) should suppress
      80              :    any reports of being declared  with unavailable or deprecated items.
      81              :    An object declared as __attribute__((deprecated)) should suppress
      82              :    warnings of uses of other deprecated items.  */
      83              : 
      84              : enum deprecated_states {
      85              :   DEPRECATED_NORMAL,
      86              :   DEPRECATED_SUPPRESS,
      87              :   UNAVAILABLE_DEPRECATED_SUPPRESS
      88              : };
      89              : 
      90              : 
      91              : /* Nonzero if we have seen an invalid cross reference
      92              :    to a struct, union, or enum, but not yet printed the message.  */
      93              : tree pending_invalid_xref;
      94              : 
      95              : /* File and line to appear in the eventual error message.  */
      96              : location_t pending_invalid_xref_location;
      97              : 
      98              : /* The file and line that the prototype came from if this is an
      99              :    old-style definition; used for diagnostics in
     100              :    store_parm_decls_oldstyle.  */
     101              : 
     102              : static location_t current_function_prototype_locus;
     103              : 
     104              : /* Whether this prototype was built-in.  */
     105              : 
     106              : static bool current_function_prototype_built_in;
     107              : 
     108              : /* The argument type information of this prototype.  */
     109              : 
     110              : static tree current_function_prototype_arg_types;
     111              : 
     112              : /* The argument information structure for the function currently being
     113              :    defined.  */
     114              : 
     115              : static struct c_arg_info *current_function_arg_info;
     116              : 
     117              : /* The obstack on which parser and related data structures, which are
     118              :    not live beyond their top-level declaration or definition, are
     119              :    allocated.  */
     120              : struct obstack parser_obstack;
     121              : 
     122              : /* The current statement tree.  */
     123              : 
     124              : static GTY(()) struct stmt_tree_s c_stmt_tree;
     125              : 
     126              : /* Zero if we are not in an iteration or switch statement, otherwise
     127              :    a bitmask.  See bitmask definitions in c-tree.h.  */
     128              : unsigned char in_statement;
     129              : 
     130              : /* A list of decls to be made automatically visible in each file scope.  */
     131              : static GTY(()) tree visible_builtins;
     132              : 
     133              : /* Set to 0 at beginning of a function definition, set to 1 if
     134              :    a return statement that specifies a return value is seen.  */
     135              : 
     136              : int current_function_returns_value;
     137              : 
     138              : /* Set to 0 at beginning of a function definition, set to 1 if
     139              :    a return statement with no argument is seen.  */
     140              : 
     141              : int current_function_returns_null;
     142              : 
     143              : /* Set to 0 at beginning of a function definition, set to 1 if
     144              :    a call to a noreturn function is seen.  */
     145              : 
     146              : int current_function_returns_abnormally;
     147              : 
     148              : /* Set to nonzero by `grokdeclarator' for a function
     149              :    whose return type is defaulted, if warnings for this are desired.  */
     150              : 
     151              : static int warn_about_return_type;
     152              : 
     153              : /* Nonzero when the current toplevel function contains a declaration
     154              :    of a nested function which is never defined.  */
     155              : 
     156              : static bool undef_nested_function;
     157              : 
     158              : /* Vector of implicit "omp declare target" attributes to be added into
     159              :    the attribute lists.  */
     160              : vec<c_omp_declare_target_attr, va_gc> *current_omp_declare_target_attribute;
     161              : 
     162              : /* Vector of
     163              :    #pragma omp begin assumes ... #pragma omp end assumes regions
     164              :    we are in.  */
     165              : vec<c_omp_begin_assumes_data, va_gc> *current_omp_begin_assumes;
     166              : 
     167              : /* Vector of "omp begin/end declare variant" blocks we are in.  */
     168              : vec<c_omp_declare_variant_attr, va_gc> *current_omp_declare_variant_attribute;
     169              : 
     170              : /* Vector of loop names with C_DECL_LOOP_NAME or C_DECL_SWITCH_NAME marked
     171              :    LABEL_DECL as the last and canonical for each loop or switch.  */
     172              : static vec<tree> loop_names;
     173              : 
     174              : /* Hash table mapping LABEL_DECLs to the canonical LABEL_DECLs if LOOP_NAMES
     175              :    vector becomes too long.  */
     176              : static decl_tree_map *loop_names_hash;
     177              : 
     178              : /* Each c_binding structure describes one binding of an identifier to
     179              :    a decl.  All the decls in a scope - irrespective of namespace - are
     180              :    chained together by the ->prev field, which (as the name implies)
     181              :    runs in reverse order.  All the decls in a given namespace bound to
     182              :    a given identifier are chained by the ->shadowed field, which runs
     183              :    from inner to outer scopes.
     184              : 
     185              :    The ->decl field usually points to a DECL node, but there are two
     186              :    exceptions.  In the namespace of type tags, the bound entity is a
     187              :    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
     188              :    identifier is encountered, it is bound to error_mark_node to
     189              :    suppress further errors about that identifier in the current
     190              :    function.
     191              : 
     192              :    The ->u.type field stores the type of the declaration in this scope;
     193              :    if NULL, the type is the type of the ->decl field.  This is only of
     194              :    relevance for objects with external or internal linkage which may
     195              :    be redeclared in inner scopes, forming composite types that only
     196              :    persist for the duration of those scopes.  In the external scope,
     197              :    this stores the composite of all the types declared for this
     198              :    object, visible or not.  The ->inner_comp field (used only at file
     199              :    scope) stores whether an incomplete array type at file scope was
     200              :    completed at an inner scope to an array size other than 1.
     201              : 
     202              :    The ->u.label field is used for labels.  It points to a structure
     203              :    which stores additional information used for warnings.
     204              : 
     205              :    The depth field is copied from the scope structure that holds this
     206              :    decl.  It is used to preserve the proper ordering of the ->shadowed
     207              :    field (see bind()) and also for a handful of special-case checks.
     208              :    Finally, the invisible bit is true for a decl which should be
     209              :    ignored for purposes of normal name lookup, and the nested bit is
     210              :    true for a decl that's been bound a second time in an inner scope;
     211              :    in all such cases, the binding in the outer scope will have its
     212              :    invisible bit true.  */
     213              : 
     214              : struct GTY((chain_next ("%h.prev"))) c_binding {
     215              :   union GTY(()) {               /* first so GTY desc can use decl */
     216              :     tree GTY((tag ("0"))) type; /* the type in this scope */
     217              :     struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */
     218              :   } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u;
     219              :   tree decl;                    /* the decl bound */
     220              :   tree id;                      /* the identifier it's bound to */
     221              :   struct c_binding *prev;       /* the previous decl in this scope */
     222              :   struct c_binding *shadowed;   /* the innermost decl shadowed by this one */
     223              :   unsigned int depth : 28;      /* depth of this scope */
     224              :   BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
     225              :   BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
     226              :   BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
     227              :   BOOL_BITFIELD in_struct : 1;  /* currently defined as struct field */
     228              :   location_t locus;             /* location for nested bindings */
     229              : };
     230              : #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
     231              : #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
     232              : #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
     233              : #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
     234              : 
     235              : /* Each C symbol points to three linked lists of c_binding structures.
     236              :    These describe the values of the identifier in the three different
     237              :    namespaces defined by the language.  */
     238              : 
     239              : struct GTY(()) lang_identifier {
     240              :   struct c_common_identifier common_id;
     241              :   struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
     242              :   struct c_binding *tag_binding;    /* struct/union/enum tags */
     243              :   struct c_binding *label_binding;  /* labels */
     244              : };
     245              : 
     246              : /* Validate c-lang.cc's assumptions.  */
     247              : extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
     248              : [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
     249              : 
     250              : /* The binding oracle; see c-tree.h.  */
     251              : void (*c_binding_oracle) (enum c_oracle_request, tree identifier);
     252              : 
     253              : /* This flag is set on an identifier if we have previously asked the
     254              :    binding oracle for this identifier's symbol binding.  */
     255              : #define I_SYMBOL_CHECKED(node) \
     256              :   (TREE_LANG_FLAG_4 (IDENTIFIER_NODE_CHECK (node)))
     257              : 
     258              : static inline struct c_binding* *
     259   4562753349 : i_symbol_binding (tree node)
     260              : {
     261   4562753349 :   struct lang_identifier *lid
     262   4562753349 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     263              : 
     264   4562753349 :   if (lid->symbol_binding == NULL
     265   1681629358 :       && c_binding_oracle != NULL
     266   4562753349 :       && !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   4562753349 :   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      4549160 : i_tag_binding (tree node)
     289              : {
     290      4549160 :   struct lang_identifier *lid
     291      4549160 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     292              : 
     293      4549160 :   if (lid->tag_binding == NULL
     294      1260096 :       && c_binding_oracle != NULL
     295      4549160 :       && !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      4549160 :   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       360593 : i_label_binding (tree node)
     318              : {
     319       360593 :   struct lang_identifier *lid
     320       360593 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     321              : 
     322       360593 :   if (lid->label_binding == NULL
     323        48086 :       && c_binding_oracle != NULL
     324       360593 :       && !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       360593 :   return &lid->label_binding;
     333              : }
     334              : 
     335              : #define I_LABEL_BINDING(node) (*i_label_binding (node))
     336              : 
     337              : #define I_LABEL_DECL(node) \
     338              :  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
     339              : 
     340              : /* Used by C_TOKEN_VEC tree.  */
     341              : struct GTY (()) c_tree_token_vec {
     342              :   struct tree_base base;
     343              :   vec<c_token, va_gc> *tokens;
     344              : };
     345              : 
     346              : STATIC_ASSERT (sizeof (c_tree_token_vec) == sizeof (c_tree_token_vec_struct));
     347              : STATIC_ASSERT (offsetof (c_tree_token_vec, tokens)
     348              :                == offsetof (c_tree_token_vec_struct, tokens));
     349              : 
     350              : /* The resulting tree type.  */
     351              : 
     352              : union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE + 2 * (TREE_CODE (&%h.generic) == C_TOKEN_VEC)"),
     353              :        chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node
     354              :  {
     355              :   union tree_node GTY ((tag ("0"),
     356              :                         desc ("tree_node_structure (&%h)")))
     357              :     generic;
     358              :   struct lang_identifier GTY ((tag ("1"))) identifier;
     359              :   struct c_tree_token_vec GTY ((tag ("2"))) c_token_vec;
     360              : };
     361              : 
     362              : /* Langhook for tree_size.  */
     363              : size_t
     364          911 : c_tree_size (enum tree_code code)
     365              : {
     366          911 :   gcc_checking_assert (code >= NUM_TREE_CODES);
     367          911 :   switch (code)
     368              :     {
     369              :     case C_TOKEN_VEC: return sizeof (c_tree_token_vec);
     370            0 :     default:
     371            0 :       switch (TREE_CODE_CLASS (code))
     372              :         {
     373              :         case tcc_declaration: return sizeof (tree_decl_non_common);
     374            0 :         case tcc_type: return sizeof (tree_type_non_common);
     375            0 :         default: gcc_unreachable ();
     376              :         }
     377              :     }
     378              : }
     379              : 
     380              : /* Track bindings and other things that matter for goto warnings.  For
     381              :    efficiency, we do not gather all the decls at the point of
     382              :    definition.  Instead, we point into the bindings structure.  As
     383              :    scopes are popped, we update these structures and gather the decls
     384              :    that matter at that time.  */
     385              : 
     386              : struct GTY(()) c_spot_bindings {
     387              :   /* The currently open scope which holds bindings defined when the
     388              :      label was defined or the goto statement was found.  */
     389              :   struct c_scope *scope;
     390              :   /* The bindings in the scope field which were defined at the point
     391              :      of the label or goto.  This lets us look at older or newer
     392              :      bindings in the scope, as appropriate.  */
     393              :   struct c_binding *bindings_in_scope;
     394              :   /* The number of statement expressions that have started since this
     395              :      label or goto statement was defined.  This is zero if we are at
     396              :      the same statement expression level.  It is positive if we are in
     397              :      a statement expression started since this spot.  It is negative
     398              :      if this spot was in a statement expression and we have left
     399              :      it.  */
     400              :   int stmt_exprs;
     401              :   /* Whether we started in a statement expression but are no longer in
     402              :      it.  This is set to true if stmt_exprs ever goes negative.  */
     403              :   bool left_stmt_expr;
     404              : };
     405              : 
     406              : /* This structure is used to keep track of bindings seen when a goto
     407              :    statement is defined.  This is only used if we see the goto
     408              :    statement before we see the label.  */
     409              : 
     410              : struct GTY(()) c_goto_bindings {
     411              :   /* The location of the goto statement.  */
     412              :   location_t loc;
     413              :   /* The bindings of the goto statement.  */
     414              :   struct c_spot_bindings goto_bindings;
     415              : };
     416              : 
     417              : typedef struct c_goto_bindings *c_goto_bindings_p;
     418              : 
     419              : /* The additional information we keep track of for a label binding.
     420              :    These fields are updated as scopes are popped.  */
     421              : 
     422              : struct GTY(()) c_label_vars {
     423              :   /* The shadowed c_label_vars, when one label shadows another (which
     424              :      can only happen using a __label__ declaration).  */
     425              :   struct c_label_vars *shadowed;
     426              :   /* The bindings when the label was defined.  */
     427              :   struct c_spot_bindings label_bindings;
     428              :   /* A list of decls that we care about: decls about which we should
     429              :      warn if a goto branches to this label from later in the function.
     430              :      Decls are added to this list as scopes are popped.  We only add
     431              :      the decls that matter.  */
     432              :   vec<tree, va_gc> *decls_in_scope;
     433              :   /* A list of goto statements to this label.  This is only used for
     434              :      goto statements seen before the label was defined, so that we can
     435              :      issue appropriate warnings for them.  */
     436              :   vec<c_goto_bindings_p, va_gc> *gotos;
     437              : };
     438              : 
     439              : /* Each c_scope structure describes the complete contents of one
     440              :    scope.  Four scopes are distinguished specially: the innermost or
     441              :    current scope, the innermost function scope, the file scope (always
     442              :    the second to outermost) and the outermost or external scope.
     443              : 
     444              :    Most declarations are recorded in the current scope.
     445              : 
     446              :    All normal label declarations are recorded in the innermost
     447              :    function scope, as are bindings of undeclared identifiers to
     448              :    error_mark_node.  (GCC permits nested functions as an extension,
     449              :    hence the 'innermost' qualifier.)  Explicitly declared labels
     450              :    (using the __label__ extension) appear in the current scope.
     451              : 
     452              :    Being in the file scope (current_scope == file_scope) causes
     453              :    special behavior in several places below.  Also, under some
     454              :    conditions the Objective-C front end records declarations in the
     455              :    file scope even though that isn't the current scope.
     456              : 
     457              :    All declarations with external linkage are recorded in the external
     458              :    scope, even if they aren't visible there; this models the fact that
     459              :    such declarations are visible to the entire program, and (with a
     460              :    bit of cleverness, see pushdecl) allows diagnosis of some violations
     461              :    of C99 6.2.2p7 and 6.2.7p2:
     462              : 
     463              :      If, within the same translation unit, the same identifier appears
     464              :      with both internal and external linkage, the behavior is
     465              :      undefined.
     466              : 
     467              :      All declarations that refer to the same object or function shall
     468              :      have compatible type; otherwise, the behavior is undefined.
     469              : 
     470              :    Initially only the built-in declarations, which describe compiler
     471              :    intrinsic functions plus a subset of the standard library, are in
     472              :    this scope.
     473              : 
     474              :    The order of the blocks list matters, and it is frequently appended
     475              :    to.  To avoid having to walk all the way to the end of the list on
     476              :    each insertion, or reverse the list later, we maintain a pointer to
     477              :    the last list entry.  (FIXME: It should be feasible to use a reversed
     478              :    list here.)
     479              : 
     480              :    The bindings list is strictly in reverse order of declarations;
     481              :    pop_scope relies on this.  */
     482              : 
     483              : 
     484              : struct GTY((chain_next ("%h.outer"))) c_scope {
     485              :   /* The scope containing this one.  */
     486              :   struct c_scope *outer;
     487              : 
     488              :   /* The next outermost function scope.  */
     489              :   struct c_scope *outer_function;
     490              : 
     491              :   /* All bindings in this scope.  */
     492              :   struct c_binding *bindings;
     493              : 
     494              :   /* For each scope (except the global one), a chain of BLOCK nodes
     495              :      for all the scopes that were entered and exited one level down.  */
     496              :   tree blocks;
     497              :   tree blocks_last;
     498              : 
     499              :   /* The depth of this scope.  Used to keep the ->shadowed chain of
     500              :      bindings sorted innermost to outermost.  */
     501              :   unsigned int depth : 28;
     502              : 
     503              :   /* True if we are currently filling this scope with parameter
     504              :      declarations.  */
     505              :   BOOL_BITFIELD parm_flag : 1;
     506              : 
     507              :   /* True if we saw [*] in this scope.  Used to give an error messages
     508              :      if these appears in a function definition.  */
     509              :   BOOL_BITFIELD had_vla_unspec : 1;
     510              : 
     511              :   /* True if we parsed a list of forward parameter decls in this scope.  */
     512              :   BOOL_BITFIELD had_forward_parm_decls : 1;
     513              : 
     514              :   /* True if this is the outermost block scope of a function body.
     515              :      This scope contains the parameters, the local variables declared
     516              :      in the outermost block, and all the labels (except those in
     517              :      nested functions, or declared at block scope with __label__).  */
     518              :   BOOL_BITFIELD function_body : 1;
     519              : 
     520              :   /* True means make a BLOCK for this scope no matter what.  */
     521              :   BOOL_BITFIELD keep : 1;
     522              : 
     523              :   /* True means that an unsuffixed float constant is _Decimal64.  */
     524              :   BOOL_BITFIELD float_const_decimal64 : 1;
     525              : 
     526              :   /* True if this scope has any label bindings.  This is used to speed
     527              :      up searching for labels when popping scopes, particularly since
     528              :      labels are normally only found at function scope.  */
     529              :   BOOL_BITFIELD has_label_bindings : 1;
     530              : 
     531              :   /* True if we should issue a warning if a goto statement crosses any
     532              :      of the bindings.  We still need to check the list of bindings to
     533              :      find the specific ones we need to warn about.  This is true if
     534              :      decl_jump_unsafe would return true for any of the bindings.  This
     535              :      is used to avoid looping over all the bindings unnecessarily.  */
     536              :   BOOL_BITFIELD has_jump_unsafe_decl : 1;
     537              : };
     538              : 
     539              : /* The scope currently in effect.  */
     540              : 
     541              : static GTY(()) struct c_scope *current_scope;
     542              : 
     543              : /* The innermost function scope.  Ordinary (not explicitly declared)
     544              :    labels, bindings to error_mark_node, and the lazily-created
     545              :    bindings of __func__ and its friends get this scope.  */
     546              : 
     547              : static GTY(()) struct c_scope *current_function_scope;
     548              : 
     549              : /* The C file scope.  This is reset for each input translation unit.  */
     550              : 
     551              : static GTY(()) struct c_scope *file_scope;
     552              : 
     553              : /* The outermost scope.  This is used for all declarations with
     554              :    external linkage, and only these, hence the name.  */
     555              : 
     556              : static GTY(()) struct c_scope *external_scope;
     557              : 
     558              : /* A chain of c_scope structures awaiting reuse.  */
     559              : 
     560              : static GTY((deletable)) struct c_scope *scope_freelist;
     561              : 
     562              : /* A chain of c_binding structures awaiting reuse.  */
     563              : 
     564              : static GTY((deletable)) struct c_binding *binding_freelist;
     565              : 
     566              : /* Append VAR to LIST in scope SCOPE.  */
     567              : #define SCOPE_LIST_APPEND(scope, list, decl) do {       \
     568              :   struct c_scope *s_ = (scope);                         \
     569              :   tree d_ = (decl);                                     \
     570              :   if (s_->list##_last)                                       \
     571              :     BLOCK_CHAIN (s_->list##_last) = d_;                      \
     572              :   else                                                  \
     573              :     s_->list = d_;                                   \
     574              :   s_->list##_last = d_;                                      \
     575              : } while (0)
     576              : 
     577              : /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE.  */
     578              : #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do {        \
     579              :   struct c_scope *t_ = (tscope);                                \
     580              :   struct c_scope *f_ = (fscope);                                \
     581              :   if (t_->to##_last)                                         \
     582              :     BLOCK_CHAIN (t_->to##_last) = f_->from;                       \
     583              :   else                                                          \
     584              :     t_->to = f_->from;                                            \
     585              :   t_->to##_last = f_->from##_last;                                \
     586              : } while (0)
     587              : 
     588              : /* A c_inline_static structure stores details of a static identifier
     589              :    referenced in a definition of a function that may be an inline
     590              :    definition if no subsequent declaration of that function uses
     591              :    "extern" or does not use "inline".  */
     592              : 
     593              : struct GTY((chain_next ("%h.next"))) c_inline_static {
     594              :   /* The location for a diagnostic.  */
     595              :   location_t location;
     596              : 
     597              :   /* The function that may be an inline definition.  */
     598              :   tree function;
     599              : 
     600              :   /* The object or function referenced.  */
     601              :   tree static_decl;
     602              : 
     603              :   /* What sort of reference this is.  */
     604              :   enum c_inline_static_type type;
     605              : 
     606              :   /* The next such structure or NULL.  */
     607              :   struct c_inline_static *next;
     608              : };
     609              : 
     610              : /* List of static identifiers used or referenced in functions that may
     611              :    be inline definitions.  */
     612              : static GTY(()) struct c_inline_static *c_inline_statics;
     613              : 
     614              : /* True means unconditionally make a BLOCK for the next scope pushed.  */
     615              : 
     616              : static bool keep_next_level_flag;
     617              : 
     618              : /* True means the next call to push_scope will be the outermost scope
     619              :    of a function body, so do not push a new scope, merely cease
     620              :    expecting parameter decls.  */
     621              : 
     622              : static bool next_is_function_body;
     623              : 
     624              : /* A vector of pointers to c_binding structures.  */
     625              : 
     626              : typedef struct c_binding *c_binding_ptr;
     627              : 
     628              : /* Information that we keep for a struct or union while it is being
     629              :    parsed.  */
     630              : 
     631      1179734 : 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      4354773 : c_struct_hasher::hash (tree type)
     660              : {
     661      4354773 :   inchash::hash hstate;
     662              : 
     663      4354773 :   hstate.add_int (TREE_CODE (type));
     664      4354773 :   tree tag = c_type_tag (type);
     665      4354773 :   hstate.add_object (tag);
     666              : 
     667      4354773 :   return hstate.end ();
     668              : }
     669              : 
     670              : /* Compare two RECORD or UNION types.  */
     671              : bool
     672     14650762 : c_struct_hasher::equal (tree t1,  tree t2)
     673              : {
     674     14650762 :   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     93785693 : add_stmt (tree t)
     701              : {
     702     93785693 :   enum tree_code code = TREE_CODE (t);
     703              : 
     704     93785693 :   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
     705              :     {
     706     93069046 :       if (!EXPR_HAS_LOCATION (t))
     707       155320 :         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     93785693 :   if (!building_stmt_list_p ())
     713            1 :     push_stmt_list ();
     714              : 
     715     93785693 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     716      1080045 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     717              : 
     718     93785693 :   append_to_statement_list_force (t, &cur_stmt_list);
     719              : 
     720     93785693 :   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    899153853 : decl_jump_unsafe (tree decl)
     732              : {
     733    899153853 :   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    899151817 :   if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl))
     742              :     return false;
     743              : 
     744    898232150 :   if (flag_openmp
     745     12584722 :       && VAR_P (decl)
     746    898263590 :       && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
     747              :     return true;
     748              : 
     749              :   /* Always warn about crossing variably modified types.  */
     750    888197958 :   if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
     751    910299211 :       && 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    898191624 :   if (warn_jump_misses_init
     757      6026117 :       && VAR_P (decl)
     758        10211 :       && !TREE_STATIC (decl)
     759    898197069 :       && DECL_INITIAL (decl) != NULL_TREE)
     760              :     return true;
     761              : 
     762              :   return false;
     763              : }
     764              : 
     765              : 
     766              : void
     767            0 : c_print_identifier (FILE *file, tree node, int indent)
     768              : {
     769            0 :   void (*save) (enum c_oracle_request, tree identifier);
     770              : 
     771              :   /* Temporarily hide any binding oracle.  Without this, calls to
     772              :      debug_tree from the debugger will end up calling into the oracle,
     773              :      making for a confusing debug session.  As the oracle isn't needed
     774              :      here for normal operation, it's simplest to suppress it.  */
     775            0 :   save = c_binding_oracle;
     776            0 :   c_binding_oracle = NULL;
     777              : 
     778            0 :   print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
     779            0 :   print_node (file, "tag", I_TAG_DECL (node), indent + 4);
     780            0 :   print_node (file, "label", I_LABEL_DECL (node), indent + 4);
     781            0 :   if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
     782              :     {
     783            0 :       tree rid = ridpointers[C_RID_CODE (node)];
     784            0 :       indent_to (file, indent + 4);
     785            0 :       fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
     786            0 :                (void *) rid, IDENTIFIER_POINTER (rid));
     787              :     }
     788              : 
     789            0 :   c_binding_oracle = save;
     790            0 : }
     791              : 
     792              : /* Establish that the scope contains declarations that are sensitive to
     793              :    jumps that cross a binding.  Together with decl_jump_unsafe, this is
     794              :    used to diagnose such jumps.  */
     795              : void
     796           93 : c_mark_decl_jump_unsafe_in_current_scope ()
     797              : {
     798           93 :   current_scope->has_jump_unsafe_decl = 1;
     799           93 : }
     800              : 
     801              : /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
     802              :    which may be any of several kinds of DECL or TYPE or error_mark_node,
     803              :    in the scope SCOPE.  */
     804              : static void
     805    899004698 : bind (tree name, tree decl, struct c_scope *scope, bool invisible,
     806              :       bool nested, location_t locus)
     807              : {
     808    899004698 :   struct c_binding *b, **here;
     809              : 
     810    899004698 :   if (binding_freelist)
     811              :     {
     812    231085115 :       b = binding_freelist;
     813    231085115 :       binding_freelist = b->prev;
     814              :     }
     815              :   else
     816    667919583 :     b = ggc_alloc<c_binding> ();
     817              : 
     818    899004698 :   b->shadowed = 0;
     819    899004698 :   b->decl = decl;
     820    899004698 :   b->id = name;
     821    899004698 :   b->depth = scope->depth;
     822    899004698 :   b->invisible = invisible;
     823    899004698 :   b->nested = nested;
     824    899004698 :   b->inner_comp = 0;
     825    899004698 :   b->in_struct = 0;
     826    899004698 :   b->locus = locus;
     827              : 
     828    899004698 :   b->u.type = NULL;
     829              : 
     830    899004698 :   b->prev = scope->bindings;
     831    899004698 :   scope->bindings = b;
     832              : 
     833    899004698 :   if (decl_jump_unsafe (decl))
     834        24210 :     scope->has_jump_unsafe_decl = 1;
     835              : 
     836    899004698 :   if (!name)
     837              :     return;
     838              : 
     839    890322346 :   switch (TREE_CODE (decl))
     840              :     {
     841        24072 :     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
     842       629364 :     case ENUMERAL_TYPE:
     843       629364 :     case UNION_TYPE:
     844       629364 :     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
     845    889668910 :     case VAR_DECL:
     846    889668910 :     case FUNCTION_DECL:
     847    889668910 :     case TYPE_DECL:
     848    889668910 :     case CONST_DECL:
     849    889668910 :     case PARM_DECL:
     850    889668910 :     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    890322390 :   while (*here && (*here)->depth > scope->depth)
     860           44 :     here = &(*here)->shadowed;
     861              : 
     862    890322346 :   b->shadowed = *here;
     863    890322346 :   *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    880746751 : free_binding_and_advance (struct c_binding *b)
     872              : {
     873    880746751 :   struct c_binding *prev = b->prev;
     874              : 
     875    880746751 :   memset (b, 0, sizeof (struct c_binding));
     876    880746751 :   b->prev = binding_freelist;
     877    880746751 :   binding_freelist = b;
     878              : 
     879    880746751 :   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        24072 : bind_label (tree name, tree label, struct c_scope *scope,
     886              :             struct c_label_vars *label_vars)
     887              : {
     888        24072 :   struct c_binding *b;
     889              : 
     890        24072 :   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
     891              :         UNKNOWN_LOCATION);
     892              : 
     893        24072 :   scope->has_label_bindings = true;
     894              : 
     895        24072 :   b = scope->bindings;
     896        24072 :   gcc_assert (b->decl == label);
     897        24072 :   label_vars->shadowed = b->u.label;
     898        24072 :   b->u.label = label_vars;
     899        24072 : }
     900              : 
     901              : /* Hook called at end of compilation to assume 1 elt
     902              :    for a file-scope tentative array defn that wasn't complete before.  */
     903              : 
     904              : void
     905         7498 : c_finish_incomplete_decl (tree decl)
     906              : {
     907         7498 :   if (VAR_P (decl))
     908              :     {
     909         7498 :       tree type = TREE_TYPE (decl);
     910         7498 :       if (type != error_mark_node
     911         7421 :           && TREE_CODE (type) == ARRAY_TYPE
     912         7226 :           && !DECL_EXTERNAL (decl)
     913         7587 :           && TYPE_DOMAIN (type) == NULL_TREE)
     914              :         {
     915           89 :           if (flag_isoc2y && !TREE_PUBLIC (decl))
     916            2 :             error_at (DECL_SOURCE_LOCATION (decl),
     917              :                       "array size missing in %q+D", decl);
     918              :           else
     919           87 :             warning_at (DECL_SOURCE_LOCATION (decl),
     920           87 :                         0, "array %q+D assumed to have one element", decl);
     921              : 
     922           89 :           complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
     923              : 
     924           89 :           relayout_decl (decl);
     925              :         }
     926              :     }
     927         7498 : }
     928              : 
     929              : /* Record that inline function FUNC contains a reference (location
     930              :    LOC) to static DECL (file-scope or function-local according to
     931              :    TYPE).  */
     932              : 
     933              : void
     934           36 : record_inline_static (location_t loc, tree func, tree decl,
     935              :                       enum c_inline_static_type type)
     936              : {
     937           36 :   c_inline_static *csi = ggc_alloc<c_inline_static> ();
     938           36 :   csi->location = loc;
     939           36 :   csi->function = func;
     940           36 :   csi->static_decl = decl;
     941           36 :   csi->type = type;
     942           36 :   csi->next = c_inline_statics;
     943           36 :   c_inline_statics = csi;
     944           36 : }
     945              : 
     946              : /* Check for references to static declarations in inline functions at
     947              :    the end of the translation unit and diagnose them if the functions
     948              :    are still inline definitions.  */
     949              : 
     950              : static void
     951       105531 : check_inline_statics (void)
     952              : {
     953       105531 :   struct c_inline_static *csi;
     954       105567 :   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       105531 :   c_inline_statics = NULL;
     974       105531 : }
     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       135120 : set_spot_bindings (struct c_spot_bindings *p, bool defining)
     981              : {
     982            0 :   if (defining)
     983              :     {
     984       127922 :       p->scope = current_scope;
     985        16874 :       p->bindings_in_scope = current_scope->bindings;
     986              :     }
     987              :   else
     988              :     {
     989         7198 :       p->scope = NULL;
     990         7198 :       p->bindings_in_scope = NULL;
     991              :     }
     992       135120 :   p->stmt_exprs = 0;
     993       135120 :   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    470612732 : 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       206045 :   p->scope = scope->outer;
    1013       206045 :   p->bindings_in_scope = p->scope->bindings;
    1014              : 
    1015       151663 :   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      2091991 : global_bindings_p (void)
    1052              : {
    1053      2091991 :   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        34896 : 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        34896 :   return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl));
    1065              : }
    1066              : 
    1067              : void
    1068        52291 : keep_next_level (void)
    1069              : {
    1070        52291 :   keep_next_level_flag = true;
    1071        52291 : }
    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       602351 : float_const_decimal64_p (void)
    1093              : {
    1094       602351 :   return current_scope->float_const_decimal64;
    1095              : }
    1096              : 
    1097              : /* Identify this scope as currently being filled with parameters.  */
    1098              : 
    1099              : void
    1100     87301454 : declare_parm_level (void)
    1101              : {
    1102     87301454 :   current_scope->parm_flag = true;
    1103     87301454 : }
    1104              : 
    1105              : void
    1106    128612900 : push_scope (void)
    1107              : {
    1108    128612900 :   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     36326428 :       current_scope->parm_flag         = false;
    1121     36326428 :       current_scope->function_body     = true;
    1122     36326428 :       current_scope->keep              = true;
    1123     36326428 :       current_scope->outer_function    = current_function_scope;
    1124     36326428 :       current_function_scope           = current_scope;
    1125              : 
    1126     36326428 :       keep_next_level_flag = false;
    1127     36326428 :       next_is_function_body = false;
    1128              : 
    1129              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1130     36326428 :       if (current_scope->outer)
    1131     36326428 :         current_scope->float_const_decimal64
    1132     36326428 :           = current_scope->outer->float_const_decimal64;
    1133              :       else
    1134            0 :         current_scope->float_const_decimal64 = false;
    1135              :     }
    1136              :   else
    1137              :     {
    1138     92286472 :       struct c_scope *scope;
    1139     92286472 :       if (scope_freelist)
    1140              :         {
    1141     91435317 :           scope = scope_freelist;
    1142     91435317 :           scope_freelist = scope->outer;
    1143              :         }
    1144              :       else
    1145       851155 :         scope = ggc_cleared_alloc<c_scope> ();
    1146              : 
    1147              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1148     92286472 :       if (current_scope)
    1149     92174945 :         scope->float_const_decimal64 = current_scope->float_const_decimal64;
    1150              :       else
    1151       111527 :         scope->float_const_decimal64 = false;
    1152              : 
    1153     92286472 :       scope->keep          = keep_next_level_flag;
    1154     92286472 :       scope->outer         = current_scope;
    1155     92286472 :       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     92286472 :       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     92286472 :       current_scope        = scope;
    1166     92286472 :       keep_next_level_flag = false;
    1167              :     }
    1168    128612900 : }
    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     92279641 : update_label_decls (struct c_scope *scope)
    1177              : {
    1178     92279641 :   struct c_scope *s;
    1179              : 
    1180     92279641 :   s = scope;
    1181    333091315 :   while (s != NULL)
    1182              :     {
    1183    281921391 :       if (s->has_label_bindings)
    1184              :         {
    1185       233270 :           struct c_binding *b;
    1186              : 
    1187      2160956 :           for (b = s->bindings; b != NULL; b = b->prev)
    1188              :             {
    1189      1927686 :               struct c_label_vars *label_vars;
    1190      1927686 :               struct c_binding *b1;
    1191      1927686 :               bool hjud;
    1192      1927686 :               unsigned int ix;
    1193      1927686 :               struct c_goto_bindings *g;
    1194              : 
    1195      1927686 :               if (TREE_CODE (b->decl) != LABEL_DECL)
    1196      1420522 :                 continue;
    1197       507164 :               label_vars = b->u.label;
    1198              : 
    1199       507164 :               b1 = label_vars->label_bindings.bindings_in_scope;
    1200       507164 :               if (label_vars->label_bindings.scope == NULL)
    1201              :                 hjud = false;
    1202              :               else
    1203       197105 :                 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
    1204       507164 :               if (update_spot_bindings (scope, &label_vars->label_bindings))
    1205              :                 {
    1206              :                   /* This label is defined in this scope.  */
    1207        54382 :                   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    472327016 :               FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1224    470257231 :                 update_spot_bindings (scope, &g->goto_bindings);
    1225              :             }
    1226              :         }
    1227              : 
    1228              :       /* Don't search beyond the current function.  */
    1229    281921391 :       if (s == current_function_scope)
    1230              :         break;
    1231              : 
    1232    240811674 :       s = s->outer;
    1233              :     }
    1234     92279641 : }
    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     92279641 : pop_scope (void)
    1243              : {
    1244     92279641 :   struct c_scope *scope = current_scope;
    1245     92279641 :   tree block, context, p;
    1246     92279641 :   struct c_binding *b;
    1247              : 
    1248     92279641 :   bool functionbody = scope->function_body;
    1249     92279641 :   bool keep = functionbody || scope->keep || scope->bindings;
    1250              : 
    1251     92279641 :   update_label_decls (scope);
    1252              : 
    1253              :   /* If appropriate, create a BLOCK to record the decls for the life
    1254              :      of this function.  */
    1255     92279641 :   block = NULL_TREE;
    1256     92279641 :   if (keep)
    1257              :     {
    1258     36816566 :       block = make_node (BLOCK);
    1259     36816566 :       BLOCK_SUBBLOCKS (block) = scope->blocks;
    1260     36816566 :       TREE_USED (block) = 1;
    1261              : 
    1262              :       /* In each subblock, record that this is its superior.  */
    1263     37096311 :       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
    1264       279745 :         BLOCK_SUPERCONTEXT (p) = block;
    1265              : 
    1266     36816566 :       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     92279641 :   if (scope->function_body)
    1283     36326427 :     context = current_function_decl;
    1284     55953214 :   else if (scope == file_scope)
    1285              :     {
    1286       105198 :       tree file_decl
    1287       105198 :         = build_translation_unit_decl (get_identifier (main_input_filename));
    1288       105198 :       context = file_decl;
    1289       105198 :       debug_hooks->register_main_translation_unit (file_decl);
    1290              :     }
    1291              :   else
    1292              :     context = block;
    1293              : 
    1294              :   /* Clear all bindings in this scope.  */
    1295    849328072 :   for (b = scope->bindings; b; b = free_binding_and_advance (b))
    1296              :     {
    1297    757048431 :       p = b->decl;
    1298    757048431 :       switch (TREE_CODE (p))
    1299              :         {
    1300        24072 :         case LABEL_DECL:
    1301              :           /* Warnings for unused labels, errors for undefined labels.  */
    1302        24072 :           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        24009 :             warn_for_unused_label (p);
    1309              : 
    1310              :           /* Labels go in BLOCK_VARS.  */
    1311        24072 :           DECL_CHAIN (p) = BLOCK_VARS (block);
    1312        24072 :           BLOCK_VARS (block) = p;
    1313        24072 :           gcc_assert (I_LABEL_BINDING (b->id) == b);
    1314        24072 :           I_LABEL_BINDING (b->id) = b->shadowed;
    1315              : 
    1316              :           /* Also pop back to the shadowed label_vars.  */
    1317        24072 :           release_tree_vector (b->u.label->decls_in_scope);
    1318        24072 :           b->u.label = b->u.label->shadowed;
    1319        24072 :           break;
    1320              : 
    1321      1428004 :         case ENUMERAL_TYPE:
    1322      1428004 :         case UNION_TYPE:
    1323      1428004 :         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      1428004 :           if (b->id)
    1328              :             {
    1329       627538 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    1330       627538 :               I_TAG_BINDING (b->id) = b->shadowed;
    1331              :             }
    1332              :           break;
    1333              : 
    1334    627184540 :         case FUNCTION_DECL:
    1335              :           /* Propagate TREE_ADDRESSABLE from nested functions to their
    1336              :              containing functions.  */
    1337    627184540 :           if (!TREE_ASM_WRITTEN (p)
    1338    627184540 :               && DECL_INITIAL (p) != NULL_TREE
    1339     72293554 :               && TREE_ADDRESSABLE (p)
    1340      3692029 :               && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
    1341    627184540 :               && DECL_ABSTRACT_ORIGIN (p) != p)
    1342            0 :             TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
    1343    627184540 :           if (!TREE_PUBLIC (p)
    1344       358726 :               && !DECL_INITIAL (p)
    1345          166 :               && !b->nested
    1346          135 :               && scope != file_scope
    1347    627184548 :               && scope != external_scope)
    1348              :             {
    1349            8 :               error ("nested function %q+D declared but never defined", p);
    1350            8 :               undef_nested_function = true;
    1351              :             }
    1352    627184532 :           else if (DECL_DECLARED_INLINE_P (p)
    1353     71107133 :                    && TREE_PUBLIC (p)
    1354    698132374 :                    && !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    627184540 :           goto common_symbol;
    1368              : 
    1369     10945712 :         case VAR_DECL:
    1370              :           /* Warnings for unused variables.  */
    1371      8391662 :           if ((!TREE_USED (p) || !DECL_READ_P (p))
    1372      2583236 :               && !warning_suppressed_p (p, OPT_Wunused_but_set_variable_)
    1373      2582724 :               && !DECL_IN_SYSTEM_HEADER (p)
    1374      2502317 :               && DECL_NAME (p)
    1375      2502317 :               && !DECL_ARTIFICIAL (p)
    1376      2501923 :               && scope != file_scope
    1377     12565473 :               && scope != external_scope)
    1378              :             {
    1379       739246 :               if (!TREE_USED (p))
    1380              :                 {
    1381       733527 :                   warning (OPT_Wunused_variable, "unused variable %q+D", p);
    1382       733527 :                   suppress_warning (p, OPT_Wunused_variable);
    1383              :                 }
    1384         5719 :               else if (DECL_CONTEXT (p) == current_function_decl)
    1385         5698 :                 warning_at (DECL_SOURCE_LOCATION (p),
    1386         5698 :                             OPT_Wunused_but_set_variable_,
    1387              :                             "variable %qD set but not used", p);
    1388              :             }
    1389              : 
    1390     10945712 :           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    655511792 :         case TYPE_DECL:
    1398    655511792 :         case CONST_DECL:
    1399     10945710 :         common_symbol:
    1400              :           /* All of these go in BLOCK_VARS, but only if this is the
    1401              :              binding in the home scope.  */
    1402    655511792 :           if (!b->nested)
    1403              :             {
    1404    394271194 :               DECL_CHAIN (p) = BLOCK_VARS (block);
    1405    394271194 :               BLOCK_VARS (block) = p;
    1406              :             }
    1407    261240598 :           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        14611 :               tree extp = copy_node (p);
    1412              : 
    1413        14611 :               DECL_EXTERNAL (extp) = 1;
    1414        14611 :               TREE_STATIC (extp) = 0;
    1415        14611 :               TREE_PUBLIC (extp) = 1;
    1416        14611 :               DECL_INITIAL (extp) = NULL_TREE;
    1417        14611 :               DECL_LANG_SPECIFIC (extp) = NULL;
    1418        14611 :               DECL_CONTEXT (extp) = current_function_decl;
    1419        14611 :               if (TREE_CODE (p) == FUNCTION_DECL)
    1420              :                 {
    1421        13057 :                   DECL_RESULT (extp) = NULL_TREE;
    1422        13057 :                   DECL_SAVED_TREE (extp) = NULL_TREE;
    1423        13057 :                   DECL_STRUCT_FUNCTION (extp) = NULL;
    1424              :                 }
    1425        14611 :               if (b->locus != UNKNOWN_LOCATION)
    1426        14596 :                 DECL_SOURCE_LOCATION (extp) = b->locus;
    1427        14611 :               DECL_CHAIN (extp) = BLOCK_VARS (block);
    1428        14611 :               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    655511792 :           if (scope == file_scope)
    1434    272617366 :               DECL_CONTEXT (p) = context;
    1435              : 
    1436    755596355 :           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    755596355 :         case PARM_DECL:
    1443    755596355 :         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    755596355 :           if (b->id)
    1447              :             {
    1448    752400238 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    1449    752400238 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    1450    752400238 :               if (b->shadowed && b->shadowed->u.type)
    1451      4776431 :                 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     92279641 :   if ((scope->function_body || scope == file_scope) && context)
    1463              :     {
    1464     36431623 :       DECL_INITIAL (context) = block;
    1465     36431623 :       BLOCK_SUPERCONTEXT (block) = context;
    1466              :     }
    1467     55848018 :   else if (scope->outer)
    1468              :     {
    1469     55742820 :       if (block)
    1470       279745 :         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     55463075 :       else if (scope->blocks)
    1475       359135 :         SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
    1476              :     }
    1477              : 
    1478              :   /* Pop the current scope, and free the structure for reuse.  */
    1479     92279641 :   current_scope = scope->outer;
    1480     92279641 :   if (scope->function_body)
    1481     36326427 :     current_function_scope = scope->outer_function;
    1482              : 
    1483     92279641 :   memset (scope, 0, sizeof (struct c_scope));
    1484     92279641 :   scope->outer = scope_freelist;
    1485     92279641 :   scope_freelist = scope;
    1486              : 
    1487     92279641 :   return block;
    1488              : }
    1489              : 
    1490              : void
    1491       105698 : push_file_scope (void)
    1492              : {
    1493       105698 :   tree decl;
    1494              : 
    1495       105698 :   if (file_scope)
    1496              :     return;
    1497              : 
    1498       105698 :   push_scope ();
    1499       105698 :   file_scope = current_scope;
    1500              : 
    1501       105698 :   start_fname_decls ();
    1502              : 
    1503    211533047 :   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
    1504    211427349 :     bind (DECL_NAME (decl), decl, file_scope,
    1505    211427349 :           /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
    1506              : }
    1507              : 
    1508              : void
    1509       105531 : pop_file_scope (void)
    1510              : {
    1511              :   /* In case there were missing closebraces, get us back to the global
    1512              :      binding level.  */
    1513       105536 :   while (current_scope != file_scope)
    1514            5 :     pop_scope ();
    1515              : 
    1516              :   /* __FUNCTION__ is defined at file scope ("").  This
    1517              :      call may not be necessary as my tests indicate it
    1518              :      still works without it.  */
    1519       105531 :   finish_fname_decls ();
    1520              : 
    1521       105531 :   check_inline_statics ();
    1522              : 
    1523              :   /* This is the point to write out a PCH if we're doing that.
    1524              :      In that case we do not want to do anything else.  */
    1525       105531 :   if (pch_file)
    1526              :     {
    1527          333 :       c_common_write_pch ();
    1528              :       /* Ensure even the callers don't try to finalize the CU.  */
    1529          333 :       flag_syntax_only = 1;
    1530          333 :       return;
    1531              :     }
    1532              : 
    1533              :   /* Pop off the file scope and close this translation unit.  */
    1534       105198 :   pop_scope ();
    1535       105198 :   file_scope = 0;
    1536              : 
    1537       105198 :   maybe_apply_pending_pragma_weaks ();
    1538              : }
    1539              : 
    1540              : /* Whether we are curently inside the initializer for an
    1541              :    underspecified object definition (C23 auto or constexpr).  */
    1542              : static bool in_underspecified_init;
    1543              : 
    1544              : /* Start an underspecified object definition for NAME at LOC.  This
    1545              :    means that NAME is shadowed inside its initializer, so neither the
    1546              :    definition being initialized, nor any definition from an outer
    1547              :    scope, may be referenced during that initializer.  Return state to
    1548              :    be passed to finish_underspecified_init.  If NAME is NULL_TREE, the
    1549              :    underspecified object is a (constexpr) compound literal; there is
    1550              :    no shadowing in that case, but all the other restrictions on
    1551              :    underspecified object definitions still apply.  */
    1552              : unsigned int
    1553          661 : start_underspecified_init (location_t loc, tree name)
    1554              : {
    1555          661 :   bool prev = in_underspecified_init;
    1556          661 :   bool ok;
    1557          661 :   if (name == NULL_TREE)
    1558              :     ok = true;
    1559              :   else
    1560              :     {
    1561          427 :       tree decl = build_decl (loc, VAR_DECL, name, error_mark_node);
    1562          427 :       C_DECL_UNDERSPECIFIED (decl) = 1;
    1563          427 :       struct c_scope *scope = current_scope;
    1564          427 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1565          427 :       if (b && B_IN_SCOPE (b, scope))
    1566              :         {
    1567            4 :           error_at (loc, "underspecified declaration of %qE, which is already "
    1568              :                     "declared in this scope", name);
    1569            4 :           ok = false;
    1570              :         }
    1571              :       else
    1572              :         {
    1573          423 :           bind (name, decl, scope, false, false, loc);
    1574          423 :           ok = true;
    1575              :         }
    1576              :     }
    1577          661 :   in_underspecified_init = true;
    1578          661 :   return ok | (prev << 1);
    1579              : }
    1580              : 
    1581              : /* Finish an underspecified object definition for NAME, before that
    1582              :    name is bound to the real declaration instead of a placeholder.
    1583              :    PREV_STATE is the value returned by the call to
    1584              :    start_underspecified_init.  If NAME is NULL_TREE, this means a
    1585              :    compound literal, as for start_underspecified_init.  */
    1586              : void
    1587          661 : finish_underspecified_init (tree name, unsigned int prev_state)
    1588              : {
    1589          661 :   if (name != NULL_TREE && (prev_state & 1))
    1590              :     {
    1591              :       /* A VAR_DECL was bound to the name to shadow any previous
    1592              :          declarations for the name; remove that binding now.  */
    1593          423 :       struct c_scope *scope = current_scope;
    1594          423 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1595          423 :       gcc_assert (b);
    1596          423 :       gcc_assert (B_IN_SCOPE (b, scope));
    1597          423 :       gcc_assert (VAR_P (b->decl));
    1598          423 :       gcc_assert (C_DECL_UNDERSPECIFIED (b->decl));
    1599          423 :       I_SYMBOL_BINDING (name) = b->shadowed;
    1600              :       /* In erroneous cases there may be other bindings added to this
    1601              :          scope during the initializer.  */
    1602          423 :       struct c_binding **p = &scope->bindings;
    1603          478 :       while (*p != b)
    1604           55 :         p = &((*p)->prev);
    1605          423 :       *p = free_binding_and_advance (*p);
    1606              :     }
    1607          661 :   in_underspecified_init = (prev_state & (1u << 1)) >> 1;
    1608          661 : }
    1609              : 
    1610              : /* Adjust the bindings for the start of a statement expression.  */
    1611              : 
    1612              : void
    1613        34875 : c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
    1614              : {
    1615        34875 :   struct c_scope *scope;
    1616              : 
    1617       235546 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1618              :     {
    1619       200671 :       struct c_binding *b;
    1620              : 
    1621       200671 :       if (!scope->has_label_bindings)
    1622       198260 :         continue;
    1623              : 
    1624        12792 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1625              :         {
    1626        10381 :           struct c_label_vars *label_vars;
    1627        10381 :           unsigned int ix;
    1628        10381 :           struct c_goto_bindings *g;
    1629              : 
    1630        10381 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1631         1612 :             continue;
    1632         8769 :           label_vars = b->u.label;
    1633         8769 :           ++label_vars->label_bindings.stmt_exprs;
    1634        12917 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1635         1795 :             ++g->goto_bindings.stmt_exprs;
    1636              :         }
    1637              :     }
    1638              : 
    1639        34875 :   if (switch_bindings != NULL)
    1640          173 :     ++switch_bindings->stmt_exprs;
    1641        34875 : }
    1642              : 
    1643              : /* Adjust the bindings for the end of a statement expression.  */
    1644              : 
    1645              : void
    1646        34875 : c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
    1647              : {
    1648        34875 :   struct c_scope *scope;
    1649              : 
    1650       200671 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1651              :     {
    1652       165796 :       struct c_binding *b;
    1653              : 
    1654       165796 :       if (!scope->has_label_bindings)
    1655       163150 :         continue;
    1656              : 
    1657        16268 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1658              :         {
    1659        13622 :           struct c_label_vars *label_vars;
    1660        13622 :           unsigned int ix;
    1661        13622 :           struct c_goto_bindings *g;
    1662              : 
    1663        13622 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1664         1672 :             continue;
    1665        11950 :           label_vars = b->u.label;
    1666        11950 :           --label_vars->label_bindings.stmt_exprs;
    1667        11950 :           if (label_vars->label_bindings.stmt_exprs < 0)
    1668              :             {
    1669         3322 :               label_vars->label_bindings.left_stmt_expr = true;
    1670         3322 :               label_vars->label_bindings.stmt_exprs = 0;
    1671              :             }
    1672        16150 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1673              :             {
    1674         1791 :               --g->goto_bindings.stmt_exprs;
    1675         1791 :               if (g->goto_bindings.stmt_exprs < 0)
    1676              :                 {
    1677          128 :                   g->goto_bindings.left_stmt_expr = true;
    1678          128 :                   g->goto_bindings.stmt_exprs = 0;
    1679              :                 }
    1680              :             }
    1681              :         }
    1682              :     }
    1683              : 
    1684        34875 :   if (switch_bindings != NULL)
    1685              :     {
    1686          173 :       --switch_bindings->stmt_exprs;
    1687          173 :       gcc_assert (switch_bindings->stmt_exprs >= 0);
    1688              :     }
    1689        34875 : }
    1690              : 
    1691              : /* Push a definition or a declaration of struct, union or enum tag "name".
    1692              :    "type" should be the type node.
    1693              :    We assume that the tag "name" is not already defined, and has a location
    1694              :    of LOC.
    1695              : 
    1696              :    Note that the definition may really be just a forward reference.
    1697              :    In that case, the TYPE_SIZE will be zero.  */
    1698              : 
    1699              : static void
    1700      1431961 : pushtag (location_t loc, tree name, tree type)
    1701              : {
    1702              :   /* Record the identifier as the type's name if it has none.  */
    1703      1431961 :   if (name && !TYPE_NAME (type))
    1704       629336 :     TYPE_NAME (type) = name;
    1705      1431961 :   bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc);
    1706              : 
    1707              :   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
    1708              :      tagged type we just added to the current scope.  This fake
    1709              :      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
    1710              :      to output a representation of a tagged type, and it also gives
    1711              :      us a convenient place to record the "scope start" address for the
    1712              :      tagged type, and it is used to track whether the type is used
    1713              :      in a non-local context via mark_decl_used.  */
    1714              : 
    1715      1431961 :   TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
    1716              :                                                 TYPE_DECL, NULL_TREE, type));
    1717              : 
    1718              :   /* An approximation for now, so we can tell this is a function-scope tag.
    1719              :      This will be updated in pop_scope.  */
    1720      1431961 :   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
    1721              : 
    1722      1431961 :   if (warn_cxx_compat && name != NULL_TREE)
    1723              :     {
    1724          633 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1725              : 
    1726          633 :       if (b != NULL
    1727           12 :           && b->decl != NULL_TREE
    1728           12 :           && TREE_CODE (b->decl) == TYPE_DECL
    1729           11 :           && (B_IN_CURRENT_SCOPE (b)
    1730            6 :               || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    1731          638 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
    1732            5 :               != TYPE_MAIN_VARIANT (type)))
    1733              :         {
    1734            5 :           auto_diagnostic_group d;
    1735            6 :           if (warning_at (loc, OPT_Wc___compat,
    1736              :                           "using %qD as both a typedef and a tag is "
    1737              :                           "invalid in C++", b->decl)
    1738            5 :               && b->locus != UNKNOWN_LOCATION)
    1739            4 :             inform (b->locus, "originally defined here");
    1740            5 :         }
    1741              :     }
    1742      1431961 : }
    1743              : 
    1744              : /* An exported interface to pushtag.  This is used by the gdb plugin's
    1745              :    binding oracle to introduce a new tag binding.  */
    1746              : 
    1747              : void
    1748            0 : c_pushtag (location_t loc, tree name, tree type)
    1749              : {
    1750            0 :   pushtag (loc, name, type);
    1751            0 : }
    1752              : 
    1753              : /* An exported interface to bind a declaration.  LOC is the location
    1754              :    to use.  DECL is the declaration to bind.  The decl's name is used
    1755              :    to determine how it is bound.  If DECL is a VAR_DECL, then
    1756              :    IS_GLOBAL determines whether the decl is put into the global (file
    1757              :    and external) scope or the current function's scope; if DECL is not
    1758              :    a VAR_DECL then it is always put into the file scope.  */
    1759              : 
    1760              : void
    1761            0 : c_bind (location_t loc, tree decl, bool is_global)
    1762              : {
    1763            0 :   struct c_scope *scope;
    1764            0 :   bool nested = false;
    1765              : 
    1766            0 :   if (!VAR_P (decl) || current_function_scope == NULL)
    1767              :     {
    1768              :       /* Types and functions are always considered to be global.  */
    1769            0 :       scope = file_scope;
    1770            0 :       DECL_EXTERNAL (decl) = 1;
    1771            0 :       TREE_PUBLIC (decl) = 1;
    1772              :     }
    1773            0 :   else if (is_global)
    1774              :     {
    1775              :       /* Also bind it into the external scope.  */
    1776            0 :       bind (DECL_NAME (decl), decl, external_scope, true, false, loc);
    1777            0 :       nested = true;
    1778            0 :       scope = file_scope;
    1779            0 :       DECL_EXTERNAL (decl) = 1;
    1780            0 :       TREE_PUBLIC (decl) = 1;
    1781              :     }
    1782              :   else
    1783              :     {
    1784            0 :       DECL_CONTEXT (decl) = current_function_decl;
    1785            0 :       TREE_PUBLIC (decl) = 0;
    1786            0 :       scope = current_function_scope;
    1787              :     }
    1788              : 
    1789            0 :   bind (DECL_NAME (decl), decl, scope, false, nested, loc);
    1790            0 : }
    1791              : 
    1792              : 
    1793              : /* Stores the first FILE*, const struct tm* etc. argument type (whatever
    1794              :    it is) seen in a declaration of a file I/O etc. built-in, corresponding
    1795              :    to the builtin_structptr_types array.  Subsequent declarations of such
    1796              :    built-ins are expected to refer to it rather than to fileptr_type_node,
    1797              :    etc. which is just void* (or to any other type).
    1798              :    Used only by match_builtin_function_types.  */
    1799              : 
    1800              : static const unsigned builtin_structptr_type_count
    1801              :   = ARRAY_SIZE (builtin_structptr_types);
    1802              : 
    1803              : static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
    1804              : 
    1805              : /* Returns true if types T1 and T2 representing return types or types
    1806              :    of function arguments are close enough to be considered interchangeable
    1807              :    in redeclarations of built-in functions.  */
    1808              : 
    1809              : static bool
    1810       627029 : types_close_enough_to_match (tree t1, tree t2)
    1811              : {
    1812       627029 :   return (TYPE_MODE (t1) == TYPE_MODE (t2)
    1813       626575 :           && POINTER_TYPE_P (t1) == POINTER_TYPE_P (t2)
    1814      2506601 :           && FUNCTION_POINTER_TYPE_P (t1) == FUNCTION_POINTER_TYPE_P (t2));
    1815              : }
    1816              : 
    1817              : /* Subroutine of compare_decls.  Allow harmless mismatches in return
    1818              :    and argument types provided that the type modes match.  Set *STRICT
    1819              :    and *ARGNO to the expected argument type and number in case of
    1820              :    an argument type mismatch or null and zero otherwise.  Return
    1821              :    a unified type given a suitable match, and 0 otherwise.  */
    1822              : 
    1823              : static tree
    1824       145411 : match_builtin_function_types (tree newtype, tree oldtype,
    1825              :                               tree *strict, unsigned *argno)
    1826              : {
    1827       145411 :   *argno = 0;
    1828       145411 :   *strict = NULL_TREE;
    1829              : 
    1830              :   /* Accept the return type of the new declaration if it has the same
    1831              :      mode and if they're both pointers or if neither is.  */
    1832       145411 :   tree oldrettype = TREE_TYPE (oldtype);
    1833       145411 :   tree newrettype = TREE_TYPE (newtype);
    1834              : 
    1835       145411 :   if (!types_close_enough_to_match (oldrettype, newrettype))
    1836              :     return NULL_TREE;
    1837              : 
    1838              :   /* Check that the return types are compatible but don't fail if they
    1839              :      are not (e.g., int vs long in ILP32) and just let the caller know.  */
    1840       145049 :   if (!comptypes (TYPE_MAIN_VARIANT (oldrettype),
    1841       145049 :                   TYPE_MAIN_VARIANT (newrettype)))
    1842           46 :     *strict = oldrettype;
    1843              : 
    1844       145049 :   tree oldargs = TYPE_ARG_TYPES (oldtype);
    1845       145049 :   tree newargs = TYPE_ARG_TYPES (newtype);
    1846       145049 :   tree tryargs = newargs;
    1847              : 
    1848       145049 :   const unsigned nlst = ARRAY_SIZE (last_structptr_types);
    1849       145049 :   const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
    1850              : 
    1851       145049 :   gcc_checking_assert (nlst == nbst);
    1852              : 
    1853       626471 :   for (unsigned i = 1; oldargs || newargs; ++i)
    1854              :     {
    1855       481677 :       if (!oldargs
    1856       481677 :           || !newargs
    1857       481622 :           || !TREE_VALUE (oldargs)
    1858       963299 :           || !TREE_VALUE (newargs))
    1859              :         return NULL_TREE;
    1860              : 
    1861       481622 :       tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
    1862       481622 :       tree newtype = TREE_VALUE (newargs);
    1863       481622 :       if (newtype == error_mark_node)
    1864              :        return NULL_TREE;
    1865       481618 :       newtype = TYPE_MAIN_VARIANT (newtype);
    1866              : 
    1867       481618 :       if (!types_close_enough_to_match (oldtype, newtype))
    1868              :         return NULL_TREE;
    1869              : 
    1870       481475 :       unsigned j = nbst;
    1871       481475 :       if (POINTER_TYPE_P (oldtype))
    1872              :         /* Iterate over well-known struct types like FILE (whose types
    1873              :            aren't known to us) and compare the pointer to each to
    1874              :            the pointer argument.  */
    1875       983465 :         for (j = 0; j < nbst; ++j)
    1876              :           {
    1877       866391 :             if (TREE_VALUE (oldargs) != builtin_structptr_types[j].node)
    1878       721812 :               continue;
    1879              :             /* Store the first FILE* etc. argument type (whatever it is), and
    1880              :                expect any subsequent declarations of file I/O etc. built-ins
    1881              :                to refer to it rather than to fileptr_type_node etc. which is
    1882              :                just void* (or const void*).  */
    1883       144579 :             if (last_structptr_types[j])
    1884              :               {
    1885       127043 :                 if (!comptypes (last_structptr_types[j], newtype))
    1886              :                   {
    1887            2 :                     *argno = i;
    1888            2 :                     *strict = last_structptr_types[j];
    1889              :                   }
    1890              :               }
    1891              :             else
    1892        17536 :               last_structptr_types[j] = newtype;
    1893              :             break;
    1894              :           }
    1895              : 
    1896       481475 :       if (j == nbst && !comptypes (oldtype, newtype))
    1897              :         {
    1898          243 :           if (POINTER_TYPE_P (oldtype))
    1899              :             {
    1900              :               /* For incompatible pointers, only reject differences in
    1901              :                  the unqualified variants of the referenced types but
    1902              :                  consider differences in qualifiers as benign (report
    1903              :                  those to caller via *STRICT below).  */
    1904          204 :               tree oldref = TYPE_MAIN_VARIANT (TREE_TYPE (oldtype));
    1905          204 :               tree newref = TYPE_MAIN_VARIANT (TREE_TYPE (newtype));
    1906          204 :               if (!comptypes (oldref, newref))
    1907              :                 return NULL_TREE;
    1908              :             }
    1909              : 
    1910          190 :           if (!*strict)
    1911              :             {
    1912          186 :               *argno = i;
    1913          186 :               *strict = oldtype;
    1914              :             }
    1915              :         }
    1916              : 
    1917       481422 :       oldargs = TREE_CHAIN (oldargs);
    1918       481422 :       newargs = TREE_CHAIN (newargs);
    1919              :     }
    1920              : 
    1921       144794 :   tree trytype = c_build_function_type (newrettype, tryargs);
    1922              : 
    1923              :   /* Allow declaration to change transaction_safe attribute.  */
    1924       144794 :   tree oldattrs = TYPE_ATTRIBUTES (oldtype);
    1925       144794 :   tree oldtsafe = lookup_attribute ("transaction_safe", oldattrs);
    1926       144794 :   tree newattrs = TYPE_ATTRIBUTES (newtype);
    1927       144794 :   tree newtsafe = lookup_attribute ("transaction_safe", newattrs);
    1928       144794 :   if (oldtsafe && !newtsafe)
    1929            0 :     oldattrs = remove_attribute ("transaction_safe", oldattrs);
    1930       144794 :   else if (newtsafe && !oldtsafe)
    1931            7 :     oldattrs = tree_cons (get_identifier ("transaction_safe"),
    1932              :                           NULL_TREE, oldattrs);
    1933              : 
    1934       144794 :   return c_build_type_attribute_variant (trytype, oldattrs);
    1935              : }
    1936              : 
    1937              : /* Subroutine of diagnose_mismatched_decls.  Check for function type
    1938              :    mismatch involving an empty arglist vs a nonempty one and give clearer
    1939              :    diagnostics.  */
    1940              : static void
    1941          178 : diagnose_arglist_conflict (tree newdecl, tree olddecl,
    1942              :                            tree newtype, tree oldtype)
    1943              : {
    1944          178 :   tree t;
    1945              : 
    1946          178 :   if (TREE_CODE (olddecl) != FUNCTION_DECL
    1947           98 :       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
    1948          305 :       || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == NULL_TREE)
    1949           68 :            || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == NULL_TREE)))
    1950          161 :     return;
    1951              : 
    1952           17 :   t = TYPE_ARG_TYPES (oldtype);
    1953           17 :   if (t == NULL_TREE)
    1954            9 :     t = TYPE_ARG_TYPES (newtype);
    1955           18 :   for (; t; t = TREE_CHAIN (t))
    1956              :     {
    1957           18 :       tree type = TREE_VALUE (t);
    1958              : 
    1959           18 :       if (TREE_CHAIN (t) == NULL_TREE
    1960           18 :           && TYPE_MAIN_VARIANT (type) != void_type_node)
    1961              :         {
    1962           10 :           inform (input_location, "a parameter list with an ellipsis "
    1963              :                   "cannot match an empty parameter name list declaration");
    1964           10 :           break;
    1965              :         }
    1966              : 
    1967            8 :       if (!error_operand_p (type)
    1968            8 :           && c_type_promotes_to (type) != type)
    1969              :         {
    1970            7 :           inform (input_location, "an argument type that has a default "
    1971              :                   "promotion cannot match an empty parameter name list "
    1972              :                   "declaration");
    1973            7 :           break;
    1974              :         }
    1975              :     }
    1976              : }
    1977              : 
    1978              : /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
    1979              :    old-style function definition, NEWDECL is a prototype declaration.
    1980              :    Diagnose inconsistencies in the argument list.  Returns TRUE if
    1981              :    the prototype is compatible, FALSE if not.  */
    1982              : static bool
    1983           19 : validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
    1984              : {
    1985           19 :   tree newargs, oldargs;
    1986           19 :   int i;
    1987              : 
    1988              : #define END_OF_ARGLIST(t) ((t) == void_type_node)
    1989              : 
    1990           19 :   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
    1991           19 :   newargs = TYPE_ARG_TYPES (newtype);
    1992           19 :   i = 1;
    1993              : 
    1994           45 :   for (;;)
    1995              :     {
    1996           32 :       tree oldargtype = TREE_VALUE (oldargs);
    1997           32 :       tree newargtype = TREE_VALUE (newargs);
    1998              : 
    1999           32 :       if (oldargtype == error_mark_node || newargtype == error_mark_node)
    2000              :         return false;
    2001              : 
    2002           58 :       oldargtype = (TYPE_ATOMIC (oldargtype)
    2003           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (oldargtype),
    2004              :                                               TYPE_QUAL_ATOMIC)
    2005           27 :                     : TYPE_MAIN_VARIANT (oldargtype));
    2006           60 :       newargtype = (TYPE_ATOMIC (newargtype)
    2007           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (newargtype),
    2008              :                                               TYPE_QUAL_ATOMIC)
    2009           29 :                     : TYPE_MAIN_VARIANT (newargtype));
    2010              : 
    2011           31 :       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
    2012              :         break;
    2013              : 
    2014              :       /* Reaching the end of just one list means the two decls don't
    2015              :          agree on the number of arguments.  */
    2016           22 :       if (END_OF_ARGLIST (oldargtype))
    2017              :         {
    2018            2 :           error ("prototype for %q+D declares more arguments "
    2019              :                  "than previous old-style definition", newdecl);
    2020            2 :           return false;
    2021              :         }
    2022           20 :       else if (END_OF_ARGLIST (newargtype))
    2023              :         {
    2024            2 :           error ("prototype for %q+D declares fewer arguments "
    2025              :                  "than previous old-style definition", newdecl);
    2026            2 :           return false;
    2027              :         }
    2028              : 
    2029              :       /* Type for passing arg must be consistent with that declared
    2030              :          for the arg.  */
    2031           18 :       else if (!comptypes (oldargtype, newargtype))
    2032              :         {
    2033            5 :           error ("prototype for %q+D declares argument %d"
    2034              :                  " with incompatible type",
    2035              :                  newdecl, i);
    2036            5 :           return false;
    2037              :         }
    2038              : 
    2039           13 :       oldargs = TREE_CHAIN (oldargs);
    2040           13 :       newargs = TREE_CHAIN (newargs);
    2041           13 :       i++;
    2042           13 :     }
    2043              : 
    2044              :   /* If we get here, no errors were found, but do issue a warning
    2045              :      for this poor-style construct.  */
    2046            9 :   warning (0, "prototype for %q+D follows non-prototype definition",
    2047              :            newdecl);
    2048            9 :   return true;
    2049              : #undef END_OF_ARGLIST
    2050              : }
    2051              : 
    2052              : /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
    2053              :    first in a pair of mismatched declarations, using the diagnostic
    2054              :    function DIAG.  */
    2055              : static void
    2056          418 : locate_old_decl (tree decl)
    2057              : {
    2058          418 :   if (TREE_CODE (decl) == FUNCTION_DECL
    2059          198 :       && fndecl_built_in_p (decl)
    2060          421 :       && !C_DECL_DECLARED_BUILTIN (decl))
    2061              :     ;
    2062          418 :   else if (DECL_INITIAL (decl))
    2063          119 :     inform (input_location,
    2064              :             "previous definition of %q+D with type %qT",
    2065          119 :             decl, TREE_TYPE (decl));
    2066          299 :   else if (C_DECL_IMPLICIT (decl))
    2067           16 :     inform (input_location,
    2068              :             "previous implicit declaration of %q+D with type %qT",
    2069           16 :             decl, TREE_TYPE (decl));
    2070              :   else
    2071          283 :     inform (input_location,
    2072              :             "previous declaration of %q+D with type %qT",
    2073          283 :             decl, TREE_TYPE (decl));
    2074          418 : }
    2075              : 
    2076              : 
    2077              : /* Helper function.  For a tagged type, it finds the declaration
    2078              :    for a visible tag declared in the same scope if such a
    2079              :    declaration exists.  */
    2080              : static tree
    2081      1142763 : previous_tag (tree type)
    2082              : {
    2083      1142763 :   struct c_binding *b = NULL;
    2084      1142763 :   tree name = c_type_tag (type);
    2085              : 
    2086      1142763 :   if (name)
    2087       568972 :     b = I_TAG_BINDING (name);
    2088              : 
    2089       568972 :   if (b)
    2090       568972 :     b = b->shadowed;
    2091              : 
    2092      1142763 :   if (b && B_IN_CURRENT_SCOPE (b))
    2093          177 :     return b->decl;
    2094              : 
    2095              :   return NULL_TREE;
    2096              : }
    2097              : 
    2098              : /* Subroutine to mark functions as versioned when using the attribute
    2099              :    'target_version'.  */
    2100              : 
    2101              : static void
    2102            0 : maybe_mark_function_versioned (tree decl)
    2103              : {
    2104            0 :   if (!DECL_FUNCTION_VERSIONED (decl))
    2105              :     {
    2106              :       /* Check if the name of the function has been overridden.  */
    2107            0 :       if (DECL_ASSEMBLER_NAME_SET_P (decl)
    2108            0 :           && IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))[0] == '*')
    2109            0 :         error_at (DECL_SOURCE_LOCATION (decl),
    2110              :                   "cannot use function multiversioning on a renamed function");
    2111              : 
    2112              :       /* We need to insert function version now to make sure the correct
    2113              :          pre-mangled assembler name is recorded.  */
    2114            0 :       cgraph_node *node = cgraph_node::get_create (decl);
    2115              : 
    2116            0 :       if (!node->function_version ())
    2117            0 :         node->insert_new_function_version ();
    2118              : 
    2119            0 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    2120              : 
    2121            0 :       tree mangled_name
    2122            0 :         = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
    2123            0 :       SET_DECL_ASSEMBLER_NAME (decl, mangled_name);
    2124              :     }
    2125            0 : }
    2126              : 
    2127              : /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
    2128              :    Returns true if the caller should proceed to merge the two, false
    2129              :    if OLDDECL should simply be discarded.  As a side effect, issues
    2130              :    all necessary diagnostics for invalid or poor-style combinations.
    2131              :    If it returns true, writes the types of NEWDECL and OLDDECL to
    2132              :    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
    2133              :    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
    2134              : 
    2135              : static bool
    2136      5108982 : diagnose_mismatched_decls (tree newdecl, tree olddecl,
    2137              :                            tree *newtypep, tree *oldtypep)
    2138              : {
    2139      5108982 :   tree newtype, oldtype;
    2140      5108982 :   bool retval = true;
    2141              : 
    2142              : #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL)  \
    2143              :                                   && DECL_EXTERNAL (DECL))
    2144              : 
    2145              :   /* If we have error_mark_node for either decl or type, just discard
    2146              :      the previous decl - we're in an error cascade already.  */
    2147      5108982 :   if (olddecl == error_mark_node || newdecl == error_mark_node)
    2148              :     return false;
    2149      5108962 :   *oldtypep = oldtype = TREE_TYPE (olddecl);
    2150      5108962 :   *newtypep = newtype = TREE_TYPE (newdecl);
    2151      5108962 :   if (oldtype == error_mark_node || newtype == error_mark_node)
    2152              :     return false;
    2153              : 
    2154              :   /* Two different categories of symbol altogether.  This is an error
    2155              :      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
    2156      5108954 :   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2157              :     {
    2158           29 :       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
    2159           17 :             && fndecl_built_in_p (olddecl)
    2160           14 :             && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2161              :         {
    2162           16 :           auto_diagnostic_group d;
    2163           16 :           error ("%q+D redeclared as different kind of symbol", newdecl);
    2164           16 :           locate_old_decl (olddecl);
    2165           16 :         }
    2166           13 :       else if (TREE_PUBLIC (newdecl))
    2167            3 :         warning (OPT_Wbuiltin_declaration_mismatch,
    2168              :                  "built-in function %q+D declared as non-function",
    2169              :                  newdecl);
    2170              :       else
    2171           10 :         warning (OPT_Wshadow, "declaration of %q+D shadows "
    2172              :                  "a built-in function", newdecl);
    2173           29 :       return false;
    2174              :     }
    2175              : 
    2176              :   /* Enumerators have no linkage, so may only be declared once in a
    2177              :      given scope.  */
    2178      5108925 :   if (TREE_CODE (olddecl) == CONST_DECL)
    2179              :     {
    2180           46 :       if (flag_isoc23
    2181           45 :           && TYPE_NAME (DECL_CONTEXT (newdecl))
    2182           43 :           && DECL_CONTEXT (newdecl) != DECL_CONTEXT (olddecl)
    2183           87 :           && TYPE_NAME (DECL_CONTEXT (newdecl)) == TYPE_NAME (DECL_CONTEXT (olddecl)))
    2184              :         {
    2185           38 :           if (!simple_cst_equal (DECL_INITIAL (olddecl), DECL_INITIAL (newdecl)))
    2186              :             {
    2187            1 :               auto_diagnostic_group d;
    2188            1 :               error ("conflicting redeclaration of enumerator %q+D", newdecl);
    2189            1 :               locate_old_decl (olddecl);
    2190            1 :             }
    2191              :         }
    2192              :       else
    2193              :         {
    2194            8 :           auto_diagnostic_group d;
    2195            8 :           error ("redeclaration of enumerator %q+D", newdecl);
    2196            8 :           locate_old_decl (olddecl);
    2197            8 :         }
    2198           46 :       return false;
    2199              :     }
    2200              : 
    2201      5108879 :   bool pedwarned = false;
    2202      5108879 :   bool warned = false;
    2203      5108879 :   bool enum_and_int_p = false;
    2204      5108879 :   auto_diagnostic_group d;
    2205              : 
    2206      5108879 :   bool comptypes_result = comptypes_check_enum_int (oldtype, newtype,
    2207              :                                                     &enum_and_int_p);
    2208      5108879 :   if (!comptypes_result)
    2209              :     {
    2210       145620 :       if (TREE_CODE (olddecl) == FUNCTION_DECL
    2211       145540 :           && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL)
    2212       291032 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2213              :         {
    2214              :           /* Accept "harmless" mismatches in function types such
    2215              :              as missing qualifiers or int vs long when they're the same
    2216              :              size.  However, diagnose return and argument types that are
    2217              :              incompatible according to language rules.  */
    2218       145411 :           tree mismatch_expect;
    2219       145411 :           unsigned mismatch_argno;
    2220              : 
    2221       145411 :           tree trytype = match_builtin_function_types (newtype, oldtype,
    2222              :                                                        &mismatch_expect,
    2223              :                                                        &mismatch_argno);
    2224              : 
    2225       145411 :           if (trytype && comptypes (newtype, trytype))
    2226       144794 :             *oldtypep = oldtype = trytype;
    2227              :           else
    2228              :             {
    2229              :               /* If types don't match for a built-in, throw away the
    2230              :                  built-in.  No point in calling locate_old_decl here, it
    2231              :                  won't print anything.  */
    2232          617 :               const char *header = header_for_builtin_fn (olddecl);
    2233          617 :               location_t loc = DECL_SOURCE_LOCATION (newdecl);
    2234         1017 :               if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    2235              :                               "conflicting types for built-in function %q+D; "
    2236              :                               "expected %qT",
    2237              :                               newdecl, oldtype)
    2238          617 :                   && header)
    2239              :                 {
    2240              :                   /* Suggest the right header to include as the preferred
    2241              :                      solution rather than the spelling of the declaration.  */
    2242          217 :                   rich_location richloc (line_table, loc);
    2243          217 :                   maybe_add_include_fixit (&richloc, header, true);
    2244          217 :                   inform (&richloc,
    2245              :                           "%qD is declared in header %qs", olddecl, header);
    2246          217 :                 }
    2247          617 :               return false;
    2248              :             }
    2249              : 
    2250       144794 :           if (mismatch_expect && extra_warnings)
    2251              :             {
    2252            5 :               location_t newloc = DECL_SOURCE_LOCATION (newdecl);
    2253            5 :               bool warned = false;
    2254            5 :               if (mismatch_argno)
    2255            5 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2256              :                                      "mismatch in argument %u type of built-in "
    2257              :                                      "function %qD; expected %qT",
    2258              :                                      mismatch_argno, newdecl, mismatch_expect);
    2259              :               else
    2260            0 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2261              :                                      "mismatch in return type of built-in "
    2262              :                                      "function %qD; expected %qT",
    2263              :                                      newdecl, mismatch_expect);
    2264            5 :               const char *header = header_for_builtin_fn (olddecl);
    2265            5 :               if (warned && header)
    2266              :                 {
    2267            5 :                   rich_location richloc (line_table, newloc);
    2268            5 :                   maybe_add_include_fixit (&richloc, header, true);
    2269            5 :                   inform (&richloc,
    2270              :                           "%qD is declared in header %qs", olddecl, header);
    2271            5 :                 }
    2272              :             }
    2273              :         }
    2274          209 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2275          209 :                && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    2276              :         {
    2277              :           /* A conflicting function declaration for a predeclared
    2278              :              function that isn't actually built in.  Objective C uses
    2279              :              these.  The new declaration silently overrides everything
    2280              :              but the volatility (i.e. noreturn) indication.  See also
    2281              :              below.  FIXME: Make Objective C use normal builtins.  */
    2282            0 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2283            0 :           return false;
    2284              :         }
    2285              :       /* Permit void foo (...) to match int foo (...) if the latter is
    2286              :          the definition and implicit int was used.  See
    2287              :          c-torture/compile/920625-2.c.  */
    2288          129 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
    2289           64 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
    2290           32 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
    2291          215 :                && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
    2292              :         {
    2293            5 :           pedwarned = pedwarn (input_location, 0,
    2294              :                                "conflicting types for %q+D", newdecl);
    2295              :           /* Make sure we keep void as the return type.  */
    2296            5 :           TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
    2297            5 :           C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
    2298              :         }
    2299              :       /* Permit void foo (...) to match an earlier call to foo (...) with
    2300              :          no declared type (thus, implicitly int).  */
    2301          204 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2302          124 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
    2303           92 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
    2304          227 :                && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
    2305              :         {
    2306           19 :           pedwarned = pedwarn (input_location, 0,
    2307              :                                "conflicting types for %q+D; have %qT",
    2308              :                                newdecl, newtype);
    2309              :           /* Make sure we keep void as the return type.  */
    2310           19 :           TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
    2311              :         }
    2312              :       else
    2313              :         {
    2314          185 :           int new_quals = TYPE_QUALS (newtype);
    2315          185 :           int old_quals = TYPE_QUALS (oldtype);
    2316              : 
    2317          185 :           if (new_quals != old_quals)
    2318              :             {
    2319           21 :               addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
    2320           21 :               addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
    2321           21 :               if (new_addr != old_addr)
    2322              :                 {
    2323            0 :                   if (ADDR_SPACE_GENERIC_P (new_addr))
    2324            0 :                     error ("conflicting named address spaces (generic vs %s) "
    2325              :                            "for %q+D",
    2326              :                            c_addr_space_name (old_addr), newdecl);
    2327            0 :                   else if (ADDR_SPACE_GENERIC_P (old_addr))
    2328            0 :                     error ("conflicting named address spaces (%s vs generic) "
    2329              :                            "for %q+D",
    2330              :                            c_addr_space_name (new_addr), newdecl);
    2331              :                   else
    2332            0 :                     error ("conflicting named address spaces (%s vs %s) "
    2333              :                            "for %q+D",
    2334              :                            c_addr_space_name (new_addr),
    2335              :                            c_addr_space_name (old_addr),
    2336              :                            newdecl);
    2337              :                 }
    2338              : 
    2339           21 :               if (CLEAR_QUAL_ADDR_SPACE (new_quals)
    2340           21 :                   != CLEAR_QUAL_ADDR_SPACE (old_quals))
    2341           21 :                 error ("conflicting type qualifiers for %q+D", newdecl);
    2342              :             }
    2343              :           else
    2344              :             {
    2345          164 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2346              :                 {
    2347           93 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl));
    2348           93 :                   if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl)))
    2349              :                     {
    2350              :                       /* Similar to the C++ front-end, for FUNCTION_DECL,
    2351              :                          if OLDDECL has attributes and NEWDECL doesn't,
    2352              :                          try the type with OLDDECL attributes.  */
    2353           12 :                       tree rettype = TREE_TYPE (newtype);
    2354           12 :                       tree tryargs = TYPE_ARG_TYPES (newtype);
    2355           12 :                       tree trytype = c_build_function_type (rettype,
    2356              :                                                             tryargs);
    2357           12 :                       trytype = c_build_type_attribute_variant (trytype,
    2358              :                                                                 attrs);
    2359           12 :                       if (comptypes (oldtype, trytype))
    2360              :                         {
    2361            7 :                           *newtypep = newtype = trytype;
    2362            7 :                           comptypes_result = true;
    2363              :                         }
    2364              :                     }
    2365              :                 }
    2366              : 
    2367          164 :               if (!comptypes_result)
    2368          157 :                 error ("conflicting types for %q+D; have %qT", newdecl,
    2369              :                        newtype);
    2370              :             }
    2371            7 :           if (!comptypes_result)
    2372              :             {
    2373          178 :               diagnose_arglist_conflict (newdecl, olddecl, newtype,
    2374              :                                          oldtype);
    2375          178 :               locate_old_decl (olddecl);
    2376          178 :               return false;
    2377              :             }
    2378              :         }
    2379              :     }
    2380              :   /* Warn about enum/integer type mismatches.  They are compatible types
    2381              :      (C23 6.7.2.2/5), but may pose portability problems.  */
    2382      4963259 :   else if (enum_and_int_p
    2383          191 :            && TREE_CODE (newdecl) != TYPE_DECL
    2384              :            /* Don't warn about acc_on_device built-in redeclaration,
    2385              :               the built-in is declared with int rather than enum because
    2386              :               the enum isn't intrinsic.  */
    2387      4963446 :            && !(TREE_CODE (olddecl) == FUNCTION_DECL
    2388          150 :                 && fndecl_built_in_p (olddecl, BUILT_IN_ACC_ON_DEVICE)
    2389          120 :                 && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2390           67 :     warned = warning_at (DECL_SOURCE_LOCATION (newdecl),
    2391           67 :                          OPT_Wenum_int_mismatch,
    2392              :                          "conflicting types for %q+D due to enum/integer "
    2393              :                          "mismatch; have %qT", newdecl, newtype);
    2394              : 
    2395              :   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
    2396              :      but silently ignore the redeclaration if either is in a system
    2397              :      header.  (Conflicting redeclarations were handled above.)  This
    2398              :      is allowed for C11 if the types are the same, not just
    2399              :      compatible.  */
    2400      5108084 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2401              :     {
    2402        45869 :       if (!comptypes_same_p (oldtype, newtype))
    2403              :         {
    2404           11 :           error ("redefinition of typedef %q+D with different type", newdecl);
    2405           11 :           locate_old_decl (olddecl);
    2406           11 :           return false;
    2407              :         }
    2408              : 
    2409        45858 :       if (DECL_IN_SYSTEM_HEADER (newdecl)
    2410         2495 :           || DECL_IN_SYSTEM_HEADER (olddecl)
    2411         2273 :           || warning_suppressed_p (newdecl, OPT_Wpedantic)
    2412        48131 :           || warning_suppressed_p (olddecl, OPT_Wpedantic))
    2413        43585 :         return true;  /* Allow OLDDECL to continue in use.  */
    2414              : 
    2415         2273 :       if (c_type_variably_modified_p (newtype))
    2416              :         {
    2417            3 :           error ("redefinition of typedef %q+D with variably modified type",
    2418              :                  newdecl);
    2419            3 :           locate_old_decl (olddecl);
    2420              :         }
    2421         2270 :       else if (pedwarn_c99 (input_location, OPT_Wpedantic,
    2422              :                             "redefinition of typedef %q+D", newdecl))
    2423            8 :         locate_old_decl (olddecl);
    2424              : 
    2425         2273 :       return true;
    2426              :     }
    2427              : 
    2428              :   /* Function declarations can either be 'static' or 'extern' (no
    2429              :      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
    2430              :      can never conflict with each other on account of linkage
    2431              :      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
    2432              :      gnu89 mode permits two definitions if one is 'extern inline' and
    2433              :      one is not.  The non- extern-inline definition supersedes the
    2434              :      extern-inline definition.  */
    2435              : 
    2436      5062215 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2437              :     {
    2438              :       /* If you declare a built-in function name as static, or
    2439              :          define the built-in with an old-style definition (so we
    2440              :          can't validate the argument list) the built-in definition is
    2441              :          overridden, but optionally warn this was a bad choice of name.  */
    2442      5043552 :       if (fndecl_built_in_p (olddecl)
    2443      9034571 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2444              :         {
    2445      3726234 :           if (!TREE_PUBLIC (newdecl)
    2446      3726234 :               || (DECL_INITIAL (newdecl)
    2447         4861 :                   && !prototype_p (TREE_TYPE (newdecl))))
    2448              :             {
    2449          104 :               warning_at (DECL_SOURCE_LOCATION (newdecl),
    2450          104 :                           OPT_Wshadow, "declaration of %qD shadows "
    2451              :                           "a built-in function", newdecl);
    2452              :               /* Discard the old built-in function.  */
    2453          104 :               return false;
    2454              :             }
    2455              : 
    2456      3726130 :           if (!prototype_p (TREE_TYPE (newdecl)))
    2457              :             {
    2458              :               /* Set for built-ins that take no arguments.  */
    2459          342 :               bool func_void_args = false;
    2460          342 :               if (tree at = TYPE_ARG_TYPES (oldtype))
    2461          342 :                 func_void_args = VOID_TYPE_P (TREE_VALUE (at));
    2462              : 
    2463          342 :               if (extra_warnings && !func_void_args)
    2464           47 :                 warning_at (DECL_SOURCE_LOCATION (newdecl),
    2465           47 :                             OPT_Wbuiltin_declaration_mismatch,
    2466              :                             "declaration of built-in function %qD without "
    2467              :                             "a prototype; expected %qT",
    2468           47 :                             newdecl, TREE_TYPE (olddecl));
    2469              :             }
    2470              :         }
    2471              : 
    2472      5043448 :       if (DECL_INITIAL (newdecl))
    2473              :         {
    2474       233215 :           if (DECL_INITIAL (olddecl))
    2475              :             {
    2476              :               /* If the new declaration isn't overriding an extern inline
    2477              :                  reject the new decl. In c99, no overriding is allowed
    2478              :                  in the same translation unit.  */
    2479          209 :               if (!DECL_EXTERN_INLINE (olddecl)
    2480           91 :                   || DECL_EXTERN_INLINE (newdecl)
    2481          204 :                   || (!flag_gnu89_inline
    2482           15 :                       && (!DECL_DECLARED_INLINE_P (olddecl)
    2483           15 :                           || !lookup_attribute ("gnu_inline",
    2484           15 :                                                 DECL_ATTRIBUTES (olddecl)))
    2485            0 :                       && (!DECL_DECLARED_INLINE_P (newdecl)
    2486            0 :                           || !lookup_attribute ("gnu_inline",
    2487            0 :                                                 DECL_ATTRIBUTES (newdecl)))))
    2488              :                 {
    2489           26 :                   auto_diagnostic_group d;
    2490           26 :                   error ("redefinition of %q+D", newdecl);
    2491           26 :                   locate_old_decl (olddecl);
    2492           26 :                   return false;
    2493           26 :                 }
    2494              :             }
    2495              :         }
    2496              :       /* If we have a prototype after an old-style function definition,
    2497              :          the argument types must be checked specially.  */
    2498      4810233 :       else if (DECL_INITIAL (olddecl)
    2499          824 :                && !prototype_p (oldtype) && prototype_p (newtype)
    2500      4810253 :                && TYPE_ACTUAL_ARG_TYPES (oldtype))
    2501              :         {
    2502           19 :           auto_diagnostic_group d;
    2503           19 :           if (!validate_proto_after_old_defn (newdecl, newtype, oldtype))
    2504              :             {
    2505           10 :               locate_old_decl (olddecl);
    2506           10 :               return false;
    2507              :             }
    2508           19 :         }
    2509              :       /* A non-static declaration (even an "extern") followed by a
    2510              :          static declaration is undefined behavior per C99 6.2.2p3-5,7.
    2511              :          The same is true for a static forward declaration at block
    2512              :          scope followed by a non-static declaration/definition at file
    2513              :          scope.  Static followed by non-static at the same scope is
    2514              :          not undefined behavior, and is the most convenient way to get
    2515              :          some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
    2516              :          the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
    2517              :          we do diagnose it if -Wtraditional.  */
    2518      5043412 :       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
    2519              :         {
    2520              :           /* Two exceptions to the rule.  If olddecl is an extern
    2521              :              inline, or a predeclared function that isn't actually
    2522              :              built in, newdecl silently overrides olddecl.  The latter
    2523              :              occur only in Objective C; see also above.  (FIXME: Make
    2524              :              Objective C use normal builtins.)  */
    2525           19 :           if (!DECL_IS_UNDECLARED_BUILTIN (olddecl)
    2526           38 :               && !DECL_EXTERN_INLINE (olddecl))
    2527              :             {
    2528            5 :               auto_diagnostic_group d;
    2529            5 :               error ("static declaration of %q+D follows "
    2530              :                      "non-static declaration", newdecl);
    2531            5 :               locate_old_decl (olddecl);
    2532            5 :             }
    2533           19 :           return false;
    2534              :         }
    2535      5043393 :       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
    2536              :         {
    2537         2329 :           if (DECL_CONTEXT (olddecl))
    2538              :             {
    2539            0 :               auto_diagnostic_group d;
    2540            0 :               error ("non-static declaration of %q+D follows "
    2541              :                      "static declaration", newdecl);
    2542            0 :               locate_old_decl (olddecl);
    2543            0 :               return false;
    2544            0 :             }
    2545         2329 :           else if (warn_traditional)
    2546              :             {
    2547            2 :               warned |= warning (OPT_Wtraditional,
    2548              :                                  "non-static declaration of %q+D "
    2549              :                                  "follows static declaration", newdecl);
    2550              :             }
    2551              :         }
    2552              : 
    2553              :       /* Make sure gnu_inline attribute is either not present, or
    2554              :          present on all inline decls.  */
    2555      5043393 :       if (DECL_DECLARED_INLINE_P (olddecl)
    2556      5044468 :           && DECL_DECLARED_INLINE_P (newdecl))
    2557              :         {
    2558          820 :           bool newa = lookup_attribute ("gnu_inline",
    2559          820 :                                         DECL_ATTRIBUTES (newdecl)) != NULL;
    2560          820 :           bool olda = lookup_attribute ("gnu_inline",
    2561          820 :                                         DECL_ATTRIBUTES (olddecl)) != NULL;
    2562          820 :           if (newa != olda)
    2563              :             {
    2564            0 :               auto_diagnostic_group d;
    2565            0 :               error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
    2566              :                         newa ? newdecl : olddecl);
    2567            0 :               error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
    2568              :                         "but not here");
    2569            0 :             }
    2570              :         }
    2571              :       /* Check if these are unmergable overlapping FMV declarations.  */
    2572              :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2573              :           && diagnose_versioned_decls (olddecl, newdecl))
    2574              :         return false;
    2575              :     }
    2576        18663 :   else if (VAR_P (newdecl))
    2577              :     {
    2578              :       /* Only variables can be thread-local, and all declarations must
    2579              :          agree on this property.  */
    2580        18626 :       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
    2581              :         {
    2582              :           /* Nothing to check.  Since OLDDECL is marked threadprivate
    2583              :              and NEWDECL does not have a thread-local attribute, we
    2584              :              will merge the threadprivate attribute into NEWDECL.  */
    2585              :           ;
    2586              :         }
    2587        55665 :       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
    2588              :         {
    2589            6 :           auto_diagnostic_group d;
    2590            6 :           if (DECL_THREAD_LOCAL_P (newdecl))
    2591            3 :             error ("thread-local declaration of %q+D follows "
    2592              :                    "non-thread-local declaration", newdecl);
    2593              :           else
    2594            3 :             error ("non-thread-local declaration of %q+D follows "
    2595              :                    "thread-local declaration", newdecl);
    2596              : 
    2597            6 :           locate_old_decl (olddecl);
    2598            6 :           return false;
    2599            6 :         }
    2600              : 
    2601              :       /* Multiple initialized definitions are not allowed (6.9p3,5).
    2602              :          For this purpose, C23 makes it clear that thread-local
    2603              :          declarations without extern are definitions, not tentative
    2604              :          definitions, whether or not they have initializers.  The
    2605              :          wording before C23 was unclear; literally it would have made
    2606              :          uninitialized thread-local declarations into tentative
    2607              :          definitions only if they also used static, but without saying
    2608              :          explicitly whether or not other cases count as
    2609              :          definitions at all.  */
    2610        19173 :       if ((DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
    2611        19172 :           || (flag_isoc23
    2612         6452 :               && DECL_THREAD_LOCAL_P (newdecl)
    2613           25 :               && !DECL_EXTERNAL (newdecl)
    2614           21 :               && !DECL_EXTERNAL (olddecl)))
    2615              :         {
    2616            7 :           auto_diagnostic_group d;
    2617            7 :           error ("redefinition of %q+D", newdecl);
    2618            7 :           locate_old_decl (olddecl);
    2619            7 :           return false;
    2620            7 :         }
    2621              : 
    2622              :       /* Objects declared at file scope: if the first declaration had
    2623              :          external linkage (even if it was an external reference) the
    2624              :          second must have external linkage as well, or the behavior is
    2625              :          undefined.  If the first declaration had internal linkage, then
    2626              :          the second must too, or else be an external reference (in which
    2627              :          case the composite declaration still has internal linkage).
    2628              :          As for function declarations, we warn about the static-then-
    2629              :          extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
    2630        18630 :       if (DECL_FILE_SCOPE_P (newdecl)
    2631        18613 :           && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
    2632              :         {
    2633          147 :           if (DECL_EXTERNAL (newdecl))
    2634              :             {
    2635          144 :               if (!DECL_FILE_SCOPE_P (olddecl))
    2636              :                 {
    2637            2 :                   auto_diagnostic_group d;
    2638            2 :                   error ("extern declaration of %q+D follows "
    2639              :                          "declaration with no linkage", newdecl);
    2640            2 :                   locate_old_decl (olddecl);
    2641            2 :                   return false;
    2642            2 :                 }
    2643          142 :               else if (warn_traditional)
    2644              :                 {
    2645            0 :                   warned |= warning (OPT_Wtraditional,
    2646              :                                      "non-static declaration of %q+D "
    2647              :                                      "follows static declaration", newdecl);
    2648              :                 }
    2649              :             }
    2650              :           else
    2651              :             {
    2652            3 :               auto_diagnostic_group d;
    2653            3 :               if (TREE_PUBLIC (newdecl))
    2654            2 :                 error ("non-static declaration of %q+D follows "
    2655              :                        "static declaration", newdecl);
    2656              :               else
    2657            1 :                 error ("static declaration of %q+D follows "
    2658              :                        "non-static declaration", newdecl);
    2659              : 
    2660            3 :               locate_old_decl (olddecl);
    2661            3 :               return false;
    2662            3 :             }
    2663              :         }
    2664              :       /* Two objects with the same name declared at the same block
    2665              :          scope must both be external references (6.7p3).  */
    2666        18466 :       else if (!DECL_FILE_SCOPE_P (newdecl))
    2667              :         {
    2668           17 :           if (DECL_EXTERNAL (newdecl))
    2669              :             {
    2670              :               /* Extern with initializer at block scope, which will
    2671              :                  already have received an error.  */
    2672              :             }
    2673           15 :           else if (DECL_EXTERNAL (olddecl))
    2674              :             {
    2675            4 :               auto_diagnostic_group d;
    2676            4 :               error ("declaration of %q+D with no linkage follows "
    2677              :                      "extern declaration", newdecl);
    2678            4 :               locate_old_decl (olddecl);
    2679            4 :             }
    2680              :           else
    2681              :             {
    2682           11 :               auto_diagnostic_group d;
    2683           11 :               error ("redeclaration of %q+D with no linkage", newdecl);
    2684           11 :               locate_old_decl (olddecl);
    2685           11 :             }
    2686              : 
    2687           17 :           return false;
    2688              :         }
    2689              : 
    2690              :       /* C++ does not permit a decl to appear multiple times at file
    2691              :          scope.  */
    2692        18591 :       if (warn_cxx_compat
    2693           68 :           && DECL_FILE_SCOPE_P (newdecl)
    2694           68 :           && !DECL_EXTERNAL (newdecl)
    2695        18609 :           && !DECL_EXTERNAL (olddecl))
    2696            5 :         warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
    2697            5 :                               OPT_Wc___compat,
    2698              :                               "duplicate declaration of %qD is "
    2699              :                               "invalid in C++", newdecl);
    2700              :     }
    2701              : 
    2702              :   /* warnings */
    2703              :   /* All decls must agree on a visibility.  */
    2704      5062021 :   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
    2705      5061984 :       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
    2706      5062764 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2707              :     {
    2708            1 :       warned |= warning (0, "redeclaration of %q+D with different visibility "
    2709              :                          "(old visibility preserved)", newdecl);
    2710              :     }
    2711              : 
    2712      5062021 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2713      5043393 :     warned |= diagnose_mismatched_attributes (olddecl, newdecl);
    2714              :   else /* PARM_DECL, VAR_DECL */
    2715              :     {
    2716              :       /* Redeclaration of a parameter is a constraint violation (this is
    2717              :          not explicitly stated, but follows from C99 6.7p3 [no more than
    2718              :          one declaration of the same identifier with no linkage in the
    2719              :          same scope, except type tags] and 6.2.2p6 [parameters have no
    2720              :          linkage]).  We must check for a forward parameter declaration,
    2721              :          indicated by TREE_ASM_WRITTEN on the old declaration - this is
    2722              :          an extension, the mandatory diagnostic for which is handled by
    2723              :          mark_forward_parm_decls.  */
    2724              : 
    2725        18628 :       if (TREE_CODE (newdecl) == PARM_DECL
    2726           37 :           && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
    2727              :         {
    2728            2 :           auto_diagnostic_group d;
    2729            2 :           error ("redefinition of parameter %q+D", newdecl);
    2730            2 :           locate_old_decl (olddecl);
    2731            2 :           return false;
    2732            2 :         }
    2733              :     }
    2734              : 
    2735              :   /* Optional warning for completely redundant decls.  */
    2736      5062019 :   if (!warned && !pedwarned
    2737      5061945 :       && warn_redundant_decls
    2738              :       /* Don't warn about a function declaration followed by a
    2739              :          definition.  */
    2740           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2741            2 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
    2742              :       /* Don't warn about redundant redeclarations of builtins.  */
    2743           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2744            2 :            && !fndecl_built_in_p (newdecl)
    2745            2 :            && fndecl_built_in_p (olddecl)
    2746            2 :            && !C_DECL_DECLARED_BUILTIN (olddecl))
    2747              :       /* Don't warn about an extern followed by a definition.  */
    2748           17 :       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
    2749              :       /* Don't warn about forward parameter decls.  */
    2750           17 :       && !(TREE_CODE (newdecl) == PARM_DECL
    2751            6 :            && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2752              :       /* Don't warn about a variable definition following a declaration.  */
    2753      5062030 :       && !(VAR_P (newdecl)
    2754           10 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
    2755              :     {
    2756            6 :       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
    2757              :                         newdecl);
    2758              :     }
    2759              : 
    2760              :   /* Report location of previous decl/defn.  */
    2761      5062019 :   if (warned || pedwarned)
    2762           80 :     locate_old_decl (olddecl);
    2763              : 
    2764              : #undef DECL_EXTERN_INLINE
    2765              : 
    2766              :   return retval;
    2767      5108879 : }
    2768              : 
    2769              : /* Subroutine of duplicate_decls.  NEWDECL has been found to be
    2770              :    consistent with OLDDECL, but carries new information.  Merge the
    2771              :    new information into OLDDECL.  This function issues no
    2772              :    diagnostics.  */
    2773              : 
    2774              : static void
    2775      5107877 : merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
    2776              : {
    2777      5107877 :   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
    2778      5107877 :                             && DECL_INITIAL (newdecl) != NULL_TREE);
    2779      5107877 :   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
    2780      5107877 :                            && prototype_p (TREE_TYPE (newdecl)));
    2781      5107877 :   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
    2782      5107877 :                            && prototype_p (TREE_TYPE (olddecl)));
    2783              : 
    2784              :   /* For real parm decl following a forward decl, rechain the old decl
    2785              :      in its new location and clear TREE_ASM_WRITTEN (it's not a
    2786              :      forward decl anymore).  */
    2787      5107877 :   if (TREE_CODE (newdecl) == PARM_DECL
    2788           35 :       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2789              :     {
    2790           35 :       struct c_binding *b, **here;
    2791              : 
    2792           54 :       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
    2793           54 :         if ((*here)->decl == olddecl)
    2794           35 :           goto found;
    2795            0 :       gcc_unreachable ();
    2796              : 
    2797           35 :     found:
    2798           35 :       b = *here;
    2799           35 :       *here = b->prev;
    2800           35 :       b->prev = current_scope->bindings;
    2801           35 :       current_scope->bindings = b;
    2802              : 
    2803           35 :       TREE_ASM_WRITTEN (olddecl) = 0;
    2804              :     }
    2805              : 
    2806      5107877 :   DECL_ATTRIBUTES (newdecl)
    2807      5107877 :     = targetm.merge_decl_attributes (olddecl, newdecl);
    2808              : 
    2809              :   /* For typedefs use the old type, as the new type's DECL_NAME points
    2810              :      at newdecl, which will be ggc_freed.  */
    2811      5107877 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2812              :     {
    2813              :       /* But NEWTYPE might have an attribute, honor that.  */
    2814        45858 :       tree tem = newtype;
    2815        45858 :       newtype = oldtype;
    2816              : 
    2817        45858 :       if (TYPE_USER_ALIGN (tem))
    2818              :         {
    2819           15 :           if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2820            6 :             SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2821           15 :           TYPE_USER_ALIGN (newtype) = true;
    2822              :         }
    2823              : 
    2824              :       /* And remove the new type from the variants list.  */
    2825        45858 :       if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2826              :         {
    2827           15 :           tree remove = TREE_TYPE (newdecl);
    2828           15 :           if (TYPE_MAIN_VARIANT (remove) == remove)
    2829              :             {
    2830            2 :               gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2831              :               /* If remove is the main variant, no need to remove that
    2832              :                  from the list.  One of the DECL_ORIGINAL_TYPE
    2833              :                  variants, e.g. created for aligned attribute, might still
    2834              :                  refer to the newdecl TYPE_DECL though, so remove that one
    2835              :                  in that case.  */
    2836            2 :               if (DECL_ORIGINAL_TYPE (newdecl)
    2837            2 :                   && DECL_ORIGINAL_TYPE (newdecl) != remove)
    2838            2 :                 for (tree t = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (newdecl));
    2839            2 :                      t; t = TYPE_MAIN_VARIANT (t))
    2840            2 :                   if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2841              :                     {
    2842            4 :                       TYPE_NEXT_VARIANT (t)
    2843            2 :                         = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2844            2 :                       break;
    2845              :                     }
    2846              :             }
    2847              :           else
    2848           13 :             for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2849            0 :                  t = TYPE_NEXT_VARIANT (t))
    2850           13 :               if (TYPE_NEXT_VARIANT (t) == remove)
    2851              :                 {
    2852           13 :                   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2853           13 :                   break;
    2854              :                 }
    2855              :         }
    2856              : 
    2857              :       /* Make sure we refer to the same type as the olddecl.  */
    2858        45858 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2859              :     }
    2860              : 
    2861              :   /* Merge the data types specified in the two decls.  */
    2862     10215754 :   TREE_TYPE (newdecl)
    2863      5107877 :     = TREE_TYPE (olddecl)
    2864     10215754 :     = composite_type (newtype, oldtype);
    2865              : 
    2866              :   /* Lay the type out, unless already done.  */
    2867      5107877 :   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
    2868              :     {
    2869            0 :       if (TREE_TYPE (newdecl) != error_mark_node)
    2870            0 :         layout_type (TREE_TYPE (newdecl));
    2871            0 :       if (TREE_CODE (newdecl) != FUNCTION_DECL
    2872              :           && TREE_CODE (newdecl) != TYPE_DECL
    2873              :           && TREE_CODE (newdecl) != CONST_DECL)
    2874            0 :         layout_decl (newdecl, 0);
    2875              :     }
    2876              :   else
    2877              :     {
    2878              :       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
    2879      5107877 :       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
    2880      5107877 :       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
    2881      5107877 :       SET_DECL_MODE (newdecl, DECL_MODE (olddecl));
    2882      5107877 :       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    2883              :         {
    2884           44 :           SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    2885           44 :           DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    2886              :         }
    2887      5107833 :       else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    2888      5107833 :                && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    2889            3 :         DECL_USER_ALIGN (newdecl) = 1;
    2890     10215754 :       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    2891      5107877 :           > DECL_WARN_IF_NOT_ALIGN (newdecl))
    2892            0 :         SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    2893              :                                     DECL_WARN_IF_NOT_ALIGN (olddecl));
    2894              :     }
    2895              : 
    2896              :   /* Keep the old rtl since we can safely use it.  */
    2897      5107877 :   if (HAS_RTL_P (olddecl))
    2898      5107877 :     COPY_DECL_RTL (olddecl, newdecl);
    2899              : 
    2900              :   /* Merge the type qualifiers.  */
    2901      5107877 :   if (TREE_READONLY (newdecl))
    2902       409920 :     TREE_READONLY (olddecl) = 1;
    2903              : 
    2904      5107877 :   if (TREE_THIS_VOLATILE (newdecl))
    2905        49617 :     TREE_THIS_VOLATILE (olddecl) = 1;
    2906              : 
    2907              :   /* Merge deprecatedness.  */
    2908      5107877 :   if (TREE_DEPRECATED (newdecl))
    2909          383 :     TREE_DEPRECATED (olddecl) = 1;
    2910              : 
    2911              :   /* Merge unavailability.  */
    2912      5107877 :   if (TREE_UNAVAILABLE (newdecl))
    2913            2 :     TREE_UNAVAILABLE (olddecl) = 1;
    2914              : 
    2915              :   /* If a decl is in a system header and the other isn't, keep the one on the
    2916              :      system header. Otherwise, keep source location of definition rather than
    2917              :      declaration and of prototype rather than non-prototype unless that
    2918              :      prototype is built-in.  */
    2919      5107877 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2920      5107842 :       && DECL_IN_SYSTEM_HEADER (olddecl)
    2921      5804929 :       && !DECL_IN_SYSTEM_HEADER (newdecl) )
    2922         1046 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2923      5106831 :   else if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2924      5106796 :            && DECL_IN_SYSTEM_HEADER (newdecl)
    2925      9476276 :            && !DECL_IN_SYSTEM_HEADER (olddecl))
    2926      3673439 :     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
    2927      1433392 :   else if ((DECL_INITIAL (newdecl) == NULL_TREE
    2928      1199719 :             && DECL_INITIAL (olddecl) != NULL_TREE)
    2929      2632189 :            || (old_is_prototype && !new_is_prototype
    2930          372 :                && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
    2931          950 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2932              : 
    2933              :   /* Merge the initialization information.  */
    2934      5107877 :    if (DECL_INITIAL (newdecl) == NULL_TREE)
    2935      4874132 :     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2936              : 
    2937              :   /* Merge 'constexpr' information.  */
    2938      5107877 :   if (VAR_P (olddecl) && VAR_P (newdecl))
    2939              :     {
    2940        18591 :       if (C_DECL_DECLARED_CONSTEXPR (olddecl))
    2941            2 :         C_DECL_DECLARED_CONSTEXPR (newdecl) = 1;
    2942        18589 :       else if (C_DECL_DECLARED_CONSTEXPR (newdecl))
    2943            1 :         C_DECL_DECLARED_CONSTEXPR (olddecl) = 1;
    2944              :     }
    2945              : 
    2946              :   /* Merge the threadprivate attribute.  */
    2947      5107877 :   if (VAR_P (olddecl) && C_DECL_THREADPRIVATE_P (olddecl))
    2948            7 :     C_DECL_THREADPRIVATE_P (newdecl) = 1;
    2949              : 
    2950      5107877 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl))
    2951              :     {
    2952              :       /* Copy the assembler name.
    2953              :          Currently, it can only be defined in the prototype.  */
    2954      5107842 :       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2955              : 
    2956              :       /* Use visibility of whichever declaration had it specified */
    2957      5107842 :       if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2958              :         {
    2959         4766 :           DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2960         4766 :           DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2961              :         }
    2962              : 
    2963      5107842 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2964              :         {
    2965      5043393 :           DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
    2966      5043393 :           DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2967      5043393 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2968      5043393 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2969      5043393 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2970      5043393 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2971      5043393 :           DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    2972      5043393 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2973            0 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2974      5043393 :           if (DECL_IS_OPERATOR_DELETE_P (olddecl))
    2975            0 :             DECL_SET_IS_OPERATOR_DELETE (newdecl, true);
    2976      5043393 :           TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    2977      5043393 :           DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    2978      5043393 :           DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    2979              :         }
    2980              : 
    2981              :       /* Merge the storage class information.  */
    2982      5107842 :       merge_weak (newdecl, olddecl);
    2983              : 
    2984              :       /* For functions, static overrides non-static.  */
    2985      5107842 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2986              :         {
    2987      5043393 :           TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
    2988              :           /* This is since we don't automatically
    2989              :              copy the attributes of NEWDECL into OLDDECL.  */
    2990      5043393 :           TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    2991              :           /* If this clears `static', clear it in the identifier too.  */
    2992      5043393 :           if (!TREE_PUBLIC (olddecl))
    2993         7749 :             TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
    2994              :         }
    2995              :     }
    2996              : 
    2997              :   /* In c99, 'extern' declaration before (or after) 'inline' means this
    2998              :      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
    2999              :      is present.  */
    3000      5107877 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3001      5043393 :       && !flag_gnu89_inline
    3002      5018999 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3003      4828428 :           || DECL_DECLARED_INLINE_P (olddecl))
    3004       190765 :       && (!DECL_DECLARED_INLINE_P (newdecl)
    3005       190571 :           || !DECL_DECLARED_INLINE_P (olddecl)
    3006          807 :           || !DECL_EXTERNAL (olddecl))
    3007       189976 :       && DECL_EXTERNAL (newdecl)
    3008       189768 :       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
    3009      5107975 :       && !current_function_decl)
    3010           81 :     DECL_EXTERNAL (newdecl) = 0;
    3011              : 
    3012              :   /* An inline definition following a static declaration is not
    3013              :      DECL_EXTERNAL.  */
    3014      5107877 :   if (new_is_definition
    3015       233172 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3016        42379 :           || DECL_DECLARED_INLINE_P (olddecl))
    3017      5298884 :       && !TREE_PUBLIC (olddecl))
    3018          900 :     DECL_EXTERNAL (newdecl) = 0;
    3019              : 
    3020      5107877 :   if (DECL_EXTERNAL (newdecl))
    3021              :     {
    3022      5016439 :       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
    3023      5016439 :       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
    3024              : 
    3025              :       /* An extern decl does not override previous storage class.  */
    3026      5016439 :       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3027      5016439 :       if (!DECL_EXTERNAL (newdecl))
    3028              :         {
    3029         1437 :           DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    3030         1437 :           DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3031              :         }
    3032              :     }
    3033              :   else
    3034              :     {
    3035        91438 :       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
    3036        91438 :       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3037              :     }
    3038              : 
    3039      5107877 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3040              :     {
    3041      5043393 :       if (DECL_FUNCTION_VERSIONED (olddecl)
    3042      5043393 :           || DECL_FUNCTION_VERSIONED (newdecl))
    3043              :         {
    3044            0 :           maybe_mark_function_versioned (olddecl);
    3045            0 :           maybe_mark_function_versioned (newdecl);
    3046              :         }
    3047              :       /* If we're redefining a function previously defined as extern
    3048              :          inline, make sure we emit debug info for the inline before we
    3049              :          throw it away, in case it was inlined into a function that
    3050              :          hasn't been written out yet.  */
    3051      5043393 :       if (new_is_definition && DECL_INITIAL (olddecl))
    3052              :         /* The new defn must not be inline.  */
    3053           75 :         DECL_UNINLINABLE (newdecl) = 1;
    3054              :       else
    3055              :         {
    3056              :           /* If either decl says `inline', this fn is inline, unless
    3057              :              its definition was passed already.  */
    3058      5043318 :           if (DECL_DECLARED_INLINE_P (newdecl)
    3059      9895791 :               || DECL_DECLARED_INLINE_P (olddecl))
    3060       191030 :             DECL_DECLARED_INLINE_P (newdecl) = 1;
    3061              : 
    3062     15129954 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3063     10088278 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3064              : 
    3065     10086636 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3066      5043318 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3067      5043318 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3068     10086498 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3069              :         }
    3070              : 
    3071      5043393 :       if (fndecl_built_in_p (olddecl))
    3072              :         {
    3073              :           /* If redeclaring a builtin function, it stays built in.
    3074              :              But it gets tagged as having been declared.  */
    3075      3990915 :           copy_decl_built_in_function (newdecl, olddecl);
    3076      3990915 :           C_DECL_DECLARED_BUILTIN (newdecl) = 1;
    3077      3990915 :           if (new_is_prototype)
    3078              :             {
    3079      3990556 :               C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
    3080      3990556 :               if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3081              :                 {
    3082      3990556 :                   enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3083      3990556 :                   switch (fncode)
    3084              :                     {
    3085              :                       /* If a compatible prototype of these builtin functions
    3086              :                          is seen, assume the runtime implements it with the
    3087              :                          expected semantics.  */
    3088         6565 :                     case BUILT_IN_STPCPY:
    3089         6565 :                       if (builtin_decl_explicit_p (fncode))
    3090         6565 :                         set_builtin_decl_implicit_p (fncode, true);
    3091              :                       break;
    3092      3983991 :                     default:
    3093      3983991 :                       if (builtin_decl_explicit_p (fncode))
    3094      3983991 :                         set_builtin_decl_declared_p (fncode, true);
    3095              :                       break;
    3096              :                     }
    3097              : 
    3098      3990556 :                   copy_attributes_to_builtin (newdecl);
    3099              :                 }
    3100              :             }
    3101              :           else
    3102          718 :             C_DECL_BUILTIN_PROTOTYPE (newdecl)
    3103          718 :               = C_DECL_BUILTIN_PROTOTYPE (olddecl);
    3104              :         }
    3105              : 
    3106              :       /* Preserve function specific target and optimization options */
    3107      5043393 :       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3108      5043899 :           && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3109          470 :         DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3110          470 :           = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3111              : 
    3112      5043393 :       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3113      5066815 :           && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3114            9 :         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3115            9 :           = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3116              : 
    3117              :       /* Also preserve various other info from the definition.  */
    3118      5043393 :       if (!new_is_definition)
    3119              :         {
    3120      4810221 :           tree t;
    3121      4810221 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3122      4810221 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3123      4810221 :           DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3124      4810221 :           DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3125      4810221 :           DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
    3126      7490526 :           for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
    3127      2680305 :             DECL_CONTEXT (t) = newdecl;
    3128              : 
    3129              :           /* See if we've got a function to instantiate from.  */
    3130      4810221 :           if (DECL_SAVED_TREE (olddecl))
    3131         1620 :             DECL_ABSTRACT_ORIGIN (newdecl)
    3132          810 :               = DECL_ABSTRACT_ORIGIN (olddecl);
    3133              :         }
    3134              :     }
    3135              : 
    3136              :   /* Merge the USED information.  */
    3137      5107877 :   if (TREE_USED (olddecl))
    3138       717173 :     TREE_USED (newdecl) = 1;
    3139      4390704 :   else if (TREE_USED (newdecl))
    3140            4 :     TREE_USED (olddecl) = 1;
    3141      5107877 :   if (VAR_P (olddecl) || TREE_CODE (olddecl) == PARM_DECL)
    3142        18626 :     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
    3143      5107877 :   if (DECL_PRESERVE_P (olddecl))
    3144           25 :     DECL_PRESERVE_P (newdecl) = 1;
    3145      5107852 :   else if (DECL_PRESERVE_P (newdecl))
    3146            4 :     DECL_PRESERVE_P (olddecl) = 1;
    3147              : 
    3148              :   /* Merge DECL_COMMON */
    3149        18591 :   if (VAR_P (olddecl) && VAR_P (newdecl)
    3150        18591 :       && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl))
    3151      5126466 :       && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl)))
    3152        37174 :     DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl);
    3153              : 
    3154              :   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
    3155              :      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
    3156              :      DECL_ARGUMENTS (if appropriate).  */
    3157      5107877 :   {
    3158      5107877 :     unsigned olddecl_uid = DECL_UID (olddecl);
    3159      5107877 :     tree olddecl_context = DECL_CONTEXT (olddecl);
    3160      5107877 :     tree olddecl_arguments = NULL;
    3161      5107877 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3162      5043393 :       olddecl_arguments = DECL_ARGUMENTS (olddecl);
    3163              : 
    3164      5107877 :     memcpy ((char *) olddecl + sizeof (struct tree_common),
    3165              :             (char *) newdecl + sizeof (struct tree_common),
    3166              :             sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3167      5107877 :     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3168      5107877 :     switch (TREE_CODE (olddecl))
    3169              :       {
    3170      5061984 :       case FUNCTION_DECL:
    3171      5061984 :       case VAR_DECL:
    3172      5061984 :         {
    3173      5061984 :           struct symtab_node *snode = olddecl->decl_with_vis.symtab_node;
    3174              : 
    3175     10123968 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3176              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3177      5061984 :                   tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3178      5061984 :           olddecl->decl_with_vis.symtab_node = snode;
    3179              : 
    3180      5061984 :           if ((DECL_EXTERNAL (olddecl)
    3181        46982 :                || TREE_PUBLIC (olddecl)
    3182         8020 :                || TREE_STATIC (olddecl))
    3183      5108959 :               && DECL_SECTION_NAME (newdecl) != NULL)
    3184            8 :             set_decl_section_name (olddecl, newdecl);
    3185              : 
    3186              :           /* This isn't quite correct for something like
    3187              :                 int __thread x attribute ((tls_model ("local-exec")));
    3188              :                 extern int __thread x;
    3189              :              as we'll lose the "local-exec" model.  */
    3190      5061984 :           if (VAR_P (olddecl) && DECL_THREAD_LOCAL_P (newdecl))
    3191           89 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3192              :           break;
    3193              :         }
    3194              : 
    3195        45893 :       case FIELD_DECL:
    3196        45893 :       case PARM_DECL:
    3197        45893 :       case LABEL_DECL:
    3198        45893 :       case RESULT_DECL:
    3199        45893 :       case CONST_DECL:
    3200        45893 :       case TYPE_DECL:
    3201        91786 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3202              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3203        45893 :                 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3204        45893 :         break;
    3205              : 
    3206            0 :       default:
    3207              : 
    3208            0 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3209              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3210              :                 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
    3211              :       }
    3212      5107877 :     DECL_UID (olddecl) = olddecl_uid;
    3213      5107877 :     DECL_CONTEXT (olddecl) = olddecl_context;
    3214      5107877 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3215      5043393 :       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
    3216              :   }
    3217              : 
    3218              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3219              :      so that encode_section_info has a chance to look at the new decl
    3220              :      flags and attributes.  */
    3221      5107877 :   if (DECL_RTL_SET_P (olddecl)
    3222      5107883 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3223            6 :           || (VAR_P (olddecl) && TREE_STATIC (olddecl))))
    3224            6 :     make_decl_rtl (olddecl);
    3225      5107877 : }
    3226              : 
    3227              : /* Handle when a new declaration NEWDECL has the same name as an old
    3228              :    one OLDDECL in the same binding contour.  Prints an error message
    3229              :    if appropriate.
    3230              : 
    3231              :    If safely possible, alter OLDDECL to look like NEWDECL, and return
    3232              :    true.  Otherwise, return false.  */
    3233              : 
    3234              : static bool
    3235      5108982 : duplicate_decls (tree newdecl, tree olddecl)
    3236              : {
    3237      5108982 :   tree newtype = NULL, oldtype = NULL;
    3238              : 
    3239      5108982 :   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
    3240              :     {
    3241              :       /* Avoid `unused variable' and other warnings for OLDDECL.  */
    3242         1105 :       suppress_warning (olddecl, OPT_Wunused);
    3243              :       /* If the types are completely different, poison them both with
    3244              :          error_mark_node.  */
    3245         1105 :       if (TREE_CODE (TREE_TYPE (newdecl)) != TREE_CODE (TREE_TYPE (olddecl))
    3246          118 :           && olddecl != error_mark_node
    3247         1203 :           && seen_error ())
    3248              :         {
    3249           65 :           if (TREE_CODE (olddecl) != FUNCTION_DECL)
    3250           53 :             TREE_TYPE (olddecl) = error_mark_node;
    3251           65 :           if (TREE_CODE (newdecl) != FUNCTION_DECL)
    3252           61 :             TREE_TYPE (newdecl) = error_mark_node;
    3253              :         }
    3254         1105 :       return false;
    3255              :     }
    3256              : 
    3257      5107877 :   merge_decls (newdecl, olddecl, newtype, oldtype);
    3258              : 
    3259              :   /* The NEWDECL will no longer be needed.
    3260              : 
    3261              :      Before releasing the node, be sure to remove function from symbol
    3262              :      table that might have been inserted there to record comdat group.
    3263              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3264              :      structure is shared in between NEWDECL and OLDECL.  */
    3265      5107877 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3266      5043393 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3267      5107877 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3268              :     {
    3269      5061984 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3270      5061984 :       if (snode)
    3271          104 :         snode->remove ();
    3272              :     }
    3273      5107877 :   ggc_free (newdecl);
    3274      5107877 :   return true;
    3275              : }
    3276              : 
    3277              : 
    3278              : /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
    3279              : static void
    3280    170793411 : warn_if_shadowing (tree new_decl)
    3281              : {
    3282    170793411 :   struct c_binding *b;
    3283              : 
    3284              :   /* Shadow warnings wanted?  */
    3285    341585906 :   if (!(warn_shadow
    3286    170792675 :         || warn_shadow_local
    3287    170792495 :         || warn_shadow_compatible_local)
    3288              :       /* No shadow warnings for internally generated vars.  */
    3289    170793654 :       || DECL_IS_UNDECLARED_BUILTIN (new_decl))
    3290              :     return;
    3291              : 
    3292              :   /* Is anything being shadowed?  Invisible decls do not count.  */
    3293          253 :   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
    3294          157 :     if (b->decl && b->decl != new_decl && !b->invisible
    3295          214 :         && (b->decl == error_mark_node
    3296           43 :             || diagnostic_report_warnings_p (global_dc,
    3297              :                                              DECL_SOURCE_LOCATION (b->decl))))
    3298              :       {
    3299           57 :         tree old_decl = b->decl;
    3300              : 
    3301           57 :         if (old_decl == error_mark_node)
    3302              :           {
    3303           14 :             warning (OPT_Wshadow, "declaration of %q+D shadows previous "
    3304              :                      "non-variable", new_decl);
    3305           50 :             break;
    3306              :           }
    3307              : 
    3308           43 :         bool warned = false;
    3309           43 :         auto_diagnostic_group d;
    3310           43 :         if (TREE_CODE (old_decl) == PARM_DECL)
    3311              :           {
    3312            5 :             enum opt_code warning_code;
    3313              : 
    3314              :             /* If '-Wshadow=compatible-local' is specified without other
    3315              :                -Wshadow= flags, we will warn only when the types of the
    3316              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3317              :                (old_decl) are compatible.  */
    3318            5 :             if (warn_shadow)
    3319              :               warning_code = OPT_Wshadow;
    3320            2 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3321              :               warning_code = OPT_Wshadow_compatible_local;
    3322              :             else
    3323            2 :               warning_code = OPT_Wshadow_local;
    3324            5 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3325              :                                  "declaration of %qD shadows a parameter",
    3326              :                                  new_decl);
    3327              :           }
    3328           38 :         else if (DECL_FILE_SCOPE_P (old_decl))
    3329              :           {
    3330              :             /* Do not warn if a variable shadows a function, unless
    3331              :                the variable is a function or a pointer-to-function.  */
    3332           34 :             if (TREE_CODE (old_decl) == FUNCTION_DECL
    3333           11 :                 && TREE_CODE (new_decl) != FUNCTION_DECL
    3334           36 :                 && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
    3335            7 :                 continue;
    3336              : 
    3337           20 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
    3338              :                                  "declaration of %qD shadows a global "
    3339              :                                  "declaration",
    3340              :                                  new_decl);
    3341              :           }
    3342           11 :         else if (TREE_CODE (old_decl) == FUNCTION_DECL
    3343           11 :                  && fndecl_built_in_p (old_decl))
    3344              :           {
    3345            0 :             warning (OPT_Wshadow, "declaration of %q+D shadows "
    3346              :                      "a built-in function", new_decl);
    3347            0 :             break;
    3348              :           }
    3349              :         else
    3350              :           {
    3351           11 :             enum opt_code warning_code;
    3352              : 
    3353              :             /* If '-Wshadow=compatible-local' is specified without other
    3354              :                -Wshadow= flags, we will warn only when the types of the
    3355              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3356              :                (old_decl) are compatible.  */
    3357           11 :             if (warn_shadow)
    3358              :               warning_code = OPT_Wshadow;
    3359            8 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3360              :               warning_code = OPT_Wshadow_compatible_local;
    3361              :             else
    3362            2 :               warning_code = OPT_Wshadow_local;
    3363           11 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3364              :                                  "declaration of %qD shadows a previous local",
    3365              :                                  new_decl);
    3366              :           }
    3367              : 
    3368           36 :         if (warned)
    3369           26 :           inform (DECL_SOURCE_LOCATION (old_decl),
    3370              :                   "shadowed declaration is here");
    3371              : 
    3372              :         break;
    3373           43 :       }
    3374              : }
    3375              : 
    3376              : /* Record a decl-node X as belonging to the current lexical scope.
    3377              :    Check for errors (such as an incompatible declaration for the same
    3378              :    name already seen in the same scope).
    3379              : 
    3380              :    Returns either X or an old decl for the same name.
    3381              :    If an old decl is returned, it may have been smashed
    3382              :    to agree with what X says.  */
    3383              : 
    3384              : tree
    3385    203775127 : pushdecl (tree x)
    3386              : {
    3387    203775127 :   tree name = DECL_NAME (x);
    3388    203775127 :   struct c_scope *scope = current_scope;
    3389    203775127 :   struct c_binding *b;
    3390    203775127 :   bool nested = false;
    3391    203775127 :   location_t locus = DECL_SOURCE_LOCATION (x);
    3392              : 
    3393              :   /* Must set DECL_CONTEXT for everything not at file scope or
    3394              :      DECL_FILE_SCOPE_P won't work.  Local externs don't count
    3395              :      unless they have initializers (which generate code).  We
    3396              :      also exclude CONST_DECLs because enumerators will get the
    3397              :      type of the enum as context.  */
    3398    203775127 :   if (current_function_decl
    3399      9144098 :       && TREE_CODE (x) != CONST_DECL
    3400    212762060 :       && (!VAR_OR_FUNCTION_DECL_P (x)
    3401      8708597 :           || DECL_INITIAL (x) || !TREE_PUBLIC (x)))
    3402      8974905 :     DECL_CONTEXT (x) = current_function_decl;
    3403              : 
    3404              :   /* Anonymous decls are just inserted in the scope.  */
    3405    203775127 :   if (!name)
    3406              :     {
    3407      7879727 :       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
    3408              :             locus);
    3409      7879727 :       return x;
    3410              :     }
    3411              : 
    3412              :   /* First, see if there is another declaration with the same name in
    3413              :      the current scope.  If there is, duplicate_decls may do all the
    3414              :      work for us.  If duplicate_decls returns false, that indicates
    3415              :      two incompatible decls in the same scope; we are to silently
    3416              :      replace the old one (duplicate_decls has issued all appropriate
    3417              :      diagnostics).  In particular, we should not consider possible
    3418              :      duplicates in the external scope, or shadowing.  */
    3419    195895400 :   b = I_SYMBOL_BINDING (name);
    3420    195895400 :   if (b && B_IN_SCOPE (b, scope))
    3421              :     {
    3422      1402169 :       struct c_binding *b_ext, *b_use;
    3423      1402169 :       tree type = TREE_TYPE (x);
    3424      1402169 :       tree visdecl = b->decl;
    3425      1402169 :       tree vistype = TREE_TYPE (visdecl);
    3426      1402169 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    3427      1402169 :           && COMPLETE_TYPE_P (TREE_TYPE (x)))
    3428         1370 :         b->inner_comp = false;
    3429      1402169 :       b_use = b;
    3430      1402169 :       b_ext = b;
    3431              :       /* If this is an external linkage declaration, we should check
    3432              :          for compatibility with the type in the external scope before
    3433              :          setting the type at this scope based on the visible
    3434              :          information only.  */
    3435      1402169 :       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
    3436              :         {
    3437      2696312 :           while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    3438      1348166 :             b_ext = b_ext->shadowed;
    3439      1348146 :           if (b_ext)
    3440              :             {
    3441      1348145 :               b_use = b_ext;
    3442      1348145 :               if (b_use->u.type)
    3443       276542 :                 TREE_TYPE (b_use->decl) = b_use->u.type;
    3444              :             }
    3445              :         }
    3446              : 
    3447              :       /* Check if x is part of a FMV set with b_use.
    3448              :          FMV is only supported in c for targets with target_version
    3449              :          attributes.  */
    3450      1402169 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    3451              :           && b_use && TREE_CODE (b_use->decl) == FUNCTION_DECL
    3452              :           && TREE_CODE (x) == FUNCTION_DECL && DECL_FILE_SCOPE_P (b_use->decl)
    3453              :           && DECL_FILE_SCOPE_P (x)
    3454              :           && disjoint_version_decls (x, b_use->decl)
    3455              :           && comptypes (vistype, type))
    3456              :         {
    3457              :           maybe_mark_function_versioned (b_use->decl);
    3458              :           maybe_mark_function_versioned (b->decl);
    3459              :           maybe_mark_function_versioned (x);
    3460              : 
    3461              :           cgraph_node *b_node = cgraph_node::get_create (b_use->decl);
    3462              :           cgraph_function_version_info *b_v = b_node->function_version ();
    3463              :           if (!b_v)
    3464              :             b_v = b_node->insert_new_function_version ();
    3465              : 
    3466              :           /* Check if this new node conflicts with any previous functions
    3467              :              in the set.  */
    3468              :           cgraph_function_version_info *version = b_v;
    3469              :           for (; version; version = version->next)
    3470              :             if (!disjoint_version_decls (version->this_node->decl, x))
    3471              :               {
    3472              :                 /* The decls define overlapping version, so attempt to merge
    3473              :                    or diagnose the conflict.  */
    3474              :                 if (duplicate_decls (x, version->this_node->decl))
    3475              :                   return version->this_node->decl;
    3476              :                 else
    3477              :                   return error_mark_node;
    3478              :               }
    3479              : 
    3480              :           /* This is a new version to be added to FMV structure.  */
    3481              :           cgraph_node::add_function_version (b_v, x);
    3482              : 
    3483              :           /* Get the first node from the structure.  */
    3484              :           cgraph_function_version_info *default_v = b_v;
    3485              :           while (default_v->prev)
    3486              :             default_v = default_v->prev;
    3487              :           /* Always use the default node for the bindings.  */
    3488              :           b_use->decl = default_v->this_node->decl;
    3489              :           b->decl = default_v->this_node->decl;
    3490              : 
    3491              :           /* Node is not a duplicate, so no need to do the rest of the
    3492              :              checks.  */
    3493              :           return x;
    3494              :         }
    3495              : 
    3496      1402169 :       if (duplicate_decls (x, b_use->decl))
    3497              :         {
    3498      1401799 :           if (b_use != b)
    3499              :             {
    3500              :               /* Save the updated type in the external scope and
    3501              :                  restore the proper type for this scope.  */
    3502      1347939 :               tree thistype;
    3503      1347939 :               if (comptypes (vistype, type))
    3504      1347897 :                 thistype = composite_type (vistype, type);
    3505              :               else
    3506           42 :                 thistype = TREE_TYPE (b_use->decl);
    3507      1347939 :               b_use->u.type = TREE_TYPE (b_use->decl);
    3508      1347939 :               if (TREE_CODE (b_use->decl) == FUNCTION_DECL
    3509      1347939 :                   && fndecl_built_in_p (b_use->decl))
    3510       286579 :                 thistype
    3511       286579 :                   = c_build_type_attribute_variant (thistype,
    3512       286579 :                                                     TYPE_ATTRIBUTES
    3513              :                                                     (b_use->u.type));
    3514      1347939 :               TREE_TYPE (b_use->decl) = thistype;
    3515              :             }
    3516      1401799 :           return b_use->decl;
    3517              :         }
    3518              :       else
    3519          370 :         goto skip_external_and_shadow_checks;
    3520              :     }
    3521              : 
    3522              :   /* All declarations with external linkage, and all external
    3523              :      references, go in the external scope, no matter what scope is
    3524              :      current.  However, the binding in that scope is ignored for
    3525              :      purposes of normal name lookup.  A separate binding structure is
    3526              :      created in the requested scope; this governs the normal
    3527              :      visibility of the symbol.
    3528              : 
    3529              :      The binding in the externals scope is used exclusively for
    3530              :      detecting duplicate declarations of the same object, no matter
    3531              :      what scope they are in; this is what we do here.  (C99 6.2.7p2:
    3532              :      All declarations that refer to the same object or function shall
    3533              :      have compatible type; otherwise, the behavior is undefined.)
    3534              :      However, in Objective-C, we also want to detect declarations
    3535              :      conflicting with those of the basic types.  */
    3536    339594063 :   if ((DECL_EXTERNAL (x) || scope == file_scope)
    3537    206008348 :       && (VAR_OR_FUNCTION_DECL_P (x) || c_dialect_objc ()))
    3538              :     {
    3539     51184563 :       tree type = TREE_TYPE (x);
    3540     51184563 :       tree vistype = NULL_TREE;
    3541     51184563 :       tree visdecl = NULL_TREE;
    3542     51184563 :       bool type_saved = false;
    3543      3706840 :       if (b && !B_IN_EXTERNAL_SCOPE (b)
    3544         1038 :           && VAR_OR_FUNCTION_DECL_P (b->decl)
    3545     51185592 :           && DECL_FILE_SCOPE_P (b->decl))
    3546              :         {
    3547          803 :           visdecl = b->decl;
    3548          803 :           vistype = TREE_TYPE (visdecl);
    3549              :         }
    3550     51184563 :       if (scope != file_scope
    3551     51184563 :           && !DECL_IN_SYSTEM_HEADER (x))
    3552        11495 :         warning_at (locus, OPT_Wnested_externs,
    3553              :                     "nested extern declaration of %qD", x);
    3554              : 
    3555     51185987 :       while (b && !B_IN_EXTERNAL_SCOPE (b))
    3556              :         {
    3557              :           /* If this decl might be modified, save its type.  This is
    3558              :              done here rather than when the decl is first bound
    3559              :              because the type may change after first binding, through
    3560              :              being completed or through attributes being added.  If we
    3561              :              encounter multiple such decls, only the first should have
    3562              :              its type saved; the others will already have had their
    3563              :              proper types saved and the types will not have changed as
    3564              :              their scopes will not have been re-entered.  */
    3565         1424 :           if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
    3566              :             {
    3567         1022 :               b->u.type = TREE_TYPE (b->decl);
    3568         1022 :               type_saved = true;
    3569              :             }
    3570         1424 :           if (B_IN_FILE_SCOPE (b)
    3571         1012 :               && VAR_P (b->decl)
    3572          572 :               && TREE_STATIC (b->decl)
    3573          281 :               && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
    3574          138 :               && !TYPE_DOMAIN (TREE_TYPE (b->decl))
    3575           47 :               && TREE_CODE (type) == ARRAY_TYPE
    3576           47 :               && TYPE_DOMAIN (type)
    3577           28 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    3578         1452 :               && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
    3579              :             {
    3580              :               /* Array type completed in inner scope, which should be
    3581              :                  diagnosed if the completion does not have size 1 and
    3582              :                  it does not get completed in the file scope.  */
    3583            6 :               b->inner_comp = true;
    3584              :             }
    3585         1424 :           b = b->shadowed;
    3586              :         }
    3587              : 
    3588              :       /* If a matching external declaration has been found, set its
    3589              :          type to the composite of all the types of that declaration.
    3590              :          After the consistency checks, it will be reset to the
    3591              :          composite of the visible types only.  */
    3592     51184563 :       if (b && b->u.type)
    3593          768 :         TREE_TYPE (b->decl) = b->u.type;
    3594              : 
    3595              :       /* the static does not go in the externals scope.  */
    3596      3706696 :       if (b && duplicate_decls (x, b->decl))
    3597              :         {
    3598      3705961 :           tree thistype;
    3599      3705961 :           if (vistype)
    3600              :             {
    3601          675 :               if (comptypes (vistype, type))
    3602          638 :                 thistype = composite_type (vistype, type);
    3603              :               else
    3604           37 :                 thistype = TREE_TYPE (b->decl);
    3605              :             }
    3606              :           else
    3607              :             thistype = type;
    3608      3705961 :           b->u.type = TREE_TYPE (b->decl);
    3609              :           /* Propagate the type attributes to the decl.  */
    3610      3705961 :           thistype
    3611      3705961 :             = c_build_type_attribute_variant (thistype,
    3612      3705961 :                                               TYPE_ATTRIBUTES (b->u.type));
    3613      3705961 :           TREE_TYPE (b->decl) = thistype;
    3614      3705961 :           bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
    3615              :                 locus);
    3616      3705961 :           return b->decl;
    3617              :         }
    3618     47478602 :       else if (TREE_PUBLIC (x))
    3619              :         {
    3620     47104272 :           if (visdecl && !b && duplicate_decls (x, visdecl))
    3621              :             {
    3622              :               /* An external declaration at block scope referring to a
    3623              :                  visible entity with internal linkage.  The composite
    3624              :                  type will already be correct for this scope, so we
    3625              :                  just need to fall through to make the declaration in
    3626              :                  this scope.  */
    3627              :               nested = true;
    3628              :               x = visdecl;
    3629              :             }
    3630              :           else
    3631              :             {
    3632     47104155 :               bind (name, x, external_scope, /*invisible=*/true,
    3633              :                     /*nested=*/false, locus);
    3634     47104155 :               nested = true;
    3635              :             }
    3636              :         }
    3637              :     }
    3638              : 
    3639    190787270 :   if (TREE_CODE (x) != PARM_DECL)
    3640     70709949 :     warn_if_shadowing (x);
    3641              : 
    3642    120077321 :  skip_external_and_shadow_checks:
    3643    190787640 :   if (TREE_CODE (x) == TYPE_DECL)
    3644              :     {
    3645              :       /* So this is a typedef, set its underlying type.  */
    3646      9722338 :       set_underlying_type (x);
    3647              : 
    3648              :       /* If X is a typedef defined in the current function, record it
    3649              :          for the purpose of implementing the -Wunused-local-typedefs
    3650              :          warning.  */
    3651      9722338 :       record_locally_defined_typedef (x);
    3652              :     }
    3653              : 
    3654    190787640 :   bind (name, x, scope, /*invisible=*/false, nested, locus);
    3655              : 
    3656              :   /* If x's type is incomplete because it's based on a
    3657              :      structure or union which has not yet been fully declared,
    3658              :      attach it to that structure or union type, so we can go
    3659              :      back and complete the variable declaration later, if the
    3660              :      structure or union gets fully declared.
    3661              : 
    3662              :      If the input is erroneous, we can have error_mark in the type
    3663              :      slot (e.g. "f(void a, ...)") - that doesn't count as an
    3664              :      incomplete type.  */
    3665    190787640 :   if (TREE_TYPE (x) != error_mark_node
    3666    190787640 :       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
    3667              :     {
    3668       184486 :       tree element = TREE_TYPE (x);
    3669              : 
    3670       204586 :       while (TREE_CODE (element) == ARRAY_TYPE)
    3671        20100 :         element = TREE_TYPE (element);
    3672       184486 :       element = TYPE_MAIN_VARIANT (element);
    3673              : 
    3674       184486 :       if ((RECORD_OR_UNION_TYPE_P (element)
    3675       140438 :            || TREE_CODE (element) == ENUMERAL_TYPE)
    3676        44119 :           && (TREE_CODE (x) != TYPE_DECL
    3677        40669 :               || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    3678       187946 :           && !COMPLETE_TYPE_P (element))
    3679          321 :         C_TYPE_INCOMPLETE_VARS (element)
    3680          642 :           = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
    3681              :     }
    3682              :   return x;
    3683              : }
    3684              : 
    3685              : 
    3686              : /* Issue a permerror about implicit function declaration.  ID is the function
    3687              :    identifier, OLDDECL is a declaration of the function in a different scope,
    3688              :    or NULL_TREE.  */
    3689              : 
    3690              : static void
    3691         3776 : implicit_decl_permerror (location_t loc, tree id, tree olddecl)
    3692              : {
    3693         3776 :   if (!warn_implicit_function_declaration)
    3694         2617 :     return;
    3695              : 
    3696         1159 :   bool warned;
    3697         1159 :   auto_diagnostic_group d;
    3698         1159 :   name_hint hint;
    3699         1159 :   if (!olddecl)
    3700          553 :     hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc);
    3701              : 
    3702         1159 :   if (flag_isoc99)
    3703              :     {
    3704         1153 :       if (const char *suggestion = hint.suggestion ())
    3705              :         {
    3706          107 :           gcc_rich_location richloc (loc);
    3707          107 :           richloc.add_fixit_replace (suggestion);
    3708          107 :           warned = permerror_opt (&richloc, OPT_Wimplicit_function_declaration,
    3709              :                                   "implicit declaration of function %qE;"
    3710              :                                   " did you mean %qs?",
    3711              :                                   id, suggestion);
    3712          107 :         }
    3713              :       else
    3714         1046 :         warned = permerror_opt (loc, OPT_Wimplicit_function_declaration,
    3715              :                                 "implicit declaration of function %qE", id);
    3716              :     }
    3717            6 :   else if (const char *suggestion = hint.suggestion ())
    3718              :     {
    3719            2 :       gcc_rich_location richloc (loc);
    3720            2 :       richloc.add_fixit_replace (suggestion);
    3721            2 :       warned = warning_at
    3722            2 :         (&richloc, OPT_Wimplicit_function_declaration,
    3723              :          G_("implicit declaration of function %qE; did you mean %qs?"),
    3724              :          id, suggestion);
    3725            2 :     }
    3726              :   else
    3727            4 :     warned = warning_at (loc, OPT_Wimplicit_function_declaration,
    3728              :                          G_("implicit declaration of function %qE"), id);
    3729              : 
    3730         1159 :   if (warned)
    3731              :     {
    3732              :       /* Whether the olddecl is an undeclared builtin function.
    3733              :          locate_old_decl will not generate a diagnostic for those,
    3734              :          so in that case we want to look elsewhere.  */
    3735           90 :       bool undeclared_builtin = (olddecl
    3736           28 :                                  && TREE_CODE (olddecl) == FUNCTION_DECL
    3737           28 :                                  && fndecl_built_in_p (olddecl)
    3738          117 :                                  && !C_DECL_DECLARED_BUILTIN (olddecl));
    3739           90 :       if (undeclared_builtin)
    3740              :         {
    3741           27 :           const char *header = header_for_builtin_fn (olddecl);
    3742           27 :           if (header)
    3743              :             {
    3744           20 :               rich_location richloc (line_table, loc);
    3745           20 :               maybe_add_include_fixit (&richloc, header, true);
    3746           20 :               inform (&richloc,
    3747              :                       "include %qs or provide a declaration of %qE",
    3748              :                       header, id);
    3749           20 :             }
    3750              :         }
    3751           63 :       else if (olddecl)
    3752            1 :         locate_old_decl (olddecl);
    3753              :     }
    3754              : 
    3755         1069 :   if (!warned)
    3756         1159 :     hint.suppress ();
    3757         1159 : }
    3758              : 
    3759              : /* Return the name of the header file that declares built-in function
    3760              :    FNDECL, or null if either we don't know or don't expect to see an
    3761              :    explicit declaration.  */
    3762              : 
    3763              : static const char *
    3764         3177 : header_for_builtin_fn (tree fndecl)
    3765              : {
    3766         3177 :   if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
    3767              :     return NULL;
    3768              : 
    3769         3177 :   switch (DECL_FUNCTION_CODE (fndecl))
    3770              :     {
    3771              :     CASE_FLT_FN (BUILT_IN_ACOS):
    3772              :     CASE_FLT_FN (BUILT_IN_ACOSH):
    3773              :     CASE_FLT_FN (BUILT_IN_ASIN):
    3774              :     CASE_FLT_FN (BUILT_IN_ASINH):
    3775              :     CASE_FLT_FN (BUILT_IN_ATAN):
    3776              :     CASE_FLT_FN (BUILT_IN_ATANH):
    3777              :     CASE_FLT_FN (BUILT_IN_ATAN2):
    3778              :     CASE_FLT_FN (BUILT_IN_CBRT):
    3779              :     CASE_FLT_FN (BUILT_IN_CEIL):
    3780              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
    3781              :     CASE_FLT_FN (BUILT_IN_COPYSIGN):
    3782              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
    3783              :     CASE_FLT_FN (BUILT_IN_COS):
    3784              :     CASE_FLT_FN (BUILT_IN_COSH):
    3785              :     CASE_FLT_FN (BUILT_IN_ERF):
    3786              :     CASE_FLT_FN (BUILT_IN_ERFC):
    3787              :     CASE_FLT_FN (BUILT_IN_EXP):
    3788              :     CASE_FLT_FN (BUILT_IN_EXP2):
    3789              :     CASE_FLT_FN (BUILT_IN_EXPM1):
    3790              :     CASE_FLT_FN (BUILT_IN_FABS):
    3791              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
    3792              :     CASE_FLT_FN (BUILT_IN_FDIM):
    3793              :     CASE_FLT_FN (BUILT_IN_FLOOR):
    3794              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
    3795              :     CASE_FLT_FN (BUILT_IN_FMA):
    3796              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
    3797              :     CASE_FLT_FN (BUILT_IN_FMAX):
    3798              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
    3799              :     CASE_FLT_FN (BUILT_IN_FMIN):
    3800              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
    3801              :     CASE_FLT_FN (BUILT_IN_FMOD):
    3802              :     CASE_FLT_FN (BUILT_IN_FREXP):
    3803              :     CASE_FLT_FN (BUILT_IN_HYPOT):
    3804              :     CASE_FLT_FN (BUILT_IN_ILOGB):
    3805              :     CASE_FLT_FN (BUILT_IN_LDEXP):
    3806              :     CASE_FLT_FN (BUILT_IN_LGAMMA):
    3807              :     CASE_FLT_FN (BUILT_IN_LLRINT):
    3808              :     CASE_FLT_FN (BUILT_IN_LLROUND):
    3809              :     CASE_FLT_FN (BUILT_IN_LOG):
    3810              :     CASE_FLT_FN (BUILT_IN_LOG10):
    3811              :     CASE_FLT_FN (BUILT_IN_LOG1P):
    3812              :     CASE_FLT_FN (BUILT_IN_LOG2):
    3813              :     CASE_FLT_FN (BUILT_IN_LOGB):
    3814              :     CASE_FLT_FN (BUILT_IN_LRINT):
    3815              :     CASE_FLT_FN (BUILT_IN_LROUND):
    3816              :     CASE_FLT_FN (BUILT_IN_MODF):
    3817              :     CASE_FLT_FN (BUILT_IN_NAN):
    3818              :     CASE_FLT_FN (BUILT_IN_NEARBYINT):
    3819              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
    3820              :     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
    3821              :     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
    3822              :     CASE_FLT_FN (BUILT_IN_POW):
    3823              :     CASE_FLT_FN (BUILT_IN_REMAINDER):
    3824              :     CASE_FLT_FN (BUILT_IN_REMQUO):
    3825              :     CASE_FLT_FN (BUILT_IN_RINT):
    3826              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
    3827              :     CASE_FLT_FN (BUILT_IN_ROUND):
    3828              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
    3829              :     CASE_FLT_FN (BUILT_IN_SCALBLN):
    3830              :     CASE_FLT_FN (BUILT_IN_SCALBN):
    3831              :     CASE_FLT_FN (BUILT_IN_SIN):
    3832              :     CASE_FLT_FN (BUILT_IN_SINH):
    3833              :     CASE_FLT_FN (BUILT_IN_SINCOS):
    3834              :     CASE_FLT_FN (BUILT_IN_SQRT):
    3835              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
    3836              :     CASE_FLT_FN (BUILT_IN_TAN):
    3837              :     CASE_FLT_FN (BUILT_IN_TANH):
    3838              :     CASE_FLT_FN (BUILT_IN_TGAMMA):
    3839              :     CASE_FLT_FN (BUILT_IN_TRUNC):
    3840              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
    3841              :     case BUILT_IN_ISINF:
    3842              :     case BUILT_IN_ISNAN:
    3843              :       return "<math.h>";
    3844           29 :     CASE_FLT_FN (BUILT_IN_CABS):
    3845           29 :     CASE_FLT_FN (BUILT_IN_CACOS):
    3846           29 :     CASE_FLT_FN (BUILT_IN_CACOSH):
    3847           29 :     CASE_FLT_FN (BUILT_IN_CARG):
    3848           29 :     CASE_FLT_FN (BUILT_IN_CASIN):
    3849           29 :     CASE_FLT_FN (BUILT_IN_CASINH):
    3850           29 :     CASE_FLT_FN (BUILT_IN_CATAN):
    3851           29 :     CASE_FLT_FN (BUILT_IN_CATANH):
    3852           29 :     CASE_FLT_FN (BUILT_IN_CCOS):
    3853           29 :     CASE_FLT_FN (BUILT_IN_CCOSH):
    3854           29 :     CASE_FLT_FN (BUILT_IN_CEXP):
    3855           29 :     CASE_FLT_FN (BUILT_IN_CIMAG):
    3856           29 :     CASE_FLT_FN (BUILT_IN_CLOG):
    3857           29 :     CASE_FLT_FN (BUILT_IN_CONJ):
    3858           29 :     CASE_FLT_FN (BUILT_IN_CPOW):
    3859           29 :     CASE_FLT_FN (BUILT_IN_CPROJ):
    3860           29 :     CASE_FLT_FN (BUILT_IN_CREAL):
    3861           29 :     CASE_FLT_FN (BUILT_IN_CSIN):
    3862           29 :     CASE_FLT_FN (BUILT_IN_CSINH):
    3863           29 :     CASE_FLT_FN (BUILT_IN_CSQRT):
    3864           29 :     CASE_FLT_FN (BUILT_IN_CTAN):
    3865           29 :     CASE_FLT_FN (BUILT_IN_CTANH):
    3866           29 :       return "<complex.h>";
    3867          228 :     case BUILT_IN_MEMCHR:
    3868          228 :     case BUILT_IN_MEMCMP:
    3869          228 :     case BUILT_IN_MEMCPY:
    3870          228 :     case BUILT_IN_MEMMOVE:
    3871          228 :     case BUILT_IN_MEMSET:
    3872          228 :     case BUILT_IN_STRCAT:
    3873          228 :     case BUILT_IN_STRCHR:
    3874          228 :     case BUILT_IN_STRCMP:
    3875          228 :     case BUILT_IN_STRCPY:
    3876          228 :     case BUILT_IN_STRCSPN:
    3877          228 :     case BUILT_IN_STRLEN:
    3878          228 :     case BUILT_IN_STRNCAT:
    3879          228 :     case BUILT_IN_STRNCMP:
    3880          228 :     case BUILT_IN_STRNCPY:
    3881          228 :     case BUILT_IN_STRPBRK:
    3882          228 :     case BUILT_IN_STRRCHR:
    3883          228 :     case BUILT_IN_STRSPN:
    3884          228 :     case BUILT_IN_STRSTR:
    3885          228 :       return "<string.h>";
    3886          544 :     case BUILT_IN_FPRINTF:
    3887          544 :     case BUILT_IN_PUTC:
    3888          544 :     case BUILT_IN_FPUTC:
    3889          544 :     case BUILT_IN_FPUTS:
    3890          544 :     case BUILT_IN_FSCANF:
    3891          544 :     case BUILT_IN_FWRITE:
    3892          544 :     case BUILT_IN_PRINTF:
    3893          544 :     case BUILT_IN_PUTCHAR:
    3894          544 :     case BUILT_IN_PUTS:
    3895          544 :     case BUILT_IN_SCANF:
    3896          544 :     case BUILT_IN_SNPRINTF:
    3897          544 :     case BUILT_IN_SPRINTF:
    3898          544 :     case BUILT_IN_SSCANF:
    3899          544 :     case BUILT_IN_VFPRINTF:
    3900          544 :     case BUILT_IN_VFSCANF:
    3901          544 :     case BUILT_IN_VPRINTF:
    3902          544 :     case BUILT_IN_VSCANF:
    3903          544 :     case BUILT_IN_VSNPRINTF:
    3904          544 :     case BUILT_IN_VSPRINTF:
    3905          544 :     case BUILT_IN_VSSCANF:
    3906          544 :       return "<stdio.h>";
    3907            2 :     case BUILT_IN_ISALNUM:
    3908            2 :     case BUILT_IN_ISALPHA:
    3909            2 :     case BUILT_IN_ISBLANK:
    3910            2 :     case BUILT_IN_ISCNTRL:
    3911            2 :     case BUILT_IN_ISDIGIT:
    3912            2 :     case BUILT_IN_ISGRAPH:
    3913            2 :     case BUILT_IN_ISLOWER:
    3914            2 :     case BUILT_IN_ISPRINT:
    3915            2 :     case BUILT_IN_ISPUNCT:
    3916            2 :     case BUILT_IN_ISSPACE:
    3917            2 :     case BUILT_IN_ISUPPER:
    3918            2 :     case BUILT_IN_ISXDIGIT:
    3919            2 :     case BUILT_IN_TOLOWER:
    3920            2 :     case BUILT_IN_TOUPPER:
    3921            2 :       return "<ctype.h>";
    3922            0 :     case BUILT_IN_ISWALNUM:
    3923            0 :     case BUILT_IN_ISWALPHA:
    3924            0 :     case BUILT_IN_ISWBLANK:
    3925            0 :     case BUILT_IN_ISWCNTRL:
    3926            0 :     case BUILT_IN_ISWDIGIT:
    3927            0 :     case BUILT_IN_ISWGRAPH:
    3928            0 :     case BUILT_IN_ISWLOWER:
    3929            0 :     case BUILT_IN_ISWPRINT:
    3930            0 :     case BUILT_IN_ISWPUNCT:
    3931            0 :     case BUILT_IN_ISWSPACE:
    3932            0 :     case BUILT_IN_ISWUPPER:
    3933            0 :     case BUILT_IN_ISWXDIGIT:
    3934            0 :     case BUILT_IN_TOWLOWER:
    3935            0 :     case BUILT_IN_TOWUPPER:
    3936            0 :       return "<wctype.h>";
    3937         1818 :     case BUILT_IN_ABORT:
    3938         1818 :     case BUILT_IN_ABS:
    3939         1818 :     case BUILT_IN_CALLOC:
    3940         1818 :     case BUILT_IN_EXIT:
    3941         1818 :     case BUILT_IN_FREE:
    3942         1818 :     case BUILT_IN_LABS:
    3943         1818 :     case BUILT_IN_LLABS:
    3944         1818 :     case BUILT_IN_MALLOC:
    3945         1818 :     case BUILT_IN_REALLOC:
    3946         1818 :     case BUILT_IN__EXIT2:
    3947         1818 :     case BUILT_IN_ALIGNED_ALLOC:
    3948         1818 :       return "<stdlib.h>";
    3949            1 :     case BUILT_IN_IMAXABS:
    3950            1 :       return "<inttypes.h>";
    3951            3 :     case BUILT_IN_STRFTIME:
    3952            3 :       return "<time.h>";
    3953              :     default:
    3954              :       return NULL;
    3955              :     }
    3956              : }
    3957              : 
    3958              : /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
    3959              :    function of type int ().  */
    3960              : 
    3961              : tree
    3962         4729 : implicitly_declare (location_t loc, tree functionid)
    3963              : {
    3964         4729 :   struct c_binding *b;
    3965         4729 :   tree decl = NULL_TREE;
    3966         4729 :   tree asmspec_tree;
    3967              : 
    3968         4743 :   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
    3969              :     {
    3970         3158 :       if (B_IN_SCOPE (b, external_scope))
    3971              :         {
    3972         3144 :           decl = b->decl;
    3973         3144 :           break;
    3974              :         }
    3975              :     }
    3976              : 
    3977         4729 :   if (decl)
    3978              :     {
    3979         3144 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    3980              :         return decl;
    3981              : 
    3982              :       /* FIXME: Objective-C has weird not-really-builtin functions
    3983              :          which are supposed to be visible automatically.  They wind up
    3984              :          in the external scope because they're pushed before the file
    3985              :          scope gets created.  Catch this here and rebind them into the
    3986              :          file scope.  */
    3987         3137 :       if (!fndecl_built_in_p (decl) && DECL_IS_UNDECLARED_BUILTIN (decl))
    3988              :         {
    3989            0 :           bind (functionid, decl, file_scope,
    3990              :                 /*invisible=*/false, /*nested=*/true,
    3991            0 :                 DECL_SOURCE_LOCATION (decl));
    3992            0 :           return decl;
    3993              :         }
    3994              :       else
    3995              :         {
    3996         3137 :           tree newtype = default_function_type;
    3997         3137 :           if (b->u.type)
    3998          753 :             TREE_TYPE (decl) = b->u.type;
    3999              :           /* Implicit declaration of a function already declared
    4000              :              (somehow) in a different scope, or as a built-in.
    4001              :              If this is the first time this has happened, warn;
    4002              :              then recycle the old declaration but with the new type.  */
    4003         3137 :           if (!C_DECL_IMPLICIT (decl))
    4004              :             {
    4005         2191 :               implicit_decl_permerror (loc, functionid, decl);
    4006         2191 :               C_DECL_IMPLICIT (decl) = 1;
    4007              :             }
    4008         3137 :           if (fndecl_built_in_p (decl))
    4009              :             {
    4010         2705 :               newtype = c_build_type_attribute_variant (newtype,
    4011         2705 :                                                         TYPE_ATTRIBUTES
    4012              :                                                         (TREE_TYPE (decl)));
    4013         2705 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4014              :                 {
    4015         2528 :                   auto_diagnostic_group d;
    4016         2528 :                   bool warned = warning_at (loc,
    4017         2528 :                                             OPT_Wbuiltin_declaration_mismatch,
    4018              :                                             "incompatible implicit "
    4019              :                                             "declaration of built-in "
    4020              :                                             "function %qD", decl);
    4021              :                   /* See if we can hint which header to include.  */
    4022         2528 :                   const char *header = header_for_builtin_fn (decl);
    4023         2528 :                   if (header != NULL && warned)
    4024              :                     {
    4025          133 :                       rich_location richloc (line_table, loc);
    4026          133 :                       maybe_add_include_fixit (&richloc, header, true);
    4027          133 :                       inform (&richloc,
    4028              :                               "include %qs or provide a declaration of %qD",
    4029              :                               header, decl);
    4030          133 :                     }
    4031         2528 :                   newtype = TREE_TYPE (decl);
    4032         2528 :                 }
    4033              :             }
    4034              :           else
    4035              :             {
    4036          432 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4037              :                 {
    4038            2 :                   auto_diagnostic_group d;
    4039            2 :                   error_at (loc, "incompatible implicit declaration of "
    4040              :                             "function %qD", decl);
    4041            2 :                   locate_old_decl (decl);
    4042            2 :                 }
    4043              :             }
    4044         3137 :           b->u.type = TREE_TYPE (decl);
    4045         3137 :           TREE_TYPE (decl) = newtype;
    4046         3137 :           bind (functionid, decl, current_scope,
    4047              :                 /*invisible=*/false, /*nested=*/true,
    4048         3137 :                 DECL_SOURCE_LOCATION (decl));
    4049         3137 :           return decl;
    4050              :         }
    4051              :     }
    4052              : 
    4053              :   /* Not seen before.  */
    4054         1585 :   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
    4055         1585 :   DECL_EXTERNAL (decl) = 1;
    4056         1585 :   TREE_PUBLIC (decl) = 1;
    4057         1585 :   C_DECL_IMPLICIT (decl) = 1;
    4058         1585 :   implicit_decl_permerror (loc, functionid, 0);
    4059         1585 :   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
    4060         1585 :   if (asmspec_tree)
    4061            1 :     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
    4062              : 
    4063              :   /* C89 says implicit declarations are in the innermost block.
    4064              :      So we record the decl in the standard fashion.  */
    4065         1585 :   decl = pushdecl (decl);
    4066              : 
    4067              :   /* No need to call objc_check_decl here - it's a function type.  */
    4068         1585 :   rest_of_decl_compilation (decl, 0, 0);
    4069              : 
    4070              :   /* Write a record describing this implicit function declaration
    4071              :      to the prototypes file (if requested).  */
    4072         1585 :   gen_aux_info_record (decl, 0, 1, 0);
    4073              : 
    4074              :   /* Possibly apply some default attributes to this implicit declaration.  */
    4075         1585 :   decl_attributes (&decl, NULL_TREE, 0);
    4076              : 
    4077         1585 :   return decl;
    4078              : }
    4079              : 
    4080              : /* Issue an error message for a reference to an undeclared variable
    4081              :    ID, including a reference to a builtin outside of function-call
    4082              :    context.  Establish a binding of the identifier to error_mark_node
    4083              :    in an appropriate scope, which will suppress further errors for the
    4084              :    same identifier.  The error message should be given location LOC.  */
    4085              : void
    4086         1256 : undeclared_variable (location_t loc, tree id)
    4087              : {
    4088         1256 :   static bool already = false;
    4089         1256 :   struct c_scope *scope;
    4090              : 
    4091         1256 :   auto_diagnostic_group d;
    4092         1256 :   if (current_function_decl == NULL_TREE)
    4093              :     {
    4094          432 :       name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4095          432 :       if (const char *suggestion = guessed_id.suggestion ())
    4096              :         {
    4097           86 :           gcc_rich_location richloc (loc);
    4098           86 :           richloc.add_fixit_replace (suggestion);
    4099           86 :           error_at (&richloc,
    4100              :                     "%qE undeclared here (not in a function);"
    4101              :                     " did you mean %qs?",
    4102              :                     id, suggestion);
    4103           86 :         }
    4104              :       else
    4105          346 :         error_at (loc, "%qE undeclared here (not in a function)", id);
    4106          432 :       scope = current_scope;
    4107          432 :     }
    4108              :   else
    4109              :     {
    4110          824 :       if (!objc_diagnose_private_ivar (id))
    4111              :         {
    4112          824 :           name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4113          824 :           if (const char *suggestion = guessed_id.suggestion ())
    4114              :             {
    4115           39 :               gcc_rich_location richloc (loc);
    4116           39 :               richloc.add_fixit_replace (suggestion);
    4117           39 :               error_at (&richloc,
    4118              :                         "%qE undeclared (first use in this function);"
    4119              :                         " did you mean %qs?",
    4120              :                         id, suggestion);
    4121           39 :             }
    4122              :           else
    4123          785 :             error_at (loc, "%qE undeclared (first use in this function)", id);
    4124          824 :         }
    4125          824 :       if (!already)
    4126              :         {
    4127          201 :           inform (loc, "each undeclared identifier is reported only"
    4128              :                   " once for each function it appears in");
    4129          201 :           already = true;
    4130              :         }
    4131              : 
    4132              :       /* If we are parsing old-style parameter decls, current_function_decl
    4133              :          will be nonnull but current_function_scope will be null.  */
    4134          824 :       scope = current_function_scope ? current_function_scope : current_scope;
    4135              :     }
    4136         1256 :   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
    4137              :         UNKNOWN_LOCATION);
    4138         1256 : }
    4139              : 
    4140              : /* Subroutine of lookup_label, declare_label, define_label: construct a
    4141              :    LABEL_DECL with all the proper frills.  Also create a struct
    4142              :    c_label_vars initialized for the current scope.  */
    4143              : 
    4144              : static tree
    4145        24072 : make_label (location_t location, tree name, bool defining,
    4146              :             struct c_label_vars **p_label_vars)
    4147              : {
    4148        24072 :   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
    4149        24072 :   DECL_CONTEXT (label) = current_function_decl;
    4150        24072 :   SET_DECL_MODE (label, VOIDmode);
    4151              : 
    4152        24072 :   c_label_vars *label_vars = ggc_alloc<c_label_vars> ();
    4153        24072 :   label_vars->shadowed = NULL;
    4154        24072 :   set_spot_bindings (&label_vars->label_bindings, defining);
    4155        24072 :   label_vars->decls_in_scope = make_tree_vector ();
    4156        24072 :   label_vars->gotos = NULL;
    4157        24072 :   *p_label_vars = label_vars;
    4158              : 
    4159        24072 :   return label;
    4160              : }
    4161              : 
    4162              : /* Get the LABEL_DECL corresponding to identifier NAME as a label.
    4163              :    Create one if none exists so far for the current function.
    4164              :    This is called when a label is used in a goto expression or
    4165              :    has its address taken.  */
    4166              : 
    4167              : tree
    4168        85558 : lookup_label (tree name)
    4169              : {
    4170        85558 :   tree label;
    4171        85558 :   struct c_label_vars *label_vars;
    4172              : 
    4173        85558 :   if (current_function_scope == 0)
    4174              :     {
    4175            2 :       error ("label %qE referenced outside of any function", name);
    4176            2 :       return NULL_TREE;
    4177              :     }
    4178              : 
    4179              :   /* Use a label already defined or ref'd with this name, but not if
    4180              :      it is inherited from a containing function and wasn't declared
    4181              :      using __label__.  */
    4182        85556 :   label = I_LABEL_DECL (name);
    4183        79555 :   if (label && (DECL_CONTEXT (label) == current_function_decl
    4184          608 :                 || C_DECLARED_LABEL_FLAG (label)))
    4185              :     {
    4186              :       /* If the label has only been declared, update its apparent
    4187              :          location to point here, for better diagnostics if it
    4188              :          turns out not to have been defined.  */
    4189        79548 :       if (DECL_INITIAL (label) == NULL_TREE)
    4190        62693 :         DECL_SOURCE_LOCATION (label) = input_location;
    4191        79548 :       return label;
    4192              :     }
    4193              : 
    4194              :   /* No label binding for that identifier; make one.  */
    4195         6008 :   label = make_label (input_location, name, false, &label_vars);
    4196              : 
    4197              :   /* Ordinary labels go in the current function scope.  */
    4198         6008 :   bind_label (name, label, current_function_scope, label_vars);
    4199              : 
    4200         6008 :   return label;
    4201              : }
    4202              : 
    4203              : /* Issue a warning about DECL for a goto statement at GOTO_LOC going
    4204              :    to LABEL.  */
    4205              : 
    4206              : static void
    4207         1490 : warn_about_goto (location_t goto_loc, tree label, tree decl)
    4208              : {
    4209         1490 :   auto_diagnostic_group d;
    4210         1490 :   if (c_type_variably_modified_p (TREE_TYPE (decl)))
    4211         1484 :     error_at (goto_loc,
    4212              :               "jump into scope of identifier with variably modified type");
    4213            6 :   else if (flag_openmp
    4214            6 :            && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
    4215            2 :     error_at (goto_loc, "jump skips OpenMP %<allocate%> allocation");
    4216              :   else
    4217            4 :     if (!warning_at (goto_loc, OPT_Wjump_misses_init,
    4218              :                      "jump skips variable initialization"))
    4219            0 :       return;
    4220         1490 :   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4221         1490 :   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
    4222         1490 : }
    4223              : 
    4224              : /* Look up a label because of a goto statement.  This is like
    4225              :    lookup_label, but also issues any appropriate warnings.  */
    4226              : 
    4227              : tree
    4228        83717 : lookup_label_for_goto (location_t loc, tree name)
    4229              : {
    4230        83717 :   tree label;
    4231        83717 :   struct c_label_vars *label_vars;
    4232        83717 :   unsigned int ix;
    4233        83717 :   tree decl;
    4234              : 
    4235        83717 :   label = lookup_label (name);
    4236        83717 :   if (label == NULL_TREE)
    4237              :     return NULL_TREE;
    4238              : 
    4239              :   /* If we are jumping to a different function, we can't issue any
    4240              :      useful warnings.  */
    4241        83717 :   if (DECL_CONTEXT (label) != current_function_decl)
    4242              :     {
    4243          522 :       gcc_assert (C_DECLARED_LABEL_FLAG (label));
    4244              :       return label;
    4245              :     }
    4246              : 
    4247        83195 :   label_vars = I_LABEL_BINDING (name)->u.label;
    4248              : 
    4249              :   /* If the label has not yet been defined, then push this goto on a
    4250              :      list for possible later warnings.  */
    4251        83195 :   if (label_vars->label_bindings.scope == NULL)
    4252              :     {
    4253        66565 :       c_goto_bindings *g = ggc_alloc<c_goto_bindings> ();
    4254              : 
    4255        66565 :       g->loc = loc;
    4256        66565 :       set_spot_bindings (&g->goto_bindings, true);
    4257        66565 :       vec_safe_push (label_vars->gotos, g);
    4258        66565 :       return label;
    4259              :     }
    4260              : 
    4261              :   /* If there are any decls in label_vars->decls_in_scope, then this
    4262              :      goto has missed the declaration of the decl.  This happens for a
    4263              :      case like
    4264              :        int i = 1;
    4265              :       lab:
    4266              :        ...
    4267              :        goto lab;
    4268              :      Issue a warning or error.  */
    4269        17405 :   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
    4270          775 :     warn_about_goto (loc, label, decl);
    4271              : 
    4272        16630 :   if (label_vars->label_bindings.left_stmt_expr)
    4273              :     {
    4274          120 :       auto_diagnostic_group d;
    4275          120 :       error_at (loc, "jump into statement expression");
    4276          120 :       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4277          120 :     }
    4278              : 
    4279              :   return label;
    4280              : }
    4281              : 
    4282              : /* Make a label named NAME in the current function, shadowing silently
    4283              :    any that may be inherited from containing functions or containing
    4284              :    scopes.  This is called for __label__ declarations.  */
    4285              : 
    4286              : tree
    4287         1192 : declare_label (tree name)
    4288              : {
    4289         1192 :   struct c_binding *b = I_LABEL_BINDING (name);
    4290         1192 :   tree label;
    4291         1192 :   struct c_label_vars *label_vars;
    4292              : 
    4293              :   /* Check to make sure that the label hasn't already been declared
    4294              :      at this scope */
    4295         1192 :   if (b && B_IN_CURRENT_SCOPE (b))
    4296              :     {
    4297            2 :       auto_diagnostic_group d;
    4298            2 :       error ("duplicate label declaration %qE", name);
    4299            2 :       locate_old_decl (b->decl);
    4300              : 
    4301              :       /* Just use the previous declaration.  */
    4302            2 :       return b->decl;
    4303            2 :     }
    4304              : 
    4305         1190 :   label = make_label (input_location, name, false, &label_vars);
    4306         1190 :   C_DECLARED_LABEL_FLAG (label) = 1;
    4307              : 
    4308              :   /* Declared labels go in the current scope.  */
    4309         1190 :   bind_label (name, label, current_scope, label_vars);
    4310              : 
    4311         1190 :   return label;
    4312              : }
    4313              : 
    4314              : /* When we define a label, issue any appropriate warnings if there are
    4315              :    any gotos earlier in the function which jump to this label.  */
    4316              : 
    4317              : static void
    4318         7118 : check_earlier_gotos (tree label, struct c_label_vars* label_vars)
    4319              : {
    4320         7118 :   unsigned int ix;
    4321         7118 :   struct c_goto_bindings *g;
    4322              : 
    4323        73617 :   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    4324              :     {
    4325        66499 :       struct c_binding *b;
    4326        66499 :       struct c_scope *scope;
    4327              : 
    4328              :       /* We have a goto to this label.  The goto is going forward.  In
    4329              :          g->scope, the goto is going to skip any binding which was
    4330              :          defined after g->bindings_in_scope.  */
    4331        66499 :       if (g->goto_bindings.scope->has_jump_unsafe_decl)
    4332              :         {
    4333          255 :           for (b = g->goto_bindings.scope->bindings;
    4334          593 :                b != g->goto_bindings.bindings_in_scope;
    4335          338 :                b = b->prev)
    4336              :             {
    4337          338 :               if (decl_jump_unsafe (b->decl))
    4338          176 :                 warn_about_goto (g->loc, label, b->decl);
    4339              :             }
    4340              :         }
    4341              : 
    4342              :       /* We also need to warn about decls defined in any scopes
    4343              :          between the scope of the label and the scope of the goto.  */
    4344        66499 :       for (scope = label_vars->label_bindings.scope;
    4345        69193 :            scope != g->goto_bindings.scope;
    4346         2694 :            scope = scope->outer)
    4347              :         {
    4348         2694 :           gcc_assert (scope != NULL);
    4349         2694 :           if (scope->has_jump_unsafe_decl)
    4350              :             {
    4351          325 :               if (scope == label_vars->label_bindings.scope)
    4352          249 :                 b = label_vars->label_bindings.bindings_in_scope;
    4353              :               else
    4354           76 :                 b = scope->bindings;
    4355          864 :               for (; b != NULL; b = b->prev)
    4356              :                 {
    4357          539 :                   if (decl_jump_unsafe (b->decl))
    4358          539 :                     warn_about_goto (g->loc, label, b->decl);
    4359              :                 }
    4360              :             }
    4361              :         }
    4362              : 
    4363        66499 :       if (g->goto_bindings.stmt_exprs > 0)
    4364              :         {
    4365          100 :           auto_diagnostic_group d;
    4366          100 :           error_at (g->loc, "jump into statement expression");
    4367          100 :           inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
    4368              :                   label);
    4369          100 :         }
    4370              :     }
    4371              : 
    4372              :   /* Now that the label is defined, we will issue warnings about
    4373              :      subsequent gotos to this label when we see them.  */
    4374         7118 :   vec_safe_truncate (label_vars->gotos, 0);
    4375         7118 :   label_vars->gotos = NULL;
    4376         7118 : }
    4377              : 
    4378              : /* Define a label, specifying the location in the source file.
    4379              :    Return the LABEL_DECL node for the label, if the definition is valid.
    4380              :    Otherwise return NULL_TREE.  */
    4381              : 
    4382              : tree
    4383        24021 : define_label (location_t location, tree name)
    4384              : {
    4385              :   /* Find any preexisting label with this name.  It is an error
    4386              :      if that label has already been defined in this function, or
    4387              :      if there is a containing function with a declared label with
    4388              :      the same name.  */
    4389        24021 :   tree label = I_LABEL_DECL (name);
    4390              : 
    4391         7154 :   if (label
    4392         7154 :       && ((DECL_CONTEXT (label) == current_function_decl
    4393         7140 :            && DECL_INITIAL (label) != NULL_TREE)
    4394         7132 :           || (DECL_CONTEXT (label) != current_function_decl
    4395           14 :               && C_DECLARED_LABEL_FLAG (label))))
    4396              :     {
    4397           29 :       auto_diagnostic_group d;
    4398           29 :       error_at (location, "duplicate label %qD", label);
    4399           29 :       locate_old_decl (label);
    4400           29 :       return NULL_TREE;
    4401           29 :     }
    4402        23992 :   else if (label && DECL_CONTEXT (label) == current_function_decl)
    4403              :     {
    4404         7118 :       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
    4405              : 
    4406              :       /* The label has been used or declared already in this function,
    4407              :          but not defined.  Update its location to point to this
    4408              :          definition.  */
    4409         7118 :       DECL_SOURCE_LOCATION (label) = location;
    4410         7118 :       set_spot_bindings (&label_vars->label_bindings, true);
    4411              : 
    4412              :       /* Issue warnings as required about any goto statements from
    4413              :          earlier in the function.  */
    4414         7118 :       check_earlier_gotos (label, label_vars);
    4415              :     }
    4416              :   else
    4417              :     {
    4418        16874 :       struct c_label_vars *label_vars;
    4419              : 
    4420              :       /* No label binding for that identifier; make one.  */
    4421        16874 :       label = make_label (location, name, true, &label_vars);
    4422              : 
    4423              :       /* Ordinary labels go in the current function scope.  */
    4424        16874 :       bind_label (name, label, current_function_scope, label_vars);
    4425              :     }
    4426              : 
    4427        23992 :   if (!in_system_header_at (input_location) && lookup_name (name))
    4428          139 :     warning_at (location, OPT_Wtraditional,
    4429              :                 "traditional C lacks a separate namespace "
    4430              :                 "for labels, identifier %qE conflicts", name);
    4431              : 
    4432              :   /* Mark label as having been defined.  */
    4433        23992 :   DECL_INITIAL (label) = error_mark_node;
    4434        23992 :   return label;
    4435              : }
    4436              : 
    4437              : /* Get the bindings for a new switch statement.  This is used to issue
    4438              :    warnings as appropriate for jumps from the switch to case or
    4439              :    default labels.  */
    4440              : 
    4441              : struct c_spot_bindings *
    4442        37365 : c_get_switch_bindings (void)
    4443              : {
    4444        37365 :   struct c_spot_bindings *switch_bindings;
    4445              : 
    4446        37365 :   switch_bindings = XNEW (struct c_spot_bindings);
    4447        37365 :   set_spot_bindings (switch_bindings, true);
    4448        37365 :   return switch_bindings;
    4449              : }
    4450              : 
    4451              : void
    4452        37365 : c_release_switch_bindings (struct c_spot_bindings *bindings)
    4453              : {
    4454        37365 :   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
    4455        37365 :   XDELETE (bindings);
    4456        37365 : }
    4457              : 
    4458              : /* This is called at the point of a case or default label to issue
    4459              :    warnings about decls as needed.  It returns true if it found an
    4460              :    error, not just a warning.  */
    4461              : 
    4462              : bool
    4463      1030563 : c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
    4464              :                               location_t switch_loc, location_t case_loc)
    4465              : {
    4466      1030563 :   bool saw_error;
    4467      1030563 :   struct c_scope *scope;
    4468              : 
    4469      1030563 :   saw_error = false;
    4470      1030563 :   for (scope = current_scope;
    4471      3091693 :        scope != switch_bindings->scope;
    4472      2061130 :        scope = scope->outer)
    4473              :     {
    4474      2061130 :       struct c_binding *b;
    4475              : 
    4476      2061130 :       gcc_assert (scope != NULL);
    4477              : 
    4478      2061130 :       if (!scope->has_jump_unsafe_decl)
    4479      2061119 :         continue;
    4480              : 
    4481           22 :       for (b = scope->bindings; b != NULL; b = b->prev)
    4482              :         {
    4483           11 :           if (decl_jump_unsafe (b->decl))
    4484              :             {
    4485           11 :               auto_diagnostic_group d;
    4486           11 :               bool emitted;
    4487           11 :               if (c_type_variably_modified_p (TREE_TYPE (b->decl)))
    4488              :                 {
    4489            6 :                   saw_error = true;
    4490            6 :                   error_at (case_loc,
    4491              :                             "switch jumps into scope of identifier with "
    4492              :                             "variably modified type");
    4493            6 :                   emitted = true;
    4494              :                 }
    4495            5 :               else if (flag_openmp
    4496            7 :                        && lookup_attribute ("omp allocate",
    4497            2 :                                             DECL_ATTRIBUTES (b->decl)))
    4498              :                 {
    4499            2 :                   saw_error = true;
    4500            2 :                   error_at (case_loc,
    4501              :                             "switch jumps over OpenMP %<allocate%> allocation");
    4502            2 :                   emitted = true;
    4503              :                 }
    4504              :               else
    4505            3 :                 emitted
    4506            3 :                   = warning_at (case_loc, OPT_Wjump_misses_init,
    4507              :                                 "switch jumps over variable initialization");
    4508           11 :               if (emitted)
    4509              :                 {
    4510           11 :                   inform (switch_loc, "switch starts here");
    4511           11 :                   inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
    4512              :                           b->decl);
    4513              :                 }
    4514           11 :             }
    4515              :         }
    4516              :     }
    4517              : 
    4518      1030563 :   if (switch_bindings->stmt_exprs > 0)
    4519              :     {
    4520            4 :       saw_error = true;
    4521            4 :       auto_diagnostic_group d;
    4522            4 :       error_at (case_loc, "switch jumps into statement expression");
    4523            4 :       inform (switch_loc, "switch starts here");
    4524            4 :     }
    4525              : 
    4526      1030563 :   return saw_error;
    4527              : }
    4528              : 
    4529              : /* Given NAME, an IDENTIFIER_NODE,
    4530              :    return the structure (or union or enum) definition for that name.
    4531              :    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
    4532              :    CODE says which kind of type the caller wants;
    4533              :    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
    4534              :    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
    4535              :    location where the tag was defined.
    4536              :    If the wrong kind of type is found, an error is reported.  */
    4537              : 
    4538              : static tree
    4539      2093327 : lookup_tag (enum tree_code code, tree name, bool thislevel_only,
    4540              :             location_t *ploc)
    4541              : {
    4542      2093327 :   struct c_binding *b = I_TAG_BINDING (name);
    4543      2093327 :   bool thislevel = false;
    4544              : 
    4545      2093327 :   if (!b || !b->decl)
    4546              :     return NULL_TREE;
    4547              : 
    4548              :   /* We only care about whether it's in this level if
    4549              :      thislevel_only was set or it might be a type clash.  */
    4550      1464370 :   if (thislevel_only || TREE_CODE (b->decl) != code)
    4551              :     {
    4552              :       /* For our purposes, a tag in the external scope is the same as
    4553              :          a tag in the file scope.  (Primarily relevant to Objective-C
    4554              :          and its builtin structure tags, which get pushed before the
    4555              :          file scope is created.)  */
    4556       469995 :       if (B_IN_CURRENT_SCOPE (b)
    4557          196 :           || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    4558      1464370 :         thislevel = true;
    4559              :     }
    4560              : 
    4561      1464370 :   if (thislevel_only && !thislevel)
    4562              :     return NULL_TREE;
    4563              : 
    4564      1464195 :   if (TREE_CODE (b->decl) != code)
    4565              :     {
    4566              :       /* Definition isn't the kind we were looking for.  */
    4567           39 :       pending_invalid_xref = name;
    4568           39 :       pending_invalid_xref_location = input_location;
    4569              : 
    4570              :       /* If in the same binding level as a declaration as a tag
    4571              :          of a different type, this must not be allowed to
    4572              :          shadow that tag, so give the error immediately.
    4573              :          (For example, "struct foo; union foo;" is invalid.)  */
    4574           39 :       if (thislevel)
    4575           18 :         pending_xref_error ();
    4576              :     }
    4577              : 
    4578      1464195 :   if (ploc != NULL)
    4579      1019953 :     *ploc = b->locus;
    4580              : 
    4581      1464195 :   return b->decl;
    4582              : }
    4583              : 
    4584              : /* Return true if a definition exists for NAME with code CODE.  */
    4585              : 
    4586              : bool
    4587          387 : tag_exists_p (enum tree_code code, tree name)
    4588              : {
    4589          387 :   struct c_binding *b = I_TAG_BINDING (name);
    4590              : 
    4591          387 :   if (b == NULL || b->decl == NULL_TREE)
    4592              :     return false;
    4593           18 :   return TREE_CODE (b->decl) == code;
    4594              : }
    4595              : 
    4596              : /* Print an error message now
    4597              :    for a recent invalid struct, union or enum cross reference.
    4598              :    We don't print them immediately because they are not invalid
    4599              :    when used in the `struct foo;' construct for shadowing.  */
    4600              : 
    4601              : void
    4602    314720405 : pending_xref_error (void)
    4603              : {
    4604    314720405 :   if (pending_invalid_xref != NULL_TREE)
    4605           27 :     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
    4606              :               pending_invalid_xref);
    4607    314720405 :   pending_invalid_xref = NULL_TREE;
    4608    314720405 : }
    4609              : 
    4610              : 
    4611              : /* Look up NAME in the current scope and its superiors
    4612              :    in the namespace of variables, functions and typedefs.
    4613              :    Return a ..._DECL node of some kind representing its definition,
    4614              :    or return NULL_TREE if it is undefined.  */
    4615              : 
    4616              : tree
    4617   1269991806 : lookup_name (tree name)
    4618              : {
    4619   1269991806 :   struct c_binding *b = I_SYMBOL_BINDING (name);
    4620              :   /* Do not resolve non-default function versions.  */
    4621   1269991806 :   if (b
    4622    857238890 :       && TREE_CODE (b->decl) == FUNCTION_DECL
    4623    117631471 :       && DECL_FUNCTION_VERSIONED (b->decl)
    4624   1269991806 :       && !is_function_default_version (b->decl))
    4625              :     return NULL_TREE;
    4626   1269991806 :   if (b && !b->invisible)
    4627              :     {
    4628    846098275 :       maybe_record_typedef_use (b->decl);
    4629    846098275 :       return b->decl;
    4630              :     }
    4631              :   return NULL_TREE;
    4632              : }
    4633              : 
    4634              : /* Similar to `lookup_name' but look only at the indicated scope.  */
    4635              : 
    4636              : static tree
    4637    132038109 : lookup_name_in_scope (tree name, struct c_scope *scope)
    4638              : {
    4639    132038109 :   struct c_binding *b;
    4640              : 
    4641    132041341 :   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
    4642      7643706 :     if (B_IN_SCOPE (b, scope))
    4643      7640474 :       return b->decl;
    4644              :   return NULL_TREE;
    4645              : }
    4646              : 
    4647              : /* Look for the closest match for NAME within the currently valid
    4648              :    scopes.
    4649              : 
    4650              :    This finds the identifier with the lowest Levenshtein distance to
    4651              :    NAME.  If there are multiple candidates with equal minimal distance,
    4652              :    the first one found is returned.  Scopes are searched from innermost
    4653              :    outwards, and within a scope in reverse order of declaration, thus
    4654              :    benefiting candidates "near" to the current scope.
    4655              : 
    4656              :    The function also looks for similar macro names to NAME, since a
    4657              :    misspelled macro name will not be expanded, and hence looks like an
    4658              :    identifier to the C frontend.
    4659              : 
    4660              :    It also looks for start_typename keywords, to detect "singed" vs "signed"
    4661              :    typos.
    4662              : 
    4663              :    Use LOC for any deferred diagnostics.  */
    4664              : 
    4665              : name_hint
    4666         2064 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    4667              : {
    4668         2064 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    4669              : 
    4670              :   /* Look up function-like macros first; maybe misusing them. */
    4671         4128 :   auto cpp_node = cpp_lookup (parse_in,
    4672         2064 :                               (const unsigned char*)IDENTIFIER_POINTER (name),
    4673         2064 :                               IDENTIFIER_LENGTH (name));
    4674         2064 :   if (cpp_node && cpp_fun_like_macro_p (cpp_node))
    4675            5 :     return name_hint
    4676              :       (nullptr,
    4677            5 :        std::make_unique<macro_like_function_used> (loc,
    4678           10 :                                                    IDENTIFIER_POINTER (name)));
    4679              : 
    4680              :   /* Next, try some well-known names in the C standard library, in case
    4681              :      the user forgot a #include.  */
    4682         2059 :   const char *header_hint
    4683         2059 :     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    4684              : 
    4685         2059 :   if (header_hint)
    4686           56 :     return name_hint
    4687              :       (nullptr,
    4688           56 :        std::make_unique<suggest_missing_header> (loc,
    4689          112 :                                                  IDENTIFIER_POINTER (name),
    4690           56 :                                                  header_hint));
    4691              : 
    4692              :   /* Next, look for exact matches for builtin defines that would have been
    4693              :      defined if the user had passed a command-line option (e.g. -fopenmp
    4694              :      for "_OPENMP").  */
    4695         2003 :   diagnostics::option_id option_id
    4696         2003 :     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
    4697         2003 :   if (option_id.m_idx > 0)
    4698            2 :     return name_hint
    4699              :       (nullptr,
    4700            2 :        std::make_unique<suggest_missing_option> (loc,
    4701            4 :                                                  IDENTIFIER_POINTER (name),
    4702            2 :                                                  option_id));
    4703              : 
    4704              :   /* Only suggest names reserved for the implementation if NAME begins
    4705              :      with an underscore.  */
    4706         2001 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    4707              : 
    4708         2001 :   best_match<tree, tree> bm (name);
    4709              : 
    4710              :   /* Look within currently valid scopes.  */
    4711         9105 :   for (c_scope *scope = current_scope; scope; scope = scope->outer)
    4712     11380903 :     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
    4713              :       {
    4714     11373799 :         if (!binding->id || binding->invisible)
    4715      6428721 :           continue;
    4716      4945078 :         if (binding->decl == error_mark_node)
    4717          374 :           continue;
    4718              :         /* Don't use bindings from implicitly declared functions,
    4719              :            as they were likely misspellings themselves.  */
    4720      4944704 :         if (TREE_CODE (binding->decl) == FUNCTION_DECL)
    4721      4541141 :           if (C_DECL_IMPLICIT (binding->decl))
    4722          229 :             continue;
    4723              :         /* Don't suggest names that are reserved for use by the
    4724              :            implementation, unless NAME began with an underscore.  */
    4725      4944475 :         if (!consider_implementation_names)
    4726              :           {
    4727      2343855 :             const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
    4728      2343855 :             if (name_reserved_for_implementation_p (suggestion_str))
    4729      2285434 :               continue;
    4730              :           }
    4731      2659041 :         switch (kind)
    4732              :           {
    4733        31031 :           case FUZZY_LOOKUP_TYPENAME:
    4734        31031 :             if (TREE_CODE (binding->decl) != TYPE_DECL)
    4735        23576 :               continue;
    4736              :             break;
    4737              : 
    4738       129178 :           case FUZZY_LOOKUP_FUNCTION_NAME:
    4739       129178 :             if (TREE_CODE (binding->decl) != FUNCTION_DECL)
    4740              :               {
    4741              :                 /* Allow function pointers.  */
    4742        26502 :                 if ((VAR_P (binding->decl)
    4743        21977 :                      || TREE_CODE (binding->decl) == PARM_DECL)
    4744         5400 :                     && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
    4745        27782 :                     && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
    4746              :                         == FUNCTION_TYPE))
    4747              :                   break;
    4748        26483 :                 continue;
    4749              :               }
    4750              :             break;
    4751              : 
    4752              :           default:
    4753              :             break;
    4754              :           }
    4755      2608982 :         bm.consider (binding->id);
    4756              :       }
    4757              : 
    4758              :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    4759              :      as:
    4760              :        x = SOME_OTHER_MACRO (y);
    4761              :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    4762              :      as a misspelled identifier.
    4763              : 
    4764              :      Use the best distance so far so that a candidate is only set if
    4765              :      a macro is better than anything so far.  This allows early rejection
    4766              :      (without calculating the edit distance) of macro names that must have
    4767              :      distance >= bm.get_best_distance (), and means that we only get a
    4768              :      non-NULL result for best_macro_match if it's better than any of
    4769              :      the identifiers already checked, which avoids needless creation
    4770              :      of identifiers for macro hashnodes.  */
    4771         2001 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    4772         2001 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    4773              :   /* If a macro is the closest so far to NAME, use it, creating an
    4774              :      identifier tree node for it.  */
    4775         2001 :   if (best_macro)
    4776              :     {
    4777           11 :       const char *id = (const char *)best_macro->ident.str;
    4778           11 :       tree macro_as_identifier
    4779           11 :         = get_identifier_with_length (id, best_macro->ident.len);
    4780           11 :       bm.set_best_so_far (macro_as_identifier,
    4781              :                           bmm.get_best_distance (),
    4782              :                           bmm.get_best_candidate_length ());
    4783              :     }
    4784              : 
    4785              :   /* Try the "start_typename" keywords to detect
    4786              :      "singed" vs "signed" typos.  */
    4787         2001 :   if (kind == FUZZY_LOOKUP_TYPENAME)
    4788              :     {
    4789        56386 :       for (unsigned i = 0; i < num_c_common_reswords; i++)
    4790              :         {
    4791        56144 :           const c_common_resword *resword = &c_common_reswords[i];
    4792        56144 :           if (!c_keyword_starts_typename (resword->rid))
    4793        42834 :             continue;
    4794        13310 :           tree resword_identifier = ridpointers [resword->rid];
    4795        13310 :           if (!resword_identifier)
    4796           30 :             continue;
    4797        13280 :           gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    4798        13280 :           bm.consider (resword_identifier);
    4799              :         }
    4800              :     }
    4801              : 
    4802         2001 :   tree best = bm.get_best_meaningful_candidate ();
    4803         2001 :   if (best)
    4804          278 :     return name_hint (IDENTIFIER_POINTER (best), NULL);
    4805              :   else
    4806         1723 :     return name_hint (NULL, NULL);
    4807              : }
    4808              : 
    4809              : 
    4810              : /* Handle the standard [[nodiscard]] attribute.  */
    4811              : 
    4812              : static tree
    4813           34 : handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
    4814              :                             int /*flags*/, bool *no_add_attrs)
    4815              : {
    4816           34 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4817              :     {
    4818           18 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
    4819            1 :         warning_at (DECL_SOURCE_LOCATION (*node),
    4820            1 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    4821              :                     "return type", name, *node);
    4822              :     }
    4823           16 :   else if (RECORD_OR_UNION_TYPE_P (*node)
    4824           12 :            || TREE_CODE (*node) == ENUMERAL_TYPE)
    4825              :     /* OK */;
    4826              :   else
    4827              :     {
    4828           10 :       pedwarn (input_location,
    4829           10 :                OPT_Wattributes, "%qE attribute can only be applied to "
    4830              :                "functions or to structure, union or enumeration types", name);
    4831           10 :       *no_add_attrs = true;
    4832              :     }
    4833           34 :   return NULL_TREE;
    4834              : }
    4835              : 
    4836              : /* Handle the standard [[noreturn]] attribute.  */
    4837              : 
    4838              : static tree
    4839           44 : handle_std_noreturn_attribute (tree *node, tree name, tree args,
    4840              :                                int flags, bool *no_add_attrs)
    4841              : {
    4842              :   /* Unlike GNU __attribute__ ((noreturn)), the standard [[noreturn]]
    4843              :      only applies to functions, not function pointers.  */
    4844           44 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4845           22 :     return handle_noreturn_attribute (node, name, args, flags, no_add_attrs);
    4846              :   else
    4847              :     {
    4848           22 :       pedwarn (input_location, OPT_Wattributes,
    4849              :                "standard %qE attribute can only be applied to functions",
    4850              :                name);
    4851           22 :       *no_add_attrs = true;
    4852           22 :       return NULL_TREE;
    4853              :     }
    4854              : }
    4855              : 
    4856              : /* Handle the standard [[unsequenced]] attribute.  */
    4857              : 
    4858              : static tree
    4859           68 : handle_std_unsequenced_attribute (tree *node, tree name, tree args,
    4860              :                                   int flags, bool *no_add_attrs)
    4861              : {
    4862              :   /* Unlike GNU __attribute__ ((unsequenced)), the standard [[unsequenced]]
    4863              :      should be only applied to function declarators or type specifiers which
    4864              :      have function type.  */
    4865           68 :   if (node[2])
    4866              :     {
    4867            8 :       auto_diagnostic_group d;
    4868            8 :       if (pedwarn (input_location, OPT_Wattributes,
    4869              :                    "standard %qE attribute can only be applied to function "
    4870              :                    "declarators or type specifiers with function type", name))
    4871            8 :         inform (input_location, "did you mean to specify it after %<)%> "
    4872              :                                 "following function parameters?");
    4873            8 :       *no_add_attrs = true;
    4874            8 :       return NULL_TREE;
    4875            8 :     }
    4876           60 :   return handle_unsequenced_attribute (node, name, args, flags, no_add_attrs);
    4877              : }
    4878              : 
    4879              : /* Handle the standard [[reproducible]] attribute.  */
    4880              : 
    4881              : static tree
    4882           34 : handle_std_reproducible_attribute (tree *node, tree name, tree args,
    4883              :                                    int flags, bool *no_add_attrs)
    4884              : {
    4885           34 :   return handle_std_unsequenced_attribute (node, name, args, flags,
    4886           34 :                                            no_add_attrs);
    4887              : }
    4888              : 
    4889              : /* Table of supported standard (C23) attributes.  */
    4890              : static const attribute_spec std_attributes[] =
    4891              : {
    4892              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    4893              :        affects_type_identity, handler, exclude } */
    4894              :   { "_Noreturn", 0, 0, false, false, false, false,
    4895              :     handle_std_noreturn_attribute, NULL },
    4896              :   { "deprecated", 0, 1, false, false, false, false,
    4897              :     handle_deprecated_attribute, NULL },
    4898              :   { "fallthrough", 0, 0, false, false, false, false,
    4899              :     handle_fallthrough_attribute, NULL },
    4900              :   { "maybe_unused", 0, 0, false, false, false, false,
    4901              :     handle_unused_attribute, NULL },
    4902              :   { "nodiscard", 0, 1, false, false, false, false,
    4903              :     handle_nodiscard_attribute, NULL },
    4904              :   { "noreturn", 0, 0, false, false, false, false,
    4905              :     handle_std_noreturn_attribute, NULL },
    4906              :   { "reproducible", 0, 0, false, true, true, false,
    4907              :     handle_std_reproducible_attribute, NULL },
    4908              :   { "unsequenced", 0, 0, false, true, true, false,
    4909              :     handle_std_unsequenced_attribute, NULL }
    4910              : };
    4911              : 
    4912              : const scoped_attribute_specs std_attribute_table =
    4913              : {
    4914              :   nullptr, { std_attributes }
    4915              : };
    4916              : 
    4917              : /* Create the predefined scalar types of C,
    4918              :    and some nodes representing standard constants (0, 1, (void *) 0).
    4919              :    Initialize the global scope.
    4920              :    Make definitions for built-in primitive functions.  */
    4921              : 
    4922              : void
    4923       111527 : c_init_decl_processing (void)
    4924              : {
    4925       111527 :   location_t save_loc = input_location;
    4926              : 
    4927              :   /* Initialize reserved words for parser.  */
    4928       111527 :   c_parse_init ();
    4929              : 
    4930       111527 :   current_function_decl = NULL_TREE;
    4931              : 
    4932       111527 :   gcc_obstack_init (&parser_obstack);
    4933              : 
    4934              :   /* Make the externals scope.  */
    4935       111527 :   push_scope ();
    4936       111527 :   external_scope = current_scope;
    4937              : 
    4938              :   /* Declarations from c_common_nodes_and_builtins must not be associated
    4939              :      with this input file, lest we get differences between using and not
    4940              :      using preprocessed headers.  */
    4941       111527 :   input_location = BUILTINS_LOCATION;
    4942              : 
    4943       111527 :   c_common_nodes_and_builtins ();
    4944              : 
    4945              :   /* In C, comparisons and TRUTH_* expressions have type int.  */
    4946       111527 :   truthvalue_type_node = integer_type_node;
    4947       111527 :   truthvalue_true_node = integer_one_node;
    4948       111527 :   truthvalue_false_node = integer_zero_node;
    4949              : 
    4950              :   /* Even in C99, which has a real boolean type.  */
    4951       111527 :   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
    4952              :                         boolean_type_node));
    4953              : 
    4954              :   /* C-specific nullptr initialization.  */
    4955       111527 :   record_builtin_type (RID_MAX, "typeof (nullptr)", nullptr_type_node);
    4956              :   /* The size and alignment of nullptr_t is the same as for a pointer to
    4957              :      character type.  */
    4958       111527 :   SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4959              : 
    4960       111527 :   input_location = save_loc;
    4961              : 
    4962       111527 :   make_fname_decl = c_make_fname_decl;
    4963       111527 :   start_fname_decls ();
    4964              : 
    4965       111527 :   if (warn_keyword_macro)
    4966              :     {
    4967         1165 :       for (unsigned int i = 0; i < num_c_common_reswords; ++i)
    4968              :         /* For C register keywords which don't start with underscore
    4969              :            or start with just single underscore.  Don't complain about
    4970              :            ObjC or Transactional Memory keywords.  */
    4971         1160 :         if (c_common_reswords[i].word[0] == '_'
    4972          530 :             && c_common_reswords[i].word[1] == '_')
    4973          390 :           continue;
    4974          995 :         else if (c_common_reswords[i].disable
    4975          770 :                  & (D_TRANSMEM | D_OBJC | D_CXX_OBJC))
    4976          225 :           continue;
    4977              :         else
    4978              :           {
    4979          545 :             tree id = get_identifier (c_common_reswords[i].word);
    4980          545 :             if (C_IS_RESERVED_WORD (id)
    4981          545 :                 && C_RID_CODE (id) != RID_CXX_COMPAT_WARN)
    4982          332 :               cpp_warn (parse_in, IDENTIFIER_POINTER (id),
    4983          332 :                         IDENTIFIER_LENGTH (id));
    4984              :           }
    4985              :     }
    4986       111527 : }
    4987              : 
    4988              : /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
    4989              :    give the decl, NAME is the initialization string and TYPE_DEP
    4990              :    indicates whether NAME depended on the type of the function.  As we
    4991              :    don't yet implement delayed emission of static data, we mark the
    4992              :    decl as emitted so it is not placed in the output.  Anything using
    4993              :    it must therefore pull out the STRING_CST initializer directly.
    4994              :    FIXME.  */
    4995              : 
    4996              : static tree
    4997         2936 : c_make_fname_decl (location_t loc, tree id, int type_dep)
    4998              : {
    4999         2936 :   const char *name = fname_as_string (type_dep);
    5000         2936 :   tree decl, type, init;
    5001         2936 :   size_t length = strlen (name);
    5002              : 
    5003         2936 :   type = c_build_array_type (char_type_node,
    5004         2936 :                              build_index_type (size_int (length)));
    5005         2936 :   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
    5006              : 
    5007         2936 :   decl = build_decl (loc, VAR_DECL, id, type);
    5008              : 
    5009         2936 :   TREE_STATIC (decl) = 1;
    5010         2936 :   TREE_READONLY (decl) = 1;
    5011         2936 :   DECL_ARTIFICIAL (decl) = 1;
    5012              : 
    5013         2936 :   init = build_string (length + 1, name);
    5014         2936 :   free (const_cast<char *> (name));
    5015         2936 :   TREE_TYPE (init) = type;
    5016         2936 :   DECL_INITIAL (decl) = init;
    5017              : 
    5018         2936 :   TREE_USED (decl) = 1;
    5019              : 
    5020         2936 :   if (current_function_decl
    5021              :       /* For invalid programs like this:
    5022              : 
    5023              :          void foo()
    5024              :          const char* p = __FUNCTION__;
    5025              : 
    5026              :          the __FUNCTION__ is believed to appear in K&R style function
    5027              :          parameter declarator.  In that case we still don't have
    5028              :          function_scope.  */
    5029         2929 :       && current_function_scope)
    5030              :     {
    5031         2921 :       DECL_CONTEXT (decl) = current_function_decl;
    5032         2921 :       bind (id, decl, current_function_scope,
    5033              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
    5034              :     }
    5035              : 
    5036         2936 :   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
    5037              : 
    5038         2936 :   return decl;
    5039              : }
    5040              : 
    5041              : tree
    5042    326270068 : c_builtin_function (tree decl)
    5043              : {
    5044    326270068 :   tree type = TREE_TYPE (decl);
    5045    326270068 :   tree   id = DECL_NAME (decl);
    5046              : 
    5047    326270068 :   const char *name = IDENTIFIER_POINTER (id);
    5048    326270068 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5049              : 
    5050              :   /* Should never be called on a symbol with a preexisting meaning.  */
    5051    326270068 :   gcc_assert (!I_SYMBOL_BINDING (id));
    5052              : 
    5053    326270068 :   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
    5054              :         UNKNOWN_LOCATION);
    5055              : 
    5056              :   /* Builtins in the implementation namespace are made visible without
    5057              :      needing to be explicitly declared.  See push_file_scope.  */
    5058    326270068 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5059              :     {
    5060    222825157 :       DECL_CHAIN (decl) = visible_builtins;
    5061    222825157 :       visible_builtins = decl;
    5062              :     }
    5063              : 
    5064    326270068 :   return decl;
    5065              : }
    5066              : 
    5067              : tree
    5068     10503579 : c_builtin_function_ext_scope (tree decl)
    5069              : {
    5070     10503579 :   tree type = TREE_TYPE (decl);
    5071     10503579 :   tree   id = DECL_NAME (decl);
    5072              : 
    5073     10503579 :   const char *name = IDENTIFIER_POINTER (id);
    5074     10503579 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5075              : 
    5076     10503579 :   if (external_scope)
    5077     10316568 :     bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
    5078              :           UNKNOWN_LOCATION);
    5079              : 
    5080              :   /* Builtins in the implementation namespace are made visible without
    5081              :      needing to be explicitly declared.  See push_file_scope.  */
    5082     10503579 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5083              :     {
    5084     10503579 :       DECL_CHAIN (decl) = visible_builtins;
    5085     10503579 :       visible_builtins = decl;
    5086              :     }
    5087              : 
    5088     10503579 :   return decl;
    5089              : }
    5090              : 
    5091              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5092              : 
    5093              : tree
    5094            0 : c_simulate_builtin_function_decl (tree decl)
    5095              : {
    5096            0 :   tree type = TREE_TYPE (decl);
    5097            0 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5098            0 :   return pushdecl (decl);
    5099              : }
    5100              : 
    5101              : /* Warn about attributes in a context where they are unused
    5102              :    (attribute-declarations, except for the "fallthrough" case, and
    5103              :    attributes on statements).  */
    5104              : 
    5105              : void
    5106     41614519 : c_warn_unused_attributes (tree attrs)
    5107              : {
    5108     41614564 :   for (tree t = attrs; t != NULL_TREE; t = TREE_CHAIN (t))
    5109           45 :     if (get_attribute_namespace (t) == NULL_TREE)
    5110              :       /* The specifications of standard attributes mean this is a
    5111              :          constraint violation.  */
    5112           29 :       pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5113              :                get_attribute_name (t));
    5114           16 :     else if (!attribute_ignored_p (t))
    5115           12 :       warning (OPT_Wattributes, "%qE attribute ignored",
    5116              :                get_attribute_name (t));
    5117     41614519 : }
    5118              : 
    5119              : /* Warn for standard attributes being applied to a type that is not
    5120              :    being defined, where that is a constraint violation, and return a
    5121              :    list of attributes with them removed.  */
    5122              : 
    5123              : tree
    5124    436822493 : c_warn_type_attributes (tree type, tree attrs)
    5125              : {
    5126    436822493 :   tree *attr_ptr = &attrs;
    5127    436845756 :   while (*attr_ptr)
    5128        23263 :     if (get_attribute_namespace (*attr_ptr) == NULL_TREE)
    5129              :       {
    5130           89 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    5131              :           {
    5132           65 :             tree name = get_attribute_name (*attr_ptr);
    5133              :             /* [[unsequenced]] and [[reproducible]] is fine on function
    5134              :                types that aren't being defined.  */
    5135           65 :             if (is_attribute_p ("unsequenced", name)
    5136           65 :                 || is_attribute_p ("reproducible", name))
    5137              :               {
    5138           60 :                 attr_ptr = &TREE_CHAIN (*attr_ptr);
    5139           60 :                 continue;
    5140              :               }
    5141              :           }
    5142           29 :         pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5143              :                  get_attribute_name (*attr_ptr));
    5144           29 :         *attr_ptr = TREE_CHAIN (*attr_ptr);
    5145              :       }
    5146              :     else
    5147        23174 :       attr_ptr = &TREE_CHAIN (*attr_ptr);
    5148    436822493 :   return attrs;
    5149              : }
    5150              : 
    5151              : /* Called when a declaration is seen that contains no names to declare.
    5152              :    If its type is a reference to a structure, union or enum inherited
    5153              :    from a containing scope, shadow that tag name for the current scope
    5154              :    with a forward reference.
    5155              :    If its type defines a new named structure or union
    5156              :    or defines an enum, it is valid but we need not do anything here.
    5157              :    Otherwise, it is an error.  */
    5158              : 
    5159              : void
    5160       505531 : shadow_tag (const struct c_declspecs *declspecs)
    5161              : {
    5162       505531 :   shadow_tag_warned (declspecs, 0);
    5163       505531 : }
    5164              : 
    5165              : /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
    5166              :    but no pedwarn.  */
    5167              : void
    5168       505601 : shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
    5169              : {
    5170       505601 :   bool found_tag = false;
    5171              : 
    5172       505601 :   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
    5173              :     {
    5174       505487 :       tree value = declspecs->type;
    5175       505487 :       enum tree_code code = TREE_CODE (value);
    5176              : 
    5177       505487 :       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
    5178              :         /* Used to test also that TYPE_SIZE (value) != 0.
    5179              :            That caused warning for `struct foo;' at top level in the file.  */
    5180              :         {
    5181       505436 :           tree name = TYPE_NAME (value);
    5182       505436 :           tree t;
    5183              : 
    5184       505436 :           found_tag = true;
    5185              : 
    5186       505436 :           if (declspecs->restrict_p)
    5187              :             {
    5188            2 :               error ("invalid use of %<restrict%>");
    5189            2 :               warned = 1;
    5190              :             }
    5191              : 
    5192       505436 :           if (in_underspecified_init)
    5193              :             {
    5194              :               /* This can only occur with extensions such as statement
    5195              :                  expressions, but is still appropriate as an error to
    5196              :                  avoid types declared in such a context escaping to
    5197              :                  the type of an auto variable.  */
    5198            1 :               error ("%qT declared in underspecified object initializer",
    5199              :                      value);
    5200            1 :               warned = 1;
    5201              :             }
    5202              : 
    5203       505436 :           if (name == NULL_TREE)
    5204              :             {
    5205        61183 :               if (warned != 1 && code != ENUMERAL_TYPE)
    5206              :                 /* Empty unnamed enum OK */
    5207              :                 {
    5208           19 :                   pedwarn (input_location, 0,
    5209              :                            "unnamed struct/union that defines no instances");
    5210           19 :                   warned = 1;
    5211              :                 }
    5212              :             }
    5213       444253 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5214        88602 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5215        26370 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5216        26362 :                    && declspecs->storage_class != csc_none)
    5217              :             {
    5218            2 :               if (warned != 1)
    5219            2 :                 pedwarn (input_location, 0,
    5220              :                          "empty declaration with storage class specifier "
    5221              :                          "does not redeclare tag");
    5222            2 :               warned = 1;
    5223            2 :               pending_xref_error ();
    5224              :             }
    5225       444251 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5226        88600 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5227        26368 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5228        26360 :                    && (declspecs->const_p
    5229        26357 :                        || declspecs->volatile_p
    5230        26357 :                        || declspecs->atomic_p
    5231        26357 :                        || declspecs->restrict_p
    5232        26357 :                        || declspecs->address_space))
    5233              :             {
    5234            3 :               if (warned != 1)
    5235            3 :                 pedwarn (input_location, 0,
    5236              :                          "empty declaration with type qualifier "
    5237              :                           "does not redeclare tag");
    5238            3 :               warned = 1;
    5239            3 :               pending_xref_error ();
    5240              :             }
    5241       444248 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5242        88597 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5243        26365 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5244        26357 :                    && declspecs->alignas_p)
    5245              :             {
    5246            1 :               if (warned != 1)
    5247            1 :                 pedwarn (input_location, 0,
    5248              :                          "empty declaration with %<_Alignas%> "
    5249              :                           "does not redeclare tag");
    5250            1 :               warned = 1;
    5251            1 :               pending_xref_error ();
    5252              :             }
    5253       444247 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5254        88596 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5255        26364 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5256        26356 :                    && code == ENUMERAL_TYPE
    5257           15 :                    && !declspecs->enum_type_specifier_ref_p)
    5258              :             {
    5259            3 :               bool warned_enum = false;
    5260            3 :               if (warned != 1)
    5261            3 :                 warned_enum = pedwarn (input_location, OPT_Wpedantic,
    5262              :                                        "empty declaration of %<enum%> type "
    5263              :                                        "does not redeclare tag");
    5264            3 :               if (warned_enum)
    5265            2 :                 warned = 1;
    5266            3 :               pending_xref_error ();
    5267            3 :             }
    5268              :           else
    5269              :             {
    5270       444244 :               pending_invalid_xref = NULL_TREE;
    5271       444244 :               t = lookup_tag (code, name, true, NULL);
    5272              : 
    5273       444244 :               if (t == NULL_TREE)
    5274              :                 {
    5275            2 :                   t = make_node (code);
    5276            2 :                   if (flag_isoc23 || code == ENUMERAL_TYPE)
    5277            1 :                     SET_TYPE_STRUCTURAL_EQUALITY (t);
    5278            2 :                   pushtag (input_location, name, t);
    5279              :                 }
    5280              :             }
    5281              :         }
    5282              :       else
    5283              :         {
    5284           51 :           if (warned != 1 && !in_system_header_at (input_location))
    5285              :             {
    5286           44 :               pedwarn (input_location, 0,
    5287              :                        "useless type name in empty declaration");
    5288           44 :               warned = 1;
    5289              :             }
    5290              :         }
    5291              :     }
    5292           71 :   else if (warned != 1 && !in_system_header_at (input_location)
    5293          185 :            && declspecs->typedef_p)
    5294              :     {
    5295           11 :       pedwarn (input_location, 0, "useless type name in empty declaration");
    5296           11 :       warned = 1;
    5297              :     }
    5298              : 
    5299       505601 :   pending_invalid_xref = NULL_TREE;
    5300              : 
    5301       505601 :   if (declspecs->inline_p)
    5302              :     {
    5303            5 :       error ("%<inline%> in empty declaration");
    5304            5 :       warned = 1;
    5305              :     }
    5306              : 
    5307       505601 :   if (declspecs->noreturn_p)
    5308              :     {
    5309            2 :       error ("%<_Noreturn%> in empty declaration");
    5310            2 :       warned = 1;
    5311              :     }
    5312              : 
    5313       505601 :   if (declspecs->constexpr_p)
    5314              :     {
    5315            7 :       error ("%<constexpr%> in empty declaration");
    5316            7 :       warned = 1;
    5317              :     }
    5318              : 
    5319       505601 :   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
    5320              :     {
    5321            2 :       error ("%<auto%> in file-scope empty declaration");
    5322            2 :       warned = 1;
    5323              :     }
    5324              : 
    5325       505601 :   if (current_scope == file_scope && declspecs->storage_class == csc_register)
    5326              :     {
    5327            2 :       error ("%<register%> in file-scope empty declaration");
    5328            2 :       warned = 1;
    5329              :     }
    5330              : 
    5331       505601 :   if (declspecs->enum_type_specifier_ref_p && !warned)
    5332              :     {
    5333           39 :       if (declspecs->storage_class != csc_none)
    5334              :         {
    5335            1 :           error ("storage class specifier in empty declaration with %<enum%> "
    5336              :                  "underlying type");
    5337            1 :           warned = 1;
    5338              :         }
    5339           38 :       else if (declspecs->thread_p)
    5340              :         {
    5341            2 :           error ("%qs in empty declaration with %<enum%> underlying type",
    5342            1 :                  declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5343            1 :           warned = 1;
    5344              :         }
    5345           37 :       else if (declspecs->const_p
    5346           36 :                || declspecs->volatile_p
    5347           36 :                || declspecs->atomic_p
    5348           36 :                || declspecs->restrict_p
    5349           36 :                || declspecs->address_space)
    5350              :         {
    5351            1 :           error ("type qualifier in empty declaration with %<enum%> "
    5352              :                  "underlying type");
    5353            1 :           warned = 1;
    5354              :         }
    5355           36 :       else if (declspecs->alignas_p)
    5356              :         {
    5357            1 :           error ("%<alignas%> in empty declaration with %<enum%> "
    5358              :                  "underlying type");
    5359            1 :           warned = 1;
    5360              :         }
    5361              :     }
    5362              : 
    5363       505433 :   if (!warned && !in_system_header_at (input_location)
    5364       624108 :       && declspecs->storage_class != csc_none)
    5365              :     {
    5366           12 :       warning (0, "useless storage class specifier in empty declaration");
    5367           12 :       warned = 2;
    5368              :     }
    5369              : 
    5370       505601 :   if (!warned && !in_system_header_at (input_location) && declspecs->thread_p)
    5371              :     {
    5372            3 :       warning (0, "useless %qs in empty declaration",
    5373            3 :                declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5374            3 :       warned = 2;
    5375              :     }
    5376              : 
    5377            3 :   if (!warned
    5378       505414 :       && !in_system_header_at (input_location)
    5379       624098 :       && (declspecs->const_p
    5380       118492 :           || declspecs->volatile_p
    5381       118492 :           || declspecs->atomic_p
    5382       118492 :           || declspecs->restrict_p
    5383       118492 :           || declspecs->address_space))
    5384              :     {
    5385            8 :       warning (0, "useless type qualifier in empty declaration");
    5386            8 :       warned = 2;
    5387              :     }
    5388              : 
    5389       505414 :   if (!warned && !in_system_header_at (input_location)
    5390       624085 :       && declspecs->alignas_p)
    5391              :     {
    5392            4 :       warning (0, "useless %<_Alignas%> in empty declaration");
    5393            4 :       warned = 2;
    5394              :     }
    5395              : 
    5396       505601 :   if (found_tag
    5397       505601 :       && warned == 2
    5398           23 :       && (declspecs->typespec_kind == ctsk_tagref_attrs
    5399           23 :           || declspecs->typespec_kind == ctsk_tagfirstref_attrs))
    5400              :     {
    5401              :       /* Standard attributes after the "struct" or "union" keyword are
    5402              :          only permitted when the contents of the type are defined, or
    5403              :          in the form "struct-or-union attribute-specifier-sequence
    5404              :          identifier;".  If the ';' was not present, attributes were
    5405              :          diagnosed in the parser.  Here, ensure that any other useless
    5406              :          elements of the declaration result in a pedwarn, not just a
    5407              :          warning.  Forward declarations of enum types are not part of
    5408              :          standard C, but handle them the same.  */
    5409            2 :       pedwarn (input_location, 0,
    5410              :                "invalid use of attributes in empty declaration");
    5411            2 :       warned = 1;
    5412              :     }
    5413              : 
    5414       505601 :   if (warned != 1)
    5415              :     {
    5416       505427 :       if (declspecs->declspecs_seen_p
    5417       505427 :           && !declspecs->non_std_attrs_seen_p)
    5418              :         /* An attribute declaration (but not a fallthrough attribute
    5419              :            declaration, which was handled separately); warn if there
    5420              :            are any attributes being ignored (but not if the attributes
    5421              :            were empty).  */
    5422           48 :         c_warn_unused_attributes (declspecs->attrs);
    5423       505379 :       else if (!found_tag)
    5424           10 :         pedwarn (input_location, 0, "empty declaration");
    5425              :     }
    5426       505601 : }
    5427              : 
    5428              : 
    5429              : /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
    5430              :    bits.  SPECS represents declaration specifiers that the grammar
    5431              :    only permits to contain type qualifiers and attributes.  */
    5432              : 
    5433              : int
    5434     18335617 : quals_from_declspecs (const struct c_declspecs *specs)
    5435              : {
    5436     18335617 :   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
    5437              :                | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
    5438              :                | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
    5439     18335617 :                | (specs->atomic_p ? TYPE_QUAL_ATOMIC : 0)
    5440     18335617 :                | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
    5441     18335617 :   gcc_assert (!specs->type
    5442              :               && !specs->decl_attr
    5443              :               && specs->typespec_word == cts_none
    5444              :               && specs->storage_class == csc_none
    5445              :               && !specs->typedef_p
    5446              :               && !specs->explicit_signed_p
    5447              :               && !specs->deprecated_p
    5448              :               && !specs->unavailable_p
    5449              :               && !specs->long_p
    5450              :               && !specs->long_long_p
    5451              :               && !specs->short_p
    5452              :               && !specs->signed_p
    5453              :               && !specs->unsigned_p
    5454              :               && !specs->complex_p
    5455              :               && !specs->inline_p
    5456              :               && !specs->noreturn_p
    5457              :               && !specs->thread_p);
    5458     18335617 :   return quals;
    5459              : }
    5460              : 
    5461              : /* Construct an array declarator.  LOC is the location of the
    5462              :    beginning of the array (usually the opening brace).  EXPR is the
    5463              :    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
    5464              :    inside the [] (to be applied to the pointer to which a parameter
    5465              :    array is converted).  STATIC_P is true if "static" is inside the
    5466              :    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
    5467              :    VLA of unspecified length which is nevertheless a complete type,
    5468              :    false otherwise.  The field for the contained declarator is left to
    5469              :    be filled in by set_array_declarator_inner.  */
    5470              : 
    5471              : struct c_declarator *
    5472      1139444 : build_array_declarator (location_t loc,
    5473              :                         tree expr, struct c_declspecs *quals, bool static_p,
    5474              :                         bool vla_unspec_p)
    5475              : {
    5476      1139444 :   struct c_declarator *declarator = XOBNEW (&parser_obstack,
    5477              :                                             struct c_declarator);
    5478      1139444 :   declarator->id_loc = loc;
    5479      1139444 :   declarator->kind = cdk_array;
    5480      1139444 :   declarator->declarator = 0;
    5481      1139444 :   declarator->u.array.dimen = expr;
    5482      1139444 :   if (quals)
    5483              :     {
    5484          966 :       declarator->u.array.attrs = quals->attrs;
    5485          966 :       declarator->u.array.quals = quals_from_declspecs (quals);
    5486              :     }
    5487              :   else
    5488              :     {
    5489      1138478 :       declarator->u.array.attrs = NULL_TREE;
    5490      1138478 :       declarator->u.array.quals = 0;
    5491              :     }
    5492      1139444 :   declarator->u.array.static_p = static_p;
    5493      1139444 :   declarator->u.array.vla_unspec_p = vla_unspec_p;
    5494      1139444 :   if (static_p || quals != NULL)
    5495         1069 :     pedwarn_c90 (loc, OPT_Wpedantic,
    5496              :                  "ISO C90 does not support %<static%> or type "
    5497              :                  "qualifiers in parameter array declarators");
    5498      1139444 :   if (vla_unspec_p)
    5499              :     {
    5500          151 :       pedwarn_c90 (loc, OPT_Wpedantic,
    5501              :                    "ISO C90 does not support %<[*]%> array declarators");
    5502          151 :       if (current_scope->parm_flag)
    5503          143 :         current_scope->had_vla_unspec = true;
    5504              :     }
    5505      1139444 :   return declarator;
    5506              : }
    5507              : 
    5508              : /* Set the contained declarator of an array declarator.  DECL is the
    5509              :    declarator, as constructed by build_array_declarator; INNER is what
    5510              :    appears on the left of the [].  */
    5511              : 
    5512              : struct c_declarator *
    5513      1139444 : set_array_declarator_inner (struct c_declarator *decl,
    5514              :                             struct c_declarator *inner)
    5515              : {
    5516      1139444 :   decl->declarator = inner;
    5517      1139444 :   return decl;
    5518              : }
    5519              : 
    5520              : /* Determine whether TYPE is a one-element array type "[1]".  */
    5521              : static bool
    5522       534424 : one_element_array_type_p (const_tree type)
    5523              : {
    5524       534424 :   if (TREE_CODE (type) != ARRAY_TYPE)
    5525              :     return false;
    5526       534424 :   return integer_zerop (array_type_nelts_minus_one (type));
    5527              : }
    5528              : 
    5529              : /* Determine whether TYPE is a zero-length array type "[0]".  */
    5530              : static bool
    5531       534424 : zero_length_array_type_p (const_tree type)
    5532              : {
    5533       534424 :   if (TREE_CODE (type) == ARRAY_TYPE)
    5534       534424 :     if (tree type_size = TYPE_SIZE_UNIT (type))
    5535       448435 :       if ((integer_zerop (type_size))
    5536         1824 :            && TYPE_DOMAIN (type) != NULL_TREE
    5537       450259 :            && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
    5538              :         return true;
    5539              :   return false;
    5540              : }
    5541              : 
    5542              : /* INIT is a constructor that forms DECL's initializer.  If the final
    5543              :    element initializes a flexible array field, adjust the size of the
    5544              :    DECL with the initializer based on whether the DECL is a union or
    5545              :    a structure.  */
    5546              : 
    5547              : static void
    5548       105789 : add_flexible_array_elts_to_size (tree decl, tree init)
    5549              : {
    5550       105789 :   tree elt, type;
    5551              : 
    5552       105789 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    5553         1598 :     return;
    5554              : 
    5555       104191 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    5556       104191 :   type = TREE_TYPE (elt);
    5557       104191 :   if (c_flexible_array_member_type_p (type))
    5558              :     {
    5559          221 :       complete_array_type (&type, elt, false);
    5560              :       /* For a structure, add the size of the initializer to the DECL's
    5561              :          size.  */
    5562          221 :       if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    5563              :         {
    5564          211 :           DECL_SIZE (decl)
    5565          211 :             = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5566          211 :           DECL_SIZE_UNIT (decl)
    5567          422 :             = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    5568              :                           TYPE_SIZE_UNIT (type));
    5569              :         }
    5570              :       /* For a union, the DECL's size is the maximum of the current size
    5571              :          and the size of the initializer.  */
    5572              :       else
    5573              :         {
    5574           10 :           DECL_SIZE (decl)
    5575           10 :             = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5576           10 :           DECL_SIZE_UNIT (decl)
    5577           20 :             = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    5578              :                           TYPE_SIZE_UNIT (type));
    5579              :         }
    5580              :     }
    5581              : }
    5582              : 
    5583              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.
    5584              :    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
    5585              :    before the type name, and set *EXPR_CONST_OPERANDS, if
    5586              :    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
    5587              :    appear in a constant expression.  */
    5588              : 
    5589              : tree
    5590    121576811 : groktypename (struct c_type_name *type_name, tree *expr,
    5591              :               bool *expr_const_operands)
    5592              : {
    5593    121576811 :   tree type;
    5594    121576811 :   tree attrs = type_name->specs->attrs;
    5595              : 
    5596    121576811 :   type_name->specs->attrs = NULL_TREE;
    5597              : 
    5598    121576811 :   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
    5599              :                          false, NULL, &attrs, expr, expr_const_operands,
    5600              :                          DEPRECATED_NORMAL);
    5601              : 
    5602              :   /* Apply attributes.  */
    5603    121576811 :   attrs = c_warn_type_attributes (type, attrs);
    5604    121576811 :   decl_attributes (&type, attrs, 0);
    5605              : 
    5606    121576811 :   return type;
    5607              : }
    5608              : 
    5609              : 
    5610              : /* Decode a "typename", such as "int **", returning a ..._TYPE node,
    5611              :    as for groktypename but setting the context to GENERIC_ASSOC.  */
    5612              : 
    5613              : tree
    5614         1438 : grokgenassoc (struct c_type_name *type_name)
    5615              : {
    5616         1438 :   tree type;
    5617         1438 :   tree attrs = type_name->specs->attrs;
    5618              : 
    5619         1438 :   type_name->specs->attrs = NULL_TREE;
    5620              : 
    5621         1438 :   type = grokdeclarator (type_name->declarator, type_name->specs, GENERIC_ASSOC,
    5622              :                          false, NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
    5623              : 
    5624              :   /* Apply attributes.  */
    5625         1438 :   attrs = c_warn_type_attributes (type, attrs);
    5626         1438 :   decl_attributes (&type, attrs, 0);
    5627              : 
    5628         1438 :   return type;
    5629              : }
    5630              : 
    5631              : 
    5632              : /* Looks up the most recent pushed declaration corresponding to DECL.  */
    5633              : 
    5634              : static tree
    5635     92983411 : lookup_last_decl (tree decl)
    5636              : {
    5637     92983411 :   tree last_decl = lookup_name (DECL_NAME (decl));
    5638     92983411 :   if (!last_decl)
    5639     90396637 :     last_decl = lookup_name_in_scope (DECL_NAME (decl), external_scope);
    5640     92983411 :   return last_decl;
    5641              : }
    5642              : 
    5643              : /* Wrapper for decl_attributes that adds some implicit attributes
    5644              :    to VAR_DECLs or FUNCTION_DECLs.  */
    5645              : 
    5646              : static tree
    5647     64654920 : c_decl_attributes (tree *node, tree attributes, int flags)
    5648              : {
    5649              :   /* Add implicit "omp declare target" attribute if requested.  */
    5650     64654920 :   if (vec_safe_length (current_omp_declare_target_attribute)
    5651         9167 :       && ((VAR_P (*node) && is_global_var (*node))
    5652         2729 :           || TREE_CODE (*node) == FUNCTION_DECL))
    5653              :     {
    5654         1131 :       if (VAR_P (*node) && !omp_mappable_type (TREE_TYPE (*node)))
    5655           13 :         attributes = tree_cons (get_identifier ("omp declare target implicit"),
    5656              :                                 NULL_TREE, attributes);
    5657              :       else
    5658         1118 :         attributes = tree_cons (get_identifier ("omp declare target"),
    5659              :                                 NULL_TREE, attributes);
    5660         1131 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5661              :         {
    5662         1001 :           int device_type
    5663         1001 :             = current_omp_declare_target_attribute->last ().device_type;
    5664         1001 :           device_type = MAX (device_type, 0);
    5665         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    5666         1001 :               && !lookup_attribute ("omp declare target host", attributes))
    5667            2 :             attributes
    5668            2 :               = tree_cons (get_identifier ("omp declare target host"),
    5669              :                            NULL_TREE, attributes);
    5670         1001 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    5671         1001 :               && !lookup_attribute ("omp declare target nohost", attributes))
    5672            2 :             attributes
    5673            2 :               = tree_cons (get_identifier ("omp declare target nohost"),
    5674              :                            NULL_TREE, attributes);
    5675              : 
    5676         1001 :           int indirect
    5677         1001 :             = current_omp_declare_target_attribute->last ().indirect;
    5678         1001 :           if (indirect && !lookup_attribute ("omp declare target indirect",
    5679              :                                              attributes))
    5680           10 :             attributes
    5681           10 :               = tree_cons (get_identifier ("omp declare target indirect"),
    5682              :                            NULL_TREE, attributes);
    5683              :         }
    5684              :     }
    5685              : 
    5686     64654920 :   if (flag_openmp || flag_openmp_simd)
    5687              :     {
    5688              :       bool diagnosed = false;
    5689      1372485 :       for (tree *pa = &attributes; *pa; )
    5690              :         {
    5691       883719 :           if (is_attribute_namespace_p ("omp", *pa))
    5692              :             {
    5693           65 :               tree name = get_attribute_name (*pa);
    5694           65 :               if (is_attribute_p ("directive", name)
    5695            0 :                   || is_attribute_p ("sequence", name)
    5696           65 :                   || is_attribute_p ("decl", name))
    5697              :                 {
    5698           65 :                   const char *p = NULL;
    5699           65 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    5700           12 :                     p = IDENTIFIER_POINTER (name);
    5701          118 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    5702              :                     {
    5703           53 :                       tree d = TREE_VALUE (a);
    5704           53 :                       gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
    5705           96 :                       if (TREE_PUBLIC (d)
    5706           43 :                           && (VAR_P (*node)
    5707            2 :                               || TREE_CODE (*node) == FUNCTION_DECL)
    5708           96 :                           && c_maybe_parse_omp_decl (*node, d))
    5709           43 :                         continue;
    5710           10 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    5711              :                     }
    5712           65 :                   if (p && !diagnosed)
    5713              :                     {
    5714           22 :                       error ("%<omp::%s%> not allowed to be specified in "
    5715              :                              "this context", p);
    5716           22 :                       diagnosed = true;
    5717              :                     }
    5718           65 :                   if (p)
    5719              :                     {
    5720           22 :                       *pa = TREE_CHAIN (*pa);
    5721           22 :                       continue;
    5722              :                     }
    5723              :                 }
    5724              :             }
    5725       883697 :           pa = &TREE_CHAIN (*pa);
    5726              :         }
    5727              :     }
    5728              : 
    5729              :   /* Look up the current declaration with all the attributes merged
    5730              :      so far so that attributes on the current declaration that's
    5731              :      about to be pushed that conflict with the former can be detected,
    5732              :      diagnosed, and rejected as appropriate.  To match the C++ FE, do
    5733              :      not pass an error_mark_node when we found an undeclared variable.  */
    5734     64654920 :   tree last_decl = lookup_last_decl (*node);
    5735     64654920 :   if (last_decl == error_mark_node)
    5736           20 :     last_decl = NULL_TREE;
    5737     64654920 :   tree attr = decl_attributes (node, attributes, flags, last_decl);
    5738     64654919 :   if (VAR_P (*node) && DECL_THREAD_LOCAL_P (*node))
    5739              :     {
    5740              :       // tls_model attribute can set a stronger TLS access model.
    5741         2833 :       tls_model model = DECL_TLS_MODEL (*node);
    5742         2833 :       tls_model default_model = decl_default_tls_model (*node);
    5743         2833 :       if (default_model > model)
    5744         1578 :         set_decl_tls_model (*node, default_model);
    5745              :     }
    5746     64654919 :   return attr;
    5747              : }
    5748              : 
    5749              : 
    5750              : /* Decode a declarator in an ordinary declaration or data definition.
    5751              :    This is called as soon as the type information and variable name
    5752              :    have been parsed, before parsing the initializer if any.
    5753              :    Here we create the ..._DECL node, fill in its type,
    5754              :    and (if DO_PUSH) put it on the list of decls for the current context.
    5755              :    When nonnull, set *LASTLOC to the location of the prior declaration
    5756              :    of the same entity if one exists.
    5757              :    The ..._DECL node is returned as the value.
    5758              : 
    5759              :    Exception: for arrays where the length is not specified,
    5760              :    the type is left null, to be filled in by `finish_decl'.
    5761              : 
    5762              :    Function definitions do not come here; they go to start_function
    5763              :    instead.  However, external and forward declarations of functions
    5764              :    do go through here.  Structure field declarations are done by
    5765              :    grokfield and not through here.  */
    5766              : 
    5767              : tree
    5768     28328515 : start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
    5769              :             bool initialized, tree attributes, bool do_push /* = true */,
    5770              :             location_t *lastloc /* = NULL */)
    5771              : {
    5772     28328515 :   tree decl;
    5773     28328515 :   tree old_decl;
    5774     28328515 :   tree tem;
    5775     28328515 :   tree expr = NULL_TREE;
    5776     28328515 :   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
    5777              : 
    5778              :   /* An object declared as __attribute__((unavailable)) suppresses
    5779              :      warnings and errors from __attribute__((deprecated/unavailable))
    5780              :      components.
    5781              :      An object declared as __attribute__((deprecated)) suppresses
    5782              :      warnings of uses of other deprecated items.  */
    5783     28328515 :   if (lookup_attribute ("unavailable", attributes))
    5784              :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
    5785     28328491 :   else if (lookup_attribute ("deprecated", attributes))
    5786        29862 :     deprecated_state = DEPRECATED_SUPPRESS;
    5787              : 
    5788     28328515 :   decl = grokdeclarator (declarator, declspecs,
    5789              :                          NORMAL, initialized, NULL, &attributes, &expr, NULL,
    5790              :                          deprecated_state);
    5791     28328515 :   if (!decl || decl == error_mark_node)
    5792              :     return NULL_TREE;
    5793              : 
    5794     28328491 :   old_decl = lookup_last_decl (decl);
    5795              : 
    5796     28328491 :   if (tree lastdecl = lastloc ? old_decl : NULL_TREE)
    5797      4878289 :     if (lastdecl != error_mark_node)
    5798      4878280 :       *lastloc = DECL_SOURCE_LOCATION (lastdecl);
    5799              : 
    5800              :   /* Make sure the size expression is evaluated at this point.  */
    5801     28328491 :   if (expr && !current_scope->parm_flag)
    5802        12974 :     add_stmt (fold_convert (void_type_node, expr));
    5803              : 
    5804     13265425 :   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))
    5805     28328493 :       && TREE_PUBLIC (decl))
    5806            1 :     warning (OPT_Wmain, "%q+D is usually a function", decl);
    5807              : 
    5808           14 :   if (warn_missing_variable_declarations && VAR_P (decl)
    5809     28328504 :       && !DECL_EXTERNAL (decl) && TREE_PUBLIC (decl) && old_decl == NULL_TREE)
    5810            5 :     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_variable_declarations,
    5811              :                 "no previous declaration for %qD", decl);
    5812              : 
    5813     28328491 :   if (initialized)
    5814              :     /* Is it valid for this decl to have an initializer at all?
    5815              :        If not, set INITIALIZED to zero, which will indirectly
    5816              :        tell 'finish_decl' to ignore the initializer once it is parsed.  */
    5817      6351185 :     switch (TREE_CODE (decl))
    5818              :       {
    5819            6 :       case TYPE_DECL:
    5820            6 :         error ("typedef %qD is initialized (use %<__typeof__%> instead)", decl);
    5821            6 :         initialized = false;
    5822            6 :         break;
    5823              : 
    5824            9 :       case FUNCTION_DECL:
    5825            9 :         error ("function %qD is initialized like a variable", decl);
    5826            9 :         initialized = false;
    5827            9 :         break;
    5828              : 
    5829           49 :       case PARM_DECL:
    5830              :         /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
    5831           49 :         error ("parameter %qD is initialized", decl);
    5832           49 :         initialized = false;
    5833           49 :         break;
    5834              : 
    5835      6351121 :       default:
    5836              :         /* Don't allow initializations for incomplete types except for
    5837              :            arrays which might be completed by the initialization.  */
    5838              : 
    5839              :         /* This can happen if the array size is an undefined macro.
    5840              :            We already gave a warning, so we don't need another one.  */
    5841      6351121 :         if (TREE_TYPE (decl) == error_mark_node)
    5842              :           initialized = false;
    5843      6351099 :         else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
    5844              :           {
    5845              :             /* A complete type is ok if size is fixed.  If the size is
    5846              :                variable, an empty initializer is OK and nonempty
    5847              :                initializers will be diagnosed in the parser.  */
    5848              :           }
    5849        12309 :         else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
    5850              :           {
    5851            3 :             error ("variable %qD has initializer but incomplete type", decl);
    5852            3 :             initialized = false;
    5853              :           }
    5854              :       }
    5855              : 
    5856           67 :   if (initialized)
    5857              :     {
    5858      6351096 :       if (current_scope == file_scope)
    5859       156367 :         TREE_STATIC (decl) = 1;
    5860              : 
    5861              :       /* Tell 'pushdecl' this is an initialized decl
    5862              :          even though we don't yet have the initializer expression.
    5863              :          Also tell 'finish_decl' it may store the real initializer.  */
    5864      6351096 :       DECL_INITIAL (decl) = error_mark_node;
    5865              :     }
    5866              : 
    5867              :   /* If this is a function declaration, write a record describing it to the
    5868              :      prototypes file (if requested).  */
    5869              : 
    5870     28328491 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5871     15063066 :     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
    5872              : 
    5873              :   /* ANSI specifies that a tentative definition which is not merged with
    5874              :      a non-tentative definition behaves exactly like a definition with an
    5875              :      initializer equal to zero.  (Section 3.7.2)
    5876              : 
    5877              :      -fno-common gives strict ANSI behavior, though this tends to break
    5878              :      a large body of code that grew up without this rule.
    5879              : 
    5880              :      Thread-local variables are never common, since there's no entrenched
    5881              :      body of code to break, and it allows more efficient variable references
    5882              :      in the presence of dynamic linking.  */
    5883              : 
    5884     28328491 :   if (VAR_P (decl)
    5885      8921114 :       && !initialized
    5886      2570018 :       && TREE_PUBLIC (decl)
    5887       986088 :       && !DECL_THREAD_LOCAL_P (decl)
    5888     29312213 :       && !flag_no_common)
    5889          128 :     DECL_COMMON (decl) = 1;
    5890              : 
    5891              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5892     28328491 :   c_decl_attributes (&decl, attributes, 0);
    5893              : 
    5894              :   /* Handle gnu_inline attribute.  */
    5895     28328490 :   if (declspecs->inline_p
    5896         1029 :       && !flag_gnu89_inline
    5897          997 :       && TREE_CODE (decl) == FUNCTION_DECL
    5898     28329479 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
    5899          966 :           || current_function_decl))
    5900              :     {
    5901           46 :       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
    5902              :         ;
    5903           37 :       else if (declspecs->storage_class != csc_static)
    5904           37 :         DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
    5905              :     }
    5906              : 
    5907     28328490 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5908     15063065 :       && DECL_DECLARED_INLINE_P (decl)
    5909         1019 :       && DECL_UNINLINABLE (decl)
    5910     28328492 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5911              :     {
    5912            2 :       auto_urlify_attributes sentinel;
    5913            2 :       warning (OPT_Wattributes, "inline function %q+D given attribute %qs",
    5914              :                decl, "noinline");
    5915            2 :     }
    5916              : 
    5917              :   /* C99 6.7.4p3: An inline definition of a function with external
    5918              :      linkage shall not contain a definition of a modifiable object
    5919              :      with static storage duration...  */
    5920     28328490 :   if (VAR_P (decl)
    5921      8921114 :       && current_scope != file_scope
    5922      7771702 :       && TREE_STATIC (decl)
    5923        78843 :       && !TREE_READONLY (decl)
    5924        76286 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    5925     28328560 :       && DECL_EXTERNAL (current_function_decl))
    5926            7 :     record_inline_static (input_location, current_function_decl,
    5927              :                           decl, csi_modifiable);
    5928              : 
    5929     28328490 :   if (c_dialect_objc ()
    5930            0 :       && VAR_OR_FUNCTION_DECL_P (decl))
    5931            0 :       objc_check_global_decl (decl);
    5932              : 
    5933              :   /* To enable versions to be created across TU's we mark and mangle all
    5934              :      non-default versioned functions.  */
    5935     28328490 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5936              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
    5937              :       && get_target_version (decl).is_valid ())
    5938              :     {
    5939              :       maybe_mark_function_versioned (decl);
    5940              :       if (current_scope != file_scope)
    5941              :         error ("versioned declarations are only allowed at file scope");
    5942              :     }
    5943              : 
    5944              :   /* Add this decl to the current scope.
    5945              :      TEM may equal DECL or it may be a previous decl of the same name.  */
    5946     28328490 :   if (do_push)
    5947              :     {
    5948     28328142 :       tem = pushdecl (decl);
    5949              : 
    5950     28328142 :       if (initialized && DECL_EXTERNAL (tem))
    5951              :         {
    5952           27 :           DECL_EXTERNAL (tem) = 0;
    5953           27 :           TREE_STATIC (tem) = 1;
    5954              :         }
    5955              : 
    5956     28328142 :       return tem;
    5957              :     }
    5958              :   else
    5959          348 :     return decl;
    5960              : }
    5961              : 
    5962              : /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
    5963              :    DECL or the non-array element type if DECL is an uninitialized array.
    5964              :    If that type has a const member, diagnose this. */
    5965              : 
    5966              : static void
    5967            7 : diagnose_uninitialized_cst_member (tree decl, tree type)
    5968              : {
    5969            7 :   tree field;
    5970           17 :   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
    5971              :     {
    5972           10 :       tree field_type;
    5973           10 :       if (TREE_CODE (field) != FIELD_DECL)
    5974            0 :         continue;
    5975           10 :       field_type = strip_array_types (TREE_TYPE (field));
    5976              : 
    5977           10 :       if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
    5978              :         {
    5979            5 :           auto_diagnostic_group d;
    5980            5 :           if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    5981              :                           "uninitialized const member in %qT is invalid in C++",
    5982            5 :                           strip_array_types (TREE_TYPE (decl))))
    5983            5 :             inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
    5984            5 :         }
    5985              : 
    5986           10 :       if (RECORD_OR_UNION_TYPE_P (field_type))
    5987            2 :         diagnose_uninitialized_cst_member (decl, field_type);
    5988              :     }
    5989            7 : }
    5990              : 
    5991              : /* Finish processing of a declaration;
    5992              :    install its initial value.
    5993              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    5994              :    If the length of an array type is not known before,
    5995              :    it must be determined now, from the initial value, or it is an error.
    5996              : 
    5997              :    INIT_LOC is the location of the initial value.  */
    5998              : 
    5999              : void
    6000    157313675 : finish_decl (tree decl, location_t init_loc, tree init,
    6001              :              tree origtype, tree asmspec_tree)
    6002              : {
    6003    157313675 :   tree type;
    6004    157313675 :   bool was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
    6005    157313675 :   const char *asmspec = 0;
    6006              : 
    6007              :   /* If a name was specified, get the string.  */
    6008    148389572 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6009    172376740 :       && DECL_FILE_SCOPE_P (decl))
    6010     16213994 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    6011    157313675 :   if (asmspec_tree)
    6012       872693 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    6013              : 
    6014    157313675 :   if (VAR_P (decl)
    6015      8924103 :       && TREE_STATIC (decl)
    6016    158376343 :       && global_bindings_p ())
    6017              :     /* So decl is a global variable. Record the types it uses
    6018              :        so that we can decide later to emit debug info for them.  */
    6019       980619 :     record_types_used_by_current_var_decl (decl);
    6020              : 
    6021              :   /* If `start_decl' didn't like having an initialization, ignore it now.  */
    6022    157313675 :   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
    6023              :     init = NULL_TREE;
    6024              : 
    6025              :   /* Don't crash if parm is initialized.  */
    6026    157313675 :   if (TREE_CODE (decl) == PARM_DECL)
    6027              :     init = NULL_TREE;
    6028              : 
    6029     32618925 :   if (init)
    6030      6354086 :     store_init_value (init_loc, decl, init, origtype);
    6031              : 
    6032    157313675 :   if (c_dialect_objc () && (VAR_OR_FUNCTION_DECL_P (decl)
    6033            0 :                             || TREE_CODE (decl) == FIELD_DECL))
    6034            0 :     objc_check_decl (decl);
    6035              : 
    6036    157313675 :   type = TREE_TYPE (decl);
    6037              : 
    6038              :   /* Deduce size of array from initialization, if not already known.
    6039              :      This is only needed for an initialization in the current scope;
    6040              :      it must not be done for a file-scope initialization of a
    6041              :      declaration with external linkage, redeclared in an inner scope
    6042              :      with the outer declaration shadowed in an intermediate scope.  */
    6043    157313675 :   if (TREE_CODE (type) == ARRAY_TYPE
    6044       853552 :       && TYPE_DOMAIN (type) == NULL_TREE
    6045        19937 :       && TREE_CODE (decl) != TYPE_DECL
    6046    157333514 :       && !(TREE_PUBLIC (decl) && current_scope != file_scope))
    6047              :     {
    6048        19652 :       bool do_default
    6049        19652 :         = !TREE_STATIC (decl) && !DECL_EXTERNAL (decl);
    6050        19652 :       int failure
    6051        19652 :         = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
    6052              :                                do_default);
    6053              : 
    6054              :       /* Get the completed type made by complete_array_type.  */
    6055        19652 :       type = TREE_TYPE (decl);
    6056              : 
    6057        19652 :       switch (failure)
    6058              :         {
    6059            0 :         case 1:
    6060            0 :           error ("initializer fails to determine size of %q+D", decl);
    6061            0 :           break;
    6062              : 
    6063         7371 :         case 2:
    6064         7371 :           if (do_default)
    6065            1 :             error ("array size missing in %q+D", decl);
    6066         7370 :           else if (!TREE_PUBLIC (decl))
    6067           37 :             pedwarn_c23 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    6068              :                          "array size missing in %q+D", decl);
    6069              :           break;
    6070              : 
    6071            3 :         case 3:
    6072            3 :           error ("zero or negative size array %q+D", decl);
    6073            3 :           break;
    6074              : 
    6075        12278 :         case 0:
    6076              :           /* For global variables, update the copy of the type that
    6077              :              exists in the binding.  */
    6078        12278 :           if (TREE_PUBLIC (decl))
    6079              :             {
    6080         3830 :               struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
    6081         7660 :               while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    6082         3830 :                 b_ext = b_ext->shadowed;
    6083         3830 :               if (b_ext && TREE_CODE (decl) == TREE_CODE (b_ext->decl))
    6084              :                 {
    6085         3830 :                   if (b_ext->u.type && comptypes (b_ext->u.type, type))
    6086          176 :                     b_ext->u.type = composite_type (b_ext->u.type, type);
    6087              :                   else
    6088         3654 :                     b_ext->u.type = type;
    6089              :                 }
    6090              :             }
    6091              :           break;
    6092              : 
    6093            0 :         default:
    6094            0 :           gcc_unreachable ();
    6095              :         }
    6096              : 
    6097        19652 :       if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
    6098        11409 :         TREE_TYPE (DECL_INITIAL (decl)) = type;
    6099              : 
    6100        19652 :       relayout_decl (decl);
    6101              :     }
    6102              : 
    6103              :   /* Look for braced array initializers for character arrays and
    6104              :      recursively convert them into STRING_CSTs.  */
    6105    157313675 :   if (tree init = DECL_INITIAL (decl))
    6106    131051252 :     DECL_INITIAL (decl) = braced_lists_to_strings (type, init);
    6107              : 
    6108    157313675 :   if (VAR_P (decl))
    6109              :     {
    6110      8924103 :       if (init && TREE_CODE (init) == CONSTRUCTOR)
    6111       105789 :         add_flexible_array_elts_to_size (decl, init);
    6112              : 
    6113      8924103 :       complete_flexible_array_elts (DECL_INITIAL (decl));
    6114              : 
    6115      8924103 :       if (is_global_var (decl))
    6116              :         {
    6117      1232769 :           type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    6118      1232769 :                                        ? TCTX_THREAD_STORAGE
    6119              :                                        : TCTX_STATIC_STORAGE);
    6120      1232769 :           if (!verify_type_context (input_location, context, TREE_TYPE (decl)))
    6121            0 :             TREE_TYPE (decl) = error_mark_node;
    6122              :         }
    6123              : 
    6124      8932216 :       if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node
    6125      8932113 :           && COMPLETE_TYPE_P (TREE_TYPE (decl)))
    6126          107 :         layout_decl (decl, 0);
    6127              : 
    6128      8924103 :       if (DECL_SIZE (decl) == NULL_TREE
    6129              :           /* Don't give an error if we already gave one earlier.  */
    6130         8006 :           && TREE_TYPE (decl) != error_mark_node
    6131      8932006 :           && (TREE_STATIC (decl)
    6132              :               /* A static variable with an incomplete type
    6133              :                  is an error if it is initialized.
    6134              :                  Also if it is not file scope.
    6135              :                  Also if it is thread-local (in C23).
    6136              :                  Otherwise, let it through, but if it is not `extern'
    6137              :                  then it may cause an error message later.  */
    6138          309 :               ? (DECL_INITIAL (decl) != NULL_TREE
    6139          309 :                  || !DECL_FILE_SCOPE_P (decl)
    6140          306 :                  || (flag_isoc23 && DECL_THREAD_LOCAL_P (decl)))
    6141              :               /* An automatic variable with an incomplete type
    6142              :                  is an error.  */
    6143         7594 :               : !DECL_EXTERNAL (decl)))
    6144              :          {
    6145           19 :            error ("storage size of %q+D isn%'t known", decl);
    6146           19 :            TREE_TYPE (decl) = error_mark_node;
    6147              :          }
    6148              : 
    6149     17663368 :       if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    6150      8654910 :           || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    6151       282787 :           && DECL_SIZE (decl) == NULL_TREE
    6152      8924391 :           && TREE_STATIC (decl))
    6153          135 :         incomplete_record_decls.safe_push (decl);
    6154              : 
    6155      8924103 :       if (is_global_var (decl)
    6156      1232769 :           && DECL_SIZE (decl) != NULL_TREE
    6157     10148909 :           && TREE_TYPE (decl) != error_mark_node)
    6158              :         {
    6159      1224786 :           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    6160      1224783 :             constant_expression_warning (DECL_SIZE (decl));
    6161              :           else
    6162              :             {
    6163            3 :               error ("storage size of %q+D isn%'t constant", decl);
    6164            3 :               TREE_TYPE (decl) = error_mark_node;
    6165              :             }
    6166              :         }
    6167              : 
    6168      8924103 :       if (TREE_USED (type))
    6169              :         {
    6170            4 :           TREE_USED (decl) = 1;
    6171            4 :           DECL_READ_P (decl) = 1;
    6172              :         }
    6173              :     }
    6174              : 
    6175              :   /* If this is a function and an assembler name is specified, reset DECL_RTL
    6176              :      so we can give it its new name.  Also, update builtin_decl if it
    6177              :      was a normal built-in.  */
    6178    157313675 :   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
    6179              :     {
    6180       859503 :       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
    6181        72430 :         set_builtin_user_assembler_name (decl, asmspec);
    6182       859503 :       set_user_assembler_name (decl, asmspec);
    6183              :     }
    6184              : 
    6185              :   /* If #pragma weak was used, mark the decl weak now.  */
    6186    157313675 :   maybe_apply_pragma_weak (decl);
    6187              : 
    6188              :   /* Output the assembler code and/or RTL code for variables and functions,
    6189              :      unless the type is an undefined structure or union.
    6190              :      If not, it will get done when the type is completed.  */
    6191              : 
    6192    157313675 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    6193              :     {
    6194              :       /* Determine the ELF visibility.  */
    6195     23987168 :       if (TREE_PUBLIC (decl))
    6196     16189192 :         c_determine_visibility (decl);
    6197              : 
    6198              :       /* This is a no-op in c-lang.cc or something real in objc-act.cc.  */
    6199     23987168 :       if (c_dialect_objc ())
    6200            0 :         objc_check_decl (decl);
    6201              : 
    6202     23987168 :       if (asmspec)
    6203              :         {
    6204              :           /* If this is not a static variable, issue a warning.
    6205              :              It doesn't make any sense to give an ASMSPEC for an
    6206              :              ordinary, non-register local variable.  Historically,
    6207              :              GCC has accepted -- but ignored -- the ASMSPEC in
    6208              :              this case.  */
    6209       873734 :           if (!DECL_FILE_SCOPE_P (decl)
    6210         1041 :               && VAR_P (decl)
    6211         1041 :               && !C_DECL_REGISTER (decl)
    6212       872701 :               && !TREE_STATIC (decl))
    6213            1 :             warning (0, "ignoring %<asm%> specifier for non-static local "
    6214              :                      "variable %q+D", decl);
    6215              :           else
    6216       872692 :             set_user_assembler_name (decl, asmspec);
    6217              :         }
    6218              : 
    6219     23987168 :       if (DECL_FILE_SCOPE_P (decl))
    6220              :         {
    6221     16213994 :           if (DECL_INITIAL (decl) == NULL_TREE
    6222     16213994 :               || DECL_INITIAL (decl) == error_mark_node)
    6223              :             /* Don't output anything
    6224              :                when a tentative file-scope definition is seen.
    6225              :                But at end of compilation, do output code for them.  */
    6226     16057429 :             DECL_DEFER_OUTPUT (decl) = 1;
    6227     16213994 :           if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl))
    6228           68 :             DECL_HARD_REGISTER (decl) = 1;
    6229     16213994 :           rest_of_decl_compilation (decl, true, 0);
    6230              : 
    6231     16213994 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6232              :             {
    6233     15062998 :               tree parms = DECL_ARGUMENTS (decl);
    6234     15062998 :               const bool builtin = fndecl_built_in_p (decl);
    6235     15062998 :               if (tree access = build_attr_access_from_parms (parms, !builtin))
    6236       346455 :                 decl_attributes (&decl, access, 0);
    6237              :             }
    6238              :         }
    6239              :       else
    6240              :         {
    6241              :           /* In conjunction with an ASMSPEC, the `register'
    6242              :              keyword indicates that we should place the variable
    6243              :              in a particular register.  */
    6244      7773174 :           if (asmspec && C_DECL_REGISTER (decl))
    6245              :             {
    6246         1033 :               DECL_HARD_REGISTER (decl) = 1;
    6247              :               /* This cannot be done for a structure with volatile
    6248              :                  fields, on which DECL_REGISTER will have been
    6249              :                  reset.  */
    6250         1033 :               if (!DECL_REGISTER (decl))
    6251            1 :                 error ("cannot put object with volatile field into register");
    6252              :             }
    6253              : 
    6254      7773174 :           if (TREE_CODE (decl) != FUNCTION_DECL)
    6255              :             {
    6256              :               /* If we're building a variable sized type, and we might be
    6257              :                  reachable other than via the top of the current binding
    6258              :                  level, then create a new BIND_EXPR so that we deallocate
    6259              :                  the object at the right time.  */
    6260              :               /* Note that DECL_SIZE can be null due to errors.  */
    6261      7773107 :               if (DECL_SIZE (decl)
    6262      7773061 :                   && !TREE_CONSTANT (DECL_SIZE (decl))
    6263      7780491 :                   && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    6264              :                 {
    6265         1337 :                   tree bind;
    6266         1337 :                   bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    6267         1337 :                   TREE_SIDE_EFFECTS (bind) = 1;
    6268         1337 :                   add_stmt (bind);
    6269         1337 :                   BIND_EXPR_BODY (bind) = push_stmt_list ();
    6270              :                 }
    6271      7773107 :               add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
    6272              :                                     DECL_EXPR, decl));
    6273              :             }
    6274              :         }
    6275              : 
    6276              : 
    6277     23987168 :       if (!DECL_FILE_SCOPE_P (decl))
    6278              :         {
    6279              :           /* Recompute the RTL of a local array now
    6280              :              if it used to be an incomplete type.  */
    6281      7773174 :           if (was_incomplete && !is_global_var (decl))
    6282              :             {
    6283              :               /* If we used it already as memory, it must stay in memory.  */
    6284         5369 :               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    6285              :               /* If it's still incomplete now, no init will save it.  */
    6286         5369 :               if (DECL_SIZE (decl) == NULL_TREE)
    6287          109 :                 DECL_INITIAL (decl) = NULL_TREE;
    6288              :             }
    6289              :         }
    6290              :     }
    6291              : 
    6292    157313675 :   if (TREE_CODE (decl) == TYPE_DECL)
    6293              :     {
    6294      4449855 :       if (!DECL_FILE_SCOPE_P (decl)
    6295      4449855 :           && c_type_variably_modified_p (TREE_TYPE (decl)))
    6296         5321 :         add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6297              : 
    6298      8515092 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
    6299              :     }
    6300              : 
    6301              :   /* Install a cleanup (aka destructor) if one was given.  */
    6302    157313675 :   if (VAR_P (decl) && !TREE_STATIC (decl))
    6303              :     {
    6304      7861432 :       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
    6305      7861432 :       if (attr)
    6306              :         {
    6307          131 :           tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
    6308          131 :           tree cleanup_decl = lookup_name (cleanup_id);
    6309          131 :           tree cleanup;
    6310          131 :           vec<tree, va_gc> *v;
    6311              : 
    6312              :           /* Build "cleanup(&decl)" for the destructor.  */
    6313          131 :           cleanup = build_unary_op (input_location, ADDR_EXPR, decl, false);
    6314          131 :           vec_alloc (v, 1);
    6315          131 :           v->quick_push (cleanup);
    6316          131 :           cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
    6317          131 :                                                vNULL, cleanup_decl, v, NULL);
    6318          131 :           vec_free (v);
    6319              : 
    6320              :           /* Don't warn about decl unused; the cleanup uses it.  */
    6321          131 :           TREE_USED (decl) = 1;
    6322          131 :           TREE_USED (cleanup_decl) = 1;
    6323          131 :           DECL_READ_P (decl) = 1;
    6324              : 
    6325          131 :           push_cleanup (decl, cleanup, false);
    6326              :         }
    6327              :     }
    6328              : 
    6329    157313675 :   if (warn_cxx_compat
    6330        22483 :       && VAR_P (decl)
    6331         7549 :       && !DECL_EXTERNAL (decl)
    6332    157320781 :       && DECL_INITIAL (decl) == NULL_TREE)
    6333              :     {
    6334         2333 :       type = strip_array_types (type);
    6335         2333 :       if (TREE_READONLY (decl))
    6336            6 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    6337              :                     "uninitialized %<const %D%> is invalid in C++", decl);
    6338         2327 :       else if (RECORD_OR_UNION_TYPE_P (type)
    6339         2327 :                && C_TYPE_FIELDS_READONLY (type))
    6340            5 :         diagnose_uninitialized_cst_member (decl, type);
    6341              :     }
    6342              : 
    6343    157313675 :   if (flag_openmp
    6344       466725 :       && VAR_P (decl)
    6345    157337733 :       && lookup_attribute ("omp declare target implicit",
    6346        24058 :                            DECL_ATTRIBUTES (decl)))
    6347              :     {
    6348           13 :       DECL_ATTRIBUTES (decl)
    6349           13 :         = remove_attribute ("omp declare target implicit",
    6350           13 :                             DECL_ATTRIBUTES (decl));
    6351           13 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    6352            9 :         error ("%q+D in declare target directive does not have mappable type",
    6353              :                decl);
    6354            4 :       else if (!lookup_attribute ("omp declare target",
    6355            4 :                                   DECL_ATTRIBUTES (decl))
    6356            8 :                && !lookup_attribute ("omp declare target link",
    6357            4 :                                      DECL_ATTRIBUTES (decl)))
    6358              :         {
    6359            4 :           DECL_ATTRIBUTES (decl)
    6360            4 :             = tree_cons (get_identifier ("omp declare target"),
    6361            4 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    6362            4 :             symtab_node *node = symtab_node::get (decl);
    6363            4 :             if (node != NULL)
    6364              :               {
    6365            4 :                 node->offloadable = 1;
    6366            4 :                 if (ENABLE_OFFLOADING)
    6367              :                   {
    6368              :                     g->have_offload = true;
    6369              :                     if (is_a <varpool_node *> (node))
    6370              :                       vec_safe_push (offload_vars, decl);
    6371              :                   }
    6372              :               }
    6373              :         }
    6374              :     }
    6375              : 
    6376              :   /* This is the last point we can lower alignment so give the target the
    6377              :      chance to do so.  */
    6378    157313675 :   if (VAR_P (decl)
    6379      8924103 :       && !is_global_var (decl)
    6380    165005009 :       && !DECL_HARD_REGISTER (decl))
    6381      7690301 :     targetm.lower_local_decl_alignment (decl);
    6382              : 
    6383    157313675 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    6384    157313675 : }
    6385              : 
    6386              : /* Given a parsed parameter declaration, decode it into a PARM_DECL.
    6387              :    EXPR is NULL or a pointer to an expression that needs to be
    6388              :    evaluated for the side effects of array size expressions in the
    6389              :    parameters.  */
    6390              : 
    6391              : tree
    6392            0 : grokparm (const struct c_parm *parm, tree *expr)
    6393              : {
    6394            0 :   tree attrs = parm->attrs;
    6395            0 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
    6396            0 :                               NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
    6397              : 
    6398            0 :   decl_attributes (&decl, attrs, 0);
    6399              : 
    6400            0 :   return decl;
    6401              : }
    6402              : 
    6403              : 
    6404              : 
    6405              : /* Given a parsed parameter declaration, decode it into a PARM_DECL
    6406              :    and push that on the current scope.  EXPR is a pointer to an
    6407              :    expression that needs to be evaluated for the side effects of array
    6408              :    size expressions in the parameters.  */
    6409              : 
    6410              : void
    6411    124672088 : push_parm_decl (const struct c_parm *parm, tree *expr)
    6412              : {
    6413    124672088 :   tree attrs = parm->attrs;
    6414    124672088 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
    6415    124672088 :                               &attrs, expr, NULL, DEPRECATED_NORMAL);
    6416    124672088 :   if (decl && DECL_P (decl))
    6417    124672088 :     DECL_SOURCE_LOCATION (decl) = parm->loc;
    6418              : 
    6419    124672088 :   decl_attributes (&decl, attrs, 0);
    6420              : 
    6421    124672088 :   decl = pushdecl (decl);
    6422              : 
    6423    124672088 :   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
    6424    124672088 : }
    6425              : 
    6426              : /* Mark all the parameter declarations to date as forward decls.
    6427              :    Also diagnose use of this extension.  */
    6428              : 
    6429              : void
    6430           42 : mark_forward_parm_decls (void)
    6431              : {
    6432           42 :   struct c_binding *b;
    6433              : 
    6434           42 :   if (current_scope->had_forward_parm_decls)
    6435           12 :     warning_at (input_location, OPT_Wmultiple_parameter_fwd_decl_lists,
    6436              :                 "more than one list of forward declarations of parameters");
    6437           42 :   if (pedantic && !current_scope->had_forward_parm_decls)
    6438            4 :     pedwarn (input_location, OPT_Wpedantic,
    6439              :              "ISO C forbids forward parameter declarations");
    6440              : 
    6441           42 :   current_scope->had_forward_parm_decls = true;
    6442              : 
    6443           95 :   for (b = current_scope->bindings; b; b = b->prev)
    6444           53 :     if (TREE_CODE (b->decl) == PARM_DECL)
    6445           53 :       TREE_ASM_WRITTEN (b->decl) = 1;
    6446           42 : }
    6447              : 
    6448              : /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
    6449              :    literal, which may be an incomplete array type completed by the
    6450              :    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
    6451              :    literal.  NON_CONST is true if the initializers contain something
    6452              :    that cannot occur in a constant expression.  If ALIGNAS_ALIGN is nonzero,
    6453              :    it is the (valid) alignment for this compound literal, as specified
    6454              :    with _Alignas.  SCSPECS are the storage class specifiers (C23) from the
    6455              :    compound literal.  */
    6456              : 
    6457              : tree
    6458       919745 : build_compound_literal (location_t loc, tree type, tree init, bool non_const,
    6459              :                         unsigned int alignas_align,
    6460              :                         struct c_declspecs *scspecs)
    6461              : {
    6462              :   /* We do not use start_decl here because we have a type, not a declarator;
    6463              :      and do not use finish_decl because the decl should be stored inside
    6464              :      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
    6465       919745 :   tree decl;
    6466       919745 :   tree complit;
    6467       919745 :   tree stmt;
    6468       919745 :   bool threadp = scspecs ? scspecs->thread_p : false;
    6469          307 :   enum c_storage_class storage_class = (scspecs
    6470              :                                         ? scspecs->storage_class
    6471              :                                         : csc_none);
    6472              : 
    6473       919745 :   if (type == error_mark_node
    6474       919738 :       || init == error_mark_node)
    6475              :     return error_mark_node;
    6476              : 
    6477       919685 :   if (current_scope == file_scope && storage_class == csc_register)
    6478              :     {
    6479            1 :       error_at (loc, "file-scope compound literal specifies %<register%>");
    6480            1 :       storage_class = csc_none;
    6481              :     }
    6482              : 
    6483       919685 :   if (current_scope != file_scope && threadp && storage_class == csc_none)
    6484              :     {
    6485            6 :       error_at (loc, "compound literal implicitly auto and declared %qs",
    6486            3 :                 scspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    6487            3 :       threadp = false;
    6488              :     }
    6489              : 
    6490       919685 :   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
    6491       919685 :   DECL_EXTERNAL (decl) = 0;
    6492       919685 :   TREE_PUBLIC (decl) = 0;
    6493      1839370 :   TREE_STATIC (decl) = (current_scope == file_scope
    6494       919685 :                         || storage_class == csc_static);
    6495       919685 :   DECL_CONTEXT (decl) = current_function_decl;
    6496       919685 :   TREE_USED (decl) = 1;
    6497       919685 :   DECL_READ_P (decl) = 1;
    6498       919685 :   DECL_ARTIFICIAL (decl) = 1;
    6499       919685 :   DECL_IGNORED_P (decl) = 1;
    6500       919685 :   C_DECL_COMPOUND_LITERAL_P (decl) = 1;
    6501      1839139 :   C_DECL_DECLARED_CONSTEXPR (decl) = scspecs && scspecs->constexpr_p;
    6502       919685 :   TREE_TYPE (decl) = type;
    6503       919685 :   if (threadp)
    6504           16 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    6505       919685 :   if (storage_class == csc_register)
    6506              :     {
    6507           25 :       C_DECL_REGISTER (decl) = 1;
    6508           25 :       DECL_REGISTER (decl) = 1;
    6509              :     }
    6510       919685 :   c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl);
    6511       919685 :   if (alignas_align)
    6512              :     {
    6513            3 :       SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    6514            3 :       DECL_USER_ALIGN (decl) = 1;
    6515              :     }
    6516       919685 :   store_init_value (loc, decl, init, NULL_TREE);
    6517       919685 :   if (current_scope != file_scope
    6518       919434 :       && TREE_STATIC (decl)
    6519           28 :       && !TREE_READONLY (decl)
    6520           17 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    6521       919691 :       && DECL_EXTERNAL (current_function_decl))
    6522            4 :     record_inline_static (input_location, current_function_decl,
    6523              :                           decl, csi_modifiable);
    6524              : 
    6525       919685 :   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
    6526              :     {
    6527          267 :       int failure = complete_array_type (&TREE_TYPE (decl),
    6528          267 :                                          DECL_INITIAL (decl), true);
    6529              :       /* If complete_array_type returns 3, it means that the initial value of
    6530              :          the compound literal is empty.  Allow it with a pedwarn; in pre-C23
    6531              :          modes, the empty initializer itself has been diagnosed if pedantic so
    6532              :          does not need to be diagnosed again here.  */
    6533          267 :       gcc_assert (failure == 0 || failure == 3);
    6534          267 :       if (failure == 3 && flag_isoc23)
    6535            1 :         pedwarn (loc, OPT_Wpedantic,
    6536              :                  "array of unknown size with empty initializer");
    6537              : 
    6538          267 :       type = TREE_TYPE (decl);
    6539          267 :       TREE_TYPE (DECL_INITIAL (decl)) = type;
    6540          267 :       relayout_decl (decl);
    6541              :     }
    6542              : 
    6543       919685 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    6544              :     {
    6545           19 :       c_incomplete_type_error (loc, NULL_TREE, type);
    6546           19 :       return error_mark_node;
    6547              :     }
    6548              : 
    6549       919387 :   if ((TREE_STATIC (decl) || C_DECL_DECLARED_CONSTEXPR (decl))
    6550       919887 :       && C_TYPE_VARIABLE_SIZE (type))
    6551            2 :     error_at (loc, "storage size isn%'t constant");
    6552              : 
    6553       919666 :   if (TREE_STATIC (decl)
    6554       919666 :       && !verify_type_context (loc, TCTX_STATIC_STORAGE, type))
    6555            0 :     return error_mark_node;
    6556              : 
    6557       919666 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
    6558       919666 :   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
    6559       919666 :   TREE_SIDE_EFFECTS (complit) = 1;
    6560              : 
    6561       919666 :   layout_decl (decl, 0);
    6562              : 
    6563       919666 :   if (TREE_STATIC (decl))
    6564              :     {
    6565              :       /* This decl needs a name for the assembler output.  */
    6566          279 :       set_compound_literal_name (decl);
    6567          279 :       DECL_DEFER_OUTPUT (decl) = 1;
    6568          279 :       DECL_COMDAT (decl) = 1;
    6569          279 :       pushdecl (decl);
    6570          279 :       rest_of_decl_compilation (decl, 1, 0);
    6571              :     }
    6572       919387 :   else if (current_function_decl && !current_scope->parm_flag)
    6573       919378 :     pushdecl (decl);
    6574              : 
    6575       919666 :   if (non_const)
    6576              :     {
    6577          221 :       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
    6578          221 :       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
    6579              :     }
    6580              : 
    6581              :   return complit;
    6582              : }
    6583              : 
    6584              : /* Check the type of a compound literal.  Here we just check that it
    6585              :    is valid for C++.  */
    6586              : 
    6587              : void
    6588       919742 : check_compound_literal_type (location_t loc, struct c_type_name *type_name)
    6589              : {
    6590       919742 :   if (warn_cxx_compat
    6591          165 :       && (type_name->specs->typespec_kind == ctsk_tagdef
    6592          164 :           || type_name->specs->typespec_kind == ctsk_tagfirstref
    6593          163 :           || type_name->specs->typespec_kind == ctsk_tagfirstref_attrs))
    6594            2 :     warning_at (loc, OPT_Wc___compat,
    6595              :                 "defining a type in a compound literal is invalid in C++");
    6596       919742 : }
    6597              : 
    6598              : /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
    6599              :    replacing with appropriate values if they are invalid.  */
    6600              : 
    6601              : static void
    6602        52739 : check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
    6603              :                                tree orig_name)
    6604              : {
    6605        52739 :   tree type_mv;
    6606        52739 :   unsigned int max_width;
    6607        52739 :   unsigned HOST_WIDE_INT w;
    6608        52739 :   const char *name = (orig_name
    6609        95715 :                       ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
    6610         9763 :                       : _("<anonymous>"));
    6611              : 
    6612              :   /* Detect and ignore out of range field width and process valid
    6613              :      field widths.  */
    6614        52739 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
    6615              :     {
    6616            8 :       error_at (loc, "bit-field %qs width not an integer constant", name);
    6617            8 :       *width = integer_one_node;
    6618              :     }
    6619              :   else
    6620              :     {
    6621        52731 :       if (TREE_CODE (*width) != INTEGER_CST)
    6622              :         {
    6623           12 :           *width = c_fully_fold (*width, false, NULL);
    6624           12 :           if (TREE_CODE (*width) == INTEGER_CST)
    6625            6 :             pedwarn (loc, OPT_Wpedantic,
    6626              :                      "bit-field %qs width not an integer constant expression",
    6627              :                      name);
    6628              :         }
    6629        52731 :       if (TREE_CODE (*width) != INTEGER_CST)
    6630              :         {
    6631            6 :           error_at (loc, "bit-field %qs width not an integer constant", name);
    6632            6 :           *width = integer_one_node;
    6633              :         }
    6634        52731 :       constant_expression_warning (*width);
    6635        52731 :       if (tree_int_cst_sgn (*width) < 0)
    6636              :         {
    6637            2 :           error_at (loc, "negative width in bit-field %qs", name);
    6638            2 :           *width = integer_one_node;
    6639              :         }
    6640        52729 :       else if (integer_zerop (*width) && orig_name)
    6641              :         {
    6642            4 :           error_at (loc, "zero width for bit-field %qs", name);
    6643            4 :           *width = integer_one_node;
    6644              :         }
    6645              :     }
    6646              : 
    6647              :   /* Detect invalid bit-field type.  */
    6648        52739 :   if (TREE_CODE (*type) != INTEGER_TYPE
    6649              :       && TREE_CODE (*type) != BOOLEAN_TYPE
    6650              :       && TREE_CODE (*type) != ENUMERAL_TYPE
    6651        52739 :       && TREE_CODE (*type) != BITINT_TYPE)
    6652              :     {
    6653            8 :       error_at (loc, "bit-field %qs has invalid type", name);
    6654            8 :       *type = unsigned_type_node;
    6655              :     }
    6656              : 
    6657        52739 :   if (TYPE_WARN_IF_NOT_ALIGN (*type))
    6658              :     {
    6659            1 :       error_at (loc, "cannot declare bit-field %qs with %<warn_if_not_aligned%> type",
    6660              :                 name);
    6661            1 :       *type = unsigned_type_node;
    6662              :     }
    6663              : 
    6664        52739 :   type_mv = TYPE_MAIN_VARIANT (*type);
    6665        52739 :   if (!in_system_header_at (input_location)
    6666        29367 :       && type_mv != integer_type_node
    6667        26628 :       && type_mv != unsigned_type_node
    6668        65355 :       && type_mv != boolean_type_node)
    6669        12033 :     pedwarn_c90 (loc, OPT_Wpedantic,
    6670              :                  "type of bit-field %qs is a GCC extension", name);
    6671              : 
    6672        52739 :   max_width = TYPE_PRECISION (*type);
    6673              : 
    6674        52739 :   if (compare_tree_int (*width, max_width) > 0)
    6675              :     {
    6676            4 :       error_at (loc, "width of %qs exceeds its type", name);
    6677            4 :       w = max_width;
    6678            4 :       *width = build_int_cst (integer_type_node, w);
    6679              :     }
    6680              :   else
    6681        52735 :     w = tree_to_uhwi (*width);
    6682              : 
    6683              :   /* Truncation of hardbool false and true representation values is always safe:
    6684              :      either the values remain different, or we'll report a problem when creating
    6685              :      the narrower type.  */
    6686        52739 :   if (c_hardbool_type_attr (*type))
    6687        52739 :     return;
    6688              : 
    6689        52458 :   if (TREE_CODE (*type) == ENUMERAL_TYPE)
    6690              :     {
    6691         4140 :       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
    6692         4140 :       if (!lt
    6693         4130 :           || w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
    6694         8266 :           || w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
    6695           15 :         warning_at (loc, 0, "%qs is narrower than values of its type", name);
    6696              :     }
    6697              : }
    6698              : 
    6699              : 
    6700              : 
    6701              : /* Print warning about variable length array if necessary.  */
    6702              : 
    6703              : static void
    6704        22493 : warn_variable_length_array (tree name, tree size)
    6705              : {
    6706        22493 :   if (TREE_CONSTANT (size))
    6707              :     {
    6708          181 :       if (name)
    6709          168 :         pedwarn_c90 (input_location, OPT_Wvla,
    6710              :                      "ISO C90 forbids array %qE whose size "
    6711              :                      "cannot be evaluated", name);
    6712              :       else
    6713           13 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
    6714              :                      "whose size cannot be evaluated");
    6715              :     }
    6716              :   else
    6717              :     {
    6718        22312 :       if (name)
    6719        13828 :         pedwarn_c90 (input_location, OPT_Wvla,
    6720              :                      "ISO C90 forbids variable length array %qE", name);
    6721              :       else
    6722         8484 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
    6723              :                      "length array");
    6724              :     }
    6725        22493 : }
    6726              : 
    6727              : /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
    6728              :    considering only those c_declspec_words found in LIST, which
    6729              :    must be terminated by cdw_number_of_elements.  */
    6730              : 
    6731              : static location_t
    6732          235 : smallest_type_quals_location (const location_t *locations,
    6733              :                               const c_declspec_word *list)
    6734              : {
    6735          235 :   location_t loc = UNKNOWN_LOCATION;
    6736         1410 :   while (*list != cdw_number_of_elements)
    6737              :     {
    6738         1175 :       location_t newloc = locations[*list];
    6739         1175 :       if (loc == UNKNOWN_LOCATION
    6740          288 :           || (newloc != UNKNOWN_LOCATION && newloc < loc))
    6741          887 :         loc = newloc;
    6742         1175 :       list++;
    6743              :     }
    6744              : 
    6745          235 :   return loc;
    6746              : }
    6747              : 
    6748              : 
    6749              : /* We attach an artificial TYPE_DECL to pointed-to type
    6750              :    and arrange for it to be included in a DECL_EXPR.  This
    6751              :    forces the sizes evaluation at a safe point and ensures it
    6752              :    is not deferred until e.g. within a deeper conditional context.
    6753              : 
    6754              :    PARM contexts have no enclosing statement list that
    6755              :    can hold the DECL_EXPR, so we need to use a BIND_EXPR
    6756              :    instead, and add it to the list of expressions that
    6757              :    need to be evaluated.
    6758              : 
    6759              :    TYPENAME contexts do have an enclosing statement list,
    6760              :    but it would be incorrect to use it, as the size should
    6761              :    only be evaluated if the containing expression is
    6762              :    evaluated.  We might also be in the middle of an
    6763              :    expression with side effects on the pointed-to type size
    6764              :    "arguments" prior to the pointer declaration point and
    6765              :    the fake TYPE_DECL in the enclosing context would force
    6766              :    the size evaluation prior to the side effects.  We therefore
    6767              :    use BIND_EXPRs in TYPENAME contexts too.  */
    6768              : static void
    6769         7038 : add_decl_expr (location_t loc, tree type, tree *expr, bool set_name_p)
    6770              : {
    6771         7038 :   tree bind = NULL_TREE;
    6772         7038 :   if (expr)
    6773              :     {
    6774         1596 :       bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, NULL_TREE,
    6775              :                      NULL_TREE);
    6776         1596 :       TREE_SIDE_EFFECTS (bind) = 1;
    6777         1596 :       BIND_EXPR_BODY (bind) = push_stmt_list ();
    6778         1596 :       push_scope ();
    6779              :     }
    6780              : 
    6781         7038 :   tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
    6782         7038 :   pushdecl (decl);
    6783         7038 :   DECL_ARTIFICIAL (decl) = 1;
    6784         7038 :   add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6785         7038 :   if (set_name_p)
    6786         6322 :     TYPE_NAME (type) = decl;
    6787              : 
    6788         7038 :   if (bind)
    6789              :     {
    6790         1596 :       pop_scope ();
    6791         1596 :       BIND_EXPR_BODY (bind) = pop_stmt_list (BIND_EXPR_BODY (bind));
    6792         1596 :       if (*expr)
    6793         1475 :         *expr = build2 (COMPOUND_EXPR, void_type_node, *expr, bind);
    6794              :       else
    6795          121 :         *expr = bind;
    6796              :     }
    6797         7038 : }
    6798              : 
    6799              : 
    6800              : /* Add attribute "arg spec" to ATTRS corresponding to an array/VLA parameter
    6801              :    declared with type TYPE.  The attribute has two arguments.  The first is
    6802              :    a string that encodes the presence of the static keyword.  The second is
    6803              :    the declared type of the array before adjustment, i.e. as an array type
    6804              :    including the outermost bound.  */
    6805              : 
    6806              : static tree
    6807       438789 : build_arg_spec_attribute (tree type, bool static_p, tree attrs)
    6808              : {
    6809       438789 :   tree vbchain = tree_cons (NULL_TREE, type, NULL_TREE);
    6810       438789 :   tree acsstr = static_p ? build_string (7, "static") :
    6811       438667 :                            build_string (1, "");
    6812       438789 :   tree args = tree_cons (NULL_TREE, acsstr, vbchain);
    6813       438789 :   tree name = get_identifier ("arg spec");
    6814       438789 :   return tree_cons (name, args, attrs);
    6815              : }
    6816              : 
    6817              : 
    6818              : /* Given declspecs and a declarator,
    6819              :    determine the name and type of the object declared
    6820              :    and construct a ..._DECL node for it.
    6821              :    (In one case we can return a ..._TYPE node instead.
    6822              :     For invalid input we sometimes return NULL_TREE.)
    6823              : 
    6824              :    DECLSPECS is a c_declspecs structure for the declaration specifiers.
    6825              : 
    6826              :    DECL_CONTEXT says which syntactic context this declaration is in:
    6827              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
    6828              :      FUNCDEF for a function definition.  Like NORMAL but a few different
    6829              :       error messages in each case.  Return value may be zero meaning
    6830              :       this definition is too screwy to try to parse.
    6831              :      PARM for a parameter declaration (either within a function prototype
    6832              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
    6833              :      TYPENAME if for a typename (in a cast or sizeof).
    6834              :       Don't make a DECL node; just return the ..._TYPE node.
    6835              :      GENERIC_ASSOC for typenames in a generic association.
    6836              :      FIELD for a struct or union field; make a FIELD_DECL.
    6837              :    INITIALIZED is true if the decl has an initializer.
    6838              :    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
    6839              :    representing the width of the bit-field.
    6840              :    DECL_ATTRS points to the list of attributes that should be added to this
    6841              :      decl.  Any nested attributes that belong on the decl itself will be
    6842              :      added to this list.
    6843              :    If EXPR is not NULL, any expressions that need to be evaluated as
    6844              :      part of evaluating variably modified types will be stored in *EXPR.
    6845              :    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
    6846              :      set to indicate whether operands in *EXPR can be used in constant
    6847              :      expressions.
    6848              :    DEPRECATED_STATE is a deprecated_states value indicating whether
    6849              :    deprecation/unavailability warnings should be suppressed.
    6850              : 
    6851              :    In the TYPENAME case, DECLARATOR is really an absolute declarator.
    6852              :    It may also be so in the PARM case, for a prototype where the
    6853              :    argument type is specified but not the name.
    6854              : 
    6855              :    This function is where the complicated C meanings of `static'
    6856              :    and `extern' are interpreted.  */
    6857              : 
    6858              : static tree
    6859    315215236 : grokdeclarator (const struct c_declarator *declarator,
    6860              :                 struct c_declspecs *declspecs,
    6861              :                 enum decl_context decl_context, bool initialized, tree *width,
    6862              :                 tree *decl_attrs, tree *expr, bool *expr_const_operands,
    6863              :                 enum deprecated_states deprecated_state)
    6864              : {
    6865    315215236 :   tree type = declspecs->type;
    6866    315215236 :   bool threadp = declspecs->thread_p;
    6867    315215236 :   bool constexprp = declspecs->constexpr_p;
    6868    315215236 :   enum c_storage_class storage_class = declspecs->storage_class;
    6869    315215236 :   int constp;
    6870    315215236 :   int restrictp;
    6871    315215236 :   int volatilep;
    6872    315215236 :   int atomicp;
    6873    315215236 :   int type_quals = TYPE_UNQUALIFIED;
    6874    315215236 :   tree name = NULL_TREE;
    6875    315215236 :   bool funcdef_flag = false;
    6876    315215236 :   bool funcdef_syntax = false;
    6877    315215236 :   bool size_varies = false;
    6878    315215236 :   bool size_error = false;
    6879    315215236 :   tree decl_attr = declspecs->decl_attr;
    6880    315215236 :   int array_ptr_quals = TYPE_UNQUALIFIED;
    6881    315215236 :   tree array_ptr_attrs = NULL_TREE;
    6882    315215236 :   bool array_parm_static = false;
    6883    315215236 :   bool array_parm_vla_unspec_p = false;
    6884    315215236 :   tree returned_attrs = NULL_TREE;
    6885    315215236 :   tree decl_id_attrs = NULL_TREE;
    6886    315215236 :   bool bitfield = width != NULL;
    6887    315215236 :   tree element_type;
    6888    315215236 :   tree orig_qual_type = NULL;
    6889    315215236 :   size_t orig_qual_indirect = 0;
    6890    315215236 :   struct c_arg_info *arg_info = 0;
    6891    315215236 :   addr_space_t as1, as2, address_space;
    6892    315215236 :   location_t loc = UNKNOWN_LOCATION;
    6893    315215236 :   tree expr_dummy;
    6894    315215236 :   bool expr_const_operands_dummy;
    6895    315215236 :   enum c_declarator_kind first_non_attr_kind;
    6896    315215236 :   unsigned int alignas_align = 0;
    6897              : 
    6898    315215236 :   if (type == NULL_TREE)
    6899              :     {
    6900              :       /* This can occur for auto on a parameter in C23 mode.  Set a
    6901              :          dummy type here so subsequent code can give diagnostics for
    6902              :          this case.  */
    6903            2 :       gcc_assert (declspecs->c23_auto_p);
    6904            2 :       gcc_assert (decl_context == PARM);
    6905            2 :       type = declspecs->type = integer_type_node;
    6906              :     }
    6907    315215236 :   if (TREE_CODE (type) == ERROR_MARK)
    6908           29 :     return error_mark_node;
    6909    315215207 :   if (expr == NULL)
    6910              :     {
    6911        38177 :       expr = &expr_dummy;
    6912        38177 :       expr_dummy = NULL_TREE;
    6913              :     }
    6914    315215207 :   if (expr_const_operands == NULL)
    6915    193696337 :     expr_const_operands = &expr_const_operands_dummy;
    6916              : 
    6917    315215207 :   if (declspecs->expr)
    6918              :     {
    6919          953 :       if (*expr)
    6920            7 :         *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
    6921              :                         declspecs->expr);
    6922              :       else
    6923          946 :         *expr = declspecs->expr;
    6924              :     }
    6925    315215207 :   *expr_const_operands = declspecs->expr_const_operands;
    6926              : 
    6927    315215207 :   if (decl_context == FUNCDEF)
    6928     36326467 :     funcdef_flag = true, decl_context = NORMAL;
    6929              : 
    6930              :   /* Look inside a declarator for the name being declared
    6931              :      and get it as an IDENTIFIER_NODE, for an error message.  */
    6932    315215207 :   {
    6933    315215207 :     const struct c_declarator *decl = declarator;
    6934              : 
    6935    315215207 :     first_non_attr_kind = cdk_attrs;
    6936    385670867 :     while (decl)
    6937    385670867 :       switch (decl->kind)
    6938              :         {
    6939      1139444 :         case cdk_array:
    6940      1139444 :           loc = decl->id_loc;
    6941              :           /* FALL THRU.  */
    6942              : 
    6943     70448871 :         case cdk_function:
    6944     70448871 :         case cdk_pointer:
    6945     70448871 :           funcdef_syntax = (decl->kind == cdk_function);
    6946     70448871 :           if (first_non_attr_kind == cdk_attrs)
    6947     68320168 :             first_non_attr_kind = decl->kind;
    6948     70448871 :           decl = decl->declarator;
    6949     70448871 :           break;
    6950              : 
    6951         6789 :         case cdk_attrs:
    6952         6789 :           decl = decl->declarator;
    6953         6789 :           break;
    6954              : 
    6955    315215207 :         case cdk_id:
    6956    315215207 :           loc = decl->id_loc;
    6957    315215207 :           if (decl->u.id.id)
    6958              :             name = decl->u.id.id;
    6959    315215207 :           decl_id_attrs = decl->u.id.attrs;
    6960    315215207 :           if (first_non_attr_kind == cdk_attrs)
    6961    246895039 :             first_non_attr_kind = decl->kind;
    6962              :           decl = 0;
    6963              :           break;
    6964              : 
    6965            0 :         default:
    6966            0 :           gcc_unreachable ();
    6967              :         }
    6968    315215207 :     if (name == NULL_TREE)
    6969              :       {
    6970    126227615 :         gcc_assert (decl_context == PARM
    6971              :                     || decl_context == TYPENAME
    6972              :                     || decl_context == GENERIC_ASSOC
    6973              :                     || (decl_context == FIELD
    6974              :                         && declarator->kind == cdk_id));
    6975    126227615 :         gcc_assert (!initialized);
    6976              :       }
    6977              :   }
    6978              : 
    6979              :   /* An enum type specifier (": specifier-qualifier-list") may only be
    6980              :      specified when the enum is being defined or in an empty
    6981              :      declaration of the form "enum identifier enum-type-specifier;".
    6982              :      Except for the case of an empty declaration that has additional
    6983              :      declaration specifiers, all invalid contexts (declarations that
    6984              :      aren't empty, type names, parameter declarations, member
    6985              :      declarations) pass through grokdeclarator.  */
    6986    315215207 :   if (declspecs->enum_type_specifier_ref_p)
    6987            6 :     error_at (loc, "%<enum%> underlying type may not be specified here");
    6988              : 
    6989              :   /* A function definition's declarator must have the form of
    6990              :      a function declarator.  */
    6991              : 
    6992    315215207 :   if (funcdef_flag && !funcdef_syntax)
    6993              :     return NULL_TREE;
    6994              : 
    6995              :   /* If this looks like a function definition, make it one,
    6996              :      even if it occurs where parms are expected.
    6997              :      Then store_parm_decls will reject it and not use it as a parm.  */
    6998    315215176 :   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
    6999        22662 :     decl_context = PARM;
    7000              : 
    7001    315215176 :   if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    7002              :     {
    7003    315215152 :       if (declspecs->unavailable_p)
    7004           28 :         error_unavailable_use (declspecs->type, declspecs->decl_attr);
    7005    315215124 :       else if (declspecs->deprecated_p
    7006           46 :                 && deprecated_state != DEPRECATED_SUPPRESS)
    7007           38 :         warn_deprecated_use (declspecs->type, declspecs->decl_attr);
    7008              :     }
    7009              : 
    7010    315215176 :   if ((decl_context == NORMAL || decl_context == FIELD)
    7011     68942194 :       && current_scope == file_scope
    7012    376084877 :       && c_type_variably_modified_p (type))
    7013              :     {
    7014            3 :       if (name)
    7015            3 :         error_at (loc, "variably modified %qE at file scope", name);
    7016              :       else
    7017            0 :         error_at (loc, "variably modified field at file scope");
    7018            3 :       type = integer_type_node;
    7019              :     }
    7020              : 
    7021    315215176 :   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
    7022              : 
    7023              :   /* Diagnose defaulting to "int".  */
    7024              : 
    7025    315215176 :   if (declspecs->default_int_p)
    7026              :     {
    7027              :       /* Issue a warning if this is an ISO C 99 program or if
    7028              :          -Wreturn-type and this is a function, or if -Wimplicit;
    7029              :          prefer the former warning since it is more explicit.  */
    7030         9764 :       if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99)
    7031         1229 :           && funcdef_flag)
    7032          702 :         warn_about_return_type = 1;
    7033              :       else
    7034              :         {
    7035         9062 :           if (name)
    7036         9052 :             permerror_opt (loc, OPT_Wimplicit_int,
    7037              :                            "type defaults to %<int%> in declaration "
    7038              :                            "of %qE", name);
    7039              :           else
    7040           10 :             permerror_opt (loc, OPT_Wimplicit_int,
    7041              :                            "type defaults to %<int%> in type name");
    7042              :         }
    7043              :     }
    7044              : 
    7045              :   /* Adjust the type if a bit-field is being declared,
    7046              :      -funsigned-bitfields applied and the type is not explicitly
    7047              :      "signed".  */
    7048    315215176 :   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
    7049           40 :       && TREE_CODE (type) == INTEGER_TYPE)
    7050           38 :     type = c_common_unsigned_type (type);
    7051              : 
    7052              :   /* Figure out the type qualifiers for the declaration.  There are
    7053              :      two ways a declaration can become qualified.  One is something
    7054              :      like `const int i' where the `const' is explicit.  Another is
    7055              :      something like `typedef const int CI; CI i' where the type of the
    7056              :      declaration contains the `const'.  A third possibility is that
    7057              :      there is a type qualifier on the element type of a typedefed
    7058              :      array type, in which case we should extract that qualifier so
    7059              :      that c_apply_type_quals_to_decl receives the full list of
    7060              :      qualifiers to work with (C90 is not entirely clear about whether
    7061              :      duplicate qualifiers should be diagnosed in this case, but it
    7062              :      seems most appropriate to do so).  */
    7063    315215176 :   element_type = strip_array_types (type);
    7064    315215176 :   constp = declspecs->const_p + TYPE_READONLY (element_type);
    7065    315215176 :   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
    7066    315215176 :   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
    7067    315215176 :   atomicp = declspecs->atomic_p + TYPE_ATOMIC (element_type);
    7068    315215176 :   as1 = declspecs->address_space;
    7069    315215176 :   as2 = TYPE_ADDR_SPACE (element_type);
    7070    315215176 :   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
    7071              : 
    7072    315215176 :   if (constp > 1)
    7073           25 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>");
    7074    315215176 :   if (restrictp > 1)
    7075            6 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>");
    7076    315215176 :   if (volatilep > 1)
    7077           15 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>");
    7078    315215176 :   if (atomicp > 1)
    7079            9 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>");
    7080              : 
    7081    315215176 :   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
    7082            0 :     error_at (loc, "conflicting named address spaces (%s vs %s)",
    7083              :               c_addr_space_name (as1), c_addr_space_name (as2));
    7084              : 
    7085    315215176 :   if ((TREE_CODE (type) == ARRAY_TYPE
    7086    315038499 :        || first_non_attr_kind == cdk_array)
    7087    316286238 :       && TYPE_QUALS (element_type))
    7088              :     {
    7089           73 :       orig_qual_type = type;
    7090           73 :       type = c_build_qualified_type (type, TYPE_UNQUALIFIED);
    7091              :     }
    7092    315215176 :   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
    7093    315215176 :                 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
    7094    315215176 :                 | (volatilep ? TYPE_QUAL_VOLATILE : 0)
    7095    315215176 :                 | (atomicp ? TYPE_QUAL_ATOMIC : 0)
    7096    315215176 :                 | ENCODE_QUAL_ADDR_SPACE (address_space));
    7097    315215176 :   if (type_quals != TYPE_QUALS (element_type))
    7098     12853261 :     orig_qual_type = NULL_TREE;
    7099              : 
    7100              :   /* Applying the _Atomic qualifier to an array type (through the use
    7101              :      of typedefs or typeof) must be detected here.  If the qualifier
    7102              :      is introduced later, any appearance of applying it to an array is
    7103              :      actually applying it to an element of that array.  */
    7104    315215176 :   if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
    7105            6 :     error_at (loc, "%<_Atomic%>-qualified array type");
    7106              : 
    7107              :   /* Warn about storage classes that are invalid for certain
    7108              :      kinds of declarations (parameters, typenames, etc.).  */
    7109              : 
    7110    315215176 :   if (funcdef_flag
    7111     36326436 :       && (threadp
    7112              :           || constexprp
    7113     36326434 :           || storage_class == csc_auto
    7114     36326434 :           || storage_class == csc_register
    7115     36326389 :           || storage_class == csc_typedef))
    7116              :     {
    7117           47 :       if (storage_class == csc_auto)
    7118           42 :         pedwarn (loc,
    7119           81 :                  (current_scope == file_scope) ? 0 : OPT_Wpedantic,
    7120              :                  "function definition declared %<auto%>");
    7121           50 :       if (storage_class == csc_register)
    7122            3 :         error_at (loc, "function definition declared %<register%>");
    7123           50 :       if (storage_class == csc_typedef)
    7124            3 :         error_at (loc, "function definition declared %<typedef%>");
    7125           50 :       if (threadp)
    7126            2 :         error_at (loc, "function definition declared %qs",
    7127            2 :                   declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7128           50 :       threadp = false;
    7129              :       /* The parser ensures a constexpr function definition never
    7130              :          reaches here.  */
    7131           50 :       gcc_assert (!constexprp);
    7132           50 :       if (storage_class == csc_auto
    7133           50 :           || storage_class == csc_register
    7134              :           || storage_class == csc_typedef)
    7135           55 :         storage_class = csc_none;
    7136              :     }
    7137    315215126 :   else if (decl_context != NORMAL && (storage_class != csc_none
    7138    250582899 :                                       || threadp
    7139    250582316 :                                       || constexprp
    7140    250582314 :                                       || declspecs->c23_auto_p))
    7141              :     {
    7142          587 :       if (decl_context == PARM
    7143          587 :           && storage_class == csc_register
    7144          568 :           && !constexprp
    7145          566 :           && !declspecs->c23_auto_p)
    7146              :         ;
    7147              :       else
    7148              :         {
    7149           21 :           switch (decl_context)
    7150              :             {
    7151            0 :             case FIELD:
    7152            0 :               if (name)
    7153            0 :                 error_at (loc, "storage class specified for structure "
    7154              :                           "field %qE", name);
    7155              :               else
    7156            0 :                 error_at (loc, "storage class specified for structure field");
    7157              :               break;
    7158           21 :             case PARM:
    7159           21 :               if (name)
    7160            7 :                 error_at (loc, "storage class specified for parameter %qE",
    7161              :                           name);
    7162              :               else
    7163           14 :                 error_at (loc, "storage class specified for unnamed parameter");
    7164              :               break;
    7165            0 :             default:
    7166            0 :               error_at (loc, "storage class specified for typename");
    7167            0 :               break;
    7168              :             }
    7169    315215176 :           storage_class = csc_none;
    7170    315215176 :           threadp = false;
    7171    315215176 :           constexprp = false;
    7172              :         }
    7173              :     }
    7174    315214539 :   else if (storage_class == csc_extern
    7175    315214539 :            && initialized
    7176     35471750 :            && !funcdef_flag)
    7177              :     {
    7178              :       /* 'extern' with initialization is invalid if not at file scope.  */
    7179           28 :        if (current_scope == file_scope)
    7180              :          {
    7181              :            /* It is fine to have 'extern const' when compiling at C
    7182              :               and C++ intersection.  */
    7183           19 :            if (!(warn_cxx_compat && constp))
    7184           18 :              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
    7185              :                          name);
    7186              :          }
    7187              :       else
    7188            9 :         error_at (loc, "%qE has both %<extern%> and initializer", name);
    7189              :     }
    7190    315214511 :   else if (current_scope == file_scope)
    7191              :     {
    7192     61744263 :       if (storage_class == csc_auto)
    7193            7 :         error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
    7194              :                   name);
    7195     61744263 :       if (pedantic && storage_class == csc_register)
    7196            4 :         pedwarn (input_location, OPT_Wpedantic,
    7197              :                  "file-scope declaration of %qE specifies %<register%>", name);
    7198              :     }
    7199              :   else
    7200              :     {
    7201    253470248 :       if (storage_class == csc_extern && funcdef_flag)
    7202            3 :         error_at (loc, "nested function %qE declared %<extern%>", name);
    7203    253470245 :       else if (threadp && storage_class == csc_none)
    7204              :         {
    7205           14 :           error_at (loc, "function-scope %qE implicitly auto and declared "
    7206              :                     "%qs", name,
    7207            7 :                     declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7208            7 :           threadp = false;
    7209              :         }
    7210              :     }
    7211              : 
    7212              :   /* Now figure out the structure of the declarator proper.
    7213              :      Descend through it, creating more complex types, until we reach
    7214              :      the declared identifier (or NULL_TREE, in an absolute declarator).
    7215              :      At each stage we maintain an unqualified version of the type
    7216              :      together with any qualifiers that should be applied to it with
    7217              :      c_build_qualified_type; this way, array types including
    7218              :      multidimensional array types are first built up in unqualified
    7219              :      form and then the qualified form is created with
    7220              :      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
    7221              : 
    7222    385670835 :   while (declarator && declarator->kind != cdk_id)
    7223              :     {
    7224     70455659 :       if (type == error_mark_node)
    7225              :         {
    7226           39 :           declarator = declarator->declarator;
    7227           39 :           continue;
    7228              :         }
    7229              : 
    7230              :       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
    7231              :          a cdk_pointer (for *...),
    7232              :          a cdk_function (for ...(...)),
    7233              :          a cdk_attrs (for nested attributes),
    7234              :          or a cdk_id (for the name being declared
    7235              :          or the place in an absolute declarator
    7236              :          where the name was omitted).
    7237              :          For the last case, we have just exited the loop.
    7238              : 
    7239              :          At this point, TYPE is the type of elements of an array,
    7240              :          or for a function to return, or for a pointer to point to.
    7241              :          After this sequence of ifs, TYPE is the type of the
    7242              :          array or function or pointer, and DECLARATOR has had its
    7243              :          outermost layer removed.  */
    7244              : 
    7245     70455620 :       if (array_ptr_quals != TYPE_UNQUALIFIED
    7246     70455620 :           || array_ptr_attrs != NULL_TREE
    7247     70455620 :           || array_parm_static)
    7248              :         {
    7249              :           /* Only the innermost declarator (making a parameter be of
    7250              :              array type which is converted to pointer type)
    7251              :              may have static or type qualifiers.  */
    7252            1 :           error_at (loc, "static or type qualifiers in non-parameter array declarator");
    7253            1 :           array_ptr_quals = TYPE_UNQUALIFIED;
    7254            1 :           array_ptr_attrs = NULL_TREE;
    7255            1 :           array_parm_static = false;
    7256              :         }
    7257              : 
    7258     70455620 :       switch (declarator->kind)
    7259              :         {
    7260         6789 :         case cdk_attrs:
    7261         6789 :           {
    7262              :             /* A declarator with embedded attributes.  */
    7263         6789 :             tree attrs = declarator->u.attrs;
    7264         6789 :             const struct c_declarator *inner_decl;
    7265         6789 :             int attr_flags = 0;
    7266         6789 :             declarator = declarator->declarator;
    7267              :             /* Standard attribute syntax precisely defines what entity
    7268              :                an attribute in each position appertains to, so only
    7269              :                apply laxity about positioning to GNU attribute syntax.
    7270              :                Standard attributes applied to a function or array
    7271              :                declarator apply exactly to that type; standard
    7272              :                attributes applied to the identifier apply to the
    7273              :                declaration rather than to the type, and are specified
    7274              :                using a cdk_id declarator rather than using
    7275              :                cdk_attrs.  */
    7276         6789 :             inner_decl = declarator;
    7277         6789 :             while (inner_decl->kind == cdk_attrs)
    7278            0 :               inner_decl = inner_decl->declarator;
    7279         6789 :             if (!cxx11_attribute_p (attrs))
    7280              :               {
    7281         6691 :                 if (inner_decl->kind == cdk_id)
    7282              :                   attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
    7283              :                 else if (inner_decl->kind == cdk_function)
    7284              :                   attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
    7285              :                 else if (inner_decl->kind == cdk_array)
    7286         6789 :                   attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
    7287              :               }
    7288         6789 :             attrs = c_warn_type_attributes (type, attrs);
    7289         6789 :             returned_attrs = decl_attributes (&type,
    7290              :                                               chainon (returned_attrs, attrs),
    7291              :                                               attr_flags);
    7292         6789 :             break;
    7293              :           }
    7294      1139434 :         case cdk_array:
    7295      1139434 :           {
    7296      1139434 :             tree itype = NULL_TREE;
    7297      1139434 :             tree size = declarator->u.array.dimen;
    7298              :             /* The index is a signed object `sizetype' bits wide.  */
    7299      1139434 :             tree index_type = c_common_signed_type (sizetype);
    7300              : 
    7301      1139434 :             array_ptr_quals = declarator->u.array.quals;
    7302      1139434 :             array_ptr_attrs = declarator->u.array.attrs;
    7303      1139434 :             array_parm_static = declarator->u.array.static_p;
    7304      1139434 :             array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
    7305              : 
    7306      1139434 :             declarator = declarator->declarator;
    7307              : 
    7308              :             /* Check for some types that there cannot be arrays of.  */
    7309              : 
    7310      1139434 :             if (VOID_TYPE_P (type))
    7311              :               {
    7312           11 :                 if (name)
    7313            9 :                   error_at (loc, "declaration of %qE as array of voids", name);
    7314              :                 else
    7315            2 :                   error_at (loc, "declaration of type name as array of voids");
    7316           11 :                 type = error_mark_node;
    7317              :               }
    7318              : 
    7319      1139434 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7320              :               {
    7321            3 :                 if (name)
    7322            2 :                   error_at (loc, "declaration of %qE as array of functions",
    7323              :                             name);
    7324              :                 else
    7325            1 :                   error_at (loc, "declaration of type name as array of "
    7326              :                             "functions");
    7327            3 :                 type = error_mark_node;
    7328              :               }
    7329              : 
    7330        21330 :             if (pedantic && !in_system_header_at (input_location)
    7331      1154475 :                 && flexible_array_type_p (type))
    7332           20 :               pedwarn (loc, OPT_Wpedantic,
    7333              :                        "invalid use of structure with flexible array member");
    7334              : 
    7335      1139434 :             if (size == error_mark_node)
    7336          119 :               type = error_mark_node;
    7337              : 
    7338      1139434 :             if (type == error_mark_node)
    7339          133 :               continue;
    7340              : 
    7341      1139301 :             if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, type))
    7342              :               {
    7343            0 :                 type = error_mark_node;
    7344            0 :                 continue;
    7345              :               }
    7346              : 
    7347              :             /* If size was specified, set ITYPE to a range-type for
    7348              :                that size.  Otherwise, ITYPE remains null.  finish_decl
    7349              :                may figure it out from an initial value.  */
    7350              : 
    7351      1139301 :             if (size)
    7352              :               {
    7353       967804 :                 bool size_maybe_const = true;
    7354       967804 :                 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
    7355       967804 :                                        && !TREE_OVERFLOW (size));
    7356       967804 :                 bool this_size_varies = false;
    7357              : 
    7358              :                 /* Strip NON_LVALUE_EXPRs since we aren't using as an
    7359              :                    lvalue.  */
    7360       967813 :                 STRIP_TYPE_NOPS (size);
    7361              : 
    7362       967804 :                 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
    7363              :                   {
    7364           16 :                     if (name)
    7365           14 :                       error_at (loc, "size of array %qE has non-integer type",
    7366              :                                 name);
    7367              :                     else
    7368            2 :                       error_at (loc,
    7369              :                                 "size of unnamed array has non-integer type");
    7370           16 :                     size = integer_one_node;
    7371           16 :                     size_int_const = true;
    7372           16 :                     size_error = true;
    7373              :                   }
    7374              :                 /* This can happen with enum forward declaration.  */
    7375       967788 :                 else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
    7376              :                   {
    7377            0 :                     if (name)
    7378            0 :                       error_at (loc, "size of array %qE has incomplete type",
    7379              :                                 name);
    7380              :                     else
    7381            0 :                       error_at (loc, "size of unnamed array has incomplete "
    7382              :                                 "type");
    7383            0 :                     size = integer_one_node;
    7384            0 :                     size_int_const = true;
    7385            0 :                     size_error = true;
    7386              :                   }
    7387              : 
    7388       967804 :                 size = c_fully_fold (size, false, &size_maybe_const);
    7389              : 
    7390       967804 :                 if (pedantic && size_maybe_const && integer_zerop (size))
    7391              :                   {
    7392            3 :                     if (name)
    7393            3 :                       pedwarn (loc, OPT_Wpedantic,
    7394              :                                "ISO C forbids zero-size array %qE", name);
    7395              :                     else
    7396            0 :                       pedwarn (loc, OPT_Wpedantic,
    7397              :                                "ISO C forbids zero-size array");
    7398              :                   }
    7399              : 
    7400       967804 :                 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
    7401              :                   {
    7402       945445 :                     constant_expression_warning (size);
    7403       945445 :                     if (tree_int_cst_sgn (size) < 0)
    7404              :                       {
    7405          462 :                         if (name)
    7406          459 :                           error_at (loc, "size of array %qE is negative", name);
    7407              :                         else
    7408            3 :                           error_at (loc, "size of unnamed array is negative");
    7409          462 :                         size = integer_one_node;
    7410          462 :                         size_int_const = true;
    7411          462 :                         size_error = true;
    7412              :                       }
    7413              :                     /* Handle a size folded to an integer constant but
    7414              :                        not an integer constant expression.  */
    7415       945445 :                     if (!size_int_const)
    7416              :                       {
    7417              :                         /* If this is a file scope declaration of an
    7418              :                            ordinary identifier, this is invalid code;
    7419              :                            diagnosing it here and not subsequently
    7420              :                            treating the type as variable-length avoids
    7421              :                            more confusing diagnostics later.  */
    7422          155 :                         if ((decl_context == NORMAL || decl_context == FIELD)
    7423          142 :                             && current_scope == file_scope)
    7424           14 :                           pedwarn (input_location, 0,
    7425              :                                    "variably modified %qE at file scope",
    7426              :                                    name);
    7427              :                         else
    7428              :                           this_size_varies = size_varies = true;
    7429          155 :                         warn_variable_length_array (name, size);
    7430              :                       }
    7431              :                   }
    7432        22359 :                 else if ((decl_context == NORMAL || decl_context == FIELD)
    7433        13258 :                          && current_scope == file_scope)
    7434              :                   {
    7435           21 :                     error_at (loc, "variably modified %qE at file scope", name);
    7436           21 :                     size = integer_one_node;
    7437              :                   }
    7438              :                 else
    7439              :                   {
    7440              :                     /* Make sure the array size remains visibly
    7441              :                        nonconstant even if it is (eg) a const variable
    7442              :                        with known value.  */
    7443        22338 :                     this_size_varies = size_varies = true;
    7444        22338 :                     warn_variable_length_array (name, size);
    7445        22338 :                     if (sanitize_flags_p (SANITIZE_VLA)
    7446          181 :                         && current_function_decl != NULL_TREE
    7447        22501 :                         && decl_context == NORMAL)
    7448              :                       {
    7449              :                         /* Evaluate the array size only once.  */
    7450          155 :                         size = save_expr (size);
    7451          155 :                         size = c_fully_fold (size, false, NULL);
    7452          155 :                         size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7453              :                                             ubsan_instrument_vla (loc, size),
    7454              :                                             size);
    7455              :                       }
    7456              :                   }
    7457              : 
    7458       967804 :                 if (integer_zerop (size) && !this_size_varies)
    7459              :                   {
    7460              :                     /* A zero-length array cannot be represented with
    7461              :                        an unsigned index type, which is what we'll
    7462              :                        get with build_index_type.  Create an
    7463              :                        open-ended range instead.  */
    7464         2603 :                     itype = build_range_type (sizetype, size, NULL_TREE);
    7465              :                   }
    7466              :                 else
    7467              :                   {
    7468              :                     /* Arrange for the SAVE_EXPR on the inside of the
    7469              :                        MINUS_EXPR, which allows the -1 to get folded
    7470              :                        with the +1 that happens when building TYPE_SIZE.  */
    7471       965201 :                     if (size_varies)
    7472        22852 :                       size = save_expr (size);
    7473       965201 :                     if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
    7474          141 :                       size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7475              :                                      integer_zero_node, size);
    7476              : 
    7477              :                     /* Compute the maximum valid index, that is, size
    7478              :                        - 1.  Do the calculation in index_type, so that
    7479              :                        if it is a variable the computations will be
    7480              :                        done in the proper mode.  */
    7481       965201 :                     itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
    7482              :                                              convert (index_type, size),
    7483              :                                              convert (index_type,
    7484              :                                                       size_one_node));
    7485              : 
    7486              :                     /* The above overflows when size does not fit
    7487              :                        in index_type.
    7488              :                        ???  While a size of INT_MAX+1 technically shouldn't
    7489              :                        cause an overflow (because we subtract 1), handling
    7490              :                        this case seems like an unnecessary complication.  */
    7491       965201 :                     if (TREE_CODE (size) == INTEGER_CST
    7492       942722 :                         && !int_fits_type_p (size, index_type))
    7493              :                       {
    7494            6 :                         if (name)
    7495            5 :                           error_at (loc, "size of array %qE is too large",
    7496              :                                     name);
    7497              :                         else
    7498            1 :                           error_at (loc, "size of unnamed array is too large");
    7499            6 :                         type = error_mark_node;
    7500            6 :                         continue;
    7501              :                       }
    7502              : 
    7503       965195 :                     itype = build_index_type (itype);
    7504              :                   }
    7505       967798 :                 if (this_size_varies)
    7506              :                   {
    7507        22479 :                     if (TREE_SIDE_EFFECTS (size))
    7508              :                       {
    7509        22116 :                         if (*expr)
    7510         8178 :                           *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7511              :                                           *expr, size);
    7512              :                         else
    7513        13938 :                           *expr = size;
    7514              :                       }
    7515        22479 :                     *expr_const_operands &= size_maybe_const;
    7516              :                   }
    7517              :               }
    7518       171497 :             else if (decl_context == FIELD)
    7519              :               {
    7520        86000 :                 bool flexible_array_member = false;
    7521        86000 :                 if (array_parm_vla_unspec_p)
    7522              :                   /* Field names can in fact have function prototype
    7523              :                      scope so [*] is disallowed here through making
    7524              :                      the field variably modified, not through being
    7525              :                      something other than a declaration with function
    7526              :                      prototype scope.  */
    7527              :                   size_varies = true;
    7528              :                 else
    7529              :                   {
    7530              :                     const struct c_declarator *t = declarator;
    7531        85997 :                     while (t->kind == cdk_attrs)
    7532            0 :                       t = t->declarator;
    7533        85997 :                     flexible_array_member = (t->kind == cdk_id);
    7534              :                   }
    7535        85997 :                 if (flexible_array_member
    7536        85997 :                     && !in_system_header_at (input_location))
    7537        84966 :                   pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    7538              :                                "support flexible array members");
    7539              : 
    7540              :                 /* ISO C99 Flexible array members are effectively
    7541              :                    identical to GCC's zero-length array extension.  */
    7542        86000 :                 if (flexible_array_member)
    7543        85977 :                   itype = build_index_type (NULL_TREE);
    7544              :               }
    7545              : 
    7546              :             /* Complain about arrays of incomplete types.  */
    7547      1139295 :             if (!COMPLETE_TYPE_P (type))
    7548              :               {
    7549           58 :                 auto_diagnostic_group d;
    7550           58 :                 error_at (loc, "array type has incomplete element type %qT",
    7551              :                           type);
    7552              :                 /* See if we can be more helpful.  */
    7553           58 :                 if (TREE_CODE (type) == ARRAY_TYPE)
    7554              :                   {
    7555           29 :                     if (name)
    7556           24 :                       inform (loc, "declaration of %qE as multidimensional "
    7557              :                               "array must have bounds for all dimensions "
    7558              :                               "except the first", name);
    7559              :                     else
    7560            5 :                       inform (loc, "declaration of multidimensional array "
    7561              :                               "must have bounds for all dimensions except "
    7562              :                               "the first");
    7563              :                   }
    7564           58 :                 type = error_mark_node;
    7565           58 :               }
    7566              :             else
    7567              :             /* When itype is NULL, a shared incomplete array type is
    7568              :                returned for all array of a given type.  Elsewhere we
    7569              :                make sure we don't complete that type before copying
    7570              :                it, but here we want to make sure we don't ever
    7571              :                modify the shared type, so we gcc_assert (itype)
    7572              :                below.  */
    7573              :               {
    7574      1139237 :                 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
    7575      1139237 :                 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
    7576            0 :                   type = c_build_qualified_type (type,
    7577              :                                                  ENCODE_QUAL_ADDR_SPACE (as));
    7578      1139237 :                 if (array_parm_vla_unspec_p)
    7579          150 :                   type = c_build_array_type_unspecified (type);
    7580              :                 else
    7581      1139087 :                   type = c_build_array_type (type, itype);
    7582              :               }
    7583              : 
    7584      1139295 :             if (array_parm_vla_unspec_p)
    7585              :               {
    7586              :                 /* C99 6.7.5.2p4 */
    7587          150 :                 if (decl_context == TYPENAME)
    7588            6 :                   warning (0, "%<[*]%> not in a declaration");
    7589          144 :                 else if (decl_context != GENERIC_ASSOC
    7590          144 :                          && decl_context != PARM
    7591            7 :                          && decl_context != FIELD)
    7592              :                   {
    7593            4 :                     error ("%<[*]%> not allowed in other than function prototype scope "
    7594              :                            "or generic association");
    7595            4 :                     type = error_mark_node;
    7596              :                   }
    7597              :                 size_varies = true;
    7598              :               }
    7599              : 
    7600      1139295 :             if (type != error_mark_node)
    7601              :               {
    7602              :                 /* The GCC extension for zero-length arrays differs from
    7603              :                    ISO flexible array members in that sizeof yields
    7604              :                    zero.  */
    7605      1139233 :                 if (size && integer_zerop (size))
    7606              :                   {
    7607         2596 :                     gcc_assert (itype);
    7608         2596 :                     type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7609         2596 :                     TYPE_SIZE (type) = bitsize_zero_node;
    7610         2596 :                     TYPE_SIZE_UNIT (type) = size_zero_node;
    7611         2596 :                     SET_TYPE_STRUCTURAL_EQUALITY (type);
    7612              :                   }
    7613              : 
    7614      1139233 :                 if (!valid_array_size_p (loc, type, name))
    7615           33 :                   type = error_mark_node;
    7616              :               }
    7617              : 
    7618      1139295 :             if (decl_context != PARM
    7619       819429 :                 && (array_ptr_quals != TYPE_UNQUALIFIED
    7620       819429 :                     || array_ptr_attrs != NULL_TREE
    7621       819428 :                     || array_parm_static))
    7622              :               {
    7623            2 :                 error_at (loc, "static or type qualifiers in non-parameter "
    7624              :                           "array declarator");
    7625            2 :                 array_ptr_quals = TYPE_UNQUALIFIED;
    7626            2 :                 array_ptr_attrs = NULL_TREE;
    7627            2 :                 array_parm_static = false;
    7628              :               }
    7629      1139295 :             orig_qual_indirect++;
    7630      1139295 :             break;
    7631              :           }
    7632     50974898 :         case cdk_function:
    7633     50974898 :           {
    7634              :             /* Say it's a definition only for the declarator closest
    7635              :                to the identifier, apart possibly from some
    7636              :                attributes.  */
    7637     50974898 :             bool really_funcdef = false;
    7638     50974898 :             tree arg_types;
    7639     50974898 :             orig_qual_type = NULL_TREE;
    7640     50974898 :             if (funcdef_flag)
    7641              :               {
    7642     36326459 :                 const struct c_declarator *t = declarator->declarator;
    7643     36326477 :                 while (t->kind == cdk_attrs)
    7644           18 :                   t = t->declarator;
    7645     36326459 :                 really_funcdef = (t->kind == cdk_id);
    7646              :               }
    7647              : 
    7648              :             /* Declaring a function type.  Make sure we have a valid
    7649              :                type for the function to return.  */
    7650     50974898 :             if (type == error_mark_node)
    7651            0 :               continue;
    7652              : 
    7653     50974898 :             size_varies = false;
    7654              : 
    7655              :             /* Warn about some types functions can't return.  */
    7656     50974898 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7657              :               {
    7658            0 :                 if (name)
    7659            0 :                   error_at (loc, "%qE declared as function returning a "
    7660              :                                  "function", name);
    7661              :                 else
    7662            0 :                   error_at (loc, "type name declared as function "
    7663              :                             "returning a function");
    7664            0 :                 type = integer_type_node;
    7665              :               }
    7666     50974898 :             if (TREE_CODE (type) == ARRAY_TYPE)
    7667              :               {
    7668            0 :                 if (name)
    7669            0 :                   error_at (loc, "%qE declared as function returning an array",
    7670              :                             name);
    7671              :                 else
    7672            0 :                   error_at (loc, "type name declared as function returning "
    7673              :                             "an array");
    7674            0 :                 type = integer_type_node;
    7675              :               }
    7676              : 
    7677              :             /* Construct the function type and go to the next
    7678              :                inner layer of declarator.  */
    7679     50974898 :             arg_info = declarator->u.arg_info;
    7680     50974898 :             arg_types = grokparms (arg_info, really_funcdef);
    7681              : 
    7682              :             /* Type qualifiers before the return type of the function
    7683              :                qualify the return type, not the function type.  */
    7684     50974898 :             if (type_quals)
    7685              :               {
    7686          235 :                 const enum c_declspec_word ignored_quals_list[] =
    7687              :                   {
    7688              :                     cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
    7689              :                     cdw_atomic, cdw_number_of_elements
    7690              :                   };
    7691          235 :                 location_t specs_loc
    7692          235 :                   = smallest_type_quals_location (declspecs->locations,
    7693              :                                                   ignored_quals_list);
    7694          235 :                 if (specs_loc == UNKNOWN_LOCATION)
    7695          139 :                   specs_loc = declspecs->locations[cdw_typedef];
    7696          139 :                 if (specs_loc == UNKNOWN_LOCATION)
    7697           15 :                   specs_loc = loc;
    7698              : 
    7699              :                 /* Type qualifiers on a function return type are
    7700              :                    normally permitted by the standard but have no
    7701              :                    effect, so give a warning at -Wreturn-type.
    7702              :                    Qualifiers on a void return type are banned on
    7703              :                    function definitions in ISO C; GCC used to used
    7704              :                    them for noreturn functions.  The resolution of C11
    7705              :                    DR#423 means qualifiers (other than _Atomic) are
    7706              :                    actually removed from the return type when
    7707              :                    determining the function type.  For C23, _Atomic is
    7708              :                    removed as well.  */
    7709          235 :                 int quals_used = type_quals;
    7710          235 :                 if (flag_isoc23)
    7711              :                   quals_used = 0;
    7712           65 :                 else if (flag_isoc11)
    7713           31 :                   quals_used &= TYPE_QUAL_ATOMIC;
    7714           65 :                 if (quals_used && VOID_TYPE_P (type) && really_funcdef)
    7715            5 :                   pedwarn (specs_loc, 0,
    7716              :                            "function definition has qualified void "
    7717              :                            "return type");
    7718              :                 else
    7719          230 :                   warning_at (specs_loc, OPT_Wignored_qualifiers,
    7720              :                               "type qualifiers ignored on function "
    7721              :                               "return type");
    7722              : 
    7723              :                 /* Ensure an error for restrict on invalid types; the
    7724              :                    DR#423 resolution is not entirely clear about
    7725              :                    this.  */
    7726          235 :                 if (flag_isoc11
    7727          201 :                     && (type_quals & TYPE_QUAL_RESTRICT)
    7728          241 :                     && (!POINTER_TYPE_P (type)
    7729            4 :                         || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
    7730            4 :                   error_at (loc, "invalid use of %<restrict%>");
    7731          235 :                 type = c_build_qualified_type (type, quals_used);
    7732              :               }
    7733     50974898 :             type_quals = TYPE_UNQUALIFIED;
    7734              : 
    7735    101949796 :             type = c_build_function_type (type, arg_types,
    7736     50974898 :                                           arg_info->no_named_args_stdarg_p);
    7737     50974898 :             declarator = declarator->declarator;
    7738              : 
    7739              :             /* Set the TYPE_CONTEXTs for each tagged type which is local to
    7740              :                the formal parameter list of this FUNCTION_TYPE to point to
    7741              :                the FUNCTION_TYPE node itself.  */
    7742     50974898 :             {
    7743     50974898 :               c_arg_tag *tag;
    7744     50974898 :               unsigned ix;
    7745              : 
    7746    436646012 :               FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
    7747          142 :                 TYPE_CONTEXT (tag->type) = type;
    7748              :             }
    7749              :             break;
    7750              :           }
    7751     18334499 :         case cdk_pointer:
    7752     18334499 :           {
    7753              :             /* Merge any constancy or volatility into the target type
    7754              :                for the pointer.  */
    7755     18334499 :             if ((type_quals & TYPE_QUAL_ATOMIC)
    7756         1988 :                 && TREE_CODE (type) == FUNCTION_TYPE)
    7757              :               {
    7758            2 :                 error_at (loc,
    7759              :                           "%<_Atomic%>-qualified function type");
    7760            2 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    7761              :               }
    7762     18334497 :             else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7763         1708 :                      && type_quals)
    7764            0 :               pedwarn (loc, OPT_Wpedantic,
    7765              :                        "ISO C forbids qualified function types");
    7766     18332791 :             if (type_quals)
    7767      6040867 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7768              :                                              orig_qual_indirect);
    7769     18334499 :             orig_qual_type = NULL_TREE;
    7770     18334499 :             size_varies = false;
    7771              : 
    7772              :             /* When the pointed-to type involves components of variable size,
    7773              :                care must be taken to ensure that the size evaluation code is
    7774              :                emitted early enough to dominate all the possible later uses
    7775              :                and late enough for the variables on which it depends to have
    7776              :                been assigned.
    7777              : 
    7778              :                This is expected to happen automatically when the pointed-to
    7779              :                type has a name/declaration of it's own, but special attention
    7780              :                is required if the type is anonymous. */
    7781     18334499 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    7782              :               {
    7783         5949 :                 bool bind_p = decl_context == TYPENAME
    7784              :                               || decl_context == FIELD
    7785         5949 :                               || decl_context == PARM;
    7786        11391 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    7787              :               }
    7788              : 
    7789     18334499 :             type = c_build_pointer_type (type);
    7790              : 
    7791              :             /* Process type qualifiers (such as const or volatile)
    7792              :                that were given inside the `*'.  */
    7793     18334499 :             type_quals = declarator->u.pointer_quals;
    7794              : 
    7795     18334499 :             declarator = declarator->declarator;
    7796     18334499 :             break;
    7797              :           }
    7798            0 :         default:
    7799            0 :           gcc_unreachable ();
    7800              :         }
    7801              :     }
    7802    315215176 :   *decl_attrs = chainon (returned_attrs, *decl_attrs);
    7803    315215176 :   *decl_attrs = chainon (decl_id_attrs, *decl_attrs);
    7804              : 
    7805              :   /* Now TYPE has the actual type, apart from any qualifiers in
    7806              :      TYPE_QUALS.  */
    7807              : 
    7808              :   /* Warn about address space used for things other than static memory or
    7809              :      pointers.  */
    7810    315215176 :   address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
    7811    315215176 :   if (!ADDR_SPACE_GENERIC_P (address_space))
    7812              :     {
    7813           10 :       if (decl_context == NORMAL)
    7814              :         {
    7815           10 :           switch (storage_class)
    7816              :             {
    7817            0 :             case csc_auto:
    7818            0 :               error ("%qs combined with %<auto%> qualifier for %qE",
    7819              :                      c_addr_space_name (address_space), name);
    7820            0 :               break;
    7821            0 :             case csc_register:
    7822            0 :               error ("%qs combined with %<register%> qualifier for %qE",
    7823              :                      c_addr_space_name (address_space), name);
    7824            0 :               break;
    7825            6 :             case csc_none:
    7826            6 :               if (current_function_scope)
    7827              :                 {
    7828            0 :                   error ("%qs specified for auto variable %qE",
    7829              :                          c_addr_space_name (address_space), name);
    7830            0 :                   break;
    7831              :                 }
    7832              :               break;
    7833              :             case csc_static:
    7834              :             case csc_extern:
    7835              :             case csc_typedef:
    7836              :               break;
    7837            0 :             default:
    7838            0 :               gcc_unreachable ();
    7839              :             }
    7840              :         }
    7841            0 :       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
    7842              :         {
    7843            0 :           if (name)
    7844            0 :             error ("%qs specified for parameter %qE",
    7845              :                    c_addr_space_name (address_space), name);
    7846              :           else
    7847            0 :             error ("%qs specified for unnamed parameter",
    7848              :                    c_addr_space_name (address_space));
    7849              :         }
    7850            0 :       else if (decl_context == FIELD)
    7851              :         {
    7852            0 :           if (name)
    7853            0 :             error ("%qs specified for structure field %qE",
    7854              :                    c_addr_space_name (address_space), name);
    7855              :           else
    7856            0 :             error ("%qs specified for structure field",
    7857              :                    c_addr_space_name (address_space));
    7858              :         }
    7859              :     }
    7860              : 
    7861              :   /* Check the type and width of a bit-field.  */
    7862    315215176 :   if (bitfield)
    7863              :     {
    7864        52739 :       check_bitfield_type_and_width (loc, &type, width, name);
    7865              :       /* C11 makes it implementation-defined (6.7.2.1#5) whether
    7866              :          atomic types are permitted for bit-fields; we have no code to
    7867              :          make bit-field accesses atomic, so disallow them.  */
    7868        52739 :       if (type_quals & TYPE_QUAL_ATOMIC)
    7869              :         {
    7870            2 :           if (name)
    7871            1 :             error_at (loc, "bit-field %qE has atomic type", name);
    7872              :           else
    7873            1 :             error_at (loc, "bit-field has atomic type");
    7874            2 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7875              :         }
    7876              :     }
    7877              : 
    7878              :   /* Reject invalid uses of _Alignas.  */
    7879    315215176 :   if (declspecs->alignas_p)
    7880              :     {
    7881          190 :       if (storage_class == csc_typedef)
    7882            1 :         error_at (loc, "alignment specified for typedef %qE", name);
    7883          189 :       else if (storage_class == csc_register)
    7884            1 :         error_at (loc, "alignment specified for %<register%> object %qE",
    7885              :                   name);
    7886          188 :       else if (decl_context == PARM)
    7887              :         {
    7888            2 :           if (name)
    7889            1 :             error_at (loc, "alignment specified for parameter %qE", name);
    7890              :           else
    7891            1 :             error_at (loc, "alignment specified for unnamed parameter");
    7892              :         }
    7893          186 :       else if (bitfield)
    7894              :         {
    7895            0 :           if (name)
    7896            0 :             error_at (loc, "alignment specified for bit-field %qE", name);
    7897              :           else
    7898            0 :             error_at (loc, "alignment specified for unnamed bit-field");
    7899              :         }
    7900          186 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
    7901            1 :         error_at (loc, "alignment specified for function %qE", name);
    7902          185 :       else if (declspecs->align_log != -1 && TYPE_P (type))
    7903              :         {
    7904          158 :           alignas_align = 1U << declspecs->align_log;
    7905          158 :           if (alignas_align < min_align_of_type (type))
    7906              :             {
    7907           26 :               if (name)
    7908           25 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7909              :                           "alignment of %qE", name);
    7910              :               else
    7911            1 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7912              :                           "alignment of unnamed field");
    7913              :               alignas_align = 0;
    7914              :             }
    7915              :         }
    7916              :     }
    7917              : 
    7918              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
    7919              : 
    7920    315215176 :   if (storage_class == csc_typedef)
    7921              :     {
    7922      4321649 :       tree decl;
    7923      4321649 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7924        12630 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7925              :         {
    7926            0 :           error_at (loc,
    7927              :                     "%<_Atomic%>-qualified function type");
    7928            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7929              :         }
    7930      4321649 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7931          537 :                && type_quals)
    7932            0 :         pedwarn (loc, OPT_Wpedantic,
    7933              :                  "ISO C forbids qualified function types");
    7934      4321112 :       if (type_quals)
    7935        31675 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7936              :                                        orig_qual_indirect);
    7937      8643298 :       decl = build_decl (declarator->id_loc,
    7938      4321649 :                          TYPE_DECL, declarator->u.id.id, type);
    7939      4321649 :       if (declspecs->explicit_signed_p)
    7940       351639 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
    7941      4321649 :       if (declspecs->inline_p)
    7942            4 :         pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
    7943      4321649 :       if (declspecs->noreturn_p)
    7944            1 :         pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
    7945              : 
    7946      4321649 :       if (warn_cxx_compat && declarator->u.id.id != NULL_TREE)
    7947              :         {
    7948         1828 :           struct c_binding *b = I_TAG_BINDING (declarator->u.id.id);
    7949              : 
    7950         1828 :           if (b != NULL
    7951           40 :               && b->decl != NULL_TREE
    7952           40 :               && (B_IN_CURRENT_SCOPE (b)
    7953            4 :                   || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    7954         1864 :               && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
    7955              :             {
    7956            7 :               auto_diagnostic_group d;
    7957            8 :               if (warning_at (declarator->id_loc, OPT_Wc___compat,
    7958              :                               "using %qD as both a typedef and a tag is "
    7959              :                               "invalid in C++", decl)
    7960            7 :                   && b->locus != UNKNOWN_LOCATION)
    7961            6 :                 inform (b->locus, "originally defined here");
    7962            7 :             }
    7963              :         }
    7964              : 
    7965      4321649 :       return decl;
    7966              :     }
    7967              : 
    7968              :   /* If this is a type name (such as, in a cast or sizeof),
    7969              :      compute the type and return it now.  */
    7970              : 
    7971    310893527 :   if (decl_context == TYPENAME || decl_context == GENERIC_ASSOC)
    7972              :     {
    7973              :       /* Note that the grammar rejects storage classes in typenames
    7974              :          and fields.  */
    7975    121578232 :       gcc_assert (storage_class == csc_none && !threadp
    7976              :                   && !declspecs->inline_p && !declspecs->noreturn_p);
    7977    121578232 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7978          257 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7979              :         {
    7980            0 :           error_at (loc,
    7981              :                     "%<_Atomic%>-qualified function type");
    7982            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7983              :         }
    7984    121578232 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7985           22 :                && type_quals)
    7986            0 :         pedwarn (loc, OPT_Wpedantic,
    7987              :                  "ISO C forbids const or volatile function types");
    7988    121578210 :       if (type_quals)
    7989          857 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7990              :                                        orig_qual_indirect);
    7991    121578232 :       return type;
    7992              :     }
    7993              : 
    7994       364107 :   if (pedantic && decl_context == FIELD
    7995    189337893 :       && c_type_variably_modified_p (type))
    7996              :     {
    7997              :       /* C99 6.7.2.1p8 */
    7998            7 :       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
    7999              :                "have a variably modified type");
    8000              :     }
    8001              : 
    8002              :   /* Aside from typedefs and type names (handle above),
    8003              :      `void' at top level (not within pointer)
    8004              :      is allowed only in public variables.
    8005              :      We don't complain about parms either, but that is because
    8006              :      a better error message can be made later.  */
    8007              : 
    8008    189315295 :   if (VOID_TYPE_P (type) && decl_context != PARM
    8009           64 :       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
    8010              :             && (storage_class == csc_extern
    8011           27 :                 || (current_scope == file_scope
    8012           18 :                     && !(storage_class == csc_static
    8013              :                          || storage_class == csc_register)))))
    8014              :     {
    8015           15 :       error_at (loc, "variable or field %qE declared void", name);
    8016           15 :       type = integer_type_node;
    8017              :     }
    8018              : 
    8019              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
    8020              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
    8021              : 
    8022    188340480 :   {
    8023    188340480 :     tree decl;
    8024              : 
    8025    188340480 :     if (decl_context == PARM)
    8026              :       {
    8027    124694750 :         tree promoted_type;
    8028    124694750 :         bool array_parameter_p = false;
    8029              : 
    8030              :         /* A parameter declared as an array of T is really a pointer to T.
    8031              :            One declared as a function is really a pointer to a function.  */
    8032              : 
    8033    124694750 :         if (TREE_CODE (type) == ARRAY_TYPE)
    8034              :           {
    8035       438803 :             if (!size_error)
    8036       438789 :               *decl_attrs = build_arg_spec_attribute (type, array_parm_static,
    8037              :                                                       *decl_attrs);
    8038              : 
    8039              :             /* Transfer const-ness of array into that of type pointed to.  */
    8040       438803 :             type = TREE_TYPE (type);
    8041       438803 :             if (orig_qual_type != NULL_TREE)
    8042              :               {
    8043            7 :                 if (orig_qual_indirect == 0)
    8044            5 :                   orig_qual_type = TREE_TYPE (orig_qual_type);
    8045              :                 else
    8046            2 :                   orig_qual_indirect--;
    8047              :               }
    8048       438803 :             if (type_quals)
    8049        48197 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8050              :                                              orig_qual_indirect);
    8051              : 
    8052              :             /* The pointed-to type may need a decl expr (see above).  */
    8053       438803 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    8054              :               {
    8055          373 :                 bool bind_p = decl_context == TYPENAME
    8056              :                               || decl_context == FIELD
    8057              :                               || decl_context == PARM;
    8058          373 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    8059              :               }
    8060              : 
    8061       438803 :             type = c_build_pointer_type (type);
    8062       438803 :             type_quals = array_ptr_quals;
    8063       438803 :             if (type_quals)
    8064          965 :               type = c_build_qualified_type (type, type_quals);
    8065              : 
    8066              :             /* We don't yet implement attributes in this context.  */
    8067       438803 :             if (array_ptr_attrs != NULL_TREE)
    8068            0 :               warning_at (loc, OPT_Wattributes,
    8069              :                           "attributes in parameter array declarator ignored");
    8070              : 
    8071              :             size_varies = false;
    8072              :             array_parameter_p = true;
    8073              :           }
    8074    124255947 :         else if (TREE_CODE (type) == FUNCTION_TYPE)
    8075              :           {
    8076          301 :             if (type_quals & TYPE_QUAL_ATOMIC)
    8077              :               {
    8078            1 :                 error_at (loc,
    8079              :                           "%<_Atomic%>-qualified function type");
    8080            1 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    8081              :               }
    8082          300 :             else if (type_quals)
    8083            0 :               pedwarn (loc, OPT_Wpedantic,
    8084              :                        "ISO C forbids qualified function types");
    8085            1 :             if (type_quals)
    8086            0 :               type = c_build_qualified_type (type, type_quals);
    8087          301 :             type = c_build_pointer_type (type);
    8088          301 :             type_quals = TYPE_UNQUALIFIED;
    8089              :           }
    8090    124255646 :         else if (type_quals)
    8091      9959557 :           type = c_build_qualified_type (type, type_quals);
    8092              : 
    8093    249389500 :         decl = build_decl (declarator->id_loc,
    8094    124694750 :                            PARM_DECL, declarator->u.id.id, type);
    8095    124694750 :         if (size_varies)
    8096           42 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8097    124694750 :         C_ARRAY_PARAMETER (decl) = array_parameter_p;
    8098              : 
    8099              :         /* Compute the type actually passed in the parmlist,
    8100              :            for the case where there is no prototype.
    8101              :            (For example, shorts and chars are passed as ints.)
    8102              :            When there is a prototype, this is overridden later.  */
    8103              : 
    8104    124694750 :         if (type == error_mark_node)
    8105              :           promoted_type = type;
    8106              :         else
    8107    124694666 :           promoted_type = c_type_promotes_to (type);
    8108              : 
    8109    124694750 :         DECL_ARG_TYPE (decl) = promoted_type;
    8110    124694750 :         if (declspecs->inline_p)
    8111            4 :           pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
    8112    124694750 :         if (declspecs->noreturn_p)
    8113            1 :           pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
    8114              :       }
    8115     64620545 :     else if (decl_context == FIELD)
    8116              :       {
    8117              :         /* Note that the grammar rejects storage classes in typenames
    8118              :            and fields.  */
    8119      4309917 :         gcc_assert (storage_class == csc_none && !threadp
    8120              :                     && !declspecs->inline_p && !declspecs->noreturn_p);
    8121              : 
    8122              :         /* Structure field.  It may not be a function.  */
    8123              : 
    8124      4309917 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8125              :           {
    8126            0 :             error_at (loc, "field %qE declared as a function", name);
    8127            0 :             type = c_build_pointer_type (type);
    8128              :           }
    8129      4309917 :         else if (TREE_CODE (type) != ERROR_MARK
    8130      4309917 :                  && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
    8131              :           {
    8132           24 :             if (name)
    8133           17 :               error_at (loc, "field %qE has incomplete type", name);
    8134              :             else
    8135            7 :               error_at (loc, "unnamed field has incomplete type");
    8136           24 :             type = error_mark_node;
    8137              :           }
    8138      4309893 :         else if (TREE_CODE (type) == ARRAY_TYPE
    8139      4309893 :                  && TYPE_DOMAIN (type) == NULL_TREE)
    8140              :           {
    8141              :             /* We have a flexible array member through a typedef.
    8142              :                Set suitable range.  Whether this is a correct position
    8143              :                for a flexible array member will be determined elsewhere.  */
    8144           14 :             if (!in_system_header_at (input_location))
    8145           14 :               pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    8146              :                            "support flexible array members");
    8147           14 :             type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    8148           14 :             TYPE_DOMAIN (type) = build_range_type (sizetype, size_zero_node,
    8149              :                                                    NULL_TREE);
    8150           14 :             if (orig_qual_indirect == 0)
    8151      4309917 :               orig_qual_type = NULL_TREE;
    8152              :           }
    8153      4309917 :         if (type != error_mark_node
    8154      4309917 :             && !verify_type_context (loc, TCTX_FIELD, type))
    8155            0 :           type = error_mark_node;
    8156              : 
    8157      4309917 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8158              :                                        orig_qual_indirect);
    8159      8619834 :         decl = build_decl (declarator->id_loc,
    8160      4309917 :                            FIELD_DECL, declarator->u.id.id, type);
    8161      4309917 :         DECL_NONADDRESSABLE_P (decl) = bitfield;
    8162      4309917 :         if (bitfield && !declarator->u.id.id)
    8163         9763 :           DECL_PADDING_P (decl) = 1;
    8164              : 
    8165      4309917 :         if (size_varies)
    8166          669 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8167              :       }
    8168     60310628 :     else if (TREE_CODE (type) == FUNCTION_TYPE)
    8169              :       {
    8170     51389507 :         if (storage_class == csc_register || threadp || constexprp)
    8171              :           {
    8172           12 :             error_at (loc, "invalid storage class for function %qE", name);
    8173              :           }
    8174     51389495 :         else if (current_scope != file_scope)
    8175              :           {
    8176              :             /* Function declaration not at file scope.  Storage
    8177              :                classes other than `extern' are not allowed, C99
    8178              :                6.7.1p5, and `extern' makes no difference.  However,
    8179              :                GCC allows 'auto', perhaps with 'inline', to support
    8180              :                nested functions.  */
    8181        10563 :             if (storage_class == csc_auto)
    8182           66 :                 pedwarn (loc, OPT_Wpedantic,
    8183              :                          "invalid storage class for function %qE", name);
    8184        10497 :             else if (storage_class == csc_static)
    8185              :               {
    8186           20 :                 error_at (loc, "invalid storage class for function %qE", name);
    8187           20 :                 if (funcdef_flag)
    8188            8 :                   storage_class = declspecs->storage_class = csc_none;
    8189              :                 else
    8190              :                   return NULL_TREE;
    8191              :               }
    8192              :           }
    8193              : 
    8194    102778990 :         decl = build_decl (declarator->id_loc,
    8195     51389495 :                            FUNCTION_DECL, declarator->u.id.id, type);
    8196     51389495 :         decl = build_decl_attribute_variant (decl, decl_attr);
    8197              : 
    8198     51389495 :         if (type_quals & TYPE_QUAL_ATOMIC)
    8199              :           {
    8200            2 :             error_at (loc,
    8201              :                       "%<_Atomic%>-qualified function type");
    8202            2 :             type_quals &= ~TYPE_QUAL_ATOMIC;
    8203              :           }
    8204     51389493 :         else if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
    8205            9 :           pedwarn (loc, OPT_Wpedantic,
    8206              :                    "ISO C forbids qualified function types");
    8207              : 
    8208              :         /* Every function declaration is an external reference
    8209              :            (DECL_EXTERNAL) except for those which are not at file
    8210              :            scope and are explicitly declared "auto".  This is
    8211              :            forbidden by standard C (C99 6.7.1p5) and is interpreted by
    8212              :            GCC to signify a forward declaration of a nested function.  */
    8213     51389495 :         if (storage_class == csc_auto && current_scope != file_scope)
    8214           66 :           DECL_EXTERNAL (decl) = 0;
    8215              :         /* In C99, a function which is declared 'inline' with 'extern'
    8216              :            is not an external reference (which is confusing).  It
    8217              :            means that the later definition of the function must be output
    8218              :            in this file, C99 6.7.4p6.  In GNU C89, a function declared
    8219              :            'extern inline' is an external reference.  */
    8220     51389429 :         else if (declspecs->inline_p && storage_class != csc_static)
    8221     35475470 :           DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
    8222     35475470 :                                   == flag_gnu89_inline);
    8223              :         else
    8224     15913959 :           DECL_EXTERNAL (decl) = !initialized;
    8225              : 
    8226              :         /* Record absence of global scope for `static' or `auto'.  */
    8227     51389495 :         TREE_PUBLIC (decl)
    8228     51389495 :           = !(storage_class == csc_static || storage_class == csc_auto);
    8229              : 
    8230              :         /* For a function definition, record the argument information
    8231              :            block where store_parm_decls will look for it.  */
    8232     51389495 :         if (funcdef_flag)
    8233     36326429 :           current_function_arg_info = arg_info;
    8234              : 
    8235     51389495 :         if (declspecs->default_int_p)
    8236         9220 :           C_FUNCTION_IMPLICIT_INT (decl) = 1;
    8237              : 
    8238              :         /* Record presence of `inline' and `_Noreturn', if it is
    8239              :            reasonable.  */
    8240     51389495 :         if (flag_hosted && MAIN_NAME_P (declarator->u.id.id))
    8241              :           {
    8242        47783 :             if (declspecs->inline_p)
    8243            5 :               pedwarn (loc, 0, "cannot inline function %<main%>");
    8244        47783 :             if (declspecs->noreturn_p)
    8245            1 :               pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
    8246              :           }
    8247              :         else
    8248              :           {
    8249     51341712 :             if (declspecs->inline_p)
    8250              :               /* Record that the function is declared `inline'.  */
    8251     35635902 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8252     51341712 :             if (declspecs->noreturn_p)
    8253              :               {
    8254        23307 :                 if (flag_isoc99)
    8255        23304 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8256              :                                "ISO C99 does not support %<_Noreturn%>");
    8257              :                 else
    8258            3 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8259              :                                "ISO C90 does not support %<_Noreturn%>");
    8260        23307 :                 TREE_THIS_VOLATILE (decl) = 1;
    8261              :               }
    8262              :           }
    8263              : 
    8264              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8265              :            behavior) to create an 'extern' declaration for a
    8266              :            function if there is a global declaration that is
    8267              :            'static' and the global declaration is not visible.
    8268              :            (If the static declaration _is_ currently visible,
    8269              :            the 'extern' declaration is taken to refer to that decl.) */
    8270     51389495 :         if (!initialized
    8271     15063057 :             && TREE_PUBLIC (decl)
    8272     15055182 :             && current_scope != file_scope)
    8273              :           {
    8274         8890 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8275         8890 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8276              : 
    8277         8890 :             if (global_decl
    8278         8890 :                 && global_decl != visible_decl
    8279         1713 :                 && VAR_OR_FUNCTION_DECL_P (global_decl)
    8280         1713 :                 && !TREE_PUBLIC (global_decl))
    8281            2 :               error_at (loc, "function previously declared %<static%> "
    8282              :                         "redeclared %<extern%>");
    8283              :           }
    8284              :       }
    8285              :     else
    8286              :       {
    8287              :         /* It's a variable.  */
    8288              :         /* An uninitialized decl with `extern' is a reference.  */
    8289      8921121 :         int extern_ref = !initialized && storage_class == csc_extern;
    8290              : 
    8291      8921121 :         if (constexprp)
    8292              :           {
    8293              :             /* The type of a constexpr variable must not be variably
    8294              :                modified, volatile, atomic or restrict qualified or
    8295              :                have a member with such a qualifier.  const
    8296              :                qualification is implicitly added, and, at file scope,
    8297              :                has internal linkage.  */
    8298          356 :             if (c_type_variably_modified_p (type))
    8299            1 :               error_at (loc, "%<constexpr%> object has variably modified "
    8300              :                         "type");
    8301          356 :             if (type_quals
    8302          356 :                 & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    8303            9 :               error_at (loc, "invalid qualifiers for %<constexpr%> object");
    8304              :             else
    8305              :               {
    8306          347 :                 tree type_no_array = strip_array_types (type);
    8307          347 :                 if (RECORD_OR_UNION_TYPE_P (type_no_array)
    8308          347 :                     && C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array))
    8309            8 :                   error_at (loc, "invalid qualifiers for field of "
    8310              :                             "%<constexpr%> object");
    8311              :               }
    8312          356 :             type_quals |= TYPE_QUAL_CONST;
    8313          356 :             if (current_scope == file_scope)
    8314          294 :               storage_class = csc_static;
    8315              :           }
    8316              : 
    8317      8921121 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8318              :                                        orig_qual_indirect);
    8319              : 
    8320              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8321              :            behavior) to create an 'extern' declaration for a
    8322              :            variable if there is a global declaration that is
    8323              :            'static' and the global declaration is not visible.
    8324              :            (If the static declaration _is_ currently visible,
    8325              :            the 'extern' declaration is taken to refer to that decl.) */
    8326      8921121 :         if (extern_ref && current_scope != file_scope)
    8327              :           {
    8328         1571 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8329         1571 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8330              : 
    8331         1571 :             if (global_decl
    8332         1571 :                 && global_decl != visible_decl
    8333          282 :                 && VAR_P (global_decl)
    8334          282 :                 && !TREE_PUBLIC (global_decl))
    8335            8 :               error_at (loc, "variable previously declared %<static%> "
    8336              :                         "redeclared %<extern%>");
    8337              :           }
    8338              : 
    8339     17842242 :         decl = build_decl (declarator->id_loc,
    8340      8921121 :                            VAR_DECL, declarator->u.id.id, type);
    8341      8921121 :         if (size_varies)
    8342         7444 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8343      8921121 :         if (constexprp)
    8344          356 :           C_DECL_DECLARED_CONSTEXPR (decl) = 1;
    8345              : 
    8346      8921121 :         if (declspecs->inline_p)
    8347            4 :           pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
    8348      8921121 :         if (declspecs->noreturn_p)
    8349            1 :           pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
    8350              : 
    8351              :         /* At file scope, an initialized extern declaration may follow
    8352              :            a static declaration.  In that case, DECL_EXTERNAL will be
    8353              :            reset later in start_decl.  */
    8354      8921121 :         DECL_EXTERNAL (decl) = (storage_class == csc_extern);
    8355              : 
    8356              :         /* At file scope, the presence of a `static' or `register' storage
    8357              :            class specifier, or the absence of all storage class specifiers
    8358              :            makes this declaration a definition (perhaps tentative).  Also,
    8359              :            the absence of `static' makes it public.  */
    8360      8921121 :         if (current_scope == file_scope)
    8361              :           {
    8362      1149419 :             TREE_PUBLIC (decl) = storage_class != csc_static;
    8363      1149419 :             TREE_STATIC (decl) = !extern_ref;
    8364              :           }
    8365              :         /* Not at file scope, only `static' makes a static definition.  */
    8366              :         else
    8367              :           {
    8368      7771702 :             TREE_STATIC (decl) = (storage_class == csc_static);
    8369      7771702 :             TREE_PUBLIC (decl) = extern_ref;
    8370              :           }
    8371              : 
    8372              :         // NB: Set a tentative TLS model to avoid tls_model attribute
    8373              :         // warnings due to lack of thread storage duration.  It will
    8374              :         // be updated by c_decl_attributes later.
    8375      8921121 :         if (threadp)
    8376         2818 :           set_decl_tls_model (decl, TLS_MODEL_REAL);
    8377              :       }
    8378              : 
    8379    189315283 :     if ((storage_class == csc_extern
    8380    138926014 :          || (storage_class == csc_none
    8381    138463803 :              && TREE_CODE (type) == FUNCTION_TYPE
    8382       808164 :              && !funcdef_flag))
    8383    189623833 :         && c_type_variably_modified_p (type))
    8384              :       {
    8385              :         /* C99 6.7.5.2p2 */
    8386            6 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8387            4 :           error_at (loc, "non-nested function with variably modified type");
    8388              :         else
    8389            2 :           error_at (loc, "object with variably modified type must have "
    8390              :                     "no linkage");
    8391              :       }
    8392              : 
    8393              :     /* For nested functions disqualify ones taking VLAs by value
    8394              :        from inlining since the middle-end cannot deal with this.
    8395              :        ???  We should arrange for those to be passed by reference
    8396              :        with emitting the copy on the caller side in the frontend.  */
    8397    189315283 :     if (storage_class == csc_none
    8398    138463803 :         && TREE_CODE (type) == FUNCTION_TYPE)
    8399      4174812 :       for (tree al = TYPE_ARG_TYPES (type); al; al = TREE_CHAIN (al))
    8400              :         {
    8401      3366688 :           tree arg = TREE_VALUE (al);
    8402      3366688 :           if (arg != error_mark_node
    8403      3366688 :               && C_TYPE_VARIABLE_SIZE (arg))
    8404              :             {
    8405           40 :               DECL_UNINLINABLE (decl) = 1;
    8406           40 :               break;
    8407              :             }
    8408              :         }
    8409              : 
    8410              :     /* Record `register' declaration for warnings on &
    8411              :        and in case doing stupid register allocation.  */
    8412              : 
    8413    189315283 :     if (storage_class == csc_register
    8414         3609 :         && TREE_CODE (type) != FUNCTION_TYPE)
    8415              :       {
    8416         3603 :         C_DECL_REGISTER (decl) = 1;
    8417         3603 :         DECL_REGISTER (decl) = 1;
    8418              :       }
    8419              : 
    8420              :     /* Record constancy and volatility.  */
    8421    189315283 :     c_apply_type_quals_to_decl (type_quals, decl);
    8422              : 
    8423              :     /* Apply _Alignas specifiers.  */
    8424    189315283 :     if (alignas_align)
    8425              :       {
    8426          123 :         SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    8427          123 :         DECL_USER_ALIGN (decl) = 1;
    8428              :       }
    8429              : 
    8430              :     /* If a type has volatile components, it should be stored in memory.
    8431              :        Otherwise, the fact that those components are volatile
    8432              :        will be ignored, and would even crash the compiler.
    8433              :        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
    8434    189315283 :     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
    8435    189315283 :         && (VAR_P (decl) ||  TREE_CODE (decl) == PARM_DECL
    8436              :           || TREE_CODE (decl) == RESULT_DECL))
    8437              :       {
    8438              :         /* It is not an error for a structure with volatile fields to
    8439              :            be declared register, but reset DECL_REGISTER since it
    8440              :            cannot actually go in a register.  */
    8441          184 :         int was_reg = C_DECL_REGISTER (decl);
    8442          184 :         C_DECL_REGISTER (decl) = 0;
    8443          184 :         DECL_REGISTER (decl) = 0;
    8444          184 :         c_mark_addressable (decl);
    8445          184 :         C_DECL_REGISTER (decl) = was_reg;
    8446              :       }
    8447              : 
    8448              :   /* This is the earliest point at which we might know the assembler
    8449              :      name of a variable.  Thus, if it's known before this, die horribly.  */
    8450    189315283 :     gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
    8451              :                 || !DECL_ASSEMBLER_NAME_SET_P (decl));
    8452              : 
    8453    189315283 :     if (warn_cxx_compat
    8454        24623 :         && VAR_P (decl)
    8455         7548 :         && TREE_PUBLIC (decl)
    8456         2805 :         && TREE_STATIC (decl)
    8457         2356 :         && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    8458         2224 :             || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    8459    189315430 :         && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
    8460            4 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    8461              :                   "non-local variable %qD with anonymous type is "
    8462              :                   "questionable in C++", decl);
    8463              : 
    8464              :     return decl;
    8465              :   }
    8466              : }
    8467              : 
    8468              : /* Decode the parameter-list info for a function type or function definition.
    8469              :    The argument is the value returned by `get_parm_info' (or made in c-parse.c
    8470              :    if there is an identifier list instead of a parameter decl list).
    8471              :    These two functions are separate because when a function returns
    8472              :    or receives functions then each is called multiple times but the order
    8473              :    of calls is different.  The last call to `grokparms' is always the one
    8474              :    that contains the formal parameter names of a function definition.
    8475              : 
    8476              :    Return a list of arg types to use in the FUNCTION_TYPE for this function.
    8477              : 
    8478              :    FUNCDEF_FLAG is true for a function definition, false for
    8479              :    a mere declaration.  A nonempty identifier-list gets an error message
    8480              :    when FUNCDEF_FLAG is false.  */
    8481              : 
    8482              : static tree
    8483     50974898 : grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
    8484              : {
    8485     50974898 :   tree arg_types = arg_info->types;
    8486              : 
    8487     50974898 :   if (funcdef_flag && arg_info->had_vla_unspec)
    8488              :     {
    8489              :       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
    8490              :       /* C99 6.7.5.2p4 */
    8491            2 :       error ("%<[*]%> not allowed in other than function prototype scope");
    8492              :     }
    8493              : 
    8494       715610 :   if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc23
    8495     50977941 :       && !in_system_header_at (input_location))
    8496         3043 :     warning (OPT_Wstrict_prototypes,
    8497              :              "function declaration isn%'t a prototype");
    8498              : 
    8499     50974898 :   if (arg_types == error_mark_node)
    8500              :     /* Don't set TYPE_ARG_TYPES in this case.  */
    8501              :     return NULL_TREE;
    8502              : 
    8503    101177180 :   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
    8504              :     {
    8505         8684 :       if (!funcdef_flag)
    8506              :         {
    8507           13 :           permerror_opt (input_location,
    8508           13 :                          OPT_Wdeclaration_missing_parameter_type,
    8509              :                          "parameter names (without types) in "
    8510              :                          "function declaration");
    8511           13 :           arg_info->parms = NULL_TREE;
    8512              :         }
    8513              :       else
    8514         8671 :         arg_info->parms = arg_info->types;
    8515              : 
    8516         8684 :       arg_info->types = NULL_TREE;
    8517         8684 :       return NULL_TREE;
    8518              :     }
    8519              :   else
    8520              :     {
    8521     50966214 :       tree parm, type, typelt;
    8522     50966214 :       unsigned int parmno;
    8523              : 
    8524              :       /* In C23, convert () to (void).  */
    8525     50966214 :       if (flag_isoc23
    8526     41901333 :           && !arg_types
    8527       765116 :           && !arg_info->parms
    8528       765116 :           && !arg_info->no_named_args_stdarg_p)
    8529              :         {
    8530       764973 :           arg_types = arg_info->types = void_list_node;
    8531       764973 :           arg_info->c23_empty_parens = 1;
    8532              :         }
    8533              : 
    8534              :       /* If there is a parameter of incomplete type in a definition,
    8535              :          this is an error.  In a declaration this is valid, and a
    8536              :          struct or union type may be completed later, before any calls
    8537              :          or definition of the function.  In the case where the tag was
    8538              :          first declared within the parameter list, a warning has
    8539              :          already been given.  If a parameter has void type, then
    8540              :          this has already received an error (constraint violation in C2Y,
    8541              :          previously implicitly undefined behavior).  */
    8542              : 
    8543     50966214 :       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
    8544    174663315 :            parm;
    8545    123697101 :            parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
    8546              :         {
    8547    123697101 :           type = TREE_VALUE (typelt);
    8548    123697101 :           if (type == error_mark_node)
    8549           61 :             continue;
    8550              : 
    8551    123697040 :           if (!COMPLETE_TYPE_P (type))
    8552              :             {
    8553           40 :               if (funcdef_flag)
    8554              :                 {
    8555           13 :                   if (DECL_NAME (parm))
    8556           13 :                     error_at (input_location,
    8557              :                               "parameter %u (%q+D) has incomplete type",
    8558              :                               parmno, parm);
    8559              :                   else
    8560            0 :                     error_at (DECL_SOURCE_LOCATION (parm),
    8561              :                               "parameter %u has incomplete type",
    8562              :                               parmno);
    8563              : 
    8564           13 :                   TREE_VALUE (typelt) = error_mark_node;
    8565           13 :                   TREE_TYPE (parm) = error_mark_node;
    8566           13 :                   arg_types = NULL_TREE;
    8567              :                 }
    8568              :             }
    8569              : 
    8570    123697040 :           if (DECL_NAME (parm) && TREE_USED (parm))
    8571        17679 :             warn_if_shadowing (parm);
    8572              :         }
    8573              :       return arg_types;
    8574              :     }
    8575              : }
    8576              : 
    8577              : /* Allocate and initialize a c_arg_info structure from the parser's
    8578              :    obstack.  */
    8579              : 
    8580              : struct c_arg_info *
    8581     50974916 : build_arg_info (void)
    8582              : {
    8583     50974916 :   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
    8584     50974916 :   ret->parms = NULL_TREE;
    8585     50974916 :   ret->tags = NULL;
    8586     50974916 :   ret->types = NULL_TREE;
    8587     50974916 :   ret->others = NULL_TREE;
    8588     50974916 :   ret->pending_sizes = NULL;
    8589     50974916 :   ret->had_vla_unspec = 0;
    8590     50974916 :   ret->no_named_args_stdarg_p = 0;
    8591     50974916 :   ret->c23_empty_parens = 0;
    8592     50974916 :   return ret;
    8593              : }
    8594              : 
    8595              : /* Take apart the current scope and return a c_arg_info structure with
    8596              :    info on a parameter list just parsed.
    8597              : 
    8598              :    This structure is later fed to 'grokparms' and 'store_parm_decls'.
    8599              : 
    8600              :    ELLIPSIS being true means the argument list ended in '...' so don't
    8601              :    append a sentinel (void_list_node) to the end of the type-list.
    8602              : 
    8603              :    EXPR is NULL or an expression that needs to be evaluated for the
    8604              :    side effects of array size expressions in the parameters.  */
    8605              : 
    8606              : struct c_arg_info *
    8607     50193627 : get_parm_info (bool ellipsis, tree expr)
    8608              : {
    8609     50193627 :   struct c_binding *b = current_scope->bindings;
    8610     50193627 :   struct c_arg_info *arg_info = build_arg_info ();
    8611              : 
    8612     50193627 :   tree parms = NULL_TREE;
    8613     50193627 :   vec<c_arg_tag, va_gc> *tags = NULL;
    8614     50193627 :   tree types = NULL_TREE;
    8615     50193627 :   tree others = NULL_TREE;
    8616              : 
    8617     50193627 :   bool gave_void_only_once_err = false;
    8618              : 
    8619     50193627 :   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
    8620              : 
    8621              :   /* The bindings in this scope must not get put into a block.
    8622              :      We will take care of deleting the binding nodes.  */
    8623     50193627 :   current_scope->bindings = 0;
    8624              : 
    8625              :   /* This function is only called if there was *something* on the
    8626              :      parameter list.  */
    8627     50193627 :   gcc_assert (b);
    8628              : 
    8629              :   /* A parameter list consisting solely of 'void' indicates that the
    8630              :      function takes no arguments.  But if the 'void' is qualified
    8631              :      (by 'const' or 'volatile'), or has a storage class specifier
    8632              :      ('register'), then the behavior is undefined; issue an error.
    8633              :      Typedefs for 'void' are OK (see DR#157).  */
    8634     50193627 :   if (b->prev == 0                       /* one binding */
    8635     13478546 :       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
    8636     13478546 :       && !DECL_NAME (b->decl)               /* anonymous */
    8637     52053417 :       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
    8638              :     {
    8639       974701 :       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
    8640       974701 :           || C_DECL_REGISTER (b->decl))
    8641           96 :         error_at (b->locus, "%<void%> as only parameter may not be qualified");
    8642              : 
    8643              :       /* There cannot be an ellipsis.  */
    8644       974701 :       if (ellipsis)
    8645           17 :         error_at (b->locus, "%<void%> must be the only parameter");
    8646              : 
    8647       974701 :       arg_info->types = void_list_node;
    8648       974701 :       return arg_info;
    8649              :     }
    8650              : 
    8651     49218926 :   if (!ellipsis)
    8652     49004798 :     types = void_list_node;
    8653              : 
    8654              :   /* Break up the bindings list into parms, tags, types, and others;
    8655              :      apply sanity checks; purge the name-to-decl bindings.  */
    8656    172916490 :   while (b)
    8657              :     {
    8658    123697564 :       tree decl = b->decl;
    8659    123697564 :       tree type = TREE_TYPE (decl);
    8660    123697564 :       c_arg_tag tag;
    8661    123697564 :       const char *keyword;
    8662              : 
    8663    123697564 :       switch (TREE_CODE (decl))
    8664              :         {
    8665    123697224 :         case PARM_DECL:
    8666    123697224 :           if (b->id)
    8667              :             {
    8668    120042932 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8669    120042932 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8670              :             }
    8671              : 
    8672              :           /* Check for forward decls that never got their actual decl.  */
    8673    123697224 :           if (TREE_ASM_WRITTEN (decl))
    8674            4 :             error_at (b->locus,
    8675              :                       "parameter %q+D has just a forward declaration", decl);
    8676              :           /* Check for (..., void, ...) and named void parameters and issue an
    8677              :              error.  */
    8678    123697220 :           else if (VOID_TYPE_P (type))
    8679              :             {
    8680          114 :               if (!gave_void_only_once_err)
    8681              :                 {
    8682          114 :                   error_at (b->locus,
    8683              :                             "%<void%> must be the only parameter and unnamed");
    8684          114 :                   gave_void_only_once_err = true;
    8685              :                 }
    8686              :             }
    8687              :           else
    8688              :             {
    8689              :               /* Valid parameter, add it to the list.  */
    8690    123697106 :               DECL_CHAIN (decl) = parms;
    8691    123697106 :               parms = decl;
    8692              : 
    8693              :               /* Since there is a prototype, args are passed in their
    8694              :                  declared types.  The back end may override this later.  */
    8695    123697106 :               DECL_ARG_TYPE (decl) = type;
    8696    123697106 :               types = tree_cons (0, type, types);
    8697              :             }
    8698              :           break;
    8699              : 
    8700           21 :         case ENUMERAL_TYPE: keyword = "enum"; goto tag;
    8701           20 :         case UNION_TYPE:    keyword = "union"; goto tag;
    8702          101 :         case RECORD_TYPE:   keyword = "struct"; goto tag;
    8703          142 :         tag:
    8704              :           /* Types may not have tag-names, in which case the type
    8705              :              appears in the bindings list with b->id NULL.  */
    8706          142 :           if (b->id)
    8707              :             {
    8708           97 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    8709           97 :               I_TAG_BINDING (b->id) = b->shadowed;
    8710              :             }
    8711              : 
    8712              :           /* Warn about any struct, union or enum tags defined in a
    8713              :              parameter list.  The scope of such types is limited to
    8714              :              the parameter list, which is rarely if ever desirable
    8715              :              (it's impossible to call such a function with type-
    8716              :              correct arguments).  An anonymous union parm type is
    8717              :              meaningful as a GNU extension, so don't warn for that.  */
    8718          142 :           if (TREE_CODE (decl) != UNION_TYPE || b->id != NULL_TREE)
    8719              :             {
    8720          122 :               if (b->id)
    8721              :                 {
    8722              :                   /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8723           97 :                   if (!flag_isoc23 || !COMPLETE_TYPE_P (decl))
    8724           73 :                     warning_at (b->locus, 0,
    8725              :                                 "%<%s %E%> declared inside parameter list"
    8726              :                                 " will not be visible outside of this definition or"
    8727              :                                 " declaration", keyword, b->id);
    8728              :                 }
    8729              :               else
    8730              :                 /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8731           25 :                 warning_at (b->locus, 0,
    8732              :                             "anonymous %s declared inside parameter list"
    8733              :                             " will not be visible outside of this definition or"
    8734              :                             " declaration", keyword);
    8735              :             }
    8736              : 
    8737          142 :           tag.id = b->id;
    8738          142 :           tag.type = decl;
    8739          142 :           vec_safe_push (tags, tag);
    8740          142 :           break;
    8741              : 
    8742           20 :         case FUNCTION_DECL:
    8743              :           /* FUNCTION_DECLs appear when there is an implicit function
    8744              :              declaration in the parameter list.  */
    8745           20 :           gcc_assert (b->nested || seen_error ());
    8746           20 :           goto set_shadowed;
    8747              : 
    8748          144 :         case CONST_DECL:
    8749          144 :         case TYPE_DECL:
    8750              :           /* CONST_DECLs appear here when we have an embedded enum,
    8751              :              and TYPE_DECLs appear here when we have an embedded struct
    8752              :              or union.  No warnings for this - we already warned about the
    8753              :              type itself.  */
    8754              : 
    8755              :           /* When we reinsert this decl in the function body, we need
    8756              :              to reconstruct whether it was marked as nested.  */
    8757          144 :           gcc_assert (!b->nested);
    8758          144 :           DECL_CHAIN (decl) = others;
    8759          144 :           others = decl;
    8760              :           /* fall through */
    8761              : 
    8762          198 :         case ERROR_MARK:
    8763          198 :         set_shadowed:
    8764              :           /* error_mark_node appears here when we have an undeclared
    8765              :              variable.  Just throw it away.  */
    8766          198 :           if (b->id)
    8767              :             {
    8768           56 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8769           56 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8770              :             }
    8771              :           break;
    8772              : 
    8773              :           /* Other things that might be encountered.  */
    8774            0 :         case LABEL_DECL:
    8775            0 :         case VAR_DECL:
    8776            0 :         default:
    8777            0 :           gcc_unreachable ();
    8778              :         }
    8779              : 
    8780    123697564 :       b = free_binding_and_advance (b);
    8781              :     }
    8782              : 
    8783     49218926 :   arg_info->parms = parms;
    8784     49218926 :   arg_info->tags = tags;
    8785     49218926 :   arg_info->types = types;
    8786     49218926 :   arg_info->others = others;
    8787     49218926 :   arg_info->pending_sizes = expr;
    8788     49218926 :   arg_info->no_named_args_stdarg_p = ellipsis && !types;
    8789     49218926 :   return arg_info;
    8790              : }
    8791              : 
    8792              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8793              :    Define the tag as a forward-reference with location LOC if it is
    8794              :    not defined.  HAVE_STD_ATTRS says whether any standard attributes
    8795              :    were present after the struct, union or enum keyword; ATTRS are the
    8796              :    standard attributes present there.  HAS_ENUM_TYPE_SPECIFIER says
    8797              :    whether an enum type specifier (": specifier-qualifier-list") is
    8798              :    present; if so, this is called before that specifier is parsed, so
    8799              :    that the tag is in scope for that specifier.  Return a c_typespec
    8800              :    structure for the type specifier.  */
    8801              : 
    8802              : struct c_typespec
    8803      1089511 : parser_xref_tag (location_t loc, enum tree_code code, tree name,
    8804              :                  bool have_std_attrs, tree attrs, bool has_enum_type_specifier)
    8805              : {
    8806      1089511 :   struct c_typespec ret;
    8807      1089511 :   tree ref;
    8808      1089511 :   location_t refloc;
    8809              : 
    8810      1089511 :   ret.expr = NULL_TREE;
    8811      1089511 :   ret.expr_const_operands = true;
    8812      1089511 :   ret.has_enum_type_specifier = has_enum_type_specifier;
    8813              : 
    8814              :   /* If a cross reference is requested, look up the type already
    8815              :      defined for this tag and return it.  If an enum type specifier is
    8816              :      present, only a definition in the current scope is relevant.  */
    8817              : 
    8818      1089511 :   ref = lookup_tag (code, name, has_enum_type_specifier, &refloc);
    8819              : 
    8820              :   /* If the visble type is still being defined, see if there is
    8821              :      an earlier definition (which may be complete).  We do not
    8822              :      have to loop because nested redefinitions are not allowed.  */
    8823      1089511 :   if (flag_isoc23 && ref && C_TYPE_BEING_DEFINED (ref))
    8824              :     {
    8825        86151 :       tree vis = previous_tag (ref);
    8826        86151 :       if (vis)
    8827           16 :         ref = vis;
    8828              :     }
    8829              : 
    8830              :   /* If this is the right type of tag, return what we found.
    8831              :      (This reference will be shadowed by shadow_tag later if appropriate.)
    8832              :      If this is the wrong type of tag, do not return it.  If it was the
    8833              :      wrong type in the same scope, we will have had an error
    8834              :      message already; if in a different scope and declaring
    8835              :      a name, pending_xref_error will give an error message; but if in a
    8836              :      different scope and not declaring a name, this tag should
    8837              :      shadow the previous declaration of a different type of tag, and
    8838              :      this would not work properly if we return the reference found.
    8839              :      (For example, with "struct foo" in an outer scope, "union foo;"
    8840              :      must shadow that tag with a new one of union type.)  */
    8841      2179022 :   ret.kind = (ref
    8842      1089511 :               ? (have_std_attrs ? ctsk_tagref_attrs : ctsk_tagref)
    8843        95083 :               : (have_std_attrs ? ctsk_tagfirstref_attrs : ctsk_tagfirstref));
    8844      1089511 :   if (ref && TREE_CODE (ref) == code)
    8845              :     {
    8846       994394 :       decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8847       994394 :       if (C_TYPE_DEFINED_IN_STRUCT (ref)
    8848            5 :           && loc != UNKNOWN_LOCATION
    8849       994399 :           && warn_cxx_compat)
    8850              :         {
    8851            5 :           auto_diagnostic_group d;
    8852            5 :           switch (code)
    8853              :             {
    8854            2 :             case ENUMERAL_TYPE:
    8855            2 :               if (warning_at (loc, OPT_Wc___compat,
    8856              :                               ("enum type defined in struct or union "
    8857              :                                "is not visible in C++")))
    8858            2 :                   inform (refloc, "enum type defined here");
    8859              :               break;
    8860            2 :             case RECORD_TYPE:
    8861            2 :               if (warning_at (loc, OPT_Wc___compat,
    8862              :                               ("struct defined in struct or union "
    8863              :                                "is not visible in C++")))
    8864            2 :                 inform (refloc, "struct defined here");
    8865              :               break;
    8866            1 :             case UNION_TYPE:
    8867            1 :               if (warning_at (loc, OPT_Wc___compat,
    8868              :                               ("union defined in struct or union "
    8869              :                                "is not visible in C++")))
    8870            1 :                 inform (refloc, "union defined here");
    8871              :               break;
    8872            0 :             default:
    8873            0 :               gcc_unreachable();
    8874              :             }
    8875            5 :         }
    8876              : 
    8877       994394 :       ret.spec = ref;
    8878       994394 :       return ret;
    8879              :     }
    8880              : 
    8881              :   /* If no such tag is yet defined, create a forward-reference node
    8882              :      and record it as the "definition".
    8883              :      When a real declaration of this type is found,
    8884              :      the forward-reference will be altered into a real type.  */
    8885              : 
    8886        95117 :   ref = make_node (code);
    8887        95117 :   if (flag_isoc23 || code == ENUMERAL_TYPE)
    8888        72849 :     SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8889        72849 :   if (code == ENUMERAL_TYPE)
    8890              :     {
    8891              :       /* Give the type a default layout like unsigned int
    8892              :          to avoid crashing if it does not get defined.  */
    8893          270 :       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
    8894          270 :       SET_TYPE_ALIGN (ref, TYPE_ALIGN (unsigned_type_node));
    8895          270 :       TYPE_USER_ALIGN (ref) = 0;
    8896          270 :       TYPE_UNSIGNED (ref) = 1;
    8897          270 :       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
    8898          270 :       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
    8899          270 :       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
    8900          270 :       ENUM_FIXED_UNDERLYING_TYPE_P (ref) = has_enum_type_specifier;
    8901              :     }
    8902              : 
    8903        95117 :   pushtag (loc, name, ref);
    8904        95117 :   decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8905        95117 :   if (in_underspecified_init)
    8906            9 :     error_at (loc, "%qT declared in underspecified object initializer",
    8907              :               ref);
    8908              : 
    8909        95117 :   ret.spec = ref;
    8910        95117 :   return ret;
    8911              : }
    8912              : 
    8913              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8914              :    Define the tag as a forward-reference if it is not defined.
    8915              :    Return a tree for the type.  */
    8916              : 
    8917              : tree
    8918            0 : xref_tag (enum tree_code code, tree name)
    8919              : {
    8920            0 :   return parser_xref_tag (input_location, code, name, false, NULL_TREE,
    8921            0 :                           false).spec;
    8922              : }
    8923              : 
    8924              : /* Make sure that the tag NAME is defined *in the current scope*
    8925              :    at least as a forward reference.
    8926              :    LOC is the location of the struct's definition.
    8927              :    CODE says which kind of tag NAME ought to be.
    8928              : 
    8929              :    This stores the current value of the file static STRUCT_PARSE_INFO
    8930              :    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
    8931              :    new c_struct_parse_info structure.  The old value of
    8932              :    STRUCT_PARSE_INFO is restored in finish_struct.  */
    8933              : 
    8934              : tree
    8935      1179734 : start_struct (location_t loc, enum tree_code code, tree name,
    8936              :               class c_struct_parse_info **enclosing_struct_parse_info)
    8937              : {
    8938              :   /* If there is already a tag defined at this scope
    8939              :      (as a forward reference), just return it.  */
    8940              : 
    8941      1179734 :   tree ref = NULL_TREE;
    8942      1179734 :   location_t refloc = UNKNOWN_LOCATION;
    8943              : 
    8944      1179734 :   if (name != NULL_TREE)
    8945       486794 :     ref = lookup_tag (code, name, true, &refloc);
    8946              : 
    8947              :   /* For C23, even if we already have a completed definition,
    8948              :      we do not use it. We will check for consistency later.
    8949              :      If we are in a nested redefinition the type is not
    8950              :      complete. We will then detect this below.  */
    8951      1179734 :   if (flag_isoc23 && ref && TYPE_SIZE (ref))
    8952              :     ref = NULL_TREE;
    8953              : 
    8954      1179625 :   if (ref && TREE_CODE (ref) == code)
    8955              :     {
    8956        25215 :       if (TYPE_STUB_DECL (ref))
    8957        25215 :         refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
    8958              : 
    8959        25215 :       if (TYPE_SIZE (ref))
    8960              :         {
    8961           11 :           auto_diagnostic_group d;
    8962           11 :           if (code == UNION_TYPE)
    8963            2 :             error_at (loc, "redefinition of %<union %E%>", name);
    8964              :           else
    8965            9 :             error_at (loc, "redefinition of %<struct %E%>", name);
    8966           11 :           if (refloc != UNKNOWN_LOCATION)
    8967           11 :             inform (refloc, "originally defined here");
    8968              :           /* Don't create structures using a name already in use.  */
    8969           11 :           ref = NULL_TREE;
    8970           11 :         }
    8971        25204 :       else if (C_TYPE_BEING_DEFINED (ref))
    8972              :         {
    8973           17 :           if (code == UNION_TYPE)
    8974            1 :             error_at (loc, "nested redefinition of %<union %E%>", name);
    8975              :           else
    8976           16 :             error_at (loc, "nested redefinition of %<struct %E%>", name);
    8977              :           /* Don't bother to report "originally defined here" for a
    8978              :              nested redefinition; the original definition should be
    8979              :              obvious.  */
    8980              :           /* Don't create structures that contain themselves.  */
    8981              :           ref = NULL_TREE;
    8982              :         }
    8983              :     }
    8984              : 
    8985              :   /* Otherwise create a forward-reference just so the tag is in scope.  */
    8986              : 
    8987        25201 :   if (ref == NULL_TREE || TREE_CODE (ref) != code)
    8988              :     {
    8989      1154547 :       ref = make_node (code);
    8990      1154547 :       if (flag_isoc23)
    8991       926340 :         SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8992      1154547 :       pushtag (loc, name, ref);
    8993              :     }
    8994              : 
    8995      1179734 :   C_TYPE_BEING_DEFINED (ref) = 1;
    8996      2390182 :   for (tree v = TYPE_MAIN_VARIANT (ref); v; v = TYPE_NEXT_VARIANT (v))
    8997      1210448 :     TYPE_PACKED (v) = flag_pack_struct;
    8998              : 
    8999      1179734 :   *enclosing_struct_parse_info = struct_parse_info;
    9000      1179734 :   struct_parse_info = new c_struct_parse_info ();
    9001      1179734 :   struct_parse_info->refloc = refloc;
    9002              : 
    9003              :   /* FIXME: This will issue a warning for a use of a type defined
    9004              :      within a statement expr used within sizeof, et. al.  This is not
    9005              :      terribly serious as C++ doesn't permit statement exprs within
    9006              :      sizeof anyhow.  */
    9007      1179734 :   if (warn_cxx_compat
    9008          574 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
    9009           10 :     warning_at (loc, OPT_Wc___compat,
    9010              :                 "defining type in %qs expression is invalid in C++",
    9011              :                 (in_sizeof ? "sizeof"
    9012            4 :                  : in_typeof ? "typeof"
    9013            1 :                  : in_alignof ? "alignof"
    9014              :                  : "_Countof"));
    9015              : 
    9016      1179734 :   if (in_underspecified_init)
    9017           18 :     error_at (loc, "%qT defined in underspecified object initializer", ref);
    9018              : 
    9019      1179734 :   return ref;
    9020              : }
    9021              : 
    9022              : /* Process the specs, declarator and width (NULL if omitted)
    9023              :    of a structure component, returning a FIELD_DECL node.
    9024              :    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
    9025              :    DECL_ATTRS is as for grokdeclarator.
    9026              : 
    9027              :    LOC is the location of the structure component.
    9028              : 
    9029              :    This is done during the parsing of the struct declaration.
    9030              :    The FIELD_DECL nodes are chained together and the lot of them
    9031              :    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
    9032              : 
    9033              : tree
    9034      4309946 : grokfield (location_t loc,
    9035              :            struct c_declarator *declarator, struct c_declspecs *declspecs,
    9036              :            tree width, tree *decl_attrs, tree *expr)
    9037              : {
    9038      4309946 :   tree value;
    9039              : 
    9040      4309946 :   if (declarator->kind == cdk_id && declarator->u.id.id == NULL_TREE
    9041        20408 :       && width == NULL_TREE)
    9042              :     {
    9043              :       /* This is an unnamed decl.
    9044              : 
    9045              :          If we have something of the form "union { list } ;" then this
    9046              :          is the anonymous union extension.  Similarly for struct.
    9047              : 
    9048              :          If this is something of the form "struct foo;", then
    9049              :            If MS or Plan 9 extensions are enabled, this is handled as
    9050              :              an anonymous struct.
    9051              :            Otherwise this is a forward declaration of a structure tag.
    9052              : 
    9053              :          If this is something of the form "foo;" and foo is a TYPE_DECL, then
    9054              :            If foo names a structure or union without a tag, then this
    9055              :              is an anonymous struct (this is permitted by C11).
    9056              :            If MS or Plan 9 extensions are enabled and foo names a
    9057              :              structure, then again this is an anonymous struct.
    9058              :            Otherwise this is an error.
    9059              : 
    9060              :          Oh what a horrid tangled web we weave.  I wonder if MS consciously
    9061              :          took this from Plan 9 or if it was an accident of implementation
    9062              :          that took root before someone noticed the bug...  */
    9063              : 
    9064        10645 :       tree type = declspecs->type;
    9065        10645 :       bool ok = false;
    9066              : 
    9067        10645 :       if (RECORD_OR_UNION_TYPE_P (type)
    9068        10639 :           && (flag_ms_extensions
    9069        10610 :               || flag_plan9_extensions
    9070        10579 :               || !declspecs->typedef_p))
    9071              :         {
    9072        10632 :           if (flag_ms_extensions || flag_plan9_extensions)
    9073              :             ok = true;
    9074        10572 :           else if (TYPE_NAME (type) == NULL)
    9075              :             ok = true;
    9076              :           else
    9077              :             ok = false;
    9078              :         }
    9079              :       if (!ok)
    9080              :         {
    9081           29 :           pedwarn (loc, 0, "declaration does not declare anything");
    9082           29 :           return NULL_TREE;
    9083              :         }
    9084        10616 :       if (flag_isoc99)
    9085        10594 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9086              :                      "ISO C99 doesn%'t support unnamed structs/unions");
    9087              :       else
    9088           22 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9089              :                      "ISO C90 doesn%'t support unnamed structs/unions");
    9090              :     }
    9091              : 
    9092      4309917 :   value = grokdeclarator (declarator, declspecs, FIELD, false,
    9093      4309917 :                           width ? &width : NULL, decl_attrs, expr, NULL,
    9094              :                           DEPRECATED_NORMAL);
    9095              : 
    9096              :   /* When this field has name, its type is a top level type, we should
    9097              :      call verify_counted_by_for_top_anonymous_type.  */
    9098      4309917 :   if (DECL_NAME (value) != NULL_TREE
    9099      4309917 :       && declspecs->typespec_kind == ctsk_tagdef)
    9100       153294 :     verify_counted_by_for_top_anonymous_type (declspecs->type);
    9101              : 
    9102      4309917 :   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
    9103      4309917 :   DECL_INITIAL (value) = width;
    9104      4309917 :   if (width)
    9105        52739 :     SET_DECL_C_BIT_FIELD (value);
    9106              : 
    9107      4309917 :   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
    9108              :     {
    9109              :       /* If we currently have a binding for this field, set the
    9110              :          in_struct field in the binding, so that we warn about lookups
    9111              :          which find it.  */
    9112         1310 :       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
    9113         1310 :       if (b != NULL)
    9114              :         {
    9115              :           /* If the in_struct field is not yet set, push it on a list
    9116              :              to be cleared when this struct is finished.  */
    9117           93 :           if (!b->in_struct)
    9118              :             {
    9119           91 :               struct_parse_info->fields.safe_push (b);
    9120           91 :               b->in_struct = 1;
    9121              :             }
    9122              :         }
    9123              :     }
    9124              : 
    9125              :   return value;
    9126              : }
    9127              : 
    9128              : /* Subroutine of detect_field_duplicates: return whether X and Y,
    9129              :    which are both fields in the same struct, have duplicate field
    9130              :    names.  */
    9131              : 
    9132              : static bool
    9133      4302942 : is_duplicate_field (tree x, tree y)
    9134              : {
    9135      4302942 :   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
    9136              :     return true;
    9137              : 
    9138              :   /* When using -fplan9-extensions, an anonymous field whose name is a
    9139              :      typedef can duplicate a field name.  */
    9140      4302941 :   if (flag_plan9_extensions
    9141      4302941 :       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
    9142              :     {
    9143            0 :       tree xt, xn, yt, yn;
    9144              : 
    9145            0 :       xt = TREE_TYPE (x);
    9146            0 :       if (DECL_NAME (x) != NULL_TREE)
    9147            0 :         xn = DECL_NAME (x);
    9148            0 :       else if (RECORD_OR_UNION_TYPE_P (xt)
    9149            0 :                && TYPE_NAME (xt) != NULL_TREE
    9150            0 :                && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
    9151            0 :         xn = DECL_NAME (TYPE_NAME (xt));
    9152              :       else
    9153              :         xn = NULL_TREE;
    9154              : 
    9155            0 :       yt = TREE_TYPE (y);
    9156            0 :       if (DECL_NAME (y) != NULL_TREE)
    9157            0 :         yn = DECL_NAME (y);
    9158            0 :       else if (RECORD_OR_UNION_TYPE_P (yt)
    9159            0 :                && TYPE_NAME (yt) != NULL_TREE
    9160            0 :                && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
    9161            0 :         yn = DECL_NAME (TYPE_NAME (yt));
    9162              :       else
    9163              :         yn = NULL_TREE;
    9164              : 
    9165            0 :       if (xn != NULL_TREE && xn == yn)
    9166            0 :         return true;
    9167              :     }
    9168              : 
    9169              :   return false;
    9170              : }
    9171              : 
    9172              : /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
    9173              :    to HTAB, giving errors for any duplicates.  */
    9174              : 
    9175              : static void
    9176        80515 : detect_field_duplicates_hash (tree fieldlist,
    9177              :                               hash_table<nofree_ptr_hash <tree_node> > *htab)
    9178              : {
    9179        80515 :   tree x, y;
    9180        80515 :   tree_node **slot;
    9181              : 
    9182      1403510 :   for (x = fieldlist; x ; x = DECL_CHAIN (x))
    9183      1322995 :     if ((y = DECL_NAME (x)) != NULL_TREE)
    9184              :       {
    9185      1302567 :         slot = htab->find_slot (y, INSERT);
    9186      1302567 :         if (*slot)
    9187              :           {
    9188           15 :             error ("duplicate member %q+D", x);
    9189           15 :             DECL_NAME (x) = NULL_TREE;
    9190              :           }
    9191      1302567 :         *slot = y;
    9192              :       }
    9193        20428 :     else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9194              :       {
    9195        11382 :         detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
    9196              : 
    9197              :         /* When using -fplan9-extensions, an anonymous field whose
    9198              :            name is a typedef can duplicate a field name.  */
    9199        11382 :         if (flag_plan9_extensions
    9200           31 :             && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9201        11412 :             && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
    9202              :           {
    9203           10 :             tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
    9204           10 :             slot = htab->find_slot (xn, INSERT);
    9205           10 :             if (*slot)
    9206            0 :               error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
    9207           10 :             *slot = xn;
    9208              :           }
    9209              :       }
    9210        80515 : }
    9211              : 
    9212              : /* Generate an error for any duplicate field names in FIELDLIST.  Munge
    9213              :    the list such that this does not present a problem later.  */
    9214              : 
    9215              : static void
    9216      1179864 : detect_field_duplicates (tree fieldlist)
    9217              : {
    9218      1179864 :   tree x, y;
    9219      1179864 :   int timeout = 10;
    9220              : 
    9221              :   /* If the struct is the list of instance variables of an Objective-C
    9222              :      class, then we need to check all the instance variables of
    9223              :      superclasses when checking for duplicates (since you can't have
    9224              :      an instance variable in a subclass with the same name as an
    9225              :      instance variable in a superclass).  We pass on this job to the
    9226              :      Objective-C compiler.  objc_detect_field_duplicates() will return
    9227              :      false if we are not checking the list of instance variables and
    9228              :      the C frontend should proceed with the standard field duplicate
    9229              :      checks.  If we are checking the list of instance variables, the
    9230              :      ObjC frontend will do the check, emit the errors if needed, and
    9231              :      then return true.  */
    9232      1179864 :   if (c_dialect_objc ())
    9233            0 :     if (objc_detect_field_duplicates (false))
    9234              :       return;
    9235              : 
    9236              :   /* First, see if there are more than "a few" fields.
    9237              :      This is trivially true if there are zero or one fields.  */
    9238      1179864 :   if (!fieldlist || !DECL_CHAIN (fieldlist))
    9239              :     return;
    9240              :   x = fieldlist;
    9241      3476743 :   do {
    9242      3476743 :     timeout--;
    9243      3476743 :     if (DECL_NAME (x) == NULL_TREE
    9244      3476743 :         && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9245              :       timeout = 0;
    9246      3476743 :     x = DECL_CHAIN (x);
    9247      3476743 :   } while (timeout > 0 && x);
    9248              : 
    9249              :   /* If there were "few" fields and no anonymous structures or unions,
    9250              :      avoid the overhead of allocating a hash table.  Instead just do
    9251              :      the nested traversal thing.  */
    9252       974127 :   if (timeout > 0)
    9253              :     {
    9254      2819392 :       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
    9255              :         /* When using -fplan9-extensions, we can have duplicates
    9256              :            between typedef names and fields.  */
    9257      1914398 :         if (DECL_NAME (x)
    9258      1914398 :             || (flag_plan9_extensions
    9259            0 :                 && DECL_NAME (x) == NULL_TREE
    9260            0 :                 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9261            0 :                 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9262            0 :                 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
    9263              :           {
    9264      6216804 :             for (y = fieldlist; y != x; y = TREE_CHAIN (y))
    9265      4302942 :               if (is_duplicate_field (y, x))
    9266              :                 {
    9267            1 :                   error ("duplicate member %q+D", x);
    9268            1 :                   DECL_NAME (x) = NULL_TREE;
    9269              :                 }
    9270              :           }
    9271              :     }
    9272              :   else
    9273              :     {
    9274        69133 :       hash_table<nofree_ptr_hash <tree_node> > htab (37);
    9275        69133 :       detect_field_duplicates_hash (fieldlist, &htab);
    9276        69133 :     }
    9277              : }
    9278              : 
    9279              : /* Finish up struct info used by -Wc++-compat.  */
    9280              : 
    9281              : static void
    9282          575 : warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code,
    9283              :                                location_t record_loc)
    9284              : {
    9285          575 :   unsigned int ix;
    9286          575 :   tree x;
    9287          575 :   struct c_binding *b;
    9288              : 
    9289          575 :   if (fieldlist == NULL_TREE)
    9290              :     {
    9291            9 :       if (code == RECORD_TYPE)
    9292            6 :         warning_at (record_loc, OPT_Wc___compat,
    9293              :                     "empty struct has size 0 in C, size 1 in C++");
    9294              :       else
    9295            3 :         warning_at (record_loc, OPT_Wc___compat,
    9296              :                     "empty union has size 0 in C, size 1 in C++");
    9297              :     }
    9298              : 
    9299              :   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
    9300              :      the current struct.  We do this now at the end of the struct
    9301              :      because the flag is used to issue visibility warnings, and we
    9302              :      only want to issue those warnings if the type is referenced
    9303              :      outside of the struct declaration.  */
    9304          623 :   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
    9305           48 :     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
    9306              : 
    9307              :   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
    9308              :      typedefs used when declaring fields in this struct.  If the name
    9309              :      of any of the fields is also a typedef name then the struct would
    9310              :      not parse in C++, because the C++ lookup rules say that the
    9311              :      typedef name would be looked up in the context of the struct, and
    9312              :      would thus be the field rather than the typedef.  */
    9313          575 :   if (!struct_parse_info->typedefs_seen.is_empty ()
    9314           67 :       && fieldlist != NULL_TREE)
    9315              :     {
    9316              :       /* Use a hash_set<tree> using the name of the typedef.  We can use
    9317              :          a hash_set<tree> because identifiers are interned.  */
    9318           67 :       hash_set<tree> tset;
    9319              : 
    9320          254 :       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
    9321          120 :         tset.add (DECL_NAME (x));
    9322              : 
    9323          387 :       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
    9324              :         {
    9325          320 :           if (DECL_NAME (x) != NULL_TREE
    9326          320 :               && tset.contains (DECL_NAME (x)))
    9327              :             {
    9328            2 :               warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
    9329              :                           "using %qD as both field and typedef name is "
    9330              :                           "invalid in C++", x);
    9331              :               /* FIXME: It would be nice to report the location where
    9332              :                  the typedef name is used.  */
    9333              :             }
    9334              :         }
    9335           67 :     }
    9336              : 
    9337              :   /* For each field which has a binding and which was not defined in
    9338              :      an enclosing struct, clear the in_struct field.  */
    9339          666 :   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
    9340           91 :     b->in_struct = 0;
    9341          575 : }
    9342              : 
    9343              : /* Function to help qsort sort FIELD_DECLs by name order.  */
    9344              : 
    9345              : static int
    9346     20193976 : field_decl_cmp (const void *x_p, const void *y_p)
    9347              : {
    9348     20193976 :   const tree *const x = (const tree *) x_p;
    9349     20193976 :   const tree *const y = (const tree *) y_p;
    9350              : 
    9351     20193976 :   if (DECL_NAME (*x) == DECL_NAME (*y))
    9352              :     /* A nontype is "greater" than a type.  */
    9353            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
    9354     20193976 :   if (DECL_NAME (*x) == NULL_TREE)
    9355              :     return -1;
    9356     20193976 :   if (DECL_NAME (*y) == NULL_TREE)
    9357              :     return 1;
    9358     20193976 :   if (DECL_NAME (*x) < DECL_NAME (*y))
    9359      9945558 :     return -1;
    9360              :   return 1;
    9361              : }
    9362              : 
    9363              : /* If this structure or union completes the type of any previous
    9364              :    variable declaration, lay it out and output its rtl.  */
    9365              : static void
    9366      1362327 : finish_incomplete_vars (tree incomplete_vars, bool toplevel)
    9367              : {
    9368      1362476 :   for (tree x = incomplete_vars; x; x = TREE_CHAIN (x))
    9369              :     {
    9370          149 :       tree decl = TREE_VALUE (x);
    9371          149 :       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
    9372            0 :         layout_array_type (TREE_TYPE (decl));
    9373          149 :       if (TREE_CODE (decl) != TYPE_DECL)
    9374              :         {
    9375          149 :           relayout_decl (decl);
    9376          149 :           if (c_dialect_objc ())
    9377            0 :             objc_check_decl (decl);
    9378          149 :           rest_of_decl_compilation (decl, toplevel, 0);
    9379              :         }
    9380              :     }
    9381      1362327 : }
    9382              : 
    9383              : /* Determine whether the FIELD_DECL X is a flexible array member according to
    9384              :    the following info:
    9385              :   A. whether the FIELD_DECL X is the last field of the DECL_CONTEXT;
    9386              :   B. whether the FIELD_DECL is an array that is declared as "[]", "[0]",
    9387              :      or "[1]";
    9388              :   C. flag_strict_flex_arrays;
    9389              :   D. the attribute strict_flex_array that is attached to the field
    9390              :      if presenting.
    9391              :   Return TRUE when it's a flexible array member, FALSE otherwise.  */
    9392              : 
    9393              : static bool
    9394      4310068 : is_flexible_array_member_p (bool is_last_field,
    9395              :                             tree x)
    9396              : {
    9397              :   /* If not the last field, return false.  */
    9398      4310068 :   if (!is_last_field)
    9399              :     return false;
    9400              : 
    9401              :   /* If not an array field, return false.  */
    9402      1654323 :   if (TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    9403              :     return false;
    9404              : 
    9405       534424 :   bool is_zero_length_array = zero_length_array_type_p (TREE_TYPE (x));
    9406       534424 :   bool is_one_element_array = one_element_array_type_p (TREE_TYPE (x));
    9407       534424 :   bool is_flexible_array = c_flexible_array_member_type_p (TREE_TYPE (x));
    9408              : 
    9409       534424 :   unsigned int strict_flex_array_level = c_strict_flex_array_level_of (x);
    9410              : 
    9411       534424 :   switch (strict_flex_array_level)
    9412              :     {
    9413              :       case 0:
    9414              :         /* Default, all trailing arrays are flexible array members.  */
    9415              :         return true;
    9416           77 :       case 1:
    9417              :         /* Level 1: all "[1]", "[0]", and "[]" are flexible array members.  */
    9418           77 :         if (is_one_element_array)
    9419              :           return true;
    9420              :         /* FALLTHROUGH.  */
    9421          141 :       case 2:
    9422              :         /* Level 2: all "[0]", and "[]" are flexible array members.  */
    9423          141 :         if (is_zero_length_array)
    9424              :           return true;
    9425              :         /* FALLTHROUGH.  */
    9426          201 :       case 3:
    9427              :         /* Level 3: Only "[]" are flexible array members.  */
    9428          201 :         if (is_flexible_array)
    9429              :           return true;
    9430              :         break;
    9431            0 :       default:
    9432            0 :         gcc_unreachable ();
    9433              :     }
    9434              :   return false;
    9435              : }
    9436              : 
    9437              : /* Recompute TYPE_CANONICAL for variants of the type including qualified
    9438              :    versions of the type and related pointer types after an aggregate type
    9439              :    has been finalized.
    9440              :    Will not update array types, pointers to array types, function
    9441              :    types and other derived types created while the type was still
    9442              :    incomplete, those will remain TYPE_STRUCTURAL_EQUALITY_P.  */
    9443              : 
    9444              : static void
    9445      1198641 : c_update_type_canonical (tree t)
    9446              : {
    9447      1198641 :   gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t && !TYPE_QUALS (t));
    9448      2424118 :   for (tree x = t, l = NULL_TREE; x; l = x, x = TYPE_NEXT_VARIANT (x))
    9449              :     {
    9450      1225477 :       if (x != t && TYPE_STRUCTURAL_EQUALITY_P (x))
    9451              :         {
    9452        26836 :           if (!TYPE_QUALS (x))
    9453        26208 :             TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
    9454              :           else
    9455              :             {
    9456          628 :               tree
    9457          628 :                 c = c_build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
    9458          628 :               if (TYPE_STRUCTURAL_EQUALITY_P (c))
    9459              :                 {
    9460          206 :                   gcc_checking_assert (TYPE_CANONICAL (t) == t);
    9461          206 :                   if (c == x)
    9462          206 :                     TYPE_CANONICAL (x) = x;
    9463              :                   else
    9464              :                     {
    9465              :                       /* build_qualified_type for this function unhelpfully
    9466              :                          moved c from some later spot in TYPE_MAIN_VARIANT (t)
    9467              :                          chain to right after t (or created it there).  Move
    9468              :                          it right before x and process c and then x.  */
    9469            0 :                       gcc_checking_assert (TYPE_NEXT_VARIANT (t) == c);
    9470            0 :                       if (l != t)
    9471              :                         {
    9472            0 :                           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (c);
    9473            0 :                           TYPE_NEXT_VARIANT (l) = c;
    9474            0 :                           TYPE_NEXT_VARIANT (c) = x;
    9475              :                         }
    9476            0 :                       TYPE_CANONICAL (c) = c;
    9477            0 :                       x = c;
    9478              :                     }
    9479              :                 }
    9480              :               else
    9481          422 :                 TYPE_CANONICAL (x) = TYPE_CANONICAL (c);
    9482              :             }
    9483              :         }
    9484      1198641 :       else if (x != t)
    9485            0 :         continue;
    9486      1294198 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9487              :         {
    9488        68721 :           if (!TYPE_STRUCTURAL_EQUALITY_P (p))
    9489            0 :             continue;
    9490        68721 :           if (TYPE_CANONICAL (x) != x || TYPE_REF_CAN_ALIAS_ALL (p))
    9491        66621 :             TYPE_CANONICAL (p)
    9492       133242 :               = c_build_pointer_type_for_mode (TYPE_CANONICAL (x), TYPE_MODE (p),
    9493              :                                                false);
    9494              :           else
    9495         2100 :             TYPE_CANONICAL (p) = p;
    9496        68721 :           c_update_type_canonical (p);
    9497              :         }
    9498              :     }
    9499      1198641 : }
    9500              : 
    9501              : 
    9502              : /* We set C_TYPE_VARIABLY_MODIFIED for derived types.  We will not update
    9503              :    array types, pointers to array types, function types and other derived
    9504              :    types created while the type was still incomplete.  We need to update
    9505              :    at least all types for which TYPE_CANONICAL will bet set, because for
    9506              :    those we later assume (in c_variably_modified_p) that the bit is
    9507              :    up-to-date.  */
    9508              : 
    9509              : static void
    9510          734 : c_update_variably_modified (tree t)
    9511              : {
    9512         1477 :   for (tree x = t; x; x = TYPE_NEXT_VARIANT (x))
    9513              :     {
    9514          743 :       C_TYPE_VARIABLY_MODIFIED (x) = 1;
    9515          761 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9516           18 :         c_update_variably_modified (p);
    9517              :     }
    9518          734 : }
    9519              : 
    9520              : 
    9521              : /* Verify the argument of the counted_by attribute of each field of
    9522              :    the containing structure, OUTMOST_STRUCT_TYPE, including its inner
    9523              :    anonymous struct/union, Report error and remove the corresponding
    9524              :    attribute when it's not.  */
    9525              : 
    9526              : static void
    9527          528 : verify_counted_by_attribute (tree outmost_struct_type,
    9528              :                              tree cur_struct_type)
    9529              : {
    9530         1700 :   for (tree field = TYPE_FIELDS (cur_struct_type); field;
    9531         1172 :        field = TREE_CHAIN (field))
    9532              :     {
    9533         1172 :       if (c_flexible_array_member_type_p (TREE_TYPE (field))
    9534         1172 :            || TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
    9535              :         {
    9536          398 :           tree attr_counted_by = lookup_attribute ("counted_by",
    9537          398 :                                                    DECL_ATTRIBUTES (field));
    9538              : 
    9539          398 :           if (!attr_counted_by)
    9540            1 :             continue;
    9541              : 
    9542              :           /* If there is an counted_by attribute attached to the field,
    9543              :              verify it.  */
    9544              : 
    9545          397 :           tree fieldname = TREE_VALUE (TREE_VALUE (attr_counted_by));
    9546              : 
    9547              :           /* Verify the argument of the attrbute is a valid field of the
    9548              :              containing structure.  */
    9549              : 
    9550          397 :           tree counted_by_field = lookup_field (outmost_struct_type,
    9551              :                                                 fieldname);
    9552              : 
    9553              :           /* Error when the field is not found in the containing structure
    9554              :              and remove the corresponding counted_by attribute from the
    9555              :              field_decl.  */
    9556          397 :           if (!counted_by_field)
    9557              :             {
    9558           24 :               error_at (DECL_SOURCE_LOCATION (field),
    9559              :                     "argument %qE to the %<counted_by%> attribute"
    9560              :                     " is not a field declaration in the same structure"
    9561              :                     " as %qD", fieldname, field);
    9562           24 :               DECL_ATTRIBUTES (field)
    9563           48 :                 = remove_attribute ("counted_by", DECL_ATTRIBUTES (field));
    9564              :             }
    9565              :           else
    9566              :           /* Error when the field is not with an integer type.  */
    9567              :             {
    9568          574 :               while (TREE_CHAIN (counted_by_field))
    9569          201 :                 counted_by_field = TREE_CHAIN (counted_by_field);
    9570          373 :               tree real_field = TREE_VALUE (counted_by_field);
    9571              : 
    9572          373 :               if (!INTEGRAL_TYPE_P (TREE_TYPE (real_field)))
    9573              :                 {
    9574            6 :                   error_at (DECL_SOURCE_LOCATION (field),
    9575              :                         "argument %qE to the %<counted_by%> attribute"
    9576              :                         " is not a field declaration with an integer type",
    9577              :                         fieldname);
    9578            6 :                   DECL_ATTRIBUTES (field)
    9579           12 :                     = remove_attribute ("counted_by",
    9580            6 :                                     DECL_ATTRIBUTES (field));
    9581              :                 }
    9582              :             }
    9583              :         }
    9584         1451 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    9585          865 :                && (DECL_NAME (field) == NULL_TREE))
    9586          188 :         verify_counted_by_attribute (outmost_struct_type, TREE_TYPE (field));
    9587              :     }
    9588          528 : }
    9589              : 
    9590              : /* Caller should make sure the TYPE is a top-level type (i.e. not being
    9591              :    nested in other structure/uniona). For such type, verify its counted_by
    9592              :    if it is an anonymous structure/union.  */
    9593              : 
    9594              : void
    9595      1351614 : verify_counted_by_for_top_anonymous_type (tree type)
    9596              : {
    9597      1351614 :   if (!RECORD_OR_UNION_TYPE_P (type))
    9598              :     return;
    9599              : 
    9600      1169158 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (type)
    9601      1169158 :       && c_type_tag (type) == NULL_TREE)
    9602           48 :     verify_counted_by_attribute (type, type);
    9603              : }
    9604              : 
    9605              : /* TYPE is a struct or union that we're applying may_alias to after the body is
    9606              :    parsed.  Fixup any POINTER_TO types.  */
    9607              : 
    9608              : static void
    9609          358 : c_fixup_may_alias (tree type)
    9610              : {
    9611          423 :   for (tree t = TYPE_POINTER_TO (type); t; t = TYPE_NEXT_PTR_TO (t))
    9612          190 :     for (tree v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    9613          125 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    9614          358 : }
    9615              : 
    9616              : /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
    9617              :    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
    9618              :    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
    9619              :    ATTRIBUTES are attributes to be applied to the structure.
    9620              : 
    9621              :    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
    9622              :    the struct was started.  */
    9623              : 
    9624              : tree
    9625      1179864 : finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
    9626              :                class c_struct_parse_info *enclosing_struct_parse_info,
    9627              :                tree *expr)
    9628              : {
    9629      1179864 :   tree x;
    9630      1179864 :   bool toplevel = file_scope == current_scope;
    9631              : 
    9632              :   /* If this type was previously laid out as a forward reference,
    9633              :      make sure we lay it out again.  */
    9634              : 
    9635      1179864 :   TYPE_SIZE (t) = NULL_TREE;
    9636              : 
    9637      1179864 :   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    9638              : 
    9639      1179864 :   if (pedantic)
    9640              :     {
    9641         6871 :       for (x = fieldlist; x; x = DECL_CHAIN (x))
    9642              :         {
    9643         6852 :           if (DECL_NAME (x) != NULL_TREE)
    9644              :             break;
    9645           25 :           if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9646              :             break;
    9647              :         }
    9648              : 
    9649         6853 :       if (x == NULL_TREE)
    9650              :         {
    9651           19 :           if (TREE_CODE (t) == UNION_TYPE)
    9652              :             {
    9653            5 :               if (fieldlist)
    9654            2 :                 pedwarn (loc, OPT_Wpedantic, "union has no named members");
    9655              :               else
    9656            3 :                 pedwarn (loc, OPT_Wpedantic, "union has no members");
    9657              :             }
    9658              :           else
    9659              :             {
    9660           14 :               if (fieldlist)
    9661            3 :                 pedwarn (loc, OPT_Wpedantic, "struct has no named members");
    9662              :               else
    9663           11 :                 pedwarn (loc, OPT_Wpedantic, "struct has no members");
    9664              :             }
    9665              :         }
    9666              :     }
    9667              : 
    9668              :   /* Install struct as DECL_CONTEXT of each field decl.
    9669              :      Also process specified field sizes, found in the DECL_INITIAL,
    9670              :      storing 0 there after the type has been changed to precision equal
    9671              :      to its width, rather than the precision of the specified standard
    9672              :      type.  (Correct layout requires the original type to have been preserved
    9673              :      until now.)  */
    9674              : 
    9675              :   bool saw_named_field = false;
    9676      5489972 :   for (x = fieldlist; x; x = DECL_CHAIN (x))
    9677              :     {
    9678              :       /* Whether this field is the last field of the structure or union.
    9679              :          for UNION, any field is the last field of it.  */
    9680      4310108 :       bool is_last_field = (DECL_CHAIN (x) == NULL_TREE)
    9681      4310108 :                             || (TREE_CODE (t) == UNION_TYPE);
    9682              : 
    9683      4310108 :       if (TREE_TYPE (x) == error_mark_node)
    9684           40 :         continue;
    9685              : 
    9686      4310068 :       DECL_CONTEXT (x) = t;
    9687              : 
    9688      4310068 :       tree t1 = strip_array_types (TREE_TYPE (x));
    9689              :       /* If any field is const, the structure type is pseudo-const.  */
    9690      4310068 :       if (TREE_READONLY (x))
    9691        64244 :         C_TYPE_FIELDS_READONLY (t) = 1;
    9692              :       else
    9693              :         {
    9694              :           /* A field that is pseudo-const makes the structure likewise.  */
    9695      4245824 :           if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1))
    9696          641 :             C_TYPE_FIELDS_READONLY (t) = 1;
    9697              :         }
    9698              : 
    9699              :       /* Any field that is volatile means variables of this type must be
    9700              :          treated in some ways as volatile.  */
    9701      4310068 :       if (TREE_THIS_VOLATILE (x))
    9702              :         {
    9703          475 :           C_TYPE_FIELDS_VOLATILE (t) = 1;
    9704          475 :           C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9705              :         }
    9706              : 
    9707              :       /* Any field that is volatile, restrict-qualified or atomic
    9708              :          means the type cannot be used for a constexpr object.  */
    9709      4310068 :       if (TYPE_QUALS (t1)
    9710      4310068 :           & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    9711         1461 :         C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9712      4308607 :       else if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_NON_CONSTEXPR (t1))
    9713          179 :             C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9714              : 
    9715              :       /* Any field of nominal variable size implies structure is too.  */
    9716      4310068 :       if (C_DECL_VARIABLE_SIZE (x))
    9717          698 :         C_TYPE_VARIABLE_SIZE (t) = 1;
    9718              : 
    9719              :       /* If any field is variably modified, record this fact. */
    9720      4310068 :       if (c_type_variably_modified_p (TREE_TYPE (x)))
    9721          777 :         C_TYPE_VARIABLY_MODIFIED (t) = 1;
    9722              : 
    9723      4310068 :       if (DECL_C_BIT_FIELD (x))
    9724              :         {
    9725        52748 :           unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
    9726        52748 :           DECL_SIZE (x) = bitsize_int (width);
    9727        52748 :           DECL_BIT_FIELD (x) = 1;
    9728              :         }
    9729              : 
    9730      4310068 :       if (TYPE_PACKED (t)
    9731      4315621 :           && (DECL_BIT_FIELD (x)
    9732         3235 :               || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
    9733         4442 :         DECL_PACKED (x) = 1;
    9734              : 
    9735              :       /* Detect flexible array member in an invalid context.  */
    9736      4310068 :       if (c_flexible_array_member_type_p (TREE_TYPE (x)))
    9737              :         {
    9738        85992 :           if (TREE_CODE (t) == UNION_TYPE)
    9739           31 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9740              :                      "flexible array member in union is a GCC extension");
    9741        85961 :           else if (!is_last_field)
    9742              :             {
    9743            3 :               error_at (DECL_SOURCE_LOCATION (x),
    9744              :                         "flexible array member not at end of struct");
    9745            3 :               TREE_TYPE (x) = error_mark_node;
    9746              :             }
    9747        85958 :           else if (!saw_named_field)
    9748           36 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9749              :                      "flexible array member in a struct with no named "
    9750              :                      "members is a GCC extension");
    9751        85992 :           if (lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9752          133 :             C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9753              :         }
    9754              : 
    9755      4310068 :       if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE
    9756      4310068 :           && lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9757          264 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9758              : 
    9759              :       /* If the field is an anonymous structure that includes a field
    9760              :          with counted_by attribute, this structure should also be marked
    9761              :          too.  */
    9762      8242994 :       if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9763       467639 :           && C_TYPE_FIELDS_HAS_COUNTED_BY (TREE_TYPE (x))
    9764           18 :           && DECL_NAME (x) == NULL_TREE
    9765      4310081 :           && c_type_tag (TREE_TYPE (x)) == NULL_TREE)
    9766           12 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9767              : 
    9768        23108 :       if (pedantic && TREE_CODE (t) == RECORD_TYPE
    9769      4329221 :           && flexible_array_type_p (TREE_TYPE (x)))
    9770           18 :         pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9771              :                  "invalid use of structure with flexible array member");
    9772              : 
    9773              :       /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x.  */
    9774      4310068 :       DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x);
    9775              : 
    9776              :       /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t.
    9777              :          when x is an array and is the last field.
    9778              :          There is only one last_field for a structure type, but there might
    9779              :          be multiple last_fields for a union type, therefore we should ORed
    9780              :          the result for multiple last_fields.  */
    9781      4310068 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    9782       691168 :         TYPE_INCLUDES_FLEXARRAY (t)
    9783      1382336 :           |= is_last_field && c_flexible_array_member_type_p (TREE_TYPE (x));
    9784              :       /* Recursively set TYPE_INCLUDES_FLEXARRAY for the context of x, t
    9785              :          when x is an union or record and is the last field.  */
    9786      3618900 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9787       467639 :         TYPE_INCLUDES_FLEXARRAY (t)
    9788       935278 :           |= is_last_field && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x));
    9789              : 
    9790      4310068 :       if (warn_flex_array_member_not_at_end
    9791           56 :           && !is_last_field
    9792           22 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9793      4310080 :           && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x)))
    9794            5 :         warning_at (DECL_SOURCE_LOCATION (x),
    9795            5 :                     OPT_Wflex_array_member_not_at_end,
    9796              :                     "structure containing a flexible array member"
    9797              :                     " is not at the end of another structure");
    9798              : 
    9799      4310068 :       if (DECL_NAME (x)
    9800      4310068 :           || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9801              :         saw_named_field = true;
    9802              : 
    9803      7928968 :       if (AGGREGATE_TYPE_P (TREE_TYPE (x))
    9804      4777707 :           && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
    9805       417654 :         TYPE_TYPELESS_STORAGE (t) = true;
    9806              :     }
    9807              : 
    9808      1179864 :   detect_field_duplicates (fieldlist);
    9809              : 
    9810              :   /* Now we have the nearly final fieldlist.  Record it,
    9811              :      then lay out the structure or union (including the fields).  */
    9812              : 
    9813      1179864 :   TYPE_FIELDS (t) = fieldlist;
    9814              : 
    9815      1179864 :   maybe_apply_pragma_scalar_storage_order (t);
    9816              : 
    9817      1179864 :   layout_type (t);
    9818              : 
    9819      1179864 :   if (TYPE_SIZE_UNIT (t)
    9820      1179864 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    9821      1179221 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    9822      2359085 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    9823            1 :     error ("type %qT is too large", t);
    9824              : 
    9825              :   /* Give bit-fields their proper types and rewrite the type of array fields
    9826              :      with scalar component if the enclosing type has reverse storage order.  */
    9827      5489972 :   for (tree field = fieldlist; field; field = DECL_CHAIN (field))
    9828              :     {
    9829      4310108 :       if (TREE_CODE (field) == FIELD_DECL
    9830      4310108 :           && DECL_INITIAL (field)
    9831      4362866 :           && TREE_TYPE (field) != error_mark_node)
    9832              :         {
    9833        52748 :           unsigned HOST_WIDE_INT width
    9834        52748 :             = tree_to_uhwi (DECL_INITIAL (field));
    9835        52748 :           tree type = TREE_TYPE (field);
    9836        52748 :           if (VECTOR_TYPE_P (type))
    9837              :             {
    9838            2 :               error_at (DECL_SOURCE_LOCATION (field),
    9839              :                         "bit-field %qD has invalid type", field);
    9840            2 :               type = TREE_TYPE (type);
    9841            2 :               TREE_TYPE (field) = type;
    9842              :             }
    9843        52748 :           if (width != TYPE_PRECISION (type))
    9844              :             {
    9845        37860 :               if (BITINT_TYPE_P (type)
    9846        38140 :                   && width >= ((TYPE_UNSIGNED (type) || flag_isoc2y) ? 1 : 2))
    9847          171 :                 TREE_TYPE (field)
    9848          342 :                   = build_bitint_type (width, TYPE_UNSIGNED (type));
    9849              :               else
    9850        37854 :                 TREE_TYPE (field)
    9851        37854 :                   = c_build_bitfield_integer_type (width,
    9852        37854 :                                                    TYPE_UNSIGNED (type));
    9853        38025 :               if (tree attr = c_hardbool_type_attr (type))
    9854          281 :                 decl_attributes (&TREE_TYPE (field),
    9855              :                                  copy_list (attr),
    9856              :                                  0, NULL_TREE);
    9857        38025 :               SET_DECL_MODE (field, TYPE_MODE (TREE_TYPE (field)));
    9858              :             }
    9859        52748 :           DECL_INITIAL (field) = NULL_TREE;
    9860              :         }
    9861      4257360 :       else if (TYPE_REVERSE_STORAGE_ORDER (t)
    9862          695 :                && TREE_CODE (field) == FIELD_DECL
    9863      4258055 :                && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
    9864              :         {
    9865          107 :           tree ftype = TREE_TYPE (field);
    9866          107 :           tree ctype = strip_array_types (ftype);
    9867          107 :           if (!RECORD_OR_UNION_TYPE_P (ctype) && TYPE_MODE (ctype) != QImode)
    9868              :             {
    9869           94 :               tree fmain_type = TYPE_MAIN_VARIANT (ftype);
    9870           94 :               tree *typep = &fmain_type;
    9871           96 :               do {
    9872           96 :                 *typep = build_distinct_type_copy (*typep);
    9873           96 :                 TYPE_REVERSE_STORAGE_ORDER (*typep) = 1;
    9874           96 :                 typep = &TREE_TYPE (*typep);
    9875           96 :               } while (TREE_CODE (*typep) == ARRAY_TYPE);
    9876           94 :               TREE_TYPE (field)
    9877          188 :                 = c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
    9878              :             }
    9879              :         }
    9880              : 
    9881              :       /* Warn on problematic type punning for storage order purposes.  */
    9882      4310108 :       if (TREE_CODE (t) == UNION_TYPE
    9883       854688 :           && TREE_CODE (field) == FIELD_DECL
    9884      5164796 :           && AGGREGATE_TYPE_P (TREE_TYPE (field)))
    9885              :         {
    9886       425135 :           tree ftype = TREE_TYPE (field);
    9887       425135 :           if (TREE_CODE (ftype) == ARRAY_TYPE)
    9888       312994 :             ftype = strip_array_types (ftype);
    9889       425135 :           if (RECORD_OR_UNION_TYPE_P (ftype)
    9890       425135 :               && TYPE_REVERSE_STORAGE_ORDER (ftype)
    9891       112635 :                  != TYPE_REVERSE_STORAGE_ORDER (t))
    9892            1 :             warning_at (DECL_SOURCE_LOCATION (field),
    9893            1 :                         OPT_Wscalar_storage_order,
    9894              :                         "type punning toggles scalar storage order");
    9895              :         }
    9896              :     }
    9897              : 
    9898              :   /* Now we have the truly final field list.
    9899              :      Store it in this type and in the variants.  */
    9900              : 
    9901      1179864 :   TYPE_FIELDS (t) = fieldlist;
    9902              : 
    9903              :   /* If there are lots of fields, sort so we can look through them fast.
    9904              :      We arbitrarily consider 16 or more elts to be "a lot".  */
    9905              : 
    9906      1179864 :   {
    9907      1179864 :     int len = 0;
    9908              : 
    9909      5048100 :     for (x = fieldlist; x; x = DECL_CHAIN (x))
    9910              :       {
    9911      3895855 :         if (len > 15 || DECL_NAME (x) == NULL)
    9912              :           break;
    9913      3868236 :         len += 1;
    9914              :       }
    9915              : 
    9916      1179864 :     if (len > 15)
    9917              :       {
    9918        22726 :         tree *field_array;
    9919        22726 :         struct lang_type *space;
    9920        22726 :         struct sorted_fields_type *space2;
    9921              : 
    9922        22726 :         len += list_length (x);
    9923              : 
    9924              :         /* Use the same allocation policy here that make_node uses, to
    9925              :            ensure that this lives as long as the rest of the struct decl.
    9926              :            All decls in an inline function need to be saved.  */
    9927              : 
    9928        22726 :         space = ((struct lang_type *)
    9929        22726 :                  ggc_internal_cleared_alloc (c_dialect_objc ()
    9930              :                                              ? sizeof (struct lang_type)
    9931              :                                              : offsetof (struct lang_type,
    9932              :                                                          info)));
    9933        22726 :         space2 = ((sorted_fields_type *)
    9934        45452 :                   ggc_internal_alloc (sizeof (struct sorted_fields_type)
    9935        22726 :                                       + len * sizeof (tree)));
    9936              : 
    9937        22726 :         len = 0;
    9938        22726 :         space->s = space2;
    9939        22726 :         field_array = &space2->elts[0];
    9940       794718 :         for (x = fieldlist; x; x = DECL_CHAIN (x))
    9941              :           {
    9942       775360 :             field_array[len++] = x;
    9943              : 
    9944              :             /* If there is anonymous struct or union, break out of the loop.  */
    9945       775360 :             if (DECL_NAME (x) == NULL)
    9946              :               break;
    9947              :           }
    9948              :         /* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
    9949        22726 :         if (x == NULL)
    9950              :           {
    9951        19358 :             TYPE_LANG_SPECIFIC (t) = space;
    9952        19358 :             TYPE_LANG_SPECIFIC (t)->s->len = len;
    9953        19358 :             field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
    9954        19358 :             qsort (field_array, len, sizeof (tree), field_decl_cmp);
    9955              :           }
    9956              :       }
    9957              :   }
    9958              : 
    9959              :   /* If this was supposed to be a transparent union, but we can't
    9960              :      make it one, warn and turn off the flag.  */
    9961      1179864 :   if (TREE_CODE (t) == UNION_TYPE
    9962       378003 :       && TYPE_TRANSPARENT_AGGR (t)
    9963      1179909 :       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
    9964              :     {
    9965           13 :       TYPE_TRANSPARENT_AGGR (t) = 0;
    9966           13 :       warning_at (loc, 0, "union cannot be made transparent");
    9967              :     }
    9968              : 
    9969      1179864 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
    9970      2390619 :   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
    9971              :     {
    9972      1210755 :       TYPE_FIELDS (x) = TYPE_FIELDS (t);
    9973      1210755 :       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
    9974      1210755 :       TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
    9975      1210755 :       TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
    9976      1210755 :       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
    9977      1210755 :       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
    9978      1210755 :       C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);
    9979      1210755 :       C_TYPE_FIELDS_HAS_COUNTED_BY (x) = C_TYPE_FIELDS_HAS_COUNTED_BY (t);
    9980      1210755 :       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
    9981      1210755 :       C_TYPE_VARIABLY_MODIFIED (x) = C_TYPE_VARIABLY_MODIFIED (t);
    9982      1210755 :       C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
    9983      1210755 :       TYPE_INCLUDES_FLEXARRAY (x) = TYPE_INCLUDES_FLEXARRAY (t);
    9984              :     }
    9985              : 
    9986              :   /* Check for consistency with previous definition.  */
    9987      1179864 :   if (flag_isoc23 && NULL != enclosing_struct_parse_info)
    9988              :     {
    9989       912240 :       tree vistype = previous_tag (t);
    9990       912240 :       if (vistype
    9991          128 :           && TREE_CODE (vistype) == TREE_CODE (t)
    9992       912368 :           && !C_TYPE_BEING_DEFINED (vistype))
    9993              :         {
    9994          108 :           TYPE_STUB_DECL (t) = TYPE_STUB_DECL (vistype);
    9995          108 :           if (c_type_variably_modified_p (t))
    9996              :             {
    9997            7 :               error ("redefinition of struct or union %qT with variably "
    9998              :                      "modified type", t);
    9999            7 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10000            7 :                 inform (struct_parse_info->refloc, "originally defined here");
   10001              :             }
   10002          101 :           else if (!comptypes_same_p (t, vistype))
   10003              :             {
   10004           38 :               error ("redefinition of struct or union %qT", t);
   10005           38 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
   10006           38 :                 inform (struct_parse_info->refloc, "originally defined here");
   10007              :             }
   10008              :         }
   10009              :     }
   10010              : 
   10011      1179864 :   C_TYPE_BEING_DEFINED (t) = 0;
   10012              : 
   10013      1179864 :   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
   10014          684 :     for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
   10015          358 :       c_fixup_may_alias (x);
   10016              : 
   10017              :   /* Set type canonical based on equivalence class.  */
   10018      1179864 :   if (flag_isoc23 && !C_TYPE_VARIABLE_SIZE (t))
   10019              :     {
   10020       947582 :       if (c_struct_htab == NULL)
   10021        35576 :         c_struct_htab = hash_table<c_struct_hasher>::create_ggc (61);
   10022              : 
   10023       947582 :       hashval_t hash = c_struct_hasher::hash (t);
   10024              : 
   10025       947582 :       gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
   10026       947582 :       gcc_checking_assert (!TYPE_NAME (t)
   10027              :                            || TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE);
   10028              : 
   10029       947582 :       tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT);
   10030       947582 :       if (*e)
   10031        62857 :         TYPE_CANONICAL (t) = TYPE_CANONICAL (*e);
   10032              :       else
   10033              :         {
   10034       884725 :           TYPE_CANONICAL (t) = c_type_canonical (t);
   10035       884725 :           *e = t;
   10036              :         }
   10037       947582 :       c_update_type_canonical (t);
   10038              :     }
   10039              : 
   10040              :   /* Update type location to the one of the definition, instead of e.g.
   10041              :      a forward declaration.  */
   10042      1179864 :   if (TYPE_STUB_DECL (t))
   10043      1179864 :     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
   10044              : 
   10045              :   /* Finish debugging output for this type.  */
   10046      1179864 :   rest_of_type_compilation (t, toplevel);
   10047              : 
   10048      1179864 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10049              : 
   10050              : 
   10051      1179864 :   if (c_type_variably_modified_p (t))
   10052              :     {
   10053          716 :       c_update_variably_modified (t);
   10054              :       /* Make sure a DECL_EXPR is created for structs with VLA members.
   10055              :          Because we do not know the context, we always pass expr
   10056              :          to force creation of a BIND_EXPR which is required in some
   10057              :          contexts.  */
   10058          716 :       add_decl_expr (loc, t, expr, false);
   10059              :     }
   10060              : 
   10061      1179864 :   if (warn_cxx_compat)
   10062          575 :     warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
   10063              : 
   10064      1179864 :   if (NULL != enclosing_struct_parse_info)
   10065              :     {
   10066      1139311 :       delete struct_parse_info;
   10067              : 
   10068      1139311 :       struct_parse_info = enclosing_struct_parse_info;
   10069              : 
   10070              :       /* If this struct is defined inside a struct, add it to
   10071              :          struct_types.  */
   10072      1139311 :       if (warn_cxx_compat
   10073              :           && struct_parse_info != NULL
   10074          350 :           && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10075          345 :         struct_parse_info->struct_types.safe_push (t);
   10076              :      }
   10077              : 
   10078              :   /* Only when the enclosing struct/union type is not anonymous, do more
   10079              :      verification on the fields with counted_by attributes.  */
   10080      1179864 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (t) && c_type_tag (t) != NULL_TREE)
   10081          292 :     verify_counted_by_attribute (t, t);
   10082              : 
   10083      1179864 :   return t;
   10084              : }
   10085              : 
   10086              : static struct {
   10087              :   gt_pointer_operator new_value;
   10088              :   void *cookie;
   10089              : } resort_data;
   10090              : 
   10091              : /* This routine compares two fields like field_decl_cmp but using the
   10092              : pointer operator in resort_data.  */
   10093              : 
   10094              : static int
   10095         5441 : resort_field_decl_cmp (const void *x_p, const void *y_p)
   10096              : {
   10097         5441 :   const tree *const x = (const tree *) x_p;
   10098         5441 :   const tree *const y = (const tree *) y_p;
   10099              : 
   10100         5441 :   if (DECL_NAME (*x) == DECL_NAME (*y))
   10101              :     /* A nontype is "greater" than a type.  */
   10102            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
   10103         5441 :   if (DECL_NAME (*x) == NULL_TREE)
   10104              :     return -1;
   10105         5441 :   if (DECL_NAME (*y) == NULL_TREE)
   10106              :     return 1;
   10107         5441 :   {
   10108         5441 :     tree d1 = DECL_NAME (*x);
   10109         5441 :     tree d2 = DECL_NAME (*y);
   10110         5441 :     resort_data.new_value (&d1, &d1, resort_data.cookie);
   10111         5441 :     resort_data.new_value (&d2, &d2, resort_data.cookie);
   10112         5441 :     if (d1 < d2)
   10113         2765 :       return -1;
   10114              :   }
   10115         2676 :   return 1;
   10116              : }
   10117              : 
   10118              : /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
   10119              : 
   10120              : void
   10121            6 : resort_sorted_fields (void *obj,
   10122              :                       void * ARG_UNUSED (orig_obj),
   10123              :                       gt_pointer_operator new_value,
   10124              :                       void *cookie)
   10125              : {
   10126            6 :   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
   10127            6 :   resort_data.new_value = new_value;
   10128            6 :   resort_data.cookie = cookie;
   10129            6 :   qsort (&sf->elts[0], sf->len, sizeof (tree),
   10130              :          resort_field_decl_cmp);
   10131            6 : }
   10132              : 
   10133              : /* Lay out the type T, and its element type, and so on.  */
   10134              : 
   10135              : static void
   10136            0 : layout_array_type (tree t)
   10137              : {
   10138            0 :   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   10139            0 :     layout_array_type (TREE_TYPE (t));
   10140            0 :   layout_type (t);
   10141            0 : }
   10142              : 
   10143              : /* Begin compiling the definition of an enumeration type.
   10144              :    NAME is its name (or null if anonymous).
   10145              :    LOC is the enum's location.
   10146              :    FIXED_UNDERLYING_TYPE is the (C23) underlying type specified in the
   10147              :    definition.
   10148              :    Returns the type object, as yet incomplete.
   10149              :    Also records info about it so that build_enumerator
   10150              :    may be used to declare the individual values as they are read.  */
   10151              : 
   10152              : tree
   10153       182463 : start_enum (location_t loc, struct c_enum_contents *the_enum, tree name,
   10154              :             tree fixed_underlying_type, bool potential_nesting_p)
   10155              : {
   10156       182463 :   tree enumtype = NULL_TREE;
   10157       182463 :   location_t enumloc = UNKNOWN_LOCATION;
   10158              : 
   10159              :   /* If this is the real definition for a previous forward reference,
   10160              :      fill in the contents in the same object that used to be the
   10161              :      forward reference.  */
   10162              : 
   10163       182463 :   if (name != NULL_TREE)
   10164        72778 :     enumtype = lookup_tag (ENUMERAL_TYPE, name, true, &enumloc);
   10165              : 
   10166        72778 :   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   10167              :     {
   10168              :       /* If the type is currently being defined or if we have seen an
   10169              :          incomplete version which is now complete, this is a nested
   10170              :          redefinition.  The later happens if the redefinition occurs
   10171              :          inside the enum specifier itself.  */
   10172          196 :       if (C_TYPE_BEING_DEFINED (enumtype)
   10173          196 :           || (potential_nesting_p && TYPE_VALUES (enumtype) != NULL_TREE))
   10174            9 :         error_at (loc, "nested redefinition of %<enum %E%>", name);
   10175              : 
   10176              :       /* For C23 we allow redefinitions.  We set to zero and check for
   10177              :          consistency later.  */
   10178          375 :       if (flag_isoc23 && TYPE_VALUES (enumtype) != NULL_TREE)
   10179              :         enumtype = NULL_TREE;
   10180              :     }
   10181              : 
   10182       109855 :   if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   10183              :     {
   10184       182295 :       enumtype = make_node (ENUMERAL_TYPE);
   10185       182295 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10186       182295 :       SET_TYPE_STRUCTURAL_EQUALITY (enumtype);
   10187       182295 :       pushtag (loc, name, enumtype);
   10188       182295 :       if (fixed_underlying_type != NULL_TREE)
   10189              :         {
   10190              :           /* For an enum definition with a fixed underlying type, the
   10191              :              type is complete during the definition and the
   10192              :              enumeration constants have that type.  If there was a
   10193              :              tag, the type was completed in c_parser_enum_specifier.
   10194              :              If not, it must be completed here.  */
   10195           12 :           ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = true;
   10196           12 :           TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (fixed_underlying_type);
   10197           12 :           TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (fixed_underlying_type);
   10198           12 :           TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (fixed_underlying_type);
   10199           12 :           SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (fixed_underlying_type));
   10200           12 :           TYPE_SIZE (enumtype) = NULL_TREE;
   10201           12 :           TYPE_PRECISION (enumtype) = TYPE_PRECISION (fixed_underlying_type);
   10202           12 :           ENUM_UNDERLYING_TYPE (enumtype) = fixed_underlying_type;
   10203           12 :           TYPE_CANONICAL (enumtype) = TYPE_CANONICAL (fixed_underlying_type);
   10204           12 :           c_update_type_canonical (enumtype);
   10205           12 :           layout_type (enumtype);
   10206              :         }
   10207              :     }
   10208              :   /* Update type location to the one of the definition, instead of e.g.
   10209              :      a forward declaration.  */
   10210          168 :   else if (TYPE_STUB_DECL (enumtype))
   10211              :     {
   10212          168 :       enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
   10213          168 :       DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
   10214              :     }
   10215              : 
   10216       182463 :   C_TYPE_BEING_DEFINED (enumtype) = 1;
   10217              : 
   10218       182463 :   if (TYPE_VALUES (enumtype) != NULL_TREE)
   10219              :     {
   10220              :       /* This enum is a named one that has been declared already.  */
   10221            6 :       auto_diagnostic_group d;
   10222            6 :       error_at (loc, "redeclaration of %<enum %E%>", name);
   10223            6 :       if (enumloc != UNKNOWN_LOCATION)
   10224            6 :         inform (enumloc, "originally defined here");
   10225              : 
   10226              :       /* Completely replace its old definition.
   10227              :          The old enumerators remain defined, however.  */
   10228            6 :       TYPE_VALUES (enumtype) = NULL_TREE;
   10229            6 :     }
   10230              : 
   10231       182463 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype)
   10232       182463 :       && fixed_underlying_type == NULL_TREE)
   10233              :     {
   10234            3 :       error_at (loc, "%<enum%> declared with but defined without "
   10235              :                 "fixed underlying type");
   10236            3 :       ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false;
   10237              :     }
   10238              : 
   10239       182463 :   the_enum->enum_next_value = integer_zero_node;
   10240       182463 :   the_enum->enum_type = enumtype;
   10241       182463 :   the_enum->enum_overflow = 0;
   10242              : 
   10243       182463 :   if (flag_short_enums && !ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10244          106 :     for (tree v = TYPE_MAIN_VARIANT (enumtype); v; v = TYPE_NEXT_VARIANT (v))
   10245           53 :       TYPE_PACKED (v) = 1;
   10246              : 
   10247              :   /* FIXME: This will issue a warning for a use of a type defined
   10248              :      within sizeof in a statement expr.  This is not terribly serious
   10249              :      as C++ doesn't permit statement exprs within sizeof anyhow.  */
   10250       182463 :   if (warn_cxx_compat
   10251          131 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
   10252            0 :     warning_at (loc, OPT_Wc___compat,
   10253              :                 "defining type in %qs expression is invalid in C++",
   10254              :                 (in_sizeof ? "sizeof"
   10255            0 :                  : in_typeof ? "typeof"
   10256            0 :                  : in_alignof ? "alignof"
   10257              :                  : "_Countof"));
   10258              : 
   10259       182463 :   if (in_underspecified_init)
   10260            6 :     error_at (loc, "%qT defined in underspecified object initializer",
   10261              :               enumtype);
   10262              : 
   10263       182463 :   return enumtype;
   10264              : }
   10265              : 
   10266              : /* After processing and defining all the values of an enumeration type,
   10267              :    install their decls in the enumeration type and finish it off.
   10268              :    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
   10269              :    and ATTRIBUTES are the specified attributes.
   10270              :    Returns ENUMTYPE.  */
   10271              : 
   10272              : tree
   10273       182463 : finish_enum (tree enumtype, tree values, tree attributes)
   10274              : {
   10275       182463 :   tree pair, tem;
   10276       182463 :   tree minnode = NULL_TREE, maxnode = NULL_TREE;
   10277       182463 :   int precision;
   10278       182463 :   signop sign;
   10279       182463 :   bool toplevel = (file_scope == current_scope);
   10280       182463 :   struct lang_type *lt;
   10281              : 
   10282       182463 :   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
   10283              : 
   10284              :   /* Calculate the maximum value of any enumerator in this type.  */
   10285              : 
   10286       182463 :   if (values == error_mark_node)
   10287           26 :     minnode = maxnode = integer_zero_node;
   10288              :   else
   10289              :     {
   10290       182437 :       minnode = maxnode = TREE_VALUE (values);
   10291      5731930 :       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
   10292              :         {
   10293      5549493 :           tree value = TREE_VALUE (pair);
   10294      5549493 :           if (tree_int_cst_lt (maxnode, value))
   10295      5401012 :             maxnode = value;
   10296      5549493 :           if (tree_int_cst_lt (value, minnode))
   10297        65189 :             minnode = value;
   10298              :         }
   10299              :     }
   10300              : 
   10301              :   /* Construct the final type of this enumeration.  It is the same
   10302              :      as one of the integral types - the narrowest one that fits, except
   10303              :      that normally we only go as narrow as int - and signed iff any of
   10304              :      the values are negative.  */
   10305       182463 :   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
   10306       182463 :   precision = MAX (tree_int_cst_min_precision (minnode, sign),
   10307              :                    tree_int_cst_min_precision (maxnode, sign));
   10308              : 
   10309       182463 :   bool wider_than_int =
   10310       182463 :     (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
   10311       182463 :      || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode));
   10312              : 
   10313              : 
   10314       182463 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10315              :     {
   10316              :       /* If the precision of the type was specified with an attribute and it
   10317              :          was too small, give an error.  Otherwise, use it.  */
   10318       182326 :       if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes))
   10319              :         {
   10320           23 :           if (precision > TYPE_PRECISION (enumtype))
   10321              :             {
   10322            6 :               TYPE_PRECISION (enumtype) = 0;
   10323            6 :               error ("specified mode too small for enumerated values");
   10324              :             }
   10325              :           else
   10326           17 :             precision = TYPE_PRECISION (enumtype);
   10327              :         }
   10328              :       else
   10329       182303 :         TYPE_PRECISION (enumtype) = 0;
   10330              : 
   10331       182326 :       if (TYPE_PACKED (enumtype)
   10332       182247 :           || precision > TYPE_PRECISION (integer_type_node)
   10333       361553 :           || TYPE_PRECISION (enumtype))
   10334              :         {
   10335         3226 :           tem = c_common_type_for_size (precision, sign == UNSIGNED ? 1 : 0);
   10336         3111 :           if (tem == NULL)
   10337              :             {
   10338              :               /* This should only occur when both signed and unsigned
   10339              :                  values of maximum precision occur among the
   10340              :                  enumerators.  */
   10341            3 :               pedwarn (input_location, 0,
   10342              :                        "enumeration values exceed range of largest integer");
   10343            3 :               tem = widest_integer_literal_type_node;
   10344              :             }
   10345         3108 :           else if (precision > TYPE_PRECISION (intmax_type_node)
   10346            4 :                    && !tree_int_cst_lt (minnode,
   10347            4 :                                         TYPE_MIN_VALUE (intmax_type_node))
   10348         3111 :                    && !tree_int_cst_lt (TYPE_MAX_VALUE (uintmax_type_node),
   10349              :                                         maxnode))
   10350            2 :             pedwarn (input_location, OPT_Wpedantic,
   10351              :                      "enumeration values exceed range of %qs",
   10352              :                      sign == UNSIGNED ? "uintmax_t" : "intmax_t");
   10353              :         }
   10354              :       else
   10355       179215 :         tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
   10356              : 
   10357       182326 :       TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
   10358       182326 :       TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
   10359       182326 :       TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
   10360       182326 :       SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (tem));
   10361       182326 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10362       182326 :       TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
   10363       182326 :       ENUM_UNDERLYING_TYPE (enumtype) =
   10364       182326 :         c_common_type_for_size (TYPE_PRECISION (tem), TYPE_UNSIGNED (tem));
   10365              : 
   10366       546978 :       TYPE_CANONICAL (enumtype) =
   10367       182326 :         TYPE_CANONICAL (ENUM_UNDERLYING_TYPE (enumtype));
   10368       182326 :       c_update_type_canonical (enumtype);
   10369              : 
   10370       182326 :       layout_type (enumtype);
   10371              :     }
   10372              : 
   10373       182463 :   if (values != error_mark_node)
   10374              :     {
   10375              :       /* Change the type of the enumerators to be the enum type.  We
   10376              :          need to do this irrespective of the size of the enum, for
   10377              :          proper type checking.  Replace the DECL_INITIALs of the
   10378              :          enumerators, and the value slots of the list, with copies
   10379              :          that have the enum type; they cannot be modified in place
   10380              :          because they may be shared (e.g.  integer_zero_node) Finally,
   10381              :          change the purpose slots to point to the names of the decls.  */
   10382      5914367 :       for (pair = values; pair; pair = TREE_CHAIN (pair))
   10383              :         {
   10384      5731930 :           tree enu = TREE_PURPOSE (pair);
   10385      5731930 :           tree ini = DECL_INITIAL (enu);
   10386              : 
   10387      5731930 :           TREE_TYPE (enu) = enumtype;
   10388              : 
   10389              :           /* Before C23, the ISO C Standard mandates enumerators to
   10390              :              have type int, even though the underlying type of an enum
   10391              :              type is unspecified.  However, C23 allows enumerators of
   10392              :              any integer type, and if an enumeration has any
   10393              :              enumerators wider than int, all enumerators have the
   10394              :              enumerated type after it is parsed.  Any enumerators that
   10395              :              fit in int are given type int in build_enumerator (which
   10396              :              is the correct type while the enumeration is being
   10397              :              parsed), so no conversions are needed here if all
   10398              :              enumerators fit in int.  If the enum has a fixed
   10399              :              underlying type, the correct type was also given in
   10400              :              build_enumerator.  */
   10401      5731930 :           if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) && wider_than_int)
   10402        33934 :             ini = convert (enumtype, ini);
   10403              : 
   10404      5731930 :           DECL_INITIAL (enu) = ini;
   10405      5731930 :           TREE_PURPOSE (pair) = DECL_NAME (enu);
   10406              :           /* To match the C++ FE, store the CONST_DECL rather than just its
   10407              :              value.  */
   10408      5731930 :           TREE_VALUE (pair) = enu;
   10409              :         }
   10410              : 
   10411       182437 :       TYPE_VALUES (enumtype) = values;
   10412              :     }
   10413              : 
   10414              :   /* Record the min/max values so that we can warn about bit-field
   10415              :      enumerations that are too small for the values.  */
   10416       182463 :   lt = ((struct lang_type *)
   10417       182463 :         ggc_internal_cleared_alloc (c_dialect_objc ()
   10418              :                                     ? sizeof (struct lang_type)
   10419              :                                     : offsetof (struct lang_type, info)));
   10420       182463 :   lt->enum_min = minnode;
   10421       182463 :   lt->enum_max = maxnode;
   10422       182463 :   TYPE_LANG_SPECIFIC (enumtype) = lt;
   10423              : 
   10424              :   /* Fix up all variant types of this enum type.  */
   10425       182463 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (enumtype));
   10426       364936 :   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
   10427              :     {
   10428       182473 :       C_TYPE_INCOMPLETE_VARS (tem) = NULL_TREE;
   10429       182473 :       if (tem == enumtype)
   10430       182463 :         continue;
   10431           10 :       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
   10432           10 :       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
   10433           10 :       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
   10434           10 :       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
   10435           10 :       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
   10436           10 :       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
   10437           10 :       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
   10438           10 :       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
   10439           10 :       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
   10440           10 :       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
   10441           10 :       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
   10442           10 :       ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
   10443           10 :       TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
   10444              :     }
   10445              : 
   10446              :   /* Finish debugging output for this type.  */
   10447       182463 :   rest_of_type_compilation (enumtype, toplevel);
   10448              : 
   10449       182463 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10450              : 
   10451              :   /* If this enum is defined inside a struct, add it to
   10452              :      struct_types.  */
   10453       182463 :   if (warn_cxx_compat
   10454          131 :       && struct_parse_info != NULL
   10455           42 :       && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10456           42 :     struct_parse_info->struct_types.safe_push (enumtype);
   10457              : 
   10458              :   /* Check for consistency with previous definition */
   10459       182463 :   if (flag_isoc23)
   10460              :     {
   10461       144372 :       tree vistype = previous_tag (enumtype);
   10462       144372 :       if (vistype
   10463           33 :           && TREE_CODE (vistype) == TREE_CODE (enumtype)
   10464       144401 :           && !C_TYPE_BEING_DEFINED (vistype))
   10465              :         {
   10466           29 :           TYPE_STUB_DECL (enumtype) = TYPE_STUB_DECL (vistype);
   10467           29 :           if (!comptypes_same_p (enumtype, vistype))
   10468            3 :             error("conflicting redefinition of enum %qT", enumtype);
   10469              :         }
   10470              :     }
   10471              : 
   10472       182463 :   C_TYPE_BEING_DEFINED (enumtype) = 0;
   10473              : 
   10474       182463 :   return enumtype;
   10475              : }
   10476              : 
   10477              : /* Build and install a CONST_DECL for one value of the
   10478              :    current enumeration type (one that was begun with start_enum).
   10479              :    DECL_LOC is the location of the enumerator.
   10480              :    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
   10481              :    Return a tree-list containing the CONST_DECL and its value.
   10482              :    Assignment of sequential values by default is handled here.  */
   10483              : 
   10484              : tree
   10485      5731947 : build_enumerator (location_t decl_loc, location_t loc,
   10486              :                   struct c_enum_contents *the_enum, tree name, tree value)
   10487              : {
   10488      5731947 :   tree decl;
   10489      5731947 :   tree old_decl;
   10490              : 
   10491              :   /* Validate and default VALUE.  */
   10492              : 
   10493      5731947 :   if (value != NULL_TREE)
   10494              :     {
   10495              :       /* Don't issue more errors for error_mark_node (i.e. an
   10496              :          undeclared identifier) - just ignore the value expression.  */
   10497      3569638 :       if (value == error_mark_node)
   10498              :         value = NULL_TREE;
   10499      3568973 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
   10500              :         {
   10501            6 :           error_at (loc, "enumerator value for %qE is not an integer constant",
   10502              :                     name);
   10503            6 :           value = NULL_TREE;
   10504              :         }
   10505              :       else
   10506              :         {
   10507      3568967 :           if (TREE_CODE (value) != INTEGER_CST)
   10508              :             {
   10509           97 :               value = c_fully_fold (value, false, NULL);
   10510           97 :               if (TREE_CODE (value) == INTEGER_CST)
   10511           48 :                 pedwarn (loc, OPT_Wpedantic,
   10512              :                          "enumerator value for %qE is not an integer "
   10513              :                          "constant expression", name);
   10514              :             }
   10515      3568967 :           if (TREE_CODE (value) != INTEGER_CST)
   10516              :             {
   10517           49 :               error ("enumerator value for %qE is not an integer constant",
   10518              :                      name);
   10519           49 :               value = NULL_TREE;
   10520              :             }
   10521              :           else
   10522              :             {
   10523      3568918 :               value = default_conversion (value);
   10524      3568918 :               constant_expression_warning (value);
   10525              :             }
   10526              :         }
   10527              :     }
   10528              : 
   10529              :   /* Default based on previous value.  */
   10530              :   /* It should no longer be possible to have NON_LVALUE_EXPR
   10531              :      in the default.  */
   10532      3568973 :   if (value == NULL_TREE)
   10533              :     {
   10534      2163029 :       value = the_enum->enum_next_value;
   10535      2163029 :       if (the_enum->enum_overflow)
   10536            8 :         error_at (loc, "overflow in enumeration values");
   10537              :     }
   10538      5731947 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10539              :     {
   10540              :       /* Enumeration constants must fit in the fixed underlying type.  */
   10541          200 :       if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (the_enum->enum_type)))
   10542            4 :         error_at (loc,
   10543              :                   "enumerator value outside the range of underlying type");
   10544              :       /* Enumeration constants for an enum with fixed underlying type
   10545              :          have the enum type, both inside and outside the
   10546              :          definition.  */
   10547          200 :       value = convert (the_enum->enum_type, value);
   10548              :     }
   10549      5731747 :   else if (flag_isoc23
   10550      5315043 :            && (old_decl = lookup_name_in_scope (name, current_scope))
   10551           35 :            && old_decl != error_mark_node
   10552           35 :            && TREE_TYPE (old_decl)
   10553           35 :            && TREE_TYPE (TREE_TYPE (old_decl))
   10554      5731781 :            && TREE_CODE (old_decl) == CONST_DECL)
   10555              :     {
   10556              :       /* Enumeration constants in a redeclaration have the previous type.  */
   10557           34 :       tree previous_type = TREE_TYPE (DECL_INITIAL (old_decl));
   10558           34 :       if (!int_fits_type_p (value, previous_type))
   10559              :         {
   10560            2 :           error_at (loc, "value of redeclared enumerator outside the range "
   10561              :                          "of %qT", previous_type);
   10562            2 :           locate_old_decl (old_decl);
   10563              :         }
   10564           34 :       value = convert (previous_type, value);
   10565              :     }
   10566              :   else
   10567              :     {
   10568              :       /* Even though the underlying type of an enum is unspecified, the
   10569              :          type of enumeration constants is explicitly defined as int
   10570              :          (6.4.4.3/2 in the C99 Standard).  C23 allows any integer type, and
   10571              :          GCC allows such types for older standards as an extension.  */
   10572      5731713 :       bool warned_range = false;
   10573      5731713 :       if (!int_fits_type_p (value,
   10574      5731713 :                             (TYPE_UNSIGNED (TREE_TYPE (value))
   10575              :                              ? uintmax_type_node
   10576              :                              : intmax_type_node)))
   10577              :         /* GCC does not consider its types larger than intmax_t to be
   10578              :            extended integer types (although C23 would permit such types to
   10579              :            be considered extended integer types if all the features
   10580              :            required by <stdint.h> and <inttypes.h> macros, such as support
   10581              :            for integer constants and I/O, were present), so diagnose if
   10582              :            such a wider type is used.  (If the wider type arose from a
   10583              :            constant of such a type, that will also have been diagnosed,
   10584              :            but this is the only diagnostic in the case where it arises
   10585              :            from choosing a wider type automatically when adding 1
   10586              :            overflows.)  */
   10587           11 :         warned_range = pedwarn (loc, OPT_Wpedantic,
   10588              :                                 "enumerator value outside the range of %qs",
   10589           11 :                                 TYPE_UNSIGNED (TREE_TYPE (value))
   10590              :                                 ? "uintmax_t"
   10591              :                                 : "intmax_t");
   10592      5731713 :       if (!warned_range && !int_fits_type_p (value, integer_type_node))
   10593         5207 :         pedwarn_c11 (loc, OPT_Wpedantic,
   10594              :                      "ISO C restricts enumerator values to range of %<int%> "
   10595              :                      "before C23");
   10596              : 
   10597              :       /* The ISO C Standard mandates enumerators to have type int before
   10598              :          C23, even though the underlying type of an enum type is
   10599              :          unspecified.  C23 allows enumerators of any integer type.  During
   10600              :          the parsing of the enumeration, C23 specifies that constants
   10601              :          representable in int have type int, constants not representable
   10602              :          in int have the type of the given expression if any, and
   10603              :          constants not representable in int and derived by adding 1 to the
   10604              :          previous constant have the type of that constant unless the
   10605              :          addition would overflow or wraparound, in which case a wider type
   10606              :          of the same signedness is chosen automatically; after the
   10607              :          enumeration is parsed, all the constants have the type of the
   10608              :          enumeration if any do not fit in int.  */
   10609      5731713 :       if (int_fits_type_p (value, integer_type_node))
   10610      5726502 :         value = convert (integer_type_node, value);
   10611              :     }
   10612              : 
   10613              :   /* Set basis for default for next value.  */
   10614      5731947 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10615              :     {
   10616          200 :       tree underlying_type = ENUM_UNDERLYING_TYPE (the_enum->enum_type);
   10617          200 :       if (TREE_CODE (underlying_type) == BOOLEAN_TYPE)
   10618              :         /* A value of 2 following a value of 1 overflows bool, but we
   10619              :            cannot carry out addition directly on bool without
   10620              :            promotion, and converting the result of arithmetic in a
   10621              :            wider type back to bool would not produce the right result
   10622              :            for this overflow check.  */
   10623           61 :         the_enum->enum_next_value = invert_truthvalue_loc (loc, value);
   10624              :       else
   10625          139 :         the_enum->enum_next_value
   10626          139 :           = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10627              :                              PLUS_EXPR, convert (underlying_type, value),
   10628              :                              convert (underlying_type, integer_one_node),
   10629              :                              false);
   10630              :     }
   10631              :   else
   10632              :     {
   10633              :       /* In a redeclaration the type can already be the enumeral type.  */
   10634      5731747 :       if (TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
   10635           12 :         value = convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (value)), value);
   10636      5731747 :       the_enum->enum_next_value
   10637      5731747 :         = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10638              :                            PLUS_EXPR, value, integer_one_node, false);
   10639              :     }
   10640      5731947 :   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
   10641      5731947 :   if (the_enum->enum_overflow
   10642      5731947 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10643              :     {
   10644              :       /* Choose a wider type with the same signedness if
   10645              :          available.  */
   10646         4398 :       int prec = TYPE_PRECISION (TREE_TYPE (value)) + 1;
   10647         4398 :       bool unsignedp = TYPE_UNSIGNED (TREE_TYPE (value));
   10648         4398 :       tree new_type = (unsignedp
   10649         4398 :                        ? long_unsigned_type_node
   10650              :                        : long_integer_type_node);
   10651         4398 :       if (prec > TYPE_PRECISION (new_type))
   10652         3465 :         new_type = (unsignedp
   10653         3465 :                     ? long_long_unsigned_type_node
   10654              :                     : long_long_integer_type_node);
   10655         4398 :       if (prec > TYPE_PRECISION (new_type))
   10656         2903 :         new_type = (unsignedp
   10657         2903 :                     ? widest_unsigned_literal_type_node
   10658              :                     : widest_integer_literal_type_node);
   10659         4398 :       if (prec <= TYPE_PRECISION (new_type))
   10660              :         {
   10661         4393 :           the_enum->enum_overflow = false;
   10662         4393 :           the_enum->enum_next_value
   10663         4393 :             = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10664              :                                PLUS_EXPR, convert (new_type, value),
   10665              :                                integer_one_node, false);
   10666         4393 :           gcc_assert (!tree_int_cst_lt (the_enum->enum_next_value, value));
   10667              :         }
   10668              :     }
   10669              : 
   10670              :   /* Now create a declaration for the enum value name.  */
   10671              : 
   10672      5731947 :   decl = build_decl (decl_loc, CONST_DECL, name, TREE_TYPE (value));
   10673      5731947 :   DECL_INITIAL (decl) = value;
   10674      5731947 :   DECL_CONTEXT (decl) = the_enum->enum_type;
   10675      5731947 :   pushdecl (decl);
   10676              : 
   10677      5731947 :   return tree_cons (decl, value, NULL_TREE);
   10678              : }
   10679              : 
   10680              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   10681              : 
   10682              : tree
   10683            0 : c_simulate_enum_decl (location_t loc, const char *name,
   10684              :                       vec<string_int_pair> *values_ptr)
   10685              : {
   10686            0 :   location_t saved_loc = input_location;
   10687            0 :   input_location = loc;
   10688              : 
   10689            0 :   struct c_enum_contents the_enum;
   10690            0 :   tree enumtype = start_enum (loc, &the_enum, get_identifier (name),
   10691              :                               NULL_TREE, false);
   10692              : 
   10693            0 :   tree value_chain = NULL_TREE;
   10694            0 :   string_int_pair *value;
   10695            0 :   vec<string_int_pair> values = *values_ptr;
   10696            0 :   unsigned int i;
   10697            0 :   FOR_EACH_VEC_ELT (values, i, value)
   10698              :     {
   10699            0 :       tree decl = build_enumerator (loc, loc, &the_enum,
   10700              :                                     get_identifier (value->first),
   10701              :                                     build_int_cst (integer_type_node,
   10702            0 :                                                    value->second));
   10703            0 :       TREE_CHAIN (decl) = value_chain;
   10704            0 :       value_chain = decl;
   10705              :     }
   10706              : 
   10707            0 :   finish_enum (enumtype, nreverse (value_chain), NULL_TREE);
   10708              : 
   10709            0 :   input_location = saved_loc;
   10710            0 :   return enumtype;
   10711              : }
   10712              : 
   10713              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   10714              : 
   10715              : tree
   10716            0 : c_simulate_record_decl (location_t loc, const char *name,
   10717              :                         array_slice<const tree> fields)
   10718              : {
   10719            0 :   location_t saved_loc = input_location;
   10720            0 :   input_location = loc;
   10721              : 
   10722            0 :   class c_struct_parse_info *struct_info;
   10723            0 :   tree ident = get_identifier (name);
   10724            0 :   tree type = start_struct (loc, RECORD_TYPE, ident, &struct_info);
   10725              : 
   10726            0 :   for (unsigned int i = 0; i < fields.size (); ++i)
   10727              :     {
   10728            0 :       DECL_FIELD_CONTEXT (fields[i]) = type;
   10729            0 :       if (i > 0)
   10730            0 :         DECL_CHAIN (fields[i - 1]) = fields[i];
   10731              :     }
   10732              : 
   10733            0 :   finish_struct (loc, type, fields[0], NULL_TREE, struct_info);
   10734              : 
   10735            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   10736            0 :   set_underlying_type (decl);
   10737            0 :   lang_hooks.decls.pushdecl (decl);
   10738              : 
   10739            0 :   input_location = saved_loc;
   10740            0 :   return type;
   10741              : }
   10742              : 
   10743              : /* Create the FUNCTION_DECL for a function definition.
   10744              :    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
   10745              :    the declaration; they describe the function's name and the type it returns,
   10746              :    but twisted together in a fashion that parallels the syntax of C.
   10747              : 
   10748              :    This function creates a binding context for the function body
   10749              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   10750              : 
   10751              :    Returns true on success.  If the DECLARATOR is not suitable for a function
   10752              :    (it defines a datum instead), we return false to report a parse error.  */
   10753              : 
   10754              : bool
   10755     36326467 : start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   10756              :                 tree attributes)
   10757              : {
   10758     36326467 :   tree decl1, old_decl;
   10759     36326467 :   tree restype, resdecl;
   10760     36326467 :   location_t loc;
   10761     36326467 :   location_t result_loc;
   10762     36326467 :   tree expr = NULL;
   10763              : 
   10764     36326467 :   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   10765     36326467 :   current_function_returns_null = 0;
   10766     36326467 :   current_function_returns_abnormally = 0;
   10767     36326467 :   warn_about_return_type = 0;
   10768     36326467 :   c_switch_stack = NULL;
   10769              : 
   10770              :   /* Indicate no valid break/continue context.  */
   10771     36326467 :   in_statement = 0;
   10772              : 
   10773     36326467 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
   10774              :                           &attributes, &expr, NULL, DEPRECATED_NORMAL);
   10775     36326467 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   10776              : 
   10777              :   /* If the declarator is not suitable for a function definition,
   10778              :      cause a syntax error.  */
   10779     36326467 :   if (decl1 == NULL_TREE
   10780     36326436 :       || TREE_CODE (decl1) != FUNCTION_DECL)
   10781              :     return false;
   10782              : 
   10783              :   /* Nested functions may have variably modified (return) type.
   10784              :      Make sure the size expression is evaluated at this point.  */
   10785     36326429 :   if (expr && !current_scope->parm_flag)
   10786           11 :     add_stmt (fold_convert (void_type_node, expr));
   10787              : 
   10788     36326429 :   loc = DECL_SOURCE_LOCATION (decl1);
   10789              : 
   10790              :   /* A nested function is not global.  */
   10791     36326429 :   if (current_function_decl != NULL_TREE)
   10792         1594 :     TREE_PUBLIC (decl1) = 0;
   10793              : 
   10794     36326429 :   c_decl_attributes (&decl1, attributes, 0);
   10795              : 
   10796     36326429 :   if (DECL_DECLARED_INLINE_P (decl1)
   10797     35634883 :       && DECL_UNINLINABLE (decl1)
   10798     36326440 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
   10799              :     {
   10800            3 :       auto_urlify_attributes sentinel;
   10801            3 :       warning_at (loc, OPT_Wattributes,
   10802              :                   "inline function %qD given attribute %qs",
   10803              :                   decl1, "noinline");
   10804            3 :     }
   10805              : 
   10806              :   /* Handle gnu_inline attribute.  */
   10807     36326429 :   if (declspecs->inline_p
   10808     35634886 :       && !flag_gnu89_inline
   10809     35600789 :       && TREE_CODE (decl1) == FUNCTION_DECL
   10810     71927218 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
   10811       159042 :           || current_function_decl))
   10812              :     {
   10813     35441819 :       if (declspecs->storage_class != csc_static)
   10814     35441813 :         DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
   10815              :     }
   10816              : 
   10817     36326429 :   announce_function (decl1);
   10818              : 
   10819     36326429 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
   10820              :     {
   10821            1 :       error_at (loc, "return type is an incomplete type");
   10822              :       /* Make it return void instead.  */
   10823            1 :       TREE_TYPE (decl1)
   10824            2 :         = c_build_function_type (void_type_node,
   10825            1 :                                  TYPE_ARG_TYPES (TREE_TYPE (decl1)),
   10826            1 :                                  TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl1)));
   10827              :     }
   10828              : 
   10829     36326429 :   if (warn_about_return_type)
   10830         1404 :     permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int
   10831            0 :                    : (warn_return_type > 0 ? OPT_Wreturn_type
   10832              :                       : OPT_Wimplicit_int),
   10833              :                    "return type defaults to %<int%>");
   10834              : 
   10835              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   10836              :      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
   10837     36326429 :   DECL_INITIAL (decl1) = error_mark_node;
   10838              : 
   10839              :   /* If this definition isn't a prototype and we had a prototype declaration
   10840              :      before, copy the arg type info from that prototype.  */
   10841     36326429 :   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
   10842     36326429 :   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
   10843     36096431 :     old_decl = NULL_TREE;
   10844              : 
   10845     36326429 :   current_function_prototype_locus = UNKNOWN_LOCATION;
   10846     36326429 :   current_function_prototype_built_in = false;
   10847     36326429 :   current_function_prototype_arg_types = NULL_TREE;
   10848     36326429 :   tree newtype = TREE_TYPE (decl1);
   10849     36326429 :   tree oldtype = old_decl ? TREE_TYPE (old_decl) : newtype;
   10850     36326429 :   if (!prototype_p (newtype))
   10851              :     {
   10852        13138 :       tree oldrt = TREE_TYPE (oldtype);
   10853        13138 :       tree newrt = TREE_TYPE (newtype);
   10854        13138 :       if (old_decl != NULL_TREE
   10855          317 :           && TREE_CODE (oldtype) == FUNCTION_TYPE
   10856          317 :           && comptypes (oldrt, newrt)
   10857        13436 :           && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype))
   10858              :         {
   10859          297 :           if (stdarg_p (oldtype))
   10860              :             {
   10861            1 :               auto_diagnostic_group d;
   10862            1 :               warning_at (loc, 0, "%q+D defined as variadic function "
   10863              :                           "without prototype", decl1);
   10864            1 :               locate_old_decl (old_decl);
   10865            1 :             }
   10866          297 :           TREE_TYPE (decl1) = composite_type (oldtype, newtype);
   10867          297 :           current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
   10868          297 :           current_function_prototype_built_in
   10869          297 :             = C_DECL_BUILTIN_PROTOTYPE (old_decl);
   10870          297 :           current_function_prototype_arg_types
   10871          297 :             = TYPE_ARG_TYPES (newtype);
   10872              :         }
   10873        13138 :       if (TREE_PUBLIC (decl1))
   10874              :         {
   10875              :           /* If there is an external prototype declaration of this
   10876              :              function, record its location but do not copy information
   10877              :              to this decl.  This may be an invisible declaration
   10878              :              (built-in or in a scope which has finished) or simply
   10879              :              have more refined argument types than any declaration
   10880              :              found above.  */
   10881        12723 :           struct c_binding *b;
   10882        12999 :           for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
   10883          713 :             if (B_IN_SCOPE (b, external_scope))
   10884              :               break;
   10885        12723 :           if (b)
   10886              :             {
   10887          437 :               tree ext_decl, ext_type;
   10888          437 :               ext_decl = b->decl;
   10889          437 :               ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
   10890          437 :               if (TREE_CODE (ext_type) == FUNCTION_TYPE
   10891          874 :                   && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
   10892          437 :                                 TREE_TYPE (ext_type)))
   10893              :                 {
   10894          417 :                   current_function_prototype_locus
   10895          417 :                     = DECL_SOURCE_LOCATION (ext_decl);
   10896          417 :                   current_function_prototype_built_in
   10897          417 :                     = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
   10898          417 :                   current_function_prototype_arg_types
   10899          417 :                     = TYPE_ARG_TYPES (ext_type);
   10900              :                 }
   10901              :             }
   10902              :         }
   10903              :     }
   10904              : 
   10905              :   /* Optionally warn about C23 compatibility.  */
   10906     36326429 :   if (warn_deprecated_non_prototype
   10907           34 :       && old_decl != NULL_TREE
   10908            5 :       && TREE_CODE (oldtype) == FUNCTION_TYPE
   10909            5 :       && !TYPE_ARG_TYPES (oldtype)
   10910            5 :       && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype)
   10911     36326434 :       && (TYPE_ARG_TYPES (newtype)
   10912            3 :           && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != void_type_node))
   10913              :     {
   10914            3 :       bool warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
   10915              :                                 "ISO C23 does not allow defining"
   10916              :                                 " parameters for function %qE declared"
   10917              :                                 " without parameters",
   10918              :                                 decl1);
   10919            3 :       if (warned)
   10920            3 :         inform (DECL_SOURCE_LOCATION (old_decl), "declared here");
   10921              :     }
   10922              : 
   10923              :   /* Optionally warn of old-fashioned def with no previous prototype.  */
   10924     36326429 :   if (warn_strict_prototypes
   10925       107548 :       && old_decl != error_mark_node
   10926       107548 :       && !prototype_p (TREE_TYPE (decl1))
   10927     36326430 :       && C_DECL_ISNT_PROTOTYPE (old_decl))
   10928            1 :     warning_at (loc, OPT_Wstrict_prototypes,
   10929              :                 "function declaration isn%'t a prototype");
   10930              :   /* Optionally warn of any global def with no previous prototype.  */
   10931     36326428 :   else if (warn_missing_prototypes
   10932       107249 :            && old_decl != error_mark_node
   10933       107249 :            && TREE_PUBLIC (decl1)
   10934        74076 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10935        74040 :            && C_DECL_ISNT_PROTOTYPE (old_decl)
   10936     36327069 :            && !DECL_DECLARED_INLINE_P (decl1))
   10937            4 :     warning_at (loc, OPT_Wmissing_prototypes,
   10938              :                 "no previous prototype for %qD", decl1);
   10939              :   /* Optionally warn of any def with no previous prototype
   10940              :      if the function has already been used.  */
   10941     36326424 :   else if (warn_missing_prototypes
   10942       107245 :            && old_decl != NULL_TREE
   10943        74403 :            && old_decl != error_mark_node
   10944        74403 :            && TREE_USED (old_decl)
   10945     36333525 :            && !prototype_p (TREE_TYPE (old_decl)))
   10946            0 :     warning_at (loc, OPT_Wmissing_prototypes,
   10947              :                 "%qD was used with no prototype before its definition", decl1);
   10948              :   /* Optionally warn of any global def with no previous declaration.  */
   10949     36326424 :   else if (warn_missing_declarations
   10950            4 :            && TREE_PUBLIC (decl1)
   10951            3 :            && old_decl == NULL_TREE
   10952            3 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10953     36326427 :            && !DECL_DECLARED_INLINE_P (decl1))
   10954            2 :     warning_at (loc, OPT_Wmissing_declarations,
   10955              :                 "no previous declaration for %qD",
   10956              :                 decl1);
   10957              :   /* Optionally warn of any def with no previous declaration
   10958              :      if the function has already been used.  */
   10959     36326422 :   else if (warn_missing_declarations
   10960            2 :            && old_decl != NULL_TREE
   10961            0 :            && old_decl != error_mark_node
   10962            0 :            && TREE_USED (old_decl)
   10963     36326422 :            && C_DECL_IMPLICIT (old_decl))
   10964            0 :     warning_at (loc, OPT_Wmissing_declarations,
   10965              :                 "%qD was used with no declaration before its definition", decl1);
   10966              : 
   10967              :   /* This function exists in static storage.
   10968              :      (This does not mean `static' in the C sense!)  */
   10969     36326429 :   TREE_STATIC (decl1) = 1;
   10970              : 
   10971              :   /* This is the earliest point at which we might know the assembler
   10972              :      name of the function.  Thus, if it's set before this, die horribly.  */
   10973     36326429 :   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
   10974              : 
   10975              :   /* If #pragma weak was used, mark the decl weak now.  */
   10976     36326429 :   if (current_scope == file_scope)
   10977     36324835 :     maybe_apply_pragma_weak (decl1);
   10978              : 
   10979              :   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
   10980     36326429 :   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
   10981              :     {
   10982         3335 :       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
   10983         3335 :           != integer_type_node)
   10984            5 :         pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
   10985         3330 :       else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
   10986            1 :         pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
   10987              :                  decl1);
   10988              : 
   10989         3335 :       check_main_parameter_types (decl1);
   10990              : 
   10991         3335 :       if (!TREE_PUBLIC (decl1))
   10992            0 :         pedwarn (loc, OPT_Wmain,
   10993              :                  "%qD is normally a non-static function", decl1);
   10994              :     }
   10995              : 
   10996     36326429 :   tree parms = current_function_arg_info->parms;
   10997     36326429 :   if (old_decl)
   10998              :     {
   10999       229998 :       location_t origloc = DECL_SOURCE_LOCATION (old_decl);
   11000       229998 :       warn_parms_array_mismatch (origloc, old_decl, parms);
   11001              :     }
   11002              : 
   11003              :   /* To enable versions to be created across TU's we mark and mangle all
   11004              :      non-default versioned functions.  */
   11005     36326429 :   if (TREE_CODE (decl1) == FUNCTION_DECL
   11006              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
   11007              :       && get_target_version (decl1).is_valid ())
   11008              :     {
   11009              :       maybe_mark_function_versioned (decl1);
   11010              :       if (current_scope != file_scope)
   11011              :         error ("versioned definitions are only allowed at file scope");
   11012              :     }
   11013              : 
   11014              :   /* Record the decl so that the function name is defined.
   11015              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   11016              :      use the old decl.  */
   11017              : 
   11018     36326429 :   current_function_decl = pushdecl (decl1);
   11019              : 
   11020     36326429 :   if (tree access = build_attr_access_from_parms (parms, false))
   11021        57800 :     decl_attributes (&current_function_decl, access, ATTR_FLAG_INTERNAL,
   11022              :                      old_decl);
   11023              : 
   11024     36326429 :   push_scope ();
   11025     36326429 :   declare_parm_level ();
   11026              : 
   11027              :   /* Set the result decl source location to the location of the typespec.  */
   11028      4103317 :   result_loc = (declspecs->locations[cdw_typespec] == UNKNOWN_LOCATION
   11029     36326429 :                 ? loc : declspecs->locations[cdw_typespec]);
   11030     36326429 :   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11031     36326429 :   resdecl = build_decl (result_loc, RESULT_DECL, NULL_TREE, restype);
   11032     36326429 :   DECL_ARTIFICIAL (resdecl) = 1;
   11033     36326429 :   DECL_IGNORED_P (resdecl) = 1;
   11034     36326429 :   DECL_RESULT (current_function_decl) = resdecl;
   11035              : 
   11036     36326429 :   start_fname_decls ();
   11037              : 
   11038     36326429 :   return true;
   11039              : }
   11040              : 
   11041              : /* Subroutine of store_parm_decls which handles new-style function
   11042              :    definitions (prototype format). The parms already have decls, so we
   11043              :    need only record them as in effect and complain if any redundant
   11044              :    old-style parm decls were written.  */
   11045              : static void
   11046     36313304 : store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
   11047              : {
   11048     36313304 :   tree decl;
   11049     36313304 :   c_arg_tag *tag;
   11050     36313304 :   unsigned ix;
   11051              : 
   11052     36313304 :   if (current_scope->bindings)
   11053              :     {
   11054            8 :       error_at (DECL_SOURCE_LOCATION (fndecl),
   11055              :                 "old-style parameter declarations in prototyped "
   11056              :                 "function definition");
   11057              : 
   11058              :       /* Get rid of the old-style declarations.  */
   11059            8 :       pop_scope ();
   11060            8 :       push_scope ();
   11061              :     }
   11062              :   /* Don't issue this warning for nested functions, and don't issue this
   11063              :      warning if we got here because ARG_INFO_TYPES was error_mark_node
   11064              :      (this happens when a function definition has just an ellipsis in
   11065              :      its parameter list).  */
   11066     36313296 :   else if (!in_system_header_at (input_location)
   11067       641763 :            && !current_function_scope
   11068       640317 :            && arg_info->types != error_mark_node
   11069     36953613 :            && !arg_info->c23_empty_parens)
   11070       588187 :     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
   11071              :                 "traditional C rejects ISO C style function definitions");
   11072              : 
   11073              :   /* Now make all the parameter declarations visible in the function body.
   11074              :      We can bypass most of the grunt work of pushdecl.  */
   11075    136363756 :   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
   11076              :     {
   11077    100050452 :       DECL_CONTEXT (decl) = current_function_decl;
   11078    100050452 :       if (DECL_NAME (decl))
   11079              :         {
   11080    100048939 :           bind (DECL_NAME (decl), decl, current_scope,
   11081              :                 /*invisible=*/false, /*nested=*/false,
   11082              :                 UNKNOWN_LOCATION);
   11083    100048939 :           if (!TREE_USED (decl))
   11084    100031518 :             warn_if_shadowing (decl);
   11085              :         }
   11086              :       else
   11087         1513 :         pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_name,
   11088              :                      "ISO C does not support omitting parameter names in "
   11089              :                      "function definitions before C23");
   11090              :     }
   11091              : 
   11092              :   /* Record the parameter list in the function declaration.  */
   11093     36313304 :   DECL_ARGUMENTS (fndecl) = arg_info->parms;
   11094              : 
   11095              :   /* Now make all the ancillary declarations visible, likewise.  */
   11096     36313365 :   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
   11097              :     {
   11098           61 :       DECL_CONTEXT (decl) = current_function_decl;
   11099           61 :       if (DECL_NAME (decl))
   11100            0 :         bind (DECL_NAME (decl), decl, current_scope,
   11101              :               /*invisible=*/false,
   11102            0 :               /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
   11103              :               UNKNOWN_LOCATION);
   11104              :     }
   11105              : 
   11106              :   /* And all the tag declarations.  */
   11107     36313421 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
   11108           61 :     if (tag->id)
   11109           28 :       bind (tag->id, tag->type, current_scope,
   11110              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
   11111     36313304 : }
   11112              : 
   11113              : /* Subroutine of store_parm_decls which handles old-style function
   11114              :    definitions (separate parameter list and declarations).  */
   11115              : 
   11116              : static void
   11117        13125 : store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
   11118              : {
   11119        13125 :   struct c_binding *b;
   11120        13125 :   tree parm, decl, last;
   11121        13125 :   tree parmids = arg_info->parms;
   11122        13125 :   hash_set<tree> seen_args;
   11123              : 
   11124        13125 :   if (!in_system_header_at (input_location))
   11125              :     {
   11126        13122 :       if (flag_isoc23)
   11127         1348 :         pedwarn (DECL_SOURCE_LOCATION (fndecl),
   11128         1348 :                  OPT_Wold_style_definition, "old-style function definition");
   11129              :       else
   11130        11774 :         warning_at (DECL_SOURCE_LOCATION (fndecl),
   11131        11774 :                     OPT_Wold_style_definition,
   11132              :                     "old-style function definition");
   11133              :     }
   11134              : 
   11135        13125 :   if (current_scope->had_vla_unspec)
   11136            1 :     error ("%<[*]%> not allowed in other than function prototype scope");
   11137              : 
   11138              :   /* Match each formal parameter name with its declaration.  Save each
   11139              :      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
   11140        47399 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11141              :     {
   11142        34274 :       if (TREE_VALUE (parm) == NULL_TREE)
   11143              :         {
   11144            0 :           error_at (DECL_SOURCE_LOCATION (fndecl),
   11145              :                     "parameter name missing from parameter list");
   11146            0 :           TREE_PURPOSE (parm) = NULL_TREE;
   11147            0 :           continue;
   11148              :         }
   11149              : 
   11150        34274 :       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
   11151        34274 :       if (b && B_IN_CURRENT_SCOPE (b))
   11152              :         {
   11153        22654 :           decl = b->decl;
   11154              :           /* Skip erroneous parameters.  */
   11155        22654 :           if (decl == error_mark_node)
   11156            2 :             continue;
   11157              :           /* If we got something other than a PARM_DECL it is an error.  */
   11158        22652 :           if (TREE_CODE (decl) != PARM_DECL)
   11159              :             {
   11160            7 :               error_at (DECL_SOURCE_LOCATION (decl),
   11161              :                         "%qD declared as a non-parameter", decl);
   11162            7 :               continue;
   11163              :             }
   11164              :           /* If the declaration is already marked, we have a duplicate
   11165              :              name.  Complain and ignore the duplicate.  */
   11166        22645 :           else if (seen_args.contains (decl))
   11167              :             {
   11168            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11169              :                         "multiple parameters named %qD", decl);
   11170            0 :               TREE_PURPOSE (parm) = NULL_TREE;
   11171            0 :               continue;
   11172              :             }
   11173              :           /* If the declaration says "void", complain and turn it into
   11174              :              an int.  */
   11175        22645 :           else if (VOID_TYPE_P (TREE_TYPE (decl)))
   11176              :             {
   11177            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11178              :                         "parameter %qD declared with void type", decl);
   11179            0 :               TREE_TYPE (decl) = integer_type_node;
   11180            0 :               DECL_ARG_TYPE (decl) = integer_type_node;
   11181            0 :               layout_decl (decl, 0);
   11182              :             }
   11183        22645 :           warn_if_shadowing (decl);
   11184              :         }
   11185              :       /* If no declaration found, default to int.  */
   11186              :       else
   11187              :         {
   11188              :           /* FIXME diagnostics: This should be the location of the argument,
   11189              :              not the FNDECL.  E.g., for an old-style declaration
   11190              : 
   11191              :                int f10(v) { blah; }
   11192              : 
   11193              :              We should use the location of the V, not the F10.
   11194              :              Unfortunately, the V is an IDENTIFIER_NODE which has no
   11195              :              location.  In the future we need locations for c_arg_info
   11196              :              entries.
   11197              : 
   11198              :              See gcc.dg/Wshadow-3.c for an example of this problem. */
   11199        11620 :           decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
   11200        11620 :                              PARM_DECL, TREE_VALUE (parm), integer_type_node);
   11201        11620 :           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
   11202        11620 :           pushdecl (decl);
   11203        11620 :           warn_if_shadowing (decl);
   11204              : 
   11205        11620 :           if (flag_isoc99)
   11206          118 :             permerror_opt (DECL_SOURCE_LOCATION (decl),
   11207          118 :                            OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
   11208              :                            decl);
   11209              :           else
   11210        11502 :             warning_at (DECL_SOURCE_LOCATION (decl),
   11211        11502 :                         OPT_Wmissing_parameter_type,
   11212              :                         "type of %qD defaults to %<int%>", decl);
   11213              :         }
   11214              : 
   11215        34265 :       TREE_PURPOSE (parm) = decl;
   11216        34265 :       seen_args.add (decl);
   11217              :     }
   11218              : 
   11219              :   /* Now examine the parms chain for incomplete declarations
   11220              :      and declarations with no corresponding names.  */
   11221              : 
   11222        47478 :   for (b = current_scope->bindings; b; b = b->prev)
   11223              :     {
   11224        34353 :       parm = b->decl;
   11225        34353 :       if (TREE_CODE (parm) != PARM_DECL)
   11226           79 :         continue;
   11227              : 
   11228        34274 :       if (TREE_TYPE (parm) != error_mark_node
   11229        34274 :           && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
   11230              :         {
   11231            0 :           error_at (DECL_SOURCE_LOCATION (parm),
   11232              :                     "parameter %qD has incomplete type", parm);
   11233            0 :           TREE_TYPE (parm) = error_mark_node;
   11234              :         }
   11235              : 
   11236        34274 :       if (!seen_args.contains (parm))
   11237              :         {
   11238            9 :           error_at (DECL_SOURCE_LOCATION (parm),
   11239              :                     "declaration for parameter %qD but no such parameter",
   11240              :                     parm);
   11241              : 
   11242              :           /* Pretend the parameter was not missing.
   11243              :              This gets us to a standard state and minimizes
   11244              :              further error messages.  */
   11245            9 :           parmids = chainon (parmids, tree_cons (parm, 0, 0));
   11246              :         }
   11247              :     }
   11248              : 
   11249              :   /* Chain the declarations together in the order of the list of
   11250              :      names.  Store that chain in the function decl, replacing the
   11251              :      list of names.  Update the current scope to match.  */
   11252        13125 :   DECL_ARGUMENTS (fndecl) = NULL_TREE;
   11253              : 
   11254        13133 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11255         8680 :     if (TREE_PURPOSE (parm))
   11256              :       break;
   11257        13125 :   if (parm && TREE_PURPOSE (parm))
   11258              :     {
   11259         8672 :       last = TREE_PURPOSE (parm);
   11260         8672 :       DECL_ARGUMENTS (fndecl) = last;
   11261              : 
   11262        34275 :       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
   11263        25603 :         if (TREE_PURPOSE (parm))
   11264              :           {
   11265        25602 :             DECL_CHAIN (last) = TREE_PURPOSE (parm);
   11266        25603 :             last = TREE_PURPOSE (parm);
   11267              :           }
   11268         8672 :       DECL_CHAIN (last) = NULL_TREE;
   11269              :     }
   11270              : 
   11271              :   /* If there was a previous prototype,
   11272              :      set the DECL_ARG_TYPE of each argument according to
   11273              :      the type previously specified, and report any mismatches.  */
   11274              : 
   11275        13125 :   if (current_function_prototype_arg_types)
   11276              :     {
   11277          171 :       tree type;
   11278          171 :       for (parm = DECL_ARGUMENTS (fndecl),
   11279          171 :              type = current_function_prototype_arg_types;
   11280          373 :            parm || (type != NULL_TREE
   11281          166 :                     && TREE_VALUE (type) != error_mark_node
   11282          166 :                     && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
   11283          202 :            parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
   11284              :         {
   11285          212 :           if (parm == NULL_TREE
   11286          206 :               || type == NULL_TREE
   11287          418 :               || (TREE_VALUE (type) != error_mark_node
   11288          192 :                   && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
   11289              :             {
   11290           10 :               if (current_function_prototype_built_in)
   11291            6 :                 warning_at (DECL_SOURCE_LOCATION (fndecl),
   11292            6 :                             0, "number of arguments doesn%'t match "
   11293              :                             "built-in prototype");
   11294              :               else
   11295              :                 {
   11296              :                   /* FIXME diagnostics: This should be the location of
   11297              :                      FNDECL, but there is bug when a prototype is
   11298              :                      declared inside function context, but defined
   11299              :                      outside of it (e.g., gcc.dg/pr15698-2.c).  In
   11300              :                      which case FNDECL gets the location of the
   11301              :                      prototype, not the definition.  */
   11302            4 :                   error_at (input_location,
   11303              :                             "number of arguments doesn%'t match prototype");
   11304              : 
   11305            4 :                   error_at (current_function_prototype_locus,
   11306              :                             "prototype declaration");
   11307              :                 }
   11308              :               break;
   11309              :             }
   11310              :           /* Type for passing arg must be consistent with that
   11311              :              declared for the arg.  ISO C says we take the unqualified
   11312              :              type for parameters declared with qualified type.  */
   11313          202 :           if (TREE_TYPE (parm) != error_mark_node
   11314          201 :               && TREE_VALUE (type) != error_mark_node
   11315          389 :               && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11316          187 :                    != TYPE_ATOMIC (TREE_VALUE (type)))
   11317          185 :                   || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
   11318          185 :                                  TYPE_MAIN_VARIANT (TREE_VALUE (type)))))
   11319              :             {
   11320           36 :               if ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11321           36 :                    == TYPE_ATOMIC (TREE_VALUE (type)))
   11322           36 :                   && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
   11323           34 :                       == TYPE_MAIN_VARIANT (TREE_VALUE (type))))
   11324              :                 {
   11325              :                   /* Adjust argument to match prototype.  E.g. a previous
   11326              :                      `int foo(float);' prototype causes
   11327              :                      `int foo(x) float x; {...}' to be treated like
   11328              :                      `int foo(float x) {...}'.  This is particularly
   11329              :                      useful for argument types like uid_t.  */
   11330           17 :                   DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
   11331              : 
   11332              :                   /* ??? Is it possible to get here with a
   11333              :                      built-in prototype or will it always have
   11334              :                      been diagnosed as conflicting with an
   11335              :                      old-style definition and discarded?  */
   11336           17 :                   if (current_function_prototype_built_in)
   11337            2 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11338            2 :                                 OPT_Wpedantic, "promoted argument %qD "
   11339              :                                 "doesn%'t match built-in prototype", parm);
   11340              :                   else
   11341              :                     {
   11342           15 :                       pedwarn (DECL_SOURCE_LOCATION (parm),
   11343           15 :                                OPT_Wpedantic, "promoted argument %qD "
   11344              :                                "doesn%'t match prototype", parm);
   11345           15 :                       pedwarn (current_function_prototype_locus, OPT_Wpedantic,
   11346              :                                "prototype declaration");
   11347              :                     }
   11348              :                 }
   11349              :               else
   11350              :                 {
   11351           19 :                   if (current_function_prototype_built_in)
   11352           10 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11353           10 :                                 0, "argument %qD doesn%'t match "
   11354              :                                 "built-in prototype", parm);
   11355              :                   else
   11356              :                     {
   11357            9 :                       error_at (DECL_SOURCE_LOCATION (parm),
   11358              :                                 "argument %qD doesn%'t match prototype", parm);
   11359            9 :                       error_at (current_function_prototype_locus,
   11360              :                                 "prototype declaration");
   11361              :                     }
   11362              :                 }
   11363              :             }
   11364              :         }
   11365          171 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = NULL_TREE;
   11366              :     }
   11367              : 
   11368              :   /* Otherwise, create a prototype that would match.  */
   11369              : 
   11370              :   else
   11371              :     {
   11372        12954 :       tree actual = NULL_TREE, last = NULL_TREE, type;
   11373              : 
   11374        47022 :       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   11375              :         {
   11376        34068 :           type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
   11377        34068 :           if (last)
   11378        25552 :             TREE_CHAIN (last) = type;
   11379              :           else
   11380              :             actual = type;
   11381        34068 :           last = type;
   11382              :         }
   11383        12954 :       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
   11384        12954 :       if (last)
   11385         8516 :         TREE_CHAIN (last) = type;
   11386              :       else
   11387              :         actual = type;
   11388              : 
   11389              :       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
   11390              :          of the type of this function, but we need to avoid having this
   11391              :          affect the types of other similarly-typed functions, so we must
   11392              :          first force the generation of an identical (but separate) type
   11393              :          node for the relevant function type.  The new node we create
   11394              :          will be a variant of the main variant of the original function
   11395              :          type.  */
   11396              : 
   11397        12954 :       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
   11398              : 
   11399        12954 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
   11400              :     }
   11401        13125 : }
   11402              : 
   11403              : /* Store parameter declarations passed in ARG_INFO into the current
   11404              :    function declaration.  */
   11405              : 
   11406              : void
   11407            0 : store_parm_decls_from (struct c_arg_info *arg_info)
   11408              : {
   11409            0 :   current_function_arg_info = arg_info;
   11410            0 :   store_parm_decls ();
   11411            0 : }
   11412              : 
   11413              : /* Called by walk_tree to look for and update context-less labels
   11414              :    or labels with context in the parent function.  */
   11415              : 
   11416              : static tree
   11417         8160 : set_labels_context_r (tree *tp, int *walk_subtrees, void *data)
   11418              : {
   11419         8160 :   tree ctx = static_cast<tree>(data);
   11420         8160 :   if (TREE_CODE (*tp) == LABEL_EXPR
   11421         8160 :       && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE
   11422            2 :           || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx)))
   11423              :     {
   11424           72 :       DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx;
   11425           72 :       *walk_subtrees = 0;
   11426              :     }
   11427              : 
   11428         8160 :   return NULL_TREE;
   11429              : }
   11430              : 
   11431              : /* Store the parameter declarations into the current function declaration.
   11432              :    This is called after parsing the parameter declarations, before
   11433              :    digesting the body of the function.
   11434              : 
   11435              :    For an old-style definition, construct a prototype out of the old-style
   11436              :    parameter declarations and inject it into the function's type.  */
   11437              : 
   11438              : void
   11439     36326429 : store_parm_decls (void)
   11440              : {
   11441     36326429 :   tree fndecl = current_function_decl;
   11442     36326429 :   bool proto;
   11443              : 
   11444              :   /* The argument information block for FNDECL.  */
   11445     36326429 :   struct c_arg_info *arg_info = current_function_arg_info;
   11446     36326429 :   current_function_arg_info = 0;
   11447              : 
   11448              :   /* True if this definition is written with a prototype.  In C23, an
   11449              :      empty argument list was converted to (void) in grokparms; in
   11450              :      older C standard versions, it does not give the function a type
   11451              :      with a prototype for future calls.  */
   11452     36326429 :   proto = arg_info->types != 0 || arg_info->no_named_args_stdarg_p;
   11453              : 
   11454        13125 :   if (proto)
   11455     36313304 :     store_parm_decls_newstyle (fndecl, arg_info);
   11456              :   else
   11457        13125 :     store_parm_decls_oldstyle (fndecl, arg_info);
   11458              : 
   11459              :   /* The next call to push_scope will be a function body.  */
   11460              : 
   11461     36326429 :   next_is_function_body = true;
   11462              : 
   11463              :   /* Write a record describing this function definition to the prototypes
   11464              :      file (if requested).  */
   11465              : 
   11466     36326429 :   gen_aux_info_record (fndecl, 1, 0, proto);
   11467              : 
   11468              :   /* Initialize the RTL code for the function.  */
   11469     36326429 :   allocate_struct_function (fndecl, false);
   11470              : 
   11471     36326429 :   if (warn_unused_local_typedefs)
   11472      3116431 :     cfun->language = ggc_cleared_alloc<language_function> ();
   11473              : 
   11474              :   /* Begin the statement tree for this function.  */
   11475     36326429 :   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
   11476              : 
   11477              :   /* ??? Insert the contents of the pending sizes list into the function
   11478              :      to be evaluated.  The only reason left to have this is
   11479              :         void foo(int n, int array[n++])
   11480              :      because we throw away the array type in favor of a pointer type, and
   11481              :      thus won't naturally see the SAVE_EXPR containing the increment.  All
   11482              :      other pending sizes would be handled by gimplify_parameters.  */
   11483     36326429 :   if (arg_info->pending_sizes)
   11484              :     {
   11485              :       /* In very special circumstances, e.g. for code like
   11486              :            _Atomic int i = 5;
   11487              :            void f (int a[i += 2]) {}
   11488              :          we need to execute the atomic assignment on function entry.
   11489              :          But in this case, it is not just a straight store, it has the
   11490              :          op= form, which means that build_atomic_assign has generated
   11491              :          gotos, labels, etc.  Because at that time the function decl
   11492              :          for F has not been created yet, those labels do not have any
   11493              :          function context.  But we have the fndecl now, so update the
   11494              :          labels accordingly.  gimplify_expr would crash otherwise.
   11495              :          Or with nested functions the labels could be created with parent
   11496              :          function's context, while when the statement is emitted at the
   11497              :          start of the nested function, it needs the nested function's
   11498              :          context.  */
   11499          297 :       walk_tree_without_duplicates (&arg_info->pending_sizes,
   11500              :                                     set_labels_context_r, fndecl);
   11501          297 :       add_stmt (arg_info->pending_sizes);
   11502              :     }
   11503     36326429 : }
   11504              : 
   11505              : /* Store PARM_DECLs in PARMS into scope temporarily.  Used for
   11506              :    c_finish_omp_declare_simd for function prototypes.  No diagnostics
   11507              :    should be done.  */
   11508              : 
   11509              : void
   11510          249 : temp_store_parm_decls (tree fndecl, tree parms)
   11511              : {
   11512          249 :   push_scope ();
   11513          699 :   for (tree p = parms; p; p = DECL_CHAIN (p))
   11514              :     {
   11515          450 :       DECL_CONTEXT (p) = fndecl;
   11516          450 :       if (DECL_NAME (p))
   11517          328 :         bind (DECL_NAME (p), p, current_scope,
   11518              :               /*invisible=*/false, /*nested=*/false,
   11519              :               UNKNOWN_LOCATION);
   11520              :     }
   11521          249 : }
   11522              : 
   11523              : /* Undo what temp_store_parm_decls did.  */
   11524              : 
   11525              : void
   11526          249 : temp_pop_parm_decls (void)
   11527              : {
   11528              :   /* Clear all bindings in this temporary scope, so that
   11529              :      pop_scope doesn't create a BLOCK.  */
   11530          249 :   struct c_binding *b = current_scope->bindings;
   11531          249 :   current_scope->bindings = NULL;
   11532          582 :   for (; b; b = free_binding_and_advance (b))
   11533              :     {
   11534          333 :       gcc_assert (TREE_CODE (b->decl) == PARM_DECL
   11535              :                   || b->decl == error_mark_node);
   11536          333 :       gcc_assert (I_SYMBOL_BINDING (b->id) == b);
   11537          333 :       I_SYMBOL_BINDING (b->id) = b->shadowed;
   11538          333 :       if (b->shadowed && b->shadowed->u.type)
   11539            0 :         TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
   11540              :     }
   11541          249 :   pop_scope ();
   11542          249 : }
   11543              : 
   11544              : 
   11545              : /* Finish up a function declaration and compile that function
   11546              :    all the way to assembler language output.  Then free the storage
   11547              :    for the function definition.
   11548              : 
   11549              :    This is called after parsing the body of the function definition.  */
   11550              : 
   11551              : void
   11552     36326427 : finish_function (location_t end_loc)
   11553              : {
   11554     36326427 :   tree fndecl = current_function_decl;
   11555              : 
   11556     36326427 :   if (c_dialect_objc ())
   11557            0 :     objc_finish_function ();
   11558              : 
   11559     36326427 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
   11560     36326425 :     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   11561              : 
   11562              :   /* Must mark the RESULT_DECL as being in this function.  */
   11563              : 
   11564     36326427 :   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
   11565     36326427 :     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   11566              : 
   11567     36374181 :   if (MAIN_NAME_P (DECL_NAME (fndecl)) && !TREE_THIS_VOLATILE (fndecl)
   11568        47753 :       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
   11569     36374180 :       == integer_type_node && flag_isoc99)
   11570              :     {
   11571              :       /* Hack.  We don't want the middle-end to warn that this return
   11572              :          is unreachable, so we mark its location as special.  Using
   11573              :          UNKNOWN_LOCATION has the problem that it gets clobbered in
   11574              :          annotate_one_with_locus.  A cleaner solution might be to
   11575              :          ensure ! should_carry_locus_p (stmt), but that needs a flag.
   11576              :       */
   11577        46364 :       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
   11578              :     }
   11579              : 
   11580              :   /* Tie off the statement tree for this function.  */
   11581     36326427 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   11582              : 
   11583     36326427 :   finish_fname_decls ();
   11584              : 
   11585              :   /* Complain if there's no return statement only if option specified on
   11586              :      command line.  */
   11587     36326427 :   if (warn_return_type > 0
   11588      3116454 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
   11589      2920511 :       && !current_function_returns_value && !current_function_returns_null
   11590              :       /* Don't complain if we are no-return.  */
   11591           72 :       && !current_function_returns_abnormally
   11592              :       /* Don't complain if we are declared noreturn.  */
   11593           21 :       && !TREE_THIS_VOLATILE (fndecl)
   11594              :       /* Don't warn for main().  */
   11595           18 :       && !MAIN_NAME_P (DECL_NAME (fndecl))
   11596              :       /* Or if they didn't actually specify a return type.  */
   11597           17 :       && !C_FUNCTION_IMPLICIT_INT (fndecl)
   11598              :       /* Normally, with -Wreturn-type, flow will complain, but we might
   11599              :          optimize out static functions.  */
   11600           17 :       && !TREE_PUBLIC (fndecl)
   11601            6 :       && targetm.warn_func_return (fndecl)
   11602     39442881 :       && warning (OPT_Wreturn_type,
   11603              :                   "no return statement in function returning non-void"))
   11604            5 :     suppress_warning (fndecl, OPT_Wreturn_type);
   11605              : 
   11606              :   /* Complain about parameters that are only set, but never otherwise used.  */
   11607     36326427 :   if (warn_unused_but_set_parameter)
   11608              :     {
   11609      3051563 :       tree decl;
   11610              : 
   11611      3051563 :       for (decl = DECL_ARGUMENTS (fndecl);
   11612     11400845 :            decl;
   11613      8349282 :            decl = DECL_CHAIN (decl))
   11614      8349282 :         if (TREE_USED (decl)
   11615      8288579 :             && TREE_CODE (decl) == PARM_DECL
   11616      8288579 :             && !DECL_READ_P (decl)
   11617           47 :             && DECL_NAME (decl)
   11618           47 :             && !DECL_ARTIFICIAL (decl)
   11619      8349329 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_))
   11620           47 :           warning_at (DECL_SOURCE_LOCATION (decl),
   11621           47 :                       OPT_Wunused_but_set_parameter_,
   11622              :                       "parameter %qD set but not used", decl);
   11623              :     }
   11624              : 
   11625              :   /* Complain about locally defined typedefs that are not used in this
   11626              :      function.  */
   11627     36326427 :   maybe_warn_unused_local_typedefs ();
   11628              : 
   11629              :   /* Possibly warn about unused parameters.  */
   11630     36326427 :   if (warn_unused_parameter)
   11631      2957674 :     do_warn_unused_parameter (fndecl);
   11632              : 
   11633              :   /* Store the end of the function, so that we get good line number
   11634              :      info for the epilogue.  */
   11635     36326427 :   cfun->function_end_locus = end_loc;
   11636              : 
   11637              :   /* Finalize the ELF visibility for the function.  */
   11638     36326427 :   c_determine_visibility (fndecl);
   11639              : 
   11640              :   /* For GNU C extern inline functions disregard inline limits.  */
   11641     36326427 :   if (DECL_EXTERNAL (fndecl)
   11642     35470412 :       && DECL_DECLARED_INLINE_P (fndecl)
   11643     71796836 :       && (flag_gnu89_inline
   11644     35439405 :           || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
   11645     35469927 :     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
   11646              : 
   11647              :   /* Genericize before inlining.  Delay genericizing nested functions
   11648              :      until their parent function is genericized.  Since finalizing
   11649              :      requires GENERIC, delay that as well.  */
   11650              : 
   11651     72652854 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
   11652     72652852 :       && !undef_nested_function)
   11653              :     {
   11654     36326419 :       if (!decl_function_context (fndecl))
   11655              :         {
   11656     36324825 :           invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   11657     36324825 :           c_genericize (fndecl);
   11658              : 
   11659              :           /* ??? Objc emits functions after finalizing the compilation unit.
   11660              :              This should be cleaned up later and this conditional removed.  */
   11661     36324825 :           if (symtab->global_info_ready)
   11662              :             {
   11663            0 :               cgraph_node::add_new_function (fndecl, false);
   11664            0 :               return;
   11665              :             }
   11666     36324825 :           cgraph_node::finalize_function (fndecl, false);
   11667              :         }
   11668              :       else
   11669              :         {
   11670              :           /* Register this function with cgraph just far enough to get it
   11671              :             added to our parent's nested function list.  Handy, since the
   11672              :             C front end doesn't have such a list.  */
   11673         1594 :           (void) cgraph_node::get_create (fndecl);
   11674              :         }
   11675              :     }
   11676              : 
   11677     36326427 :   if (!decl_function_context (fndecl))
   11678     36324833 :     undef_nested_function = false;
   11679              : 
   11680     36326427 :   if (cfun->language != NULL)
   11681              :     {
   11682      3116430 :       ggc_free (cfun->language);
   11683      3116430 :       cfun->language = NULL;
   11684              :     }
   11685              : 
   11686              :   /* We're leaving the context of this function, so zap cfun.
   11687              :      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
   11688              :      tree_rest_of_compilation.  */
   11689     36326427 :   set_cfun (NULL);
   11690     36326427 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, current_function_decl);
   11691     36326427 :   current_function_decl = NULL;
   11692              : }
   11693              : 
   11694              : /* Check the declarations given in a for-loop for satisfying the C99
   11695              :    constraints.  If exactly one such decl is found, return it.  LOC is
   11696              :    the location of the opening parenthesis of the for loop.  The last
   11697              :    parameter allows you to control the "for loop initial declarations
   11698              :    are only allowed in C99 mode".  Normally, you should pass
   11699              :    flag_isoc99 as that parameter.  But in some cases (Objective-C
   11700              :    foreach loop, for example) we want to run the checks in this
   11701              :    function even if not in C99 mode, so we allow the caller to turn
   11702              :    off the error about not being in C99 mode.
   11703              : */
   11704              : 
   11705              : tree
   11706        25950 : check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
   11707              : {
   11708        25950 :   struct c_binding *b;
   11709        25950 :   tree one_decl = NULL_TREE;
   11710        25950 :   int n_decls = 0;
   11711              : 
   11712        25950 :   if (!turn_off_iso_c99_error)
   11713              :     {
   11714            1 :       static bool hint = true;
   11715              :       /* If we get here, declarations have been used in a for loop without
   11716              :          the C99 for loop scope.  This doesn't make much sense, so don't
   11717              :          allow it.  */
   11718            1 :       auto_diagnostic_group d;
   11719            1 :       error_at (loc, "%<for%> loop initial declarations "
   11720              :                 "are only allowed in C99 or C11 mode");
   11721            1 :       if (hint)
   11722              :         {
   11723            1 :           inform (loc,
   11724              :                   "use option %<-std=c99%>, %<-std=gnu99%>, %<-std=c11%> or "
   11725              :                   "%<-std=gnu11%> to compile your code");
   11726            1 :           hint = false;
   11727              :         }
   11728            1 :       return NULL_TREE;
   11729            1 :     }
   11730              :   else
   11731        25949 :     pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop "
   11732              :                  "initial declarations");
   11733              : 
   11734              :   /* C99 subclause 6.8.5 paragraph 3:
   11735              : 
   11736              :        [#3]  The  declaration  part  of  a for statement shall only
   11737              :        declare identifiers for objects having storage class auto or
   11738              :        register.
   11739              : 
   11740              :      It isn't clear whether, in this sentence, "identifiers" binds to
   11741              :      "shall only declare" or to "objects" - that is, whether all identifiers
   11742              :      declared must be identifiers for objects, or whether the restriction
   11743              :      only applies to those that are.  (A question on this in comp.std.c
   11744              :      in November 2000 received no answer.)  We implement the strictest
   11745              :      interpretation, to avoid creating an extension which later causes
   11746              :      problems.
   11747              : 
   11748              :      This constraint was removed in C23.  */
   11749              : 
   11750        51973 :   for (b = current_scope->bindings; b; b = b->prev)
   11751              :     {
   11752        26024 :       tree id = b->id;
   11753        26024 :       tree decl = b->decl;
   11754              : 
   11755        26024 :       if (!id)
   11756           27 :         continue;
   11757              : 
   11758        25997 :       switch (TREE_CODE (decl))
   11759              :         {
   11760        25949 :         case VAR_DECL:
   11761        25949 :           {
   11762        25949 :             location_t decl_loc = DECL_SOURCE_LOCATION (decl);
   11763        25949 :             if (TREE_STATIC (decl))
   11764            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11765              :                            "declaration of static variable %qD in %<for%> "
   11766              :                            "loop initial declaration", decl);
   11767        25944 :             else if (DECL_EXTERNAL (decl))
   11768            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11769              :                            "declaration of %<extern%> variable %qD in %<for%> "
   11770              :                            "loop initial declaration", decl);
   11771              :           }
   11772              :           break;
   11773              : 
   11774            6 :         case RECORD_TYPE:
   11775            6 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11776              :                        "%<struct %E%> declared in %<for%> loop initial "
   11777              :                        "declaration", id);
   11778            6 :           break;
   11779            5 :         case UNION_TYPE:
   11780            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11781              :                        "%<union %E%> declared in %<for%> loop initial "
   11782              :                        "declaration",
   11783              :                        id);
   11784            5 :           break;
   11785            5 :         case ENUMERAL_TYPE:
   11786            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11787              :                        "%<enum %E%> declared in %<for%> loop "
   11788              :                        "initial declaration", id);
   11789            5 :           break;
   11790           32 :         default:
   11791           32 :           pedwarn_c11 (loc, OPT_Wpedantic, "declaration of non-variable "
   11792              :                        "%qD in %<for%> loop initial declaration", decl);
   11793              :         }
   11794              : 
   11795        25997 :       n_decls++;
   11796        25997 :       one_decl = decl;
   11797              :     }
   11798              : 
   11799        25949 :   return n_decls == 1 ? one_decl : NULL_TREE;
   11800              : }
   11801              : 
   11802              : /* Save and reinitialize the variables
   11803              :    used during compilation of a C function.  */
   11804              : 
   11805              : void
   11806         1622 : c_push_function_context (void)
   11807              : {
   11808         1622 :   struct language_function *p = cfun->language;
   11809              :   /* cfun->language might have been already allocated by the use of
   11810              :      -Wunused-local-typedefs.  In that case, just re-use it.  */
   11811         1622 :   if (p == NULL)
   11812         1566 :     cfun->language = p = ggc_cleared_alloc<language_function> ();
   11813              : 
   11814         1622 :   p->base.x_stmt_tree = c_stmt_tree;
   11815         1622 :   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
   11816         1622 :   p->x_in_statement = in_statement;
   11817         1622 :   p->x_switch_stack = c_switch_stack;
   11818         1622 :   p->loop_names = loop_names;
   11819         1622 :   loop_names = vNULL;
   11820         1622 :   p->loop_names_hash = loop_names_hash;
   11821         1622 :   loop_names_hash = NULL;
   11822         1622 :   p->arg_info = current_function_arg_info;
   11823         1622 :   p->returns_value = current_function_returns_value;
   11824         1622 :   p->returns_null = current_function_returns_null;
   11825         1622 :   p->returns_abnormally = current_function_returns_abnormally;
   11826         1622 :   p->warn_about_return_type = warn_about_return_type;
   11827              : 
   11828         1622 :   push_function_context ();
   11829         1622 : }
   11830              : 
   11831              : /* Restore the variables used during compilation of a C function.  */
   11832              : 
   11833              : void
   11834         1622 : c_pop_function_context (void)
   11835              : {
   11836         1622 :   struct language_function *p;
   11837              : 
   11838         1622 :   pop_function_context ();
   11839         1622 :   p = cfun->language;
   11840              : 
   11841              :   /* When -Wunused-local-typedefs is in effect, cfun->languages is
   11842              :      used to store data throughout the life time of the current cfun,
   11843              :      So don't deallocate it.  */
   11844         1622 :   if (!warn_unused_local_typedefs)
   11845         1566 :     cfun->language = NULL;
   11846              : 
   11847         1622 :   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
   11848         1622 :       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
   11849              :     {
   11850              :       /* Stop pointing to the local nodes about to be freed.  */
   11851              :       /* But DECL_INITIAL must remain nonzero so we know this
   11852              :          was an actual function definition.  */
   11853            0 :       DECL_INITIAL (current_function_decl) = error_mark_node;
   11854            0 :       DECL_ARGUMENTS (current_function_decl) = NULL_TREE;
   11855              :     }
   11856              : 
   11857         1622 :   c_stmt_tree = p->base.x_stmt_tree;
   11858         1622 :   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
   11859         1622 :   in_statement = p->x_in_statement;
   11860         1622 :   c_switch_stack = p->x_switch_stack;
   11861         1622 :   loop_names.release ();
   11862         1622 :   loop_names = p->loop_names;
   11863         1622 :   p->loop_names = vNULL;
   11864         1622 :   delete loop_names_hash;
   11865         1622 :   loop_names_hash = p->loop_names_hash;
   11866         1622 :   p->loop_names_hash = NULL;
   11867         1622 :   current_function_arg_info = p->arg_info;
   11868         1622 :   current_function_returns_value = p->returns_value;
   11869         1622 :   current_function_returns_null = p->returns_null;
   11870         1622 :   current_function_returns_abnormally = p->returns_abnormally;
   11871         1622 :   warn_about_return_type = p->warn_about_return_type;
   11872         1622 : }
   11873              : 
   11874              : /* The functions below are required for functionality of doing
   11875              :    function at once processing in the C front end. Currently these
   11876              :    functions are not called from anywhere in the C front end, but as
   11877              :    these changes continue, that will change.  */
   11878              : 
   11879              : /* Returns the stmt_tree (if any) to which statements are currently
   11880              :    being added.  If there is no active statement-tree, NULL is
   11881              :    returned.  */
   11882              : 
   11883              : stmt_tree
   11884    986163458 : current_stmt_tree (void)
   11885              : {
   11886    986163458 :   return &c_stmt_tree;
   11887              : }
   11888              : 
   11889              : /* Return the global value of T as a symbol.  */
   11890              : 
   11891              : tree
   11892      3939170 : identifier_global_value (tree t)
   11893              : {
   11894      3939170 :   struct c_binding *b;
   11895              : 
   11896      3940137 :   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
   11897      3932905 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11898      3931938 :       return b->decl;
   11899              : 
   11900              :   return NULL_TREE;
   11901              : }
   11902              : 
   11903              : /* Return the global value of tag T as a symbol.  */
   11904              : 
   11905              : tree
   11906           12 : identifier_global_tag (tree t)
   11907              : {
   11908           12 :   struct c_binding *b;
   11909              : 
   11910           12 :   for (b = I_TAG_BINDING (t); b; b = b->shadowed)
   11911           11 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11912           11 :       return b->decl;
   11913              : 
   11914              :   return NULL_TREE;
   11915              : }
   11916              : 
   11917              : /* Returns non-zero (result of __has_builtin) if NAME refers to a built-in
   11918              :    function or function-like operator.  */
   11919              : 
   11920              : int
   11921        25096 : names_builtin_p (const char *name)
   11922              : {
   11923        25096 :   tree id = get_identifier (name);
   11924        25096 :   if (tree decl = identifier_global_value (id))
   11925        25008 :     return TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_UNDECLARED_BUILTIN (decl);
   11926              : 
   11927              :   /* Also detect common reserved C words that aren't strictly built-in
   11928              :      functions.  */
   11929           88 :   switch (C_RID_CODE (id))
   11930              :     {
   11931              :     case RID_BUILTIN_ASSOC_BARRIER:
   11932              :     case RID_BUILTIN_CONVERTVECTOR:
   11933              :     case RID_BUILTIN_HAS_ATTRIBUTE:
   11934              :     case RID_BUILTIN_SHUFFLE:
   11935              :     case RID_BUILTIN_SHUFFLEVECTOR:
   11936              :     case RID_BUILTIN_STDC:
   11937              :     case RID_BUILTIN_COUNTED_BY_REF:
   11938              :     case RID_CHOOSE_EXPR:
   11939              :     case RID_OFFSETOF:
   11940              :     case RID_TYPES_COMPATIBLE_P:
   11941              :     case RID_C23_VA_START:
   11942              :     case RID_VA_ARG:
   11943              :       return 1;
   11944           67 :     default:
   11945           67 :       break;
   11946              :     }
   11947              : 
   11948           67 :   return 0;
   11949              : }
   11950              : 
   11951              : /* In C, the only C-linkage public declaration is at file scope.  */
   11952              : 
   11953              : tree
   11954            5 : c_linkage_bindings (tree name)
   11955              : {
   11956            5 :   return identifier_global_value (name);
   11957              : }
   11958              : 
   11959              : /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
   11960              :    otherwise the name is found in ridpointers from RID_INDEX.  */
   11961              : 
   11962              : void
   11963      3345810 : record_builtin_type (enum rid rid_index, const char *name, tree type)
   11964              : {
   11965      3345810 :   tree id, decl;
   11966      3345810 :   if (name == 0)
   11967      1561378 :     id = ridpointers[(int) rid_index];
   11968              :   else
   11969      1784432 :     id = get_identifier (name);
   11970      3345810 :   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
   11971      3345810 :   pushdecl (decl);
   11972      3345810 :   if (debug_hooks->type_decl)
   11973      3345810 :     debug_hooks->type_decl (decl, false);
   11974      3345810 : }
   11975              : 
   11976              : /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
   11977              : 
   11978              : struct c_parm *
   11979    124672088 : build_c_parm (struct c_declspecs *specs, tree attrs,
   11980              :               struct c_declarator *declarator,
   11981              :               location_t loc)
   11982              : {
   11983    124672088 :   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
   11984    124672088 :   ret->specs = specs;
   11985    124672088 :   ret->attrs = attrs;
   11986    124672088 :   ret->declarator = declarator;
   11987    124672088 :   ret->loc = loc;
   11988    124672088 :   return ret;
   11989              : }
   11990              : 
   11991              : /* Return a declarator with nested attributes.  TARGET is the inner
   11992              :    declarator to which these attributes apply.  ATTRS are the
   11993              :    attributes.  */
   11994              : 
   11995              : struct c_declarator *
   11996         6789 : build_attrs_declarator (tree attrs, struct c_declarator *target)
   11997              : {
   11998         6789 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   11999         6789 :   ret->kind = cdk_attrs;
   12000         6789 :   ret->declarator = target;
   12001         6789 :   ret->u.attrs = attrs;
   12002         6789 :   return ret;
   12003              : }
   12004              : 
   12005              : /* Return a declarator for a function with arguments specified by ARGS
   12006              :    and return type specified by TARGET.  */
   12007              : 
   12008              : struct c_declarator *
   12009     50974916 : build_function_declarator (struct c_arg_info *args,
   12010              :                            struct c_declarator *target)
   12011              : {
   12012     50974916 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12013     50974916 :   ret->kind = cdk_function;
   12014     50974916 :   ret->declarator = target;
   12015     50974916 :   ret->u.arg_info = args;
   12016     50974916 :   return ret;
   12017              : }
   12018              : 
   12019              : /* Return a declarator for the identifier IDENT (which may be
   12020              :    NULL_TREE for an abstract declarator).  */
   12021              : 
   12022              : struct c_declarator *
   12023    315216911 : build_id_declarator (tree ident)
   12024              : {
   12025    315216911 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12026    315216911 :   ret->kind = cdk_id;
   12027    315216911 :   ret->declarator = 0;
   12028    315216911 :   ret->u.id.id = ident;
   12029    315216911 :   ret->u.id.attrs = NULL_TREE;
   12030              :   /* Default value - may get reset to a more precise location. */
   12031    315216911 :   ret->id_loc = input_location;
   12032    315216911 :   return ret;
   12033              : }
   12034              : 
   12035              : /* Return something to represent absolute declarators containing a *.
   12036              :    TARGET is the absolute declarator that the * contains.
   12037              :    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
   12038              :    to apply to the pointer type.  */
   12039              : 
   12040              : struct c_declarator *
   12041     18334651 : make_pointer_declarator (struct c_declspecs *type_quals_attrs,
   12042              :                          struct c_declarator *target)
   12043              : {
   12044     18334651 :   tree attrs;
   12045     18334651 :   int quals = 0;
   12046     18334651 :   struct c_declarator *itarget = target;
   12047     18334651 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12048     18334651 :   if (type_quals_attrs)
   12049              :     {
   12050     18334651 :       attrs = type_quals_attrs->attrs;
   12051     18334651 :       quals = quals_from_declspecs (type_quals_attrs);
   12052     18334651 :       if (attrs != NULL_TREE)
   12053         6517 :         itarget = build_attrs_declarator (attrs, target);
   12054              :     }
   12055     18334651 :   ret->kind = cdk_pointer;
   12056     18334651 :   ret->declarator = itarget;
   12057     18334651 :   ret->u.pointer_quals = quals;
   12058     18334651 :   return ret;
   12059              : }
   12060              : 
   12061              : /* Return a pointer to a structure for an empty list of declaration
   12062              :    specifiers.  */
   12063              : 
   12064              : struct c_declspecs *
   12065    456249533 : build_null_declspecs (void)
   12066              : {
   12067    456249533 :   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
   12068    456249533 :   memset (ret, 0, sizeof *ret);
   12069    456249533 :   ret->align_log = -1;
   12070    456249533 :   ret->typespec_word = cts_none;
   12071    456249533 :   ret->storage_class = csc_none;
   12072    456249533 :   ret->expr_const_operands = true;
   12073    456249533 :   ret->typespec_kind = ctsk_none;
   12074    456249533 :   ret->address_space = ADDR_SPACE_GENERIC;
   12075    456249533 :   return ret;
   12076              : }
   12077              : 
   12078              : /* Add the address space ADDRSPACE to the declaration specifiers
   12079              :    SPECS, returning SPECS.  */
   12080              : 
   12081              : struct c_declspecs *
   12082          177 : declspecs_add_addrspace (location_t location,
   12083              :                          struct c_declspecs *specs, addr_space_t as)
   12084              : {
   12085          177 :   specs->non_sc_seen_p = true;
   12086          177 :   specs->declspecs_seen_p = true;
   12087          177 :   specs->non_std_attrs_seen_p = true;
   12088              : 
   12089          177 :   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
   12090            0 :       && specs->address_space != as)
   12091            0 :     error ("incompatible address space qualifiers %qs and %qs",
   12092              :            c_addr_space_name (as),
   12093              :            c_addr_space_name (specs->address_space));
   12094              :   else
   12095              :     {
   12096          177 :       specs->address_space = as;
   12097          177 :       specs->locations[cdw_address_space] = location;
   12098              :     }
   12099          177 :   return specs;
   12100              : }
   12101              : 
   12102              : /* Add the type qualifier QUAL to the declaration specifiers SPECS,
   12103              :    returning SPECS.  */
   12104              : 
   12105              : struct c_declspecs *
   12106     16642536 : declspecs_add_qual (location_t loc,
   12107              :                     struct c_declspecs *specs, tree qual)
   12108              : {
   12109     16642536 :   enum rid i;
   12110     16642536 :   bool dupe = false;
   12111     16642536 :   specs->non_sc_seen_p = true;
   12112     16642536 :   specs->declspecs_seen_p = true;
   12113     16642536 :   specs->non_std_attrs_seen_p = true;
   12114     16642536 :   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
   12115              :               && C_IS_RESERVED_WORD (qual));
   12116     16642536 :   i = C_RID_CODE (qual);
   12117     16642536 :   location_t prev_loc = UNKNOWN_LOCATION;
   12118     16642536 :   switch (i)
   12119              :     {
   12120     13125424 :     case RID_CONST:
   12121     13125424 :       dupe = specs->const_p;
   12122     13125424 :       specs->const_p = true;
   12123     13125424 :       prev_loc = specs->locations[cdw_const];
   12124     13125424 :       specs->locations[cdw_const] = loc;
   12125     13125424 :       break;
   12126        96187 :     case RID_VOLATILE:
   12127        96187 :       dupe = specs->volatile_p;
   12128        96187 :       specs->volatile_p = true;
   12129        96187 :       prev_loc = specs->locations[cdw_volatile];
   12130        96187 :       specs->locations[cdw_volatile] = loc;
   12131        96187 :       break;
   12132      3400525 :     case RID_RESTRICT:
   12133      3400525 :       dupe = specs->restrict_p;
   12134      3400525 :       specs->restrict_p = true;
   12135      3400525 :       prev_loc = specs->locations[cdw_restrict];
   12136      3400525 :       specs->locations[cdw_restrict] = loc;
   12137      3400525 :       break;
   12138        20400 :     case RID_ATOMIC:
   12139        20400 :       dupe = specs->atomic_p;
   12140        20400 :       specs->atomic_p = true;
   12141        20400 :       prev_loc = specs->locations[cdw_atomic];
   12142        20400 :       specs->locations[cdw_atomic] = loc;
   12143        20400 :       break;
   12144            0 :     default:
   12145            0 :       gcc_unreachable ();
   12146              :     }
   12147     16642536 :   if (dupe)
   12148              :     {
   12149           56 :       bool warned = pedwarn_c90 (loc, OPT_Wpedantic,
   12150              :                                  "duplicate %qE declaration specifier", qual);
   12151           56 :       if (!warned
   12152           52 :           && warn_duplicate_decl_specifier
   12153           33 :           && prev_loc >= RESERVED_LOCATION_COUNT
   12154           33 :           && !from_macro_expansion_at (prev_loc)
   12155           77 :           && !from_macro_expansion_at (loc))
   12156           12 :         warning_at (loc, OPT_Wduplicate_decl_specifier,
   12157              :                     "duplicate %qE declaration specifier", qual);
   12158              :     }
   12159     16642536 :   return specs;
   12160              : }
   12161              : 
   12162              : /* Add the type specifier TYPE to the declaration specifiers SPECS,
   12163              :    returning SPECS.  */
   12164              : 
   12165              : struct c_declspecs *
   12166    333117602 : declspecs_add_type (location_t loc, struct c_declspecs *specs,
   12167              :                     struct c_typespec spec)
   12168              : {
   12169    333117602 :   tree type = spec.spec;
   12170    333117602 :   specs->non_sc_seen_p = true;
   12171    333117602 :   specs->declspecs_seen_p = true;
   12172    333117602 :   specs->non_std_attrs_seen_p = true;
   12173    333117602 :   specs->typespec_kind = spec.kind;
   12174    333117602 :   if (TREE_DEPRECATED (type))
   12175           56 :     specs->deprecated_p = true;
   12176    333117602 :   if (TREE_UNAVAILABLE (type))
   12177           40 :     specs->unavailable_p = true;
   12178              : 
   12179              :   /* As a type specifier is present, "auto" must be used as a storage
   12180              :      class specifier, not for type deduction.  */
   12181    333117602 :   if (specs->c23_auto_p)
   12182              :     {
   12183          115 :       specs->c23_auto_p = false;
   12184          115 :       if (specs->storage_class != csc_none)
   12185            1 :         error ("multiple storage classes in declaration specifiers");
   12186          114 :       else if (specs->thread_p)
   12187            1 :         error ("%qs used with %<auto%>",
   12188            1 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   12189          113 :       else if (specs->constexpr_p)
   12190              :         /* auto may only be used with another storage class specifier,
   12191              :            such as constexpr, if the type is inferred.  */
   12192            2 :         error ("%<auto%> used with %<constexpr%>");
   12193              :       else
   12194          111 :         specs->storage_class = csc_auto;
   12195              :     }
   12196              : 
   12197              :   /* Handle type specifier keywords.  */
   12198    333117602 :   if (TREE_CODE (type) == IDENTIFIER_NODE
   12199     83967902 :       && C_IS_RESERVED_WORD (type)
   12200    417085504 :       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
   12201              :     {
   12202     83967902 :       enum rid i = C_RID_CODE (type);
   12203     83967902 :       if (specs->type)
   12204              :         {
   12205           58 :           error_at (loc, "two or more data types in declaration specifiers");
   12206           58 :           return specs;
   12207              :         }
   12208     83967844 :       if ((int) i <= (int) RID_LAST_MODIFIER)
   12209              :         {
   12210              :           /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
   12211     22061932 :           bool dupe = false;
   12212     22061932 :           switch (i)
   12213              :             {
   12214     11035094 :             case RID_LONG:
   12215     11035094 :               if (specs->long_long_p)
   12216              :                 {
   12217          104 :                   error_at (loc, "%<long long long%> is too long for GCC");
   12218          104 :                   break;
   12219              :                 }
   12220     11034990 :               if (specs->long_p)
   12221              :                 {
   12222      2965445 :                   if (specs->typespec_word == cts_double)
   12223              :                     {
   12224           15 :                       error_at (loc,
   12225              :                                 "both %qs and %qs in declaration specifiers",
   12226              :                                 "long long", "double");
   12227           15 :                       break;
   12228              :                     }
   12229      2965430 :                   pedwarn_c90 (loc, OPT_Wlong_long,
   12230              :                                "ISO C90 does not support %<long long%>");
   12231      2965430 :                   specs->long_long_p = 1;
   12232      2965430 :                   specs->locations[cdw_long_long] = loc;
   12233      2965430 :                   break;
   12234              :                 }
   12235      8069545 :               if (specs->short_p)
   12236           77 :                 error_at (loc,
   12237              :                           "both %qs and %qs in declaration specifiers",
   12238              :                           "long", "short");
   12239      8069468 :               else if (specs->typespec_word == cts_auto_type)
   12240            1 :                 error_at (loc,
   12241              :                           "both %qs and %qs in declaration specifiers",
   12242              :                           "long", "__auto_type");
   12243              :               else if (specs->typespec_word == cts_void)
   12244            5 :                 error_at (loc,
   12245              :                           "both %qs and %qs in declaration specifiers",
   12246              :                           "long", "void");
   12247              :               else if (specs->typespec_word == cts_int_n)
   12248           19 :                 error_at (loc,
   12249              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12250           19 :                           "long", int_n_data[specs->u.int_n_idx].bitsize);
   12251              :               else if (specs->typespec_word == cts_bool)
   12252            3 :                 error_at (loc,
   12253              :                           "both %qs and %qs in declaration specifiers",
   12254              :                           "long", "_Bool");
   12255              :               else if (specs->typespec_word == cts_bitint)
   12256            3 :                 error_at (loc,
   12257              :                           "both %qs and %qs in declaration specifiers",
   12258              :                           "long", "_BitInt");
   12259              :               else if (specs->typespec_word == cts_char)
   12260           21 :                 error_at (loc,
   12261              :                           "both %qs and %qs in declaration specifiers",
   12262              :                           "long", "char");
   12263              :               else if (specs->typespec_word == cts_float)
   12264            7 :                 error_at (loc,
   12265              :                           "both %qs and %qs in declaration specifiers",
   12266              :                           "long", "float");
   12267              :               else if (specs->typespec_word == cts_floatn_nx)
   12268            0 :                 error_at (loc,
   12269              :                           "both %qs and %<_Float%d%s%> in declaration "
   12270              :                           "specifiers", "long",
   12271            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12272            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12273              :                           ? "x"
   12274              :                           : "");
   12275              :               else if (specs->typespec_word == cts_dfloat32)
   12276            4 :                 error_at (loc,
   12277              :                           "both %qs and %qs in declaration specifiers",
   12278              :                           "long", "_Decimal32");
   12279              :               else if (specs->typespec_word == cts_dfloat64)
   12280            4 :                 error_at (loc,
   12281              :                           "both %qs and %qs in declaration specifiers",
   12282              :                           "long", "_Decimal64");
   12283              :               else if (specs->typespec_word == cts_dfloat128)
   12284            4 :                 error_at (loc,
   12285              :                           "both %qs and %qs in declaration specifiers",
   12286              :                           "long", "_Decimal128");
   12287              :               else if (specs->typespec_word == cts_dfloat64x)
   12288            0 :                 error_at (loc,
   12289              :                           "both %qs and %qs in declaration specifiers",
   12290              :                           "long", "_Decimal64x");
   12291              :               else
   12292              :                 {
   12293      8069397 :                   specs->long_p = true;
   12294      8069397 :                   specs->locations[cdw_long] = loc;
   12295              :                 }
   12296              :               break;
   12297      1703065 :             case RID_SHORT:
   12298      1703065 :               dupe = specs->short_p;
   12299      1703065 :               if (specs->long_p)
   12300          197 :                 error_at (loc,
   12301              :                           "both %qs and %qs in declaration specifiers",
   12302              :                           "long", "short");
   12303      1702868 :               else if (specs->typespec_word == cts_auto_type)
   12304            1 :                 error_at (loc,
   12305              :                           "both %qs and %qs in declaration specifiers",
   12306              :                           "short", "__auto_type");
   12307              :               else if (specs->typespec_word == cts_void)
   12308            5 :                 error_at (loc,
   12309              :                           "both %qs and %qs in declaration specifiers",
   12310              :                           "short", "void");
   12311              :               else if (specs->typespec_word == cts_int_n)
   12312           19 :                 error_at (loc,
   12313              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12314           19 :                           "short", int_n_data[specs->u.int_n_idx].bitsize);
   12315              :               else if (specs->typespec_word == cts_bool)
   12316            3 :                 error_at (loc,
   12317              :                           "both %qs and %qs in declaration specifiers",
   12318              :                           "short", "_Bool");
   12319              :               else if (specs->typespec_word == cts_bitint)
   12320            1 :                 error_at (loc,
   12321              :                           "both %qs and %qs in declaration specifiers",
   12322              :                           "short", "_BitInt");
   12323              :               else if (specs->typespec_word == cts_char)
   12324           21 :                 error_at (loc,
   12325              :                           "both %qs and %qs in declaration specifiers",
   12326              :                           "short", "char");
   12327              :               else if (specs->typespec_word == cts_float)
   12328            7 :                 error_at (loc,
   12329              :                           "both %qs and %qs in declaration specifiers",
   12330              :                           "short", "float");
   12331              :               else if (specs->typespec_word == cts_double)
   12332            7 :                 error_at (loc,
   12333              :                           "both %qs and %qs in declaration specifiers",
   12334              :                           "short", "double");
   12335              :               else if (specs->typespec_word == cts_floatn_nx)
   12336            0 :                 error_at (loc,
   12337              :                           "both %qs and %<_Float%d%s%> in declaration "
   12338              :                           "specifiers", "short",
   12339            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12340            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12341              :                           ? "x"
   12342              :                           : "");
   12343              :               else if (specs->typespec_word == cts_dfloat32)
   12344            4 :                 error_at (loc,
   12345              :                           "both %qs and %qs in declaration specifiers",
   12346              :                           "short", "_Decimal32");
   12347              :               else if (specs->typespec_word == cts_dfloat64)
   12348            4 :                 error_at (loc,
   12349              :                           "both %qs and %qs in declaration specifiers",
   12350              :                           "short", "_Decimal64");
   12351              :               else if (specs->typespec_word == cts_dfloat128)
   12352            4 :                 error_at (loc,
   12353              :                           "both %qs and %qs in declaration specifiers",
   12354              :                           "short", "_Decimal128");
   12355              :               else if (specs->typespec_word == cts_dfloat64x)
   12356            0 :                 error_at (loc,
   12357              :                           "both %qs and %qs in declaration specifiers",
   12358              :                           "short", "_Decimal64x");
   12359              :               else
   12360              :                 {
   12361      1702792 :                   specs->short_p = true;
   12362      1702792 :                   specs->locations[cdw_short] = loc;
   12363              :                 }
   12364              :               break;
   12365       553352 :             case RID_SIGNED:
   12366       553352 :               dupe = specs->signed_p;
   12367       553352 :               if (specs->unsigned_p)
   12368          138 :                 error_at (loc,
   12369              :                           "both %qs and %qs in declaration specifiers",
   12370              :                           "signed", "unsigned");
   12371       553214 :               else if (specs->typespec_word == cts_auto_type)
   12372            1 :                 error_at (loc,
   12373              :                           "both %qs and %qs in declaration specifiers",
   12374              :                           "signed", "__auto_type");
   12375              :               else if (specs->typespec_word == cts_void)
   12376            5 :                 error_at (loc,
   12377              :                           "both %qs and %qs in declaration specifiers",
   12378              :                           "signed", "void");
   12379              :               else if (specs->typespec_word == cts_bool)
   12380            3 :                 error_at (loc,
   12381              :                           "both %qs and %qs in declaration specifiers",
   12382              :                           "signed", "_Bool");
   12383              :               else if (specs->typespec_word == cts_float)
   12384            7 :                 error_at (loc,
   12385              :                           "both %qs and %qs in declaration specifiers",
   12386              :                           "signed", "float");
   12387              :               else if (specs->typespec_word == cts_double)
   12388           21 :                 error_at (loc,
   12389              :                           "both %qs and %qs in declaration specifiers",
   12390              :                           "signed", "double");
   12391              :               else if (specs->typespec_word == cts_floatn_nx)
   12392            0 :                 error_at (loc,
   12393              :                           "both %qs and %<_Float%d%s%> in declaration "
   12394              :                           "specifiers", "signed",
   12395            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12396            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12397              :                           ? "x"
   12398              :                           : "");
   12399              :               else if (specs->typespec_word == cts_dfloat32)
   12400            4 :                 error_at (loc,
   12401              :                           "both %qs and %qs in declaration specifiers",
   12402              :                           "signed", "_Decimal32");
   12403              :               else if (specs->typespec_word == cts_dfloat64)
   12404            4 :                 error_at (loc,
   12405              :                           "both %qs and %qs in declaration specifiers",
   12406              :                           "signed", "_Decimal64");
   12407              :               else if (specs->typespec_word == cts_dfloat128)
   12408            4 :                 error_at (loc,
   12409              :                           "both %qs and %qs in declaration specifiers",
   12410              :                           "signed", "_Decimal128");
   12411              :               else if (specs->typespec_word == cts_dfloat64x)
   12412            0 :                 error_at (loc,
   12413              :                           "both %qs and %qs in declaration specifiers",
   12414              :                           "signed", "_Decimal64x");
   12415              :               else
   12416              :                 {
   12417       553165 :                   specs->signed_p = true;
   12418       553165 :                   specs->locations[cdw_signed] = loc;
   12419              :                 }
   12420              :               break;
   12421      6192421 :             case RID_UNSIGNED:
   12422      6192421 :               dupe = specs->unsigned_p;
   12423      6192421 :               if (specs->signed_p)
   12424          139 :                 error_at (loc,
   12425              :                           "both %qs and %qs in declaration specifiers",
   12426              :                           "signed", "unsigned");
   12427      6192282 :               else if (specs->typespec_word == cts_auto_type)
   12428            1 :                 error_at (loc,
   12429              :                           "both %qs and %qs in declaration specifiers",
   12430              :                           "unsigned", "__auto_type");
   12431              :               else if (specs->typespec_word == cts_void)
   12432            5 :                 error_at (loc,
   12433              :                           "both %qs and %qs in declaration specifiers",
   12434              :                           "unsigned", "void");
   12435              :               else if (specs->typespec_word == cts_bool)
   12436            3 :                 error_at (loc,
   12437              :                           "both %qs and %qs in declaration specifiers",
   12438              :                           "unsigned", "_Bool");
   12439              :               else if (specs->typespec_word == cts_float)
   12440            7 :                 error_at (loc,
   12441              :                           "both %qs and %qs in declaration specifiers",
   12442              :                           "unsigned", "float");
   12443              :               else if (specs->typespec_word == cts_double)
   12444           21 :                 error_at (loc,
   12445              :                           "both %qs and %qs in declaration specifiers",
   12446              :                           "unsigned", "double");
   12447              :               else if (specs->typespec_word == cts_floatn_nx)
   12448            0 :                 error_at (loc,
   12449              :                           "both %qs and %<_Float%d%s%> in declaration "
   12450              :                           "specifiers", "unsigned",
   12451            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12452            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12453              :                           ? "x"
   12454              :                           : "");
   12455              :               else if (specs->typespec_word == cts_dfloat32)
   12456            2 :                 error_at (loc,
   12457              :                           "both %qs and %qs in declaration specifiers",
   12458              :                           "unsigned", "_Decimal32");
   12459              :               else if (specs->typespec_word == cts_dfloat64)
   12460            2 :                 error_at (loc,
   12461              :                           "both %qs and %qs in declaration specifiers",
   12462              :                           "unsigned", "_Decimal64");
   12463              :               else if (specs->typespec_word == cts_dfloat128)
   12464            2 :                 error_at (loc,
   12465              :                           "both %qs and %qs in declaration specifiers",
   12466              :                           "unsigned", "_Decimal128");
   12467              :               else if (specs->typespec_word == cts_dfloat64x)
   12468            0 :                 error_at (loc,
   12469              :                           "both %qs and %qs in declaration specifiers",
   12470              :                           "unsigned", "_Decimal64x");
   12471              :               else
   12472              :                 {
   12473      6192239 :                   specs->unsigned_p = true;
   12474      6192239 :                   specs->locations[cdw_unsigned] = loc;
   12475              :                 }
   12476              :               break;
   12477      2577939 :             case RID_COMPLEX:
   12478      2577939 :               dupe = specs->complex_p;
   12479      2577939 :               if (!in_system_header_at (loc))
   12480        69027 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12481              :                              "ISO C90 does not support complex types");
   12482      2577939 :               if (specs->typespec_word == cts_auto_type)
   12483            1 :                 error_at (loc,
   12484              :                           "both %qs and %qs in declaration specifiers",
   12485              :                           "complex", "__auto_type");
   12486              :               else if (specs->typespec_word == cts_void)
   12487            2 :                 error_at (loc,
   12488              :                           "both %qs and %qs in declaration specifiers",
   12489              :                           "complex", "void");
   12490              :               else if (specs->typespec_word == cts_bool)
   12491            2 :                 error_at (loc,
   12492              :                           "both %qs and %qs in declaration specifiers",
   12493              :                           "complex", "_Bool");
   12494              :               else if (specs->typespec_word == cts_bitint)
   12495            1 :                 error_at (loc,
   12496              :                           "both %qs and %qs in declaration specifiers",
   12497              :                           "complex", "_BitInt");
   12498              :               else if (specs->typespec_word == cts_dfloat32)
   12499            1 :                 error_at (loc,
   12500              :                           "both %qs and %qs in declaration specifiers",
   12501              :                           "complex", "_Decimal32");
   12502              :               else if (specs->typespec_word == cts_dfloat64)
   12503            1 :                 error_at (loc,
   12504              :                           "both %qs and %qs in declaration specifiers",
   12505              :                           "complex", "_Decimal64");
   12506              :               else if (specs->typespec_word == cts_dfloat128)
   12507            1 :                 error_at (loc,
   12508              :                           "both %qs and %qs in declaration specifiers",
   12509              :                           "complex", "_Decimal128");
   12510              :               else if (specs->typespec_word == cts_dfloat64x)
   12511            0 :                 error_at (loc,
   12512              :                           "both %qs and %qs in declaration specifiers",
   12513              :                           "complex", "_Decimal64x");
   12514              :               else if (specs->typespec_word == cts_fract)
   12515            0 :                 error_at (loc,
   12516              :                           "both %qs and %qs in declaration specifiers",
   12517              :                           "complex", "_Fract");
   12518              :               else if (specs->typespec_word == cts_accum)
   12519            0 :                 error_at (loc,
   12520              :                           "both %qs and %qs in declaration specifiers",
   12521              :                           "complex", "_Accum");
   12522      2577930 :               else if (specs->saturating_p)
   12523            0 :                 error_at (loc,
   12524              :                           "both %qs and %qs in declaration specifiers",
   12525              :                           "complex", "_Sat");
   12526              :               else
   12527              :                 {
   12528      2577930 :                   specs->complex_p = true;
   12529      2577930 :                   specs->locations[cdw_complex] = loc;
   12530              :                 }
   12531              :               break;
   12532           61 :             case RID_SAT:
   12533           61 :               dupe = specs->saturating_p;
   12534           61 :               pedwarn (loc, OPT_Wpedantic,
   12535              :                        "ISO C does not support saturating types");
   12536           61 :               if (specs->typespec_word == cts_int_n)
   12537            0 :                 error_at (loc,
   12538              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12539            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12540              :               else if (specs->typespec_word == cts_auto_type)
   12541            0 :                 error_at (loc,
   12542              :                           "both %qs and %qs in declaration specifiers",
   12543              :                           "_Sat", "__auto_type");
   12544              :               else if (specs->typespec_word == cts_void)
   12545            0 :                 error_at (loc,
   12546              :                           "both %qs and %qs in declaration specifiers",
   12547              :                           "_Sat", "void");
   12548              :               else if (specs->typespec_word == cts_bool)
   12549            0 :                 error_at (loc,
   12550              :                           "both %qs and %qs in declaration specifiers",
   12551              :                           "_Sat", "_Bool");
   12552              :               else if (specs->typespec_word == cts_bitint)
   12553            0 :                 error_at (loc,
   12554              :                           "both %qs and %qs in declaration specifiers",
   12555              :                           "_Sat", "_BitInt");
   12556              :               else if (specs->typespec_word == cts_char)
   12557            0 :                 error_at (loc,
   12558              :                           "both %qs and %qs in declaration specifiers",
   12559              :                           "_Sat", "char");
   12560              :               else if (specs->typespec_word == cts_int)
   12561            0 :                 error_at (loc,
   12562              :                           "both %qs and %qs in declaration specifiers",
   12563              :                           "_Sat", "int");
   12564              :               else if (specs->typespec_word == cts_float)
   12565            0 :                 error_at (loc,
   12566              :                           "both %qs and %qs in declaration specifiers",
   12567              :                           "_Sat", "float");
   12568              :               else if (specs->typespec_word == cts_double)
   12569            0 :                 error_at (loc,
   12570              :                           "both %qs and %qs in declaration specifiers",
   12571              :                           "_Sat", "double");
   12572              :               else if (specs->typespec_word == cts_floatn_nx)
   12573            0 :                 error_at (loc,
   12574              :                           "both %qs and %<_Float%d%s%> in declaration "
   12575              :                           "specifiers", "_Sat",
   12576            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12577            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12578              :                           ? "x"
   12579              :                           : "");
   12580              :               else if (specs->typespec_word == cts_dfloat32)
   12581            0 :                 error_at (loc,
   12582              :                           "both %qs and %qs in declaration specifiers",
   12583              :                           "_Sat", "_Decimal32");
   12584              :               else if (specs->typespec_word == cts_dfloat64)
   12585            0 :                 error_at (loc,
   12586              :                           "both %qs and %qs in declaration specifiers",
   12587              :                           "_Sat", "_Decimal64");
   12588              :               else if (specs->typespec_word == cts_dfloat128)
   12589            0 :                 error_at (loc,
   12590              :                           "both %qs and %qs in declaration specifiers",
   12591              :                           "_Sat", "_Decimal128");
   12592              :               else if (specs->typespec_word == cts_dfloat64x)
   12593            0 :                 error_at (loc,
   12594              :                           "both %qs and %qs in declaration specifiers",
   12595              :                           "_Sat", "_Decimal64x");
   12596           61 :               else if (specs->complex_p)
   12597            0 :                 error_at (loc,
   12598              :                           "both %qs and %qs in declaration specifiers",
   12599              :                           "_Sat", "complex");
   12600              :               else
   12601              :                 {
   12602           61 :                   specs->saturating_p = true;
   12603           61 :                   specs->locations[cdw_saturating] = loc;
   12604              :                 }
   12605              :               break;
   12606            0 :             default:
   12607            0 :               gcc_unreachable ();
   12608              :             }
   12609              : 
   12610     22061932 :           if (dupe)
   12611          378 :             error_at (loc, "duplicate %qE", type);
   12612              : 
   12613     22061932 :           return specs;
   12614              :         }
   12615              :       else
   12616              :         {
   12617              :           /* "void", "_Bool", "char", "int", "float", "double",
   12618              :              "_FloatN", "_FloatNx", "_Decimal32", "__intN",
   12619              :              "_Decimal64", "_Decimal128", "_Fract", "_Accum", "_BitInt(N)" or
   12620              :              "__auto_type".  */
   12621     61905912 :           if (specs->typespec_word != cts_none)
   12622              :             {
   12623         2171 :               if (i == RID_BOOL)
   12624              :                 {
   12625          175 :                   auto_diagnostic_group d;
   12626          175 :                   if (specs->storage_class == csc_typedef)
   12627            4 :                     error_at (loc,
   12628              :                               "%qs cannot be defined via %<typedef%>",
   12629            2 :                               IDENTIFIER_POINTER (type));
   12630              :                   else
   12631          346 :                     error_at (loc,
   12632              :                               "%qs cannot be used here",
   12633          173 :                               IDENTIFIER_POINTER (type));
   12634          175 :                   add_note_about_new_keyword (loc, type);
   12635          175 :                 }
   12636              :               else
   12637         1996 :                 error_at (loc,
   12638              :                           "two or more data types in declaration specifiers");
   12639         2171 :               return specs;
   12640              :             }
   12641     61903741 :           switch (i)
   12642              :             {
   12643         1890 :             case RID_AUTO_TYPE:
   12644         1890 :               if (specs->long_p)
   12645            1 :                 error_at (loc,
   12646              :                           "both %qs and %qs in declaration specifiers",
   12647              :                           "long", "__auto_type");
   12648         1889 :               else if (specs->short_p)
   12649            1 :                 error_at (loc,
   12650              :                           "both %qs and %qs in declaration specifiers",
   12651              :                           "short", "__auto_type");
   12652         1888 :               else if (specs->signed_p)
   12653            1 :                 error_at (loc,
   12654              :                           "both %qs and %qs in declaration specifiers",
   12655              :                           "signed", "__auto_type");
   12656         1887 :               else if (specs->unsigned_p)
   12657            1 :                 error_at (loc,
   12658              :                           "both %qs and %qs in declaration specifiers",
   12659              :                           "unsigned", "__auto_type");
   12660         1886 :               else if (specs->complex_p)
   12661            1 :                 error_at (loc,
   12662              :                           "both %qs and %qs in declaration specifiers",
   12663              :                           "complex", "__auto_type");
   12664         1885 :               else if (specs->saturating_p)
   12665            0 :                 error_at (loc,
   12666              :                           "both %qs and %qs in declaration specifiers",
   12667              :                           "_Sat", "__auto_type");
   12668              :               else
   12669              :                 {
   12670         1885 :                   specs->typespec_word = cts_auto_type;
   12671         1885 :                   specs->locations[cdw_typespec] = loc;
   12672              :                 }
   12673         1890 :               return specs;
   12674        51856 :             case RID_INT_N_0:
   12675        51856 :             case RID_INT_N_1:
   12676        51856 :             case RID_INT_N_2:
   12677        51856 :             case RID_INT_N_3:
   12678        51856 :               specs->u.int_n_idx = i - RID_INT_N_0;
   12679        51856 :               if (!in_system_header_at (input_location)
   12680              :                   /* If the INT_N type ends in "__", and so is of the format
   12681              :                      "__intN__", don't pedwarn.  */
   12682        51856 :                   && (strncmp (IDENTIFIER_POINTER (type)
   12683        41208 :                                + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0))
   12684        41208 :                 pedwarn (loc, OPT_Wpedantic,
   12685              :                          "ISO C does not support %<__int%d%> types",
   12686        41208 :                          int_n_data[specs->u.int_n_idx].bitsize);
   12687              : 
   12688        51856 :               if (specs->long_p)
   12689           53 :                 error_at (loc,
   12690              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12691           53 :                           int_n_data[specs->u.int_n_idx].bitsize, "long");
   12692        51803 :               else if (specs->saturating_p)
   12693            0 :                 error_at (loc,
   12694              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12695            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12696        51803 :               else if (specs->short_p)
   12697           19 :                 error_at (loc,
   12698              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12699           19 :                           int_n_data[specs->u.int_n_idx].bitsize, "short");
   12700        51784 :               else if (! int_n_enabled_p[specs->u.int_n_idx])
   12701              :                 {
   12702            0 :                   specs->typespec_word = cts_int_n;
   12703            0 :                   error_at (loc,
   12704              :                             "%<__int%d%> is not supported on this target",
   12705            0 :                             int_n_data[specs->u.int_n_idx].bitsize);
   12706              :                 }
   12707              :               else
   12708              :                 {
   12709        51784 :                   specs->typespec_word = cts_int_n;
   12710        51784 :                   specs->locations[cdw_typespec] = loc;
   12711              :                 }
   12712        51856 :               return specs;
   12713      7973431 :             case RID_VOID:
   12714      7973431 :               if (specs->long_p)
   12715           44 :                 error_at (loc,
   12716              :                           "both %qs and %qs in declaration specifiers",
   12717              :                           "long", "void");
   12718      7973387 :               else if (specs->short_p)
   12719           21 :                 error_at (loc,
   12720              :                           "both %qs and %qs in declaration specifiers",
   12721              :                           "short", "void");
   12722      7973366 :               else if (specs->signed_p)
   12723            5 :                 error_at (loc,
   12724              :                           "both %qs and %qs in declaration specifiers",
   12725              :                           "signed", "void");
   12726      7973361 :               else if (specs->unsigned_p)
   12727            5 :                 error_at (loc,
   12728              :                           "both %qs and %qs in declaration specifiers",
   12729              :                           "unsigned", "void");
   12730      7973356 :               else if (specs->complex_p)
   12731            2 :                 error_at (loc,
   12732              :                           "both %qs and %qs in declaration specifiers",
   12733              :                           "complex", "void");
   12734      7973354 :               else if (specs->saturating_p)
   12735            0 :                 error_at (loc,
   12736              :                           "both %qs and %qs in declaration specifiers",
   12737              :                           "_Sat", "void");
   12738              :               else
   12739              :                 {
   12740      7973354 :                   specs->typespec_word = cts_void;
   12741      7973354 :                   specs->locations[cdw_typespec] = loc;
   12742              :                 }
   12743      7973431 :               return specs;
   12744        89688 :             case RID_BOOL:
   12745        89688 :               if (!in_system_header_at (loc))
   12746        71605 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12747              :                              "ISO C90 does not support boolean types");
   12748        89688 :               if (specs->long_p)
   12749           27 :                 error_at (loc,
   12750              :                           "both %qs and %qs in declaration specifiers",
   12751              :                           "long", "_Bool");
   12752        89661 :               else if (specs->short_p)
   12753           11 :                 error_at (loc,
   12754              :                           "both %qs and %qs in declaration specifiers",
   12755              :                           "short", "_Bool");
   12756        89650 :               else if (specs->signed_p)
   12757            3 :                 error_at (loc,
   12758              :                           "both %qs and %qs in declaration specifiers",
   12759              :                           "signed", "_Bool");
   12760        89647 :               else if (specs->unsigned_p)
   12761            3 :                 error_at (loc,
   12762              :                           "both %qs and %qs in declaration specifiers",
   12763              :                           "unsigned", "_Bool");
   12764        89644 :               else if (specs->complex_p)
   12765            2 :                 error_at (loc,
   12766              :                           "both %qs and %qs in declaration specifiers",
   12767              :                           "complex", "_Bool");
   12768        89642 :               else if (specs->saturating_p)
   12769            0 :                 error_at (loc,
   12770              :                           "both %qs and %qs in declaration specifiers",
   12771              :                           "_Sat", "_Bool");
   12772              :               else
   12773              :                 {
   12774        89642 :                   specs->typespec_word = cts_bool;
   12775        89642 :                   specs->locations[cdw_typespec] = loc;
   12776              :                 }
   12777        89688 :               return specs;
   12778      9048412 :             case RID_CHAR:
   12779      9048412 :               if (specs->long_p)
   12780           44 :                 error_at (loc,
   12781              :                           "both %qs and %qs in declaration specifiers",
   12782              :                           "long", "char");
   12783      9048368 :               else if (specs->short_p)
   12784           21 :                 error_at (loc,
   12785              :                           "both %qs and %qs in declaration specifiers",
   12786              :                           "short", "char");
   12787      9048347 :               else if (specs->saturating_p)
   12788            0 :                 error_at (loc,
   12789              :                           "both %qs and %qs in declaration specifiers",
   12790              :                           "_Sat", "char");
   12791              :               else
   12792              :                 {
   12793      9048347 :                   specs->typespec_word = cts_char;
   12794      9048347 :                   specs->locations[cdw_typespec] = loc;
   12795              :                 }
   12796      9048412 :               return specs;
   12797     23978395 :             case RID_INT:
   12798     23978395 :               if (specs->saturating_p)
   12799            0 :                 error_at (loc,
   12800              :                           "both %qs and %qs in declaration specifiers",
   12801              :                           "_Sat", "int");
   12802              :               else
   12803              :                 {
   12804     23978395 :                   specs->typespec_word = cts_int;
   12805     23978395 :                   specs->locations[cdw_typespec] = loc;
   12806              :                 }
   12807     23978395 :               return specs;
   12808      3631665 :             case RID_FLOAT:
   12809      3631665 :               if (specs->long_p)
   12810           44 :                 error_at (loc,
   12811              :                           "both %qs and %qs in declaration specifiers",
   12812              :                           "long", "float");
   12813      3631621 :               else if (specs->short_p)
   12814           21 :                 error_at (loc,
   12815              :                           "both %qs and %qs in declaration specifiers",
   12816              :                           "short", "float");
   12817      3631600 :               else if (specs->signed_p)
   12818            5 :                 error_at (loc,
   12819              :                           "both %qs and %qs in declaration specifiers",
   12820              :                           "signed", "float");
   12821      3631595 :               else if (specs->unsigned_p)
   12822            5 :                 error_at (loc,
   12823              :                           "both %qs and %qs in declaration specifiers",
   12824              :                           "unsigned", "float");
   12825      3631590 :               else if (specs->saturating_p)
   12826            0 :                 error_at (loc,
   12827              :                           "both %qs and %qs in declaration specifiers",
   12828              :                           "_Sat", "float");
   12829              :               else
   12830              :                 {
   12831      3631590 :                   specs->typespec_word = cts_float;
   12832      3631590 :                   specs->locations[cdw_typespec] = loc;
   12833              :                 }
   12834      3631665 :               return specs;
   12835      6606089 :             case RID_DOUBLE:
   12836      6606089 :               if (specs->long_long_p)
   12837           22 :                 error_at (loc,
   12838              :                           "both %qs and %qs in declaration specifiers",
   12839              :                           "long long", "double");
   12840      6606067 :               else if (specs->short_p)
   12841           21 :                 error_at (loc,
   12842              :                           "both %qs and %qs in declaration specifiers",
   12843              :                           "short", "double");
   12844      6606046 :               else if (specs->signed_p)
   12845           13 :                 error_at (loc,
   12846              :                           "both %qs and %qs in declaration specifiers",
   12847              :                           "signed", "double");
   12848      6606033 :               else if (specs->unsigned_p)
   12849           13 :                 error_at (loc,
   12850              :                           "both %qs and %qs in declaration specifiers",
   12851              :                           "unsigned", "double");
   12852      6606020 :               else if (specs->saturating_p)
   12853            0 :                 error_at (loc,
   12854              :                           "both %qs and %qs in declaration specifiers",
   12855              :                           "_Sat", "double");
   12856              :               else
   12857              :                 {
   12858      6606020 :                   specs->typespec_word = cts_double;
   12859      6606020 :                   specs->locations[cdw_typespec] = loc;
   12860              :                 }
   12861      6606089 :               return specs;
   12862     10427948 :             CASE_RID_FLOATN_NX:
   12863     10427948 :               specs->u.floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
   12864     10427948 :               if (!in_system_header_at (input_location))
   12865        53760 :                 pedwarn_c11 (loc, OPT_Wpedantic,
   12866              :                              "ISO C does not support the %<_Float%d%s%> type"
   12867              :                              " before C23",
   12868        53760 :                              floatn_nx_types[specs->u.floatn_nx_idx].n,
   12869        53760 :                              floatn_nx_types[specs->u.floatn_nx_idx].extended
   12870              :                              ? "x"
   12871              :                              : "");
   12872              : 
   12873     10427948 :               if (specs->long_p)
   12874            0 :                 error_at (loc,
   12875              :                           "both %qs and %<_Float%d%s%> in declaration "
   12876              :                           "specifiers", "long",
   12877            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12878            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12879              :                           ? "x"
   12880              :                           : "");
   12881     10427948 :               else if (specs->short_p)
   12882            0 :                 error_at (loc,
   12883              :                           "both %qs and %<_Float%d%s%> in declaration "
   12884              :                           "specifiers", "short",
   12885            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12886            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12887              :                           ? "x"
   12888              :                           : "");
   12889     10427948 :               else if (specs->signed_p)
   12890            0 :                 error_at (loc,
   12891              :                           "both %qs and %<_Float%d%s%> in declaration "
   12892              :                           "specifiers", "signed",
   12893            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12894            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12895              :                           ? "x"
   12896              :                           : "");
   12897     10427948 :               else if (specs->unsigned_p)
   12898            0 :                 error_at (loc,
   12899              :                           "both %qs and %<_Float%d%s%> in declaration "
   12900              :                           "specifiers", "unsigned",
   12901            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12902            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12903              :                           ? "x"
   12904              :                           : "");
   12905     10427948 :               else if (specs->saturating_p)
   12906            0 :                 error_at (loc,
   12907              :                           "both %qs and %<_Float%d%s%> in declaration "
   12908              :                           "specifiers", "_Sat",
   12909            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12910            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12911              :                           ? "x"
   12912              :                           : "");
   12913     10427948 :               else if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   12914              :                 {
   12915           88 :                   specs->typespec_word = cts_floatn_nx;
   12916          176 :                   error_at (loc,
   12917              :                             "%<_Float%d%s%> is not supported on this target",
   12918           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].n,
   12919           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].extended
   12920              :                             ? "x"
   12921              :                             : "");
   12922              :                 }
   12923              :               else
   12924              :                 {
   12925     10427860 :                   specs->typespec_word = cts_floatn_nx;
   12926     10427860 :                   specs->locations[cdw_typespec] = loc;
   12927              :                 }
   12928     10427948 :               return specs;
   12929        47639 :             case RID_DFLOAT32:
   12930        47639 :             case RID_DFLOAT64:
   12931        47639 :             case RID_DFLOAT128:
   12932        47639 :             case RID_DFLOAT64X:
   12933        47639 :               {
   12934        47639 :                 const char *str;
   12935        47639 :                 if (i == RID_DFLOAT32)
   12936              :                   str = "_Decimal32";
   12937              :                 else if (i == RID_DFLOAT64)
   12938              :                   str = "_Decimal64";
   12939              :                 else if (i == RID_DFLOAT128)
   12940              :                   str = "_Decimal128";
   12941              :                 else
   12942        47639 :                   str = "_Decimal64x";
   12943        47639 :                 if (specs->long_long_p)
   12944           18 :                   error_at (loc,
   12945              :                             "both %qs and %qs in declaration specifiers",
   12946              :                             "long long", str);
   12947        47639 :                 if (specs->long_p)
   12948           33 :                   error_at (loc,
   12949              :                             "both %qs and %qs in declaration specifiers",
   12950              :                             "long", str);
   12951        47606 :                 else if (specs->short_p)
   12952           18 :                   error_at (loc,
   12953              :                             "both %qs and %qs in declaration specifiers",
   12954              :                             "short", str);
   12955        47588 :                 else if (specs->signed_p)
   12956            6 :                   error_at (loc,
   12957              :                             "both %qs and %qs in declaration specifiers",
   12958              :                             "signed", str);
   12959        47582 :                 else if (specs->unsigned_p)
   12960            3 :                   error_at (loc,
   12961              :                             "both %qs and %qs in declaration specifiers",
   12962              :                             "unsigned", str);
   12963        47579 :                 else if (specs->complex_p)
   12964            3 :                   error_at (loc,
   12965              :                             "both %qs and %qs in declaration specifiers",
   12966              :                             "complex", str);
   12967        47576 :                 else if (specs->saturating_p)
   12968            0 :                   error_at (loc,
   12969              :                             "both %qs and %qs in declaration specifiers",
   12970              :                             "_Sat", str);
   12971        47576 :                 else if (i == RID_DFLOAT32)
   12972        15957 :                   specs->typespec_word = cts_dfloat32;
   12973        31619 :                 else if (i == RID_DFLOAT64)
   12974        15838 :                   specs->typespec_word = cts_dfloat64;
   12975        15781 :                 else if (i == RID_DFLOAT128)
   12976        15734 :                   specs->typespec_word = cts_dfloat128;
   12977              :                 else
   12978           47 :                   specs->typespec_word = cts_dfloat64x;
   12979        47639 :                 specs->locations[cdw_typespec] = loc;
   12980              :               }
   12981        47639 :               if (!targetm.decimal_float_supported_p ())
   12982            0 :                 error_at (loc,
   12983              :                           "decimal floating-point not supported "
   12984              :                           "for this target");
   12985        47639 :               pedwarn_c11 (loc, OPT_Wpedantic,
   12986              :                            "ISO C does not support decimal floating-point "
   12987              :                            "before C23");
   12988        47639 :               return specs;
   12989           63 :             case RID_FRACT:
   12990           63 :             case RID_ACCUM:
   12991           63 :               {
   12992           63 :                 const char *str;
   12993           63 :                 if (i == RID_FRACT)
   12994              :                   str = "_Fract";
   12995              :                 else
   12996           31 :                   str = "_Accum";
   12997           63 :                 if (specs->complex_p)
   12998            0 :                   error_at (loc,
   12999              :                             "both %qs and %qs in declaration specifiers",
   13000              :                             "complex", str);
   13001           63 :                 else if (i == RID_FRACT)
   13002           32 :                     specs->typespec_word = cts_fract;
   13003              :                 else
   13004           31 :                     specs->typespec_word = cts_accum;
   13005           63 :                 specs->locations[cdw_typespec] = loc;
   13006              :               }
   13007           63 :               if (!targetm.fixed_point_supported_p ())
   13008           63 :                 error_at (loc,
   13009              :                           "fixed-point types not supported for this target");
   13010           63 :               pedwarn (loc, OPT_Wpedantic,
   13011              :                        "ISO C does not support fixed-point types");
   13012           63 :               return specs;
   13013        46665 :             case RID_BITINT:
   13014        46665 :               if (specs->long_p)
   13015            2 :                 error_at (loc,
   13016              :                           "both %qs and %qs in declaration specifiers",
   13017              :                           "long", "_BitInt");
   13018        46663 :               else if (specs->short_p)
   13019            1 :                 error_at (loc,
   13020              :                           "both %qs and %qs in declaration specifiers",
   13021              :                           "short", "_BitInt");
   13022        46662 :               else if (specs->complex_p)
   13023            1 :                 error_at (loc,
   13024              :                           "both %qs and %qs in declaration specifiers",
   13025              :                           "complex", "_BitInt");
   13026        46661 :               else if (specs->saturating_p)
   13027            0 :                 error_at (loc,
   13028              :                           "both %qs and %qs in declaration specifiers",
   13029              :                           "_Sat", "_BitInt");
   13030              :               else
   13031              :                 {
   13032        46661 :                   specs->typespec_word = cts_bitint;
   13033        46661 :                   specs->locations[cdw_typespec] = loc;
   13034        46661 :                   specs->u.bitint_prec = -1;
   13035        46661 :                   if (error_operand_p (spec.expr))
   13036            7 :                     return specs;
   13037        46661 :                   if (TREE_CODE (spec.expr) != INTEGER_CST
   13038        46661 :                       || !INTEGRAL_TYPE_P (TREE_TYPE (spec.expr)))
   13039              :                     {
   13040            1 :                       error_at (loc, "%<_BitInt%> argument is not an integer "
   13041              :                                      "constant expression");
   13042            1 :                       return specs;
   13043              :                     }
   13044        46660 :                   if (tree_int_cst_sgn (spec.expr) <= 0)
   13045              :                     {
   13046            4 :                       error_at (loc, "%<_BitInt%> argument %qE is not a "
   13047              :                                      "positive integer constant expression",
   13048              :                                 spec.expr);
   13049            4 :                       return specs;
   13050              :                     }
   13051        46656 :                   if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1)
   13052              :                     {
   13053            2 :                       error_at (loc, "%<_BitInt%> argument %qE is larger than "
   13054              :                                      "%<BITINT_MAXWIDTH%> %qd",
   13055              :                                 spec.expr, (int) WIDE_INT_MAX_PRECISION - 1);
   13056            2 :                       return specs;
   13057              :                     }
   13058        46654 :                   specs->u.bitint_prec = tree_to_uhwi (spec.expr);
   13059        46654 :                   struct bitint_info info;
   13060        46654 :                   if (!targetm.c.bitint_type_info (specs->u.bitint_prec,
   13061              :                                                    &info))
   13062              :                     {
   13063            0 :                       sorry_at (loc, "%<_BitInt(%d)%> is not supported on "
   13064              :                                      "this target", specs->u.bitint_prec);
   13065            0 :                       specs->u.bitint_prec = -1;
   13066            0 :                       return specs;
   13067              :                     }
   13068              :                 }
   13069        46658 :               return specs;
   13070              :             default:
   13071              :               /* ObjC reserved word "id", handled below.  */
   13072              :               break;
   13073              :             }
   13074              :         }
   13075              :     }
   13076              : 
   13077              :   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
   13078              :      form of ObjC type, cases such as "int" and "long" being handled
   13079              :      above), a TYPE (struct, union, enum and typeof specifiers) or an
   13080              :      ERROR_MARK.  In none of these cases may there have previously
   13081              :      been any type specifiers.  */
   13082    249149700 :   if (specs->type || specs->typespec_word != cts_none
   13083    249149688 :       || specs->long_p || specs->short_p || specs->signed_p
   13084    249149685 :       || specs->unsigned_p || specs->complex_p)
   13085           21 :     error_at (loc, "two or more data types in declaration specifiers");
   13086    249149679 :   else if (TREE_CODE (type) == TYPE_DECL)
   13087              :     {
   13088    245864912 :       specs->type = TREE_TYPE (type);
   13089    245864912 :       if (TREE_TYPE (type) != error_mark_node)
   13090              :         {
   13091    245864897 :           mark_decl_used (type, false);
   13092    245864897 :           specs->decl_attr = DECL_ATTRIBUTES (type);
   13093    245864897 :           specs->typedef_p = true;
   13094    245864897 :           specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
   13095    245864897 :           specs->locations[cdw_typedef] = loc;
   13096              : 
   13097              :           /* If this typedef name is defined in a struct, then a C++
   13098              :              lookup would return a different value.  */
   13099    245864897 :           if (warn_cxx_compat
   13100    245864897 :               && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
   13101            2 :             warning_at (loc, OPT_Wc___compat,
   13102              :                         "C++ lookup of %qD would return a field, not a type",
   13103              :                         type);
   13104              : 
   13105              :           /* If we are parsing a struct, record that a struct field
   13106              :              used a typedef.  */
   13107    245864897 :           if (warn_cxx_compat && struct_parse_info != NULL)
   13108         1766 :             struct_parse_info->typedefs_seen.safe_push (type);
   13109              :         }
   13110              :     }
   13111      3284767 :   else if (TREE_CODE (type) == IDENTIFIER_NODE)
   13112              :     {
   13113            0 :       tree t = lookup_name (type);
   13114            0 :       if (!t || TREE_CODE (t) != TYPE_DECL)
   13115            0 :         error_at (loc, "%qE fails to be a typedef or built in type", type);
   13116            0 :       else if (TREE_TYPE (t) == error_mark_node)
   13117              :         ;
   13118              :       else
   13119              :         {
   13120            0 :           specs->type = TREE_TYPE (t);
   13121            0 :           specs->locations[cdw_typespec] = loc;
   13122              :         }
   13123              :     }
   13124              :   else
   13125              :     {
   13126      3284767 :       if (TREE_CODE (type) != ERROR_MARK)
   13127              :         {
   13128      3284561 :           if (spec.kind == ctsk_typeof)
   13129              :             {
   13130       833008 :               specs->typedef_p = true;
   13131       833008 :               specs->locations[cdw_typedef] = loc;
   13132              :             }
   13133              : 
   13134      3284561 :           if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
   13135      1066854 :               || TREE_CODE (type) == ENUMERAL_TYPE)
   13136      2460148 :             mark_decl_used (TYPE_STUB_DECL (type), false);
   13137              : 
   13138      3284561 :           if (spec.expr)
   13139              :             {
   13140          957 :               tree expr = save_expr (fold_convert (void_type_node, spec.expr));
   13141          957 :               if (specs->expr)
   13142            0 :                 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
   13143              :                                       specs->expr, expr);
   13144              :               else
   13145          957 :                 specs->expr = expr;
   13146          957 :               specs->expr_const_operands &= spec.expr_const_operands;
   13147              :             }
   13148              :         }
   13149      3284767 :       specs->type = type;
   13150      3284767 :       if (spec.has_enum_type_specifier
   13151          187 :           && spec.kind != ctsk_tagdef)
   13152           49 :         specs->enum_type_specifier_ref_p = true;
   13153              :     }
   13154              : 
   13155              :   return specs;
   13156              : }
   13157              : 
   13158              : /* Add the storage class specifier or function specifier SCSPEC to the
   13159              :    declaration specifiers SPECS, returning SPECS.  */
   13160              : 
   13161              : struct c_declspecs *
   13162     90788111 : declspecs_add_scspec (location_t loc,
   13163              :                       struct c_declspecs *specs,
   13164              :                       tree scspec)
   13165              : {
   13166     90788111 :   enum rid i;
   13167     90788111 :   enum c_storage_class n = csc_none;
   13168     90788111 :   bool dupe = false;
   13169     90788111 :   specs->declspecs_seen_p = true;
   13170     90788111 :   specs->non_std_attrs_seen_p = true;
   13171     90788111 :   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
   13172              :               && C_IS_RESERVED_WORD (scspec));
   13173     90788111 :   i = C_RID_CODE (scspec);
   13174     90788111 :   if (specs->non_sc_seen_p)
   13175         2096 :     warning (OPT_Wold_style_declaration,
   13176              :              "%qE is not at beginning of declaration", scspec);
   13177     90788111 :   switch (i)
   13178              :     {
   13179     35635926 :     case RID_INLINE:
   13180              :       /* C99 permits duplicate inline.  Although of doubtful utility,
   13181              :          it seems simplest to permit it in gnu89 mode as well, as
   13182              :          there is also little utility in maintaining this as a
   13183              :          difference between gnu89 and C99 inline.  */
   13184     35635926 :       dupe = false;
   13185     35635926 :       specs->inline_p = true;
   13186     35635926 :       specs->locations[cdw_inline] = loc;
   13187     35635926 :       break;
   13188        23317 :     case RID_NORETURN:
   13189              :       /* Duplicate _Noreturn is permitted.  */
   13190        23317 :       dupe = false;
   13191        23317 :       specs->noreturn_p = true;
   13192        23317 :       specs->locations[cdw_noreturn] = loc;
   13193        23317 :       break;
   13194         2860 :     case RID_THREAD:
   13195         2860 :       dupe = specs->thread_p;
   13196         2860 :       if (specs->storage_class == csc_auto)
   13197            2 :         error ("%qE used with %<auto%>", scspec);
   13198         2858 :       else if (specs->storage_class == csc_register)
   13199            3 :         error ("%qE used with %<register%>", scspec);
   13200         2855 :       else if (specs->storage_class == csc_typedef)
   13201            2 :         error ("%qE used with %<typedef%>", scspec);
   13202         2853 :       else if (specs->constexpr_p)
   13203            2 :         error ("%qE used with %<constexpr%>", scspec);
   13204              :       else
   13205              :         {
   13206         2851 :           specs->thread_p = true;
   13207         2851 :           specs->thread_gnu_p = (strcmp (IDENTIFIER_POINTER (scspec),
   13208         2851 :                                          "__thread") == 0);
   13209              :           /* A diagnostic is not required for the use of this
   13210              :              identifier in the implementation namespace; only diagnose
   13211              :              it for the C11 spelling because of existing code using
   13212              :              the other spelling.  */
   13213         2851 :           if (!specs->thread_gnu_p)
   13214              :             {
   13215          116 :               if (flag_isoc99)
   13216          113 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13217              :                              "ISO C99 does not support %qE", scspec);
   13218              :               else
   13219            3 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13220              :                              "ISO C90 does not support %qE", scspec);
   13221              :             }
   13222         2851 :           specs->locations[cdw_thread] = loc;
   13223              :         }
   13224              :       break;
   13225          262 :     case RID_AUTO:
   13226          262 :       if (flag_isoc23
   13227          223 :           && specs->typespec_kind == ctsk_none
   13228          212 :           && specs->storage_class != csc_typedef)
   13229              :         {
   13230              :           /* "auto" potentially used for type deduction.  */
   13231          211 :           if (specs->c23_auto_p)
   13232            2 :             error ("duplicate %qE", scspec);
   13233          211 :           specs->c23_auto_p = true;
   13234          211 :           return specs;
   13235              :         }
   13236           51 :       n = csc_auto;
   13237              :       /* auto may only be used with another storage class specifier,
   13238              :          such as constexpr, if the type is inferred.  */
   13239           51 :       if (specs->constexpr_p)
   13240            2 :         error ("%qE used with %<constexpr%>", scspec);
   13241              :       break;
   13242     50373925 :     case RID_EXTERN:
   13243     50373925 :       n = csc_extern;
   13244              :       /* Diagnose "__thread extern".  */
   13245     50373925 :       if (specs->thread_p && specs->thread_gnu_p)
   13246            2 :         error ("%<__thread%> before %<extern%>");
   13247              :       break;
   13248              :     case RID_REGISTER:
   13249              :       n = csc_register;
   13250              :       break;
   13251       426662 :     case RID_STATIC:
   13252       426662 :       n = csc_static;
   13253              :       /* Diagnose "__thread static".  */
   13254       426662 :       if (specs->thread_p && specs->thread_gnu_p)
   13255            1 :         error ("%<__thread%> before %<static%>");
   13256              :       break;
   13257      4321410 :     case RID_TYPEDEF:
   13258      4321410 :       n = csc_typedef;
   13259      4321410 :       if (specs->c23_auto_p)
   13260              :         {
   13261            1 :           error ("%<typedef%> used with %<auto%>");
   13262            1 :           specs->c23_auto_p = false;
   13263              :         }
   13264              :       break;
   13265          616 :     case RID_CONSTEXPR:
   13266          616 :       dupe = specs->constexpr_p;
   13267          616 :       if (specs->storage_class == csc_extern)
   13268            1 :         error ("%qE used with %<extern%>", scspec);
   13269          615 :       else if (specs->storage_class == csc_typedef)
   13270            1 :         error ("%qE used with %<typedef%>", scspec);
   13271          614 :       else if (specs->storage_class == csc_auto)
   13272              :         /* auto may only be used with another storage class specifier,
   13273              :            such as constexpr, if the type is inferred.  */
   13274            2 :         error ("%qE used with %<auto%>", scspec);
   13275          612 :       else if (specs->thread_p)
   13276            4 :         error ("%qE used with %qs", scspec,
   13277            2 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   13278              :       else
   13279          610 :         specs->constexpr_p = true;
   13280              :       break;
   13281            0 :     default:
   13282            0 :       gcc_unreachable ();
   13283              :     }
   13284     90787906 :   if (n != csc_none && n == specs->storage_class)
   13285              :     dupe = true;
   13286     90787892 :   if (dupe)
   13287              :     {
   13288           12 :       if (i == RID_THREAD)
   13289            2 :         error ("duplicate %<_Thread_local%> or %<__thread%>");
   13290              :       else
   13291           10 :         error ("duplicate %qE", scspec);
   13292              :     }
   13293     90787900 :   if (n != csc_none)
   13294              :     {
   13295     55125181 :       if (specs->storage_class != csc_none && n != specs->storage_class)
   13296              :         {
   13297            7 :           error ("multiple storage classes in declaration specifiers");
   13298              :         }
   13299              :       else
   13300              :         {
   13301     55125174 :           specs->storage_class = n;
   13302     55125174 :           specs->locations[cdw_storage_class] = loc;
   13303     55125174 :           if (n != csc_extern && n != csc_static && specs->thread_p)
   13304              :             {
   13305            8 :               error ("%qs used with %qE",
   13306            8 :                      specs->thread_gnu_p ? "__thread" : "_Thread_local",
   13307              :                      scspec);
   13308            8 :               specs->thread_p = false;
   13309              :             }
   13310     55125174 :           if (n != csc_auto && n != csc_register && n != csc_static
   13311     54695332 :               && specs->constexpr_p)
   13312              :             {
   13313            2 :               error ("%<constexpr%> used with %qE", scspec);
   13314            2 :               specs->constexpr_p = false;
   13315              :             }
   13316              :         }
   13317              :     }
   13318              :   return specs;
   13319              : }
   13320              : 
   13321              : /* Add the attributes ATTRS to the declaration specifiers SPECS,
   13322              :    returning SPECS.  */
   13323              : 
   13324              : struct c_declspecs *
   13325     35947763 : declspecs_add_attrs (location_t loc, struct c_declspecs *specs, tree attrs)
   13326              : {
   13327     35947763 :   specs->attrs = chainon (attrs, specs->attrs);
   13328     35947763 :   specs->locations[cdw_attributes] = loc;
   13329     35947763 :   specs->declspecs_seen_p = true;
   13330              :   /* In the case of standard attributes at the start of the
   13331              :      declaration, the caller will reset this.  */
   13332     35947763 :   specs->non_std_attrs_seen_p = true;
   13333     35947763 :   return specs;
   13334              : }
   13335              : 
   13336              : /* Add an _Alignas specifier (expression ALIGN, or type whose
   13337              :    alignment is ALIGN) to the declaration specifiers SPECS, returning
   13338              :    SPECS.  */
   13339              : struct c_declspecs *
   13340          202 : declspecs_add_alignas (location_t loc,
   13341              :                        struct c_declspecs *specs, tree align)
   13342              : {
   13343          202 :   specs->alignas_p = true;
   13344          202 :   specs->locations[cdw_alignas] = loc;
   13345          202 :   if (align == error_mark_node)
   13346              :     return specs;
   13347              : 
   13348              :   /* Only accept the alignment if it's valid and greater than
   13349              :      the current one.  Zero is invalid but by C11 required to
   13350              :      be silently ignored.  */
   13351          200 :   int align_log = check_user_alignment (align, false, /* warn_zero = */false);
   13352          200 :   if (align_log > specs->align_log)
   13353          167 :     specs->align_log = align_log;
   13354              :   return specs;
   13355              : }
   13356              : 
   13357              : /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
   13358              :    specifiers with any other type specifier to determine the resulting
   13359              :    type.  This is where ISO C checks on complex types are made, since
   13360              :    "_Complex long" is a prefix of the valid ISO C type "_Complex long
   13361              :    double".  Also apply postfix standard attributes to modify the type.  */
   13362              : 
   13363              : struct c_declspecs *
   13364    315239431 : finish_declspecs (struct c_declspecs *specs)
   13365              : {
   13366              :   /* If a type was specified as a whole, we have no modifiers and are
   13367              :      done.  */
   13368    315239431 :   if (specs->type != NULL_TREE)
   13369              :     {
   13370    249149633 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13371              :                   && !specs->signed_p && !specs->unsigned_p
   13372              :                   && !specs->complex_p && !specs->c23_auto_p);
   13373              : 
   13374              :       /* Set a dummy type.  */
   13375    249149633 :       if (TREE_CODE (specs->type) == ERROR_MARK)
   13376          184 :         specs->type = integer_type_node;
   13377    249149633 :       goto handle_postfix_attrs;
   13378              :     }
   13379              : 
   13380              :   /* If none of "void", "_Bool", "char", "int", "float" or "double"
   13381              :      has been specified, treat it as "int" unless "_Complex" is
   13382              :      present and there are no other specifiers.  If we just have
   13383              :      "_Complex", it is equivalent to "_Complex double", but e.g.
   13384              :      "_Complex short" is equivalent to "_Complex short int".  */
   13385     66089798 :   if (specs->typespec_word == cts_none)
   13386              :     {
   13387      4186535 :       if (specs->saturating_p)
   13388              :         {
   13389            1 :           error_at (specs->locations[cdw_saturating],
   13390              :                     "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
   13391            1 :           if (!targetm.fixed_point_supported_p ())
   13392            1 :             error_at (specs->locations[cdw_saturating],
   13393              :                       "fixed-point types not supported for this target");
   13394            1 :           specs->typespec_word = cts_fract;
   13395              :         }
   13396      4186534 :       else if (specs->long_p || specs->short_p
   13397       192940 :                || specs->signed_p || specs->unsigned_p)
   13398              :         {
   13399      4176091 :           specs->typespec_word = cts_int;
   13400              :         }
   13401        10443 :       else if (specs->complex_p)
   13402              :         {
   13403          131 :           specs->typespec_word = cts_double;
   13404          131 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13405              :                    "ISO C does not support plain %<complex%> meaning "
   13406              :                    "%<double complex%>");
   13407              :         }
   13408        10312 :       else if (specs->c23_auto_p)
   13409              :         {
   13410              :           /* Type to be filled in later, including applying postfix
   13411              :              attributes.  This warning only actually appears for
   13412              :              -Wc11-c23-compat in C23 mode; in older modes, there may
   13413              :              be a warning or pedwarn for implicit "int" instead, or
   13414              :              other errors for use of auto at file scope.  */
   13415           93 :           pedwarn_c11 (input_location, OPT_Wpedantic,
   13416              :                        "ISO C does not support %<auto%> type deduction "
   13417              :                        "before C23");
   13418           93 :           return specs;
   13419              :         }
   13420              :       else
   13421              :         {
   13422        10219 :           specs->typespec_word = cts_int;
   13423        10219 :           specs->default_int_p = true;
   13424              :           /* We don't diagnose this here because grokdeclarator will
   13425              :              give more specific diagnostics according to whether it is
   13426              :              a function definition.  */
   13427              :         }
   13428              :     }
   13429              : 
   13430              :   /* If "signed" was specified, record this to distinguish "int" and
   13431              :      "signed int" in the case of a bit-field with
   13432              :      -funsigned-bitfields.  */
   13433     66089705 :   specs->explicit_signed_p = specs->signed_p;
   13434              : 
   13435              :   /* Now compute the actual type.  */
   13436     66089705 :   gcc_assert (!specs->c23_auto_p);
   13437     66089705 :   switch (specs->typespec_word)
   13438              :     {
   13439         1885 :     case cts_auto_type:
   13440         1885 :       gcc_assert (!specs->long_p && !specs->short_p
   13441              :                   && !specs->signed_p && !specs->unsigned_p
   13442              :                   && !specs->complex_p);
   13443              :       /* Type to be filled in later.  */
   13444         1885 :       if (specs->postfix_attrs)
   13445            2 :         error ("%<__auto_type%> followed by %<[[]]%> attributes");
   13446              :       break;
   13447      7973354 :     case cts_void:
   13448      7973354 :       gcc_assert (!specs->long_p && !specs->short_p
   13449              :                   && !specs->signed_p && !specs->unsigned_p
   13450              :                   && !specs->complex_p);
   13451      7973354 :       specs->type = void_type_node;
   13452      7973354 :       break;
   13453        89642 :     case cts_bool:
   13454        89642 :       gcc_assert (!specs->long_p && !specs->short_p
   13455              :                   && !specs->signed_p && !specs->unsigned_p
   13456              :                   && !specs->complex_p);
   13457        89642 :       specs->type = boolean_type_node;
   13458        89642 :       break;
   13459      9048347 :     case cts_char:
   13460      9048347 :       gcc_assert (!specs->long_p && !specs->short_p);
   13461      9048347 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13462      9048347 :       if (specs->signed_p)
   13463       172930 :         specs->type = signed_char_type_node;
   13464      8875417 :       else if (specs->unsigned_p)
   13465       883425 :         specs->type = unsigned_char_type_node;
   13466              :       else
   13467      7991992 :         specs->type = char_type_node;
   13468      9048347 :       if (specs->complex_p)
   13469              :         {
   13470         3856 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13471              :                    "ISO C does not support complex integer types");
   13472         3856 :           specs->type = build_complex_type (specs->type);
   13473              :         }
   13474              :       break;
   13475        51784 :     case cts_int_n:
   13476        51784 :       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
   13477        51784 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13478        51784 :       if (! int_n_enabled_p[specs->u.int_n_idx])
   13479            0 :         specs->type = integer_type_node;
   13480              :       else
   13481        51784 :         specs->type = (specs->unsigned_p
   13482        51784 :                        ? int_n_trees[specs->u.int_n_idx].unsigned_type
   13483              :                        : int_n_trees[specs->u.int_n_idx].signed_type);
   13484        51784 :       if (specs->complex_p)
   13485              :         {
   13486          199 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13487              :                    "ISO C does not support complex integer types");
   13488          199 :           specs->type = build_complex_type (specs->type);
   13489              :         }
   13490              :       break;
   13491     28164703 :     case cts_int:
   13492     28164703 :       gcc_assert (!(specs->long_p && specs->short_p));
   13493     28164703 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13494     28164703 :       if (specs->long_long_p)
   13495      2965430 :         specs->type = (specs->unsigned_p
   13496      2965430 :                        ? long_long_unsigned_type_node
   13497              :                        : long_long_integer_type_node);
   13498     25199273 :       else if (specs->long_p)
   13499      2222154 :         specs->type = (specs->unsigned_p
   13500      2222154 :                        ? long_unsigned_type_node
   13501              :                        : long_integer_type_node);
   13502     22977119 :       else if (specs->short_p)
   13503      1702715 :         specs->type = (specs->unsigned_p
   13504      1702715 :                        ? short_unsigned_type_node
   13505              :                        : short_integer_type_node);
   13506              :       else
   13507     21274404 :         specs->type = (specs->unsigned_p
   13508     21274404 :                        ? unsigned_type_node
   13509              :                        : integer_type_node);
   13510     28164703 :       if (specs->complex_p)
   13511              :         {
   13512        14934 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13513              :                    "ISO C does not support complex integer types");
   13514        14934 :           specs->type = build_complex_type (specs->type);
   13515              :         }
   13516              :       break;
   13517      3631590 :     case cts_float:
   13518      3631590 :       gcc_assert (!specs->long_p && !specs->short_p
   13519              :                   && !specs->signed_p && !specs->unsigned_p);
   13520      7263180 :       specs->type = (specs->complex_p
   13521      3631590 :                      ? complex_float_type_node
   13522              :                      : float_type_node);
   13523      3631590 :       break;
   13524      6606151 :     case cts_double:
   13525      6606151 :       gcc_assert (!specs->long_long_p && !specs->short_p
   13526              :                   && !specs->signed_p && !specs->unsigned_p);
   13527      6606151 :       if (specs->long_p)
   13528              :         {
   13529      2881813 :           specs->type = (specs->complex_p
   13530      2881813 :                          ? complex_long_double_type_node
   13531              :                          : long_double_type_node);
   13532              :         }
   13533              :       else
   13534              :         {
   13535      3724338 :           specs->type = (specs->complex_p
   13536      3724338 :                          ? complex_double_type_node
   13537              :                          : double_type_node);
   13538              :         }
   13539              :       break;
   13540     10427948 :     case cts_floatn_nx:
   13541     10427948 :       gcc_assert (!specs->long_p && !specs->short_p
   13542              :                   && !specs->signed_p && !specs->unsigned_p);
   13543     10427948 :       if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   13544           88 :         specs->type = integer_type_node;
   13545     10427860 :       else if (specs->complex_p)
   13546      1555507 :         specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13547              :       else
   13548      8872353 :         specs->type = FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13549              :       break;
   13550        47576 :     case cts_dfloat32:
   13551        47576 :     case cts_dfloat64:
   13552        47576 :     case cts_dfloat128:
   13553        47576 :     case cts_dfloat64x:
   13554        47576 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13555              :                   && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
   13556        47576 :       if (!targetm.decimal_float_supported_p ())
   13557            0 :         specs->type = integer_type_node;
   13558        47576 :       else if (specs->typespec_word == cts_dfloat32)
   13559        15957 :         specs->type = dfloat32_type_node;
   13560        31619 :       else if (specs->typespec_word == cts_dfloat64)
   13561        15838 :         specs->type = dfloat64_type_node;
   13562        15781 :       else if (specs->typespec_word == cts_dfloat128)
   13563        15734 :         specs->type = dfloat128_type_node;
   13564              :       else
   13565           47 :         specs->type = dfloat64x_type_node;
   13566              :       break;
   13567           33 :     case cts_fract:
   13568           33 :       gcc_assert (!specs->complex_p);
   13569           33 :       if (!targetm.fixed_point_supported_p ())
   13570           33 :         specs->type = integer_type_node;
   13571            0 :       else if (specs->saturating_p)
   13572              :         {
   13573            0 :           if (specs->long_long_p)
   13574            0 :             specs->type = specs->unsigned_p
   13575            0 :                           ? sat_unsigned_long_long_fract_type_node
   13576              :                           : sat_long_long_fract_type_node;
   13577            0 :           else if (specs->long_p)
   13578            0 :             specs->type = specs->unsigned_p
   13579            0 :                           ? sat_unsigned_long_fract_type_node
   13580              :                           : sat_long_fract_type_node;
   13581            0 :           else if (specs->short_p)
   13582            0 :             specs->type = specs->unsigned_p
   13583            0 :                           ? sat_unsigned_short_fract_type_node
   13584              :                           : sat_short_fract_type_node;
   13585              :           else
   13586            0 :             specs->type = specs->unsigned_p
   13587            0 :                           ? sat_unsigned_fract_type_node
   13588              :                           : sat_fract_type_node;
   13589              :         }
   13590              :       else
   13591              :         {
   13592            0 :           if (specs->long_long_p)
   13593            0 :             specs->type = specs->unsigned_p
   13594            0 :                           ? unsigned_long_long_fract_type_node
   13595              :                           : long_long_fract_type_node;
   13596            0 :           else if (specs->long_p)
   13597            0 :             specs->type = specs->unsigned_p
   13598            0 :                           ? unsigned_long_fract_type_node
   13599              :                           : long_fract_type_node;
   13600            0 :           else if (specs->short_p)
   13601            0 :             specs->type = specs->unsigned_p
   13602            0 :                           ? unsigned_short_fract_type_node
   13603              :                           : short_fract_type_node;
   13604              :           else
   13605            0 :             specs->type = specs->unsigned_p
   13606            0 :                           ? unsigned_fract_type_node
   13607              :                           : fract_type_node;
   13608              :         }
   13609              :       break;
   13610           31 :     case cts_accum:
   13611           31 :       gcc_assert (!specs->complex_p);
   13612           31 :       if (!targetm.fixed_point_supported_p ())
   13613           31 :         specs->type = integer_type_node;
   13614            0 :       else if (specs->saturating_p)
   13615              :         {
   13616            0 :           if (specs->long_long_p)
   13617            0 :             specs->type = specs->unsigned_p
   13618            0 :                           ? sat_unsigned_long_long_accum_type_node
   13619              :                           : sat_long_long_accum_type_node;
   13620            0 :           else if (specs->long_p)
   13621            0 :             specs->type = specs->unsigned_p
   13622            0 :                           ? sat_unsigned_long_accum_type_node
   13623              :                           : sat_long_accum_type_node;
   13624            0 :           else if (specs->short_p)
   13625            0 :             specs->type = specs->unsigned_p
   13626            0 :                           ? sat_unsigned_short_accum_type_node
   13627              :                           : sat_short_accum_type_node;
   13628              :           else
   13629            0 :             specs->type = specs->unsigned_p
   13630            0 :                           ? sat_unsigned_accum_type_node
   13631              :                           : sat_accum_type_node;
   13632              :         }
   13633              :       else
   13634              :         {
   13635            0 :           if (specs->long_long_p)
   13636            0 :             specs->type = specs->unsigned_p
   13637            0 :                           ? unsigned_long_long_accum_type_node
   13638              :                           : long_long_accum_type_node;
   13639            0 :           else if (specs->long_p)
   13640            0 :             specs->type = specs->unsigned_p
   13641            0 :                           ? unsigned_long_accum_type_node
   13642              :                           : long_accum_type_node;
   13643            0 :           else if (specs->short_p)
   13644            0 :             specs->type = specs->unsigned_p
   13645            0 :                           ? unsigned_short_accum_type_node
   13646              :                           : short_accum_type_node;
   13647              :           else
   13648            0 :             specs->type = specs->unsigned_p
   13649            0 :                           ? unsigned_accum_type_node
   13650              :                           : accum_type_node;
   13651              :         }
   13652              :       break;
   13653        46661 :     case cts_bitint:
   13654        46661 :       gcc_assert (!specs->long_p && !specs->short_p
   13655              :                   && !specs->complex_p);
   13656        46661 :       if (!specs->unsigned_p && specs->u.bitint_prec == 1 && !flag_isoc2y)
   13657              :         {
   13658            2 :           error_at (specs->locations[cdw_typespec],
   13659              :                     "%<signed _BitInt%> argument must be at least 2 "
   13660              :                     "before C2Y");
   13661            2 :           specs->type = integer_type_node;
   13662            2 :           break;
   13663              :         }
   13664        46659 :       if (specs->u.bitint_prec == -1)
   13665            7 :         specs->type = integer_type_node;
   13666              :       else
   13667              :         {
   13668        69044 :           pedwarn_c11 (specs->locations[cdw_typespec], OPT_Wpedantic,
   13669              :                        "ISO C does not support %<%s_BitInt(%d)%> before C23",
   13670              :                        specs->unsigned_p ? "unsigned "
   13671        22392 :                        : specs->signed_p ? "signed " : "",
   13672              :                        specs->u.bitint_prec);
   13673        46652 :           specs->type = build_bitint_type (specs->u.bitint_prec,
   13674        46652 :                                            specs->unsigned_p);
   13675              :         }
   13676              :       break;
   13677            0 :     default:
   13678            0 :       gcc_unreachable ();
   13679              :     }
   13680    315239338 :  handle_postfix_attrs:
   13681    315239338 :   if (specs->type != NULL)
   13682              :     {
   13683    315237453 :       specs->postfix_attrs
   13684    315237453 :         = c_warn_type_attributes (specs->type, specs->postfix_attrs);
   13685    315237453 :       decl_attributes (&specs->type, specs->postfix_attrs, 0);
   13686    315237453 :       specs->postfix_attrs = NULL_TREE;
   13687              :     }
   13688              : 
   13689              :   return specs;
   13690              : }
   13691              : 
   13692              : /* Perform final processing on one file scope's declarations (or the
   13693              :    external scope's declarations), GLOBALS.  */
   13694              : 
   13695              : static void
   13696       210396 : c_write_global_declarations_1 (tree globals)
   13697              : {
   13698       210396 :   tree decl;
   13699       210396 :   bool reconsider;
   13700              : 
   13701              :   /* Process the decls in the order they were written.  */
   13702    385397251 :   for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13703              :     {
   13704              :       /* Check for used but undefined static functions using the C
   13705              :          standard's definition of "used", and set TREE_NO_WARNING so
   13706              :          that check_global_declaration doesn't repeat the check.  */
   13707    385186855 :       if (TREE_CODE (decl) == FUNCTION_DECL
   13708    367058081 :           && DECL_INITIAL (decl) == NULL_TREE
   13709    330733633 :           && DECL_EXTERNAL (decl)
   13710    330733628 :           && !TREE_PUBLIC (decl)
   13711    385186982 :           && !warning_suppressed_p (decl, OPT_Wunused))
   13712              :         {
   13713          122 :           if (C_DECL_USED (decl))
   13714              :             {
   13715           31 :               if (pedwarn (input_location, 0, "%q+F used but never defined",
   13716              :                            decl))
   13717           30 :                 suppress_warning (decl, OPT_Wunused);
   13718              :             }
   13719              :           /* For -Wunused-function warn about unused static prototypes.  */
   13720           91 :           else if (warn_unused_function
   13721            2 :                    && ! DECL_ARTIFICIAL (decl)
   13722           93 :                    && warning (OPT_Wunused_function,
   13723              :                                "%q+F declared %<static%> but never defined",
   13724              :                                decl))
   13725            2 :             suppress_warning (decl, OPT_Wunused);
   13726              :         }
   13727              : 
   13728    385186855 :       wrapup_global_declaration_1 (decl);
   13729              :     }
   13730              : 
   13731       244551 :   do
   13732              :     {
   13733       244551 :       reconsider = false;
   13734    499590304 :       for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13735    499345753 :         reconsider |= wrapup_global_declaration_2 (decl);
   13736              :     }
   13737              :   while (reconsider);
   13738       210396 : }
   13739              : 
   13740              : /* Preserve the external declarations scope across a garbage collect.  */
   13741              : static GTY(()) tree ext_block;
   13742              : 
   13743              : /* Collect all references relevant to SOURCE_FILE.  */
   13744              : 
   13745              : static void
   13746           15 : collect_all_refs (const char *source_file)
   13747              : {
   13748           15 :   tree t;
   13749           15 :   unsigned i;
   13750              : 
   13751           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13752           15 :     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
   13753              : 
   13754           15 :   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
   13755           15 : }
   13756              : 
   13757              : /* Collect source file references at global level.  */
   13758              : 
   13759              : static void
   13760           15 : collect_source_refs (void)
   13761              : {
   13762           15 :   tree t;
   13763           15 :   tree decls;
   13764           15 :   tree decl;
   13765           15 :   unsigned i;
   13766              : 
   13767           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13768              :     {
   13769           15 :       decls = DECL_INITIAL (t);
   13770           82 :       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
   13771           67 :         if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13772           67 :           collect_source_ref (DECL_SOURCE_FILE (decl));
   13773              :     }
   13774              : 
   13775        44261 :   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
   13776        44246 :     if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13777           11 :       collect_source_ref (DECL_SOURCE_FILE (decl));
   13778           15 : }
   13779              : 
   13780              : /* Free attribute access data that are not needed by the middle end. */
   13781              : 
   13782              : static void
   13783       105198 : free_attr_access_data ()
   13784              : {
   13785       105198 :   struct cgraph_node *n;
   13786              : 
   13787              :   /* Iterate over all functions declared in the translation unit.  */
   13788     36431289 :   FOR_EACH_FUNCTION (n)
   13789              :     {
   13790    136409496 :       for (tree parm = DECL_ARGUMENTS (n->decl); parm; parm = TREE_CHAIN (parm))
   13791    100083405 :         if (tree attrs = DECL_ATTRIBUTES (parm))
   13792        97813 :           attr_access::free_lang_data (attrs);
   13793              : 
   13794     36326091 :       tree fntype = TREE_TYPE (n->decl);
   13795     36326091 :       if (!fntype || fntype == error_mark_node)
   13796            0 :         continue;
   13797     36326091 :       tree attrs = TYPE_ATTRIBUTES (fntype);
   13798     36326091 :       if (!attrs)
   13799     36090325 :         continue;
   13800              : 
   13801       235766 :       attr_access::free_lang_data (attrs);
   13802              :     }
   13803       105198 : }
   13804              : 
   13805              : /* Perform any final parser cleanups and generate initial debugging
   13806              :    information.  */
   13807              : 
   13808              : void
   13809       105531 : c_parse_final_cleanups (void)
   13810              : {
   13811       105531 :   tree t;
   13812       105531 :   unsigned i;
   13813              : 
   13814              :   /* We don't want to do this if generating a PCH.  */
   13815       105531 :   if (pch_file)
   13816       105531 :     return;
   13817              : 
   13818       105198 :   timevar_stop (TV_PHASE_PARSING);
   13819       105198 :   timevar_start (TV_PHASE_DEFERRED);
   13820              : 
   13821              :   /* Do the Objective-C stuff.  This is where all the Objective-C
   13822              :      module stuff gets generated (symtab, class/protocol/selector
   13823              :      lists etc).  */
   13824       105198 :   if (c_dialect_objc ())
   13825            0 :     objc_write_global_declarations ();
   13826              : 
   13827              :   /* Close the external scope.  */
   13828       105198 :   ext_block = pop_scope ();
   13829       105198 :   external_scope = 0;
   13830       105198 :   gcc_assert (!current_scope);
   13831              : 
   13832              :   /* Handle -fdump-ada-spec[-slim]. */
   13833       105198 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
   13834              :     {
   13835              :       /* Build a table of files to generate specs for */
   13836           15 :       collect_source_ref (main_input_filename);
   13837           15 :       if (!flag_dump_ada_spec_slim)
   13838           15 :         collect_source_refs ();
   13839              : 
   13840           15 :       dump_ada_specs (collect_all_refs, NULL);
   13841              :     }
   13842              : 
   13843              :   /* Process all file scopes in this compilation, and the external_scope,
   13844              :      through wrapup_global_declarations.  */
   13845       210396 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13846       105198 :     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
   13847       105198 :   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
   13848              : 
   13849              :   /* Call this to set cpp_implicit_aliases_done on all nodes.  This is
   13850              :      important for function multiversioning aliases to get resolved.  */
   13851       105198 :   symtab->process_same_body_aliases ();
   13852              : 
   13853       105198 :   if (!in_lto_p)
   13854       105198 :     free_attr_access_data ();
   13855              : 
   13856       105198 :   timevar_stop (TV_PHASE_DEFERRED);
   13857       105198 :   timevar_start (TV_PHASE_PARSING);
   13858              : 
   13859       105198 :   ext_block = NULL;
   13860              : }
   13861              : 
   13862              : /* Register reserved keyword WORD as qualifier for address space AS.  */
   13863              : 
   13864              : void
   13865       223054 : c_register_addr_space (const char *word, addr_space_t as)
   13866              : {
   13867       223054 :   int rid = RID_FIRST_ADDR_SPACE + as;
   13868       223054 :   tree id;
   13869              : 
   13870              :   /* Address space qualifiers are only supported
   13871              :      in C with GNU extensions enabled.  */
   13872       223054 :   if (c_dialect_objc () || flag_no_asm)
   13873              :     return;
   13874              : 
   13875       210570 :   id = get_identifier (word);
   13876       210570 :   C_SET_RID_CODE (id, rid);
   13877       210570 :   C_IS_RESERVED_WORD (id) = 1;
   13878       210570 :   ridpointers [rid] = id;
   13879              : }
   13880              : 
   13881              : /* Return identifier to look up for omp declare reduction.  */
   13882              : 
   13883              : tree
   13884         3254 : c_omp_reduction_id (enum tree_code reduction_code, tree reduction_id)
   13885              : {
   13886         3254 :   const char *p = NULL;
   13887         3254 :   switch (reduction_code)
   13888              :     {
   13889              :     case PLUS_EXPR: p = "+"; break;
   13890          267 :     case MULT_EXPR: p = "*"; break;
   13891          157 :     case MINUS_EXPR: p = "-"; break;
   13892           31 :     case BIT_AND_EXPR: p = "&"; break;
   13893           14 :     case BIT_XOR_EXPR: p = "^"; break;
   13894           92 :     case BIT_IOR_EXPR: p = "|"; break;
   13895           67 :     case TRUTH_ANDIF_EXPR: p = "&&"; break;
   13896           78 :     case TRUTH_ORIF_EXPR: p = "||"; break;
   13897           46 :     case MIN_EXPR: p = "min"; break;
   13898           83 :     case MAX_EXPR: p = "max"; break;
   13899              :     default:
   13900              :       break;
   13901              :     }
   13902              : 
   13903          835 :   if (p == NULL)
   13904              :     {
   13905          213 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
   13906            0 :         return error_mark_node;
   13907          213 :       p = IDENTIFIER_POINTER (reduction_id);
   13908              :     }
   13909              : 
   13910         3254 :   const char prefix[] = "omp declare reduction ";
   13911         3254 :   size_t lenp = sizeof (prefix);
   13912         3254 :   size_t len = strlen (p);
   13913         3254 :   char *name = XALLOCAVEC (char, lenp + len);
   13914         3254 :   memcpy (name, prefix, lenp - 1);
   13915         3254 :   memcpy (name + lenp - 1, p, len + 1);
   13916         3254 :   return get_identifier (name);
   13917              : }
   13918              : 
   13919              : /* Lookup REDUCTION_ID in the current scope, or create an artificial
   13920              :    VAR_DECL, bind it into the current scope and return it.  */
   13921              : 
   13922              : tree
   13923          161 : c_omp_reduction_decl (tree reduction_id)
   13924              : {
   13925          161 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13926          161 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   13927           47 :     return b->decl;
   13928              : 
   13929          114 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   13930              :                           reduction_id, integer_type_node);
   13931          114 :   DECL_ARTIFICIAL (decl) = 1;
   13932          114 :   DECL_EXTERNAL (decl) = 1;
   13933          114 :   TREE_STATIC (decl) = 1;
   13934          114 :   TREE_PUBLIC (decl) = 0;
   13935          114 :   bind (reduction_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   13936          114 :   return decl;
   13937              : }
   13938              : 
   13939              : /* Lookup REDUCTION_ID in the first scope where it has entry for TYPE.  */
   13940              : 
   13941              : tree
   13942          273 : c_omp_reduction_lookup (tree reduction_id, tree type)
   13943              : {
   13944          273 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13945          276 :   while (b)
   13946              :     {
   13947          274 :       tree t;
   13948          294 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   13949          291 :         if (comptypes (TREE_PURPOSE (t), type))
   13950          271 :           return TREE_VALUE (t);
   13951            3 :       b = b->shadowed;
   13952              :     }
   13953            2 :   return error_mark_node;
   13954              : }
   13955              : 
   13956              : /* Helper function called via walk_tree, to diagnose invalid
   13957              :    #pragma omp declare reduction combiners or initializers.  */
   13958              : 
   13959              : tree
   13960         1401 : c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
   13961              : {
   13962         1401 :   tree *vars = (tree *) data;
   13963         1401 :   if (SSA_VAR_P (*tp)
   13964          413 :       && !DECL_ARTIFICIAL (*tp)
   13965           24 :       && *tp != vars[0]
   13966           24 :       && *tp != vars[1])
   13967              :     {
   13968           24 :       location_t loc = DECL_SOURCE_LOCATION (vars[0]);
   13969           24 :       if (strcmp (IDENTIFIER_POINTER (DECL_NAME (vars[0])), "omp_out") == 0)
   13970           10 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
   13971              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
   13972              :                   *tp);
   13973              :       else
   13974           14 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
   13975              :                        "to variable %qD which is not %<omp_priv%> nor "
   13976              :                        "%<omp_orig%>",
   13977              :                   *tp);
   13978           24 :       return *tp;
   13979              :     }
   13980              :   return NULL_TREE;
   13981              : }
   13982              : 
   13983              : /* Return identifier to look up for omp declare mapper.  */
   13984              : 
   13985              : tree
   13986          695 : c_omp_mapper_id (tree mapper_id)
   13987              : {
   13988          695 :   const char *p = NULL;
   13989              : 
   13990          695 :   const char prefix[] = "omp declare mapper ";
   13991              : 
   13992          695 :   if (mapper_id == NULL_TREE)
   13993              :     p = "<default>";
   13994           24 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
   13995           24 :     p = IDENTIFIER_POINTER (mapper_id);
   13996              :   else
   13997            0 :     return error_mark_node;
   13998              : 
   13999          695 :   size_t lenp = sizeof (prefix);
   14000          695 :   size_t len = strlen (p);
   14001          695 :   char *name = XALLOCAVEC (char, lenp + len);
   14002          695 :   memcpy (name, prefix, lenp - 1);
   14003          695 :   memcpy (name + lenp - 1, p, len + 1);
   14004          695 :   return get_identifier (name);
   14005              : }
   14006              : 
   14007              : /* Lookup MAPPER_ID in the current scope, or create an artificial
   14008              :    VAR_DECL, bind it into the current scope and return it.  */
   14009              : 
   14010              : tree
   14011           73 : c_omp_mapper_decl (tree mapper_id)
   14012              : {
   14013           73 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14014           73 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   14015           22 :     return b->decl;
   14016              : 
   14017           51 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   14018              :                           mapper_id, integer_type_node);
   14019           51 :   DECL_ARTIFICIAL (decl) = 1;
   14020           51 :   DECL_EXTERNAL (decl) = 1;
   14021           51 :   TREE_STATIC (decl) = 1;
   14022           51 :   TREE_PUBLIC (decl) = 0;
   14023           51 :   bind (mapper_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   14024           51 :   return decl;
   14025              : }
   14026              : 
   14027              : /* Lookup MAPPER_ID in the first scope where it has entry for TYPE.  */
   14028              : 
   14029              : tree
   14030         5411 : c_omp_mapper_lookup (tree mapper_id, tree type)
   14031              : {
   14032         5411 :   if (!RECORD_OR_UNION_TYPE_P (type))
   14033              :     return NULL_TREE;
   14034              : 
   14035          622 :   mapper_id = c_omp_mapper_id (mapper_id);
   14036              : 
   14037          622 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14038          628 :   while (b)
   14039              :     {
   14040          127 :       tree t;
   14041          146 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   14042          140 :         if (comptypes (TREE_PURPOSE (t), type))
   14043          121 :           return TREE_VALUE (t);
   14044            6 :       b = b->shadowed;
   14045              :     }
   14046              :   return NULL_TREE;
   14047              : }
   14048              : 
   14049              : /* For C, we record a pointer to the mapper itself without wrapping it in an
   14050              :    artificial function or similar.  So, just return it.  */
   14051              : 
   14052              : tree
   14053          113 : c_omp_extract_mapper_directive (tree mapper)
   14054              : {
   14055          113 :   return mapper;
   14056              : }
   14057              : 
   14058              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
   14059              :    nothing more complicated.  */
   14060              : 
   14061              : tree
   14062          569 : c_omp_map_array_section (location_t loc, tree t)
   14063              : {
   14064          569 :   tree low = TREE_OPERAND (t, 1);
   14065          569 :   tree len = TREE_OPERAND (t, 2);
   14066              : 
   14067          569 :   if (len && integer_onep (len))
   14068              :     {
   14069           92 :       t = TREE_OPERAND (t, 0);
   14070              : 
   14071           92 :       if (!low)
   14072           14 :         low = integer_zero_node;
   14073              : 
   14074           92 :       t = build_array_ref (loc, t, low);
   14075              :     }
   14076              : 
   14077          569 :   return t;
   14078              : }
   14079              : 
   14080              : /* Helper function for below function.  */
   14081              : 
   14082              : static tree
   14083        51781 : c_omp_scan_mapper_bindings_r (tree *tp, int *walk_subtrees, void *ptr)
   14084              : {
   14085        51781 :   tree t = *tp;
   14086        51781 :   omp_mapper_list<tree> *mlist = (omp_mapper_list<tree> *) ptr;
   14087        51781 :   tree aggr_type = NULL_TREE;
   14088              : 
   14089        51781 :   if (TREE_CODE (t) == SIZEOF_EXPR
   14090        51781 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   14091              :     {
   14092            0 :       *walk_subtrees = 0;
   14093            0 :       return NULL_TREE;
   14094              :     }
   14095              : 
   14096        51781 :   if (TREE_CODE (t) == OMP_CLAUSE)
   14097              :     return NULL_TREE;
   14098              : 
   14099        48492 :   if (TREE_CODE (t) == COMPONENT_REF
   14100        48492 :       && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   14101          370 :     aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   14102        48122 :   else if ((TREE_CODE (t) == VAR_DECL
   14103              :             || TREE_CODE (t) == PARM_DECL
   14104              :             || TREE_CODE (t) == RESULT_DECL)
   14105         5392 :            && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   14106          121 :     aggr_type = TREE_TYPE (t);
   14107              : 
   14108          491 :   if (aggr_type)
   14109              :     {
   14110          491 :       tree mapper_fn = c_omp_mapper_lookup (NULL_TREE, aggr_type);
   14111          491 :       if (mapper_fn)
   14112           76 :         mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   14113              :     }
   14114              : 
   14115              :   return NULL_TREE;
   14116              : }
   14117              : 
   14118              : /* Scan an offload region's body, and record uses of struct- or union-typed
   14119              :    variables.  Add _mapper_binding_ fake clauses to *CLAUSES_PTR.  */
   14120              : 
   14121              : void
   14122         2079 : c_omp_scan_mapper_bindings (location_t loc, tree *clauses_ptr, tree body)
   14123              : {
   14124         2079 :   hash_set<omp_name_type<tree>> seen_types;
   14125         2079 :   auto_vec<tree> mappers;
   14126         2079 :   omp_mapper_list<tree> mlist (&seen_types, &mappers);
   14127              : 
   14128         2079 :   walk_tree_without_duplicates (&body, c_omp_scan_mapper_bindings_r, &mlist);
   14129              : 
   14130         2079 :   unsigned int i;
   14131         2079 :   tree mapper;
   14132         4200 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14133           42 :     c_omp_find_nested_mappers (&mlist, mapper);
   14134              : 
   14135         2150 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14136              :     {
   14137           42 :       if (mapper == error_mark_node)
   14138            0 :         continue;
   14139           42 :       tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   14140           42 :       tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   14141              : 
   14142           42 :       tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   14143           42 :       OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   14144           42 :       OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   14145           42 :       OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper;
   14146              : 
   14147           42 :       OMP_CLAUSE_CHAIN (c) = *clauses_ptr;
   14148           42 :       *clauses_ptr = c;
   14149              :     }
   14150         2079 : }
   14151              : 
   14152              : bool
   14153          247 : c_check_in_current_scope (tree decl)
   14154              : {
   14155          247 :   struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (decl));
   14156          247 :   return b != NULL && B_IN_CURRENT_SCOPE (b);
   14157              : }
   14158              : 
   14159              : /* Search for loop or switch names.  BEFORE_LABELS is last statement before
   14160              :    possible labels and SWITCH_P true for a switch, false for loops.
   14161              :    Searches through last statements in cur_stmt_list, stops when seeing
   14162              :    BEFORE_LABELs, or statement other than LABEL_EXPR or CASE_LABEL_EXPR.
   14163              :    Returns number of loop/switch names found and if any are found, sets
   14164              :    *LAST_P to the canonical loop/switch name LABEL_DECL.  */
   14165              : 
   14166              : int
   14167       515068 : c_get_loop_names (tree before_labels, bool switch_p, tree *last_p)
   14168              : {
   14169       515068 :   *last_p = NULL_TREE;
   14170      1030136 :   if (!building_stmt_list_p ()
   14171       515068 :       || !STATEMENT_LIST_HAS_LABEL (cur_stmt_list)
   14172       535708 :       || before_labels == void_list_node)
   14173       494428 :     return 0;
   14174              : 
   14175        20640 :   int ret = 0;
   14176        20640 :   tree last = NULL_TREE;
   14177        20640 :   for (tree_stmt_iterator tsi = tsi_last (cur_stmt_list);
   14178        28853 :        !tsi_end_p (tsi); tsi_prev (&tsi))
   14179              :     {
   14180        27996 :       tree stmt = tsi_stmt (tsi);
   14181        27996 :       if (stmt == before_labels)
   14182              :         break;
   14183         8213 :       else if (TREE_CODE (stmt) == LABEL_EXPR)
   14184              :         {
   14185         1098 :           if (last == NULL_TREE)
   14186          904 :             last = LABEL_EXPR_LABEL (stmt);
   14187              :           else
   14188              :             {
   14189          194 :               loop_names.safe_push (LABEL_EXPR_LABEL (stmt));
   14190          194 :               ++ret;
   14191              :             }
   14192              :         }
   14193         7115 :       else if (TREE_CODE (stmt) != CASE_LABEL_EXPR
   14194         4793 :                && TREE_CODE (stmt) != DEBUG_BEGIN_STMT)
   14195              :         break;
   14196              :     }
   14197        20640 :   if (last)
   14198              :     {
   14199          904 :       if (switch_p)
   14200          131 :         C_DECL_SWITCH_NAME (last) = 1;
   14201              :       else
   14202          773 :         C_DECL_LOOP_NAME (last) = 1;
   14203          904 :       loop_names.safe_push (last);
   14204          904 :       ++ret;
   14205          904 :       if (loop_names.length () > 16)
   14206              :         {
   14207           20 :           unsigned int first = 0, i;
   14208           20 :           tree l, c = NULL_TREE;
   14209           20 :           if (loop_names_hash == NULL)
   14210            8 :             loop_names_hash = new decl_tree_map (ret);
   14211              :           else
   14212           12 :             first = loop_names.length () - ret;
   14213          210 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14214              :             {
   14215          170 :               if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14216           48 :                 c = l;
   14217          170 :               gcc_checking_assert (c);
   14218          170 :               loop_names_hash->put (l, c);
   14219          170 :               if (i == first)
   14220              :                 break;
   14221              :             }
   14222              :         }
   14223          904 :       *last_p = last;
   14224              :     }
   14225              :   return ret;
   14226              : }
   14227              : 
   14228              : /* Undoes what get_loop_names did when it returned NUM_NAMES.  */
   14229              : 
   14230              : void
   14231          904 : c_release_loop_names (int num_names)
   14232              : {
   14233          904 :   unsigned len = loop_names.length () - num_names;
   14234          904 :   if (loop_names_hash)
   14235              :     {
   14236           20 :       if (len <= 16)
   14237              :         {
   14238            8 :           delete loop_names_hash;
   14239            8 :           loop_names_hash = NULL;
   14240              :         }
   14241              :       else
   14242              :         {
   14243           12 :           unsigned int i;
   14244           12 :           tree l;
   14245           42 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14246              :             {
   14247           30 :               loop_names_hash->remove (l);
   14248           30 :               if (i == len)
   14249              :                 break;
   14250              :             }
   14251              :         }
   14252              :     }
   14253          904 :   loop_names.truncate (len);
   14254          904 : }
   14255              : 
   14256              : /* Finish processing of break or continue identifier operand.
   14257              :    NAME is the identifier operand of break or continue and
   14258              :    IS_BREAK is true iff it is break stmt.  Returns the operand
   14259              :    to use for BREAK_STMT or CONTINUE_STMT, either NULL_TREE or
   14260              :    canonical loop/switch name LABEL_DECL.  */
   14261              : 
   14262              : tree
   14263          316 : c_finish_bc_name (location_t loc, tree name, bool is_break)
   14264              : {
   14265          316 :   tree label = NULL_TREE, lab;
   14266          457 :   pedwarn_c23 (loc, OPT_Wpedantic,
   14267              :                "ISO C does not support %qs statement with an identifier "
   14268              :                "operand before C2Y", is_break ? "break" : "continue");
   14269              : 
   14270              :   /* If I_LABEL_DECL is NULL or not from current function, don't waste time
   14271              :      trying to find it among loop_names, it can't be there.  */
   14272          316 :   if (!loop_names.is_empty ()
   14273          296 :       && current_function_scope
   14274          296 :       && (lab = I_LABEL_DECL (name))
   14275          290 :       && DECL_CONTEXT (lab) == current_function_decl)
   14276              :     {
   14277          280 :       unsigned int i;
   14278          280 :       tree l, c = NULL_TREE;
   14279          280 :       if (loop_names_hash)
   14280              :         {
   14281           86 :           if (tree *val = loop_names_hash->get (lab))
   14282           86 :             label = *val;
   14283              :         }
   14284              :       else
   14285          565 :         FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14286              :           {
   14287          363 :             if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14288              :               c = l;
   14289          363 :             gcc_checking_assert (c);
   14290          363 :             if (l == lab)
   14291              :               {
   14292              :                 label = c;
   14293              :                 break;
   14294              :               }
   14295              :           }
   14296          280 :       if (label)
   14297          272 :         TREE_USED (lab) = 1;
   14298              :     }
   14299          272 :   if (label == NULL_TREE)
   14300              :     {
   14301           44 :       auto_vec<const char *> candidates;
   14302           44 :       unsigned int i;
   14303           44 :       tree l, c = NULL_TREE;
   14304          115 :       FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14305              :         {
   14306           28 :           if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14307              :             c = l;
   14308           28 :           gcc_checking_assert (c);
   14309           42 :           if (is_break || C_DECL_LOOP_NAME (c))
   14310           25 :             candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l)));
   14311              :         }
   14312           44 :       const char *hint = find_closest_string (IDENTIFIER_POINTER (name),
   14313              :                                               &candidates);
   14314           44 :       if (hint)
   14315              :         {
   14316           22 :           gcc_rich_location richloc (loc);
   14317           22 :           richloc.add_fixit_replace (hint);
   14318           22 :           if (is_break)
   14319           11 :             error_at (&richloc, "%<break%> statement operand %qE does not "
   14320              :                                 "refer to a named loop or %<switch%>; "
   14321              :                                 "did you mean %qs?", name, hint);
   14322              :           else
   14323           11 :             error_at (&richloc, "%<continue%> statement operand %qE does not "
   14324              :                                 "refer to a named loop; did you mean %qs?",
   14325              :                       name, hint);
   14326           22 :         }
   14327           22 :       else if (is_break)
   14328           12 :         error_at (loc, "%<break%> statement operand %qE does not refer to a "
   14329              :                        "named loop or %<switch%>", name);
   14330              :       else
   14331           10 :         error_at (loc, "%<continue%> statement operand %qE does not refer to "
   14332              :                        "a named loop", name);
   14333           44 :     }
   14334          272 :   else if (!C_DECL_LOOP_NAME (label) && !is_break)
   14335              :     {
   14336            2 :       auto_diagnostic_group d;
   14337            2 :       error_at (loc, "%<continue%> statement operand %qE refers to a named "
   14338              :                      "%<switch%>", name);
   14339            2 :       inform (DECL_SOURCE_LOCATION (label), "%<switch%> name defined here");
   14340            2 :       label = NULL_TREE;
   14341            2 :     }
   14342          270 :   else if (!C_DECL_LOOP_SWITCH_NAME_VALID (label))
   14343              :     {
   14344           18 :       auto_diagnostic_group d;
   14345           18 :       if (C_DECL_LOOP_NAME (label))
   14346              :         {
   14347           16 :           error_at (loc, "%qs statement operand %qE refers to a loop outside "
   14348              :                          "of its body", is_break ? "break" : "continue", name);
   14349           16 :           inform (DECL_SOURCE_LOCATION (label), "loop name defined here");
   14350              :         }
   14351              :       else
   14352              :         {
   14353            2 :           error_at (loc, "%<break%> statement operand %qE refers to a "
   14354              :                          "%<switch%> outside of its body", name);
   14355            2 :           inform (DECL_SOURCE_LOCATION (label),
   14356              :                   "%<switch%> name defined here");
   14357              :         }
   14358           18 :       label = NULL_TREE;
   14359           18 :     }
   14360          252 :   else if (label == loop_names.last () && (in_statement & IN_NAMED_STMT) != 0)
   14361              :     /* If it is just a fancy reference to the innermost construct, handle it
   14362              :        just like break; or continue; though tracking cheaply what is the
   14363              :        innermost loop for continue when nested in switches would require
   14364              :        another global variable and updating it.  */
   14365              :     label = NULL_TREE;
   14366              :   else
   14367           98 :     C_DECL_LOOP_SWITCH_NAME_USED (label) = 1;
   14368          316 :   return label;
   14369              : }
   14370              : 
   14371              : #include "gt-c-c-decl.h"
        

Generated by: LCOV version 2.4-beta

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