LCOV - code coverage report
Current view: top level - gcc/c - c-decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.2 % 6390 5893
Test Date: 2026-02-28 14:20:25 Functions: 93.0 % 187 174
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   4537990991 : i_symbol_binding (tree node)
     260              : {
     261   4537990991 :   struct lang_identifier *lid
     262   4537990991 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     263              : 
     264   4537990991 :   if (lid->symbol_binding == NULL
     265   1669902274 :       && c_binding_oracle != NULL
     266   4537990991 :       && !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   4537990991 :   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      4520161 : i_tag_binding (tree node)
     289              : {
     290      4520161 :   struct lang_identifier *lid
     291      4520161 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     292              : 
     293      4520161 :   if (lid->tag_binding == NULL
     294      1252130 :       && c_binding_oracle != NULL
     295      4520161 :       && !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      4520161 :   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       359345 : i_label_binding (tree node)
     318              : {
     319       359345 :   struct lang_identifier *lid
     320       359345 :     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
     321              : 
     322       359345 :   if (lid->label_binding == NULL
     323        47782 :       && c_binding_oracle != NULL
     324       359345 :       && !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       359345 :   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      1177497 : 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      4313555 : c_struct_hasher::hash (tree type)
     660              : {
     661      4313555 :   inchash::hash hstate;
     662              : 
     663      4313555 :   hstate.add_int (TREE_CODE (type));
     664      4313555 :   tree tag = c_type_tag (type);
     665      4313555 :   hstate.add_object (tag);
     666              : 
     667      4313555 :   return hstate.end ();
     668              : }
     669              : 
     670              : /* Compare two RECORD or UNION types.  */
     671              : bool
     672     14626375 : c_struct_hasher::equal (tree t1,  tree t2)
     673              : {
     674     14626375 :   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     93580987 : add_stmt (tree t)
     701              : {
     702     93580987 :   enum tree_code code = TREE_CODE (t);
     703              : 
     704     93580987 :   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
     705              :     {
     706     92867636 :       if (!EXPR_HAS_LOCATION (t))
     707       154936 :         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     93580987 :   if (!building_stmt_list_p ())
     713            1 :     push_stmt_list ();
     714              : 
     715     93580987 :   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
     716      1079132 :     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
     717              : 
     718     93580987 :   append_to_statement_list_force (t, &cur_stmt_list);
     719              : 
     720     93580987 :   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    893189452 : decl_jump_unsafe (tree decl)
     732              : {
     733    893189452 :   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    893187418 :   if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl))
     742              :     return false;
     743              : 
     744    892269772 :   if (flag_openmp
     745     12435733 :       && VAR_P (decl)
     746    892301089 :       && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
     747              :     return true;
     748              : 
     749              :   /* Always warn about crossing variably modified types.  */
     750    882243342 :   if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
     751    904273762 :       && 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    892229369 :   if (warn_jump_misses_init
     757      5995643 :       && VAR_P (decl)
     758        10211 :       && !TREE_STATIC (decl)
     759    892234814 :       && 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           71 : c_mark_decl_jump_unsafe_in_current_scope ()
     797              : {
     798           71 :   current_scope->has_jump_unsafe_decl = 1;
     799           71 : }
     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    893040333 : bind (tree name, tree decl, struct c_scope *scope, bool invisible,
     806              :       bool nested, location_t locus)
     807              : {
     808    893040333 :   struct c_binding *b, **here;
     809              : 
     810    893040333 :   if (binding_freelist)
     811              :     {
     812    230088966 :       b = binding_freelist;
     813    230088966 :       binding_freelist = b->prev;
     814              :     }
     815              :   else
     816    662951367 :     b = ggc_alloc<c_binding> ();
     817              : 
     818    893040333 :   b->shadowed = 0;
     819    893040333 :   b->decl = decl;
     820    893040333 :   b->id = name;
     821    893040333 :   b->depth = scope->depth;
     822    893040333 :   b->invisible = invisible;
     823    893040333 :   b->nested = nested;
     824    893040333 :   b->inner_comp = 0;
     825    893040333 :   b->in_struct = 0;
     826    893040333 :   b->locus = locus;
     827              : 
     828    893040333 :   b->u.type = NULL;
     829              : 
     830    893040333 :   b->prev = scope->bindings;
     831    893040333 :   scope->bindings = b;
     832              : 
     833    893040333 :   if (decl_jump_unsafe (decl))
     834        24110 :     scope->has_jump_unsafe_decl = 1;
     835              : 
     836    893040333 :   if (!name)
     837              :     return;
     838              : 
     839    884416207 :   switch (TREE_CODE (decl))
     840              :     {
     841        23920 :     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
     842       625358 :     case ENUMERAL_TYPE:
     843       625358 :     case UNION_TYPE:
     844       625358 :     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
     845    883766929 :     case VAR_DECL:
     846    883766929 :     case FUNCTION_DECL:
     847    883766929 :     case TYPE_DECL:
     848    883766929 :     case CONST_DECL:
     849    883766929 :     case PARM_DECL:
     850    883766929 :     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    884416251 :   while (*here && (*here)->depth > scope->depth)
     860           44 :     here = &(*here)->shadowed;
     861              : 
     862    884416207 :   b->shadowed = *here;
     863    884416207 :   *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    876151061 : free_binding_and_advance (struct c_binding *b)
     872              : {
     873    876151061 :   struct c_binding *prev = b->prev;
     874              : 
     875    876151061 :   memset (b, 0, sizeof (struct c_binding));
     876    876151061 :   b->prev = binding_freelist;
     877    876151061 :   binding_freelist = b;
     878              : 
     879    876151061 :   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        23920 : bind_label (tree name, tree label, struct c_scope *scope,
     886              :             struct c_label_vars *label_vars)
     887              : {
     888        23920 :   struct c_binding *b;
     889              : 
     890        23920 :   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
     891              :         UNKNOWN_LOCATION);
     892              : 
     893        23920 :   scope->has_label_bindings = true;
     894              : 
     895        23920 :   b = scope->bindings;
     896        23920 :   gcc_assert (b->decl == label);
     897        23920 :   label_vars->shadowed = b->u.label;
     898        23920 :   b->u.label = label_vars;
     899        23920 : }
     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       105206 : check_inline_statics (void)
     952              : {
     953       105206 :   struct c_inline_static *csi;
     954       105242 :   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       105206 :   c_inline_statics = NULL;
     974       105206 : }
     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       134720 : set_spot_bindings (struct c_spot_bindings *p, bool defining)
     981              : {
     982            0 :   if (defining)
     983              :     {
     984       127583 :       p->scope = current_scope;
     985        16783 :       p->bindings_in_scope = current_scope->bindings;
     986              :     }
     987              :   else
     988              :     {
     989         7137 :       p->scope = NULL;
     990         7137 :       p->bindings_in_scope = NULL;
     991              :     }
     992       134720 :   p->stmt_exprs = 0;
     993       134720 :   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    470607936 : 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       205563 :   p->scope = scope->outer;
    1013       205563 :   p->bindings_in_scope = p->scope->bindings;
    1014              : 
    1015       151499 :   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      2087970 : global_bindings_p (void)
    1052              : {
    1053      2087970 :   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        34872 : 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        34872 :   return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl));
    1065              : }
    1066              : 
    1067              : void
    1068        52222 : keep_next_level (void)
    1069              : {
    1070        52222 :   keep_next_level_flag = true;
    1071        52222 : }
    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       602114 : float_const_decimal64_p (void)
    1093              : {
    1094       602114 :   return current_scope->float_const_decimal64;
    1095              : }
    1096              : 
    1097              : /* Identify this scope as currently being filled with parameters.  */
    1098              : 
    1099              : void
    1100     86746958 : declare_parm_level (void)
    1101              : {
    1102     86746958 :   current_scope->parm_flag = true;
    1103     86746958 : }
    1104              : 
    1105              : void
    1106    127960410 : push_scope (void)
    1107              : {
    1108    127960410 :   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     36250321 :       current_scope->parm_flag         = false;
    1121     36250321 :       current_scope->function_body     = true;
    1122     36250321 :       current_scope->keep              = true;
    1123     36250321 :       current_scope->outer_function    = current_function_scope;
    1124     36250321 :       current_function_scope           = current_scope;
    1125              : 
    1126     36250321 :       keep_next_level_flag = false;
    1127     36250321 :       next_is_function_body = false;
    1128              : 
    1129              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1130     36250321 :       if (current_scope->outer)
    1131     36250321 :         current_scope->float_const_decimal64
    1132     36250321 :           = current_scope->outer->float_const_decimal64;
    1133              :       else
    1134            0 :         current_scope->float_const_decimal64 = false;
    1135              :     }
    1136              :   else
    1137              :     {
    1138     91710089 :       struct c_scope *scope;
    1139     91710089 :       if (scope_freelist)
    1140              :         {
    1141     90864866 :           scope = scope_freelist;
    1142     90864866 :           scope_freelist = scope->outer;
    1143              :         }
    1144              :       else
    1145       845223 :         scope = ggc_cleared_alloc<c_scope> ();
    1146              : 
    1147              :       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
    1148     91710089 :       if (current_scope)
    1149     91599326 :         scope->float_const_decimal64 = current_scope->float_const_decimal64;
    1150              :       else
    1151       110763 :         scope->float_const_decimal64 = false;
    1152              : 
    1153     91710089 :       scope->keep          = keep_next_level_flag;
    1154     91710089 :       scope->outer         = current_scope;
    1155     91710089 :       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     91710089 :       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     91710089 :       current_scope        = scope;
    1166     91710089 :       keep_next_level_flag = false;
    1167              :     }
    1168    127960410 : }
    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     91703706 : update_label_decls (struct c_scope *scope)
    1177              : {
    1178     91703706 :   struct c_scope *s;
    1179              : 
    1180     91703706 :   s = scope;
    1181    330991609 :   while (s != NULL)
    1182              :     {
    1183    280300609 :       if (s->has_label_bindings)
    1184              :         {
    1185       232201 :           struct c_binding *b;
    1186              : 
    1187      2145911 :           for (b = s->bindings; b != NULL; b = b->prev)
    1188              :             {
    1189      1913710 :               struct c_label_vars *label_vars;
    1190      1913710 :               struct c_binding *b1;
    1191      1913710 :               bool hjud;
    1192      1913710 :               unsigned int ix;
    1193      1913710 :               struct c_goto_bindings *g;
    1194              : 
    1195      1913710 :               if (TREE_CODE (b->decl) != LABEL_DECL)
    1196      1410028 :                 continue;
    1197       503682 :               label_vars = b->u.label;
    1198              : 
    1199       503682 :               b1 = label_vars->label_bindings.bindings_in_scope;
    1200       503682 :               if (label_vars->label_bindings.scope == NULL)
    1201              :                 hjud = false;
    1202              :               else
    1203       194247 :                 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
    1204       503682 :               if (update_spot_bindings (scope, &label_vars->label_bindings))
    1205              :                 {
    1206              :                   /* This label is defined in this scope.  */
    1207        54064 :                   if (hjud)
    1208              :                     {
    1209       169658 :                       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       148239 :                           if (decl_jump_unsafe (b1->decl))
    1216        19449 :                             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    472311102 :               FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1224    470255753 :                 update_spot_bindings (scope, &g->goto_bindings);
    1225              :             }
    1226              :         }
    1227              : 
    1228              :       /* Don't search beyond the current function.  */
    1229    280300609 :       if (s == current_function_scope)
    1230              :         break;
    1231              : 
    1232    239287903 :       s = s->outer;
    1233              :     }
    1234     91703706 : }
    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     91703706 : pop_scope (void)
    1243              : {
    1244     91703706 :   struct c_scope *scope = current_scope;
    1245     91703706 :   tree block, context, p;
    1246     91703706 :   struct c_binding *b;
    1247              : 
    1248     91703706 :   bool functionbody = scope->function_body;
    1249     91703706 :   bool keep = functionbody || scope->keep || scope->bindings;
    1250              : 
    1251     91703706 :   update_label_decls (scope);
    1252              : 
    1253              :   /* If appropriate, create a BLOCK to record the decls for the life
    1254              :      of this function.  */
    1255     91703706 :   block = NULL_TREE;
    1256     91703706 :   if (keep)
    1257              :     {
    1258     36739253 :       block = make_node (BLOCK);
    1259     36739253 :       BLOCK_SUBBLOCKS (block) = scope->blocks;
    1260     36739253 :       TREE_USED (block) = 1;
    1261              : 
    1262              :       /* In each subblock, record that this is its superior.  */
    1263     37018438 :       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
    1264       279185 :         BLOCK_SUPERCONTEXT (p) = block;
    1265              : 
    1266     36739253 :       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     91703706 :   if (scope->function_body)
    1283     36250320 :     context = current_function_decl;
    1284     55453386 :   else if (scope == file_scope)
    1285              :     {
    1286       104875 :       tree file_decl
    1287       104875 :         = build_translation_unit_decl (get_identifier (main_input_filename));
    1288       104875 :       context = file_decl;
    1289       104875 :       debug_hooks->register_main_translation_unit (file_decl);
    1290              :     }
    1291              :   else
    1292              :     context = block;
    1293              : 
    1294              :   /* Clear all bindings in this scope.  */
    1295    844943649 :   for (b = scope->bindings; b; b = free_binding_and_advance (b))
    1296              :     {
    1297    753239943 :       p = b->decl;
    1298    753239943 :       switch (TREE_CODE (p))
    1299              :         {
    1300        23920 :         case LABEL_DECL:
    1301              :           /* Warnings for unused labels, errors for undefined labels.  */
    1302        23920 :           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        23857 :             warn_for_unused_label (p);
    1309              : 
    1310              :           /* Labels go in BLOCK_VARS.  */
    1311        23920 :           DECL_CHAIN (p) = BLOCK_VARS (block);
    1312        23920 :           BLOCK_VARS (block) = p;
    1313        23920 :           gcc_assert (I_LABEL_BINDING (b->id) == b);
    1314        23920 :           I_LABEL_BINDING (b->id) = b->shadowed;
    1315              : 
    1316              :           /* Also pop back to the shadowed label_vars.  */
    1317        23920 :           release_tree_vector (b->u.label->decls_in_scope);
    1318        23920 :           b->u.label = b->u.label->shadowed;
    1319        23920 :           break;
    1320              : 
    1321      1423318 :         case ENUMERAL_TYPE:
    1322      1423318 :         case UNION_TYPE:
    1323      1423318 :         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      1423318 :           if (b->id)
    1328              :             {
    1329       623537 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    1330       623537 :               I_TAG_BINDING (b->id) = b->shadowed;
    1331              :             }
    1332              :           break;
    1333              : 
    1334    623654485 :         case FUNCTION_DECL:
    1335              :           /* Propagate TREE_ADDRESSABLE from nested functions to their
    1336              :              containing functions.  */
    1337    623654485 :           if (!TREE_ASM_WRITTEN (p)
    1338    623654485 :               && DECL_INITIAL (p) != NULL_TREE
    1339     72142348 :               && TREE_ADDRESSABLE (p)
    1340      3684763 :               && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
    1341    623654485 :               && DECL_ABSTRACT_ORIGIN (p) != p)
    1342            0 :             TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
    1343    623654485 :           if (!TREE_PUBLIC (p)
    1344       357695 :               && !DECL_INITIAL (p)
    1345          161 :               && !b->nested
    1346          130 :               && scope != file_scope
    1347    623654493 :               && scope != external_scope)
    1348              :             {
    1349            8 :               error ("nested function %q+D declared but never defined", p);
    1350            8 :               undef_nested_function = true;
    1351              :             }
    1352    623654477 :           else if (DECL_DECLARED_INLINE_P (p)
    1353     70959324 :                    && TREE_PUBLIC (p)
    1354    694455391 :                    && !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    623654485 :           goto common_symbol;
    1368              : 
    1369     10935946 :         case VAR_DECL:
    1370              :           /* Warnings for unused variables.  */
    1371      8372700 :           if ((!TREE_USED (p) || !DECL_READ_P (p))
    1372      2592183 :               && !warning_suppressed_p (p, OPT_Wunused_but_set_variable_)
    1373      2591675 :               && !DECL_IN_SYSTEM_HEADER (p)
    1374      2512702 :               && DECL_NAME (p)
    1375      2512702 :               && !DECL_ARTIFICIAL (p)
    1376      2512337 :               && scope != file_scope
    1377     12560530 :               && scope != external_scope)
    1378              :             {
    1379       738469 :               if (!TREE_USED (p))
    1380              :                 {
    1381       732792 :                   warning (OPT_Wunused_variable, "unused variable %q+D", p);
    1382       732792 :                   suppress_warning (p, OPT_Wunused_variable);
    1383              :                 }
    1384         5677 :               else if (DECL_CONTEXT (p) == current_function_decl)
    1385         5656 :                 warning_at (DECL_SOURCE_LOCATION (p),
    1386         5656 :                             OPT_Wunused_but_set_variable_,
    1387              :                             "variable %qD set but not used", p);
    1388              :             }
    1389              : 
    1390     10935946 :           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    651911783 :         case TYPE_DECL:
    1398    651911783 :         case CONST_DECL:
    1399     10935944 :         common_symbol:
    1400              :           /* All of these go in BLOCK_VARS, but only if this is the
    1401              :              binding in the home scope.  */
    1402    651911783 :           if (!b->nested)
    1403              :             {
    1404    392354176 :               DECL_CHAIN (p) = BLOCK_VARS (block);
    1405    392354176 :               BLOCK_VARS (block) = p;
    1406              :             }
    1407    259557607 :           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        14594 :               tree extp = copy_node (p);
    1412              : 
    1413        14594 :               DECL_EXTERNAL (extp) = 1;
    1414        14594 :               TREE_STATIC (extp) = 0;
    1415        14594 :               TREE_PUBLIC (extp) = 1;
    1416        14594 :               DECL_INITIAL (extp) = NULL_TREE;
    1417        14594 :               DECL_LANG_SPECIFIC (extp) = NULL;
    1418        14594 :               DECL_CONTEXT (extp) = current_function_decl;
    1419        14594 :               if (TREE_CODE (p) == FUNCTION_DECL)
    1420              :                 {
    1421        13055 :                   DECL_RESULT (extp) = NULL_TREE;
    1422        13055 :                   DECL_SAVED_TREE (extp) = NULL_TREE;
    1423        13055 :                   DECL_STRUCT_FUNCTION (extp) = NULL;
    1424              :                 }
    1425        14594 :               if (b->locus != UNKNOWN_LOCATION)
    1426        14594 :                 DECL_SOURCE_LOCATION (extp) = b->locus;
    1427        14594 :               DECL_CHAIN (extp) = BLOCK_VARS (block);
    1428        14594 :               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    651911783 :           if (scope == file_scope)
    1434    270892202 :               DECL_CONTEXT (p) = context;
    1435              : 
    1436    751792705 :           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    751792705 :         case PARM_DECL:
    1443    751792705 :         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    751792705 :           if (b->id)
    1447              :             {
    1448    748605966 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    1449    748605966 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    1450    748605966 :               if (b->shadowed && b->shadowed->u.type)
    1451      4651650 :                 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     91703706 :   if ((scope->function_body || scope == file_scope) && context)
    1463              :     {
    1464     36355193 :       DECL_INITIAL (context) = block;
    1465     36355193 :       BLOCK_SUPERCONTEXT (block) = context;
    1466              :     }
    1467     55348513 :   else if (scope->outer)
    1468              :     {
    1469     55243638 :       if (block)
    1470       279185 :         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     54964453 :       else if (scope->blocks)
    1475       358524 :         SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
    1476              :     }
    1477              : 
    1478              :   /* Pop the current scope, and free the structure for reuse.  */
    1479     91703706 :   current_scope = scope->outer;
    1480     91703706 :   if (scope->function_body)
    1481     36250320 :     current_function_scope = scope->outer_function;
    1482              : 
    1483     91703706 :   memset (scope, 0, sizeof (struct c_scope));
    1484     91703706 :   scope->outer = scope_freelist;
    1485     91703706 :   scope_freelist = scope;
    1486              : 
    1487     91703706 :   return block;
    1488              : }
    1489              : 
    1490              : void
    1491       105368 : push_file_scope (void)
    1492              : {
    1493       105368 :   tree decl;
    1494              : 
    1495       105368 :   if (file_scope)
    1496              :     return;
    1497              : 
    1498       105368 :   push_scope ();
    1499       105368 :   file_scope = current_scope;
    1500              : 
    1501       105368 :   start_fname_decls ();
    1502              : 
    1503    210282383 :   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
    1504    210177015 :     bind (DECL_NAME (decl), decl, file_scope,
    1505    210177015 :           /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
    1506              : }
    1507              : 
    1508              : void
    1509       105206 : pop_file_scope (void)
    1510              : {
    1511              :   /* In case there were missing closebraces, get us back to the global
    1512              :      binding level.  */
    1513       105211 :   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       105206 :   finish_fname_decls ();
    1520              : 
    1521       105206 :   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       105206 :   if (pch_file)
    1526              :     {
    1527          331 :       c_common_write_pch ();
    1528              :       /* Ensure even the callers don't try to finalize the CU.  */
    1529          331 :       flag_syntax_only = 1;
    1530          331 :       return;
    1531              :     }
    1532              : 
    1533              :   /* Pop off the file scope and close this translation unit.  */
    1534       104875 :   pop_scope ();
    1535       104875 :   file_scope = 0;
    1536              : 
    1537       104875 :   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        34851 : c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
    1614              : {
    1615        34851 :   struct c_scope *scope;
    1616              : 
    1617       235404 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1618              :     {
    1619       200553 :       struct c_binding *b;
    1620              : 
    1621       200553 :       if (!scope->has_label_bindings)
    1622       198146 :         continue;
    1623              : 
    1624        12756 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1625              :         {
    1626        10349 :           struct c_label_vars *label_vars;
    1627        10349 :           unsigned int ix;
    1628        10349 :           struct c_goto_bindings *g;
    1629              : 
    1630        10349 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1631         1588 :             continue;
    1632         8761 :           label_vars = b->u.label;
    1633         8761 :           ++label_vars->label_bindings.stmt_exprs;
    1634        12885 :           FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    1635         1795 :             ++g->goto_bindings.stmt_exprs;
    1636              :         }
    1637              :     }
    1638              : 
    1639        34851 :   if (switch_bindings != NULL)
    1640          173 :     ++switch_bindings->stmt_exprs;
    1641        34851 : }
    1642              : 
    1643              : /* Adjust the bindings for the end of a statement expression.  */
    1644              : 
    1645              : void
    1646        34851 : c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
    1647              : {
    1648        34851 :   struct c_scope *scope;
    1649              : 
    1650       200553 :   for (scope = current_scope; scope != NULL; scope = scope->outer)
    1651              :     {
    1652       165702 :       struct c_binding *b;
    1653              : 
    1654       165702 :       if (!scope->has_label_bindings)
    1655       163060 :         continue;
    1656              : 
    1657        16232 :       for (b = scope->bindings; b != NULL; b = b->prev)
    1658              :         {
    1659        13590 :           struct c_label_vars *label_vars;
    1660        13590 :           unsigned int ix;
    1661        13590 :           struct c_goto_bindings *g;
    1662              : 
    1663        13590 :           if (TREE_CODE (b->decl) != LABEL_DECL)
    1664         1648 :             continue;
    1665        11942 :           label_vars = b->u.label;
    1666        11942 :           --label_vars->label_bindings.stmt_exprs;
    1667        11942 :           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        16118 :           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        34851 :   if (switch_bindings != NULL)
    1685              :     {
    1686          173 :       --switch_bindings->stmt_exprs;
    1687          173 :       gcc_assert (switch_bindings->stmt_exprs >= 0);
    1688              :     }
    1689        34851 : }
    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      1427275 : pushtag (location_t loc, tree name, tree type)
    1701              : {
    1702              :   /* Record the identifier as the type's name if it has none.  */
    1703      1427275 :   if (name && !TYPE_NAME (type))
    1704       625335 :     TYPE_NAME (type) = name;
    1705      1427275 :   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.  */
    1713              : 
    1714      1427275 :   TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
    1715              :                                                 TYPE_DECL, NULL_TREE, type));
    1716              : 
    1717              :   /* An approximation for now, so we can tell this is a function-scope tag.
    1718              :      This will be updated in pop_scope.  */
    1719      1427275 :   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
    1720              : 
    1721      1427275 :   if (warn_cxx_compat && name != NULL_TREE)
    1722              :     {
    1723          629 :       struct c_binding *b = I_SYMBOL_BINDING (name);
    1724              : 
    1725          629 :       if (b != NULL
    1726           12 :           && b->decl != NULL_TREE
    1727           12 :           && TREE_CODE (b->decl) == TYPE_DECL
    1728           11 :           && (B_IN_CURRENT_SCOPE (b)
    1729            6 :               || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    1730          634 :           && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
    1731            5 :               != TYPE_MAIN_VARIANT (type)))
    1732              :         {
    1733            5 :           auto_diagnostic_group d;
    1734            6 :           if (warning_at (loc, OPT_Wc___compat,
    1735              :                           "using %qD as both a typedef and a tag is "
    1736              :                           "invalid in C++", b->decl)
    1737            5 :               && b->locus != UNKNOWN_LOCATION)
    1738            4 :             inform (b->locus, "originally defined here");
    1739            5 :         }
    1740              :     }
    1741      1427275 : }
    1742              : 
    1743              : /* An exported interface to pushtag.  This is used by the gdb plugin's
    1744              :    binding oracle to introduce a new tag binding.  */
    1745              : 
    1746              : void
    1747            0 : c_pushtag (location_t loc, tree name, tree type)
    1748              : {
    1749            0 :   pushtag (loc, name, type);
    1750            0 : }
    1751              : 
    1752              : /* An exported interface to bind a declaration.  LOC is the location
    1753              :    to use.  DECL is the declaration to bind.  The decl's name is used
    1754              :    to determine how it is bound.  If DECL is a VAR_DECL, then
    1755              :    IS_GLOBAL determines whether the decl is put into the global (file
    1756              :    and external) scope or the current function's scope; if DECL is not
    1757              :    a VAR_DECL then it is always put into the file scope.  */
    1758              : 
    1759              : void
    1760            0 : c_bind (location_t loc, tree decl, bool is_global)
    1761              : {
    1762            0 :   struct c_scope *scope;
    1763            0 :   bool nested = false;
    1764              : 
    1765            0 :   if (!VAR_P (decl) || current_function_scope == NULL)
    1766              :     {
    1767              :       /* Types and functions are always considered to be global.  */
    1768            0 :       scope = file_scope;
    1769            0 :       DECL_EXTERNAL (decl) = 1;
    1770            0 :       TREE_PUBLIC (decl) = 1;
    1771              :     }
    1772            0 :   else if (is_global)
    1773              :     {
    1774              :       /* Also bind it into the external scope.  */
    1775            0 :       bind (DECL_NAME (decl), decl, external_scope, true, false, loc);
    1776            0 :       nested = true;
    1777            0 :       scope = file_scope;
    1778            0 :       DECL_EXTERNAL (decl) = 1;
    1779            0 :       TREE_PUBLIC (decl) = 1;
    1780              :     }
    1781              :   else
    1782              :     {
    1783            0 :       DECL_CONTEXT (decl) = current_function_decl;
    1784            0 :       TREE_PUBLIC (decl) = 0;
    1785            0 :       scope = current_function_scope;
    1786              :     }
    1787              : 
    1788            0 :   bind (DECL_NAME (decl), decl, scope, false, nested, loc);
    1789            0 : }
    1790              : 
    1791              : 
    1792              : /* Stores the first FILE*, const struct tm* etc. argument type (whatever
    1793              :    it is) seen in a declaration of a file I/O etc. built-in, corresponding
    1794              :    to the builtin_structptr_types array.  Subsequent declarations of such
    1795              :    built-ins are expected to refer to it rather than to fileptr_type_node,
    1796              :    etc. which is just void* (or to any other type).
    1797              :    Used only by match_builtin_function_types.  */
    1798              : 
    1799              : static const unsigned builtin_structptr_type_count
    1800              :   = ARRAY_SIZE (builtin_structptr_types);
    1801              : 
    1802              : static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
    1803              : 
    1804              : /* Returns true if types T1 and T2 representing return types or types
    1805              :    of function arguments are close enough to be considered interchangeable
    1806              :    in redeclarations of built-in functions.  */
    1807              : 
    1808              : static bool
    1809       622955 : types_close_enough_to_match (tree t1, tree t2)
    1810              : {
    1811       622955 :   return (TYPE_MODE (t1) == TYPE_MODE (t2)
    1812       622500 :           && POINTER_TYPE_P (t1) == POINTER_TYPE_P (t2)
    1813      2490302 :           && FUNCTION_POINTER_TYPE_P (t1) == FUNCTION_POINTER_TYPE_P (t2));
    1814              : }
    1815              : 
    1816              : /* Subroutine of compare_decls.  Allow harmless mismatches in return
    1817              :    and argument types provided that the type modes match.  Set *STRICT
    1818              :    and *ARGNO to the expected argument type and number in case of
    1819              :    an argument type mismatch or null and zero otherwise.  Return
    1820              :    a unified type given a suitable match, and 0 otherwise.  */
    1821              : 
    1822              : static tree
    1823       144488 : match_builtin_function_types (tree newtype, tree oldtype,
    1824              :                               tree *strict, unsigned *argno)
    1825              : {
    1826       144488 :   *argno = 0;
    1827       144488 :   *strict = NULL_TREE;
    1828              : 
    1829              :   /* Accept the return type of the new declaration if it has the same
    1830              :      mode and if they're both pointers or if neither is.  */
    1831       144488 :   tree oldrettype = TREE_TYPE (oldtype);
    1832       144488 :   tree newrettype = TREE_TYPE (newtype);
    1833              : 
    1834       144488 :   if (!types_close_enough_to_match (oldrettype, newrettype))
    1835              :     return NULL_TREE;
    1836              : 
    1837              :   /* Check that the return types are compatible but don't fail if they
    1838              :      are not (e.g., int vs long in ILP32) and just let the caller know.  */
    1839       144126 :   if (!comptypes (TYPE_MAIN_VARIANT (oldrettype),
    1840       144126 :                   TYPE_MAIN_VARIANT (newrettype)))
    1841           46 :     *strict = oldrettype;
    1842              : 
    1843       144126 :   tree oldargs = TYPE_ARG_TYPES (oldtype);
    1844       144126 :   tree newargs = TYPE_ARG_TYPES (newtype);
    1845       144126 :   tree tryargs = newargs;
    1846              : 
    1847       144126 :   const unsigned nlst = ARRAY_SIZE (last_structptr_types);
    1848       144126 :   const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
    1849              : 
    1850       144126 :   gcc_checking_assert (nlst == nbst);
    1851              : 
    1852       622396 :   for (unsigned i = 1; oldargs || newargs; ++i)
    1853              :     {
    1854       478526 :       if (!oldargs
    1855       478526 :           || !newargs
    1856       478471 :           || !TREE_VALUE (oldargs)
    1857       956997 :           || !TREE_VALUE (newargs))
    1858              :         return NULL_TREE;
    1859              : 
    1860       478471 :       tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
    1861       478471 :       tree newtype = TREE_VALUE (newargs);
    1862       478471 :       if (newtype == error_mark_node)
    1863              :        return NULL_TREE;
    1864       478467 :       newtype = TYPE_MAIN_VARIANT (newtype);
    1865              : 
    1866       478467 :       if (!types_close_enough_to_match (oldtype, newtype))
    1867              :         return NULL_TREE;
    1868              : 
    1869       478323 :       unsigned j = nbst;
    1870       478323 :       if (POINTER_TYPE_P (oldtype))
    1871              :         /* Iterate over well-known struct types like FILE (whose types
    1872              :            aren't known to us) and compare the pointer to each to
    1873              :            the pointer argument.  */
    1874       977098 :         for (j = 0; j < nbst; ++j)
    1875              :           {
    1876       860814 :             if (TREE_VALUE (oldargs) != builtin_structptr_types[j].node)
    1877       717159 :               continue;
    1878              :             /* Store the first FILE* etc. argument type (whatever it is), and
    1879              :                expect any subsequent declarations of file I/O etc. built-ins
    1880              :                to refer to it rather than to fileptr_type_node etc. which is
    1881              :                just void* (or const void*).  */
    1882       143655 :             if (last_structptr_types[j])
    1883              :               {
    1884       126193 :                 if (!comptypes (last_structptr_types[j], newtype))
    1885              :                   {
    1886            2 :                     *argno = i;
    1887            2 :                     *strict = last_structptr_types[j];
    1888              :                   }
    1889              :               }
    1890              :             else
    1891        17462 :               last_structptr_types[j] = newtype;
    1892              :             break;
    1893              :           }
    1894              : 
    1895       478323 :       if (j == nbst && !comptypes (oldtype, newtype))
    1896              :         {
    1897          243 :           if (POINTER_TYPE_P (oldtype))
    1898              :             {
    1899              :               /* For incompatible pointers, only reject differences in
    1900              :                  the unqualified variants of the referenced types but
    1901              :                  consider differences in qualifiers as benign (report
    1902              :                  those to caller via *STRICT below).  */
    1903          204 :               tree oldref = TYPE_MAIN_VARIANT (TREE_TYPE (oldtype));
    1904          204 :               tree newref = TYPE_MAIN_VARIANT (TREE_TYPE (newtype));
    1905          204 :               if (!comptypes (oldref, newref))
    1906              :                 return NULL_TREE;
    1907              :             }
    1908              : 
    1909          190 :           if (!*strict)
    1910              :             {
    1911          186 :               *argno = i;
    1912          186 :               *strict = oldtype;
    1913              :             }
    1914              :         }
    1915              : 
    1916       478270 :       oldargs = TREE_CHAIN (oldargs);
    1917       478270 :       newargs = TREE_CHAIN (newargs);
    1918              :     }
    1919              : 
    1920       143870 :   tree trytype = c_build_function_type (newrettype, tryargs);
    1921              : 
    1922              :   /* Allow declaration to change transaction_safe attribute.  */
    1923       143870 :   tree oldattrs = TYPE_ATTRIBUTES (oldtype);
    1924       143870 :   tree oldtsafe = lookup_attribute ("transaction_safe", oldattrs);
    1925       143870 :   tree newattrs = TYPE_ATTRIBUTES (newtype);
    1926       143870 :   tree newtsafe = lookup_attribute ("transaction_safe", newattrs);
    1927       143870 :   if (oldtsafe && !newtsafe)
    1928            0 :     oldattrs = remove_attribute ("transaction_safe", oldattrs);
    1929       143870 :   else if (newtsafe && !oldtsafe)
    1930            7 :     oldattrs = tree_cons (get_identifier ("transaction_safe"),
    1931              :                           NULL_TREE, oldattrs);
    1932              : 
    1933       143870 :   return c_build_type_attribute_variant (trytype, oldattrs);
    1934              : }
    1935              : 
    1936              : /* Subroutine of diagnose_mismatched_decls.  Check for function type
    1937              :    mismatch involving an empty arglist vs a nonempty one and give clearer
    1938              :    diagnostics.  */
    1939              : static void
    1940          176 : diagnose_arglist_conflict (tree newdecl, tree olddecl,
    1941              :                            tree newtype, tree oldtype)
    1942              : {
    1943          176 :   tree t;
    1944              : 
    1945          176 :   if (TREE_CODE (olddecl) != FUNCTION_DECL
    1946           98 :       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
    1947          303 :       || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == NULL_TREE)
    1948           68 :            || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == NULL_TREE)))
    1949          159 :     return;
    1950              : 
    1951           17 :   t = TYPE_ARG_TYPES (oldtype);
    1952           17 :   if (t == NULL_TREE)
    1953            9 :     t = TYPE_ARG_TYPES (newtype);
    1954           18 :   for (; t; t = TREE_CHAIN (t))
    1955              :     {
    1956           18 :       tree type = TREE_VALUE (t);
    1957              : 
    1958           18 :       if (TREE_CHAIN (t) == NULL_TREE
    1959           18 :           && TYPE_MAIN_VARIANT (type) != void_type_node)
    1960              :         {
    1961           10 :           inform (input_location, "a parameter list with an ellipsis "
    1962              :                   "cannot match an empty parameter name list declaration");
    1963           10 :           break;
    1964              :         }
    1965              : 
    1966            8 :       if (!error_operand_p (type)
    1967            8 :           && c_type_promotes_to (type) != type)
    1968              :         {
    1969            7 :           inform (input_location, "an argument type that has a default "
    1970              :                   "promotion cannot match an empty parameter name list "
    1971              :                   "declaration");
    1972            7 :           break;
    1973              :         }
    1974              :     }
    1975              : }
    1976              : 
    1977              : /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
    1978              :    old-style function definition, NEWDECL is a prototype declaration.
    1979              :    Diagnose inconsistencies in the argument list.  Returns TRUE if
    1980              :    the prototype is compatible, FALSE if not.  */
    1981              : static bool
    1982           19 : validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
    1983              : {
    1984           19 :   tree newargs, oldargs;
    1985           19 :   int i;
    1986              : 
    1987              : #define END_OF_ARGLIST(t) ((t) == void_type_node)
    1988              : 
    1989           19 :   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
    1990           19 :   newargs = TYPE_ARG_TYPES (newtype);
    1991           19 :   i = 1;
    1992              : 
    1993           45 :   for (;;)
    1994              :     {
    1995           32 :       tree oldargtype = TREE_VALUE (oldargs);
    1996           32 :       tree newargtype = TREE_VALUE (newargs);
    1997              : 
    1998           32 :       if (oldargtype == error_mark_node || newargtype == error_mark_node)
    1999              :         return false;
    2000              : 
    2001           58 :       oldargtype = (TYPE_ATOMIC (oldargtype)
    2002           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (oldargtype),
    2003              :                                               TYPE_QUAL_ATOMIC)
    2004           27 :                     : TYPE_MAIN_VARIANT (oldargtype));
    2005           60 :       newargtype = (TYPE_ATOMIC (newargtype)
    2006           31 :                     ? c_build_qualified_type (TYPE_MAIN_VARIANT (newargtype),
    2007              :                                               TYPE_QUAL_ATOMIC)
    2008           29 :                     : TYPE_MAIN_VARIANT (newargtype));
    2009              : 
    2010           31 :       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
    2011              :         break;
    2012              : 
    2013              :       /* Reaching the end of just one list means the two decls don't
    2014              :          agree on the number of arguments.  */
    2015           22 :       if (END_OF_ARGLIST (oldargtype))
    2016              :         {
    2017            2 :           error ("prototype for %q+D declares more arguments "
    2018              :                  "than previous old-style definition", newdecl);
    2019            2 :           return false;
    2020              :         }
    2021           20 :       else if (END_OF_ARGLIST (newargtype))
    2022              :         {
    2023            2 :           error ("prototype for %q+D declares fewer arguments "
    2024              :                  "than previous old-style definition", newdecl);
    2025            2 :           return false;
    2026              :         }
    2027              : 
    2028              :       /* Type for passing arg must be consistent with that declared
    2029              :          for the arg.  */
    2030           18 :       else if (!comptypes (oldargtype, newargtype))
    2031              :         {
    2032            5 :           error ("prototype for %q+D declares argument %d"
    2033              :                  " with incompatible type",
    2034              :                  newdecl, i);
    2035            5 :           return false;
    2036              :         }
    2037              : 
    2038           13 :       oldargs = TREE_CHAIN (oldargs);
    2039           13 :       newargs = TREE_CHAIN (newargs);
    2040           13 :       i++;
    2041           13 :     }
    2042              : 
    2043              :   /* If we get here, no errors were found, but do issue a warning
    2044              :      for this poor-style construct.  */
    2045            9 :   warning (0, "prototype for %q+D follows non-prototype definition",
    2046              :            newdecl);
    2047            9 :   return true;
    2048              : #undef END_OF_ARGLIST
    2049              : }
    2050              : 
    2051              : /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
    2052              :    first in a pair of mismatched declarations, using the diagnostic
    2053              :    function DIAG.  */
    2054              : static void
    2055          418 : locate_old_decl (tree decl)
    2056              : {
    2057          418 :   if (TREE_CODE (decl) == FUNCTION_DECL
    2058          200 :       && fndecl_built_in_p (decl)
    2059          421 :       && !C_DECL_DECLARED_BUILTIN (decl))
    2060              :     ;
    2061          418 :   else if (DECL_INITIAL (decl))
    2062          121 :     inform (input_location,
    2063              :             "previous definition of %q+D with type %qT",
    2064          121 :             decl, TREE_TYPE (decl));
    2065          297 :   else if (C_DECL_IMPLICIT (decl))
    2066           16 :     inform (input_location,
    2067              :             "previous implicit declaration of %q+D with type %qT",
    2068           16 :             decl, TREE_TYPE (decl));
    2069              :   else
    2070          281 :     inform (input_location,
    2071              :             "previous declaration of %q+D with type %qT",
    2072          281 :             decl, TREE_TYPE (decl));
    2073          418 : }
    2074              : 
    2075              : 
    2076              : /* Helper function.  For a tagged type, it finds the declaration
    2077              :    for a visible tag declared in the same scope if such a
    2078              :    declaration exists.  */
    2079              : static tree
    2080      1137199 : previous_tag (tree type)
    2081              : {
    2082      1137199 :   struct c_binding *b = NULL;
    2083      1137199 :   tree name = c_type_tag (type);
    2084              : 
    2085      1137199 :   if (name)
    2086       565036 :     b = I_TAG_BINDING (name);
    2087              : 
    2088       565036 :   if (b)
    2089       565036 :     b = b->shadowed;
    2090              : 
    2091      1137199 :   if (b && B_IN_CURRENT_SCOPE (b))
    2092          173 :     return b->decl;
    2093              : 
    2094              :   return NULL_TREE;
    2095              : }
    2096              : 
    2097              : /* Subroutine to mark functions as versioned when using the attribute
    2098              :    'target_version'.  */
    2099              : 
    2100              : static void
    2101            0 : maybe_mark_function_versioned (tree decl)
    2102              : {
    2103            0 :   if (!DECL_FUNCTION_VERSIONED (decl))
    2104              :     {
    2105              :       /* Check if the name of the function has been overridden.  */
    2106            0 :       if (DECL_ASSEMBLER_NAME_SET_P (decl)
    2107            0 :           && IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))[0] == '*')
    2108            0 :         error_at (DECL_SOURCE_LOCATION (decl),
    2109              :                   "cannot use function multiversioning on a renamed function");
    2110              : 
    2111              :       /* We need to insert function version now to make sure the correct
    2112              :          pre-mangled assembler name is recorded.  */
    2113            0 :       cgraph_node *node = cgraph_node::get_create (decl);
    2114              : 
    2115            0 :       if (!node->function_version ())
    2116            0 :         node->insert_new_function_version ();
    2117              : 
    2118            0 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    2119              : 
    2120            0 :       tree mangled_name
    2121            0 :         = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
    2122            0 :       SET_DECL_ASSEMBLER_NAME (decl, mangled_name);
    2123              :     }
    2124            0 : }
    2125              : 
    2126              : /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
    2127              :    Returns true if the caller should proceed to merge the two, false
    2128              :    if OLDDECL should simply be discarded.  As a side effect, issues
    2129              :    all necessary diagnostics for invalid or poor-style combinations.
    2130              :    If it returns true, writes the types of NEWDECL and OLDDECL to
    2131              :    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
    2132              :    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
    2133              : 
    2134              : static bool
    2135      4977829 : diagnose_mismatched_decls (tree newdecl, tree olddecl,
    2136              :                            tree *newtypep, tree *oldtypep)
    2137              : {
    2138      4977829 :   tree newtype, oldtype;
    2139      4977829 :   bool retval = true;
    2140              : 
    2141              : #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL)  \
    2142              :                                   && DECL_EXTERNAL (DECL))
    2143              : 
    2144              :   /* If we have error_mark_node for either decl or type, just discard
    2145              :      the previous decl - we're in an error cascade already.  */
    2146      4977829 :   if (olddecl == error_mark_node || newdecl == error_mark_node)
    2147              :     return false;
    2148      4977809 :   *oldtypep = oldtype = TREE_TYPE (olddecl);
    2149      4977809 :   *newtypep = newtype = TREE_TYPE (newdecl);
    2150      4977809 :   if (oldtype == error_mark_node || newtype == error_mark_node)
    2151              :     return false;
    2152              : 
    2153              :   /* Two different categories of symbol altogether.  This is an error
    2154              :      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
    2155      4977801 :   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2156              :     {
    2157           30 :       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
    2158           18 :             && fndecl_built_in_p (olddecl)
    2159           15 :             && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2160              :         {
    2161           16 :           auto_diagnostic_group d;
    2162           16 :           error ("%q+D redeclared as different kind of symbol", newdecl);
    2163           16 :           locate_old_decl (olddecl);
    2164           16 :         }
    2165           14 :       else if (TREE_PUBLIC (newdecl))
    2166            3 :         warning (OPT_Wbuiltin_declaration_mismatch,
    2167              :                  "built-in function %q+D declared as non-function",
    2168              :                  newdecl);
    2169              :       else
    2170           11 :         warning (OPT_Wshadow, "declaration of %q+D shadows "
    2171              :                  "a built-in function", newdecl);
    2172           30 :       return false;
    2173              :     }
    2174              : 
    2175              :   /* Enumerators have no linkage, so may only be declared once in a
    2176              :      given scope.  */
    2177      4977771 :   if (TREE_CODE (olddecl) == CONST_DECL)
    2178              :     {
    2179           46 :       if (flag_isoc23
    2180           45 :           && TYPE_NAME (DECL_CONTEXT (newdecl))
    2181           43 :           && DECL_CONTEXT (newdecl) != DECL_CONTEXT (olddecl)
    2182           87 :           && TYPE_NAME (DECL_CONTEXT (newdecl)) == TYPE_NAME (DECL_CONTEXT (olddecl)))
    2183              :         {
    2184           38 :           if (!simple_cst_equal (DECL_INITIAL (olddecl), DECL_INITIAL (newdecl)))
    2185              :             {
    2186            1 :               auto_diagnostic_group d;
    2187            1 :               error ("conflicting redeclaration of enumerator %q+D", newdecl);
    2188            1 :               locate_old_decl (olddecl);
    2189            1 :             }
    2190              :         }
    2191              :       else
    2192              :         {
    2193            8 :           auto_diagnostic_group d;
    2194            8 :           error ("redeclaration of enumerator %q+D", newdecl);
    2195            8 :           locate_old_decl (olddecl);
    2196            8 :         }
    2197           46 :       return false;
    2198              :     }
    2199              : 
    2200      4977725 :   bool pedwarned = false;
    2201      4977725 :   bool warned = false;
    2202      4977725 :   bool enum_and_int_p = false;
    2203      4977725 :   auto_diagnostic_group d;
    2204              : 
    2205      4977725 :   int comptypes_result = comptypes_check_enum_int (oldtype, newtype,
    2206              :                                                    &enum_and_int_p);
    2207      4977725 :   if (!comptypes_result)
    2208              :     {
    2209       144695 :       if (TREE_CODE (olddecl) == FUNCTION_DECL
    2210       144617 :           && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL)
    2211       289184 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2212              :         {
    2213              :           /* Accept "harmless" mismatches in function types such
    2214              :              as missing qualifiers or int vs long when they're the same
    2215              :              size.  However, diagnose return and argument types that are
    2216              :              incompatible according to language rules.  */
    2217       144488 :           tree mismatch_expect;
    2218       144488 :           unsigned mismatch_argno;
    2219              : 
    2220       144488 :           tree trytype = match_builtin_function_types (newtype, oldtype,
    2221              :                                                        &mismatch_expect,
    2222              :                                                        &mismatch_argno);
    2223              : 
    2224       144488 :           if (trytype && comptypes (newtype, trytype))
    2225       143870 :             *oldtypep = oldtype = trytype;
    2226              :           else
    2227              :             {
    2228              :               /* If types don't match for a built-in, throw away the
    2229              :                  built-in.  No point in calling locate_old_decl here, it
    2230              :                  won't print anything.  */
    2231          618 :               const char *header = header_for_builtin_fn (olddecl);
    2232          618 :               location_t loc = DECL_SOURCE_LOCATION (newdecl);
    2233         1019 :               if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    2234              :                               "conflicting types for built-in function %q+D; "
    2235              :                               "expected %qT",
    2236              :                               newdecl, oldtype)
    2237          618 :                   && header)
    2238              :                 {
    2239              :                   /* Suggest the right header to include as the preferred
    2240              :                      solution rather than the spelling of the declaration.  */
    2241          217 :                   rich_location richloc (line_table, loc);
    2242          217 :                   maybe_add_include_fixit (&richloc, header, true);
    2243          217 :                   inform (&richloc,
    2244              :                           "%qD is declared in header %qs", olddecl, header);
    2245          217 :                 }
    2246          618 :               return false;
    2247              :             }
    2248              : 
    2249       143870 :           if (mismatch_expect && extra_warnings)
    2250              :             {
    2251            5 :               location_t newloc = DECL_SOURCE_LOCATION (newdecl);
    2252            5 :               bool warned = false;
    2253            5 :               if (mismatch_argno)
    2254            5 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2255              :                                      "mismatch in argument %u type of built-in "
    2256              :                                      "function %qD; expected %qT",
    2257              :                                      mismatch_argno, newdecl, mismatch_expect);
    2258              :               else
    2259            0 :                 warned = warning_at (newloc, OPT_Wbuiltin_declaration_mismatch,
    2260              :                                      "mismatch in return type of built-in "
    2261              :                                      "function %qD; expected %qT",
    2262              :                                      newdecl, mismatch_expect);
    2263            5 :               const char *header = header_for_builtin_fn (olddecl);
    2264            5 :               if (warned && header)
    2265              :                 {
    2266            5 :                   rich_location richloc (line_table, newloc);
    2267            5 :                   maybe_add_include_fixit (&richloc, header, true);
    2268            5 :                   inform (&richloc,
    2269              :                           "%qD is declared in header %qs", olddecl, header);
    2270            5 :                 }
    2271              :             }
    2272              :         }
    2273          207 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2274          207 :                && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    2275              :         {
    2276              :           /* A conflicting function declaration for a predeclared
    2277              :              function that isn't actually built in.  Objective C uses
    2278              :              these.  The new declaration silently overrides everything
    2279              :              but the volatility (i.e. noreturn) indication.  See also
    2280              :              below.  FIXME: Make Objective C use normal builtins.  */
    2281            0 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2282            0 :           return false;
    2283              :         }
    2284              :       /* Permit void foo (...) to match int foo (...) if the latter is
    2285              :          the definition and implicit int was used.  See
    2286              :          c-torture/compile/920625-2.c.  */
    2287          129 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
    2288           64 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
    2289           32 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
    2290          213 :                && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
    2291              :         {
    2292            5 :           pedwarned = pedwarn (input_location, 0,
    2293              :                                "conflicting types for %q+D", newdecl);
    2294              :           /* Make sure we keep void as the return type.  */
    2295            5 :           TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
    2296            5 :           C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
    2297              :         }
    2298              :       /* Permit void foo (...) to match an earlier call to foo (...) with
    2299              :          no declared type (thus, implicitly int).  */
    2300          202 :       else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2301          124 :                && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
    2302           92 :                && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
    2303          225 :                && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
    2304              :         {
    2305           19 :           pedwarned = pedwarn (input_location, 0,
    2306              :                                "conflicting types for %q+D; have %qT",
    2307              :                                newdecl, newtype);
    2308              :           /* Make sure we keep void as the return type.  */
    2309           19 :           TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
    2310              :         }
    2311              :       else
    2312              :         {
    2313          183 :           int new_quals = TYPE_QUALS (newtype);
    2314          183 :           int old_quals = TYPE_QUALS (oldtype);
    2315              : 
    2316          183 :           if (new_quals != old_quals)
    2317              :             {
    2318           21 :               addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
    2319           21 :               addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
    2320           21 :               if (new_addr != old_addr)
    2321              :                 {
    2322            0 :                   if (ADDR_SPACE_GENERIC_P (new_addr))
    2323            0 :                     error ("conflicting named address spaces (generic vs %s) "
    2324              :                            "for %q+D",
    2325              :                            c_addr_space_name (old_addr), newdecl);
    2326            0 :                   else if (ADDR_SPACE_GENERIC_P (old_addr))
    2327            0 :                     error ("conflicting named address spaces (%s vs generic) "
    2328              :                            "for %q+D",
    2329              :                            c_addr_space_name (new_addr), newdecl);
    2330              :                   else
    2331            0 :                     error ("conflicting named address spaces (%s vs %s) "
    2332              :                            "for %q+D",
    2333              :                            c_addr_space_name (new_addr),
    2334              :                            c_addr_space_name (old_addr),
    2335              :                            newdecl);
    2336              :                 }
    2337              : 
    2338           21 :               if (CLEAR_QUAL_ADDR_SPACE (new_quals)
    2339           21 :                   != CLEAR_QUAL_ADDR_SPACE (old_quals))
    2340           21 :                 error ("conflicting type qualifiers for %q+D", newdecl);
    2341              :             }
    2342              :           else
    2343              :             {
    2344          162 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2345              :                 {
    2346           93 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl));
    2347           93 :                   if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl)))
    2348              :                     {
    2349              :                       /* Similar to the C++ front-end, for FUNCTION_DECL,
    2350              :                          if OLDDECL has attributes and NEWDECL doesn't,
    2351              :                          try the type with OLDDECL attributes.  */
    2352           12 :                       tree rettype = TREE_TYPE (newtype);
    2353           12 :                       tree tryargs = TYPE_ARG_TYPES (newtype);
    2354           12 :                       tree trytype = c_build_function_type (rettype,
    2355              :                                                             tryargs);
    2356           12 :                       trytype = c_build_type_attribute_variant (trytype,
    2357              :                                                                 attrs);
    2358           12 :                       if (comptypes (oldtype, trytype))
    2359              :                         {
    2360            7 :                           *newtypep = newtype = trytype;
    2361            7 :                           comptypes_result = 1;
    2362              :                         }
    2363              :                     }
    2364              :                 }
    2365              : 
    2366          162 :               if (!comptypes_result)
    2367          155 :                 error ("conflicting types for %q+D; have %qT", newdecl,
    2368              :                        newtype);
    2369              :             }
    2370            7 :           if (!comptypes_result)
    2371              :             {
    2372          176 :               diagnose_arglist_conflict (newdecl, olddecl, newtype,
    2373              :                                          oldtype);
    2374          176 :               locate_old_decl (olddecl);
    2375          176 :               return false;
    2376              :             }
    2377              :         }
    2378              :     }
    2379              :   /* Warn about enum/integer type mismatches.  They are compatible types
    2380              :      (C23 6.7.2.2/5), but may pose portability problems.  */
    2381      4833030 :   else if (enum_and_int_p
    2382          191 :            && TREE_CODE (newdecl) != TYPE_DECL
    2383              :            /* Don't warn about acc_on_device built-in redeclaration,
    2384              :               the built-in is declared with int rather than enum because
    2385              :               the enum isn't intrinsic.  */
    2386      4833217 :            && !(TREE_CODE (olddecl) == FUNCTION_DECL
    2387          150 :                 && fndecl_built_in_p (olddecl, BUILT_IN_ACC_ON_DEVICE)
    2388          120 :                 && !C_DECL_DECLARED_BUILTIN (olddecl)))
    2389           67 :     warned = warning_at (DECL_SOURCE_LOCATION (newdecl),
    2390           67 :                          OPT_Wenum_int_mismatch,
    2391              :                          "conflicting types for %q+D due to enum/integer "
    2392              :                          "mismatch; have %qT", newdecl, newtype);
    2393              : 
    2394              :   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
    2395              :      but silently ignore the redeclaration if either is in a system
    2396              :      header.  (Conflicting redeclarations were handled above.)  This
    2397              :      is allowed for C11 if the types are the same, not just
    2398              :      compatible.  */
    2399      4976931 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2400              :     {
    2401        45768 :       bool types_different = false;
    2402              : 
    2403        45768 :       comptypes_result
    2404        45768 :         = comptypes_check_different_types (oldtype, newtype, &types_different);
    2405              : 
    2406        45768 :       if (comptypes_result != 1 || types_different)
    2407              :         {
    2408           11 :           error ("redefinition of typedef %q+D with different type", newdecl);
    2409           11 :           locate_old_decl (olddecl);
    2410           11 :           return false;
    2411              :         }
    2412              : 
    2413        45757 :       if (DECL_IN_SYSTEM_HEADER (newdecl)
    2414         2484 :           || DECL_IN_SYSTEM_HEADER (olddecl)
    2415         2262 :           || warning_suppressed_p (newdecl, OPT_Wpedantic)
    2416        48019 :           || warning_suppressed_p (olddecl, OPT_Wpedantic))
    2417        43495 :         return true;  /* Allow OLDDECL to continue in use.  */
    2418              : 
    2419         2262 :       if (c_type_variably_modified_p (newtype))
    2420              :         {
    2421            3 :           error ("redefinition of typedef %q+D with variably modified type",
    2422              :                  newdecl);
    2423            3 :           locate_old_decl (olddecl);
    2424              :         }
    2425         2259 :       else if (pedwarn_c99 (input_location, OPT_Wpedantic,
    2426              :                             "redefinition of typedef %q+D", newdecl))
    2427            8 :         locate_old_decl (olddecl);
    2428              : 
    2429         2262 :       return true;
    2430              :     }
    2431              : 
    2432              :   /* Function declarations can either be 'static' or 'extern' (no
    2433              :      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
    2434              :      can never conflict with each other on account of linkage
    2435              :      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
    2436              :      gnu89 mode permits two definitions if one is 'extern inline' and
    2437              :      one is not.  The non- extern-inline definition supersedes the
    2438              :      extern-inline definition.  */
    2439              : 
    2440      4931163 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2441              :     {
    2442              :       /* If you declare a built-in function name as static, or
    2443              :          define the built-in with an old-style definition (so we
    2444              :          can't validate the argument list) the built-in definition is
    2445              :          overridden, but optionally warn this was a bad choice of name.  */
    2446      4912518 :       if (fndecl_built_in_p (olddecl)
    2447      8780141 :           && !C_DECL_DECLARED_BUILTIN (olddecl))
    2448              :         {
    2449      3609058 :           if (!TREE_PUBLIC (newdecl)
    2450      3609058 :               || (DECL_INITIAL (newdecl)
    2451         4855 :                   && !prototype_p (TREE_TYPE (newdecl))))
    2452              :             {
    2453          103 :               warning_at (DECL_SOURCE_LOCATION (newdecl),
    2454          103 :                           OPT_Wshadow, "declaration of %qD shadows "
    2455              :                           "a built-in function", newdecl);
    2456              :               /* Discard the old built-in function.  */
    2457          103 :               return false;
    2458              :             }
    2459              : 
    2460      3608955 :           if (!prototype_p (TREE_TYPE (newdecl)))
    2461              :             {
    2462              :               /* Set for built-ins that take no arguments.  */
    2463          342 :               bool func_void_args = false;
    2464          342 :               if (tree at = TYPE_ARG_TYPES (oldtype))
    2465          342 :                 func_void_args = VOID_TYPE_P (TREE_VALUE (at));
    2466              : 
    2467          342 :               if (extra_warnings && !func_void_args)
    2468           47 :                 warning_at (DECL_SOURCE_LOCATION (newdecl),
    2469           47 :                             OPT_Wbuiltin_declaration_mismatch,
    2470              :                             "declaration of built-in function %qD without "
    2471              :                             "a prototype; expected %qT",
    2472           47 :                             newdecl, TREE_TYPE (olddecl));
    2473              :             }
    2474              :         }
    2475              : 
    2476      4912415 :       if (DECL_INITIAL (newdecl))
    2477              :         {
    2478       232271 :           if (DECL_INITIAL (olddecl))
    2479              :             {
    2480              :               /* If the new declaration isn't overriding an extern inline
    2481              :                  reject the new decl. In c99, no overriding is allowed
    2482              :                  in the same translation unit.  */
    2483          211 :               if (!DECL_EXTERN_INLINE (olddecl)
    2484           91 :                   || DECL_EXTERN_INLINE (newdecl)
    2485          206 :                   || (!flag_gnu89_inline
    2486           15 :                       && (!DECL_DECLARED_INLINE_P (olddecl)
    2487           15 :                           || !lookup_attribute ("gnu_inline",
    2488           15 :                                                 DECL_ATTRIBUTES (olddecl)))
    2489            0 :                       && (!DECL_DECLARED_INLINE_P (newdecl)
    2490            0 :                           || !lookup_attribute ("gnu_inline",
    2491            0 :                                                 DECL_ATTRIBUTES (newdecl)))))
    2492              :                 {
    2493           28 :                   auto_diagnostic_group d;
    2494           28 :                   error ("redefinition of %q+D", newdecl);
    2495           28 :                   locate_old_decl (olddecl);
    2496           28 :                   return false;
    2497           28 :                 }
    2498              :             }
    2499              :         }
    2500              :       /* If we have a prototype after an old-style function definition,
    2501              :          the argument types must be checked specially.  */
    2502      4680144 :       else if (DECL_INITIAL (olddecl)
    2503          824 :                && !prototype_p (oldtype) && prototype_p (newtype)
    2504      4680164 :                && TYPE_ACTUAL_ARG_TYPES (oldtype))
    2505              :         {
    2506           19 :           auto_diagnostic_group d;
    2507           19 :           if (!validate_proto_after_old_defn (newdecl, newtype, oldtype))
    2508              :             {
    2509           10 :               locate_old_decl (olddecl);
    2510           10 :               return false;
    2511              :             }
    2512           19 :         }
    2513              :       /* A non-static declaration (even an "extern") followed by a
    2514              :          static declaration is undefined behavior per C99 6.2.2p3-5,7.
    2515              :          The same is true for a static forward declaration at block
    2516              :          scope followed by a non-static declaration/definition at file
    2517              :          scope.  Static followed by non-static at the same scope is
    2518              :          not undefined behavior, and is the most convenient way to get
    2519              :          some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
    2520              :          the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
    2521              :          we do diagnose it if -Wtraditional.  */
    2522      4912377 :       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
    2523              :         {
    2524              :           /* Two exceptions to the rule.  If olddecl is an extern
    2525              :              inline, or a predeclared function that isn't actually
    2526              :              built in, newdecl silently overrides olddecl.  The latter
    2527              :              occur only in Objective C; see also above.  (FIXME: Make
    2528              :              Objective C use normal builtins.)  */
    2529           19 :           if (!DECL_IS_UNDECLARED_BUILTIN (olddecl)
    2530           38 :               && !DECL_EXTERN_INLINE (olddecl))
    2531              :             {
    2532            5 :               auto_diagnostic_group d;
    2533            5 :               error ("static declaration of %q+D follows "
    2534              :                      "non-static declaration", newdecl);
    2535            5 :               locate_old_decl (olddecl);
    2536            5 :             }
    2537           19 :           return false;
    2538              :         }
    2539      4912358 :       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
    2540              :         {
    2541         2329 :           if (DECL_CONTEXT (olddecl))
    2542              :             {
    2543            0 :               auto_diagnostic_group d;
    2544            0 :               error ("non-static declaration of %q+D follows "
    2545              :                      "static declaration", newdecl);
    2546            0 :               locate_old_decl (olddecl);
    2547            0 :               return false;
    2548            0 :             }
    2549         2329 :           else if (warn_traditional)
    2550              :             {
    2551            2 :               warned |= warning (OPT_Wtraditional,
    2552              :                                  "non-static declaration of %q+D "
    2553              :                                  "follows static declaration", newdecl);
    2554              :             }
    2555              :         }
    2556              : 
    2557              :       /* Make sure gnu_inline attribute is either not present, or
    2558              :          present on all inline decls.  */
    2559      4912358 :       if (DECL_DECLARED_INLINE_P (olddecl)
    2560      4913433 :           && DECL_DECLARED_INLINE_P (newdecl))
    2561              :         {
    2562          820 :           bool newa = lookup_attribute ("gnu_inline",
    2563          820 :                                         DECL_ATTRIBUTES (newdecl)) != NULL;
    2564          820 :           bool olda = lookup_attribute ("gnu_inline",
    2565          820 :                                         DECL_ATTRIBUTES (olddecl)) != NULL;
    2566          820 :           if (newa != olda)
    2567              :             {
    2568            0 :               auto_diagnostic_group d;
    2569            0 :               error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
    2570              :                         newa ? newdecl : olddecl);
    2571            0 :               error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
    2572              :                         "but not here");
    2573            0 :             }
    2574              :         }
    2575              :       /* Check if these are unmergable overlapping FMV declarations.  */
    2576              :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2577              :           && diagnose_versioned_decls (olddecl, newdecl))
    2578              :         return false;
    2579              :     }
    2580        18645 :   else if (VAR_P (newdecl))
    2581              :     {
    2582              :       /* Only variables can be thread-local, and all declarations must
    2583              :          agree on this property.  */
    2584        18608 :       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
    2585              :         {
    2586              :           /* Nothing to check.  Since OLDDECL is marked threadprivate
    2587              :              and NEWDECL does not have a thread-local attribute, we
    2588              :              will merge the threadprivate attribute into NEWDECL.  */
    2589              :           ;
    2590              :         }
    2591        55611 :       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
    2592              :         {
    2593            6 :           auto_diagnostic_group d;
    2594            6 :           if (DECL_THREAD_LOCAL_P (newdecl))
    2595            3 :             error ("thread-local declaration of %q+D follows "
    2596              :                    "non-thread-local declaration", newdecl);
    2597              :           else
    2598            3 :             error ("non-thread-local declaration of %q+D follows "
    2599              :                    "thread-local declaration", newdecl);
    2600              : 
    2601            6 :           locate_old_decl (olddecl);
    2602            6 :           return false;
    2603            6 :         }
    2604              : 
    2605              :       /* Multiple initialized definitions are not allowed (6.9p3,5).
    2606              :          For this purpose, C23 makes it clear that thread-local
    2607              :          declarations without extern are definitions, not tentative
    2608              :          definitions, whether or not they have initializers.  The
    2609              :          wording before C23 was unclear; literally it would have made
    2610              :          uninitialized thread-local declarations into tentative
    2611              :          definitions only if they also used static, but without saying
    2612              :          explicitly whether or not other cases count as
    2613              :          definitions at all.  */
    2614        19143 :       if ((DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
    2615        19142 :           || (flag_isoc23
    2616         6434 :               && DECL_THREAD_LOCAL_P (newdecl)
    2617           25 :               && !DECL_EXTERNAL (newdecl)
    2618           21 :               && !DECL_EXTERNAL (olddecl)))
    2619              :         {
    2620            7 :           auto_diagnostic_group d;
    2621            7 :           error ("redefinition of %q+D", newdecl);
    2622            7 :           locate_old_decl (olddecl);
    2623            7 :           return false;
    2624            7 :         }
    2625              : 
    2626              :       /* Objects declared at file scope: if the first declaration had
    2627              :          external linkage (even if it was an external reference) the
    2628              :          second must have external linkage as well, or the behavior is
    2629              :          undefined.  If the first declaration had internal linkage, then
    2630              :          the second must too, or else be an external reference (in which
    2631              :          case the composite declaration still has internal linkage).
    2632              :          As for function declarations, we warn about the static-then-
    2633              :          extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
    2634        18612 :       if (DECL_FILE_SCOPE_P (newdecl)
    2635        18595 :           && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
    2636              :         {
    2637          147 :           if (DECL_EXTERNAL (newdecl))
    2638              :             {
    2639          144 :               if (!DECL_FILE_SCOPE_P (olddecl))
    2640              :                 {
    2641            2 :                   auto_diagnostic_group d;
    2642            2 :                   error ("extern declaration of %q+D follows "
    2643              :                          "declaration with no linkage", newdecl);
    2644            2 :                   locate_old_decl (olddecl);
    2645            2 :                   return false;
    2646            2 :                 }
    2647          142 :               else if (warn_traditional)
    2648              :                 {
    2649            0 :                   warned |= warning (OPT_Wtraditional,
    2650              :                                      "non-static declaration of %q+D "
    2651              :                                      "follows static declaration", newdecl);
    2652              :                 }
    2653              :             }
    2654              :           else
    2655              :             {
    2656            3 :               auto_diagnostic_group d;
    2657            3 :               if (TREE_PUBLIC (newdecl))
    2658            2 :                 error ("non-static declaration of %q+D follows "
    2659              :                        "static declaration", newdecl);
    2660              :               else
    2661            1 :                 error ("static declaration of %q+D follows "
    2662              :                        "non-static declaration", newdecl);
    2663              : 
    2664            3 :               locate_old_decl (olddecl);
    2665            3 :               return false;
    2666            3 :             }
    2667              :         }
    2668              :       /* Two objects with the same name declared at the same block
    2669              :          scope must both be external references (6.7p3).  */
    2670        18448 :       else if (!DECL_FILE_SCOPE_P (newdecl))
    2671              :         {
    2672           17 :           if (DECL_EXTERNAL (newdecl))
    2673              :             {
    2674              :               /* Extern with initializer at block scope, which will
    2675              :                  already have received an error.  */
    2676              :             }
    2677           15 :           else if (DECL_EXTERNAL (olddecl))
    2678              :             {
    2679            4 :               auto_diagnostic_group d;
    2680            4 :               error ("declaration of %q+D with no linkage follows "
    2681              :                      "extern declaration", newdecl);
    2682            4 :               locate_old_decl (olddecl);
    2683            4 :             }
    2684              :           else
    2685              :             {
    2686           11 :               auto_diagnostic_group d;
    2687           11 :               error ("redeclaration of %q+D with no linkage", newdecl);
    2688           11 :               locate_old_decl (olddecl);
    2689           11 :             }
    2690              : 
    2691           17 :           return false;
    2692              :         }
    2693              : 
    2694              :       /* C++ does not permit a decl to appear multiple times at file
    2695              :          scope.  */
    2696        18573 :       if (warn_cxx_compat
    2697           68 :           && DECL_FILE_SCOPE_P (newdecl)
    2698           68 :           && !DECL_EXTERNAL (newdecl)
    2699        18591 :           && !DECL_EXTERNAL (olddecl))
    2700            5 :         warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
    2701            5 :                               OPT_Wc___compat,
    2702              :                               "duplicate declaration of %qD is "
    2703              :                               "invalid in C++", newdecl);
    2704              :     }
    2705              : 
    2706              :   /* warnings */
    2707              :   /* All decls must agree on a visibility.  */
    2708      4930968 :   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
    2709      4930931 :       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
    2710      4931711 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2711              :     {
    2712            1 :       warned |= warning (0, "redeclaration of %q+D with different visibility "
    2713              :                          "(old visibility preserved)", newdecl);
    2714              :     }
    2715              : 
    2716      4930968 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2717      4912358 :     warned |= diagnose_mismatched_attributes (olddecl, newdecl);
    2718              :   else /* PARM_DECL, VAR_DECL */
    2719              :     {
    2720              :       /* Redeclaration of a parameter is a constraint violation (this is
    2721              :          not explicitly stated, but follows from C99 6.7p3 [no more than
    2722              :          one declaration of the same identifier with no linkage in the
    2723              :          same scope, except type tags] and 6.2.2p6 [parameters have no
    2724              :          linkage]).  We must check for a forward parameter declaration,
    2725              :          indicated by TREE_ASM_WRITTEN on the old declaration - this is
    2726              :          an extension, the mandatory diagnostic for which is handled by
    2727              :          mark_forward_parm_decls.  */
    2728              : 
    2729        18610 :       if (TREE_CODE (newdecl) == PARM_DECL
    2730           37 :           && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
    2731              :         {
    2732            2 :           auto_diagnostic_group d;
    2733            2 :           error ("redefinition of parameter %q+D", newdecl);
    2734            2 :           locate_old_decl (olddecl);
    2735            2 :           return false;
    2736            2 :         }
    2737              :     }
    2738              : 
    2739              :   /* Optional warning for completely redundant decls.  */
    2740      4930966 :   if (!warned && !pedwarned
    2741      4930892 :       && warn_redundant_decls
    2742              :       /* Don't warn about a function declaration followed by a
    2743              :          definition.  */
    2744           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2745            2 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
    2746              :       /* Don't warn about redundant redeclarations of builtins.  */
    2747           18 :       && !(TREE_CODE (newdecl) == FUNCTION_DECL
    2748            2 :            && !fndecl_built_in_p (newdecl)
    2749            2 :            && fndecl_built_in_p (olddecl)
    2750            2 :            && !C_DECL_DECLARED_BUILTIN (olddecl))
    2751              :       /* Don't warn about an extern followed by a definition.  */
    2752           17 :       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
    2753              :       /* Don't warn about forward parameter decls.  */
    2754           17 :       && !(TREE_CODE (newdecl) == PARM_DECL
    2755            6 :            && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2756              :       /* Don't warn about a variable definition following a declaration.  */
    2757      4930977 :       && !(VAR_P (newdecl)
    2758           10 :            && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
    2759              :     {
    2760            6 :       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
    2761              :                         newdecl);
    2762              :     }
    2763              : 
    2764              :   /* Report location of previous decl/defn.  */
    2765      4930966 :   if (warned || pedwarned)
    2766           80 :     locate_old_decl (olddecl);
    2767              : 
    2768              : #undef DECL_EXTERN_INLINE
    2769              : 
    2770              :   return retval;
    2771      4977725 : }
    2772              : 
    2773              : /* Subroutine of duplicate_decls.  NEWDECL has been found to be
    2774              :    consistent with OLDDECL, but carries new information.  Merge the
    2775              :    new information into OLDDECL.  This function issues no
    2776              :    diagnostics.  */
    2777              : 
    2778              : static void
    2779      4976723 : merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
    2780              : {
    2781      4976723 :   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
    2782      4976723 :                             && DECL_INITIAL (newdecl) != NULL_TREE);
    2783      4976723 :   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
    2784      4976723 :                            && prototype_p (TREE_TYPE (newdecl)));
    2785      4976723 :   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
    2786      4976723 :                            && prototype_p (TREE_TYPE (olddecl)));
    2787              : 
    2788              :   /* For real parm decl following a forward decl, rechain the old decl
    2789              :      in its new location and clear TREE_ASM_WRITTEN (it's not a
    2790              :      forward decl anymore).  */
    2791      4976723 :   if (TREE_CODE (newdecl) == PARM_DECL
    2792           35 :       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
    2793              :     {
    2794           35 :       struct c_binding *b, **here;
    2795              : 
    2796           54 :       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
    2797           54 :         if ((*here)->decl == olddecl)
    2798           35 :           goto found;
    2799            0 :       gcc_unreachable ();
    2800              : 
    2801           35 :     found:
    2802           35 :       b = *here;
    2803           35 :       *here = b->prev;
    2804           35 :       b->prev = current_scope->bindings;
    2805           35 :       current_scope->bindings = b;
    2806              : 
    2807           35 :       TREE_ASM_WRITTEN (olddecl) = 0;
    2808              :     }
    2809              : 
    2810      4976723 :   DECL_ATTRIBUTES (newdecl)
    2811      4976723 :     = targetm.merge_decl_attributes (olddecl, newdecl);
    2812              : 
    2813              :   /* For typedefs use the old type, as the new type's DECL_NAME points
    2814              :      at newdecl, which will be ggc_freed.  */
    2815      4976723 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2816              :     {
    2817              :       /* But NEWTYPE might have an attribute, honor that.  */
    2818        45757 :       tree tem = newtype;
    2819        45757 :       newtype = oldtype;
    2820              : 
    2821        45757 :       if (TYPE_USER_ALIGN (tem))
    2822              :         {
    2823           15 :           if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2824            6 :             SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2825           15 :           TYPE_USER_ALIGN (newtype) = true;
    2826              :         }
    2827              : 
    2828              :       /* And remove the new type from the variants list.  */
    2829        45757 :       if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2830              :         {
    2831           15 :           tree remove = TREE_TYPE (newdecl);
    2832           15 :           if (TYPE_MAIN_VARIANT (remove) == remove)
    2833              :             {
    2834            2 :               gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2835              :               /* If remove is the main variant, no need to remove that
    2836              :                  from the list.  One of the DECL_ORIGINAL_TYPE
    2837              :                  variants, e.g. created for aligned attribute, might still
    2838              :                  refer to the newdecl TYPE_DECL though, so remove that one
    2839              :                  in that case.  */
    2840            2 :               if (DECL_ORIGINAL_TYPE (newdecl)
    2841            2 :                   && DECL_ORIGINAL_TYPE (newdecl) != remove)
    2842            2 :                 for (tree t = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (newdecl));
    2843            2 :                      t; t = TYPE_MAIN_VARIANT (t))
    2844            2 :                   if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2845              :                     {
    2846            4 :                       TYPE_NEXT_VARIANT (t)
    2847            2 :                         = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2848            2 :                       break;
    2849              :                     }
    2850              :             }
    2851              :           else
    2852           13 :             for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2853            0 :                  t = TYPE_NEXT_VARIANT (t))
    2854           13 :               if (TYPE_NEXT_VARIANT (t) == remove)
    2855              :                 {
    2856           13 :                   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2857           13 :                   break;
    2858              :                 }
    2859              :         }
    2860              : 
    2861              :       /* Make sure we refer to the same type as the olddecl.  */
    2862        45757 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2863              :     }
    2864              : 
    2865              :   /* Merge the data types specified in the two decls.  */
    2866      9953446 :   TREE_TYPE (newdecl)
    2867      4976723 :     = TREE_TYPE (olddecl)
    2868      9953446 :     = composite_type (newtype, oldtype);
    2869              : 
    2870              :   /* Lay the type out, unless already done.  */
    2871      4976723 :   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
    2872              :     {
    2873            0 :       if (TREE_TYPE (newdecl) != error_mark_node)
    2874            0 :         layout_type (TREE_TYPE (newdecl));
    2875            0 :       if (TREE_CODE (newdecl) != FUNCTION_DECL
    2876              :           && TREE_CODE (newdecl) != TYPE_DECL
    2877              :           && TREE_CODE (newdecl) != CONST_DECL)
    2878            0 :         layout_decl (newdecl, 0);
    2879              :     }
    2880              :   else
    2881              :     {
    2882              :       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
    2883      4976723 :       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
    2884      4976723 :       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
    2885      4976723 :       SET_DECL_MODE (newdecl, DECL_MODE (olddecl));
    2886      4976723 :       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    2887              :         {
    2888           44 :           SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    2889           44 :           DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    2890              :         }
    2891      4976679 :       else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    2892      4976679 :                && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    2893            3 :         DECL_USER_ALIGN (newdecl) = 1;
    2894      9953446 :       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    2895      4976723 :           > DECL_WARN_IF_NOT_ALIGN (newdecl))
    2896            0 :         SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    2897              :                                     DECL_WARN_IF_NOT_ALIGN (olddecl));
    2898              :     }
    2899              : 
    2900              :   /* Keep the old rtl since we can safely use it.  */
    2901      4976723 :   if (HAS_RTL_P (olddecl))
    2902      4976723 :     COPY_DECL_RTL (olddecl, newdecl);
    2903              : 
    2904              :   /* Merge the type qualifiers.  */
    2905      4976723 :   if (TREE_READONLY (newdecl))
    2906       392420 :     TREE_READONLY (olddecl) = 1;
    2907              : 
    2908      4976723 :   if (TREE_THIS_VOLATILE (newdecl))
    2909        49189 :     TREE_THIS_VOLATILE (olddecl) = 1;
    2910              : 
    2911              :   /* Merge deprecatedness.  */
    2912      4976723 :   if (TREE_DEPRECATED (newdecl))
    2913          381 :     TREE_DEPRECATED (olddecl) = 1;
    2914              : 
    2915              :   /* Merge unavailability.  */
    2916      4976723 :   if (TREE_UNAVAILABLE (newdecl))
    2917            2 :     TREE_UNAVAILABLE (olddecl) = 1;
    2918              : 
    2919              :   /* If a decl is in a system header and the other isn't, keep the one on the
    2920              :      system header. Otherwise, keep source location of definition rather than
    2921              :      declaration and of prototype rather than non-prototype unless that
    2922              :      prototype is built-in.  */
    2923      4976723 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2924      4976688 :       && DECL_IN_SYSTEM_HEADER (olddecl)
    2925      5660018 :       && !DECL_IN_SYSTEM_HEADER (newdecl) )
    2926         1042 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2927      4975681 :   else if (HAS_DECL_ASSEMBLER_NAME_P (olddecl)
    2928      4975646 :            && DECL_IN_SYSTEM_HEADER (newdecl)
    2929      9214134 :            && !DECL_IN_SYSTEM_HEADER (olddecl))
    2930      3556200 :     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
    2931      1419481 :   else if ((DECL_INITIAL (newdecl) == NULL_TREE
    2932      1186766 :             && DECL_INITIAL (olddecl) != NULL_TREE)
    2933      2605325 :            || (old_is_prototype && !new_is_prototype
    2934          372 :                && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
    2935          950 :     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2936              : 
    2937              :   /* Merge the initialization information.  */
    2938      4976723 :    if (DECL_INITIAL (newdecl) == NULL_TREE)
    2939      4743936 :     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2940              : 
    2941              :   /* Merge 'constexpr' information.  */
    2942      4976723 :   if (VAR_P (olddecl) && VAR_P (newdecl))
    2943              :     {
    2944        18573 :       if (C_DECL_DECLARED_CONSTEXPR (olddecl))
    2945            2 :         C_DECL_DECLARED_CONSTEXPR (newdecl) = 1;
    2946        18571 :       else if (C_DECL_DECLARED_CONSTEXPR (newdecl))
    2947            1 :         C_DECL_DECLARED_CONSTEXPR (olddecl) = 1;
    2948              :     }
    2949              : 
    2950              :   /* Merge the threadprivate attribute.  */
    2951      4976723 :   if (VAR_P (olddecl) && C_DECL_THREADPRIVATE_P (olddecl))
    2952            7 :     C_DECL_THREADPRIVATE_P (newdecl) = 1;
    2953              : 
    2954      4976723 :   if (HAS_DECL_ASSEMBLER_NAME_P (olddecl))
    2955              :     {
    2956              :       /* Copy the assembler name.
    2957              :          Currently, it can only be defined in the prototype.  */
    2958      4976688 :       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2959              : 
    2960              :       /* Use visibility of whichever declaration had it specified */
    2961      4976688 :       if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2962              :         {
    2963         4758 :           DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2964         4758 :           DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2965              :         }
    2966              : 
    2967      4976688 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2968              :         {
    2969      4912358 :           DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
    2970      4912358 :           DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2971      4912358 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2972      4912358 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2973      4912358 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2974      4912358 :           TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    2975      4912358 :           DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    2976      4912358 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2977            0 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2978      4912358 :           if (DECL_IS_OPERATOR_DELETE_P (olddecl))
    2979            0 :             DECL_SET_IS_OPERATOR_DELETE (newdecl, true);
    2980      4912358 :           TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    2981      4912358 :           DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    2982      4912358 :           DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    2983              :         }
    2984              : 
    2985              :       /* Merge the storage class information.  */
    2986      4976688 :       merge_weak (newdecl, olddecl);
    2987              : 
    2988              :       /* For functions, static overrides non-static.  */
    2989      4976688 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2990              :         {
    2991      4912358 :           TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
    2992              :           /* This is since we don't automatically
    2993              :              copy the attributes of NEWDECL into OLDDECL.  */
    2994      4912358 :           TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    2995              :           /* If this clears `static', clear it in the identifier too.  */
    2996      4912358 :           if (!TREE_PUBLIC (olddecl))
    2997         7719 :             TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
    2998              :         }
    2999              :     }
    3000              : 
    3001              :   /* In c99, 'extern' declaration before (or after) 'inline' means this
    3002              :      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
    3003              :      is present.  */
    3004      4976723 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3005      4912358 :       && !flag_gnu89_inline
    3006      4887965 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3007      4698216 :           || DECL_DECLARED_INLINE_P (olddecl))
    3008       189943 :       && (!DECL_DECLARED_INLINE_P (newdecl)
    3009       189749 :           || !DECL_DECLARED_INLINE_P (olddecl)
    3010          807 :           || !DECL_EXTERNAL (olddecl))
    3011       189154 :       && DECL_EXTERNAL (newdecl)
    3012       188946 :       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
    3013      4976821 :       && !current_function_decl)
    3014           81 :     DECL_EXTERNAL (newdecl) = 0;
    3015              : 
    3016              :   /* An inline definition following a static declaration is not
    3017              :      DECL_EXTERNAL.  */
    3018      4976723 :   if (new_is_definition
    3019       232226 :       && (DECL_DECLARED_INLINE_P (newdecl)
    3020        42255 :           || DECL_DECLARED_INLINE_P (olddecl))
    3021      5166908 :       && !TREE_PUBLIC (olddecl))
    3022          900 :     DECL_EXTERNAL (newdecl) = 0;
    3023              : 
    3024      4976723 :   if (DECL_EXTERNAL (newdecl))
    3025              :     {
    3026      4885526 :       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
    3027      4885526 :       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
    3028              : 
    3029              :       /* An extern decl does not override previous storage class.  */
    3030      4885526 :       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3031      4885526 :       if (!DECL_EXTERNAL (newdecl))
    3032              :         {
    3033         1437 :           DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    3034         1437 :           DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3035              :         }
    3036              :     }
    3037              :   else
    3038              :     {
    3039        91197 :       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
    3040        91197 :       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
    3041              :     }
    3042              : 
    3043      4976723 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3044              :     {
    3045      4912358 :       if (DECL_FUNCTION_VERSIONED (olddecl)
    3046      4912358 :           || DECL_FUNCTION_VERSIONED (newdecl))
    3047              :         {
    3048            0 :           maybe_mark_function_versioned (olddecl);
    3049            0 :           maybe_mark_function_versioned (newdecl);
    3050              :         }
    3051              :       /* If we're redefining a function previously defined as extern
    3052              :          inline, make sure we emit debug info for the inline before we
    3053              :          throw it away, in case it was inlined into a function that
    3054              :          hasn't been written out yet.  */
    3055      4912358 :       if (new_is_definition && DECL_INITIAL (olddecl))
    3056              :         /* The new defn must not be inline.  */
    3057           75 :         DECL_UNINLINABLE (newdecl) = 1;
    3058              :       else
    3059              :         {
    3060              :           /* If either decl says `inline', this fn is inline, unless
    3061              :              its definition was passed already.  */
    3062      4912283 :           if (DECL_DECLARED_INLINE_P (newdecl)
    3063      9634543 :               || DECL_DECLARED_INLINE_P (olddecl))
    3064       190208 :             DECL_DECLARED_INLINE_P (newdecl) = 1;
    3065              : 
    3066     14736849 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3067      9826200 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3068              : 
    3069      9824566 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3070      4912283 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3071      4912283 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3072      9824428 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3073              :         }
    3074              : 
    3075      4912358 :       if (fndecl_built_in_p (olddecl))
    3076              :         {
    3077              :           /* If redeclaring a builtin function, it stays built in.
    3078              :              But it gets tagged as having been declared.  */
    3079      3867520 :           copy_decl_built_in_function (newdecl, olddecl);
    3080      3867520 :           C_DECL_DECLARED_BUILTIN (newdecl) = 1;
    3081      3867520 :           if (new_is_prototype)
    3082              :             {
    3083      3867161 :               C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
    3084      3867161 :               if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3085              :                 {
    3086      3867161 :                   enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3087      3867161 :                   switch (fncode)
    3088              :                     {
    3089              :                       /* If a compatible prototype of these builtin functions
    3090              :                          is seen, assume the runtime implements it with the
    3091              :                          expected semantics.  */
    3092         6476 :                     case BUILT_IN_STPCPY:
    3093         6476 :                       if (builtin_decl_explicit_p (fncode))
    3094         6476 :                         set_builtin_decl_implicit_p (fncode, true);
    3095              :                       break;
    3096      3860685 :                     default:
    3097      3860685 :                       if (builtin_decl_explicit_p (fncode))
    3098      3860685 :                         set_builtin_decl_declared_p (fncode, true);
    3099              :                       break;
    3100              :                     }
    3101              : 
    3102      3867161 :                   copy_attributes_to_builtin (newdecl);
    3103              :                 }
    3104              :             }
    3105              :           else
    3106          718 :             C_DECL_BUILTIN_PROTOTYPE (newdecl)
    3107          718 :               = C_DECL_BUILTIN_PROTOTYPE (olddecl);
    3108              :         }
    3109              : 
    3110              :       /* Preserve function specific target and optimization options */
    3111      4912358 :       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3112      4912864 :           && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3113          470 :         DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3114          470 :           = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3115              : 
    3116      4912358 :       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3117      4935780 :           && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3118            9 :         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3119            9 :           = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3120              : 
    3121              :       /* Also preserve various other info from the definition.  */
    3122      4912358 :       if (!new_is_definition)
    3123              :         {
    3124      4680132 :           tree t;
    3125      4680132 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3126      4680132 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3127      4680132 :           DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3128      4680132 :           DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3129      4680132 :           DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
    3130      7341299 :           for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
    3131      2661167 :             DECL_CONTEXT (t) = newdecl;
    3132              : 
    3133              :           /* See if we've got a function to instantiate from.  */
    3134      4680132 :           if (DECL_SAVED_TREE (olddecl))
    3135         1620 :             DECL_ABSTRACT_ORIGIN (newdecl)
    3136          810 :               = DECL_ABSTRACT_ORIGIN (olddecl);
    3137              :         }
    3138              :     }
    3139              : 
    3140              :   /* Merge the USED information.  */
    3141      4976723 :   if (TREE_USED (olddecl))
    3142       716808 :     TREE_USED (newdecl) = 1;
    3143      4259915 :   else if (TREE_USED (newdecl))
    3144            4 :     TREE_USED (olddecl) = 1;
    3145      4976723 :   if (VAR_P (olddecl) || TREE_CODE (olddecl) == PARM_DECL)
    3146        18608 :     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
    3147      4976723 :   if (DECL_PRESERVE_P (olddecl))
    3148           25 :     DECL_PRESERVE_P (newdecl) = 1;
    3149      4976698 :   else if (DECL_PRESERVE_P (newdecl))
    3150            4 :     DECL_PRESERVE_P (olddecl) = 1;
    3151              : 
    3152              :   /* Merge DECL_COMMON */
    3153        18573 :   if (VAR_P (olddecl) && VAR_P (newdecl)
    3154        18573 :       && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl))
    3155      4995294 :       && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl)))
    3156        37138 :     DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl);
    3157              : 
    3158              :   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
    3159              :      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
    3160              :      DECL_ARGUMENTS (if appropriate).  */
    3161      4976723 :   {
    3162      4976723 :     unsigned olddecl_uid = DECL_UID (olddecl);
    3163      4976723 :     tree olddecl_context = DECL_CONTEXT (olddecl);
    3164      4976723 :     tree olddecl_arguments = NULL;
    3165      4976723 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3166      4912358 :       olddecl_arguments = DECL_ARGUMENTS (olddecl);
    3167              : 
    3168      4976723 :     memcpy ((char *) olddecl + sizeof (struct tree_common),
    3169              :             (char *) newdecl + sizeof (struct tree_common),
    3170              :             sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3171      4976723 :     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3172      4976723 :     switch (TREE_CODE (olddecl))
    3173              :       {
    3174      4930931 :       case FUNCTION_DECL:
    3175      4930931 :       case VAR_DECL:
    3176      4930931 :         {
    3177      4930931 :           struct symtab_node *snode = olddecl->decl_with_vis.symtab_node;
    3178              : 
    3179      9861862 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3180              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3181      4930931 :                   tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3182      4930931 :           olddecl->decl_with_vis.symtab_node = snode;
    3183              : 
    3184      4930931 :           if ((DECL_EXTERNAL (olddecl)
    3185        46842 :                || TREE_PUBLIC (olddecl)
    3186         7990 :                || TREE_STATIC (olddecl))
    3187      4977766 :               && DECL_SECTION_NAME (newdecl) != NULL)
    3188            8 :             set_decl_section_name (olddecl, newdecl);
    3189              : 
    3190              :           /* This isn't quite correct for something like
    3191              :                 int __thread x attribute ((tls_model ("local-exec")));
    3192              :                 extern int __thread x;
    3193              :              as we'll lose the "local-exec" model.  */
    3194      4930931 :           if (VAR_P (olddecl) && DECL_THREAD_LOCAL_P (newdecl))
    3195           89 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3196              :           break;
    3197              :         }
    3198              : 
    3199        45792 :       case FIELD_DECL:
    3200        45792 :       case PARM_DECL:
    3201        45792 :       case LABEL_DECL:
    3202        45792 :       case RESULT_DECL:
    3203        45792 :       case CONST_DECL:
    3204        45792 :       case TYPE_DECL:
    3205        91584 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3206              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3207        45792 :                 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
    3208        45792 :         break;
    3209              : 
    3210            0 :       default:
    3211              : 
    3212            0 :         memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3213              :                 (char *) newdecl + sizeof (struct tree_decl_common),
    3214              :                 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
    3215              :       }
    3216      4976723 :     DECL_UID (olddecl) = olddecl_uid;
    3217      4976723 :     DECL_CONTEXT (olddecl) = olddecl_context;
    3218      4976723 :     if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3219      4912358 :       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
    3220              :   }
    3221              : 
    3222              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3223              :      so that encode_section_info has a chance to look at the new decl
    3224              :      flags and attributes.  */
    3225      4976723 :   if (DECL_RTL_SET_P (olddecl)
    3226      4976723 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3227            0 :           || (VAR_P (olddecl) && TREE_STATIC (olddecl))))
    3228            0 :     make_decl_rtl (olddecl);
    3229      4976723 : }
    3230              : 
    3231              : /* Handle when a new declaration NEWDECL has the same name as an old
    3232              :    one OLDDECL in the same binding contour.  Prints an error message
    3233              :    if appropriate.
    3234              : 
    3235              :    If safely possible, alter OLDDECL to look like NEWDECL, and return
    3236              :    true.  Otherwise, return false.  */
    3237              : 
    3238              : static bool
    3239      4977829 : duplicate_decls (tree newdecl, tree olddecl)
    3240              : {
    3241      4977829 :   tree newtype = NULL, oldtype = NULL;
    3242              : 
    3243      4977829 :   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
    3244              :     {
    3245              :       /* Avoid `unused variable' and other warnings for OLDDECL.  */
    3246         1106 :       suppress_warning (olddecl, OPT_Wunused);
    3247              :       /* If the types are completely different, poison them both with
    3248              :          error_mark_node.  */
    3249         1106 :       if (TREE_CODE (TREE_TYPE (newdecl)) != TREE_CODE (TREE_TYPE (olddecl))
    3250          118 :           && olddecl != error_mark_node
    3251         1204 :           && seen_error ())
    3252              :         {
    3253           64 :           if (TREE_CODE (olddecl) != FUNCTION_DECL)
    3254           52 :             TREE_TYPE (olddecl) = error_mark_node;
    3255           64 :           if (TREE_CODE (newdecl) != FUNCTION_DECL)
    3256           60 :             TREE_TYPE (newdecl) = error_mark_node;
    3257              :         }
    3258         1106 :       return false;
    3259              :     }
    3260              : 
    3261      4976723 :   merge_decls (newdecl, olddecl, newtype, oldtype);
    3262              : 
    3263              :   /* The NEWDECL will no longer be needed.
    3264              : 
    3265              :      Before releasing the node, be sure to remove function from symbol
    3266              :      table that might have been inserted there to record comdat group.
    3267              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3268              :      structure is shared in between NEWDECL and OLDECL.  */
    3269      4976723 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3270      4912358 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3271      4976723 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3272              :     {
    3273      4930931 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3274      4930931 :       if (snode)
    3275          104 :         snode->remove ();
    3276              :     }
    3277      4976723 :   ggc_free (newdecl);
    3278      4976723 :   return true;
    3279              : }
    3280              : 
    3281              : 
    3282              : /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
    3283              : static void
    3284    170167129 : warn_if_shadowing (tree new_decl)
    3285              : {
    3286    170167129 :   struct c_binding *b;
    3287              : 
    3288              :   /* Shadow warnings wanted?  */
    3289    340333342 :   if (!(warn_shadow
    3290    170166393 :         || warn_shadow_local
    3291    170166213 :         || warn_shadow_compatible_local)
    3292              :       /* No shadow warnings for internally generated vars.  */
    3293    170167372 :       || DECL_IS_UNDECLARED_BUILTIN (new_decl))
    3294              :     return;
    3295              : 
    3296              :   /* Is anything being shadowed?  Invisible decls do not count.  */
    3297          253 :   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
    3298          157 :     if (b->decl && b->decl != new_decl && !b->invisible
    3299          214 :         && (b->decl == error_mark_node
    3300           43 :             || diagnostic_report_warnings_p (global_dc,
    3301              :                                              DECL_SOURCE_LOCATION (b->decl))))
    3302              :       {
    3303           57 :         tree old_decl = b->decl;
    3304              : 
    3305           57 :         if (old_decl == error_mark_node)
    3306              :           {
    3307           14 :             warning (OPT_Wshadow, "declaration of %q+D shadows previous "
    3308              :                      "non-variable", new_decl);
    3309           50 :             break;
    3310              :           }
    3311              : 
    3312           43 :         bool warned = false;
    3313           43 :         auto_diagnostic_group d;
    3314           43 :         if (TREE_CODE (old_decl) == PARM_DECL)
    3315              :           {
    3316            5 :             enum opt_code warning_code;
    3317              : 
    3318              :             /* If '-Wshadow=compatible-local' is specified without other
    3319              :                -Wshadow= flags, we will warn only when the types of the
    3320              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3321              :                (old_decl) are compatible.  */
    3322            5 :             if (warn_shadow)
    3323              :               warning_code = OPT_Wshadow;
    3324            2 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3325              :               warning_code = OPT_Wshadow_compatible_local;
    3326              :             else
    3327            2 :               warning_code = OPT_Wshadow_local;
    3328            5 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3329              :                                  "declaration of %qD shadows a parameter",
    3330              :                                  new_decl);
    3331              :           }
    3332           38 :         else if (DECL_FILE_SCOPE_P (old_decl))
    3333              :           {
    3334              :             /* Do not warn if a variable shadows a function, unless
    3335              :                the variable is a function or a pointer-to-function.  */
    3336           34 :             if (TREE_CODE (old_decl) == FUNCTION_DECL
    3337           11 :                 && TREE_CODE (new_decl) != FUNCTION_DECL
    3338           36 :                 && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
    3339            7 :                 continue;
    3340              : 
    3341           20 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
    3342              :                                  "declaration of %qD shadows a global "
    3343              :                                  "declaration",
    3344              :                                  new_decl);
    3345              :           }
    3346           11 :         else if (TREE_CODE (old_decl) == FUNCTION_DECL
    3347           11 :                  && fndecl_built_in_p (old_decl))
    3348              :           {
    3349            0 :             warning (OPT_Wshadow, "declaration of %q+D shadows "
    3350              :                      "a built-in function", new_decl);
    3351            0 :             break;
    3352              :           }
    3353              :         else
    3354              :           {
    3355           11 :             enum opt_code warning_code;
    3356              : 
    3357              :             /* If '-Wshadow=compatible-local' is specified without other
    3358              :                -Wshadow= flags, we will warn only when the types of the
    3359              :                shadowing variable (i.e. new_decl) and the shadowed variable
    3360              :                (old_decl) are compatible.  */
    3361           11 :             if (warn_shadow)
    3362              :               warning_code = OPT_Wshadow;
    3363            8 :             else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
    3364              :               warning_code = OPT_Wshadow_compatible_local;
    3365              :             else
    3366            2 :               warning_code = OPT_Wshadow_local;
    3367           11 :             warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
    3368              :                                  "declaration of %qD shadows a previous local",
    3369              :                                  new_decl);
    3370              :           }
    3371              : 
    3372           36 :         if (warned)
    3373           26 :           inform (DECL_SOURCE_LOCATION (old_decl),
    3374              :                   "shadowed declaration is here");
    3375              : 
    3376              :         break;
    3377           43 :       }
    3378              : }
    3379              : 
    3380              : /* Record a decl-node X as belonging to the current lexical scope.
    3381              :    Check for errors (such as an incompatible declaration for the same
    3382              :    name already seen in the same scope).
    3383              : 
    3384              :    Returns either X or an old decl for the same name.
    3385              :    If an old decl is returned, it may have been smashed
    3386              :    to agree with what X says.  */
    3387              : 
    3388              : tree
    3389    202399160 : pushdecl (tree x)
    3390              : {
    3391    202399160 :   tree name = DECL_NAME (x);
    3392    202399160 :   struct c_scope *scope = current_scope;
    3393    202399160 :   struct c_binding *b;
    3394    202399160 :   bool nested = false;
    3395    202399160 :   location_t locus = DECL_SOURCE_LOCATION (x);
    3396              : 
    3397              :   /* Must set DECL_CONTEXT for everything not at file scope or
    3398              :      DECL_FILE_SCOPE_P won't work.  Local externs don't count
    3399              :      unless they have initializers (which generate code).  We
    3400              :      also exclude CONST_DECLs because enumerators will get the
    3401              :      type of the enum as context.  */
    3402    202399160 :   if (current_function_decl
    3403      9126363 :       && TREE_CODE (x) != CONST_DECL
    3404    211368710 :       && (!VAR_OR_FUNCTION_DECL_P (x)
    3405      8691591 :           || DECL_INITIAL (x) || !TREE_PUBLIC (x)))
    3406      8957524 :     DECL_CONTEXT (x) = current_function_decl;
    3407              : 
    3408              :   /* Anonymous decls are just inserted in the scope.  */
    3409    202399160 :   if (!name)
    3410              :     {
    3411      7822186 :       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
    3412              :             locus);
    3413      7822186 :       return x;
    3414              :     }
    3415              : 
    3416              :   /* First, see if there is another declaration with the same name in
    3417              :      the current scope.  If there is, duplicate_decls may do all the
    3418              :      work for us.  If duplicate_decls returns false, that indicates
    3419              :      two incompatible decls in the same scope; we are to silently
    3420              :      replace the old one (duplicate_decls has issued all appropriate
    3421              :      diagnostics).  In particular, we should not consider possible
    3422              :      duplicates in the external scope, or shadowing.  */
    3423    194576974 :   b = I_SYMBOL_BINDING (name);
    3424    194576974 :   if (b && B_IN_SCOPE (b, scope))
    3425              :     {
    3426      1388058 :       struct c_binding *b_ext, *b_use;
    3427      1388058 :       tree type = TREE_TYPE (x);
    3428      1388058 :       tree visdecl = b->decl;
    3429      1388058 :       tree vistype = TREE_TYPE (visdecl);
    3430      1388058 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    3431      1388058 :           && COMPLETE_TYPE_P (TREE_TYPE (x)))
    3432         1370 :         b->inner_comp = false;
    3433      1388058 :       b_use = b;
    3434      1388058 :       b_ext = b;
    3435              :       /* If this is an external linkage declaration, we should check
    3436              :          for compatibility with the type in the external scope before
    3437              :          setting the type at this scope based on the visible
    3438              :          information only.  */
    3439      1388058 :       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
    3440              :         {
    3441      2668352 :           while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    3442      1334186 :             b_ext = b_ext->shadowed;
    3443      1334166 :           if (b_ext)
    3444              :             {
    3445      1334165 :               b_use = b_ext;
    3446      1334165 :               if (b_use->u.type)
    3447       270317 :                 TREE_TYPE (b_use->decl) = b_use->u.type;
    3448              :             }
    3449              :         }
    3450              : 
    3451              :       /* Check if x is part of a FMV set with b_use.
    3452              :          FMV is only supported in c for targets with target_version
    3453              :          attributes.  */
    3454      1388058 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    3455              :           && b_use && TREE_CODE (b_use->decl) == FUNCTION_DECL
    3456              :           && TREE_CODE (x) == FUNCTION_DECL && DECL_FILE_SCOPE_P (b_use->decl)
    3457              :           && DECL_FILE_SCOPE_P (x)
    3458              :           && disjoint_version_decls (x, b_use->decl)
    3459              :           && comptypes (vistype, type) != 0)
    3460              :         {
    3461              :           maybe_mark_function_versioned (b_use->decl);
    3462              :           maybe_mark_function_versioned (b->decl);
    3463              :           maybe_mark_function_versioned (x);
    3464              : 
    3465              :           cgraph_node *b_node = cgraph_node::get_create (b_use->decl);
    3466              :           cgraph_function_version_info *b_v = b_node->function_version ();
    3467              :           if (!b_v)
    3468              :             b_v = b_node->insert_new_function_version ();
    3469              : 
    3470              :           /* Check if this new node conflicts with any previous functions
    3471              :              in the set.  */
    3472              :           cgraph_function_version_info *version = b_v;
    3473              :           for (; version; version = version->next)
    3474              :             if (!disjoint_version_decls (version->this_node->decl, x))
    3475              :               {
    3476              :                 /* The decls define overlapping version, so attempt to merge
    3477              :                    or diagnose the conflict.  */
    3478              :                 if (duplicate_decls (x, version->this_node->decl))
    3479              :                   return version->this_node->decl;
    3480              :                 else
    3481              :                   return error_mark_node;
    3482              :               }
    3483              : 
    3484              :           /* This is a new version to be added to FMV structure.  */
    3485              :           cgraph_node::add_function_version (b_v, x);
    3486              : 
    3487              :           /* Get the first node from the structure.  */
    3488              :           cgraph_function_version_info *default_v = b_v;
    3489              :           while (default_v->prev)
    3490              :             default_v = default_v->prev;
    3491              :           /* Always use the default node for the bindings.  */
    3492              :           b_use->decl = default_v->this_node->decl;
    3493              :           b->decl = default_v->this_node->decl;
    3494              : 
    3495              :           /* Node is not a duplicate, so no need to do the rest of the
    3496              :              checks.  */
    3497              :           return x;
    3498              :         }
    3499              : 
    3500      1388058 :       if (duplicate_decls (x, b_use->decl))
    3501              :         {
    3502      1387686 :           if (b_use != b)
    3503              :             {
    3504              :               /* Save the updated type in the external scope and
    3505              :                  restore the proper type for this scope.  */
    3506      1333957 :               tree thistype;
    3507      1333957 :               if (comptypes (vistype, type))
    3508      1333915 :                 thistype = composite_type (vistype, type);
    3509              :               else
    3510           42 :                 thistype = TREE_TYPE (b_use->decl);
    3511      1333957 :               b_use->u.type = TREE_TYPE (b_use->decl);
    3512      1333957 :               if (TREE_CODE (b_use->decl) == FUNCTION_DECL
    3513      1333957 :                   && fndecl_built_in_p (b_use->decl))
    3514       280220 :                 thistype
    3515       280220 :                   = c_build_type_attribute_variant (thistype,
    3516       280220 :                                                     TYPE_ATTRIBUTES
    3517              :                                                     (b_use->u.type));
    3518      1333957 :               TREE_TYPE (b_use->decl) = thistype;
    3519              :             }
    3520      1387686 :           return b_use->decl;
    3521              :         }
    3522              :       else
    3523          372 :         goto skip_external_and_shadow_checks;
    3524              :     }
    3525              : 
    3526              :   /* All declarations with external linkage, and all external
    3527              :      references, go in the external scope, no matter what scope is
    3528              :      current.  However, the binding in that scope is ignored for
    3529              :      purposes of normal name lookup.  A separate binding structure is
    3530              :      created in the requested scope; this governs the normal
    3531              :      visibility of the symbol.
    3532              : 
    3533              :      The binding in the externals scope is used exclusively for
    3534              :      detecting duplicate declarations of the same object, no matter
    3535              :      what scope they are in; this is what we do here.  (C99 6.2.7p2:
    3536              :      All declarations that refer to the same object or function shall
    3537              :      have compatible type; otherwise, the behavior is undefined.)
    3538              :      However, in Objective-C, we also want to detect declarations
    3539              :      conflicting with those of the basic types.  */
    3540    337431909 :   if ((DECL_EXTERNAL (x) || scope == file_scope)
    3541    204663666 :       && (VAR_OR_FUNCTION_DECL_P (x) || c_dialect_objc ()))
    3542              :     {
    3543     50734412 :       tree type = TREE_TYPE (x);
    3544     50734412 :       tree vistype = NULL_TREE;
    3545     50734412 :       tree visdecl = NULL_TREE;
    3546     50734412 :       bool type_saved = false;
    3547      3589798 :       if (b && !B_IN_EXTERNAL_SCOPE (b)
    3548         1038 :           && VAR_OR_FUNCTION_DECL_P (b->decl)
    3549     50735441 :           && DECL_FILE_SCOPE_P (b->decl))
    3550              :         {
    3551          803 :           visdecl = b->decl;
    3552          803 :           vistype = TREE_TYPE (visdecl);
    3553              :         }
    3554     50734412 :       if (scope != file_scope
    3555     50734412 :           && !DECL_IN_SYSTEM_HEADER (x))
    3556        11476 :         warning_at (locus, OPT_Wnested_externs,
    3557              :                     "nested extern declaration of %qD", x);
    3558              : 
    3559     50735836 :       while (b && !B_IN_EXTERNAL_SCOPE (b))
    3560              :         {
    3561              :           /* If this decl might be modified, save its type.  This is
    3562              :              done here rather than when the decl is first bound
    3563              :              because the type may change after first binding, through
    3564              :              being completed or through attributes being added.  If we
    3565              :              encounter multiple such decls, only the first should have
    3566              :              its type saved; the others will already have had their
    3567              :              proper types saved and the types will not have changed as
    3568              :              their scopes will not have been re-entered.  */
    3569         1424 :           if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
    3570              :             {
    3571         1022 :               b->u.type = TREE_TYPE (b->decl);
    3572         1022 :               type_saved = true;
    3573              :             }
    3574         1424 :           if (B_IN_FILE_SCOPE (b)
    3575         1012 :               && VAR_P (b->decl)
    3576          572 :               && TREE_STATIC (b->decl)
    3577          281 :               && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
    3578          138 :               && !TYPE_DOMAIN (TREE_TYPE (b->decl))
    3579           47 :               && TREE_CODE (type) == ARRAY_TYPE
    3580           47 :               && TYPE_DOMAIN (type)
    3581           28 :               && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
    3582         1452 :               && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
    3583              :             {
    3584              :               /* Array type completed in inner scope, which should be
    3585              :                  diagnosed if the completion does not have size 1 and
    3586              :                  it does not get completed in the file scope.  */
    3587            6 :               b->inner_comp = true;
    3588              :             }
    3589         1424 :           b = b->shadowed;
    3590              :         }
    3591              : 
    3592              :       /* If a matching external declaration has been found, set its
    3593              :          type to the composite of all the types of that declaration.
    3594              :          After the consistency checks, it will be reset to the
    3595              :          composite of the visible types only.  */
    3596     50734412 :       if (b && b->u.type)
    3597          768 :         TREE_TYPE (b->decl) = b->u.type;
    3598              : 
    3599              :       /* the static does not go in the externals scope.  */
    3600      3589654 :       if (b && duplicate_decls (x, b->decl))
    3601              :         {
    3602      3588920 :           tree thistype;
    3603      3588920 :           if (vistype)
    3604              :             {
    3605          675 :               if (comptypes (vistype, type))
    3606          638 :                 thistype = composite_type (vistype, type);
    3607              :               else
    3608           37 :                 thistype = TREE_TYPE (b->decl);
    3609              :             }
    3610              :           else
    3611              :             thistype = type;
    3612      3588920 :           b->u.type = TREE_TYPE (b->decl);
    3613              :           /* Propagate the type attributes to the decl.  */
    3614      3588920 :           thistype
    3615      3588920 :             = c_build_type_attribute_variant (thistype,
    3616      3588920 :                                               TYPE_ATTRIBUTES (b->u.type));
    3617      3588920 :           TREE_TYPE (b->decl) = thistype;
    3618      3588920 :           bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
    3619              :                 locus);
    3620      3588920 :           return b->decl;
    3621              :         }
    3622     47145492 :       else if (TREE_PUBLIC (x))
    3623              :         {
    3624     46772256 :           if (visdecl && !b && duplicate_decls (x, visdecl))
    3625              :             {
    3626              :               /* An external declaration at block scope referring to a
    3627              :                  visible entity with internal linkage.  The composite
    3628              :                  type will already be correct for this scope, so we
    3629              :                  just need to fall through to make the declaration in
    3630              :                  this scope.  */
    3631              :               nested = true;
    3632              :               x = visdecl;
    3633              :             }
    3634              :           else
    3635              :             {
    3636     46772139 :               bind (name, x, external_scope, /*invisible=*/true,
    3637              :                     /*nested=*/false, locus);
    3638     46772139 :               nested = true;
    3639              :             }
    3640              :         }
    3641              :     }
    3642              : 
    3643    189599996 :   if (TREE_CODE (x) != PARM_DECL)
    3644     70287308 :     warn_if_shadowing (x);
    3645              : 
    3646    119312688 :  skip_external_and_shadow_checks:
    3647    189600368 :   if (TREE_CODE (x) == TYPE_DECL)
    3648              :     {
    3649              :       /* So this is a typedef, set its underlying type.  */
    3650      9670168 :       set_underlying_type (x);
    3651              : 
    3652              :       /* If X is a typedef defined in the current function, record it
    3653              :          for the purpose of implementing the -Wunused-local-typedefs
    3654              :          warning.  */
    3655      9670168 :       record_locally_defined_typedef (x);
    3656              :     }
    3657              : 
    3658    189600368 :   bind (name, x, scope, /*invisible=*/false, nested, locus);
    3659              : 
    3660              :   /* If x's type is incomplete because it's based on a
    3661              :      structure or union which has not yet been fully declared,
    3662              :      attach it to that structure or union type, so we can go
    3663              :      back and complete the variable declaration later, if the
    3664              :      structure or union gets fully declared.
    3665              : 
    3666              :      If the input is erroneous, we can have error_mark in the type
    3667              :      slot (e.g. "f(void a, ...)") - that doesn't count as an
    3668              :      incomplete type.  */
    3669    189600368 :   if (TREE_TYPE (x) != error_mark_node
    3670    189600368 :       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
    3671              :     {
    3672       183376 :       tree element = TREE_TYPE (x);
    3673              : 
    3674       203398 :       while (TREE_CODE (element) == ARRAY_TYPE)
    3675        20022 :         element = TREE_TYPE (element);
    3676       183376 :       element = TYPE_MAIN_VARIANT (element);
    3677              : 
    3678       183376 :       if ((RECORD_OR_UNION_TYPE_P (element)
    3679       139498 :            || TREE_CODE (element) == ENUMERAL_TYPE)
    3680        43949 :           && (TREE_CODE (x) != TYPE_DECL
    3681        40486 :               || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    3682       186847 :           && !COMPLETE_TYPE_P (element))
    3683          321 :         C_TYPE_INCOMPLETE_VARS (element)
    3684          642 :           = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
    3685              :     }
    3686              :   return x;
    3687              : }
    3688              : 
    3689              : 
    3690              : /* Issue a permerror about implicit function declaration.  ID is the function
    3691              :    identifier, OLDDECL is a declaration of the function in a different scope,
    3692              :    or NULL_TREE.  */
    3693              : 
    3694              : static void
    3695         3776 : implicit_decl_permerror (location_t loc, tree id, tree olddecl)
    3696              : {
    3697         3776 :   if (!warn_implicit_function_declaration)
    3698         2617 :     return;
    3699              : 
    3700         1159 :   bool warned;
    3701         1159 :   auto_diagnostic_group d;
    3702         1159 :   name_hint hint;
    3703         1159 :   if (!olddecl)
    3704          553 :     hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc);
    3705              : 
    3706         1159 :   if (flag_isoc99)
    3707              :     {
    3708         1153 :       if (const char *suggestion = hint.suggestion ())
    3709              :         {
    3710          107 :           gcc_rich_location richloc (loc);
    3711          107 :           richloc.add_fixit_replace (suggestion);
    3712          107 :           warned = permerror_opt (&richloc, OPT_Wimplicit_function_declaration,
    3713              :                                   "implicit declaration of function %qE;"
    3714              :                                   " did you mean %qs?",
    3715              :                                   id, suggestion);
    3716          107 :         }
    3717              :       else
    3718         1046 :         warned = permerror_opt (loc, OPT_Wimplicit_function_declaration,
    3719              :                                 "implicit declaration of function %qE", id);
    3720              :     }
    3721            6 :   else if (const char *suggestion = hint.suggestion ())
    3722              :     {
    3723            2 :       gcc_rich_location richloc (loc);
    3724            2 :       richloc.add_fixit_replace (suggestion);
    3725            2 :       warned = warning_at
    3726            2 :         (&richloc, OPT_Wimplicit_function_declaration,
    3727              :          G_("implicit declaration of function %qE; did you mean %qs?"),
    3728              :          id, suggestion);
    3729            2 :     }
    3730              :   else
    3731            4 :     warned = warning_at (loc, OPT_Wimplicit_function_declaration,
    3732              :                          G_("implicit declaration of function %qE"), id);
    3733              : 
    3734         1159 :   if (warned)
    3735              :     {
    3736              :       /* Whether the olddecl is an undeclared builtin function.
    3737              :          locate_old_decl will not generate a diagnostic for those,
    3738              :          so in that case we want to look elsewhere.  */
    3739           90 :       bool undeclared_builtin = (olddecl
    3740           28 :                                  && TREE_CODE (olddecl) == FUNCTION_DECL
    3741           28 :                                  && fndecl_built_in_p (olddecl)
    3742          117 :                                  && !C_DECL_DECLARED_BUILTIN (olddecl));
    3743           90 :       if (undeclared_builtin)
    3744              :         {
    3745           27 :           const char *header = header_for_builtin_fn (olddecl);
    3746           27 :           if (header)
    3747              :             {
    3748           20 :               rich_location richloc (line_table, loc);
    3749           20 :               maybe_add_include_fixit (&richloc, header, true);
    3750           20 :               inform (&richloc,
    3751              :                       "include %qs or provide a declaration of %qE",
    3752              :                       header, id);
    3753           20 :             }
    3754              :         }
    3755           63 :       else if (olddecl)
    3756            1 :         locate_old_decl (olddecl);
    3757              :     }
    3758              : 
    3759         1069 :   if (!warned)
    3760         1159 :     hint.suppress ();
    3761         1159 : }
    3762              : 
    3763              : /* Return the name of the header file that declares built-in function
    3764              :    FNDECL, or null if either we don't know or don't expect to see an
    3765              :    explicit declaration.  */
    3766              : 
    3767              : static const char *
    3768         3178 : header_for_builtin_fn (tree fndecl)
    3769              : {
    3770         3178 :   if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
    3771              :     return NULL;
    3772              : 
    3773         3178 :   switch (DECL_FUNCTION_CODE (fndecl))
    3774              :     {
    3775              :     CASE_FLT_FN (BUILT_IN_ACOS):
    3776              :     CASE_FLT_FN (BUILT_IN_ACOSH):
    3777              :     CASE_FLT_FN (BUILT_IN_ASIN):
    3778              :     CASE_FLT_FN (BUILT_IN_ASINH):
    3779              :     CASE_FLT_FN (BUILT_IN_ATAN):
    3780              :     CASE_FLT_FN (BUILT_IN_ATANH):
    3781              :     CASE_FLT_FN (BUILT_IN_ATAN2):
    3782              :     CASE_FLT_FN (BUILT_IN_CBRT):
    3783              :     CASE_FLT_FN (BUILT_IN_CEIL):
    3784              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
    3785              :     CASE_FLT_FN (BUILT_IN_COPYSIGN):
    3786              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
    3787              :     CASE_FLT_FN (BUILT_IN_COS):
    3788              :     CASE_FLT_FN (BUILT_IN_COSH):
    3789              :     CASE_FLT_FN (BUILT_IN_ERF):
    3790              :     CASE_FLT_FN (BUILT_IN_ERFC):
    3791              :     CASE_FLT_FN (BUILT_IN_EXP):
    3792              :     CASE_FLT_FN (BUILT_IN_EXP2):
    3793              :     CASE_FLT_FN (BUILT_IN_EXPM1):
    3794              :     CASE_FLT_FN (BUILT_IN_FABS):
    3795              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
    3796              :     CASE_FLT_FN (BUILT_IN_FDIM):
    3797              :     CASE_FLT_FN (BUILT_IN_FLOOR):
    3798              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
    3799              :     CASE_FLT_FN (BUILT_IN_FMA):
    3800              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
    3801              :     CASE_FLT_FN (BUILT_IN_FMAX):
    3802              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
    3803              :     CASE_FLT_FN (BUILT_IN_FMIN):
    3804              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
    3805              :     CASE_FLT_FN (BUILT_IN_FMOD):
    3806              :     CASE_FLT_FN (BUILT_IN_FREXP):
    3807              :     CASE_FLT_FN (BUILT_IN_HYPOT):
    3808              :     CASE_FLT_FN (BUILT_IN_ILOGB):
    3809              :     CASE_FLT_FN (BUILT_IN_LDEXP):
    3810              :     CASE_FLT_FN (BUILT_IN_LGAMMA):
    3811              :     CASE_FLT_FN (BUILT_IN_LLRINT):
    3812              :     CASE_FLT_FN (BUILT_IN_LLROUND):
    3813              :     CASE_FLT_FN (BUILT_IN_LOG):
    3814              :     CASE_FLT_FN (BUILT_IN_LOG10):
    3815              :     CASE_FLT_FN (BUILT_IN_LOG1P):
    3816              :     CASE_FLT_FN (BUILT_IN_LOG2):
    3817              :     CASE_FLT_FN (BUILT_IN_LOGB):
    3818              :     CASE_FLT_FN (BUILT_IN_LRINT):
    3819              :     CASE_FLT_FN (BUILT_IN_LROUND):
    3820              :     CASE_FLT_FN (BUILT_IN_MODF):
    3821              :     CASE_FLT_FN (BUILT_IN_NAN):
    3822              :     CASE_FLT_FN (BUILT_IN_NEARBYINT):
    3823              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
    3824              :     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
    3825              :     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
    3826              :     CASE_FLT_FN (BUILT_IN_POW):
    3827              :     CASE_FLT_FN (BUILT_IN_REMAINDER):
    3828              :     CASE_FLT_FN (BUILT_IN_REMQUO):
    3829              :     CASE_FLT_FN (BUILT_IN_RINT):
    3830              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
    3831              :     CASE_FLT_FN (BUILT_IN_ROUND):
    3832              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
    3833              :     CASE_FLT_FN (BUILT_IN_SCALBLN):
    3834              :     CASE_FLT_FN (BUILT_IN_SCALBN):
    3835              :     CASE_FLT_FN (BUILT_IN_SIN):
    3836              :     CASE_FLT_FN (BUILT_IN_SINH):
    3837              :     CASE_FLT_FN (BUILT_IN_SINCOS):
    3838              :     CASE_FLT_FN (BUILT_IN_SQRT):
    3839              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
    3840              :     CASE_FLT_FN (BUILT_IN_TAN):
    3841              :     CASE_FLT_FN (BUILT_IN_TANH):
    3842              :     CASE_FLT_FN (BUILT_IN_TGAMMA):
    3843              :     CASE_FLT_FN (BUILT_IN_TRUNC):
    3844              :     CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
    3845              :     case BUILT_IN_ISINF:
    3846              :     case BUILT_IN_ISNAN:
    3847              :       return "<math.h>";
    3848           29 :     CASE_FLT_FN (BUILT_IN_CABS):
    3849           29 :     CASE_FLT_FN (BUILT_IN_CACOS):
    3850           29 :     CASE_FLT_FN (BUILT_IN_CACOSH):
    3851           29 :     CASE_FLT_FN (BUILT_IN_CARG):
    3852           29 :     CASE_FLT_FN (BUILT_IN_CASIN):
    3853           29 :     CASE_FLT_FN (BUILT_IN_CASINH):
    3854           29 :     CASE_FLT_FN (BUILT_IN_CATAN):
    3855           29 :     CASE_FLT_FN (BUILT_IN_CATANH):
    3856           29 :     CASE_FLT_FN (BUILT_IN_CCOS):
    3857           29 :     CASE_FLT_FN (BUILT_IN_CCOSH):
    3858           29 :     CASE_FLT_FN (BUILT_IN_CEXP):
    3859           29 :     CASE_FLT_FN (BUILT_IN_CIMAG):
    3860           29 :     CASE_FLT_FN (BUILT_IN_CLOG):
    3861           29 :     CASE_FLT_FN (BUILT_IN_CONJ):
    3862           29 :     CASE_FLT_FN (BUILT_IN_CPOW):
    3863           29 :     CASE_FLT_FN (BUILT_IN_CPROJ):
    3864           29 :     CASE_FLT_FN (BUILT_IN_CREAL):
    3865           29 :     CASE_FLT_FN (BUILT_IN_CSIN):
    3866           29 :     CASE_FLT_FN (BUILT_IN_CSINH):
    3867           29 :     CASE_FLT_FN (BUILT_IN_CSQRT):
    3868           29 :     CASE_FLT_FN (BUILT_IN_CTAN):
    3869           29 :     CASE_FLT_FN (BUILT_IN_CTANH):
    3870           29 :       return "<complex.h>";
    3871          228 :     case BUILT_IN_MEMCHR:
    3872          228 :     case BUILT_IN_MEMCMP:
    3873          228 :     case BUILT_IN_MEMCPY:
    3874          228 :     case BUILT_IN_MEMMOVE:
    3875          228 :     case BUILT_IN_MEMSET:
    3876          228 :     case BUILT_IN_STRCAT:
    3877          228 :     case BUILT_IN_STRCHR:
    3878          228 :     case BUILT_IN_STRCMP:
    3879          228 :     case BUILT_IN_STRCPY:
    3880          228 :     case BUILT_IN_STRCSPN:
    3881          228 :     case BUILT_IN_STRLEN:
    3882          228 :     case BUILT_IN_STRNCAT:
    3883          228 :     case BUILT_IN_STRNCMP:
    3884          228 :     case BUILT_IN_STRNCPY:
    3885          228 :     case BUILT_IN_STRPBRK:
    3886          228 :     case BUILT_IN_STRRCHR:
    3887          228 :     case BUILT_IN_STRSPN:
    3888          228 :     case BUILT_IN_STRSTR:
    3889          228 :       return "<string.h>";
    3890          544 :     case BUILT_IN_FPRINTF:
    3891          544 :     case BUILT_IN_PUTC:
    3892          544 :     case BUILT_IN_FPUTC:
    3893          544 :     case BUILT_IN_FPUTS:
    3894          544 :     case BUILT_IN_FSCANF:
    3895          544 :     case BUILT_IN_FWRITE:
    3896          544 :     case BUILT_IN_PRINTF:
    3897          544 :     case BUILT_IN_PUTCHAR:
    3898          544 :     case BUILT_IN_PUTS:
    3899          544 :     case BUILT_IN_SCANF:
    3900          544 :     case BUILT_IN_SNPRINTF:
    3901          544 :     case BUILT_IN_SPRINTF:
    3902          544 :     case BUILT_IN_SSCANF:
    3903          544 :     case BUILT_IN_VFPRINTF:
    3904          544 :     case BUILT_IN_VFSCANF:
    3905          544 :     case BUILT_IN_VPRINTF:
    3906          544 :     case BUILT_IN_VSCANF:
    3907          544 :     case BUILT_IN_VSNPRINTF:
    3908          544 :     case BUILT_IN_VSPRINTF:
    3909          544 :     case BUILT_IN_VSSCANF:
    3910          544 :       return "<stdio.h>";
    3911            2 :     case BUILT_IN_ISALNUM:
    3912            2 :     case BUILT_IN_ISALPHA:
    3913            2 :     case BUILT_IN_ISBLANK:
    3914            2 :     case BUILT_IN_ISCNTRL:
    3915            2 :     case BUILT_IN_ISDIGIT:
    3916            2 :     case BUILT_IN_ISGRAPH:
    3917            2 :     case BUILT_IN_ISLOWER:
    3918            2 :     case BUILT_IN_ISPRINT:
    3919            2 :     case BUILT_IN_ISPUNCT:
    3920            2 :     case BUILT_IN_ISSPACE:
    3921            2 :     case BUILT_IN_ISUPPER:
    3922            2 :     case BUILT_IN_ISXDIGIT:
    3923            2 :     case BUILT_IN_TOLOWER:
    3924            2 :     case BUILT_IN_TOUPPER:
    3925            2 :       return "<ctype.h>";
    3926            0 :     case BUILT_IN_ISWALNUM:
    3927            0 :     case BUILT_IN_ISWALPHA:
    3928            0 :     case BUILT_IN_ISWBLANK:
    3929            0 :     case BUILT_IN_ISWCNTRL:
    3930            0 :     case BUILT_IN_ISWDIGIT:
    3931            0 :     case BUILT_IN_ISWGRAPH:
    3932            0 :     case BUILT_IN_ISWLOWER:
    3933            0 :     case BUILT_IN_ISWPRINT:
    3934            0 :     case BUILT_IN_ISWPUNCT:
    3935            0 :     case BUILT_IN_ISWSPACE:
    3936            0 :     case BUILT_IN_ISWUPPER:
    3937            0 :     case BUILT_IN_ISWXDIGIT:
    3938            0 :     case BUILT_IN_TOWLOWER:
    3939            0 :     case BUILT_IN_TOWUPPER:
    3940            0 :       return "<wctype.h>";
    3941         1818 :     case BUILT_IN_ABORT:
    3942         1818 :     case BUILT_IN_ABS:
    3943         1818 :     case BUILT_IN_CALLOC:
    3944         1818 :     case BUILT_IN_EXIT:
    3945         1818 :     case BUILT_IN_FREE:
    3946         1818 :     case BUILT_IN_LABS:
    3947         1818 :     case BUILT_IN_LLABS:
    3948         1818 :     case BUILT_IN_MALLOC:
    3949         1818 :     case BUILT_IN_REALLOC:
    3950         1818 :     case BUILT_IN__EXIT2:
    3951         1818 :     case BUILT_IN_ALIGNED_ALLOC:
    3952         1818 :       return "<stdlib.h>";
    3953            1 :     case BUILT_IN_IMAXABS:
    3954            1 :       return "<inttypes.h>";
    3955            3 :     case BUILT_IN_STRFTIME:
    3956            3 :       return "<time.h>";
    3957              :     default:
    3958              :       return NULL;
    3959              :     }
    3960              : }
    3961              : 
    3962              : /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
    3963              :    function of type int ().  */
    3964              : 
    3965              : tree
    3966         4729 : implicitly_declare (location_t loc, tree functionid)
    3967              : {
    3968         4729 :   struct c_binding *b;
    3969         4729 :   tree decl = NULL_TREE;
    3970         4729 :   tree asmspec_tree;
    3971              : 
    3972         4743 :   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
    3973              :     {
    3974         3158 :       if (B_IN_SCOPE (b, external_scope))
    3975              :         {
    3976         3144 :           decl = b->decl;
    3977         3144 :           break;
    3978              :         }
    3979              :     }
    3980              : 
    3981         4729 :   if (decl)
    3982              :     {
    3983         3144 :       if (TREE_CODE (decl) != FUNCTION_DECL)
    3984              :         return decl;
    3985              : 
    3986              :       /* FIXME: Objective-C has weird not-really-builtin functions
    3987              :          which are supposed to be visible automatically.  They wind up
    3988              :          in the external scope because they're pushed before the file
    3989              :          scope gets created.  Catch this here and rebind them into the
    3990              :          file scope.  */
    3991         3137 :       if (!fndecl_built_in_p (decl) && DECL_IS_UNDECLARED_BUILTIN (decl))
    3992              :         {
    3993            0 :           bind (functionid, decl, file_scope,
    3994              :                 /*invisible=*/false, /*nested=*/true,
    3995            0 :                 DECL_SOURCE_LOCATION (decl));
    3996            0 :           return decl;
    3997              :         }
    3998              :       else
    3999              :         {
    4000         3137 :           tree newtype = default_function_type;
    4001         3137 :           if (b->u.type)
    4002          753 :             TREE_TYPE (decl) = b->u.type;
    4003              :           /* Implicit declaration of a function already declared
    4004              :              (somehow) in a different scope, or as a built-in.
    4005              :              If this is the first time this has happened, warn;
    4006              :              then recycle the old declaration but with the new type.  */
    4007         3137 :           if (!C_DECL_IMPLICIT (decl))
    4008              :             {
    4009         2191 :               implicit_decl_permerror (loc, functionid, decl);
    4010         2191 :               C_DECL_IMPLICIT (decl) = 1;
    4011              :             }
    4012         3137 :           if (fndecl_built_in_p (decl))
    4013              :             {
    4014         2705 :               newtype = c_build_type_attribute_variant (newtype,
    4015         2705 :                                                         TYPE_ATTRIBUTES
    4016              :                                                         (TREE_TYPE (decl)));
    4017         2705 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4018              :                 {
    4019         2528 :                   auto_diagnostic_group d;
    4020         2528 :                   bool warned = warning_at (loc,
    4021         2528 :                                             OPT_Wbuiltin_declaration_mismatch,
    4022              :                                             "incompatible implicit "
    4023              :                                             "declaration of built-in "
    4024              :                                             "function %qD", decl);
    4025              :                   /* See if we can hint which header to include.  */
    4026         2528 :                   const char *header = header_for_builtin_fn (decl);
    4027         2528 :                   if (header != NULL && warned)
    4028              :                     {
    4029          133 :                       rich_location richloc (line_table, loc);
    4030          133 :                       maybe_add_include_fixit (&richloc, header, true);
    4031          133 :                       inform (&richloc,
    4032              :                               "include %qs or provide a declaration of %qD",
    4033              :                               header, decl);
    4034          133 :                     }
    4035         2528 :                   newtype = TREE_TYPE (decl);
    4036         2528 :                 }
    4037              :             }
    4038              :           else
    4039              :             {
    4040          432 :               if (!comptypes (newtype, TREE_TYPE (decl)))
    4041              :                 {
    4042            2 :                   auto_diagnostic_group d;
    4043            2 :                   error_at (loc, "incompatible implicit declaration of "
    4044              :                             "function %qD", decl);
    4045            2 :                   locate_old_decl (decl);
    4046            2 :                 }
    4047              :             }
    4048         3137 :           b->u.type = TREE_TYPE (decl);
    4049         3137 :           TREE_TYPE (decl) = newtype;
    4050         3137 :           bind (functionid, decl, current_scope,
    4051              :                 /*invisible=*/false, /*nested=*/true,
    4052         3137 :                 DECL_SOURCE_LOCATION (decl));
    4053         3137 :           return decl;
    4054              :         }
    4055              :     }
    4056              : 
    4057              :   /* Not seen before.  */
    4058         1585 :   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
    4059         1585 :   DECL_EXTERNAL (decl) = 1;
    4060         1585 :   TREE_PUBLIC (decl) = 1;
    4061         1585 :   C_DECL_IMPLICIT (decl) = 1;
    4062         1585 :   implicit_decl_permerror (loc, functionid, 0);
    4063         1585 :   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
    4064         1585 :   if (asmspec_tree)
    4065            1 :     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
    4066              : 
    4067              :   /* C89 says implicit declarations are in the innermost block.
    4068              :      So we record the decl in the standard fashion.  */
    4069         1585 :   decl = pushdecl (decl);
    4070              : 
    4071              :   /* No need to call objc_check_decl here - it's a function type.  */
    4072         1585 :   rest_of_decl_compilation (decl, 0, 0);
    4073              : 
    4074              :   /* Write a record describing this implicit function declaration
    4075              :      to the prototypes file (if requested).  */
    4076         1585 :   gen_aux_info_record (decl, 0, 1, 0);
    4077              : 
    4078              :   /* Possibly apply some default attributes to this implicit declaration.  */
    4079         1585 :   decl_attributes (&decl, NULL_TREE, 0);
    4080              : 
    4081         1585 :   return decl;
    4082              : }
    4083              : 
    4084              : /* Issue an error message for a reference to an undeclared variable
    4085              :    ID, including a reference to a builtin outside of function-call
    4086              :    context.  Establish a binding of the identifier to error_mark_node
    4087              :    in an appropriate scope, which will suppress further errors for the
    4088              :    same identifier.  The error message should be given location LOC.  */
    4089              : void
    4090         1257 : undeclared_variable (location_t loc, tree id)
    4091              : {
    4092         1257 :   static bool already = false;
    4093         1257 :   struct c_scope *scope;
    4094              : 
    4095         1257 :   auto_diagnostic_group d;
    4096         1257 :   if (current_function_decl == NULL_TREE)
    4097              :     {
    4098          433 :       name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4099          433 :       if (const char *suggestion = guessed_id.suggestion ())
    4100              :         {
    4101           86 :           gcc_rich_location richloc (loc);
    4102           86 :           richloc.add_fixit_replace (suggestion);
    4103           86 :           error_at (&richloc,
    4104              :                     "%qE undeclared here (not in a function);"
    4105              :                     " did you mean %qs?",
    4106              :                     id, suggestion);
    4107           86 :         }
    4108              :       else
    4109          347 :         error_at (loc, "%qE undeclared here (not in a function)", id);
    4110          433 :       scope = current_scope;
    4111          433 :     }
    4112              :   else
    4113              :     {
    4114          824 :       if (!objc_diagnose_private_ivar (id))
    4115              :         {
    4116          824 :           name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
    4117          824 :           if (const char *suggestion = guessed_id.suggestion ())
    4118              :             {
    4119           39 :               gcc_rich_location richloc (loc);
    4120           39 :               richloc.add_fixit_replace (suggestion);
    4121           39 :               error_at (&richloc,
    4122              :                         "%qE undeclared (first use in this function);"
    4123              :                         " did you mean %qs?",
    4124              :                         id, suggestion);
    4125           39 :             }
    4126              :           else
    4127          785 :             error_at (loc, "%qE undeclared (first use in this function)", id);
    4128          824 :         }
    4129          824 :       if (!already)
    4130              :         {
    4131          201 :           inform (loc, "each undeclared identifier is reported only"
    4132              :                   " once for each function it appears in");
    4133          201 :           already = true;
    4134              :         }
    4135              : 
    4136              :       /* If we are parsing old-style parameter decls, current_function_decl
    4137              :          will be nonnull but current_function_scope will be null.  */
    4138          824 :       scope = current_function_scope ? current_function_scope : current_scope;
    4139              :     }
    4140         1257 :   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
    4141              :         UNKNOWN_LOCATION);
    4142         1257 : }
    4143              : 
    4144              : /* Subroutine of lookup_label, declare_label, define_label: construct a
    4145              :    LABEL_DECL with all the proper frills.  Also create a struct
    4146              :    c_label_vars initialized for the current scope.  */
    4147              : 
    4148              : static tree
    4149        23920 : make_label (location_t location, tree name, bool defining,
    4150              :             struct c_label_vars **p_label_vars)
    4151              : {
    4152        23920 :   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
    4153        23920 :   DECL_CONTEXT (label) = current_function_decl;
    4154        23920 :   SET_DECL_MODE (label, VOIDmode);
    4155              : 
    4156        23920 :   c_label_vars *label_vars = ggc_alloc<c_label_vars> ();
    4157        23920 :   label_vars->shadowed = NULL;
    4158        23920 :   set_spot_bindings (&label_vars->label_bindings, defining);
    4159        23920 :   label_vars->decls_in_scope = make_tree_vector ();
    4160        23920 :   label_vars->gotos = NULL;
    4161        23920 :   *p_label_vars = label_vars;
    4162              : 
    4163        23920 :   return label;
    4164              : }
    4165              : 
    4166              : /* Get the LABEL_DECL corresponding to identifier NAME as a label.
    4167              :    Create one if none exists so far for the current function.
    4168              :    This is called when a label is used in a goto expression or
    4169              :    has its address taken.  */
    4170              : 
    4171              : tree
    4172        85362 : lookup_label (tree name)
    4173              : {
    4174        85362 :   tree label;
    4175        85362 :   struct c_label_vars *label_vars;
    4176              : 
    4177        85362 :   if (current_function_scope == 0)
    4178              :     {
    4179            2 :       error ("label %qE referenced outside of any function", name);
    4180            2 :       return NULL_TREE;
    4181              :     }
    4182              : 
    4183              :   /* Use a label already defined or ref'd with this name, but not if
    4184              :      it is inherited from a containing function and wasn't declared
    4185              :      using __label__.  */
    4186        85360 :   label = I_LABEL_DECL (name);
    4187        79420 :   if (label && (DECL_CONTEXT (label) == current_function_decl
    4188          608 :                 || C_DECLARED_LABEL_FLAG (label)))
    4189              :     {
    4190              :       /* If the label has only been declared, update its apparent
    4191              :          location to point here, for better diagnostics if it
    4192              :          turns out not to have been defined.  */
    4193        79413 :       if (DECL_INITIAL (label) == NULL_TREE)
    4194        62680 :         DECL_SOURCE_LOCATION (label) = input_location;
    4195        79413 :       return label;
    4196              :     }
    4197              : 
    4198              :   /* No label binding for that identifier; make one.  */
    4199         5947 :   label = make_label (input_location, name, false, &label_vars);
    4200              : 
    4201              :   /* Ordinary labels go in the current function scope.  */
    4202         5947 :   bind_label (name, label, current_function_scope, label_vars);
    4203              : 
    4204         5947 :   return label;
    4205              : }
    4206              : 
    4207              : /* Issue a warning about DECL for a goto statement at GOTO_LOC going
    4208              :    to LABEL.  */
    4209              : 
    4210              : static void
    4211         1482 : warn_about_goto (location_t goto_loc, tree label, tree decl)
    4212              : {
    4213         1482 :   auto_diagnostic_group d;
    4214         1482 :   if (c_type_variably_modified_p (TREE_TYPE (decl)))
    4215         1476 :     error_at (goto_loc,
    4216              :               "jump into scope of identifier with variably modified type");
    4217            6 :   else if (flag_openmp
    4218            6 :            && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (decl)))
    4219            2 :     error_at (goto_loc, "jump skips OpenMP %<allocate%> allocation");
    4220              :   else
    4221            4 :     if (!warning_at (goto_loc, OPT_Wjump_misses_init,
    4222              :                      "jump skips variable initialization"))
    4223            0 :       return;
    4224         1482 :   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4225         1482 :   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
    4226         1482 : }
    4227              : 
    4228              : /* Look up a label because of a goto statement.  This is like
    4229              :    lookup_label, but also issues any appropriate warnings.  */
    4230              : 
    4231              : tree
    4232        83530 : lookup_label_for_goto (location_t loc, tree name)
    4233              : {
    4234        83530 :   tree label;
    4235        83530 :   struct c_label_vars *label_vars;
    4236        83530 :   unsigned int ix;
    4237        83530 :   tree decl;
    4238              : 
    4239        83530 :   label = lookup_label (name);
    4240        83530 :   if (label == NULL_TREE)
    4241              :     return NULL_TREE;
    4242              : 
    4243              :   /* If we are jumping to a different function, we can't issue any
    4244              :      useful warnings.  */
    4245        83530 :   if (DECL_CONTEXT (label) != current_function_decl)
    4246              :     {
    4247          522 :       gcc_assert (C_DECLARED_LABEL_FLAG (label));
    4248              :       return label;
    4249              :     }
    4250              : 
    4251        83008 :   label_vars = I_LABEL_BINDING (name)->u.label;
    4252              : 
    4253              :   /* If the label has not yet been defined, then push this goto on a
    4254              :      list for possible later warnings.  */
    4255        83008 :   if (label_vars->label_bindings.scope == NULL)
    4256              :     {
    4257        66500 :       c_goto_bindings *g = ggc_alloc<c_goto_bindings> ();
    4258              : 
    4259        66500 :       g->loc = loc;
    4260        66500 :       set_spot_bindings (&g->goto_bindings, true);
    4261        66500 :       vec_safe_push (label_vars->gotos, g);
    4262        66500 :       return label;
    4263              :     }
    4264              : 
    4265              :   /* If there are any decls in label_vars->decls_in_scope, then this
    4266              :      goto has missed the declaration of the decl.  This happens for a
    4267              :      case like
    4268              :        int i = 1;
    4269              :       lab:
    4270              :        ...
    4271              :        goto lab;
    4272              :      Issue a warning or error.  */
    4273        17283 :   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
    4274          775 :     warn_about_goto (loc, label, decl);
    4275              : 
    4276        16508 :   if (label_vars->label_bindings.left_stmt_expr)
    4277              :     {
    4278          120 :       auto_diagnostic_group d;
    4279          120 :       error_at (loc, "jump into statement expression");
    4280          120 :       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
    4281          120 :     }
    4282              : 
    4283              :   return label;
    4284              : }
    4285              : 
    4286              : /* Make a label named NAME in the current function, shadowing silently
    4287              :    any that may be inherited from containing functions or containing
    4288              :    scopes.  This is called for __label__ declarations.  */
    4289              : 
    4290              : tree
    4291         1192 : declare_label (tree name)
    4292              : {
    4293         1192 :   struct c_binding *b = I_LABEL_BINDING (name);
    4294         1192 :   tree label;
    4295         1192 :   struct c_label_vars *label_vars;
    4296              : 
    4297              :   /* Check to make sure that the label hasn't already been declared
    4298              :      at this scope */
    4299         1192 :   if (b && B_IN_CURRENT_SCOPE (b))
    4300              :     {
    4301            2 :       auto_diagnostic_group d;
    4302            2 :       error ("duplicate label declaration %qE", name);
    4303            2 :       locate_old_decl (b->decl);
    4304              : 
    4305              :       /* Just use the previous declaration.  */
    4306            2 :       return b->decl;
    4307            2 :     }
    4308              : 
    4309         1190 :   label = make_label (input_location, name, false, &label_vars);
    4310         1190 :   C_DECLARED_LABEL_FLAG (label) = 1;
    4311              : 
    4312              :   /* Declared labels go in the current scope.  */
    4313         1190 :   bind_label (name, label, current_scope, label_vars);
    4314              : 
    4315         1190 :   return label;
    4316              : }
    4317              : 
    4318              : /* When we define a label, issue any appropriate warnings if there are
    4319              :    any gotos earlier in the function which jump to this label.  */
    4320              : 
    4321              : static void
    4322         7057 : check_earlier_gotos (tree label, struct c_label_vars* label_vars)
    4323              : {
    4324         7057 :   unsigned int ix;
    4325         7057 :   struct c_goto_bindings *g;
    4326              : 
    4327        73491 :   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
    4328              :     {
    4329        66434 :       struct c_binding *b;
    4330        66434 :       struct c_scope *scope;
    4331              : 
    4332              :       /* We have a goto to this label.  The goto is going forward.  In
    4333              :          g->scope, the goto is going to skip any binding which was
    4334              :          defined after g->bindings_in_scope.  */
    4335        66434 :       if (g->goto_bindings.scope->has_jump_unsafe_decl)
    4336              :         {
    4337          251 :           for (b = g->goto_bindings.scope->bindings;
    4338          581 :                b != g->goto_bindings.bindings_in_scope;
    4339          330 :                b = b->prev)
    4340              :             {
    4341          330 :               if (decl_jump_unsafe (b->decl))
    4342          168 :                 warn_about_goto (g->loc, label, b->decl);
    4343              :             }
    4344              :         }
    4345              : 
    4346              :       /* We also need to warn about decls defined in any scopes
    4347              :          between the scope of the label and the scope of the goto.  */
    4348        66434 :       for (scope = label_vars->label_bindings.scope;
    4349        69128 :            scope != g->goto_bindings.scope;
    4350         2694 :            scope = scope->outer)
    4351              :         {
    4352         2694 :           gcc_assert (scope != NULL);
    4353         2694 :           if (scope->has_jump_unsafe_decl)
    4354              :             {
    4355          325 :               if (scope == label_vars->label_bindings.scope)
    4356          249 :                 b = label_vars->label_bindings.bindings_in_scope;
    4357              :               else
    4358           76 :                 b = scope->bindings;
    4359          864 :               for (; b != NULL; b = b->prev)
    4360              :                 {
    4361          539 :                   if (decl_jump_unsafe (b->decl))
    4362          539 :                     warn_about_goto (g->loc, label, b->decl);
    4363              :                 }
    4364              :             }
    4365              :         }
    4366              : 
    4367        66434 :       if (g->goto_bindings.stmt_exprs > 0)
    4368              :         {
    4369          100 :           auto_diagnostic_group d;
    4370          100 :           error_at (g->loc, "jump into statement expression");
    4371          100 :           inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
    4372              :                   label);
    4373          100 :         }
    4374              :     }
    4375              : 
    4376              :   /* Now that the label is defined, we will issue warnings about
    4377              :      subsequent gotos to this label when we see them.  */
    4378         7057 :   vec_safe_truncate (label_vars->gotos, 0);
    4379         7057 :   label_vars->gotos = NULL;
    4380         7057 : }
    4381              : 
    4382              : /* Define a label, specifying the location in the source file.
    4383              :    Return the LABEL_DECL node for the label, if the definition is valid.
    4384              :    Otherwise return NULL_TREE.  */
    4385              : 
    4386              : tree
    4387        23869 : define_label (location_t location, tree name)
    4388              : {
    4389              :   /* Find any preexisting label with this name.  It is an error
    4390              :      if that label has already been defined in this function, or
    4391              :      if there is a containing function with a declared label with
    4392              :      the same name.  */
    4393        23869 :   tree label = I_LABEL_DECL (name);
    4394              : 
    4395         7093 :   if (label
    4396         7093 :       && ((DECL_CONTEXT (label) == current_function_decl
    4397         7079 :            && DECL_INITIAL (label) != NULL_TREE)
    4398         7071 :           || (DECL_CONTEXT (label) != current_function_decl
    4399           14 :               && C_DECLARED_LABEL_FLAG (label))))
    4400              :     {
    4401           29 :       auto_diagnostic_group d;
    4402           29 :       error_at (location, "duplicate label %qD", label);
    4403           29 :       locate_old_decl (label);
    4404           29 :       return NULL_TREE;
    4405           29 :     }
    4406        23840 :   else if (label && DECL_CONTEXT (label) == current_function_decl)
    4407              :     {
    4408         7057 :       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
    4409              : 
    4410              :       /* The label has been used or declared already in this function,
    4411              :          but not defined.  Update its location to point to this
    4412              :          definition.  */
    4413         7057 :       DECL_SOURCE_LOCATION (label) = location;
    4414         7057 :       set_spot_bindings (&label_vars->label_bindings, true);
    4415              : 
    4416              :       /* Issue warnings as required about any goto statements from
    4417              :          earlier in the function.  */
    4418         7057 :       check_earlier_gotos (label, label_vars);
    4419              :     }
    4420              :   else
    4421              :     {
    4422        16783 :       struct c_label_vars *label_vars;
    4423              : 
    4424              :       /* No label binding for that identifier; make one.  */
    4425        16783 :       label = make_label (location, name, true, &label_vars);
    4426              : 
    4427              :       /* Ordinary labels go in the current function scope.  */
    4428        16783 :       bind_label (name, label, current_function_scope, label_vars);
    4429              :     }
    4430              : 
    4431        23840 :   if (!in_system_header_at (input_location) && lookup_name (name))
    4432          139 :     warning_at (location, OPT_Wtraditional,
    4433              :                 "traditional C lacks a separate namespace "
    4434              :                 "for labels, identifier %qE conflicts", name);
    4435              : 
    4436              :   /* Mark label as having been defined.  */
    4437        23840 :   DECL_INITIAL (label) = error_mark_node;
    4438        23840 :   return label;
    4439              : }
    4440              : 
    4441              : /* Get the bindings for a new switch statement.  This is used to issue
    4442              :    warnings as appropriate for jumps from the switch to case or
    4443              :    default labels.  */
    4444              : 
    4445              : struct c_spot_bindings *
    4446        37243 : c_get_switch_bindings (void)
    4447              : {
    4448        37243 :   struct c_spot_bindings *switch_bindings;
    4449              : 
    4450        37243 :   switch_bindings = XNEW (struct c_spot_bindings);
    4451        37243 :   set_spot_bindings (switch_bindings, true);
    4452        37243 :   return switch_bindings;
    4453              : }
    4454              : 
    4455              : void
    4456        37243 : c_release_switch_bindings (struct c_spot_bindings *bindings)
    4457              : {
    4458        37243 :   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
    4459        37243 :   XDELETE (bindings);
    4460        37243 : }
    4461              : 
    4462              : /* This is called at the point of a case or default label to issue
    4463              :    warnings about decls as needed.  It returns true if it found an
    4464              :    error, not just a warning.  */
    4465              : 
    4466              : bool
    4467      1029802 : c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
    4468              :                               location_t switch_loc, location_t case_loc)
    4469              : {
    4470      1029802 :   bool saw_error;
    4471      1029802 :   struct c_scope *scope;
    4472              : 
    4473      1029802 :   saw_error = false;
    4474      1029802 :   for (scope = current_scope;
    4475      3089434 :        scope != switch_bindings->scope;
    4476      2059632 :        scope = scope->outer)
    4477              :     {
    4478      2059632 :       struct c_binding *b;
    4479              : 
    4480      2059632 :       gcc_assert (scope != NULL);
    4481              : 
    4482      2059632 :       if (!scope->has_jump_unsafe_decl)
    4483      2059621 :         continue;
    4484              : 
    4485           22 :       for (b = scope->bindings; b != NULL; b = b->prev)
    4486              :         {
    4487           11 :           if (decl_jump_unsafe (b->decl))
    4488              :             {
    4489           11 :               auto_diagnostic_group d;
    4490           11 :               bool emitted;
    4491           11 :               if (c_type_variably_modified_p (TREE_TYPE (b->decl)))
    4492              :                 {
    4493            6 :                   saw_error = true;
    4494            6 :                   error_at (case_loc,
    4495              :                             "switch jumps into scope of identifier with "
    4496              :                             "variably modified type");
    4497            6 :                   emitted = true;
    4498              :                 }
    4499            5 :               else if (flag_openmp
    4500            7 :                        && lookup_attribute ("omp allocate",
    4501            2 :                                             DECL_ATTRIBUTES (b->decl)))
    4502              :                 {
    4503            2 :                   saw_error = true;
    4504            2 :                   error_at (case_loc,
    4505              :                             "switch jumps over OpenMP %<allocate%> allocation");
    4506            2 :                   emitted = true;
    4507              :                 }
    4508              :               else
    4509            3 :                 emitted
    4510            3 :                   = warning_at (case_loc, OPT_Wjump_misses_init,
    4511              :                                 "switch jumps over variable initialization");
    4512           11 :               if (emitted)
    4513              :                 {
    4514           11 :                   inform (switch_loc, "switch starts here");
    4515           11 :                   inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
    4516              :                           b->decl);
    4517              :                 }
    4518           11 :             }
    4519              :         }
    4520              :     }
    4521              : 
    4522      1029802 :   if (switch_bindings->stmt_exprs > 0)
    4523              :     {
    4524            4 :       saw_error = true;
    4525            4 :       auto_diagnostic_group d;
    4526            4 :       error_at (case_loc, "switch jumps into statement expression");
    4527            4 :       inform (switch_loc, "switch starts here");
    4528            4 :     }
    4529              : 
    4530      1029802 :   return saw_error;
    4531              : }
    4532              : 
    4533              : /* Given NAME, an IDENTIFIER_NODE,
    4534              :    return the structure (or union or enum) definition for that name.
    4535              :    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
    4536              :    CODE says which kind of type the caller wants;
    4537              :    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
    4538              :    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
    4539              :    location where the tag was defined.
    4540              :    If the wrong kind of type is found, an error is reported.  */
    4541              : 
    4542              : static tree
    4543      2080287 : lookup_tag (enum tree_code code, tree name, bool thislevel_only,
    4544              :             location_t *ploc)
    4545              : {
    4546      2080287 :   struct c_binding *b = I_TAG_BINDING (name);
    4547      2080287 :   bool thislevel = false;
    4548              : 
    4549      2080287 :   if (!b || !b->decl)
    4550              :     return NULL_TREE;
    4551              : 
    4552              :   /* We only care about whether it's in this level if
    4553              :      thislevel_only was set or it might be a type clash.  */
    4554      1455310 :   if (thislevel_only || TREE_CODE (b->decl) != code)
    4555              :     {
    4556              :       /* For our purposes, a tag in the external scope is the same as
    4557              :          a tag in the file scope.  (Primarily relevant to Objective-C
    4558              :          and its builtin structure tags, which get pushed before the
    4559              :          file scope is created.)  */
    4560       467029 :       if (B_IN_CURRENT_SCOPE (b)
    4561          179 :           || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    4562      1455310 :         thislevel = true;
    4563              :     }
    4564              : 
    4565      1455310 :   if (thislevel_only && !thislevel)
    4566              :     return NULL_TREE;
    4567              : 
    4568      1455152 :   if (TREE_CODE (b->decl) != code)
    4569              :     {
    4570              :       /* Definition isn't the kind we were looking for.  */
    4571           39 :       pending_invalid_xref = name;
    4572           39 :       pending_invalid_xref_location = input_location;
    4573              : 
    4574              :       /* If in the same binding level as a declaration as a tag
    4575              :          of a different type, this must not be allowed to
    4576              :          shadow that tag, so give the error immediately.
    4577              :          (For example, "struct foo; union foo;" is invalid.)  */
    4578           39 :       if (thislevel)
    4579           18 :         pending_xref_error ();
    4580              :     }
    4581              : 
    4582      1455152 :   if (ploc != NULL)
    4583      1013734 :     *ploc = b->locus;
    4584              : 
    4585      1455152 :   return b->decl;
    4586              : }
    4587              : 
    4588              : /* Return true if a definition exists for NAME with code CODE.  */
    4589              : 
    4590              : bool
    4591          384 : tag_exists_p (enum tree_code code, tree name)
    4592              : {
    4593          384 :   struct c_binding *b = I_TAG_BINDING (name);
    4594              : 
    4595          384 :   if (b == NULL || b->decl == NULL_TREE)
    4596              :     return false;
    4597           18 :   return TREE_CODE (b->decl) == code;
    4598              : }
    4599              : 
    4600              : /* Print an error message now
    4601              :    for a recent invalid struct, union or enum cross reference.
    4602              :    We don't print them immediately because they are not invalid
    4603              :    when used in the `struct foo;' construct for shadowing.  */
    4604              : 
    4605              : void
    4606    313174797 : pending_xref_error (void)
    4607              : {
    4608    313174797 :   if (pending_invalid_xref != NULL_TREE)
    4609           27 :     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
    4610              :               pending_invalid_xref);
    4611    313174797 :   pending_invalid_xref = NULL_TREE;
    4612    313174797 : }
    4613              : 
    4614              : 
    4615              : /* Look up NAME in the current scope and its superiors
    4616              :    in the namespace of variables, functions and typedefs.
    4617              :    Return a ..._DECL node of some kind representing its definition,
    4618              :    or return NULL_TREE if it is undefined.  */
    4619              : 
    4620              : tree
    4621   1265371484 : lookup_name (tree name)
    4622              : {
    4623   1265371484 :   struct c_binding *b = I_SYMBOL_BINDING (name);
    4624              :   /* Do not resolve non-default function versions.  */
    4625   1265371484 :   if (b
    4626    855414038 :       && TREE_CODE (b->decl) == FUNCTION_DECL
    4627    117007669 :       && DECL_FUNCTION_VERSIONED (b->decl)
    4628   1265371484 :       && !is_function_default_version (b->decl))
    4629              :     return NULL_TREE;
    4630   1265371484 :   if (b && !b->invisible)
    4631              :     {
    4632    844624476 :       maybe_record_typedef_use (b->decl);
    4633    844624476 :       return b->decl;
    4634              :     }
    4635              :   return NULL_TREE;
    4636              : }
    4637              : 
    4638              : /* Similar to `lookup_name' but look only at the indicated scope.  */
    4639              : 
    4640              : static tree
    4641    131055580 : lookup_name_in_scope (tree name, struct c_scope *scope)
    4642              : {
    4643    131055580 :   struct c_binding *b;
    4644              : 
    4645    131058807 :   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
    4646      7408746 :     if (B_IN_SCOPE (b, scope))
    4647      7405519 :       return b->decl;
    4648              :   return NULL_TREE;
    4649              : }
    4650              : 
    4651              : /* Look for the closest match for NAME within the currently valid
    4652              :    scopes.
    4653              : 
    4654              :    This finds the identifier with the lowest Levenshtein distance to
    4655              :    NAME.  If there are multiple candidates with equal minimal distance,
    4656              :    the first one found is returned.  Scopes are searched from innermost
    4657              :    outwards, and within a scope in reverse order of declaration, thus
    4658              :    benefiting candidates "near" to the current scope.
    4659              : 
    4660              :    The function also looks for similar macro names to NAME, since a
    4661              :    misspelled macro name will not be expanded, and hence looks like an
    4662              :    identifier to the C frontend.
    4663              : 
    4664              :    It also looks for start_typename keywords, to detect "singed" vs "signed"
    4665              :    typos.
    4666              : 
    4667              :    Use LOC for any deferred diagnostics.  */
    4668              : 
    4669              : name_hint
    4670         2062 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    4671              : {
    4672         2062 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    4673              : 
    4674              :   /* Look up function-like macros first; maybe misusing them. */
    4675         4124 :   auto cpp_node = cpp_lookup (parse_in,
    4676         2062 :                               (const unsigned char*)IDENTIFIER_POINTER (name),
    4677         2062 :                               IDENTIFIER_LENGTH (name));
    4678         2062 :   if (cpp_node && cpp_fun_like_macro_p (cpp_node))
    4679            5 :     return name_hint
    4680              :       (nullptr,
    4681            5 :        std::make_unique<macro_like_function_used> (loc,
    4682           10 :                                                    IDENTIFIER_POINTER (name)));
    4683              : 
    4684              :   /* Next, try some well-known names in the C standard library, in case
    4685              :      the user forgot a #include.  */
    4686         2057 :   const char *header_hint
    4687         2057 :     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    4688              : 
    4689         2057 :   if (header_hint)
    4690           56 :     return name_hint
    4691              :       (nullptr,
    4692           56 :        std::make_unique<suggest_missing_header> (loc,
    4693          112 :                                                  IDENTIFIER_POINTER (name),
    4694           56 :                                                  header_hint));
    4695              : 
    4696              :   /* Next, look for exact matches for builtin defines that would have been
    4697              :      defined if the user had passed a command-line option (e.g. -fopenmp
    4698              :      for "_OPENMP").  */
    4699         2001 :   diagnostics::option_id option_id
    4700         2001 :     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
    4701         2001 :   if (option_id.m_idx > 0)
    4702            2 :     return name_hint
    4703              :       (nullptr,
    4704            2 :        std::make_unique<suggest_missing_option> (loc,
    4705            4 :                                                  IDENTIFIER_POINTER (name),
    4706            2 :                                                  option_id));
    4707              : 
    4708              :   /* Only suggest names reserved for the implementation if NAME begins
    4709              :      with an underscore.  */
    4710         1999 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    4711              : 
    4712         1999 :   best_match<tree, tree> bm (name);
    4713              : 
    4714              :   /* Look within currently valid scopes.  */
    4715         9097 :   for (c_scope *scope = current_scope; scope; scope = scope->outer)
    4716     11346600 :     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
    4717              :       {
    4718     11339502 :         if (!binding->id || binding->invisible)
    4719      6410468 :           continue;
    4720      4929034 :         if (binding->decl == error_mark_node)
    4721          374 :           continue;
    4722              :         /* Don't use bindings from implicitly declared functions,
    4723              :            as they were likely misspellings themselves.  */
    4724      4928660 :         if (TREE_CODE (binding->decl) == FUNCTION_DECL)
    4725      4524823 :           if (C_DECL_IMPLICIT (binding->decl))
    4726          229 :             continue;
    4727              :         /* Don't suggest names that are reserved for use by the
    4728              :            implementation, unless NAME began with an underscore.  */
    4729      4928431 :         if (!consider_implementation_names)
    4730              :           {
    4731      2338547 :             const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
    4732      2338547 :             if (name_reserved_for_implementation_p (suggestion_str))
    4733      2280147 :               continue;
    4734              :           }
    4735      2648284 :         switch (kind)
    4736              :           {
    4737        24317 :           case FUZZY_LOOKUP_TYPENAME:
    4738        24317 :             if (TREE_CODE (binding->decl) != TYPE_DECL)
    4739        17012 :               continue;
    4740              :             break;
    4741              : 
    4742       128923 :           case FUZZY_LOOKUP_FUNCTION_NAME:
    4743       128923 :             if (TREE_CODE (binding->decl) != FUNCTION_DECL)
    4744              :               {
    4745              :                 /* Allow function pointers.  */
    4746        26502 :                 if ((VAR_P (binding->decl)
    4747        21977 :                      || TREE_CODE (binding->decl) == PARM_DECL)
    4748         5400 :                     && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
    4749        27782 :                     && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
    4750              :                         == FUNCTION_TYPE))
    4751              :                   break;
    4752        26483 :                 continue;
    4753              :               }
    4754              :             break;
    4755              : 
    4756              :           default:
    4757              :             break;
    4758              :           }
    4759      2604789 :         bm.consider (binding->id);
    4760              :       }
    4761              : 
    4762              :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    4763              :      as:
    4764              :        x = SOME_OTHER_MACRO (y);
    4765              :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    4766              :      as a misspelled identifier.
    4767              : 
    4768              :      Use the best distance so far so that a candidate is only set if
    4769              :      a macro is better than anything so far.  This allows early rejection
    4770              :      (without calculating the edit distance) of macro names that must have
    4771              :      distance >= bm.get_best_distance (), and means that we only get a
    4772              :      non-NULL result for best_macro_match if it's better than any of
    4773              :      the identifiers already checked, which avoids needless creation
    4774              :      of identifiers for macro hashnodes.  */
    4775         1999 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    4776         1999 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    4777              :   /* If a macro is the closest so far to NAME, use it, creating an
    4778              :      identifier tree node for it.  */
    4779         1999 :   if (best_macro)
    4780              :     {
    4781           11 :       const char *id = (const char *)best_macro->ident.str;
    4782           11 :       tree macro_as_identifier
    4783           11 :         = get_identifier_with_length (id, best_macro->ident.len);
    4784           11 :       bm.set_best_so_far (macro_as_identifier,
    4785              :                           bmm.get_best_distance (),
    4786              :                           bmm.get_best_candidate_length ());
    4787              :     }
    4788              : 
    4789              :   /* Try the "start_typename" keywords to detect
    4790              :      "singed" vs "signed" typos.  */
    4791         1999 :   if (kind == FUZZY_LOOKUP_TYPENAME)
    4792              :     {
    4793        55687 :       for (unsigned i = 0; i < num_c_common_reswords; i++)
    4794              :         {
    4795        55448 :           const c_common_resword *resword = &c_common_reswords[i];
    4796        55448 :           if (!c_keyword_starts_typename (resword->rid))
    4797        42303 :             continue;
    4798        13145 :           tree resword_identifier = ridpointers [resword->rid];
    4799        13145 :           if (!resword_identifier)
    4800           30 :             continue;
    4801        13115 :           gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    4802        13115 :           bm.consider (resword_identifier);
    4803              :         }
    4804              :     }
    4805              : 
    4806         1999 :   tree best = bm.get_best_meaningful_candidate ();
    4807         1999 :   if (best)
    4808          278 :     return name_hint (IDENTIFIER_POINTER (best), NULL);
    4809              :   else
    4810         1721 :     return name_hint (NULL, NULL);
    4811              : }
    4812              : 
    4813              : 
    4814              : /* Handle the standard [[nodiscard]] attribute.  */
    4815              : 
    4816              : static tree
    4817           34 : handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
    4818              :                             int /*flags*/, bool *no_add_attrs)
    4819              : {
    4820           34 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4821              :     {
    4822           18 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
    4823            1 :         warning_at (DECL_SOURCE_LOCATION (*node),
    4824            1 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    4825              :                     "return type", name, *node);
    4826              :     }
    4827           16 :   else if (RECORD_OR_UNION_TYPE_P (*node)
    4828           12 :            || TREE_CODE (*node) == ENUMERAL_TYPE)
    4829              :     /* OK */;
    4830              :   else
    4831              :     {
    4832           10 :       pedwarn (input_location,
    4833           10 :                OPT_Wattributes, "%qE attribute can only be applied to "
    4834              :                "functions or to structure, union or enumeration types", name);
    4835           10 :       *no_add_attrs = true;
    4836              :     }
    4837           34 :   return NULL_TREE;
    4838              : }
    4839              : 
    4840              : /* Handle the standard [[noreturn]] attribute.  */
    4841              : 
    4842              : static tree
    4843           44 : handle_std_noreturn_attribute (tree *node, tree name, tree args,
    4844              :                                int flags, bool *no_add_attrs)
    4845              : {
    4846              :   /* Unlike GNU __attribute__ ((noreturn)), the standard [[noreturn]]
    4847              :      only applies to functions, not function pointers.  */
    4848           44 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    4849           22 :     return handle_noreturn_attribute (node, name, args, flags, no_add_attrs);
    4850              :   else
    4851              :     {
    4852           22 :       pedwarn (input_location, OPT_Wattributes,
    4853              :                "standard %qE attribute can only be applied to functions",
    4854              :                name);
    4855           22 :       *no_add_attrs = true;
    4856           22 :       return NULL_TREE;
    4857              :     }
    4858              : }
    4859              : 
    4860              : /* Handle the standard [[unsequenced]] attribute.  */
    4861              : 
    4862              : static tree
    4863           68 : handle_std_unsequenced_attribute (tree *node, tree name, tree args,
    4864              :                                   int flags, bool *no_add_attrs)
    4865              : {
    4866              :   /* Unlike GNU __attribute__ ((unsequenced)), the standard [[unsequenced]]
    4867              :      should be only applied to function declarators or type specifiers which
    4868              :      have function type.  */
    4869           68 :   if (node[2])
    4870              :     {
    4871            8 :       auto_diagnostic_group d;
    4872            8 :       if (pedwarn (input_location, OPT_Wattributes,
    4873              :                    "standard %qE attribute can only be applied to function "
    4874              :                    "declarators or type specifiers with function type", name))
    4875            8 :         inform (input_location, "did you mean to specify it after %<)%> "
    4876              :                                 "following function parameters?");
    4877            8 :       *no_add_attrs = true;
    4878            8 :       return NULL_TREE;
    4879            8 :     }
    4880           60 :   return handle_unsequenced_attribute (node, name, args, flags, no_add_attrs);
    4881              : }
    4882              : 
    4883              : /* Handle the standard [[reproducible]] attribute.  */
    4884              : 
    4885              : static tree
    4886           34 : handle_std_reproducible_attribute (tree *node, tree name, tree args,
    4887              :                                    int flags, bool *no_add_attrs)
    4888              : {
    4889           34 :   return handle_std_unsequenced_attribute (node, name, args, flags,
    4890           34 :                                            no_add_attrs);
    4891              : }
    4892              : 
    4893              : /* Table of supported standard (C23) attributes.  */
    4894              : static const attribute_spec std_attributes[] =
    4895              : {
    4896              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    4897              :        affects_type_identity, handler, exclude } */
    4898              :   { "_Noreturn", 0, 0, false, false, false, false,
    4899              :     handle_std_noreturn_attribute, NULL },
    4900              :   { "deprecated", 0, 1, false, false, false, false,
    4901              :     handle_deprecated_attribute, NULL },
    4902              :   { "fallthrough", 0, 0, false, false, false, false,
    4903              :     handle_fallthrough_attribute, NULL },
    4904              :   { "maybe_unused", 0, 0, false, false, false, false,
    4905              :     handle_unused_attribute, NULL },
    4906              :   { "nodiscard", 0, 1, false, false, false, false,
    4907              :     handle_nodiscard_attribute, NULL },
    4908              :   { "noreturn", 0, 0, false, false, false, false,
    4909              :     handle_std_noreturn_attribute, NULL },
    4910              :   { "reproducible", 0, 0, false, true, true, false,
    4911              :     handle_std_reproducible_attribute, NULL },
    4912              :   { "unsequenced", 0, 0, false, true, true, false,
    4913              :     handle_std_unsequenced_attribute, NULL }
    4914              : };
    4915              : 
    4916              : const scoped_attribute_specs std_attribute_table =
    4917              : {
    4918              :   nullptr, { std_attributes }
    4919              : };
    4920              : 
    4921              : /* Create the predefined scalar types of C,
    4922              :    and some nodes representing standard constants (0, 1, (void *) 0).
    4923              :    Initialize the global scope.
    4924              :    Make definitions for built-in primitive functions.  */
    4925              : 
    4926              : void
    4927       110763 : c_init_decl_processing (void)
    4928              : {
    4929       110763 :   location_t save_loc = input_location;
    4930              : 
    4931              :   /* Initialize reserved words for parser.  */
    4932       110763 :   c_parse_init ();
    4933              : 
    4934       110763 :   current_function_decl = NULL_TREE;
    4935              : 
    4936       110763 :   gcc_obstack_init (&parser_obstack);
    4937              : 
    4938              :   /* Make the externals scope.  */
    4939       110763 :   push_scope ();
    4940       110763 :   external_scope = current_scope;
    4941              : 
    4942              :   /* Declarations from c_common_nodes_and_builtins must not be associated
    4943              :      with this input file, lest we get differences between using and not
    4944              :      using preprocessed headers.  */
    4945       110763 :   input_location = BUILTINS_LOCATION;
    4946              : 
    4947       110763 :   c_common_nodes_and_builtins ();
    4948              : 
    4949              :   /* In C, comparisons and TRUTH_* expressions have type int.  */
    4950       110763 :   truthvalue_type_node = integer_type_node;
    4951       110763 :   truthvalue_true_node = integer_one_node;
    4952       110763 :   truthvalue_false_node = integer_zero_node;
    4953              : 
    4954              :   /* Even in C99, which has a real boolean type.  */
    4955       110763 :   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
    4956              :                         boolean_type_node));
    4957              : 
    4958              :   /* C-specific nullptr initialization.  */
    4959       110763 :   record_builtin_type (RID_MAX, "typeof (nullptr)", nullptr_type_node);
    4960              :   /* The size and alignment of nullptr_t is the same as for a pointer to
    4961              :      character type.  */
    4962       110763 :   SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4963              : 
    4964       110763 :   input_location = save_loc;
    4965              : 
    4966       110763 :   make_fname_decl = c_make_fname_decl;
    4967       110763 :   start_fname_decls ();
    4968              : 
    4969       110763 :   if (warn_keyword_macro)
    4970              :     {
    4971         1165 :       for (unsigned int i = 0; i < num_c_common_reswords; ++i)
    4972              :         /* For C register keywords which don't start with underscore
    4973              :            or start with just single underscore.  Don't complain about
    4974              :            ObjC or Transactional Memory keywords.  */
    4975         1160 :         if (c_common_reswords[i].word[0] == '_'
    4976          530 :             && c_common_reswords[i].word[1] == '_')
    4977          390 :           continue;
    4978          995 :         else if (c_common_reswords[i].disable
    4979          770 :                  & (D_TRANSMEM | D_OBJC | D_CXX_OBJC))
    4980          225 :           continue;
    4981              :         else
    4982              :           {
    4983          545 :             tree id = get_identifier (c_common_reswords[i].word);
    4984          545 :             if (C_IS_RESERVED_WORD (id)
    4985          545 :                 && C_RID_CODE (id) != RID_CXX_COMPAT_WARN)
    4986          332 :               cpp_warn (parse_in, IDENTIFIER_POINTER (id),
    4987          332 :                         IDENTIFIER_LENGTH (id));
    4988              :           }
    4989              :     }
    4990       110763 : }
    4991              : 
    4992              : /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
    4993              :    give the decl, NAME is the initialization string and TYPE_DEP
    4994              :    indicates whether NAME depended on the type of the function.  As we
    4995              :    don't yet implement delayed emission of static data, we mark the
    4996              :    decl as emitted so it is not placed in the output.  Anything using
    4997              :    it must therefore pull out the STRING_CST initializer directly.
    4998              :    FIXME.  */
    4999              : 
    5000              : static tree
    5001         2929 : c_make_fname_decl (location_t loc, tree id, int type_dep)
    5002              : {
    5003         2929 :   const char *name = fname_as_string (type_dep);
    5004         2929 :   tree decl, type, init;
    5005         2929 :   size_t length = strlen (name);
    5006              : 
    5007         2929 :   type = c_build_array_type (char_type_node,
    5008         2929 :                              build_index_type (size_int (length)));
    5009         2929 :   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
    5010              : 
    5011         2929 :   decl = build_decl (loc, VAR_DECL, id, type);
    5012              : 
    5013         2929 :   TREE_STATIC (decl) = 1;
    5014         2929 :   TREE_READONLY (decl) = 1;
    5015         2929 :   DECL_ARTIFICIAL (decl) = 1;
    5016              : 
    5017         2929 :   init = build_string (length + 1, name);
    5018         2929 :   free (const_cast<char *> (name));
    5019         2929 :   TREE_TYPE (init) = type;
    5020         2929 :   DECL_INITIAL (decl) = init;
    5021              : 
    5022         2929 :   TREE_USED (decl) = 1;
    5023              : 
    5024         2929 :   if (current_function_decl
    5025              :       /* For invalid programs like this:
    5026              : 
    5027              :          void foo()
    5028              :          const char* p = __FUNCTION__;
    5029              : 
    5030              :          the __FUNCTION__ is believed to appear in K&R style function
    5031              :          parameter declarator.  In that case we still don't have
    5032              :          function_scope.  */
    5033         2922 :       && current_function_scope)
    5034              :     {
    5035         2914 :       DECL_CONTEXT (decl) = current_function_decl;
    5036         2914 :       bind (id, decl, current_function_scope,
    5037              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
    5038              :     }
    5039              : 
    5040         2929 :   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
    5041              : 
    5042         2929 :   return decl;
    5043              : }
    5044              : 
    5045              : tree
    5046    323475802 : c_builtin_function (tree decl)
    5047              : {
    5048    323475802 :   tree type = TREE_TYPE (decl);
    5049    323475802 :   tree   id = DECL_NAME (decl);
    5050              : 
    5051    323475802 :   const char *name = IDENTIFIER_POINTER (id);
    5052    323475802 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5053              : 
    5054              :   /* Should never be called on a symbol with a preexisting meaning.  */
    5055    323475802 :   gcc_assert (!I_SYMBOL_BINDING (id));
    5056              : 
    5057    323475802 :   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
    5058              :         UNKNOWN_LOCATION);
    5059              : 
    5060              :   /* Builtins in the implementation namespace are made visible without
    5061              :      needing to be explicitly declared.  See push_file_scope.  */
    5062    323475802 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5063              :     {
    5064    220715332 :       DECL_CHAIN (decl) = visible_builtins;
    5065    220715332 :       visible_builtins = decl;
    5066              :     }
    5067              : 
    5068    323475802 :   return decl;
    5069              : }
    5070              : 
    5071              : tree
    5072     10486076 : c_builtin_function_ext_scope (tree decl)
    5073              : {
    5074     10486076 :   tree type = TREE_TYPE (decl);
    5075     10486076 :   tree   id = DECL_NAME (decl);
    5076              : 
    5077     10486076 :   const char *name = IDENTIFIER_POINTER (id);
    5078     10486076 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5079              : 
    5080     10486076 :   if (external_scope)
    5081     10299175 :     bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
    5082              :           UNKNOWN_LOCATION);
    5083              : 
    5084              :   /* Builtins in the implementation namespace are made visible without
    5085              :      needing to be explicitly declared.  See push_file_scope.  */
    5086     10486076 :   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
    5087              :     {
    5088     10486076 :       DECL_CHAIN (decl) = visible_builtins;
    5089     10486076 :       visible_builtins = decl;
    5090              :     }
    5091              : 
    5092     10486076 :   return decl;
    5093              : }
    5094              : 
    5095              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5096              : 
    5097              : tree
    5098            0 : c_simulate_builtin_function_decl (tree decl)
    5099              : {
    5100            0 :   tree type = TREE_TYPE (decl);
    5101            0 :   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
    5102            0 :   return pushdecl (decl);
    5103              : }
    5104              : 
    5105              : /* Warn about attributes in a context where they are unused
    5106              :    (attribute-declarations, except for the "fallthrough" case, and
    5107              :    attributes on statements).  */
    5108              : 
    5109              : void
    5110     41517859 : c_warn_unused_attributes (tree attrs)
    5111              : {
    5112     41517904 :   for (tree t = attrs; t != NULL_TREE; t = TREE_CHAIN (t))
    5113           45 :     if (get_attribute_namespace (t) == NULL_TREE)
    5114              :       /* The specifications of standard attributes mean this is a
    5115              :          constraint violation.  */
    5116           29 :       pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5117              :                get_attribute_name (t));
    5118           16 :     else if (!attribute_ignored_p (t))
    5119           12 :       warning (OPT_Wattributes, "%qE attribute ignored",
    5120              :                get_attribute_name (t));
    5121     41517859 : }
    5122              : 
    5123              : /* Warn for standard attributes being applied to a type that is not
    5124              :    being defined, where that is a constraint violation, and return a
    5125              :    list of attributes with them removed.  */
    5126              : 
    5127              : tree
    5128    435021218 : c_warn_type_attributes (tree type, tree attrs)
    5129              : {
    5130    435021218 :   tree *attr_ptr = &attrs;
    5131    435044432 :   while (*attr_ptr)
    5132        23214 :     if (get_attribute_namespace (*attr_ptr) == NULL_TREE)
    5133              :       {
    5134           89 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    5135              :           {
    5136           65 :             tree name = get_attribute_name (*attr_ptr);
    5137              :             /* [[unsequenced]] and [[reproducible]] is fine on function
    5138              :                types that aren't being defined.  */
    5139           65 :             if (is_attribute_p ("unsequenced", name)
    5140           65 :                 || is_attribute_p ("reproducible", name))
    5141              :               {
    5142           60 :                 attr_ptr = &TREE_CHAIN (*attr_ptr);
    5143           60 :                 continue;
    5144              :               }
    5145              :           }
    5146           29 :         pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    5147              :                  get_attribute_name (*attr_ptr));
    5148           29 :         *attr_ptr = TREE_CHAIN (*attr_ptr);
    5149              :       }
    5150              :     else
    5151        23125 :       attr_ptr = &TREE_CHAIN (*attr_ptr);
    5152    435021218 :   return attrs;
    5153              : }
    5154              : 
    5155              : /* Called when a declaration is seen that contains no names to declare.
    5156              :    If its type is a reference to a structure, union or enum inherited
    5157              :    from a containing scope, shadow that tag name for the current scope
    5158              :    with a forward reference.
    5159              :    If its type defines a new named structure or union
    5160              :    or defines an enum, it is valid but we need not do anything here.
    5161              :    Otherwise, it is an error.  */
    5162              : 
    5163              : void
    5164       501419 : shadow_tag (const struct c_declspecs *declspecs)
    5165              : {
    5166       501419 :   shadow_tag_warned (declspecs, 0);
    5167       501419 : }
    5168              : 
    5169              : /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
    5170              :    but no pedwarn.  */
    5171              : void
    5172       501489 : shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
    5173              : {
    5174       501489 :   bool found_tag = false;
    5175              : 
    5176       501489 :   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
    5177              :     {
    5178       501375 :       tree value = declspecs->type;
    5179       501375 :       enum tree_code code = TREE_CODE (value);
    5180              : 
    5181       501375 :       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
    5182              :         /* Used to test also that TYPE_SIZE (value) != 0.
    5183              :            That caused warning for `struct foo;' at top level in the file.  */
    5184              :         {
    5185       501324 :           tree name = TYPE_NAME (value);
    5186       501324 :           tree t;
    5187              : 
    5188       501324 :           found_tag = true;
    5189              : 
    5190       501324 :           if (declspecs->restrict_p)
    5191              :             {
    5192            2 :               error ("invalid use of %<restrict%>");
    5193            2 :               warned = 1;
    5194              :             }
    5195              : 
    5196       501324 :           if (in_underspecified_init)
    5197              :             {
    5198              :               /* This can only occur with extensions such as statement
    5199              :                  expressions, but is still appropriate as an error to
    5200              :                  avoid types declared in such a context escaping to
    5201              :                  the type of an auto variable.  */
    5202            1 :               error ("%qT declared in underspecified object initializer",
    5203              :                      value);
    5204            1 :               warned = 1;
    5205              :             }
    5206              : 
    5207       501324 :           if (name == NULL_TREE)
    5208              :             {
    5209        59895 :               if (warned != 1 && code != ENUMERAL_TYPE)
    5210              :                 /* Empty unnamed enum OK */
    5211              :                 {
    5212           19 :                   pedwarn (input_location, 0,
    5213              :                            "unnamed struct/union that defines no instances");
    5214           19 :                   warned = 1;
    5215              :                 }
    5216              :             }
    5217       441429 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5218        88071 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5219        26198 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5220        26190 :                    && declspecs->storage_class != csc_none)
    5221              :             {
    5222            2 :               if (warned != 1)
    5223            2 :                 pedwarn (input_location, 0,
    5224              :                          "empty declaration with storage class specifier "
    5225              :                          "does not redeclare tag");
    5226            2 :               warned = 1;
    5227            2 :               pending_xref_error ();
    5228              :             }
    5229       441427 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5230        88069 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5231        26196 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5232        26188 :                    && (declspecs->const_p
    5233        26185 :                        || declspecs->volatile_p
    5234        26185 :                        || declspecs->atomic_p
    5235        26185 :                        || declspecs->restrict_p
    5236        26185 :                        || declspecs->address_space))
    5237              :             {
    5238            3 :               if (warned != 1)
    5239            3 :                 pedwarn (input_location, 0,
    5240              :                          "empty declaration with type qualifier "
    5241              :                           "does not redeclare tag");
    5242            3 :               warned = 1;
    5243            3 :               pending_xref_error ();
    5244              :             }
    5245       441424 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5246        88066 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5247        26193 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5248        26185 :                    && declspecs->alignas_p)
    5249              :             {
    5250            1 :               if (warned != 1)
    5251            1 :                 pedwarn (input_location, 0,
    5252              :                          "empty declaration with %<_Alignas%> "
    5253              :                           "does not redeclare tag");
    5254            1 :               warned = 1;
    5255            1 :               pending_xref_error ();
    5256              :             }
    5257       441423 :           else if (declspecs->typespec_kind != ctsk_tagdef
    5258        88065 :                    && declspecs->typespec_kind != ctsk_tagfirstref
    5259        26192 :                    && declspecs->typespec_kind != ctsk_tagfirstref_attrs
    5260        26184 :                    && code == ENUMERAL_TYPE
    5261           15 :                    && !declspecs->enum_type_specifier_ref_p)
    5262              :             {
    5263            3 :               bool warned_enum = false;
    5264            3 :               if (warned != 1)
    5265            3 :                 warned_enum = pedwarn (input_location, OPT_Wpedantic,
    5266              :                                        "empty declaration of %<enum%> type "
    5267              :                                        "does not redeclare tag");
    5268            3 :               if (warned_enum)
    5269            2 :                 warned = 1;
    5270            3 :               pending_xref_error ();
    5271            3 :             }
    5272              :           else
    5273              :             {
    5274       441420 :               pending_invalid_xref = NULL_TREE;
    5275       441420 :               t = lookup_tag (code, name, true, NULL);
    5276              : 
    5277       441420 :               if (t == NULL_TREE)
    5278              :                 {
    5279            2 :                   t = make_node (code);
    5280            2 :                   if (flag_isoc23 || code == ENUMERAL_TYPE)
    5281            1 :                     SET_TYPE_STRUCTURAL_EQUALITY (t);
    5282            2 :                   pushtag (input_location, name, t);
    5283              :                 }
    5284              :             }
    5285              :         }
    5286              :       else
    5287              :         {
    5288           51 :           if (warned != 1 && !in_system_header_at (input_location))
    5289              :             {
    5290           44 :               pedwarn (input_location, 0,
    5291              :                        "useless type name in empty declaration");
    5292           44 :               warned = 1;
    5293              :             }
    5294              :         }
    5295              :     }
    5296           71 :   else if (warned != 1 && !in_system_header_at (input_location)
    5297          185 :            && declspecs->typedef_p)
    5298              :     {
    5299           11 :       pedwarn (input_location, 0, "useless type name in empty declaration");
    5300           11 :       warned = 1;
    5301              :     }
    5302              : 
    5303       501489 :   pending_invalid_xref = NULL_TREE;
    5304              : 
    5305       501489 :   if (declspecs->inline_p)
    5306              :     {
    5307            5 :       error ("%<inline%> in empty declaration");
    5308            5 :       warned = 1;
    5309              :     }
    5310              : 
    5311       501489 :   if (declspecs->noreturn_p)
    5312              :     {
    5313            2 :       error ("%<_Noreturn%> in empty declaration");
    5314            2 :       warned = 1;
    5315              :     }
    5316              : 
    5317       501489 :   if (declspecs->constexpr_p)
    5318              :     {
    5319            7 :       error ("%<constexpr%> in empty declaration");
    5320            7 :       warned = 1;
    5321              :     }
    5322              : 
    5323       501489 :   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
    5324              :     {
    5325            2 :       error ("%<auto%> in file-scope empty declaration");
    5326            2 :       warned = 1;
    5327              :     }
    5328              : 
    5329       501489 :   if (current_scope == file_scope && declspecs->storage_class == csc_register)
    5330              :     {
    5331            2 :       error ("%<register%> in file-scope empty declaration");
    5332            2 :       warned = 1;
    5333              :     }
    5334              : 
    5335       501489 :   if (declspecs->enum_type_specifier_ref_p && !warned)
    5336              :     {
    5337           39 :       if (declspecs->storage_class != csc_none)
    5338              :         {
    5339            1 :           error ("storage class specifier in empty declaration with %<enum%> "
    5340              :                  "underlying type");
    5341            1 :           warned = 1;
    5342              :         }
    5343           38 :       else if (declspecs->thread_p)
    5344              :         {
    5345            2 :           error ("%qs in empty declaration with %<enum%> underlying type",
    5346            1 :                  declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5347            1 :           warned = 1;
    5348              :         }
    5349           37 :       else if (declspecs->const_p
    5350           36 :                || declspecs->volatile_p
    5351           36 :                || declspecs->atomic_p
    5352           36 :                || declspecs->restrict_p
    5353           36 :                || declspecs->address_space)
    5354              :         {
    5355            1 :           error ("type qualifier in empty declaration with %<enum%> "
    5356              :                  "underlying type");
    5357            1 :           warned = 1;
    5358              :         }
    5359           36 :       else if (declspecs->alignas_p)
    5360              :         {
    5361            1 :           error ("%<alignas%> in empty declaration with %<enum%> "
    5362              :                  "underlying type");
    5363            1 :           warned = 1;
    5364              :         }
    5365              :     }
    5366              : 
    5367       501321 :   if (!warned && !in_system_header_at (input_location)
    5368       619604 :       && declspecs->storage_class != csc_none)
    5369              :     {
    5370           12 :       warning (0, "useless storage class specifier in empty declaration");
    5371           12 :       warned = 2;
    5372              :     }
    5373              : 
    5374       501489 :   if (!warned && !in_system_header_at (input_location) && declspecs->thread_p)
    5375              :     {
    5376            3 :       warning (0, "useless %qs in empty declaration",
    5377            3 :                declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    5378            3 :       warned = 2;
    5379              :     }
    5380              : 
    5381            3 :   if (!warned
    5382       501302 :       && !in_system_header_at (input_location)
    5383       619594 :       && (declspecs->const_p
    5384       118100 :           || declspecs->volatile_p
    5385       118100 :           || declspecs->atomic_p
    5386       118100 :           || declspecs->restrict_p
    5387       118100 :           || declspecs->address_space))
    5388              :     {
    5389            8 :       warning (0, "useless type qualifier in empty declaration");
    5390            8 :       warned = 2;
    5391              :     }
    5392              : 
    5393       501302 :   if (!warned && !in_system_header_at (input_location)
    5394       619581 :       && declspecs->alignas_p)
    5395              :     {
    5396            4 :       warning (0, "useless %<_Alignas%> in empty declaration");
    5397            4 :       warned = 2;
    5398              :     }
    5399              : 
    5400       501489 :   if (found_tag
    5401       501489 :       && warned == 2
    5402           23 :       && (declspecs->typespec_kind == ctsk_tagref_attrs
    5403           23 :           || declspecs->typespec_kind == ctsk_tagfirstref_attrs))
    5404              :     {
    5405              :       /* Standard attributes after the "struct" or "union" keyword are
    5406              :          only permitted when the contents of the type are defined, or
    5407              :          in the form "struct-or-union attribute-specifier-sequence
    5408              :          identifier;".  If the ';' was not present, attributes were
    5409              :          diagnosed in the parser.  Here, ensure that any other useless
    5410              :          elements of the declaration result in a pedwarn, not just a
    5411              :          warning.  Forward declarations of enum types are not part of
    5412              :          standard C, but handle them the same.  */
    5413            2 :       pedwarn (input_location, 0,
    5414              :                "invalid use of attributes in empty declaration");
    5415            2 :       warned = 1;
    5416              :     }
    5417              : 
    5418       501489 :   if (warned != 1)
    5419              :     {
    5420       501315 :       if (declspecs->declspecs_seen_p
    5421       501315 :           && !declspecs->non_std_attrs_seen_p)
    5422              :         /* An attribute declaration (but not a fallthrough attribute
    5423              :            declaration, which was handled separately); warn if there
    5424              :            are any attributes being ignored (but not if the attributes
    5425              :            were empty).  */
    5426           48 :         c_warn_unused_attributes (declspecs->attrs);
    5427       501267 :       else if (!found_tag)
    5428           10 :         pedwarn (input_location, 0, "empty declaration");
    5429              :     }
    5430       501489 : }
    5431              : 
    5432              : 
    5433              : /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
    5434              :    bits.  SPECS represents declaration specifiers that the grammar
    5435              :    only permits to contain type qualifiers and attributes.  */
    5436              : 
    5437              : int
    5438     18212056 : quals_from_declspecs (const struct c_declspecs *specs)
    5439              : {
    5440     18212056 :   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
    5441              :                | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
    5442              :                | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
    5443     18212056 :                | (specs->atomic_p ? TYPE_QUAL_ATOMIC : 0)
    5444     18212056 :                | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
    5445     18212056 :   gcc_assert (!specs->type
    5446              :               && !specs->decl_attr
    5447              :               && specs->typespec_word == cts_none
    5448              :               && specs->storage_class == csc_none
    5449              :               && !specs->typedef_p
    5450              :               && !specs->explicit_signed_p
    5451              :               && !specs->deprecated_p
    5452              :               && !specs->unavailable_p
    5453              :               && !specs->long_p
    5454              :               && !specs->long_long_p
    5455              :               && !specs->short_p
    5456              :               && !specs->signed_p
    5457              :               && !specs->unsigned_p
    5458              :               && !specs->complex_p
    5459              :               && !specs->inline_p
    5460              :               && !specs->noreturn_p
    5461              :               && !specs->thread_p);
    5462     18212056 :   return quals;
    5463              : }
    5464              : 
    5465              : /* Construct an array declarator.  LOC is the location of the
    5466              :    beginning of the array (usually the opening brace).  EXPR is the
    5467              :    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
    5468              :    inside the [] (to be applied to the pointer to which a parameter
    5469              :    array is converted).  STATIC_P is true if "static" is inside the
    5470              :    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
    5471              :    VLA of unspecified length which is nevertheless a complete type,
    5472              :    false otherwise.  The field for the contained declarator is left to
    5473              :    be filled in by set_array_declarator_inner.  */
    5474              : 
    5475              : struct c_declarator *
    5476      1151478 : build_array_declarator (location_t loc,
    5477              :                         tree expr, struct c_declspecs *quals, bool static_p,
    5478              :                         bool vla_unspec_p)
    5479              : {
    5480      1151478 :   struct c_declarator *declarator = XOBNEW (&parser_obstack,
    5481              :                                             struct c_declarator);
    5482      1151478 :   declarator->id_loc = loc;
    5483      1151478 :   declarator->kind = cdk_array;
    5484      1151478 :   declarator->declarator = 0;
    5485      1151478 :   declarator->u.array.dimen = expr;
    5486      1151478 :   if (quals)
    5487              :     {
    5488          966 :       declarator->u.array.attrs = quals->attrs;
    5489          966 :       declarator->u.array.quals = quals_from_declspecs (quals);
    5490              :     }
    5491              :   else
    5492              :     {
    5493      1150512 :       declarator->u.array.attrs = NULL_TREE;
    5494      1150512 :       declarator->u.array.quals = 0;
    5495              :     }
    5496      1151478 :   declarator->u.array.static_p = static_p;
    5497      1151478 :   declarator->u.array.vla_unspec_p = vla_unspec_p;
    5498      1151478 :   if (static_p || quals != NULL)
    5499         1069 :     pedwarn_c90 (loc, OPT_Wpedantic,
    5500              :                  "ISO C90 does not support %<static%> or type "
    5501              :                  "qualifiers in parameter array declarators");
    5502      1151478 :   if (vla_unspec_p)
    5503              :     {
    5504          151 :       pedwarn_c90 (loc, OPT_Wpedantic,
    5505              :                    "ISO C90 does not support %<[*]%> array declarators");
    5506          151 :       if (current_scope->parm_flag)
    5507          143 :         current_scope->had_vla_unspec = true;
    5508              :     }
    5509      1151478 :   return declarator;
    5510              : }
    5511              : 
    5512              : /* Set the contained declarator of an array declarator.  DECL is the
    5513              :    declarator, as constructed by build_array_declarator; INNER is what
    5514              :    appears on the left of the [].  */
    5515              : 
    5516              : struct c_declarator *
    5517      1151478 : set_array_declarator_inner (struct c_declarator *decl,
    5518              :                             struct c_declarator *inner)
    5519              : {
    5520      1151478 :   decl->declarator = inner;
    5521      1151478 :   return decl;
    5522              : }
    5523              : 
    5524              : /* Determine whether TYPE is a one-element array type "[1]".  */
    5525              : static bool
    5526       533378 : one_element_array_type_p (const_tree type)
    5527              : {
    5528       533378 :   if (TREE_CODE (type) != ARRAY_TYPE)
    5529              :     return false;
    5530       533378 :   return integer_zerop (array_type_nelts_minus_one (type));
    5531              : }
    5532              : 
    5533              : /* Determine whether TYPE is a zero-length array type "[0]".  */
    5534              : static bool
    5535       533378 : zero_length_array_type_p (const_tree type)
    5536              : {
    5537       533378 :   if (TREE_CODE (type) == ARRAY_TYPE)
    5538       533378 :     if (tree type_size = TYPE_SIZE_UNIT (type))
    5539       447394 :       if ((integer_zerop (type_size))
    5540         1824 :            && TYPE_DOMAIN (type) != NULL_TREE
    5541       449218 :            && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
    5542              :         return true;
    5543              :   return false;
    5544              : }
    5545              : 
    5546              : /* INIT is a constructor that forms DECL's initializer.  If the final
    5547              :    element initializes a flexible array field, adjust the size of the
    5548              :    DECL with the initializer based on whether the DECL is a union or
    5549              :    a structure.  */
    5550              : 
    5551              : static void
    5552       104857 : add_flexible_array_elts_to_size (tree decl, tree init)
    5553              : {
    5554       104857 :   tree elt, type;
    5555              : 
    5556       104857 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    5557         1453 :     return;
    5558              : 
    5559       103404 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    5560       103404 :   type = TREE_TYPE (elt);
    5561       103404 :   if (c_flexible_array_member_type_p (type))
    5562              :     {
    5563          221 :       complete_array_type (&type, elt, false);
    5564              :       /* For a structure, add the size of the initializer to the DECL's
    5565              :          size.  */
    5566          221 :       if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    5567              :         {
    5568          211 :           DECL_SIZE (decl)
    5569          211 :             = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5570          211 :           DECL_SIZE_UNIT (decl)
    5571          422 :             = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    5572              :                           TYPE_SIZE_UNIT (type));
    5573              :         }
    5574              :       /* For a union, the DECL's size is the maximum of the current size
    5575              :          and the size of the initializer.  */
    5576              :       else
    5577              :         {
    5578           10 :           DECL_SIZE (decl)
    5579           10 :             = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
    5580           10 :           DECL_SIZE_UNIT (decl)
    5581           20 :             = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    5582              :                           TYPE_SIZE_UNIT (type));
    5583              :         }
    5584              :     }
    5585              : }
    5586              : 
    5587              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.
    5588              :    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
    5589              :    before the type name, and set *EXPR_CONST_OPERANDS, if
    5590              :    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
    5591              :    appear in a constant expression.  */
    5592              : 
    5593              : tree
    5594    121325701 : groktypename (struct c_type_name *type_name, tree *expr,
    5595              :               bool *expr_const_operands)
    5596              : {
    5597    121325701 :   tree type;
    5598    121325701 :   tree attrs = type_name->specs->attrs;
    5599              : 
    5600    121325701 :   type_name->specs->attrs = NULL_TREE;
    5601              : 
    5602    121325701 :   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
    5603              :                          false, NULL, &attrs, expr, expr_const_operands,
    5604              :                          DEPRECATED_NORMAL);
    5605              : 
    5606              :   /* Apply attributes.  */
    5607    121325701 :   attrs = c_warn_type_attributes (type, attrs);
    5608    121325701 :   decl_attributes (&type, attrs, 0);
    5609              : 
    5610    121325701 :   return type;
    5611              : }
    5612              : 
    5613              : 
    5614              : /* Decode a "typename", such as "int **", returning a ..._TYPE node,
    5615              :    as for groktypename but setting the context to GENERIC_ASSOC.  */
    5616              : 
    5617              : tree
    5618          820 : grokgenassoc (struct c_type_name *type_name)
    5619              : {
    5620          820 :   tree type;
    5621          820 :   tree attrs = type_name->specs->attrs;
    5622              : 
    5623          820 :   type_name->specs->attrs = NULL_TREE;
    5624              : 
    5625          820 :   type = grokdeclarator (type_name->declarator, type_name->specs, GENERIC_ASSOC,
    5626              :                          false, NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
    5627              : 
    5628              :   /* Apply attributes.  */
    5629          820 :   attrs = c_warn_type_attributes (type, attrs);
    5630          820 :   decl_attributes (&type, attrs, 0);
    5631              : 
    5632          820 :   return type;
    5633              : }
    5634              : 
    5635              : 
    5636              : /* Looks up the most recent pushed declaration corresponding to DECL.  */
    5637              : 
    5638              : static tree
    5639     92071682 : lookup_last_decl (tree decl)
    5640              : {
    5641     92071682 :   tree last_decl = lookup_name (DECL_NAME (decl));
    5642     92071682 :   if (!last_decl)
    5643     89512300 :     last_decl = lookup_name_in_scope (DECL_NAME (decl), external_scope);
    5644     92071682 :   return last_decl;
    5645              : }
    5646              : 
    5647              : /* Wrapper for decl_attributes that adds some implicit attributes
    5648              :    to VAR_DECLs or FUNCTION_DECLs.  */
    5649              : 
    5650              : static tree
    5651     64161002 : c_decl_attributes (tree *node, tree attributes, int flags)
    5652              : {
    5653              :   /* Add implicit "omp declare target" attribute if requested.  */
    5654     64161002 :   if (vec_safe_length (current_omp_declare_target_attribute)
    5655         9163 :       && ((VAR_P (*node) && is_global_var (*node))
    5656         2727 :           || TREE_CODE (*node) == FUNCTION_DECL))
    5657              :     {
    5658         1129 :       if (VAR_P (*node) && !omp_mappable_type (TREE_TYPE (*node)))
    5659           13 :         attributes = tree_cons (get_identifier ("omp declare target implicit"),
    5660              :                                 NULL_TREE, attributes);
    5661              :       else
    5662         1116 :         attributes = tree_cons (get_identifier ("omp declare target"),
    5663              :                                 NULL_TREE, attributes);
    5664         1129 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5665              :         {
    5666          999 :           int device_type
    5667          999 :             = current_omp_declare_target_attribute->last ().device_type;
    5668          999 :           device_type = MAX (device_type, 0);
    5669          999 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0
    5670          999 :               && !lookup_attribute ("omp declare target host", attributes))
    5671            2 :             attributes
    5672            2 :               = tree_cons (get_identifier ("omp declare target host"),
    5673              :                            NULL_TREE, attributes);
    5674          999 :           if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0
    5675          999 :               && !lookup_attribute ("omp declare target nohost", attributes))
    5676            2 :             attributes
    5677            2 :               = tree_cons (get_identifier ("omp declare target nohost"),
    5678              :                            NULL_TREE, attributes);
    5679              : 
    5680          999 :           int indirect
    5681          999 :             = current_omp_declare_target_attribute->last ().indirect;
    5682          999 :           if (indirect && !lookup_attribute ("omp declare target indirect",
    5683              :                                              attributes))
    5684           10 :             attributes
    5685           10 :               = tree_cons (get_identifier ("omp declare target indirect"),
    5686              :                            NULL_TREE, attributes);
    5687              :         }
    5688              :     }
    5689              : 
    5690     64161002 :   if (flag_openmp || flag_openmp_simd)
    5691              :     {
    5692              :       bool diagnosed = false;
    5693      1365438 :       for (tree *pa = &attributes; *pa; )
    5694              :         {
    5695       880646 :           if (is_attribute_namespace_p ("omp", *pa))
    5696              :             {
    5697           65 :               tree name = get_attribute_name (*pa);
    5698           65 :               if (is_attribute_p ("directive", name)
    5699            0 :                   || is_attribute_p ("sequence", name)
    5700           65 :                   || is_attribute_p ("decl", name))
    5701              :                 {
    5702           65 :                   const char *p = NULL;
    5703           65 :                   if (TREE_VALUE (*pa) == NULL_TREE)
    5704           12 :                     p = IDENTIFIER_POINTER (name);
    5705          118 :                   for (tree a = TREE_VALUE (*pa); a; a = TREE_CHAIN (a))
    5706              :                     {
    5707           53 :                       tree d = TREE_VALUE (a);
    5708           53 :                       gcc_assert (TREE_CODE (d) == C_TOKEN_VEC);
    5709           96 :                       if (TREE_PUBLIC (d)
    5710           43 :                           && (VAR_P (*node)
    5711            2 :                               || TREE_CODE (*node) == FUNCTION_DECL)
    5712           96 :                           && c_maybe_parse_omp_decl (*node, d))
    5713           43 :                         continue;
    5714           10 :                       p = TREE_PUBLIC (d) ? "decl" : "directive";
    5715              :                     }
    5716           65 :                   if (p && !diagnosed)
    5717              :                     {
    5718           22 :                       error ("%<omp::%s%> not allowed to be specified in "
    5719              :                              "this context", p);
    5720           22 :                       diagnosed = true;
    5721              :                     }
    5722           65 :                   if (p)
    5723              :                     {
    5724           22 :                       *pa = TREE_CHAIN (*pa);
    5725           22 :                       continue;
    5726              :                     }
    5727              :                 }
    5728              :             }
    5729       880624 :           pa = &TREE_CHAIN (*pa);
    5730              :         }
    5731              :     }
    5732              : 
    5733              :   /* Look up the current declaration with all the attributes merged
    5734              :      so far so that attributes on the current declaration that's
    5735              :      about to be pushed that conflict with the former can be detected,
    5736              :      diagnosed, and rejected as appropriate.  To match the C++ FE, do
    5737              :      not pass an error_mark_node when we found an undeclared variable.  */
    5738     64161002 :   tree last_decl = lookup_last_decl (*node);
    5739     64161002 :   if (last_decl == error_mark_node)
    5740           20 :     last_decl = NULL_TREE;
    5741     64161002 :   tree attr = decl_attributes (node, attributes, flags, last_decl);
    5742     64161001 :   if (VAR_P (*node) && DECL_THREAD_LOCAL_P (*node))
    5743              :     {
    5744              :       // tls_model attribute can set a stronger TLS access model.
    5745         2834 :       tls_model model = DECL_TLS_MODEL (*node);
    5746         2834 :       tls_model default_model = decl_default_tls_model (*node);
    5747         2834 :       if (default_model > model)
    5748         1580 :         set_decl_tls_model (*node, default_model);
    5749              :     }
    5750     64161001 :   return attr;
    5751              : }
    5752              : 
    5753              : 
    5754              : /* Decode a declarator in an ordinary declaration or data definition.
    5755              :    This is called as soon as the type information and variable name
    5756              :    have been parsed, before parsing the initializer if any.
    5757              :    Here we create the ..._DECL node, fill in its type,
    5758              :    and (if DO_PUSH) put it on the list of decls for the current context.
    5759              :    When nonnull, set *LASTLOC to the location of the prior declaration
    5760              :    of the same entity if one exists.
    5761              :    The ..._DECL node is returned as the value.
    5762              : 
    5763              :    Exception: for arrays where the length is not specified,
    5764              :    the type is left null, to be filled in by `finish_decl'.
    5765              : 
    5766              :    Function definitions do not come here; they go to start_function
    5767              :    instead.  However, external and forward declarations of functions
    5768              :    do go through here.  Structure field declarations are done by
    5769              :    grokfield and not through here.  */
    5770              : 
    5771              : tree
    5772     27910704 : start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
    5773              :             bool initialized, tree attributes, bool do_push /* = true */,
    5774              :             location_t *lastloc /* = NULL */)
    5775              : {
    5776     27910704 :   tree decl;
    5777     27910704 :   tree old_decl;
    5778     27910704 :   tree tem;
    5779     27910704 :   tree expr = NULL_TREE;
    5780     27910704 :   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
    5781              : 
    5782              :   /* An object declared as __attribute__((unavailable)) suppresses
    5783              :      warnings and errors from __attribute__((deprecated/unavailable))
    5784              :      components.
    5785              :      An object declared as __attribute__((deprecated)) suppresses
    5786              :      warnings of uses of other deprecated items.  */
    5787     27910704 :   if (lookup_attribute ("unavailable", attributes))
    5788              :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
    5789     27910680 :   else if (lookup_attribute ("deprecated", attributes))
    5790        32262 :     deprecated_state = DEPRECATED_SUPPRESS;
    5791              : 
    5792     27910704 :   decl = grokdeclarator (declarator, declspecs,
    5793              :                          NORMAL, initialized, NULL, &attributes, &expr, NULL,
    5794              :                          deprecated_state);
    5795     27910704 :   if (!decl || decl == error_mark_node)
    5796              :     return NULL_TREE;
    5797              : 
    5798     27910680 :   old_decl = lookup_last_decl (decl);
    5799              : 
    5800     27910680 :   if (tree lastdecl = lastloc ? old_decl : NULL_TREE)
    5801      4748070 :     if (lastdecl != error_mark_node)
    5802      4748061 :       *lastloc = DECL_SOURCE_LOCATION (lastdecl);
    5803              : 
    5804              :   /* Make sure the size expression is evaluated at this point.  */
    5805     27910680 :   if (expr && !current_scope->parm_flag)
    5806        12936 :     add_stmt (fold_convert (void_type_node, expr));
    5807              : 
    5808     13239247 :   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))
    5809     27910682 :       && TREE_PUBLIC (decl))
    5810            1 :     warning (OPT_Wmain, "%q+D is usually a function", decl);
    5811              : 
    5812           14 :   if (warn_missing_variable_declarations && VAR_P (decl)
    5813     27910693 :       && !DECL_EXTERNAL (decl) && TREE_PUBLIC (decl) && old_decl == NULL_TREE)
    5814            5 :     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_variable_declarations,
    5815              :                 "no previous declaration for %qD", decl);
    5816              : 
    5817     27910680 :   if (initialized)
    5818              :     /* Is it valid for this decl to have an initializer at all?
    5819              :        If not, set INITIALIZED to zero, which will indirectly
    5820              :        tell 'finish_decl' to ignore the initializer once it is parsed.  */
    5821      6337197 :     switch (TREE_CODE (decl))
    5822              :       {
    5823            6 :       case TYPE_DECL:
    5824            6 :         error ("typedef %qD is initialized (use %<__typeof__%> instead)", decl);
    5825            6 :         initialized = false;
    5826            6 :         break;
    5827              : 
    5828            9 :       case FUNCTION_DECL:
    5829            9 :         error ("function %qD is initialized like a variable", decl);
    5830            9 :         initialized = false;
    5831            9 :         break;
    5832              : 
    5833           49 :       case PARM_DECL:
    5834              :         /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
    5835           49 :         error ("parameter %qD is initialized", decl);
    5836           49 :         initialized = false;
    5837           49 :         break;
    5838              : 
    5839      6337133 :       default:
    5840              :         /* Don't allow initializations for incomplete types except for
    5841              :            arrays which might be completed by the initialization.  */
    5842              : 
    5843              :         /* This can happen if the array size is an undefined macro.
    5844              :            We already gave a warning, so we don't need another one.  */
    5845      6337133 :         if (TREE_TYPE (decl) == error_mark_node)
    5846              :           initialized = false;
    5847      6337111 :         else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
    5848              :           {
    5849              :             /* A complete type is ok if size is fixed.  If the size is
    5850              :                variable, an empty initializer is OK and nonempty
    5851              :                initializers will be diagnosed in the parser.  */
    5852              :           }
    5853        12233 :         else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
    5854              :           {
    5855            3 :             error ("variable %qD has initializer but incomplete type", decl);
    5856            3 :             initialized = false;
    5857              :           }
    5858              :       }
    5859              : 
    5860           67 :   if (initialized)
    5861              :     {
    5862      6337108 :       if (current_scope == file_scope)
    5863       155603 :         TREE_STATIC (decl) = 1;
    5864              : 
    5865              :       /* Tell 'pushdecl' this is an initialized decl
    5866              :          even though we don't yet have the initializer expression.
    5867              :          Also tell 'finish_decl' it may store the real initializer.  */
    5868      6337108 :       DECL_INITIAL (decl) = error_mark_node;
    5869              :     }
    5870              : 
    5871              :   /* If this is a function declaration, write a record describing it to the
    5872              :      prototypes file (if requested).  */
    5873              : 
    5874     27910680 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    5875     14671433 :     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
    5876              : 
    5877              :   /* ANSI specifies that a tentative definition which is not merged with
    5878              :      a non-tentative definition behaves exactly like a definition with an
    5879              :      initializer equal to zero.  (Section 3.7.2)
    5880              : 
    5881              :      -fno-common gives strict ANSI behavior, though this tends to break
    5882              :      a large body of code that grew up without this rule.
    5883              : 
    5884              :      Thread-local variables are never common, since there's no entrenched
    5885              :      body of code to break, and it allows more efficient variable references
    5886              :      in the presence of dynamic linking.  */
    5887              : 
    5888     27910680 :   if (VAR_P (decl)
    5889      8909735 :       && !initialized
    5890      2572627 :       && TREE_PUBLIC (decl)
    5891       990477 :       && !DECL_THREAD_LOCAL_P (decl)
    5892     28898794 :       && !flag_no_common)
    5893          128 :     DECL_COMMON (decl) = 1;
    5894              : 
    5895              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5896     27910680 :   c_decl_attributes (&decl, attributes, 0);
    5897              : 
    5898              :   /* Handle gnu_inline attribute.  */
    5899     27910679 :   if (declspecs->inline_p
    5900         1029 :       && !flag_gnu89_inline
    5901          997 :       && TREE_CODE (decl) == FUNCTION_DECL
    5902     27911668 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
    5903          966 :           || current_function_decl))
    5904              :     {
    5905           46 :       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
    5906              :         ;
    5907           37 :       else if (declspecs->storage_class != csc_static)
    5908           37 :         DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
    5909              :     }
    5910              : 
    5911     27910679 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5912     14671432 :       && DECL_DECLARED_INLINE_P (decl)
    5913         1019 :       && DECL_UNINLINABLE (decl)
    5914     27910681 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5915              :     {
    5916            2 :       auto_urlify_attributes sentinel;
    5917            2 :       warning (OPT_Wattributes, "inline function %q+D given attribute %qs",
    5918              :                decl, "noinline");
    5919            2 :     }
    5920              : 
    5921              :   /* C99 6.7.4p3: An inline definition of a function with external
    5922              :      linkage shall not contain a definition of a modifiable object
    5923              :      with static storage duration...  */
    5924     27910679 :   if (VAR_P (decl)
    5925      8909735 :       && current_scope != file_scope
    5926      7756734 :       && TREE_STATIC (decl)
    5927        78798 :       && !TREE_READONLY (decl)
    5928        76226 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    5929     27910749 :       && DECL_EXTERNAL (current_function_decl))
    5930            7 :     record_inline_static (input_location, current_function_decl,
    5931              :                           decl, csi_modifiable);
    5932              : 
    5933     27910679 :   if (c_dialect_objc ()
    5934            0 :       && VAR_OR_FUNCTION_DECL_P (decl))
    5935            0 :       objc_check_global_decl (decl);
    5936              : 
    5937              :   /* To enable versions to be created across TU's we mark and mangle all
    5938              :      non-default versioned functions.  */
    5939     27910679 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5940              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
    5941              :       && get_target_version (decl).is_valid ())
    5942              :     {
    5943              :       maybe_mark_function_versioned (decl);
    5944              :       if (current_scope != file_scope)
    5945              :         error ("versioned declarations are only allowed at file scope");
    5946              :     }
    5947              : 
    5948              :   /* Add this decl to the current scope.
    5949              :      TEM may equal DECL or it may be a previous decl of the same name.  */
    5950     27910679 :   if (do_push)
    5951              :     {
    5952     27910331 :       tem = pushdecl (decl);
    5953              : 
    5954     27910331 :       if (initialized && DECL_EXTERNAL (tem))
    5955              :         {
    5956           27 :           DECL_EXTERNAL (tem) = 0;
    5957           27 :           TREE_STATIC (tem) = 1;
    5958              :         }
    5959              : 
    5960     27910331 :       return tem;
    5961              :     }
    5962              :   else
    5963          348 :     return decl;
    5964              : }
    5965              : 
    5966              : /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
    5967              :    DECL or the non-array element type if DECL is an uninitialized array.
    5968              :    If that type has a const member, diagnose this. */
    5969              : 
    5970              : static void
    5971            7 : diagnose_uninitialized_cst_member (tree decl, tree type)
    5972              : {
    5973            7 :   tree field;
    5974           17 :   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
    5975              :     {
    5976           10 :       tree field_type;
    5977           10 :       if (TREE_CODE (field) != FIELD_DECL)
    5978            0 :         continue;
    5979           10 :       field_type = strip_array_types (TREE_TYPE (field));
    5980              : 
    5981           10 :       if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
    5982              :         {
    5983            5 :           auto_diagnostic_group d;
    5984            5 :           if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    5985              :                           "uninitialized const member in %qT is invalid in C++",
    5986            5 :                           strip_array_types (TREE_TYPE (decl))))
    5987            5 :             inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
    5988            5 :         }
    5989              : 
    5990           10 :       if (RECORD_OR_UNION_TYPE_P (field_type))
    5991            2 :         diagnose_uninitialized_cst_member (decl, field_type);
    5992              :     }
    5993            7 : }
    5994              : 
    5995              : /* Finish processing of a declaration;
    5996              :    install its initial value.
    5997              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    5998              :    If the length of an array type is not known before,
    5999              :    it must be determined now, from the initial value, or it is an error.
    6000              : 
    6001              :    INIT_LOC is the location of the initial value.  */
    6002              : 
    6003              : void
    6004    156095216 : finish_decl (tree decl, location_t init_loc, tree init,
    6005              :              tree origtype, tree asmspec_tree)
    6006              : {
    6007    156095216 :   tree type;
    6008    156095216 :   bool was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
    6009    156095216 :   const char *asmspec = 0;
    6010              : 
    6011              :   /* If a name was specified, get the string.  */
    6012    147182499 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    6013    170766648 :       && DECL_FILE_SCOPE_P (decl))
    6014     15825950 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    6015    156095216 :   if (asmspec_tree)
    6016       870869 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    6017              : 
    6018    156095216 :   if (VAR_P (decl)
    6019      8912717 :       && TREE_STATIC (decl)
    6020    157156663 :       && global_bindings_p ())
    6021              :     /* So decl is a global variable. Record the types it uses
    6022              :        so that we can decide later to emit debug info for them.  */
    6023       979450 :     record_types_used_by_current_var_decl (decl);
    6024              : 
    6025              :   /* If `start_decl' didn't like having an initialization, ignore it now.  */
    6026    156095216 :   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
    6027              :     init = NULL_TREE;
    6028              : 
    6029              :   /* Don't crash if parm is initialized.  */
    6030    156095216 :   if (TREE_CODE (decl) == PARM_DECL)
    6031              :     init = NULL_TREE;
    6032              : 
    6033     32209729 :   if (init)
    6034      6340091 :     store_init_value (init_loc, decl, init, origtype);
    6035              : 
    6036    156095216 :   if (c_dialect_objc () && (VAR_OR_FUNCTION_DECL_P (decl)
    6037            0 :                             || TREE_CODE (decl) == FIELD_DECL))
    6038            0 :     objc_check_decl (decl);
    6039              : 
    6040    156095216 :   type = TREE_TYPE (decl);
    6041              : 
    6042              :   /* Deduce size of array from initialization, if not already known.
    6043              :      This is only needed for an initialization in the current scope;
    6044              :      it must not be done for a file-scope initialization of a
    6045              :      declaration with external linkage, redeclared in an inner scope
    6046              :      with the outer declaration shadowed in an intermediate scope.  */
    6047    156095216 :   if (TREE_CODE (type) == ARRAY_TYPE
    6048       867451 :       && TYPE_DOMAIN (type) == NULL_TREE
    6049        19859 :       && TREE_CODE (decl) != TYPE_DECL
    6050    156114979 :       && !(TREE_PUBLIC (decl) && current_scope != file_scope))
    6051              :     {
    6052        19576 :       bool do_default
    6053        19576 :         = !TREE_STATIC (decl) && !DECL_EXTERNAL (decl);
    6054        19576 :       int failure
    6055        19576 :         = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
    6056              :                                do_default);
    6057              : 
    6058              :       /* Get the completed type made by complete_array_type.  */
    6059        19576 :       type = TREE_TYPE (decl);
    6060              : 
    6061        19576 :       switch (failure)
    6062              :         {
    6063            0 :         case 1:
    6064            0 :           error ("initializer fails to determine size of %q+D", decl);
    6065            0 :           break;
    6066              : 
    6067         7371 :         case 2:
    6068         7371 :           if (do_default)
    6069            1 :             error ("array size missing in %q+D", decl);
    6070         7370 :           else if (!TREE_PUBLIC (decl))
    6071           37 :             pedwarn_c23 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    6072              :                          "array size missing in %q+D", decl);
    6073              :           break;
    6074              : 
    6075            3 :         case 3:
    6076            3 :           error ("zero or negative size array %q+D", decl);
    6077            3 :           break;
    6078              : 
    6079        12202 :         case 0:
    6080              :           /* For global variables, update the copy of the type that
    6081              :              exists in the binding.  */
    6082        12202 :           if (TREE_PUBLIC (decl))
    6083              :             {
    6084         3823 :               struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
    6085         7646 :               while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
    6086         3823 :                 b_ext = b_ext->shadowed;
    6087         3823 :               if (b_ext && TREE_CODE (decl) == TREE_CODE (b_ext->decl))
    6088              :                 {
    6089         3823 :                   if (b_ext->u.type && comptypes (b_ext->u.type, type))
    6090          176 :                     b_ext->u.type = composite_type (b_ext->u.type, type);
    6091              :                   else
    6092         3647 :                     b_ext->u.type = type;
    6093              :                 }
    6094              :             }
    6095              :           break;
    6096              : 
    6097            0 :         default:
    6098            0 :           gcc_unreachable ();
    6099              :         }
    6100              : 
    6101        19576 :       if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
    6102        11333 :         TREE_TYPE (DECL_INITIAL (decl)) = type;
    6103              : 
    6104        19576 :       relayout_decl (decl);
    6105              :     }
    6106              : 
    6107              :   /* Look for braced array initializers for character arrays and
    6108              :      recursively convert them into STRING_CSTs.  */
    6109    156095216 :   if (tree init = DECL_INITIAL (decl))
    6110    130227986 :     DECL_INITIAL (decl) = braced_lists_to_strings (type, init);
    6111              : 
    6112    156095216 :   if (VAR_P (decl))
    6113              :     {
    6114      8912717 :       if (init && TREE_CODE (init) == CONSTRUCTOR)
    6115       104857 :         add_flexible_array_elts_to_size (decl, init);
    6116              : 
    6117      8912717 :       complete_flexible_array_elts (DECL_INITIAL (decl));
    6118              : 
    6119      8912717 :       if (is_global_var (decl))
    6120              :         {
    6121      1236306 :           type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    6122      1236306 :                                        ? TCTX_THREAD_STORAGE
    6123              :                                        : TCTX_STATIC_STORAGE);
    6124      1236306 :           if (!verify_type_context (input_location, context, TREE_TYPE (decl)))
    6125            0 :             TREE_TYPE (decl) = error_mark_node;
    6126              :         }
    6127              : 
    6128      8920830 :       if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node
    6129      8920727 :           && COMPLETE_TYPE_P (TREE_TYPE (decl)))
    6130          107 :         layout_decl (decl, 0);
    6131              : 
    6132      8912717 :       if (DECL_SIZE (decl) == NULL_TREE
    6133              :           /* Don't give an error if we already gave one earlier.  */
    6134         8006 :           && TREE_TYPE (decl) != error_mark_node
    6135      8920620 :           && (TREE_STATIC (decl)
    6136              :               /* A static variable with an incomplete type
    6137              :                  is an error if it is initialized.
    6138              :                  Also if it is not file scope.
    6139              :                  Also if it is thread-local (in C23).
    6140              :                  Otherwise, let it through, but if it is not `extern'
    6141              :                  then it may cause an error message later.  */
    6142          309 :               ? (DECL_INITIAL (decl) != NULL_TREE
    6143          309 :                  || !DECL_FILE_SCOPE_P (decl)
    6144          306 :                  || (flag_isoc23 && DECL_THREAD_LOCAL_P (decl)))
    6145              :               /* An automatic variable with an incomplete type
    6146              :                  is an error.  */
    6147         7594 :               : !DECL_EXTERNAL (decl)))
    6148              :          {
    6149           19 :            error ("storage size of %q+D isn%'t known", decl);
    6150           19 :            TREE_TYPE (decl) = error_mark_node;
    6151              :          }
    6152              : 
    6153     17635842 :       if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    6154      8639048 :           || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    6155       287218 :           && DECL_SIZE (decl) == NULL_TREE
    6156      8913005 :           && TREE_STATIC (decl))
    6157          135 :         incomplete_record_decls.safe_push (decl);
    6158              : 
    6159      8912717 :       if (is_global_var (decl)
    6160      1236306 :           && DECL_SIZE (decl) != NULL_TREE
    6161     10141060 :           && TREE_TYPE (decl) != error_mark_node)
    6162              :         {
    6163      1228324 :           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    6164      1228321 :             constant_expression_warning (DECL_SIZE (decl));
    6165              :           else
    6166              :             {
    6167            3 :               error ("storage size of %q+D isn%'t constant", decl);
    6168            3 :               TREE_TYPE (decl) = error_mark_node;
    6169              :             }
    6170              :         }
    6171              : 
    6172      8912717 :       if (TREE_USED (type))
    6173              :         {
    6174            4 :           TREE_USED (decl) = 1;
    6175            4 :           DECL_READ_P (decl) = 1;
    6176              :         }
    6177              :     }
    6178              : 
    6179              :   /* If this is a function and an assembler name is specified, reset DECL_RTL
    6180              :      so we can give it its new name.  Also, update builtin_decl if it
    6181              :      was a normal built-in.  */
    6182    156095216 :   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
    6183              :     {
    6184       857682 :       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
    6185        71914 :         set_builtin_user_assembler_name (decl, asmspec);
    6186       857682 :       set_user_assembler_name (decl, asmspec);
    6187              :     }
    6188              : 
    6189              :   /* If #pragma weak was used, mark the decl weak now.  */
    6190    156095216 :   maybe_apply_pragma_weak (decl);
    6191              : 
    6192              :   /* Output the assembler code and/or RTL code for variables and functions,
    6193              :      unless the type is an undefined structure or union.
    6194              :      If not, it will get done when the type is completed.  */
    6195              : 
    6196    156095216 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    6197              :     {
    6198              :       /* Determine the ELF visibility.  */
    6199     23584149 :       if (TREE_PUBLIC (decl))
    6200     15801253 :         c_determine_visibility (decl);
    6201              : 
    6202              :       /* This is a no-op in c-lang.cc or something real in objc-act.cc.  */
    6203     23584149 :       if (c_dialect_objc ())
    6204            0 :         objc_check_decl (decl);
    6205              : 
    6206     23584149 :       if (asmspec)
    6207              :         {
    6208              :           /* If this is not a static variable, issue a warning.
    6209              :              It doesn't make any sense to give an ASMSPEC for an
    6210              :              ordinary, non-register local variable.  Historically,
    6211              :              GCC has accepted -- but ignored -- the ASMSPEC in
    6212              :              this case.  */
    6213       871907 :           if (!DECL_FILE_SCOPE_P (decl)
    6214         1038 :               && VAR_P (decl)
    6215         1038 :               && !C_DECL_REGISTER (decl)
    6216       870877 :               && !TREE_STATIC (decl))
    6217            1 :             warning (0, "ignoring %<asm%> specifier for non-static local "
    6218              :                      "variable %q+D", decl);
    6219              :           else
    6220       870868 :             set_user_assembler_name (decl, asmspec);
    6221              :         }
    6222              : 
    6223     23584149 :       if (DECL_FILE_SCOPE_P (decl))
    6224              :         {
    6225     15825950 :           if (DECL_INITIAL (decl) == NULL_TREE
    6226     15825950 :               || DECL_INITIAL (decl) == error_mark_node)
    6227              :             /* Don't output anything
    6228              :                when a tentative file-scope definition is seen.
    6229              :                But at end of compilation, do output code for them.  */
    6230     15670150 :             DECL_DEFER_OUTPUT (decl) = 1;
    6231     15825950 :           if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl))
    6232           68 :             DECL_HARD_REGISTER (decl) = 1;
    6233     15825950 :           rest_of_decl_compilation (decl, true, 0);
    6234              : 
    6235     15825950 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6236              :             {
    6237     14671365 :               tree parms = DECL_ARGUMENTS (decl);
    6238     14671365 :               const bool builtin = fndecl_built_in_p (decl);
    6239     14671365 :               if (tree access = build_attr_access_from_parms (parms, !builtin))
    6240       343629 :                 decl_attributes (&decl, access, 0);
    6241              :             }
    6242              :         }
    6243              :       else
    6244              :         {
    6245              :           /* In conjunction with an ASMSPEC, the `register'
    6246              :              keyword indicates that we should place the variable
    6247              :              in a particular register.  */
    6248      7758199 :           if (asmspec && C_DECL_REGISTER (decl))
    6249              :             {
    6250         1030 :               DECL_HARD_REGISTER (decl) = 1;
    6251              :               /* This cannot be done for a structure with volatile
    6252              :                  fields, on which DECL_REGISTER will have been
    6253              :                  reset.  */
    6254         1030 :               if (!DECL_REGISTER (decl))
    6255            1 :                 error ("cannot put object with volatile field into register");
    6256              :             }
    6257              : 
    6258      7758199 :           if (TREE_CODE (decl) != FUNCTION_DECL)
    6259              :             {
    6260              :               /* If we're building a variable sized type, and we might be
    6261              :                  reachable other than via the top of the current binding
    6262              :                  level, then create a new BIND_EXPR so that we deallocate
    6263              :                  the object at the right time.  */
    6264              :               /* Note that DECL_SIZE can be null due to errors.  */
    6265      7758132 :               if (DECL_SIZE (decl)
    6266      7758086 :                   && !TREE_CONSTANT (DECL_SIZE (decl))
    6267      7765498 :                   && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    6268              :                 {
    6269         1337 :                   tree bind;
    6270         1337 :                   bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    6271         1337 :                   TREE_SIDE_EFFECTS (bind) = 1;
    6272         1337 :                   add_stmt (bind);
    6273         1337 :                   BIND_EXPR_BODY (bind) = push_stmt_list ();
    6274              :                 }
    6275      7758132 :               add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
    6276              :                                     DECL_EXPR, decl));
    6277              :             }
    6278              :         }
    6279              : 
    6280              : 
    6281     23584149 :       if (!DECL_FILE_SCOPE_P (decl))
    6282              :         {
    6283              :           /* Recompute the RTL of a local array now
    6284              :              if it used to be an incomplete type.  */
    6285      7758199 :           if (was_incomplete && !is_global_var (decl))
    6286              :             {
    6287              :               /* If we used it already as memory, it must stay in memory.  */
    6288         5277 :               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    6289              :               /* If it's still incomplete now, no init will save it.  */
    6290         5277 :               if (DECL_SIZE (decl) == NULL_TREE)
    6291          109 :                 DECL_INITIAL (decl) = NULL_TREE;
    6292              :             }
    6293              :         }
    6294              :     }
    6295              : 
    6296    156095216 :   if (TREE_CODE (decl) == TYPE_DECL)
    6297              :     {
    6298      4435028 :       if (!DECL_FILE_SCOPE_P (decl)
    6299      4435028 :           && c_type_variably_modified_p (TREE_TYPE (decl)))
    6300         5321 :         add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6301              : 
    6302      8485522 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
    6303              :     }
    6304              : 
    6305              :   /* Install a cleanup (aka destructor) if one was given.  */
    6306    156095216 :   if (VAR_P (decl) && !TREE_STATIC (decl))
    6307              :     {
    6308      7851267 :       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
    6309      7851267 :       if (attr)
    6310              :         {
    6311          131 :           tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
    6312          131 :           tree cleanup_decl = lookup_name (cleanup_id);
    6313          131 :           tree cleanup;
    6314          131 :           vec<tree, va_gc> *v;
    6315              : 
    6316              :           /* Build "cleanup(&decl)" for the destructor.  */
    6317          131 :           cleanup = build_unary_op (input_location, ADDR_EXPR, decl, false);
    6318          131 :           vec_alloc (v, 1);
    6319          131 :           v->quick_push (cleanup);
    6320          131 :           cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
    6321          131 :                                                vNULL, cleanup_decl, v, NULL);
    6322          131 :           vec_free (v);
    6323              : 
    6324              :           /* Don't warn about decl unused; the cleanup uses it.  */
    6325          131 :           TREE_USED (decl) = 1;
    6326          131 :           TREE_USED (cleanup_decl) = 1;
    6327          131 :           DECL_READ_P (decl) = 1;
    6328              : 
    6329          131 :           push_cleanup (decl, cleanup, false);
    6330              :         }
    6331              :     }
    6332              : 
    6333    156095216 :   if (warn_cxx_compat
    6334        22413 :       && VAR_P (decl)
    6335         7549 :       && !DECL_EXTERNAL (decl)
    6336    156102322 :       && DECL_INITIAL (decl) == NULL_TREE)
    6337              :     {
    6338         2333 :       type = strip_array_types (type);
    6339         2333 :       if (TREE_READONLY (decl))
    6340            6 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    6341              :                     "uninitialized %<const %D%> is invalid in C++", decl);
    6342         2327 :       else if (RECORD_OR_UNION_TYPE_P (type)
    6343         2327 :                && C_TYPE_FIELDS_READONLY (type))
    6344            5 :         diagnose_uninitialized_cst_member (decl, type);
    6345              :     }
    6346              : 
    6347    156095216 :   if (flag_openmp
    6348       457806 :       && VAR_P (decl)
    6349    156119192 :       && lookup_attribute ("omp declare target implicit",
    6350        23976 :                            DECL_ATTRIBUTES (decl)))
    6351              :     {
    6352           13 :       DECL_ATTRIBUTES (decl)
    6353           13 :         = remove_attribute ("omp declare target implicit",
    6354           13 :                             DECL_ATTRIBUTES (decl));
    6355           13 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    6356            9 :         error ("%q+D in declare target directive does not have mappable type",
    6357              :                decl);
    6358            4 :       else if (!lookup_attribute ("omp declare target",
    6359            4 :                                   DECL_ATTRIBUTES (decl))
    6360            8 :                && !lookup_attribute ("omp declare target link",
    6361            4 :                                      DECL_ATTRIBUTES (decl)))
    6362              :         {
    6363            4 :           DECL_ATTRIBUTES (decl)
    6364            4 :             = tree_cons (get_identifier ("omp declare target"),
    6365            4 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    6366            4 :             symtab_node *node = symtab_node::get (decl);
    6367            4 :             if (node != NULL)
    6368              :               {
    6369            4 :                 node->offloadable = 1;
    6370            4 :                 if (ENABLE_OFFLOADING)
    6371              :                   {
    6372              :                     g->have_offload = true;
    6373              :                     if (is_a <varpool_node *> (node))
    6374              :                       vec_safe_push (offload_vars, decl);
    6375              :                   }
    6376              :               }
    6377              :         }
    6378              :     }
    6379              : 
    6380              :   /* This is the last point we can lower alignment so give the target the
    6381              :      chance to do so.  */
    6382    156095216 :   if (VAR_P (decl)
    6383      8912717 :       && !is_global_var (decl)
    6384    163771627 :       && !DECL_HARD_REGISTER (decl))
    6385      7675381 :     targetm.lower_local_decl_alignment (decl);
    6386              : 
    6387    156095216 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    6388    156095216 : }
    6389              : 
    6390              : /* Given a parsed parameter declaration, decode it into a PARM_DECL.
    6391              :    EXPR is NULL or a pointer to an expression that needs to be
    6392              :    evaluated for the side effects of array size expressions in the
    6393              :    parameters.  */
    6394              : 
    6395              : tree
    6396            0 : grokparm (const struct c_parm *parm, tree *expr)
    6397              : {
    6398            0 :   tree attrs = parm->attrs;
    6399            0 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
    6400            0 :                               NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
    6401              : 
    6402            0 :   decl_attributes (&decl, attrs, 0);
    6403              : 
    6404            0 :   return decl;
    6405              : }
    6406              : 
    6407              : 
    6408              : 
    6409              : /* Given a parsed parameter declaration, decode it into a PARM_DECL
    6410              :    and push that on the current scope.  EXPR is a pointer to an
    6411              :    expression that needs to be evaluated for the side effects of array
    6412              :    size expressions in the parameters.  */
    6413              : 
    6414              : void
    6415    123862825 : push_parm_decl (const struct c_parm *parm, tree *expr)
    6416              : {
    6417    123862825 :   tree attrs = parm->attrs;
    6418    123862825 :   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
    6419    123862825 :                               &attrs, expr, NULL, DEPRECATED_NORMAL);
    6420    123862825 :   if (decl && DECL_P (decl))
    6421    123862825 :     DECL_SOURCE_LOCATION (decl) = parm->loc;
    6422              : 
    6423    123862825 :   decl_attributes (&decl, attrs, 0);
    6424              : 
    6425    123862825 :   decl = pushdecl (decl);
    6426              : 
    6427    123862825 :   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
    6428    123862825 : }
    6429              : 
    6430              : /* Mark all the parameter declarations to date as forward decls.
    6431              :    Also diagnose use of this extension.  */
    6432              : 
    6433              : void
    6434           42 : mark_forward_parm_decls (void)
    6435              : {
    6436           42 :   struct c_binding *b;
    6437              : 
    6438           42 :   if (current_scope->had_forward_parm_decls)
    6439           12 :     warning_at (input_location, OPT_Wmultiple_parameter_fwd_decl_lists,
    6440              :                 "more than one list of forward declarations of parameters");
    6441           42 :   if (pedantic && !current_scope->had_forward_parm_decls)
    6442            4 :     pedwarn (input_location, OPT_Wpedantic,
    6443              :              "ISO C forbids forward parameter declarations");
    6444              : 
    6445           42 :   current_scope->had_forward_parm_decls = true;
    6446              : 
    6447           95 :   for (b = current_scope->bindings; b; b = b->prev)
    6448           53 :     if (TREE_CODE (b->decl) == PARM_DECL)
    6449           53 :       TREE_ASM_WRITTEN (b->decl) = 1;
    6450           42 : }
    6451              : 
    6452              : /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
    6453              :    literal, which may be an incomplete array type completed by the
    6454              :    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
    6455              :    literal.  NON_CONST is true if the initializers contain something
    6456              :    that cannot occur in a constant expression.  If ALIGNAS_ALIGN is nonzero,
    6457              :    it is the (valid) alignment for this compound literal, as specified
    6458              :    with _Alignas.  SCSPECS are the storage class specifiers (C23) from the
    6459              :    compound literal.  */
    6460              : 
    6461              : tree
    6462       917724 : build_compound_literal (location_t loc, tree type, tree init, bool non_const,
    6463              :                         unsigned int alignas_align,
    6464              :                         struct c_declspecs *scspecs)
    6465              : {
    6466              :   /* We do not use start_decl here because we have a type, not a declarator;
    6467              :      and do not use finish_decl because the decl should be stored inside
    6468              :      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
    6469       917724 :   tree decl;
    6470       917724 :   tree complit;
    6471       917724 :   tree stmt;
    6472       917724 :   bool threadp = scspecs ? scspecs->thread_p : false;
    6473          307 :   enum c_storage_class storage_class = (scspecs
    6474              :                                         ? scspecs->storage_class
    6475              :                                         : csc_none);
    6476              : 
    6477       917724 :   if (type == error_mark_node
    6478       917717 :       || init == error_mark_node)
    6479              :     return error_mark_node;
    6480              : 
    6481       917664 :   if (current_scope == file_scope && storage_class == csc_register)
    6482              :     {
    6483            1 :       error_at (loc, "file-scope compound literal specifies %<register%>");
    6484            1 :       storage_class = csc_none;
    6485              :     }
    6486              : 
    6487       917664 :   if (current_scope != file_scope && threadp && storage_class == csc_none)
    6488              :     {
    6489            6 :       error_at (loc, "compound literal implicitly auto and declared %qs",
    6490            3 :                 scspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    6491            3 :       threadp = false;
    6492              :     }
    6493              : 
    6494       917664 :   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
    6495       917664 :   DECL_EXTERNAL (decl) = 0;
    6496       917664 :   TREE_PUBLIC (decl) = 0;
    6497      1835328 :   TREE_STATIC (decl) = (current_scope == file_scope
    6498       917664 :                         || storage_class == csc_static);
    6499       917664 :   DECL_CONTEXT (decl) = current_function_decl;
    6500       917664 :   TREE_USED (decl) = 1;
    6501       917664 :   DECL_READ_P (decl) = 1;
    6502       917664 :   DECL_ARTIFICIAL (decl) = 1;
    6503       917664 :   DECL_IGNORED_P (decl) = 1;
    6504       917664 :   C_DECL_COMPOUND_LITERAL_P (decl) = 1;
    6505      1835097 :   C_DECL_DECLARED_CONSTEXPR (decl) = scspecs && scspecs->constexpr_p;
    6506       917664 :   TREE_TYPE (decl) = type;
    6507       917664 :   if (threadp)
    6508           16 :     set_decl_tls_model (decl, decl_default_tls_model (decl));
    6509       917664 :   if (storage_class == csc_register)
    6510              :     {
    6511           25 :       C_DECL_REGISTER (decl) = 1;
    6512           25 :       DECL_REGISTER (decl) = 1;
    6513              :     }
    6514       917664 :   c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl);
    6515       917664 :   if (alignas_align)
    6516              :     {
    6517            3 :       SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    6518            3 :       DECL_USER_ALIGN (decl) = 1;
    6519              :     }
    6520       917664 :   store_init_value (loc, decl, init, NULL_TREE);
    6521       917664 :   if (current_scope != file_scope
    6522       917413 :       && TREE_STATIC (decl)
    6523           28 :       && !TREE_READONLY (decl)
    6524           17 :       && DECL_DECLARED_INLINE_P (current_function_decl)
    6525       917670 :       && DECL_EXTERNAL (current_function_decl))
    6526            4 :     record_inline_static (input_location, current_function_decl,
    6527              :                           decl, csi_modifiable);
    6528              : 
    6529       917664 :   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
    6530              :     {
    6531          267 :       int failure = complete_array_type (&TREE_TYPE (decl),
    6532          267 :                                          DECL_INITIAL (decl), true);
    6533              :       /* If complete_array_type returns 3, it means that the initial value of
    6534              :          the compound literal is empty.  Allow it with a pedwarn; in pre-C23
    6535              :          modes, the empty initializer itself has been diagnosed if pedantic so
    6536              :          does not need to be diagnosed again here.  */
    6537          267 :       gcc_assert (failure == 0 || failure == 3);
    6538          267 :       if (failure == 3 && flag_isoc23)
    6539            1 :         pedwarn (loc, OPT_Wpedantic,
    6540              :                  "array of unknown size with empty initializer");
    6541              : 
    6542          267 :       type = TREE_TYPE (decl);
    6543          267 :       TREE_TYPE (DECL_INITIAL (decl)) = type;
    6544          267 :       relayout_decl (decl);
    6545              :     }
    6546              : 
    6547       917664 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    6548              :     {
    6549           19 :       c_incomplete_type_error (loc, NULL_TREE, type);
    6550           19 :       return error_mark_node;
    6551              :     }
    6552              : 
    6553       917366 :   if ((TREE_STATIC (decl) || C_DECL_DECLARED_CONSTEXPR (decl))
    6554       917866 :       && C_TYPE_VARIABLE_SIZE (type))
    6555            2 :     error_at (loc, "storage size isn%'t constant");
    6556              : 
    6557       917645 :   if (TREE_STATIC (decl)
    6558       917645 :       && !verify_type_context (loc, TCTX_STATIC_STORAGE, type))
    6559            0 :     return error_mark_node;
    6560              : 
    6561       917645 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
    6562       917645 :   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
    6563       917645 :   TREE_SIDE_EFFECTS (complit) = 1;
    6564              : 
    6565       917645 :   layout_decl (decl, 0);
    6566              : 
    6567       917645 :   if (TREE_STATIC (decl))
    6568              :     {
    6569              :       /* This decl needs a name for the assembler output.  */
    6570          279 :       set_compound_literal_name (decl);
    6571          279 :       DECL_DEFER_OUTPUT (decl) = 1;
    6572          279 :       DECL_COMDAT (decl) = 1;
    6573          279 :       pushdecl (decl);
    6574          279 :       rest_of_decl_compilation (decl, 1, 0);
    6575              :     }
    6576       917366 :   else if (current_function_decl && !current_scope->parm_flag)
    6577       917357 :     pushdecl (decl);
    6578              : 
    6579       917645 :   if (non_const)
    6580              :     {
    6581          221 :       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
    6582          221 :       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
    6583              :     }
    6584              : 
    6585              :   return complit;
    6586              : }
    6587              : 
    6588              : /* Check the type of a compound literal.  Here we just check that it
    6589              :    is valid for C++.  */
    6590              : 
    6591              : void
    6592       917721 : check_compound_literal_type (location_t loc, struct c_type_name *type_name)
    6593              : {
    6594       917721 :   if (warn_cxx_compat
    6595          165 :       && (type_name->specs->typespec_kind == ctsk_tagdef
    6596          164 :           || type_name->specs->typespec_kind == ctsk_tagfirstref
    6597          163 :           || type_name->specs->typespec_kind == ctsk_tagfirstref_attrs))
    6598            2 :     warning_at (loc, OPT_Wc___compat,
    6599              :                 "defining a type in a compound literal is invalid in C++");
    6600       917721 : }
    6601              : 
    6602              : /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
    6603              :    replacing with appropriate values if they are invalid.  */
    6604              : 
    6605              : static void
    6606        52580 : check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
    6607              :                                tree orig_name)
    6608              : {
    6609        52580 :   tree type_mv;
    6610        52580 :   unsigned int max_width;
    6611        52580 :   unsigned HOST_WIDE_INT w;
    6612        52580 :   const char *name = (orig_name
    6613        95420 :                       ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
    6614         9740 :                       : _("<anonymous>"));
    6615              : 
    6616              :   /* Detect and ignore out of range field width and process valid
    6617              :      field widths.  */
    6618        52580 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
    6619              :     {
    6620            8 :       error_at (loc, "bit-field %qs width not an integer constant", name);
    6621            8 :       *width = integer_one_node;
    6622              :     }
    6623              :   else
    6624              :     {
    6625        52572 :       if (TREE_CODE (*width) != INTEGER_CST)
    6626              :         {
    6627           12 :           *width = c_fully_fold (*width, false, NULL);
    6628           12 :           if (TREE_CODE (*width) == INTEGER_CST)
    6629            6 :             pedwarn (loc, OPT_Wpedantic,
    6630              :                      "bit-field %qs width not an integer constant expression",
    6631              :                      name);
    6632              :         }
    6633        52572 :       if (TREE_CODE (*width) != INTEGER_CST)
    6634              :         {
    6635            6 :           error_at (loc, "bit-field %qs width not an integer constant", name);
    6636            6 :           *width = integer_one_node;
    6637              :         }
    6638        52572 :       constant_expression_warning (*width);
    6639        52572 :       if (tree_int_cst_sgn (*width) < 0)
    6640              :         {
    6641            2 :           error_at (loc, "negative width in bit-field %qs", name);
    6642            2 :           *width = integer_one_node;
    6643              :         }
    6644        52570 :       else if (integer_zerop (*width) && orig_name)
    6645              :         {
    6646            4 :           error_at (loc, "zero width for bit-field %qs", name);
    6647            4 :           *width = integer_one_node;
    6648              :         }
    6649              :     }
    6650              : 
    6651              :   /* Detect invalid bit-field type.  */
    6652        52580 :   if (TREE_CODE (*type) != INTEGER_TYPE
    6653              :       && TREE_CODE (*type) != BOOLEAN_TYPE
    6654              :       && TREE_CODE (*type) != ENUMERAL_TYPE
    6655        52580 :       && TREE_CODE (*type) != BITINT_TYPE)
    6656              :     {
    6657            8 :       error_at (loc, "bit-field %qs has invalid type", name);
    6658            8 :       *type = unsigned_type_node;
    6659              :     }
    6660              : 
    6661        52580 :   if (TYPE_WARN_IF_NOT_ALIGN (*type))
    6662              :     {
    6663            1 :       error_at (loc, "cannot declare bit-field %qs with %<warn_if_not_aligned%> type",
    6664              :                 name);
    6665            1 :       *type = unsigned_type_node;
    6666              :     }
    6667              : 
    6668        52580 :   type_mv = TYPE_MAIN_VARIANT (*type);
    6669        52580 :   if (!in_system_header_at (input_location)
    6670        29374 :       && type_mv != integer_type_node
    6671        26635 :       && type_mv != unsigned_type_node
    6672        65185 :       && type_mv != boolean_type_node)
    6673        12023 :     pedwarn_c90 (loc, OPT_Wpedantic,
    6674              :                  "type of bit-field %qs is a GCC extension", name);
    6675              : 
    6676        52580 :   max_width = TYPE_PRECISION (*type);
    6677              : 
    6678        52580 :   if (compare_tree_int (*width, max_width) > 0)
    6679              :     {
    6680            4 :       error_at (loc, "width of %qs exceeds its type", name);
    6681            4 :       w = max_width;
    6682            4 :       *width = build_int_cst (integer_type_node, w);
    6683              :     }
    6684              :   else
    6685        52576 :     w = tree_to_uhwi (*width);
    6686              : 
    6687              :   /* Truncation of hardbool false and true representation values is always safe:
    6688              :      either the values remain different, or we'll report a problem when creating
    6689              :      the narrower type.  */
    6690        52580 :   if (c_hardbool_type_attr (*type))
    6691        52580 :     return;
    6692              : 
    6693        52299 :   if (TREE_CODE (*type) == ENUMERAL_TYPE)
    6694              :     {
    6695         4130 :       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
    6696         4130 :       if (!lt
    6697         4120 :           || w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
    6698         8246 :           || w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
    6699           15 :         warning_at (loc, 0, "%qs is narrower than values of its type", name);
    6700              :     }
    6701              : }
    6702              : 
    6703              : 
    6704              : 
    6705              : /* Print warning about variable length array if necessary.  */
    6706              : 
    6707              : static void
    6708        22463 : warn_variable_length_array (tree name, tree size)
    6709              : {
    6710        22463 :   if (TREE_CONSTANT (size))
    6711              :     {
    6712          181 :       if (name)
    6713          168 :         pedwarn_c90 (input_location, OPT_Wvla,
    6714              :                      "ISO C90 forbids array %qE whose size "
    6715              :                      "cannot be evaluated", name);
    6716              :       else
    6717           13 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
    6718              :                      "whose size cannot be evaluated");
    6719              :     }
    6720              :   else
    6721              :     {
    6722        22282 :       if (name)
    6723        13799 :         pedwarn_c90 (input_location, OPT_Wvla,
    6724              :                      "ISO C90 forbids variable length array %qE", name);
    6725              :       else
    6726         8483 :         pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
    6727              :                      "length array");
    6728              :     }
    6729        22463 : }
    6730              : 
    6731              : /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
    6732              :    considering only those c_declspec_words found in LIST, which
    6733              :    must be terminated by cdw_number_of_elements.  */
    6734              : 
    6735              : static location_t
    6736          235 : smallest_type_quals_location (const location_t *locations,
    6737              :                               const c_declspec_word *list)
    6738              : {
    6739          235 :   location_t loc = UNKNOWN_LOCATION;
    6740         1410 :   while (*list != cdw_number_of_elements)
    6741              :     {
    6742         1175 :       location_t newloc = locations[*list];
    6743         1175 :       if (loc == UNKNOWN_LOCATION
    6744          288 :           || (newloc != UNKNOWN_LOCATION && newloc < loc))
    6745          887 :         loc = newloc;
    6746         1175 :       list++;
    6747              :     }
    6748              : 
    6749          235 :   return loc;
    6750              : }
    6751              : 
    6752              : 
    6753              : /* We attach an artificial TYPE_DECL to pointed-to type
    6754              :    and arrange for it to be included in a DECL_EXPR.  This
    6755              :    forces the sizes evaluation at a safe point and ensures it
    6756              :    is not deferred until e.g. within a deeper conditional context.
    6757              : 
    6758              :    PARM contexts have no enclosing statement list that
    6759              :    can hold the DECL_EXPR, so we need to use a BIND_EXPR
    6760              :    instead, and add it to the list of expressions that
    6761              :    need to be evaluated.
    6762              : 
    6763              :    TYPENAME contexts do have an enclosing statement list,
    6764              :    but it would be incorrect to use it, as the size should
    6765              :    only be evaluated if the containing expression is
    6766              :    evaluated.  We might also be in the middle of an
    6767              :    expression with side effects on the pointed-to type size
    6768              :    "arguments" prior to the pointer declaration point and
    6769              :    the fake TYPE_DECL in the enclosing context would force
    6770              :    the size evaluation prior to the side effects.  We therefore
    6771              :    use BIND_EXPRs in TYPENAME contexts too.  */
    6772              : static void
    6773         6982 : add_decl_expr (location_t loc, tree type, tree *expr, bool set_name_p)
    6774              : {
    6775         6982 :   tree bind = NULL_TREE;
    6776         6982 :   if (expr)
    6777              :     {
    6778         1546 :       bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, NULL_TREE,
    6779              :                      NULL_TREE);
    6780         1546 :       TREE_SIDE_EFFECTS (bind) = 1;
    6781         1546 :       BIND_EXPR_BODY (bind) = push_stmt_list ();
    6782         1546 :       push_scope ();
    6783              :     }
    6784              : 
    6785         6982 :   tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
    6786         6982 :   pushdecl (decl);
    6787         6982 :   DECL_ARTIFICIAL (decl) = 1;
    6788         6982 :   add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
    6789         6982 :   if (set_name_p)
    6790         6315 :     TYPE_NAME (type) = decl;
    6791              : 
    6792         6982 :   if (bind)
    6793              :     {
    6794         1546 :       pop_scope ();
    6795         1546 :       BIND_EXPR_BODY (bind) = pop_stmt_list (BIND_EXPR_BODY (bind));
    6796         1546 :       if (*expr)
    6797         1451 :         *expr = build2 (COMPOUND_EXPR, void_type_node, *expr, bind);
    6798              :       else
    6799           95 :         *expr = bind;
    6800              :     }
    6801         6982 : }
    6802              : 
    6803              : 
    6804              : /* Add attribute "arg spec" to ATTRS corresponding to an array/VLA parameter
    6805              :    declared with type TYPE.  The attribute has two arguments.  The first is
    6806              :    a string that encodes the presence of the static keyword.  The second is
    6807              :    the declared type of the array before adjustment, i.e. as an array type
    6808              :    including the outermost bound.  */
    6809              : 
    6810              : static tree
    6811       435588 : build_arg_spec_attribute (tree type, bool static_p, tree attrs)
    6812              : {
    6813       435588 :   tree vbchain = tree_cons (NULL_TREE, type, NULL_TREE);
    6814       435588 :   tree acsstr = static_p ? build_string (7, "static") :
    6815       435466 :                            build_string (1, "");
    6816       435588 :   tree args = tree_cons (NULL_TREE, acsstr, vbchain);
    6817       435588 :   tree name = get_identifier ("arg spec");
    6818       435588 :   return tree_cons (name, args, attrs);
    6819              : }
    6820              : 
    6821              : 
    6822              : /* Given declspecs and a declarator,
    6823              :    determine the name and type of the object declared
    6824              :    and construct a ..._DECL node for it.
    6825              :    (In one case we can return a ..._TYPE node instead.
    6826              :     For invalid input we sometimes return NULL_TREE.)
    6827              : 
    6828              :    DECLSPECS is a c_declspecs structure for the declaration specifiers.
    6829              : 
    6830              :    DECL_CONTEXT says which syntactic context this declaration is in:
    6831              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
    6832              :      FUNCDEF for a function definition.  Like NORMAL but a few different
    6833              :       error messages in each case.  Return value may be zero meaning
    6834              :       this definition is too screwy to try to parse.
    6835              :      PARM for a parameter declaration (either within a function prototype
    6836              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
    6837              :      TYPENAME if for a typename (in a cast or sizeof).
    6838              :       Don't make a DECL node; just return the ..._TYPE node.
    6839              :      GENERIC_ASSOC for typenames in a generic association.
    6840              :      FIELD for a struct or union field; make a FIELD_DECL.
    6841              :    INITIALIZED is true if the decl has an initializer.
    6842              :    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
    6843              :    representing the width of the bit-field.
    6844              :    DECL_ATTRS points to the list of attributes that should be added to this
    6845              :      decl.  Any nested attributes that belong on the decl itself will be
    6846              :      added to this list.
    6847              :    If EXPR is not NULL, any expressions that need to be evaluated as
    6848              :      part of evaluating variably modified types will be stored in *EXPR.
    6849              :    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
    6850              :      set to indicate whether operands in *EXPR can be used in constant
    6851              :      expressions.
    6852              :    DEPRECATED_STATE is a deprecated_states value indicating whether
    6853              :    deprecation/unavailability warnings should be suppressed.
    6854              : 
    6855              :    In the TYPENAME case, DECLARATOR is really an absolute declarator.
    6856              :    It may also be so in the PARM case, for a prototype where the
    6857              :    argument type is specified but not the name.
    6858              : 
    6859              :    This function is where the complicated C meanings of `static'
    6860              :    and `extern' are interpreted.  */
    6861              : 
    6862              : static tree
    6863    313669020 : grokdeclarator (const struct c_declarator *declarator,
    6864              :                 struct c_declspecs *declspecs,
    6865              :                 enum decl_context decl_context, bool initialized, tree *width,
    6866              :                 tree *decl_attrs, tree *expr, bool *expr_const_operands,
    6867              :                 enum deprecated_states deprecated_state)
    6868              : {
    6869    313669020 :   tree type = declspecs->type;
    6870    313669020 :   bool threadp = declspecs->thread_p;
    6871    313669020 :   bool constexprp = declspecs->constexpr_p;
    6872    313669020 :   enum c_storage_class storage_class = declspecs->storage_class;
    6873    313669020 :   int constp;
    6874    313669020 :   int restrictp;
    6875    313669020 :   int volatilep;
    6876    313669020 :   int atomicp;
    6877    313669020 :   int type_quals = TYPE_UNQUALIFIED;
    6878    313669020 :   tree name = NULL_TREE;
    6879    313669020 :   bool funcdef_flag = false;
    6880    313669020 :   bool funcdef_syntax = false;
    6881    313669020 :   bool size_varies = false;
    6882    313669020 :   bool size_error = false;
    6883    313669020 :   tree decl_attr = declspecs->decl_attr;
    6884    313669020 :   int array_ptr_quals = TYPE_UNQUALIFIED;
    6885    313669020 :   tree array_ptr_attrs = NULL_TREE;
    6886    313669020 :   bool array_parm_static = false;
    6887    313669020 :   bool array_parm_vla_unspec_p = false;
    6888    313669020 :   tree returned_attrs = NULL_TREE;
    6889    313669020 :   tree decl_id_attrs = NULL_TREE;
    6890    313669020 :   bool bitfield = width != NULL;
    6891    313669020 :   tree element_type;
    6892    313669020 :   tree orig_qual_type = NULL;
    6893    313669020 :   size_t orig_qual_indirect = 0;
    6894    313669020 :   struct c_arg_info *arg_info = 0;
    6895    313669020 :   addr_space_t as1, as2, address_space;
    6896    313669020 :   location_t loc = UNKNOWN_LOCATION;
    6897    313669020 :   tree expr_dummy;
    6898    313669020 :   bool expr_const_operands_dummy;
    6899    313669020 :   enum c_declarator_kind first_non_attr_kind;
    6900    313669020 :   unsigned int alignas_align = 0;
    6901              : 
    6902    313669020 :   if (type == NULL_TREE)
    6903              :     {
    6904              :       /* This can occur for auto on a parameter in C23 mode.  Set a
    6905              :          dummy type here so subsequent code can give diagnostics for
    6906              :          this case.  */
    6907            2 :       gcc_assert (declspecs->c23_auto_p);
    6908            2 :       gcc_assert (decl_context == PARM);
    6909            2 :       type = declspecs->type = integer_type_node;
    6910              :     }
    6911    313669020 :   if (TREE_CODE (type) == ERROR_MARK)
    6912           29 :     return error_mark_node;
    6913    313668991 :   if (expr == NULL)
    6914              :     {
    6915        38211 :       expr = &expr_dummy;
    6916        38211 :       expr_dummy = NULL_TREE;
    6917              :     }
    6918    313668991 :   if (expr_const_operands == NULL)
    6919    192401843 :     expr_const_operands = &expr_const_operands_dummy;
    6920              : 
    6921    313668991 :   if (declspecs->expr)
    6922              :     {
    6923          917 :       if (*expr)
    6924            7 :         *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
    6925              :                         declspecs->expr);
    6926              :       else
    6927          910 :         *expr = declspecs->expr;
    6928              :     }
    6929    313668991 :   *expr_const_operands = declspecs->expr_const_operands;
    6930              : 
    6931    313668991 :   if (decl_context == FUNCDEF)
    6932     36250360 :     funcdef_flag = true, decl_context = NORMAL;
    6933              : 
    6934              :   /* Look inside a declarator for the name being declared
    6935              :      and get it as an IDENTIFIER_NODE, for an error message.  */
    6936    313668991 :   {
    6937    313668991 :     const struct c_declarator *decl = declarator;
    6938              : 
    6939    313668991 :     first_non_attr_kind = cdk_attrs;
    6940    383534720 :     while (decl)
    6941    383534720 :       switch (decl->kind)
    6942              :         {
    6943      1151478 :         case cdk_array:
    6944      1151478 :           loc = decl->id_loc;
    6945              :           /* FALL THRU.  */
    6946              : 
    6947     69858957 :         case cdk_function:
    6948     69858957 :         case cdk_pointer:
    6949     69858957 :           funcdef_syntax = (decl->kind == cdk_function);
    6950     69858957 :           if (first_non_attr_kind == cdk_attrs)
    6951     67754082 :             first_non_attr_kind = decl->kind;
    6952     69858957 :           decl = decl->declarator;
    6953     69858957 :           break;
    6954              : 
    6955         6772 :         case cdk_attrs:
    6956         6772 :           decl = decl->declarator;
    6957         6772 :           break;
    6958              : 
    6959    313668991 :         case cdk_id:
    6960    313668991 :           loc = decl->id_loc;
    6961    313668991 :           if (decl->u.id.id)
    6962              :             name = decl->u.id.id;
    6963    313668991 :           decl_id_attrs = decl->u.id.attrs;
    6964    313668991 :           if (first_non_attr_kind == cdk_attrs)
    6965    245914909 :             first_non_attr_kind = decl->kind;
    6966              :           decl = 0;
    6967              :           break;
    6968              : 
    6969            0 :         default:
    6970            0 :           gcc_unreachable ();
    6971              :         }
    6972    313668991 :     if (name == NULL_TREE)
    6973              :       {
    6974    125931497 :         gcc_assert (decl_context == PARM
    6975              :                     || decl_context == TYPENAME
    6976              :                     || decl_context == GENERIC_ASSOC
    6977              :                     || (decl_context == FIELD
    6978              :                         && declarator->kind == cdk_id));
    6979    125931497 :         gcc_assert (!initialized);
    6980              :       }
    6981              :   }
    6982              : 
    6983              :   /* An enum type specifier (": specifier-qualifier-list") may only be
    6984              :      specified when the enum is being defined or in an empty
    6985              :      declaration of the form "enum identifier enum-type-specifier;".
    6986              :      Except for the case of an empty declaration that has additional
    6987              :      declaration specifiers, all invalid contexts (declarations that
    6988              :      aren't empty, type names, parameter declarations, member
    6989              :      declarations) pass through grokdeclarator.  */
    6990    313668991 :   if (declspecs->enum_type_specifier_ref_p)
    6991            6 :     error_at (loc, "%<enum%> underlying type may not be specified here");
    6992              : 
    6993              :   /* A function definition's declarator must have the form of
    6994              :      a function declarator.  */
    6995              : 
    6996    313668991 :   if (funcdef_flag && !funcdef_syntax)
    6997              :     return NULL_TREE;
    6998              : 
    6999              :   /* If this looks like a function definition, make it one,
    7000              :      even if it occurs where parms are expected.
    7001              :      Then store_parm_decls will reject it and not use it as a parm.  */
    7002    313668960 :   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
    7003        22662 :     decl_context = PARM;
    7004              : 
    7005    313668960 :   if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
    7006              :     {
    7007    313668936 :       if (declspecs->unavailable_p)
    7008           28 :         error_unavailable_use (declspecs->type, declspecs->decl_attr);
    7009    313668908 :       else if (declspecs->deprecated_p
    7010           46 :                 && deprecated_state != DEPRECATED_SUPPRESS)
    7011           38 :         warn_deprecated_use (declspecs->type, declspecs->decl_attr);
    7012              :     }
    7013              : 
    7014    313668960 :   if ((decl_context == NORMAL || decl_context == FIELD)
    7015     68456969 :       && current_scope == file_scope
    7016    374068651 :       && c_type_variably_modified_p (type))
    7017              :     {
    7018            3 :       if (name)
    7019            3 :         error_at (loc, "variably modified %qE at file scope", name);
    7020              :       else
    7021            0 :         error_at (loc, "variably modified field at file scope");
    7022            3 :       type = integer_type_node;
    7023              :     }
    7024              : 
    7025    313668960 :   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
    7026              : 
    7027              :   /* Diagnose defaulting to "int".  */
    7028              : 
    7029    313668960 :   if (declspecs->default_int_p)
    7030              :     {
    7031              :       /* Issue a warning if this is an ISO C 99 program or if
    7032              :          -Wreturn-type and this is a function, or if -Wimplicit;
    7033              :          prefer the former warning since it is more explicit.  */
    7034         9764 :       if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99)
    7035         1229 :           && funcdef_flag)
    7036          702 :         warn_about_return_type = 1;
    7037              :       else
    7038              :         {
    7039         9062 :           if (name)
    7040         9052 :             permerror_opt (loc, OPT_Wimplicit_int,
    7041              :                            "type defaults to %<int%> in declaration "
    7042              :                            "of %qE", name);
    7043              :           else
    7044           10 :             permerror_opt (loc, OPT_Wimplicit_int,
    7045              :                            "type defaults to %<int%> in type name");
    7046              :         }
    7047              :     }
    7048              : 
    7049              :   /* Adjust the type if a bit-field is being declared,
    7050              :      -funsigned-bitfields applied and the type is not explicitly
    7051              :      "signed".  */
    7052    313668960 :   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
    7053           40 :       && TREE_CODE (type) == INTEGER_TYPE)
    7054           38 :     type = c_common_unsigned_type (type);
    7055              : 
    7056              :   /* Figure out the type qualifiers for the declaration.  There are
    7057              :      two ways a declaration can become qualified.  One is something
    7058              :      like `const int i' where the `const' is explicit.  Another is
    7059              :      something like `typedef const int CI; CI i' where the type of the
    7060              :      declaration contains the `const'.  A third possibility is that
    7061              :      there is a type qualifier on the element type of a typedefed
    7062              :      array type, in which case we should extract that qualifier so
    7063              :      that c_apply_type_quals_to_decl receives the full list of
    7064              :      qualifiers to work with (C90 is not entirely clear about whether
    7065              :      duplicate qualifiers should be diagnosed in this case, but it
    7066              :      seems most appropriate to do so).  */
    7067    313668960 :   element_type = strip_array_types (type);
    7068    313668960 :   constp = declspecs->const_p + TYPE_READONLY (element_type);
    7069    313668960 :   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
    7070    313668960 :   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
    7071    313668960 :   atomicp = declspecs->atomic_p + TYPE_ATOMIC (element_type);
    7072    313668960 :   as1 = declspecs->address_space;
    7073    313668960 :   as2 = TYPE_ADDR_SPACE (element_type);
    7074    313668960 :   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
    7075              : 
    7076    313668960 :   if (constp > 1)
    7077           25 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>");
    7078    313668960 :   if (restrictp > 1)
    7079            6 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>");
    7080    313668960 :   if (volatilep > 1)
    7081           15 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>");
    7082    313668960 :   if (atomicp > 1)
    7083            9 :     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>");
    7084              : 
    7085    313668960 :   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
    7086            0 :     error_at (loc, "conflicting named address spaces (%s vs %s)",
    7087              :               c_addr_space_name (as1), c_addr_space_name (as2));
    7088              : 
    7089    313668960 :   if ((TREE_CODE (type) == ARRAY_TYPE
    7090    313493606 :        || first_non_attr_kind == cdk_array)
    7091    314752678 :       && TYPE_QUALS (element_type))
    7092              :     {
    7093           73 :       orig_qual_type = type;
    7094           73 :       type = c_build_qualified_type (type, TYPE_UNQUALIFIED);
    7095              :     }
    7096    313668960 :   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
    7097    313668960 :                 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
    7098    313668960 :                 | (volatilep ? TYPE_QUAL_VOLATILE : 0)
    7099    313668960 :                 | (atomicp ? TYPE_QUAL_ATOMIC : 0)
    7100    313668960 :                 | ENCODE_QUAL_ADDR_SPACE (address_space));
    7101    313668960 :   if (type_quals != TYPE_QUALS (element_type))
    7102     12796289 :     orig_qual_type = NULL_TREE;
    7103              : 
    7104              :   /* Applying the _Atomic qualifier to an array type (through the use
    7105              :      of typedefs or typeof) must be detected here.  If the qualifier
    7106              :      is introduced later, any appearance of applying it to an array is
    7107              :      actually applying it to an element of that array.  */
    7108    313668960 :   if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
    7109            6 :     error_at (loc, "%<_Atomic%>-qualified array type");
    7110              : 
    7111              :   /* Warn about storage classes that are invalid for certain
    7112              :      kinds of declarations (parameters, typenames, etc.).  */
    7113              : 
    7114    313668960 :   if (funcdef_flag
    7115     36250329 :       && (threadp
    7116              :           || constexprp
    7117     36250327 :           || storage_class == csc_auto
    7118     36250327 :           || storage_class == csc_register
    7119     36250282 :           || storage_class == csc_typedef))
    7120              :     {
    7121           47 :       if (storage_class == csc_auto)
    7122           42 :         pedwarn (loc,
    7123           81 :                  (current_scope == file_scope) ? 0 : OPT_Wpedantic,
    7124              :                  "function definition declared %<auto%>");
    7125           50 :       if (storage_class == csc_register)
    7126            3 :         error_at (loc, "function definition declared %<register%>");
    7127           50 :       if (storage_class == csc_typedef)
    7128            3 :         error_at (loc, "function definition declared %<typedef%>");
    7129           50 :       if (threadp)
    7130            2 :         error_at (loc, "function definition declared %qs",
    7131            2 :                   declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7132           50 :       threadp = false;
    7133              :       /* The parser ensures a constexpr function definition never
    7134              :          reaches here.  */
    7135           50 :       gcc_assert (!constexprp);
    7136           50 :       if (storage_class == csc_auto
    7137           50 :           || storage_class == csc_register
    7138              :           || storage_class == csc_typedef)
    7139           55 :         storage_class = csc_none;
    7140              :     }
    7141    313668910 :   else if (decl_context != NORMAL && (storage_class != csc_none
    7142    249530601 :                                       || threadp
    7143    249530018 :                                       || constexprp
    7144    249530016 :                                       || declspecs->c23_auto_p))
    7145              :     {
    7146          587 :       if (decl_context == PARM
    7147          587 :           && storage_class == csc_register
    7148          568 :           && !constexprp
    7149          566 :           && !declspecs->c23_auto_p)
    7150              :         ;
    7151              :       else
    7152              :         {
    7153           21 :           switch (decl_context)
    7154              :             {
    7155            0 :             case FIELD:
    7156            0 :               if (name)
    7157            0 :                 error_at (loc, "storage class specified for structure "
    7158              :                           "field %qE", name);
    7159              :               else
    7160            0 :                 error_at (loc, "storage class specified for structure field");
    7161              :               break;
    7162           21 :             case PARM:
    7163           21 :               if (name)
    7164            7 :                 error_at (loc, "storage class specified for parameter %qE",
    7165              :                           name);
    7166              :               else
    7167           14 :                 error_at (loc, "storage class specified for unnamed parameter");
    7168              :               break;
    7169            0 :             default:
    7170            0 :               error_at (loc, "storage class specified for typename");
    7171            0 :               break;
    7172              :             }
    7173    313668960 :           storage_class = csc_none;
    7174    313668960 :           threadp = false;
    7175    313668960 :           constexprp = false;
    7176              :         }
    7177              :     }
    7178    313668323 :   else if (storage_class == csc_extern
    7179    313668323 :            && initialized
    7180     35398288 :            && !funcdef_flag)
    7181              :     {
    7182              :       /* 'extern' with initialization is invalid if not at file scope.  */
    7183           28 :        if (current_scope == file_scope)
    7184              :          {
    7185              :            /* It is fine to have 'extern const' when compiling at C
    7186              :               and C++ intersection.  */
    7187           19 :            if (!(warn_cxx_compat && constp))
    7188           18 :              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
    7189              :                          name);
    7190              :          }
    7191              :       else
    7192            9 :         error_at (loc, "%qE has both %<extern%> and initializer", name);
    7193              :     }
    7194    313668295 :   else if (current_scope == file_scope)
    7195              :     {
    7196     61273582 :       if (storage_class == csc_auto)
    7197            7 :         error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
    7198              :                   name);
    7199     61273582 :       if (pedantic && storage_class == csc_register)
    7200            4 :         pedwarn (input_location, OPT_Wpedantic,
    7201              :                  "file-scope declaration of %qE specifies %<register%>", name);
    7202              :     }
    7203              :   else
    7204              :     {
    7205    252394713 :       if (storage_class == csc_extern && funcdef_flag)
    7206            3 :         error_at (loc, "nested function %qE declared %<extern%>", name);
    7207    252394710 :       else if (threadp && storage_class == csc_none)
    7208              :         {
    7209           14 :           error_at (loc, "function-scope %qE implicitly auto and declared "
    7210              :                     "%qs", name,
    7211            7 :                     declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
    7212            7 :           threadp = false;
    7213              :         }
    7214              :     }
    7215              : 
    7216              :   /* Now figure out the structure of the declarator proper.
    7217              :      Descend through it, creating more complex types, until we reach
    7218              :      the declared identifier (or NULL_TREE, in an absolute declarator).
    7219              :      At each stage we maintain an unqualified version of the type
    7220              :      together with any qualifiers that should be applied to it with
    7221              :      c_build_qualified_type; this way, array types including
    7222              :      multidimensional array types are first built up in unqualified
    7223              :      form and then the qualified form is created with
    7224              :      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
    7225              : 
    7226    383534688 :   while (declarator && declarator->kind != cdk_id)
    7227              :     {
    7228     69865728 :       if (type == error_mark_node)
    7229              :         {
    7230           39 :           declarator = declarator->declarator;
    7231           39 :           continue;
    7232              :         }
    7233              : 
    7234              :       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
    7235              :          a cdk_pointer (for *...),
    7236              :          a cdk_function (for ...(...)),
    7237              :          a cdk_attrs (for nested attributes),
    7238              :          or a cdk_id (for the name being declared
    7239              :          or the place in an absolute declarator
    7240              :          where the name was omitted).
    7241              :          For the last case, we have just exited the loop.
    7242              : 
    7243              :          At this point, TYPE is the type of elements of an array,
    7244              :          or for a function to return, or for a pointer to point to.
    7245              :          After this sequence of ifs, TYPE is the type of the
    7246              :          array or function or pointer, and DECLARATOR has had its
    7247              :          outermost layer removed.  */
    7248              : 
    7249     69865689 :       if (array_ptr_quals != TYPE_UNQUALIFIED
    7250     69865689 :           || array_ptr_attrs != NULL_TREE
    7251     69865689 :           || array_parm_static)
    7252              :         {
    7253              :           /* Only the innermost declarator (making a parameter be of
    7254              :              array type which is converted to pointer type)
    7255              :              may have static or type qualifiers.  */
    7256            1 :           error_at (loc, "static or type qualifiers in non-parameter array declarator");
    7257            1 :           array_ptr_quals = TYPE_UNQUALIFIED;
    7258            1 :           array_ptr_attrs = NULL_TREE;
    7259            1 :           array_parm_static = false;
    7260              :         }
    7261              : 
    7262     69865689 :       switch (declarator->kind)
    7263              :         {
    7264         6772 :         case cdk_attrs:
    7265         6772 :           {
    7266              :             /* A declarator with embedded attributes.  */
    7267         6772 :             tree attrs = declarator->u.attrs;
    7268         6772 :             const struct c_declarator *inner_decl;
    7269         6772 :             int attr_flags = 0;
    7270         6772 :             declarator = declarator->declarator;
    7271              :             /* Standard attribute syntax precisely defines what entity
    7272              :                an attribute in each position appertains to, so only
    7273              :                apply laxity about positioning to GNU attribute syntax.
    7274              :                Standard attributes applied to a function or array
    7275              :                declarator apply exactly to that type; standard
    7276              :                attributes applied to the identifier apply to the
    7277              :                declaration rather than to the type, and are specified
    7278              :                using a cdk_id declarator rather than using
    7279              :                cdk_attrs.  */
    7280         6772 :             inner_decl = declarator;
    7281         6772 :             while (inner_decl->kind == cdk_attrs)
    7282            0 :               inner_decl = inner_decl->declarator;
    7283         6772 :             if (!cxx11_attribute_p (attrs))
    7284              :               {
    7285         6674 :                 if (inner_decl->kind == cdk_id)
    7286              :                   attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
    7287              :                 else if (inner_decl->kind == cdk_function)
    7288              :                   attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
    7289              :                 else if (inner_decl->kind == cdk_array)
    7290         6772 :                   attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
    7291              :               }
    7292         6772 :             attrs = c_warn_type_attributes (type, attrs);
    7293         6772 :             returned_attrs = decl_attributes (&type,
    7294              :                                               chainon (returned_attrs, attrs),
    7295              :                                               attr_flags);
    7296         6772 :             break;
    7297              :           }
    7298      1151468 :         case cdk_array:
    7299      1151468 :           {
    7300      1151468 :             tree itype = NULL_TREE;
    7301      1151468 :             tree size = declarator->u.array.dimen;
    7302              :             /* The index is a signed object `sizetype' bits wide.  */
    7303      1151468 :             tree index_type = c_common_signed_type (sizetype);
    7304              : 
    7305      1151468 :             array_ptr_quals = declarator->u.array.quals;
    7306      1151468 :             array_ptr_attrs = declarator->u.array.attrs;
    7307      1151468 :             array_parm_static = declarator->u.array.static_p;
    7308      1151468 :             array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
    7309              : 
    7310      1151468 :             declarator = declarator->declarator;
    7311              : 
    7312              :             /* Check for some types that there cannot be arrays of.  */
    7313              : 
    7314      1151468 :             if (VOID_TYPE_P (type))
    7315              :               {
    7316           11 :                 if (name)
    7317            9 :                   error_at (loc, "declaration of %qE as array of voids", name);
    7318              :                 else
    7319            2 :                   error_at (loc, "declaration of type name as array of voids");
    7320           11 :                 type = error_mark_node;
    7321              :               }
    7322              : 
    7323      1151468 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7324              :               {
    7325            3 :                 if (name)
    7326            2 :                   error_at (loc, "declaration of %qE as array of functions",
    7327              :                             name);
    7328              :                 else
    7329            1 :                   error_at (loc, "declaration of type name as array of "
    7330              :                             "functions");
    7331            3 :                 type = error_mark_node;
    7332              :               }
    7333              : 
    7334        22018 :             if (pedantic && !in_system_header_at (input_location)
    7335      1166315 :                 && flexible_array_type_p (type))
    7336           20 :               pedwarn (loc, OPT_Wpedantic,
    7337              :                        "invalid use of structure with flexible array member");
    7338              : 
    7339      1151468 :             if (size == error_mark_node)
    7340          119 :               type = error_mark_node;
    7341              : 
    7342      1151468 :             if (type == error_mark_node)
    7343          133 :               continue;
    7344              : 
    7345      1151335 :             if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, type))
    7346              :               {
    7347            0 :                 type = error_mark_node;
    7348            0 :                 continue;
    7349              :               }
    7350              : 
    7351              :             /* If size was specified, set ITYPE to a range-type for
    7352              :                that size.  Otherwise, ITYPE remains null.  finish_decl
    7353              :                may figure it out from an initial value.  */
    7354              : 
    7355      1151335 :             if (size)
    7356              :               {
    7357       980247 :                 bool size_maybe_const = true;
    7358       980247 :                 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
    7359       980247 :                                        && !TREE_OVERFLOW (size));
    7360       980247 :                 bool this_size_varies = false;
    7361              : 
    7362              :                 /* Strip NON_LVALUE_EXPRs since we aren't using as an
    7363              :                    lvalue.  */
    7364       980256 :                 STRIP_TYPE_NOPS (size);
    7365              : 
    7366       980247 :                 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
    7367              :                   {
    7368           16 :                     if (name)
    7369           14 :                       error_at (loc, "size of array %qE has non-integer type",
    7370              :                                 name);
    7371              :                     else
    7372            2 :                       error_at (loc,
    7373              :                                 "size of unnamed array has non-integer type");
    7374           16 :                     size = integer_one_node;
    7375           16 :                     size_int_const = true;
    7376           16 :                     size_error = true;
    7377              :                   }
    7378              :                 /* This can happen with enum forward declaration.  */
    7379       980231 :                 else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
    7380              :                   {
    7381            0 :                     if (name)
    7382            0 :                       error_at (loc, "size of array %qE has incomplete type",
    7383              :                                 name);
    7384              :                     else
    7385            0 :                       error_at (loc, "size of unnamed array has incomplete "
    7386              :                                 "type");
    7387            0 :                     size = integer_one_node;
    7388            0 :                     size_int_const = true;
    7389            0 :                     size_error = true;
    7390              :                   }
    7391              : 
    7392       980247 :                 size = c_fully_fold (size, false, &size_maybe_const);
    7393              : 
    7394       980247 :                 if (pedantic && size_maybe_const && integer_zerop (size))
    7395              :                   {
    7396            3 :                     if (name)
    7397            3 :                       pedwarn (loc, OPT_Wpedantic,
    7398              :                                "ISO C forbids zero-size array %qE", name);
    7399              :                     else
    7400            0 :                       pedwarn (loc, OPT_Wpedantic,
    7401              :                                "ISO C forbids zero-size array");
    7402              :                   }
    7403              : 
    7404       980247 :                 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
    7405              :                   {
    7406       957918 :                     constant_expression_warning (size);
    7407       957918 :                     if (tree_int_cst_sgn (size) < 0)
    7408              :                       {
    7409          461 :                         if (name)
    7410          458 :                           error_at (loc, "size of array %qE is negative", name);
    7411              :                         else
    7412            3 :                           error_at (loc, "size of unnamed array is negative");
    7413          461 :                         size = integer_one_node;
    7414          461 :                         size_int_const = true;
    7415          461 :                         size_error = true;
    7416              :                       }
    7417              :                     /* Handle a size folded to an integer constant but
    7418              :                        not an integer constant expression.  */
    7419       957918 :                     if (!size_int_const)
    7420              :                       {
    7421              :                         /* If this is a file scope declaration of an
    7422              :                            ordinary identifier, this is invalid code;
    7423              :                            diagnosing it here and not subsequently
    7424              :                            treating the type as variable-length avoids
    7425              :                            more confusing diagnostics later.  */
    7426          155 :                         if ((decl_context == NORMAL || decl_context == FIELD)
    7427          142 :                             && current_scope == file_scope)
    7428           14 :                           pedwarn (input_location, 0,
    7429              :                                    "variably modified %qE at file scope",
    7430              :                                    name);
    7431              :                         else
    7432              :                           this_size_varies = size_varies = true;
    7433          155 :                         warn_variable_length_array (name, size);
    7434              :                       }
    7435              :                   }
    7436        22329 :                 else if ((decl_context == NORMAL || decl_context == FIELD)
    7437        13229 :                          && current_scope == file_scope)
    7438              :                   {
    7439           21 :                     error_at (loc, "variably modified %qE at file scope", name);
    7440           21 :                     size = integer_one_node;
    7441              :                   }
    7442              :                 else
    7443              :                   {
    7444              :                     /* Make sure the array size remains visibly
    7445              :                        nonconstant even if it is (eg) a const variable
    7446              :                        with known value.  */
    7447        22308 :                     this_size_varies = size_varies = true;
    7448        22308 :                     warn_variable_length_array (name, size);
    7449        22308 :                     if (sanitize_flags_p (SANITIZE_VLA)
    7450          181 :                         && current_function_decl != NULL_TREE
    7451        22471 :                         && decl_context == NORMAL)
    7452              :                       {
    7453              :                         /* Evaluate the array size only once.  */
    7454          155 :                         size = save_expr (size);
    7455          155 :                         size = c_fully_fold (size, false, NULL);
    7456          155 :                         size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7457              :                                             ubsan_instrument_vla (loc, size),
    7458              :                                             size);
    7459              :                       }
    7460              :                   }
    7461              : 
    7462       980247 :                 if (integer_zerop (size) && !this_size_varies)
    7463              :                   {
    7464              :                     /* A zero-length array cannot be represented with
    7465              :                        an unsigned index type, which is what we'll
    7466              :                        get with build_index_type.  Create an
    7467              :                        open-ended range instead.  */
    7468         2603 :                     itype = build_range_type (sizetype, size, NULL_TREE);
    7469              :                   }
    7470              :                 else
    7471              :                   {
    7472              :                     /* Arrange for the SAVE_EXPR on the inside of the
    7473              :                        MINUS_EXPR, which allows the -1 to get folded
    7474              :                        with the +1 that happens when building TYPE_SIZE.  */
    7475       977644 :                     if (size_varies)
    7476        22822 :                       size = save_expr (size);
    7477       977644 :                     if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
    7478          141 :                       size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7479              :                                      integer_zero_node, size);
    7480              : 
    7481              :                     /* Compute the maximum valid index, that is, size
    7482              :                        - 1.  Do the calculation in index_type, so that
    7483              :                        if it is a variable the computations will be
    7484              :                        done in the proper mode.  */
    7485       977644 :                     itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
    7486              :                                              convert (index_type, size),
    7487              :                                              convert (index_type,
    7488              :                                                       size_one_node));
    7489              : 
    7490              :                     /* The above overflows when size does not fit
    7491              :                        in index_type.
    7492              :                        ???  While a size of INT_MAX+1 technically shouldn't
    7493              :                        cause an overflow (because we subtract 1), handling
    7494              :                        this case seems like an unnecessary complication.  */
    7495       977644 :                     if (TREE_CODE (size) == INTEGER_CST
    7496       955195 :                         && !int_fits_type_p (size, index_type))
    7497              :                       {
    7498            6 :                         if (name)
    7499            5 :                           error_at (loc, "size of array %qE is too large",
    7500              :                                     name);
    7501              :                         else
    7502            1 :                           error_at (loc, "size of unnamed array is too large");
    7503            6 :                         type = error_mark_node;
    7504            6 :                         continue;
    7505              :                       }
    7506              : 
    7507       977638 :                     itype = build_index_type (itype);
    7508              :                   }
    7509       980241 :                 if (this_size_varies)
    7510              :                   {
    7511        22449 :                     if (TREE_SIDE_EFFECTS (size))
    7512              :                       {
    7513        22086 :                         if (*expr)
    7514         8175 :                           *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
    7515              :                                           *expr, size);
    7516              :                         else
    7517        13911 :                           *expr = size;
    7518              :                       }
    7519        22449 :                     *expr_const_operands &= size_maybe_const;
    7520              :                   }
    7521              :               }
    7522       171088 :             else if (decl_context == FIELD)
    7523              :               {
    7524        85997 :                 bool flexible_array_member = false;
    7525        85997 :                 if (array_parm_vla_unspec_p)
    7526              :                   /* Field names can in fact have function prototype
    7527              :                      scope so [*] is disallowed here through making
    7528              :                      the field variably modified, not through being
    7529              :                      something other than a declaration with function
    7530              :                      prototype scope.  */
    7531              :                   size_varies = true;
    7532              :                 else
    7533              :                   {
    7534              :                     const struct c_declarator *t = declarator;
    7535        85994 :                     while (t->kind == cdk_attrs)
    7536            0 :                       t = t->declarator;
    7537        85994 :                     flexible_array_member = (t->kind == cdk_id);
    7538              :                   }
    7539        85994 :                 if (flexible_array_member
    7540        85994 :                     && !in_system_header_at (input_location))
    7541        84964 :                   pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    7542              :                                "support flexible array members");
    7543              : 
    7544              :                 /* ISO C99 Flexible array members are effectively
    7545              :                    identical to GCC's zero-length array extension.  */
    7546        85997 :                 if (flexible_array_member)
    7547        85974 :                   itype = build_index_type (NULL_TREE);
    7548              :               }
    7549              : 
    7550              :             /* Complain about arrays of incomplete types.  */
    7551      1151329 :             if (!COMPLETE_TYPE_P (type))
    7552              :               {
    7553           57 :                 auto_diagnostic_group d;
    7554           57 :                 error_at (loc, "array type has incomplete element type %qT",
    7555              :                           type);
    7556              :                 /* See if we can be more helpful.  */
    7557           57 :                 if (TREE_CODE (type) == ARRAY_TYPE)
    7558              :                   {
    7559           29 :                     if (name)
    7560           24 :                       inform (loc, "declaration of %qE as multidimensional "
    7561              :                               "array must have bounds for all dimensions "
    7562              :                               "except the first", name);
    7563              :                     else
    7564            5 :                       inform (loc, "declaration of multidimensional array "
    7565              :                               "must have bounds for all dimensions except "
    7566              :                               "the first");
    7567              :                   }
    7568           57 :                 type = error_mark_node;
    7569           57 :               }
    7570              :             else
    7571              :             /* When itype is NULL, a shared incomplete array type is
    7572              :                returned for all array of a given type.  Elsewhere we
    7573              :                make sure we don't complete that type before copying
    7574              :                it, but here we want to make sure we don't ever
    7575              :                modify the shared type, so we gcc_assert (itype)
    7576              :                below.  */
    7577              :               {
    7578      1151272 :                 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
    7579      1151272 :                 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
    7580            0 :                   type = c_build_qualified_type (type,
    7581              :                                                  ENCODE_QUAL_ADDR_SPACE (as));
    7582      1151272 :                 if (array_parm_vla_unspec_p)
    7583          150 :                   type = c_build_array_type_unspecified (type);
    7584              :                 else
    7585      1151122 :                   type = c_build_array_type (type, itype);
    7586              :               }
    7587              : 
    7588      1151329 :             if (array_parm_vla_unspec_p)
    7589              :               {
    7590              :                 /* C99 6.7.5.2p4 */
    7591          150 :                 if (decl_context == TYPENAME)
    7592            6 :                   warning (0, "%<[*]%> not in a declaration");
    7593          144 :                 else if (decl_context != GENERIC_ASSOC
    7594          144 :                          && decl_context != PARM
    7595            7 :                          && decl_context != FIELD)
    7596              :                   {
    7597            4 :                     error ("%<[*]%> not allowed in other than function prototype scope "
    7598              :                            "or generic association");
    7599            4 :                     type = error_mark_node;
    7600              :                   }
    7601              :                 size_varies = true;
    7602              :               }
    7603              : 
    7604      1151329 :             if (type != error_mark_node)
    7605              :               {
    7606              :                 /* The GCC extension for zero-length arrays differs from
    7607              :                    ISO flexible array members in that sizeof yields
    7608              :                    zero.  */
    7609      1151268 :                 if (size && integer_zerop (size))
    7610              :                   {
    7611         2596 :                     gcc_assert (itype);
    7612         2596 :                     type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7613         2596 :                     TYPE_SIZE (type) = bitsize_zero_node;
    7614         2596 :                     TYPE_SIZE_UNIT (type) = size_zero_node;
    7615         2596 :                     SET_TYPE_STRUCTURAL_EQUALITY (type);
    7616              :                   }
    7617              : 
    7618      1151268 :                 if (!valid_array_size_p (loc, type, name))
    7619           33 :                   type = error_mark_node;
    7620              :               }
    7621              : 
    7622      1151329 :             if (decl_context != PARM
    7623       833556 :                 && (array_ptr_quals != TYPE_UNQUALIFIED
    7624       833556 :                     || array_ptr_attrs != NULL_TREE
    7625       833555 :                     || array_parm_static))
    7626              :               {
    7627            2 :                 error_at (loc, "static or type qualifiers in non-parameter "
    7628              :                           "array declarator");
    7629            2 :                 array_ptr_quals = TYPE_UNQUALIFIED;
    7630            2 :                 array_ptr_attrs = NULL_TREE;
    7631            2 :                 array_parm_static = false;
    7632              :               }
    7633      1151329 :             orig_qual_indirect++;
    7634      1151329 :             break;
    7635              :           }
    7636     50496510 :         case cdk_function:
    7637     50496510 :           {
    7638              :             /* Say it's a definition only for the declarator closest
    7639              :                to the identifier, apart possibly from some
    7640              :                attributes.  */
    7641     50496510 :             bool really_funcdef = false;
    7642     50496510 :             tree arg_types;
    7643     50496510 :             orig_qual_type = NULL_TREE;
    7644     50496510 :             if (funcdef_flag)
    7645              :               {
    7646     36250351 :                 const struct c_declarator *t = declarator->declarator;
    7647     36250369 :                 while (t->kind == cdk_attrs)
    7648           18 :                   t = t->declarator;
    7649     36250351 :                 really_funcdef = (t->kind == cdk_id);
    7650              :               }
    7651              : 
    7652              :             /* Declaring a function type.  Make sure we have a valid
    7653              :                type for the function to return.  */
    7654     50496510 :             if (type == error_mark_node)
    7655            0 :               continue;
    7656              : 
    7657     50496510 :             size_varies = false;
    7658              : 
    7659              :             /* Warn about some types functions can't return.  */
    7660     50496510 :             if (TREE_CODE (type) == FUNCTION_TYPE)
    7661              :               {
    7662            0 :                 if (name)
    7663            0 :                   error_at (loc, "%qE declared as function returning a "
    7664              :                                  "function", name);
    7665              :                 else
    7666            0 :                   error_at (loc, "type name declared as function "
    7667              :                             "returning a function");
    7668            0 :                 type = integer_type_node;
    7669              :               }
    7670     50496510 :             if (TREE_CODE (type) == ARRAY_TYPE)
    7671              :               {
    7672            0 :                 if (name)
    7673            0 :                   error_at (loc, "%qE declared as function returning an array",
    7674              :                             name);
    7675              :                 else
    7676            0 :                   error_at (loc, "type name declared as function returning "
    7677              :                             "an array");
    7678            0 :                 type = integer_type_node;
    7679              :               }
    7680              : 
    7681              :             /* Construct the function type and go to the next
    7682              :                inner layer of declarator.  */
    7683     50496510 :             arg_info = declarator->u.arg_info;
    7684     50496510 :             arg_types = grokparms (arg_info, really_funcdef);
    7685              : 
    7686              :             /* Type qualifiers before the return type of the function
    7687              :                qualify the return type, not the function type.  */
    7688     50496510 :             if (type_quals)
    7689              :               {
    7690          235 :                 const enum c_declspec_word ignored_quals_list[] =
    7691              :                   {
    7692              :                     cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
    7693              :                     cdw_atomic, cdw_number_of_elements
    7694              :                   };
    7695          235 :                 location_t specs_loc
    7696          235 :                   = smallest_type_quals_location (declspecs->locations,
    7697              :                                                   ignored_quals_list);
    7698          235 :                 if (specs_loc == UNKNOWN_LOCATION)
    7699          139 :                   specs_loc = declspecs->locations[cdw_typedef];
    7700          139 :                 if (specs_loc == UNKNOWN_LOCATION)
    7701           15 :                   specs_loc = loc;
    7702              : 
    7703              :                 /* Type qualifiers on a function return type are
    7704              :                    normally permitted by the standard but have no
    7705              :                    effect, so give a warning at -Wreturn-type.
    7706              :                    Qualifiers on a void return type are banned on
    7707              :                    function definitions in ISO C; GCC used to used
    7708              :                    them for noreturn functions.  The resolution of C11
    7709              :                    DR#423 means qualifiers (other than _Atomic) are
    7710              :                    actually removed from the return type when
    7711              :                    determining the function type.  For C23, _Atomic is
    7712              :                    removed as well.  */
    7713          235 :                 int quals_used = type_quals;
    7714          235 :                 if (flag_isoc23)
    7715              :                   quals_used = 0;
    7716           65 :                 else if (flag_isoc11)
    7717           31 :                   quals_used &= TYPE_QUAL_ATOMIC;
    7718           65 :                 if (quals_used && VOID_TYPE_P (type) && really_funcdef)
    7719            5 :                   pedwarn (specs_loc, 0,
    7720              :                            "function definition has qualified void "
    7721              :                            "return type");
    7722              :                 else
    7723          230 :                   warning_at (specs_loc, OPT_Wignored_qualifiers,
    7724              :                               "type qualifiers ignored on function "
    7725              :                               "return type");
    7726              : 
    7727              :                 /* Ensure an error for restrict on invalid types; the
    7728              :                    DR#423 resolution is not entirely clear about
    7729              :                    this.  */
    7730          235 :                 if (flag_isoc11
    7731          201 :                     && (type_quals & TYPE_QUAL_RESTRICT)
    7732          241 :                     && (!POINTER_TYPE_P (type)
    7733            4 :                         || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
    7734            4 :                   error_at (loc, "invalid use of %<restrict%>");
    7735          235 :                 type = c_build_qualified_type (type, quals_used);
    7736              :               }
    7737     50496510 :             type_quals = TYPE_UNQUALIFIED;
    7738              : 
    7739    100993020 :             type = c_build_function_type (type, arg_types,
    7740     50496510 :                                           arg_info->no_named_args_stdarg_p);
    7741     50496510 :             declarator = declarator->declarator;
    7742              : 
    7743              :             /* Set the TYPE_CONTEXTs for each tagged type which is local to
    7744              :                the formal parameter list of this FUNCTION_TYPE to point to
    7745              :                the FUNCTION_TYPE node itself.  */
    7746     50496510 :             {
    7747     50496510 :               c_arg_tag *tag;
    7748     50496510 :               unsigned ix;
    7749              : 
    7750    434031470 :               FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
    7751          137 :                 TYPE_CONTEXT (tag->type) = type;
    7752              :             }
    7753              :             break;
    7754              :           }
    7755     18210939 :         case cdk_pointer:
    7756     18210939 :           {
    7757              :             /* Merge any constancy or volatility into the target type
    7758              :                for the pointer.  */
    7759     18210939 :             if ((type_quals & TYPE_QUAL_ATOMIC)
    7760         1984 :                 && TREE_CODE (type) == FUNCTION_TYPE)
    7761              :               {
    7762            2 :                 error_at (loc,
    7763              :                           "%<_Atomic%>-qualified function type");
    7764            2 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    7765              :               }
    7766     18210937 :             else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7767         1701 :                      && type_quals)
    7768            0 :               pedwarn (loc, OPT_Wpedantic,
    7769              :                        "ISO C forbids qualified function types");
    7770     18209238 :             if (type_quals)
    7771      5996390 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7772              :                                              orig_qual_indirect);
    7773     18210939 :             orig_qual_type = NULL_TREE;
    7774     18210939 :             size_varies = false;
    7775              : 
    7776              :             /* When the pointed-to type involves components of variable size,
    7777              :                care must be taken to ensure that the size evaluation code is
    7778              :                emitted early enough to dominate all the possible later uses
    7779              :                and late enough for the variables on which it depends to have
    7780              :                been assigned.
    7781              : 
    7782              :                This is expected to happen automatically when the pointed-to
    7783              :                type has a name/declaration of it's own, but special attention
    7784              :                is required if the type is anonymous. */
    7785     18210939 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    7786              :               {
    7787         5942 :                 bool bind_p = decl_context == TYPENAME
    7788              :                               || decl_context == FIELD
    7789         5942 :                               || decl_context == PARM;
    7790        11378 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    7791              :               }
    7792              : 
    7793     18210939 :             type = c_build_pointer_type (type);
    7794              : 
    7795              :             /* Process type qualifiers (such as const or volatile)
    7796              :                that were given inside the `*'.  */
    7797     18210939 :             type_quals = declarator->u.pointer_quals;
    7798              : 
    7799     18210939 :             declarator = declarator->declarator;
    7800     18210939 :             break;
    7801              :           }
    7802            0 :         default:
    7803            0 :           gcc_unreachable ();
    7804              :         }
    7805              :     }
    7806    313668960 :   *decl_attrs = chainon (returned_attrs, *decl_attrs);
    7807    313668960 :   *decl_attrs = chainon (decl_id_attrs, *decl_attrs);
    7808              : 
    7809              :   /* Now TYPE has the actual type, apart from any qualifiers in
    7810              :      TYPE_QUALS.  */
    7811              : 
    7812              :   /* Warn about address space used for things other than static memory or
    7813              :      pointers.  */
    7814    313668960 :   address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
    7815    313668960 :   if (!ADDR_SPACE_GENERIC_P (address_space))
    7816              :     {
    7817           10 :       if (decl_context == NORMAL)
    7818              :         {
    7819           10 :           switch (storage_class)
    7820              :             {
    7821            0 :             case csc_auto:
    7822            0 :               error ("%qs combined with %<auto%> qualifier for %qE",
    7823              :                      c_addr_space_name (address_space), name);
    7824            0 :               break;
    7825            0 :             case csc_register:
    7826            0 :               error ("%qs combined with %<register%> qualifier for %qE",
    7827              :                      c_addr_space_name (address_space), name);
    7828            0 :               break;
    7829            6 :             case csc_none:
    7830            6 :               if (current_function_scope)
    7831              :                 {
    7832            0 :                   error ("%qs specified for auto variable %qE",
    7833              :                          c_addr_space_name (address_space), name);
    7834            0 :                   break;
    7835              :                 }
    7836              :               break;
    7837              :             case csc_static:
    7838              :             case csc_extern:
    7839              :             case csc_typedef:
    7840              :               break;
    7841            0 :             default:
    7842            0 :               gcc_unreachable ();
    7843              :             }
    7844              :         }
    7845            0 :       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
    7846              :         {
    7847            0 :           if (name)
    7848            0 :             error ("%qs specified for parameter %qE",
    7849              :                    c_addr_space_name (address_space), name);
    7850              :           else
    7851            0 :             error ("%qs specified for unnamed parameter",
    7852              :                    c_addr_space_name (address_space));
    7853              :         }
    7854            0 :       else if (decl_context == FIELD)
    7855              :         {
    7856            0 :           if (name)
    7857            0 :             error ("%qs specified for structure field %qE",
    7858              :                    c_addr_space_name (address_space), name);
    7859              :           else
    7860            0 :             error ("%qs specified for structure field",
    7861              :                    c_addr_space_name (address_space));
    7862              :         }
    7863              :     }
    7864              : 
    7865              :   /* Check the type and width of a bit-field.  */
    7866    313668960 :   if (bitfield)
    7867              :     {
    7868        52580 :       check_bitfield_type_and_width (loc, &type, width, name);
    7869              :       /* C11 makes it implementation-defined (6.7.2.1#5) whether
    7870              :          atomic types are permitted for bit-fields; we have no code to
    7871              :          make bit-field accesses atomic, so disallow them.  */
    7872        52580 :       if (type_quals & TYPE_QUAL_ATOMIC)
    7873              :         {
    7874            2 :           if (name)
    7875            1 :             error_at (loc, "bit-field %qE has atomic type", name);
    7876              :           else
    7877            1 :             error_at (loc, "bit-field has atomic type");
    7878            2 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7879              :         }
    7880              :     }
    7881              : 
    7882              :   /* Reject invalid uses of _Alignas.  */
    7883    313668960 :   if (declspecs->alignas_p)
    7884              :     {
    7885          190 :       if (storage_class == csc_typedef)
    7886            1 :         error_at (loc, "alignment specified for typedef %qE", name);
    7887          189 :       else if (storage_class == csc_register)
    7888            1 :         error_at (loc, "alignment specified for %<register%> object %qE",
    7889              :                   name);
    7890          188 :       else if (decl_context == PARM)
    7891              :         {
    7892            2 :           if (name)
    7893            1 :             error_at (loc, "alignment specified for parameter %qE", name);
    7894              :           else
    7895            1 :             error_at (loc, "alignment specified for unnamed parameter");
    7896              :         }
    7897          186 :       else if (bitfield)
    7898              :         {
    7899            0 :           if (name)
    7900            0 :             error_at (loc, "alignment specified for bit-field %qE", name);
    7901              :           else
    7902            0 :             error_at (loc, "alignment specified for unnamed bit-field");
    7903              :         }
    7904          186 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
    7905            1 :         error_at (loc, "alignment specified for function %qE", name);
    7906          185 :       else if (declspecs->align_log != -1 && TYPE_P (type))
    7907              :         {
    7908          158 :           alignas_align = 1U << declspecs->align_log;
    7909          158 :           if (alignas_align < min_align_of_type (type))
    7910              :             {
    7911           26 :               if (name)
    7912           25 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7913              :                           "alignment of %qE", name);
    7914              :               else
    7915            1 :                 error_at (loc, "%<_Alignas%> specifiers cannot reduce "
    7916              :                           "alignment of unnamed field");
    7917              :               alignas_align = 0;
    7918              :             }
    7919              :         }
    7920              :     }
    7921              : 
    7922              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
    7923              : 
    7924    313668960 :   if (storage_class == csc_typedef)
    7925              :     {
    7926      4306850 :       tree decl;
    7927      4306850 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7928        12591 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7929              :         {
    7930            0 :           error_at (loc,
    7931              :                     "%<_Atomic%>-qualified function type");
    7932            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7933              :         }
    7934      4306850 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7935          609 :                && type_quals)
    7936            0 :         pedwarn (loc, OPT_Wpedantic,
    7937              :                  "ISO C forbids qualified function types");
    7938      4306241 :       if (type_quals)
    7939        31493 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7940              :                                        orig_qual_indirect);
    7941      8613700 :       decl = build_decl (declarator->id_loc,
    7942      4306850 :                          TYPE_DECL, declarator->u.id.id, type);
    7943      4306850 :       if (declspecs->explicit_signed_p)
    7944       355569 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
    7945      4306850 :       if (declspecs->inline_p)
    7946            4 :         pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
    7947      4306850 :       if (declspecs->noreturn_p)
    7948            1 :         pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
    7949              : 
    7950      4306850 :       if (warn_cxx_compat && declarator->u.id.id != NULL_TREE)
    7951              :         {
    7952         1826 :           struct c_binding *b = I_TAG_BINDING (declarator->u.id.id);
    7953              : 
    7954         1826 :           if (b != NULL
    7955           40 :               && b->decl != NULL_TREE
    7956           40 :               && (B_IN_CURRENT_SCOPE (b)
    7957            4 :                   || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
    7958         1862 :               && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
    7959              :             {
    7960            7 :               auto_diagnostic_group d;
    7961            8 :               if (warning_at (declarator->id_loc, OPT_Wc___compat,
    7962              :                               "using %qD as both a typedef and a tag is "
    7963              :                               "invalid in C++", decl)
    7964            7 :                   && b->locus != UNKNOWN_LOCATION)
    7965            6 :                 inform (b->locus, "originally defined here");
    7966            7 :             }
    7967              :         }
    7968              : 
    7969      4306850 :       return decl;
    7970              :     }
    7971              : 
    7972              :   /* If this is a type name (such as, in a cast or sizeof),
    7973              :      compute the type and return it now.  */
    7974              : 
    7975    309362110 :   if (decl_context == TYPENAME || decl_context == GENERIC_ASSOC)
    7976              :     {
    7977              :       /* Note that the grammar rejects storage classes in typenames
    7978              :          and fields.  */
    7979    121326504 :       gcc_assert (storage_class == csc_none && !threadp
    7980              :                   && !declspecs->inline_p && !declspecs->noreturn_p);
    7981    121326504 :       if ((type_quals & TYPE_QUAL_ATOMIC)
    7982          257 :           && TREE_CODE (type) == FUNCTION_TYPE)
    7983              :         {
    7984            0 :           error_at (loc,
    7985              :                     "%<_Atomic%>-qualified function type");
    7986            0 :           type_quals &= ~TYPE_QUAL_ATOMIC;
    7987              :         }
    7988    121326504 :       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
    7989           22 :                && type_quals)
    7990            0 :         pedwarn (loc, OPT_Wpedantic,
    7991              :                  "ISO C forbids const or volatile function types");
    7992    121326482 :       if (type_quals)
    7993          854 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    7994              :                                        orig_qual_indirect);
    7995    121326504 :       return type;
    7996              :     }
    7997              : 
    7998       375287 :   if (pedantic && decl_context == FIELD
    7999    188060405 :       && c_type_variably_modified_p (type))
    8000              :     {
    8001              :       /* C99 6.7.2.1p8 */
    8002            7 :       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
    8003              :                "have a variably modified type");
    8004              :     }
    8005              : 
    8006              :   /* Aside from typedefs and type names (handle above),
    8007              :      `void' at top level (not within pointer)
    8008              :      is allowed only in public variables.
    8009              :      We don't complain about parms either, but that is because
    8010              :      a better error message can be made later.  */
    8011              : 
    8012    188035606 :   if (VOID_TYPE_P (type) && decl_context != PARM
    8013           64 :       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
    8014              :             && (storage_class == csc_extern
    8015           27 :                 || (current_scope == file_scope
    8016           18 :                     && !(storage_class == csc_static
    8017              :                          || storage_class == csc_register)))))
    8018              :     {
    8019           15 :       error_at (loc, "variable or field %qE declared void", name);
    8020           15 :       type = integer_type_node;
    8021              :     }
    8022              : 
    8023              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
    8024              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
    8025              : 
    8026    187082862 :   {
    8027    187082862 :     tree decl;
    8028              : 
    8029    187082862 :     if (decl_context == PARM)
    8030              :       {
    8031    123885487 :         tree promoted_type;
    8032    123885487 :         bool array_parameter_p = false;
    8033              : 
    8034              :         /* A parameter declared as an array of T is really a pointer to T.
    8035              :            One declared as a function is really a pointer to a function.  */
    8036              : 
    8037    123885487 :         if (TREE_CODE (type) == ARRAY_TYPE)
    8038              :           {
    8039       435602 :             if (!size_error)
    8040       435588 :               *decl_attrs = build_arg_spec_attribute (type, array_parm_static,
    8041              :                                                       *decl_attrs);
    8042              : 
    8043              :             /* Transfer const-ness of array into that of type pointed to.  */
    8044       435602 :             type = TREE_TYPE (type);
    8045       435602 :             if (orig_qual_type != NULL_TREE)
    8046              :               {
    8047            7 :                 if (orig_qual_indirect == 0)
    8048            5 :                   orig_qual_type = TREE_TYPE (orig_qual_type);
    8049              :                 else
    8050            2 :                   orig_qual_indirect--;
    8051              :               }
    8052       435602 :             if (type_quals)
    8053        48104 :               type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8054              :                                              orig_qual_indirect);
    8055              : 
    8056              :             /* The pointed-to type may need a decl expr (see above).  */
    8057       435602 :             if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
    8058              :               {
    8059          373 :                 bool bind_p = decl_context == TYPENAME
    8060              :                               || decl_context == FIELD
    8061              :                               || decl_context == PARM;
    8062          373 :                 add_decl_expr (loc, type, bind_p ? expr : NULL, true);
    8063              :               }
    8064              : 
    8065       435602 :             type = c_build_pointer_type (type);
    8066       435602 :             type_quals = array_ptr_quals;
    8067       435602 :             if (type_quals)
    8068          965 :               type = c_build_qualified_type (type, type_quals);
    8069              : 
    8070              :             /* We don't yet implement attributes in this context.  */
    8071       435602 :             if (array_ptr_attrs != NULL_TREE)
    8072            0 :               warning_at (loc, OPT_Wattributes,
    8073              :                           "attributes in parameter array declarator ignored");
    8074              : 
    8075              :             size_varies = false;
    8076              :             array_parameter_p = true;
    8077              :           }
    8078    123449885 :         else if (TREE_CODE (type) == FUNCTION_TYPE)
    8079              :           {
    8080          301 :             if (type_quals & TYPE_QUAL_ATOMIC)
    8081              :               {
    8082            1 :                 error_at (loc,
    8083              :                           "%<_Atomic%>-qualified function type");
    8084            1 :                 type_quals &= ~TYPE_QUAL_ATOMIC;
    8085              :               }
    8086          300 :             else if (type_quals)
    8087            0 :               pedwarn (loc, OPT_Wpedantic,
    8088              :                        "ISO C forbids qualified function types");
    8089            1 :             if (type_quals)
    8090            0 :               type = c_build_qualified_type (type, type_quals);
    8091          301 :             type = c_build_pointer_type (type);
    8092          301 :             type_quals = TYPE_UNQUALIFIED;
    8093              :           }
    8094    123449584 :         else if (type_quals)
    8095      9922602 :           type = c_build_qualified_type (type, type_quals);
    8096              : 
    8097    247770974 :         decl = build_decl (declarator->id_loc,
    8098    123885487 :                            PARM_DECL, declarator->u.id.id, type);
    8099    123885487 :         if (size_varies)
    8100           42 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8101    123885487 :         C_ARRAY_PARAMETER (decl) = array_parameter_p;
    8102              : 
    8103              :         /* Compute the type actually passed in the parmlist,
    8104              :            for the case where there is no prototype.
    8105              :            (For example, shorts and chars are passed as ints.)
    8106              :            When there is a prototype, this is overridden later.  */
    8107              : 
    8108    123885487 :         if (type == error_mark_node)
    8109              :           promoted_type = type;
    8110              :         else
    8111    123885403 :           promoted_type = c_type_promotes_to (type);
    8112              : 
    8113    123885487 :         DECL_ARG_TYPE (decl) = promoted_type;
    8114    123885487 :         if (declspecs->inline_p)
    8115            4 :           pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
    8116    123885487 :         if (declspecs->noreturn_p)
    8117            1 :           pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
    8118              :       }
    8119     64150119 :     else if (decl_context == FIELD)
    8120              :       {
    8121              :         /* Note that the grammar rejects storage classes in typenames
    8122              :            and fields.  */
    8123      4318610 :         gcc_assert (storage_class == csc_none && !threadp
    8124              :                     && !declspecs->inline_p && !declspecs->noreturn_p);
    8125              : 
    8126              :         /* Structure field.  It may not be a function.  */
    8127              : 
    8128      4318610 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8129              :           {
    8130            0 :             error_at (loc, "field %qE declared as a function", name);
    8131            0 :             type = c_build_pointer_type (type);
    8132              :           }
    8133      4318610 :         else if (TREE_CODE (type) != ERROR_MARK
    8134      4318610 :                  && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
    8135              :           {
    8136           24 :             if (name)
    8137           17 :               error_at (loc, "field %qE has incomplete type", name);
    8138              :             else
    8139            7 :               error_at (loc, "unnamed field has incomplete type");
    8140           24 :             type = error_mark_node;
    8141              :           }
    8142      4318586 :         else if (TREE_CODE (type) == ARRAY_TYPE
    8143      4318586 :                  && TYPE_DOMAIN (type) == NULL_TREE)
    8144              :           {
    8145              :             /* We have a flexible array member through a typedef.
    8146              :                Set suitable range.  Whether this is a correct position
    8147              :                for a flexible array member will be determined elsewhere.  */
    8148           14 :             if (!in_system_header_at (input_location))
    8149           14 :               pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
    8150              :                            "support flexible array members");
    8151           14 :             type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    8152           14 :             TYPE_DOMAIN (type) = build_range_type (sizetype, size_zero_node,
    8153              :                                                    NULL_TREE);
    8154           14 :             if (orig_qual_indirect == 0)
    8155      4318610 :               orig_qual_type = NULL_TREE;
    8156              :           }
    8157      4318610 :         if (type != error_mark_node
    8158      4318610 :             && !verify_type_context (loc, TCTX_FIELD, type))
    8159            0 :           type = error_mark_node;
    8160              : 
    8161      4318610 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8162              :                                        orig_qual_indirect);
    8163      8637220 :         decl = build_decl (declarator->id_loc,
    8164      4318610 :                            FIELD_DECL, declarator->u.id.id, type);
    8165      4318610 :         DECL_NONADDRESSABLE_P (decl) = bitfield;
    8166      4318610 :         if (bitfield && !declarator->u.id.id)
    8167         9740 :           DECL_PADDING_P (decl) = 1;
    8168              : 
    8169      4318610 :         if (size_varies)
    8170          648 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8171              :       }
    8172     59831509 :     else if (TREE_CODE (type) == FUNCTION_TYPE)
    8173              :       {
    8174     50921767 :         if (storage_class == csc_register || threadp || constexprp)
    8175              :           {
    8176           12 :             error_at (loc, "invalid storage class for function %qE", name);
    8177              :           }
    8178     50921755 :         else if (current_scope != file_scope)
    8179              :           {
    8180              :             /* Function declaration not at file scope.  Storage
    8181              :                classes other than `extern' are not allowed, C99
    8182              :                6.7.1p5, and `extern' makes no difference.  However,
    8183              :                GCC allows 'auto', perhaps with 'inline', to support
    8184              :                nested functions.  */
    8185        10554 :             if (storage_class == csc_auto)
    8186           66 :                 pedwarn (loc, OPT_Wpedantic,
    8187              :                          "invalid storage class for function %qE", name);
    8188        10488 :             else if (storage_class == csc_static)
    8189              :               {
    8190           20 :                 error_at (loc, "invalid storage class for function %qE", name);
    8191           20 :                 if (funcdef_flag)
    8192            8 :                   storage_class = declspecs->storage_class = csc_none;
    8193              :                 else
    8194              :                   return NULL_TREE;
    8195              :               }
    8196              :           }
    8197              : 
    8198    101843510 :         decl = build_decl (declarator->id_loc,
    8199     50921755 :                            FUNCTION_DECL, declarator->u.id.id, type);
    8200     50921755 :         decl = build_decl_attribute_variant (decl, decl_attr);
    8201              : 
    8202     50921755 :         if (type_quals & TYPE_QUAL_ATOMIC)
    8203              :           {
    8204            2 :             error_at (loc,
    8205              :                       "%<_Atomic%>-qualified function type");
    8206            2 :             type_quals &= ~TYPE_QUAL_ATOMIC;
    8207              :           }
    8208     50921753 :         else if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
    8209            9 :           pedwarn (loc, OPT_Wpedantic,
    8210              :                    "ISO C forbids qualified function types");
    8211              : 
    8212              :         /* Every function declaration is an external reference
    8213              :            (DECL_EXTERNAL) except for those which are not at file
    8214              :            scope and are explicitly declared "auto".  This is
    8215              :            forbidden by standard C (C99 6.7.1p5) and is interpreted by
    8216              :            GCC to signify a forward declaration of a nested function.  */
    8217     50921755 :         if (storage_class == csc_auto && current_scope != file_scope)
    8218           66 :           DECL_EXTERNAL (decl) = 0;
    8219              :         /* In C99, a function which is declared 'inline' with 'extern'
    8220              :            is not an external reference (which is confusing).  It
    8221              :            means that the later definition of the function must be output
    8222              :            in this file, C99 6.7.4p6.  In GNU C89, a function declared
    8223              :            'extern inline' is an external reference.  */
    8224     50921689 :         else if (declspecs->inline_p && storage_class != csc_static)
    8225     35402006 :           DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
    8226     35402006 :                                   == flag_gnu89_inline);
    8227              :         else
    8228     15519683 :           DECL_EXTERNAL (decl) = !initialized;
    8229              : 
    8230              :         /* Record absence of global scope for `static' or `auto'.  */
    8231     50921755 :         TREE_PUBLIC (decl)
    8232     50921755 :           = !(storage_class == csc_static || storage_class == csc_auto);
    8233              : 
    8234              :         /* For a function definition, record the argument information
    8235              :            block where store_parm_decls will look for it.  */
    8236     50921755 :         if (funcdef_flag)
    8237     36250322 :           current_function_arg_info = arg_info;
    8238              : 
    8239     50921755 :         if (declspecs->default_int_p)
    8240         9220 :           C_FUNCTION_IMPLICIT_INT (decl) = 1;
    8241              : 
    8242              :         /* Record presence of `inline' and `_Noreturn', if it is
    8243              :            reasonable.  */
    8244     50921755 :         if (flag_hosted && MAIN_NAME_P (declarator->u.id.id))
    8245              :           {
    8246        47518 :             if (declspecs->inline_p)
    8247            5 :               pedwarn (loc, 0, "cannot inline function %<main%>");
    8248        47518 :             if (declspecs->noreturn_p)
    8249            1 :               pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
    8250              :           }
    8251              :         else
    8252              :           {
    8253     50874237 :             if (declspecs->inline_p)
    8254              :               /* Record that the function is declared `inline'.  */
    8255     35561557 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8256     50874237 :             if (declspecs->noreturn_p)
    8257              :               {
    8258        23307 :                 if (flag_isoc99)
    8259        23304 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8260              :                                "ISO C99 does not support %<_Noreturn%>");
    8261              :                 else
    8262            3 :                   pedwarn_c99 (loc, OPT_Wpedantic,
    8263              :                                "ISO C90 does not support %<_Noreturn%>");
    8264        23307 :                 TREE_THIS_VOLATILE (decl) = 1;
    8265              :               }
    8266              :           }
    8267              : 
    8268              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8269              :            behavior) to create an 'extern' declaration for a
    8270              :            function if there is a global declaration that is
    8271              :            'static' and the global declaration is not visible.
    8272              :            (If the static declaration _is_ currently visible,
    8273              :            the 'extern' declaration is taken to refer to that decl.) */
    8274     50921755 :         if (!initialized
    8275     14671424 :             && TREE_PUBLIC (decl)
    8276     14663584 :             && current_scope != file_scope)
    8277              :           {
    8278         8888 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8279         8888 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8280              : 
    8281         8888 :             if (global_decl
    8282         8888 :                 && global_decl != visible_decl
    8283         1713 :                 && VAR_OR_FUNCTION_DECL_P (global_decl)
    8284         1713 :                 && !TREE_PUBLIC (global_decl))
    8285            2 :               error_at (loc, "function previously declared %<static%> "
    8286              :                         "redeclared %<extern%>");
    8287              :           }
    8288              :       }
    8289              :     else
    8290              :       {
    8291              :         /* It's a variable.  */
    8292              :         /* An uninitialized decl with `extern' is a reference.  */
    8293      8909742 :         int extern_ref = !initialized && storage_class == csc_extern;
    8294              : 
    8295      8909742 :         if (constexprp)
    8296              :           {
    8297              :             /* The type of a constexpr variable must not be variably
    8298              :                modified, volatile, atomic or restrict qualified or
    8299              :                have a member with such a qualifier.  const
    8300              :                qualification is implicitly added, and, at file scope,
    8301              :                has internal linkage.  */
    8302          356 :             if (c_type_variably_modified_p (type))
    8303            1 :               error_at (loc, "%<constexpr%> object has variably modified "
    8304              :                         "type");
    8305          356 :             if (type_quals
    8306          356 :                 & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    8307            9 :               error_at (loc, "invalid qualifiers for %<constexpr%> object");
    8308              :             else
    8309              :               {
    8310          347 :                 tree type_no_array = strip_array_types (type);
    8311          347 :                 if (RECORD_OR_UNION_TYPE_P (type_no_array)
    8312          347 :                     && C_TYPE_FIELDS_NON_CONSTEXPR (type_no_array))
    8313            8 :                   error_at (loc, "invalid qualifiers for field of "
    8314              :                             "%<constexpr%> object");
    8315              :               }
    8316          356 :             type_quals |= TYPE_QUAL_CONST;
    8317          356 :             if (current_scope == file_scope)
    8318          294 :               storage_class = csc_static;
    8319              :           }
    8320              : 
    8321      8909742 :         type = c_build_qualified_type (type, type_quals, orig_qual_type,
    8322              :                                        orig_qual_indirect);
    8323              : 
    8324              :         /* C99 6.2.2p7: It is invalid (compile-time undefined
    8325              :            behavior) to create an 'extern' declaration for a
    8326              :            variable if there is a global declaration that is
    8327              :            'static' and the global declaration is not visible.
    8328              :            (If the static declaration _is_ currently visible,
    8329              :            the 'extern' declaration is taken to refer to that decl.) */
    8330      8909742 :         if (extern_ref && current_scope != file_scope)
    8331              :           {
    8332         1571 :             tree global_decl  = identifier_global_value (declarator->u.id.id);
    8333         1571 :             tree visible_decl = lookup_name (declarator->u.id.id);
    8334              : 
    8335         1571 :             if (global_decl
    8336         1571 :                 && global_decl != visible_decl
    8337          282 :                 && VAR_P (global_decl)
    8338          282 :                 && !TREE_PUBLIC (global_decl))
    8339            8 :               error_at (loc, "variable previously declared %<static%> "
    8340              :                         "redeclared %<extern%>");
    8341              :           }
    8342              : 
    8343     17819484 :         decl = build_decl (declarator->id_loc,
    8344      8909742 :                            VAR_DECL, declarator->u.id.id, type);
    8345      8909742 :         if (size_varies)
    8346         7426 :           C_DECL_VARIABLE_SIZE (decl) = 1;
    8347      8909742 :         if (constexprp)
    8348          356 :           C_DECL_DECLARED_CONSTEXPR (decl) = 1;
    8349              : 
    8350      8909742 :         if (declspecs->inline_p)
    8351            4 :           pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
    8352      8909742 :         if (declspecs->noreturn_p)
    8353            1 :           pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
    8354              : 
    8355              :         /* At file scope, an initialized extern declaration may follow
    8356              :            a static declaration.  In that case, DECL_EXTERNAL will be
    8357              :            reset later in start_decl.  */
    8358      8909742 :         DECL_EXTERNAL (decl) = (storage_class == csc_extern);
    8359              : 
    8360              :         /* At file scope, the presence of a `static' or `register' storage
    8361              :            class specifier, or the absence of all storage class specifiers
    8362              :            makes this declaration a definition (perhaps tentative).  Also,
    8363              :            the absence of `static' makes it public.  */
    8364      8909742 :         if (current_scope == file_scope)
    8365              :           {
    8366      1153008 :             TREE_PUBLIC (decl) = storage_class != csc_static;
    8367      1153008 :             TREE_STATIC (decl) = !extern_ref;
    8368              :           }
    8369              :         /* Not at file scope, only `static' makes a static definition.  */
    8370              :         else
    8371              :           {
    8372      7756734 :             TREE_STATIC (decl) = (storage_class == csc_static);
    8373      7756734 :             TREE_PUBLIC (decl) = extern_ref;
    8374              :           }
    8375              : 
    8376              :         // NB: Set a tentative TLS model to avoid tls_model attribute
    8377              :         // warnings due to lack of thread storage duration.  It will
    8378              :         // be updated by c_decl_attributes later.
    8379      8909742 :         if (threadp)
    8380         2819 :           set_decl_tls_model (decl, TLS_MODEL_REAL);
    8381              :       }
    8382              : 
    8383    188035594 :     if ((storage_class == csc_extern
    8384    138109301 :          || (storage_class == csc_none
    8385    137648260 :              && TREE_CODE (type) == FUNCTION_TYPE
    8386       809210 :              && !funcdef_flag))
    8387    188346816 :         && c_type_variably_modified_p (type))
    8388              :       {
    8389              :         /* C99 6.7.5.2p2 */
    8390            6 :         if (TREE_CODE (type) == FUNCTION_TYPE)
    8391            4 :           error_at (loc, "non-nested function with variably modified type");
    8392              :         else
    8393            2 :           error_at (loc, "object with variably modified type must have "
    8394              :                     "no linkage");
    8395              :       }
    8396              : 
    8397              :     /* For nested functions disqualify ones taking VLAs by value
    8398              :        from inlining since the middle-end cannot deal with this.
    8399              :        ???  We should arrange for those to be passed by reference
    8400              :        with emitting the copy on the caller side in the frontend.  */
    8401    188035594 :     if (storage_class == csc_none
    8402    137648260 :         && TREE_CODE (type) == FUNCTION_TYPE)
    8403      4200275 :       for (tree al = TYPE_ARG_TYPES (type); al; al = TREE_CHAIN (al))
    8404              :         {
    8405      3391105 :           tree arg = TREE_VALUE (al);
    8406      3391105 :           if (arg != error_mark_node
    8407      3391105 :               && C_TYPE_VARIABLE_SIZE (arg))
    8408              :             {
    8409           40 :               DECL_UNINLINABLE (decl) = 1;
    8410           40 :               break;
    8411              :             }
    8412              :         }
    8413              : 
    8414              :     /* Record `register' declaration for warnings on &
    8415              :        and in case doing stupid register allocation.  */
    8416              : 
    8417    188035594 :     if (storage_class == csc_register
    8418         3608 :         && TREE_CODE (type) != FUNCTION_TYPE)
    8419              :       {
    8420         3602 :         C_DECL_REGISTER (decl) = 1;
    8421         3602 :         DECL_REGISTER (decl) = 1;
    8422              :       }
    8423              : 
    8424              :     /* Record constancy and volatility.  */
    8425    188035594 :     c_apply_type_quals_to_decl (type_quals, decl);
    8426              : 
    8427              :     /* Apply _Alignas specifiers.  */
    8428    188035594 :     if (alignas_align)
    8429              :       {
    8430          123 :         SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
    8431          123 :         DECL_USER_ALIGN (decl) = 1;
    8432              :       }
    8433              : 
    8434              :     /* If a type has volatile components, it should be stored in memory.
    8435              :        Otherwise, the fact that those components are volatile
    8436              :        will be ignored, and would even crash the compiler.
    8437              :        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
    8438    188035594 :     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
    8439    188035594 :         && (VAR_P (decl) ||  TREE_CODE (decl) == PARM_DECL
    8440              :           || TREE_CODE (decl) == RESULT_DECL))
    8441              :       {
    8442              :         /* It is not an error for a structure with volatile fields to
    8443              :            be declared register, but reset DECL_REGISTER since it
    8444              :            cannot actually go in a register.  */
    8445          184 :         int was_reg = C_DECL_REGISTER (decl);
    8446          184 :         C_DECL_REGISTER (decl) = 0;
    8447          184 :         DECL_REGISTER (decl) = 0;
    8448          184 :         c_mark_addressable (decl);
    8449          184 :         C_DECL_REGISTER (decl) = was_reg;
    8450              :       }
    8451              : 
    8452              :   /* This is the earliest point at which we might know the assembler
    8453              :      name of a variable.  Thus, if it's known before this, die horribly.  */
    8454    188035594 :     gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
    8455              :                 || !DECL_ASSEMBLER_NAME_SET_P (decl));
    8456              : 
    8457    188035594 :     if (warn_cxx_compat
    8458        24549 :         && VAR_P (decl)
    8459         7548 :         && TREE_PUBLIC (decl)
    8460         2805 :         && TREE_STATIC (decl)
    8461         2356 :         && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    8462         2224 :             || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    8463    188035741 :         && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
    8464            4 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    8465              :                   "non-local variable %qD with anonymous type is "
    8466              :                   "questionable in C++", decl);
    8467              : 
    8468              :     return decl;
    8469              :   }
    8470              : }
    8471              : 
    8472              : /* Decode the parameter-list info for a function type or function definition.
    8473              :    The argument is the value returned by `get_parm_info' (or made in c-parse.c
    8474              :    if there is an identifier list instead of a parameter decl list).
    8475              :    These two functions are separate because when a function returns
    8476              :    or receives functions then each is called multiple times but the order
    8477              :    of calls is different.  The last call to `grokparms' is always the one
    8478              :    that contains the formal parameter names of a function definition.
    8479              : 
    8480              :    Return a list of arg types to use in the FUNCTION_TYPE for this function.
    8481              : 
    8482              :    FUNCDEF_FLAG is true for a function definition, false for
    8483              :    a mere declaration.  A nonempty identifier-list gets an error message
    8484              :    when FUNCDEF_FLAG is false.  */
    8485              : 
    8486              : static tree
    8487     50496510 : grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
    8488              : {
    8489     50496510 :   tree arg_types = arg_info->types;
    8490              : 
    8491     50496510 :   if (funcdef_flag && arg_info->had_vla_unspec)
    8492              :     {
    8493              :       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
    8494              :       /* C99 6.7.5.2p4 */
    8495            2 :       error ("%<[*]%> not allowed in other than function prototype scope");
    8496              :     }
    8497              : 
    8498       715575 :   if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc23
    8499     50499552 :       && !in_system_header_at (input_location))
    8500         3042 :     warning (OPT_Wstrict_prototypes,
    8501              :              "function declaration isn%'t a prototype");
    8502              : 
    8503     50496510 :   if (arg_types == error_mark_node)
    8504              :     /* Don't set TYPE_ARG_TYPES in this case.  */
    8505              :     return NULL_TREE;
    8506              : 
    8507    100220782 :   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
    8508              :     {
    8509         8685 :       if (!funcdef_flag)
    8510              :         {
    8511           13 :           permerror_opt (input_location,
    8512           13 :                          OPT_Wdeclaration_missing_parameter_type,
    8513              :                          "parameter names (without types) in "
    8514              :                          "function declaration");
    8515           13 :           arg_info->parms = NULL_TREE;
    8516              :         }
    8517              :       else
    8518         8672 :         arg_info->parms = arg_info->types;
    8519              : 
    8520         8685 :       arg_info->types = NULL_TREE;
    8521         8685 :       return NULL_TREE;
    8522              :     }
    8523              :   else
    8524              :     {
    8525     50487825 :       tree parm, type, typelt;
    8526     50487825 :       unsigned int parmno;
    8527              : 
    8528              :       /* In C23, convert () to (void).  */
    8529     50487825 :       if (flag_isoc23
    8530     41439735 :           && !arg_types
    8531       764743 :           && !arg_info->parms
    8532       764743 :           && !arg_info->no_named_args_stdarg_p)
    8533              :         {
    8534       764601 :           arg_types = arg_info->types = void_list_node;
    8535       764601 :           arg_info->c23_empty_parens = 1;
    8536              :         }
    8537              : 
    8538              :       /* If there is a parameter of incomplete type in a definition,
    8539              :          this is an error.  In a declaration this is valid, and a
    8540              :          struct or union type may be completed later, before any calls
    8541              :          or definition of the function.  In the case where the tag was
    8542              :          first declared within the parameter list, a warning has
    8543              :          already been given.  If a parameter has void type, then
    8544              :          this has already received an error (constraint violation in C2Y,
    8545              :          previously implicitly undefined behavior).  */
    8546              : 
    8547     50487825 :       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
    8548    173397734 :            parm;
    8549    122909909 :            parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
    8550              :         {
    8551    122909909 :           type = TREE_VALUE (typelt);
    8552    122909909 :           if (type == error_mark_node)
    8553           61 :             continue;
    8554              : 
    8555    122909848 :           if (!COMPLETE_TYPE_P (type))
    8556              :             {
    8557           40 :               if (funcdef_flag)
    8558              :                 {
    8559           13 :                   if (DECL_NAME (parm))
    8560           13 :                     error_at (input_location,
    8561              :                               "parameter %u (%q+D) has incomplete type",
    8562              :                               parmno, parm);
    8563              :                   else
    8564            0 :                     error_at (DECL_SOURCE_LOCATION (parm),
    8565              :                               "parameter %u has incomplete type",
    8566              :                               parmno);
    8567              : 
    8568           13 :                   TREE_VALUE (typelt) = error_mark_node;
    8569           13 :                   TREE_TYPE (parm) = error_mark_node;
    8570           13 :                   arg_types = NULL_TREE;
    8571              :                 }
    8572              :             }
    8573              : 
    8574    122909848 :           if (DECL_NAME (parm) && TREE_USED (parm))
    8575        17655 :             warn_if_shadowing (parm);
    8576              :         }
    8577              :       return arg_types;
    8578              :     }
    8579              : }
    8580              : 
    8581              : /* Allocate and initialize a c_arg_info structure from the parser's
    8582              :    obstack.  */
    8583              : 
    8584              : struct c_arg_info *
    8585     50496528 : build_arg_info (void)
    8586              : {
    8587     50496528 :   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
    8588     50496528 :   ret->parms = NULL_TREE;
    8589     50496528 :   ret->tags = NULL;
    8590     50496528 :   ret->types = NULL_TREE;
    8591     50496528 :   ret->others = NULL_TREE;
    8592     50496528 :   ret->pending_sizes = NULL;
    8593     50496528 :   ret->had_vla_unspec = 0;
    8594     50496528 :   ret->no_named_args_stdarg_p = 0;
    8595     50496528 :   ret->c23_empty_parens = 0;
    8596     50496528 :   return ret;
    8597              : }
    8598              : 
    8599              : /* Take apart the current scope and return a c_arg_info structure with
    8600              :    info on a parameter list just parsed.
    8601              : 
    8602              :    This structure is later fed to 'grokparms' and 'store_parm_decls'.
    8603              : 
    8604              :    ELLIPSIS being true means the argument list ended in '...' so don't
    8605              :    append a sentinel (void_list_node) to the end of the type-list.
    8606              : 
    8607              :    EXPR is NULL or an expression that needs to be evaluated for the
    8608              :    side effects of array size expressions in the parameters.  */
    8609              : 
    8610              : struct c_arg_info *
    8611     49715616 : get_parm_info (bool ellipsis, tree expr)
    8612              : {
    8613     49715616 :   struct c_binding *b = current_scope->bindings;
    8614     49715616 :   struct c_arg_info *arg_info = build_arg_info ();
    8615              : 
    8616     49715616 :   tree parms = NULL_TREE;
    8617     49715616 :   vec<c_arg_tag, va_gc> *tags = NULL;
    8618     49715616 :   tree types = NULL_TREE;
    8619     49715616 :   tree others = NULL_TREE;
    8620              : 
    8621     49715616 :   bool gave_void_only_once_err = false;
    8622              : 
    8623     49715616 :   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
    8624              : 
    8625              :   /* The bindings in this scope must not get put into a block.
    8626              :      We will take care of deleting the binding nodes.  */
    8627     49715616 :   current_scope->bindings = 0;
    8628              : 
    8629              :   /* This function is only called if there was *something* on the
    8630              :      parameter list.  */
    8631     49715616 :   gcc_assert (b);
    8632              : 
    8633              :   /* A parameter list consisting solely of 'void' indicates that the
    8634              :      function takes no arguments.  But if the 'void' is qualified
    8635              :      (by 'const' or 'volatile'), or has a storage class specifier
    8636              :      ('register'), then the behavior is undefined; issue an error.
    8637              :      Typedefs for 'void' are OK (see DR#157).  */
    8638     49715616 :   if (b->prev == 0                       /* one binding */
    8639     13231272 :       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
    8640     13231272 :       && !DECL_NAME (b->decl)               /* anonymous */
    8641     51526785 :       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
    8642              :     {
    8643       952630 :       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
    8644       952630 :           || C_DECL_REGISTER (b->decl))
    8645           96 :         error_at (b->locus, "%<void%> as only parameter may not be qualified");
    8646              : 
    8647              :       /* There cannot be an ellipsis.  */
    8648       952630 :       if (ellipsis)
    8649           17 :         error_at (b->locus, "%<void%> must be the only parameter");
    8650              : 
    8651       952630 :       arg_info->types = void_list_node;
    8652       952630 :       return arg_info;
    8653              :     }
    8654              : 
    8655     48762986 :   if (!ellipsis)
    8656     48550291 :     types = void_list_node;
    8657              : 
    8658              :   /* Break up the bindings list into parms, tags, types, and others;
    8659              :      apply sanity checks; purge the name-to-decl bindings.  */
    8660    171673348 :   while (b)
    8661              :     {
    8662    122910362 :       tree decl = b->decl;
    8663    122910362 :       tree type = TREE_TYPE (decl);
    8664    122910362 :       c_arg_tag tag;
    8665    122910362 :       const char *keyword;
    8666              : 
    8667    122910362 :       switch (TREE_CODE (decl))
    8668              :         {
    8669    122910032 :         case PARM_DECL:
    8670    122910032 :           if (b->id)
    8671              :             {
    8672    119278299 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8673    119278299 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8674              :             }
    8675              : 
    8676              :           /* Check for forward decls that never got their actual decl.  */
    8677    122910032 :           if (TREE_ASM_WRITTEN (decl))
    8678            4 :             error_at (b->locus,
    8679              :                       "parameter %q+D has just a forward declaration", decl);
    8680              :           /* Check for (..., void, ...) and named void parameters and issue an
    8681              :              error.  */
    8682    122910028 :           else if (VOID_TYPE_P (type))
    8683              :             {
    8684          114 :               if (!gave_void_only_once_err)
    8685              :                 {
    8686          114 :                   error_at (b->locus,
    8687              :                             "%<void%> must be the only parameter and unnamed");
    8688          114 :                   gave_void_only_once_err = true;
    8689              :                 }
    8690              :             }
    8691              :           else
    8692              :             {
    8693              :               /* Valid parameter, add it to the list.  */
    8694    122909914 :               DECL_CHAIN (decl) = parms;
    8695    122909914 :               parms = decl;
    8696              : 
    8697              :               /* Since there is a prototype, args are passed in their
    8698              :                  declared types.  The back end may override this later.  */
    8699    122909914 :               DECL_ARG_TYPE (decl) = type;
    8700    122909914 :               types = tree_cons (0, type, types);
    8701              :             }
    8702              :           break;
    8703              : 
    8704           21 :         case ENUMERAL_TYPE: keyword = "enum"; goto tag;
    8705           20 :         case UNION_TYPE:    keyword = "union"; goto tag;
    8706           96 :         case RECORD_TYPE:   keyword = "struct"; goto tag;
    8707          137 :         tag:
    8708              :           /* Types may not have tag-names, in which case the type
    8709              :              appears in the bindings list with b->id NULL.  */
    8710          137 :           if (b->id)
    8711              :             {
    8712           92 :               gcc_assert (I_TAG_BINDING (b->id) == b);
    8713           92 :               I_TAG_BINDING (b->id) = b->shadowed;
    8714              :             }
    8715              : 
    8716              :           /* Warn about any struct, union or enum tags defined in a
    8717              :              parameter list.  The scope of such types is limited to
    8718              :              the parameter list, which is rarely if ever desirable
    8719              :              (it's impossible to call such a function with type-
    8720              :              correct arguments).  An anonymous union parm type is
    8721              :              meaningful as a GNU extension, so don't warn for that.  */
    8722          137 :           if (TREE_CODE (decl) != UNION_TYPE || b->id != NULL_TREE)
    8723              :             {
    8724          117 :               if (b->id)
    8725              :                 {
    8726              :                   /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8727           92 :                   if (!flag_isoc23 || !COMPLETE_TYPE_P (decl))
    8728           72 :                     warning_at (b->locus, 0,
    8729              :                                 "%<%s %E%> declared inside parameter list"
    8730              :                                 " will not be visible outside of this definition or"
    8731              :                                 " declaration", keyword, b->id);
    8732              :                 }
    8733              :               else
    8734              :                 /* The %s will be one of 'struct', 'union', or 'enum'.  */
    8735           25 :                 warning_at (b->locus, 0,
    8736              :                             "anonymous %s declared inside parameter list"
    8737              :                             " will not be visible outside of this definition or"
    8738              :                             " declaration", keyword);
    8739              :             }
    8740              : 
    8741          137 :           tag.id = b->id;
    8742          137 :           tag.type = decl;
    8743          137 :           vec_safe_push (tags, tag);
    8744          137 :           break;
    8745              : 
    8746           20 :         case FUNCTION_DECL:
    8747              :           /* FUNCTION_DECLs appear when there is an implicit function
    8748              :              declaration in the parameter list.  */
    8749           20 :           gcc_assert (b->nested || seen_error ());
    8750           20 :           goto set_shadowed;
    8751              : 
    8752          139 :         case CONST_DECL:
    8753          139 :         case TYPE_DECL:
    8754              :           /* CONST_DECLs appear here when we have an embedded enum,
    8755              :              and TYPE_DECLs appear here when we have an embedded struct
    8756              :              or union.  No warnings for this - we already warned about the
    8757              :              type itself.  */
    8758              : 
    8759              :           /* When we reinsert this decl in the function body, we need
    8760              :              to reconstruct whether it was marked as nested.  */
    8761          139 :           gcc_assert (!b->nested);
    8762          139 :           DECL_CHAIN (decl) = others;
    8763          139 :           others = decl;
    8764              :           /* fall through */
    8765              : 
    8766          193 :         case ERROR_MARK:
    8767          193 :         set_shadowed:
    8768              :           /* error_mark_node appears here when we have an undeclared
    8769              :              variable.  Just throw it away.  */
    8770          193 :           if (b->id)
    8771              :             {
    8772           56 :               gcc_assert (I_SYMBOL_BINDING (b->id) == b);
    8773           56 :               I_SYMBOL_BINDING (b->id) = b->shadowed;
    8774              :             }
    8775              :           break;
    8776              : 
    8777              :           /* Other things that might be encountered.  */
    8778            0 :         case LABEL_DECL:
    8779            0 :         case VAR_DECL:
    8780            0 :         default:
    8781            0 :           gcc_unreachable ();
    8782              :         }
    8783              : 
    8784    122910362 :       b = free_binding_and_advance (b);
    8785              :     }
    8786              : 
    8787     48762986 :   arg_info->parms = parms;
    8788     48762986 :   arg_info->tags = tags;
    8789     48762986 :   arg_info->types = types;
    8790     48762986 :   arg_info->others = others;
    8791     48762986 :   arg_info->pending_sizes = expr;
    8792     48762986 :   arg_info->no_named_args_stdarg_p = ellipsis && !types;
    8793     48762986 :   return arg_info;
    8794              : }
    8795              : 
    8796              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8797              :    Define the tag as a forward-reference with location LOC if it is
    8798              :    not defined.  HAVE_STD_ATTRS says whether any standard attributes
    8799              :    were present after the struct, union or enum keyword; ATTRS are the
    8800              :    standard attributes present there.  HAS_ENUM_TYPE_SPECIFIER says
    8801              :    whether an enum type specifier (": specifier-qualifier-list") is
    8802              :    present; if so, this is called before that specifier is parsed, so
    8803              :    that the tag is in scope for that specifier.  Return a c_typespec
    8804              :    structure for the type specifier.  */
    8805              : 
    8806              : struct c_typespec
    8807      1082929 : parser_xref_tag (location_t loc, enum tree_code code, tree name,
    8808              :                  bool have_std_attrs, tree attrs, bool has_enum_type_specifier)
    8809              : {
    8810      1082929 :   struct c_typespec ret;
    8811      1082929 :   tree ref;
    8812      1082929 :   location_t refloc;
    8813              : 
    8814      1082929 :   ret.expr = NULL_TREE;
    8815      1082929 :   ret.expr_const_operands = true;
    8816      1082929 :   ret.has_enum_type_specifier = has_enum_type_specifier;
    8817              : 
    8818              :   /* If a cross reference is requested, look up the type already
    8819              :      defined for this tag and return it.  If an enum type specifier is
    8820              :      present, only a definition in the current scope is relevant.  */
    8821              : 
    8822      1082929 :   ref = lookup_tag (code, name, has_enum_type_specifier, &refloc);
    8823              : 
    8824              :   /* If the visble type is still being defined, see if there is
    8825              :      an earlier definition (which may be complete).  We do not
    8826              :      have to loop because nested redefinitions are not allowed.  */
    8827      1082929 :   if (flag_isoc23 && ref && C_TYPE_BEING_DEFINED (ref))
    8828              :     {
    8829        85771 :       tree vis = previous_tag (ref);
    8830        85771 :       if (vis)
    8831           16 :         ref = vis;
    8832              :     }
    8833              : 
    8834              :   /* If this is the right type of tag, return what we found.
    8835              :      (This reference will be shadowed by shadow_tag later if appropriate.)
    8836              :      If this is the wrong type of tag, do not return it.  If it was the
    8837              :      wrong type in the same scope, we will have had an error
    8838              :      message already; if in a different scope and declaring
    8839              :      a name, pending_xref_error will give an error message; but if in a
    8840              :      different scope and not declaring a name, this tag should
    8841              :      shadow the previous declaration of a different type of tag, and
    8842              :      this would not work properly if we return the reference found.
    8843              :      (For example, with "struct foo" in an outer scope, "union foo;"
    8844              :      must shadow that tag with a new one of union type.)  */
    8845      2165858 :   ret.kind = (ref
    8846      1082929 :               ? (have_std_attrs ? ctsk_tagref_attrs : ctsk_tagref)
    8847        94595 :               : (have_std_attrs ? ctsk_tagfirstref_attrs : ctsk_tagfirstref));
    8848      1082929 :   if (ref && TREE_CODE (ref) == code)
    8849              :     {
    8850       988300 :       decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8851       988300 :       if (C_TYPE_DEFINED_IN_STRUCT (ref)
    8852            5 :           && loc != UNKNOWN_LOCATION
    8853       988305 :           && warn_cxx_compat)
    8854              :         {
    8855            5 :           auto_diagnostic_group d;
    8856            5 :           switch (code)
    8857              :             {
    8858            2 :             case ENUMERAL_TYPE:
    8859            2 :               if (warning_at (loc, OPT_Wc___compat,
    8860              :                               ("enum type defined in struct or union "
    8861              :                                "is not visible in C++")))
    8862            2 :                   inform (refloc, "enum type defined here");
    8863              :               break;
    8864            2 :             case RECORD_TYPE:
    8865            2 :               if (warning_at (loc, OPT_Wc___compat,
    8866              :                               ("struct defined in struct or union "
    8867              :                                "is not visible in C++")))
    8868            2 :                 inform (refloc, "struct defined here");
    8869              :               break;
    8870            1 :             case UNION_TYPE:
    8871            1 :               if (warning_at (loc, OPT_Wc___compat,
    8872              :                               ("union defined in struct or union "
    8873              :                                "is not visible in C++")))
    8874            1 :                 inform (refloc, "union defined here");
    8875              :               break;
    8876            0 :             default:
    8877            0 :               gcc_unreachable();
    8878              :             }
    8879            5 :         }
    8880              : 
    8881       988300 :       ret.spec = ref;
    8882       988300 :       return ret;
    8883              :     }
    8884              : 
    8885              :   /* If no such tag is yet defined, create a forward-reference node
    8886              :      and record it as the "definition".
    8887              :      When a real declaration of this type is found,
    8888              :      the forward-reference will be altered into a real type.  */
    8889              : 
    8890        94629 :   ref = make_node (code);
    8891        94629 :   if (flag_isoc23 || code == ENUMERAL_TYPE)
    8892        72367 :     SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8893        72367 :   if (code == ENUMERAL_TYPE)
    8894              :     {
    8895              :       /* Give the type a default layout like unsigned int
    8896              :          to avoid crashing if it does not get defined.  */
    8897          251 :       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
    8898          251 :       SET_TYPE_ALIGN (ref, TYPE_ALIGN (unsigned_type_node));
    8899          251 :       TYPE_USER_ALIGN (ref) = 0;
    8900          251 :       TYPE_UNSIGNED (ref) = 1;
    8901          251 :       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
    8902          251 :       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
    8903          251 :       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
    8904          251 :       ENUM_FIXED_UNDERLYING_TYPE_P (ref) = has_enum_type_specifier;
    8905              :     }
    8906              : 
    8907        94629 :   pushtag (loc, name, ref);
    8908        94629 :   decl_attributes (&ref, attrs, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8909        94629 :   if (in_underspecified_init)
    8910            9 :     error_at (loc, "%qT declared in underspecified object initializer",
    8911              :               ref);
    8912              : 
    8913        94629 :   ret.spec = ref;
    8914        94629 :   return ret;
    8915              : }
    8916              : 
    8917              : /* Get the struct, enum or union (CODE says which) with tag NAME.
    8918              :    Define the tag as a forward-reference if it is not defined.
    8919              :    Return a tree for the type.  */
    8920              : 
    8921              : tree
    8922            0 : xref_tag (enum tree_code code, tree name)
    8923              : {
    8924            0 :   return parser_xref_tag (input_location, code, name, false, NULL_TREE,
    8925            0 :                           false).spec;
    8926              : }
    8927              : 
    8928              : /* Make sure that the tag NAME is defined *in the current scope*
    8929              :    at least as a forward reference.
    8930              :    LOC is the location of the struct's definition.
    8931              :    CODE says which kind of tag NAME ought to be.
    8932              : 
    8933              :    This stores the current value of the file static STRUCT_PARSE_INFO
    8934              :    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
    8935              :    new c_struct_parse_info structure.  The old value of
    8936              :    STRUCT_PARSE_INFO is restored in finish_struct.  */
    8937              : 
    8938              : tree
    8939      1177497 : start_struct (location_t loc, enum tree_code code, tree name,
    8940              :               class c_struct_parse_info **enclosing_struct_parse_info)
    8941              : {
    8942              :   /* If there is already a tag defined at this scope
    8943              :      (as a forward reference), just return it.  */
    8944              : 
    8945      1177497 :   tree ref = NULL_TREE;
    8946      1177497 :   location_t refloc = UNKNOWN_LOCATION;
    8947              : 
    8948      1177497 :   if (name != NULL_TREE)
    8949       484249 :     ref = lookup_tag (code, name, true, &refloc);
    8950              : 
    8951              :   /* For C23, even if we already have a completed definition,
    8952              :      we do not use it. We will check for consistency later.
    8953              :      If we are in a nested redefinition the type is not
    8954              :      complete. We will then detect this below.  */
    8955      1177497 :   if (flag_isoc23 && ref && TYPE_SIZE (ref))
    8956              :     ref = NULL_TREE;
    8957              : 
    8958      1177392 :   if (ref && TREE_CODE (ref) == code)
    8959              :     {
    8960        25112 :       if (TYPE_STUB_DECL (ref))
    8961        25112 :         refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
    8962              : 
    8963        25112 :       if (TYPE_SIZE (ref))
    8964              :         {
    8965           11 :           auto_diagnostic_group d;
    8966           11 :           if (code == UNION_TYPE)
    8967            2 :             error_at (loc, "redefinition of %<union %E%>", name);
    8968              :           else
    8969            9 :             error_at (loc, "redefinition of %<struct %E%>", name);
    8970           11 :           if (refloc != UNKNOWN_LOCATION)
    8971           11 :             inform (refloc, "originally defined here");
    8972              :           /* Don't create structures using a name already in use.  */
    8973           11 :           ref = NULL_TREE;
    8974           11 :         }
    8975        25101 :       else if (C_TYPE_BEING_DEFINED (ref))
    8976              :         {
    8977           17 :           if (code == UNION_TYPE)
    8978            1 :             error_at (loc, "nested redefinition of %<union %E%>", name);
    8979              :           else
    8980           16 :             error_at (loc, "nested redefinition of %<struct %E%>", name);
    8981              :           /* Don't bother to report "originally defined here" for a
    8982              :              nested redefinition; the original definition should be
    8983              :              obvious.  */
    8984              :           /* Don't create structures that contain themselves.  */
    8985              :           ref = NULL_TREE;
    8986              :         }
    8987              :     }
    8988              : 
    8989              :   /* Otherwise create a forward-reference just so the tag is in scope.  */
    8990              : 
    8991        25098 :   if (ref == NULL_TREE || TREE_CODE (ref) != code)
    8992              :     {
    8993      1152413 :       ref = make_node (code);
    8994      1152413 :       if (flag_isoc23)
    8995       923579 :         SET_TYPE_STRUCTURAL_EQUALITY (ref);
    8996      1152413 :       pushtag (loc, name, ref);
    8997              :     }
    8998              : 
    8999      1177497 :   C_TYPE_BEING_DEFINED (ref) = 1;
    9000      2385525 :   for (tree v = TYPE_MAIN_VARIANT (ref); v; v = TYPE_NEXT_VARIANT (v))
    9001      1208028 :     TYPE_PACKED (v) = flag_pack_struct;
    9002              : 
    9003      1177497 :   *enclosing_struct_parse_info = struct_parse_info;
    9004      1177497 :   struct_parse_info = new c_struct_parse_info ();
    9005      1177497 :   struct_parse_info->refloc = refloc;
    9006              : 
    9007              :   /* FIXME: This will issue a warning for a use of a type defined
    9008              :      within a statement expr used within sizeof, et. al.  This is not
    9009              :      terribly serious as C++ doesn't permit statement exprs within
    9010              :      sizeof anyhow.  */
    9011      1177497 :   if (warn_cxx_compat
    9012          574 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
    9013           10 :     warning_at (loc, OPT_Wc___compat,
    9014              :                 "defining type in %qs expression is invalid in C++",
    9015              :                 (in_sizeof ? "sizeof"
    9016            4 :                  : in_typeof ? "typeof"
    9017            1 :                  : in_alignof ? "alignof"
    9018              :                  : "_Countof"));
    9019              : 
    9020      1177497 :   if (in_underspecified_init)
    9021           18 :     error_at (loc, "%qT defined in underspecified object initializer", ref);
    9022              : 
    9023      1177497 :   return ref;
    9024              : }
    9025              : 
    9026              : /* Process the specs, declarator and width (NULL if omitted)
    9027              :    of a structure component, returning a FIELD_DECL node.
    9028              :    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
    9029              :    DECL_ATTRS is as for grokdeclarator.
    9030              : 
    9031              :    LOC is the location of the structure component.
    9032              : 
    9033              :    This is done during the parsing of the struct declaration.
    9034              :    The FIELD_DECL nodes are chained together and the lot of them
    9035              :    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
    9036              : 
    9037              : tree
    9038      4318639 : grokfield (location_t loc,
    9039              :            struct c_declarator *declarator, struct c_declspecs *declspecs,
    9040              :            tree width, tree *decl_attrs, tree *expr)
    9041              : {
    9042      4318639 :   tree value;
    9043              : 
    9044      4318639 :   if (declarator->kind == cdk_id && declarator->u.id.id == NULL_TREE
    9045        20648 :       && width == NULL_TREE)
    9046              :     {
    9047              :       /* This is an unnamed decl.
    9048              : 
    9049              :          If we have something of the form "union { list } ;" then this
    9050              :          is the anonymous union extension.  Similarly for struct.
    9051              : 
    9052              :          If this is something of the form "struct foo;", then
    9053              :            If MS or Plan 9 extensions are enabled, this is handled as
    9054              :              an anonymous struct.
    9055              :            Otherwise this is a forward declaration of a structure tag.
    9056              : 
    9057              :          If this is something of the form "foo;" and foo is a TYPE_DECL, then
    9058              :            If foo names a structure or union without a tag, then this
    9059              :              is an anonymous struct (this is permitted by C11).
    9060              :            If MS or Plan 9 extensions are enabled and foo names a
    9061              :              structure, then again this is an anonymous struct.
    9062              :            Otherwise this is an error.
    9063              : 
    9064              :          Oh what a horrid tangled web we weave.  I wonder if MS consciously
    9065              :          took this from Plan 9 or if it was an accident of implementation
    9066              :          that took root before someone noticed the bug...  */
    9067              : 
    9068        10908 :       tree type = declspecs->type;
    9069        10908 :       bool ok = false;
    9070              : 
    9071        10908 :       if (RECORD_OR_UNION_TYPE_P (type)
    9072        10902 :           && (flag_ms_extensions
    9073        10873 :               || flag_plan9_extensions
    9074        10842 :               || !declspecs->typedef_p))
    9075              :         {
    9076        10895 :           if (flag_ms_extensions || flag_plan9_extensions)
    9077              :             ok = true;
    9078        10835 :           else if (TYPE_NAME (type) == NULL)
    9079              :             ok = true;
    9080              :           else
    9081              :             ok = false;
    9082              :         }
    9083              :       if (!ok)
    9084              :         {
    9085           29 :           pedwarn (loc, 0, "declaration does not declare anything");
    9086           29 :           return NULL_TREE;
    9087              :         }
    9088        10879 :       if (flag_isoc99)
    9089        10857 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9090              :                      "ISO C99 doesn%'t support unnamed structs/unions");
    9091              :       else
    9092           22 :         pedwarn_c99 (loc, OPT_Wpedantic,
    9093              :                      "ISO C90 doesn%'t support unnamed structs/unions");
    9094              :     }
    9095              : 
    9096      4318610 :   value = grokdeclarator (declarator, declspecs, FIELD, false,
    9097      4318610 :                           width ? &width : NULL, decl_attrs, expr, NULL,
    9098              :                           DEPRECATED_NORMAL);
    9099              : 
    9100              :   /* When this field has name, its type is a top level type, we should
    9101              :      call verify_counted_by_for_top_anonymous_type.  */
    9102      4318610 :   if (DECL_NAME (value) != NULL_TREE
    9103      4318610 :       && declspecs->typespec_kind == ctsk_tagdef)
    9104       153015 :     verify_counted_by_for_top_anonymous_type (declspecs->type);
    9105              : 
    9106      4318610 :   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
    9107      4318610 :   DECL_INITIAL (value) = width;
    9108      4318610 :   if (width)
    9109        52580 :     SET_DECL_C_BIT_FIELD (value);
    9110              : 
    9111      4318610 :   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
    9112              :     {
    9113              :       /* If we currently have a binding for this field, set the
    9114              :          in_struct field in the binding, so that we warn about lookups
    9115              :          which find it.  */
    9116         1312 :       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
    9117         1312 :       if (b != NULL)
    9118              :         {
    9119              :           /* If the in_struct field is not yet set, push it on a list
    9120              :              to be cleared when this struct is finished.  */
    9121           93 :           if (!b->in_struct)
    9122              :             {
    9123           91 :               struct_parse_info->fields.safe_push (b);
    9124           91 :               b->in_struct = 1;
    9125              :             }
    9126              :         }
    9127              :     }
    9128              : 
    9129              :   return value;
    9130              : }
    9131              : 
    9132              : /* Subroutine of detect_field_duplicates: return whether X and Y,
    9133              :    which are both fields in the same struct, have duplicate field
    9134              :    names.  */
    9135              : 
    9136              : static bool
    9137      4305173 : is_duplicate_field (tree x, tree y)
    9138              : {
    9139      4305173 :   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
    9140              :     return true;
    9141              : 
    9142              :   /* When using -fplan9-extensions, an anonymous field whose name is a
    9143              :      typedef can duplicate a field name.  */
    9144      4305172 :   if (flag_plan9_extensions
    9145      4305172 :       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
    9146              :     {
    9147            0 :       tree xt, xn, yt, yn;
    9148              : 
    9149            0 :       xt = TREE_TYPE (x);
    9150            0 :       if (DECL_NAME (x) != NULL_TREE)
    9151            0 :         xn = DECL_NAME (x);
    9152            0 :       else if (RECORD_OR_UNION_TYPE_P (xt)
    9153            0 :                && TYPE_NAME (xt) != NULL_TREE
    9154            0 :                && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
    9155            0 :         xn = DECL_NAME (TYPE_NAME (xt));
    9156              :       else
    9157              :         xn = NULL_TREE;
    9158              : 
    9159            0 :       yt = TREE_TYPE (y);
    9160            0 :       if (DECL_NAME (y) != NULL_TREE)
    9161            0 :         yn = DECL_NAME (y);
    9162            0 :       else if (RECORD_OR_UNION_TYPE_P (yt)
    9163            0 :                && TYPE_NAME (yt) != NULL_TREE
    9164            0 :                && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
    9165            0 :         yn = DECL_NAME (TYPE_NAME (yt));
    9166              :       else
    9167              :         yn = NULL_TREE;
    9168              : 
    9169            0 :       if (xn != NULL_TREE && xn == yn)
    9170            0 :         return true;
    9171              :     }
    9172              : 
    9173              :   return false;
    9174              : }
    9175              : 
    9176              : /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
    9177              :    to HTAB, giving errors for any duplicates.  */
    9178              : 
    9179              : static void
    9180        80650 : detect_field_duplicates_hash (tree fieldlist,
    9181              :                               hash_table<nofree_ptr_hash <tree_node> > *htab)
    9182              : {
    9183        80650 :   tree x, y;
    9184        80650 :   tree_node **slot;
    9185              : 
    9186      1415030 :   for (x = fieldlist; x ; x = DECL_CHAIN (x))
    9187      1334380 :     if ((y = DECL_NAME (x)) != NULL_TREE)
    9188              :       {
    9189      1313750 :         slot = htab->find_slot (y, INSERT);
    9190      1313750 :         if (*slot)
    9191              :           {
    9192           15 :             error ("duplicate member %q+D", x);
    9193           15 :             DECL_NAME (x) = NULL_TREE;
    9194              :           }
    9195      1313750 :         *slot = y;
    9196              :       }
    9197        20630 :     else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9198              :       {
    9199        11606 :         detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
    9200              : 
    9201              :         /* When using -fplan9-extensions, an anonymous field whose
    9202              :            name is a typedef can duplicate a field name.  */
    9203        11606 :         if (flag_plan9_extensions
    9204           31 :             && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9205        11636 :             && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
    9206              :           {
    9207           10 :             tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
    9208           10 :             slot = htab->find_slot (xn, INSERT);
    9209           10 :             if (*slot)
    9210            0 :               error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
    9211           10 :             *slot = xn;
    9212              :           }
    9213              :       }
    9214        80650 : }
    9215              : 
    9216              : /* Generate an error for any duplicate field names in FIELDLIST.  Munge
    9217              :    the list such that this does not present a problem later.  */
    9218              : 
    9219              : static void
    9220      1177591 : detect_field_duplicates (tree fieldlist)
    9221              : {
    9222      1177591 :   tree x, y;
    9223      1177591 :   int timeout = 10;
    9224              : 
    9225              :   /* If the struct is the list of instance variables of an Objective-C
    9226              :      class, then we need to check all the instance variables of
    9227              :      superclasses when checking for duplicates (since you can't have
    9228              :      an instance variable in a subclass with the same name as an
    9229              :      instance variable in a superclass).  We pass on this job to the
    9230              :      Objective-C compiler.  objc_detect_field_duplicates() will return
    9231              :      false if we are not checking the list of instance variables and
    9232              :      the C frontend should proceed with the standard field duplicate
    9233              :      checks.  If we are checking the list of instance variables, the
    9234              :      ObjC frontend will do the check, emit the errors if needed, and
    9235              :      then return true.  */
    9236      1177591 :   if (c_dialect_objc ())
    9237            0 :     if (objc_detect_field_duplicates (false))
    9238              :       return;
    9239              : 
    9240              :   /* First, see if there are more than "a few" fields.
    9241              :      This is trivially true if there are zero or one fields.  */
    9242      1177591 :   if (!fieldlist || !DECL_CHAIN (fieldlist))
    9243              :     return;
    9244              :   x = fieldlist;
    9245      3471418 :   do {
    9246      3471418 :     timeout--;
    9247      3471418 :     if (DECL_NAME (x) == NULL_TREE
    9248      3471418 :         && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9249              :       timeout = 0;
    9250      3471418 :     x = DECL_CHAIN (x);
    9251      3471418 :   } while (timeout > 0 && x);
    9252              : 
    9253              :   /* If there were "few" fields and no anonymous structures or unions,
    9254              :      avoid the overhead of allocating a hash table.  Instead just do
    9255              :      the nested traversal thing.  */
    9256       972168 :   if (timeout > 0)
    9257              :     {
    9258      2817387 :       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
    9259              :         /* When using -fplan9-extensions, we can have duplicates
    9260              :            between typedef names and fields.  */
    9261      1914263 :         if (DECL_NAME (x)
    9262      1914263 :             || (flag_plan9_extensions
    9263            0 :                 && DECL_NAME (x) == NULL_TREE
    9264            0 :                 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9265            0 :                 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
    9266            0 :                 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
    9267              :           {
    9268      6218900 :             for (y = fieldlist; y != x; y = TREE_CHAIN (y))
    9269      4305173 :               if (is_duplicate_field (y, x))
    9270              :                 {
    9271            1 :                   error ("duplicate member %q+D", x);
    9272            1 :                   DECL_NAME (x) = NULL_TREE;
    9273              :                 }
    9274              :           }
    9275              :     }
    9276              :   else
    9277              :     {
    9278        69044 :       hash_table<nofree_ptr_hash <tree_node> > htab (37);
    9279        69044 :       detect_field_duplicates_hash (fieldlist, &htab);
    9280        69044 :     }
    9281              : }
    9282              : 
    9283              : /* Finish up struct info used by -Wc++-compat.  */
    9284              : 
    9285              : static void
    9286          575 : warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code,
    9287              :                                location_t record_loc)
    9288              : {
    9289          575 :   unsigned int ix;
    9290          575 :   tree x;
    9291          575 :   struct c_binding *b;
    9292              : 
    9293          575 :   if (fieldlist == NULL_TREE)
    9294              :     {
    9295            9 :       if (code == RECORD_TYPE)
    9296            6 :         warning_at (record_loc, OPT_Wc___compat,
    9297              :                     "empty struct has size 0 in C, size 1 in C++");
    9298              :       else
    9299            3 :         warning_at (record_loc, OPT_Wc___compat,
    9300              :                     "empty union has size 0 in C, size 1 in C++");
    9301              :     }
    9302              : 
    9303              :   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
    9304              :      the current struct.  We do this now at the end of the struct
    9305              :      because the flag is used to issue visibility warnings, and we
    9306              :      only want to issue those warnings if the type is referenced
    9307              :      outside of the struct declaration.  */
    9308          623 :   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
    9309           48 :     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
    9310              : 
    9311              :   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
    9312              :      typedefs used when declaring fields in this struct.  If the name
    9313              :      of any of the fields is also a typedef name then the struct would
    9314              :      not parse in C++, because the C++ lookup rules say that the
    9315              :      typedef name would be looked up in the context of the struct, and
    9316              :      would thus be the field rather than the typedef.  */
    9317          575 :   if (!struct_parse_info->typedefs_seen.is_empty ()
    9318           67 :       && fieldlist != NULL_TREE)
    9319              :     {
    9320              :       /* Use a hash_set<tree> using the name of the typedef.  We can use
    9321              :          a hash_set<tree> because identifiers are interned.  */
    9322           67 :       hash_set<tree> tset;
    9323              : 
    9324          254 :       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
    9325          120 :         tset.add (DECL_NAME (x));
    9326              : 
    9327          387 :       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
    9328              :         {
    9329          320 :           if (DECL_NAME (x) != NULL_TREE
    9330          320 :               && tset.contains (DECL_NAME (x)))
    9331              :             {
    9332            2 :               warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
    9333              :                           "using %qD as both field and typedef name is "
    9334              :                           "invalid in C++", x);
    9335              :               /* FIXME: It would be nice to report the location where
    9336              :                  the typedef name is used.  */
    9337              :             }
    9338              :         }
    9339           67 :     }
    9340              : 
    9341              :   /* For each field which has a binding and which was not defined in
    9342              :      an enclosing struct, clear the in_struct field.  */
    9343          666 :   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
    9344           91 :     b->in_struct = 0;
    9345          575 : }
    9346              : 
    9347              : /* Function to help qsort sort FIELD_DECLs by name order.  */
    9348              : 
    9349              : static int
    9350     20110521 : field_decl_cmp (const void *x_p, const void *y_p)
    9351              : {
    9352     20110521 :   const tree *const x = (const tree *) x_p;
    9353     20110521 :   const tree *const y = (const tree *) y_p;
    9354              : 
    9355     20110521 :   if (DECL_NAME (*x) == DECL_NAME (*y))
    9356              :     /* A nontype is "greater" than a type.  */
    9357            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
    9358     20110521 :   if (DECL_NAME (*x) == NULL_TREE)
    9359              :     return -1;
    9360     20110521 :   if (DECL_NAME (*y) == NULL_TREE)
    9361              :     return 1;
    9362     20110521 :   if (DECL_NAME (*x) < DECL_NAME (*y))
    9363      9903458 :     return -1;
    9364              :   return 1;
    9365              : }
    9366              : 
    9367              : /* If this structure or union completes the type of any previous
    9368              :    variable declaration, lay it out and output its rtl.  */
    9369              : static void
    9370      1357972 : finish_incomplete_vars (tree incomplete_vars, bool toplevel)
    9371              : {
    9372      1358121 :   for (tree x = incomplete_vars; x; x = TREE_CHAIN (x))
    9373              :     {
    9374          149 :       tree decl = TREE_VALUE (x);
    9375          149 :       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
    9376            0 :         layout_array_type (TREE_TYPE (decl));
    9377          149 :       if (TREE_CODE (decl) != TYPE_DECL)
    9378              :         {
    9379          149 :           relayout_decl (decl);
    9380          149 :           if (c_dialect_objc ())
    9381            0 :             objc_check_decl (decl);
    9382          149 :           rest_of_decl_compilation (decl, toplevel, 0);
    9383              :         }
    9384              :     }
    9385      1357972 : }
    9386              : 
    9387              : /* Determine whether the FIELD_DECL X is a flexible array member according to
    9388              :    the following info:
    9389              :   A. whether the FIELD_DECL X is the last field of the DECL_CONTEXT;
    9390              :   B. whether the FIELD_DECL is an array that is declared as "[]", "[0]",
    9391              :      or "[1]";
    9392              :   C. flag_strict_flex_arrays;
    9393              :   D. the attribute strict_flex_array that is attached to the field
    9394              :      if presenting.
    9395              :   Return TRUE when it's a flexible array member, FALSE otherwise.  */
    9396              : 
    9397              : static bool
    9398      4318690 : is_flexible_array_member_p (bool is_last_field,
    9399              :                             tree x)
    9400              : {
    9401              :   /* If not the last field, return false.  */
    9402      4318690 :   if (!is_last_field)
    9403              :     return false;
    9404              : 
    9405              :   /* If not an array field, return false.  */
    9406      1651599 :   if (TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    9407              :     return false;
    9408              : 
    9409       533378 :   bool is_zero_length_array = zero_length_array_type_p (TREE_TYPE (x));
    9410       533378 :   bool is_one_element_array = one_element_array_type_p (TREE_TYPE (x));
    9411       533378 :   bool is_flexible_array = c_flexible_array_member_type_p (TREE_TYPE (x));
    9412              : 
    9413       533378 :   unsigned int strict_flex_array_level = c_strict_flex_array_level_of (x);
    9414              : 
    9415       533378 :   switch (strict_flex_array_level)
    9416              :     {
    9417              :       case 0:
    9418              :         /* Default, all trailing arrays are flexible array members.  */
    9419              :         return true;
    9420           77 :       case 1:
    9421              :         /* Level 1: all "[1]", "[0]", and "[]" are flexible array members.  */
    9422           77 :         if (is_one_element_array)
    9423              :           return true;
    9424              :         /* FALLTHROUGH.  */
    9425          141 :       case 2:
    9426              :         /* Level 2: all "[0]", and "[]" are flexible array members.  */
    9427          141 :         if (is_zero_length_array)
    9428              :           return true;
    9429              :         /* FALLTHROUGH.  */
    9430          201 :       case 3:
    9431              :         /* Level 3: Only "[]" are flexible array members.  */
    9432          201 :         if (is_flexible_array)
    9433              :           return true;
    9434              :         break;
    9435            0 :       default:
    9436            0 :         gcc_unreachable ();
    9437              :     }
    9438              :   return false;
    9439              : }
    9440              : 
    9441              : /* Recompute TYPE_CANONICAL for variants of the type including qualified
    9442              :    versions of the type and related pointer types after an aggregate type
    9443              :    has been finalized.
    9444              :    Will not update array types, pointers to array types, function
    9445              :    types and other derived types created while the type was still
    9446              :    incomplete, those will remain TYPE_STRUCTURAL_EQUALITY_P.  */
    9447              : 
    9448              : static void
    9449      1193921 : c_update_type_canonical (tree t)
    9450              : {
    9451      1193921 :   gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t && !TYPE_QUALS (t));
    9452      2414497 :   for (tree x = t, l = NULL_TREE; x; l = x, x = TYPE_NEXT_VARIANT (x))
    9453              :     {
    9454      1220576 :       if (x != t && TYPE_STRUCTURAL_EQUALITY_P (x))
    9455              :         {
    9456        26655 :           if (!TYPE_QUALS (x))
    9457        26029 :             TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
    9458              :           else
    9459              :             {
    9460          626 :               tree
    9461          626 :                 c = c_build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
    9462          626 :               if (TYPE_STRUCTURAL_EQUALITY_P (c))
    9463              :                 {
    9464          614 :                   gcc_checking_assert (TYPE_CANONICAL (t) == t);
    9465          614 :                   if (c == x)
    9466          614 :                     TYPE_CANONICAL (x) = x;
    9467              :                   else
    9468              :                     {
    9469              :                       /* build_qualified_type for this function unhelpfully
    9470              :                          moved c from some later spot in TYPE_MAIN_VARIANT (t)
    9471              :                          chain to right after t (or created it there).  Move
    9472              :                          it right before x and process c and then x.  */
    9473            0 :                       gcc_checking_assert (TYPE_NEXT_VARIANT (t) == c);
    9474            0 :                       if (l != t)
    9475              :                         {
    9476            0 :                           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (c);
    9477            0 :                           TYPE_NEXT_VARIANT (l) = c;
    9478            0 :                           TYPE_NEXT_VARIANT (c) = x;
    9479              :                         }
    9480            0 :                       TYPE_CANONICAL (c) = c;
    9481            0 :                       x = c;
    9482              :                     }
    9483              :                 }
    9484              :               else
    9485           12 :                 TYPE_CANONICAL (x) = TYPE_CANONICAL (c);
    9486              :             }
    9487              :         }
    9488      1193921 :       else if (x != t)
    9489            0 :         continue;
    9490      1289492 :       for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p))
    9491              :         {
    9492        68916 :           if (!TYPE_STRUCTURAL_EQUALITY_P (p))
    9493            0 :             continue;
    9494        68916 :           if (TYPE_CANONICAL (x) != x || TYPE_REF_CAN_ALIAS_ALL (p))
    9495         2610 :             TYPE_CANONICAL (p)
    9496         5220 :               = c_build_pointer_type_for_mode (TYPE_CANONICAL (x), TYPE_MODE (p),
    9497              :                                                false);
    9498              :           else
    9499        66306 :             TYPE_CANONICAL (p) = p;
    9500        68916 :           c_update_type_canonical (p);
    9501              :         }
    9502              :     }
    9503      1193921 : }
    9504              : 
    9505              : /* Verify the argument of the counted_by attribute of each field of
    9506              :    the containing structure, OUTMOST_STRUCT_TYPE, including its inner
    9507              :    anonymous struct/union, Report error and remove the corresponding
    9508              :    attribute when it's not.  */
    9509              : 
    9510              : static void
    9511          354 : verify_counted_by_attribute (tree outmost_struct_type,
    9512              :                              tree cur_struct_type)
    9513              : {
    9514         1178 :   for (tree field = TYPE_FIELDS (cur_struct_type); field;
    9515          824 :        field = TREE_CHAIN (field))
    9516              :     {
    9517          824 :       if (c_flexible_array_member_type_p (TREE_TYPE (field))
    9518          824 :            || TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE)
    9519              :         {
    9520          304 :           tree attr_counted_by = lookup_attribute ("counted_by",
    9521          304 :                                                    DECL_ATTRIBUTES (field));
    9522              : 
    9523          304 :           if (!attr_counted_by)
    9524            1 :             continue;
    9525              : 
    9526              :           /* If there is an counted_by attribute attached to the field,
    9527              :              verify it.  */
    9528              : 
    9529          303 :           tree fieldname = TREE_VALUE (TREE_VALUE (attr_counted_by));
    9530              : 
    9531              :           /* Verify the argument of the attrbute is a valid field of the
    9532              :              containing structure.  */
    9533              : 
    9534          303 :           tree counted_by_field = lookup_field (outmost_struct_type,
    9535              :                                                 fieldname);
    9536              : 
    9537              :           /* Error when the field is not found in the containing structure
    9538              :              and remove the corresponding counted_by attribute from the
    9539              :              field_decl.  */
    9540          303 :           if (!counted_by_field)
    9541              :             {
    9542           24 :               error_at (DECL_SOURCE_LOCATION (field),
    9543              :                     "argument %qE to the %<counted_by%> attribute"
    9544              :                     " is not a field declaration in the same structure"
    9545              :                     " as %qD", fieldname, field);
    9546           24 :               DECL_ATTRIBUTES (field)
    9547           48 :                 = remove_attribute ("counted_by", DECL_ATTRIBUTES (field));
    9548              :             }
    9549              :           else
    9550              :           /* Error when the field is not with an integer type.  */
    9551              :             {
    9552          400 :               while (TREE_CHAIN (counted_by_field))
    9553          121 :                 counted_by_field = TREE_CHAIN (counted_by_field);
    9554          279 :               tree real_field = TREE_VALUE (counted_by_field);
    9555              : 
    9556          279 :               if (!INTEGRAL_TYPE_P (TREE_TYPE (real_field)))
    9557              :                 {
    9558            6 :                   error_at (DECL_SOURCE_LOCATION (field),
    9559              :                         "argument %qE to the %<counted_by%> attribute"
    9560              :                         " is not a field declaration with an integer type",
    9561              :                         fieldname);
    9562            6 :                   DECL_ATTRIBUTES (field)
    9563           12 :                     = remove_attribute ("counted_by",
    9564            6 :                                     DECL_ATTRIBUTES (field));
    9565              :                 }
    9566              :             }
    9567              :         }
    9568          983 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    9569          571 :                && (DECL_NAME (field) == NULL_TREE))
    9570          108 :         verify_counted_by_attribute (outmost_struct_type, TREE_TYPE (field));
    9571              :     }
    9572          354 : }
    9573              : 
    9574              : /* Caller should make sure the TYPE is a top-level type (i.e. not being
    9575              :    nested in other structure/uniona). For such type, verify its counted_by
    9576              :    if it is an anonymous structure/union.  */
    9577              : 
    9578              : void
    9579      1347032 : verify_counted_by_for_top_anonymous_type (tree type)
    9580              : {
    9581      1347032 :   if (!RECORD_OR_UNION_TYPE_P (type))
    9582              :     return;
    9583              : 
    9584      1166658 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (type)
    9585      1166658 :       && c_type_tag (type) == NULL_TREE)
    9586           48 :     verify_counted_by_attribute (type, type);
    9587              : }
    9588              : 
    9589              : /* TYPE is a struct or union that we're applying may_alias to after the body is
    9590              :    parsed.  Fixup any POINTER_TO types.  */
    9591              : 
    9592              : static void
    9593          353 : c_fixup_may_alias (tree type)
    9594              : {
    9595          418 :   for (tree t = TYPE_POINTER_TO (type); t; t = TYPE_NEXT_PTR_TO (t))
    9596          190 :     for (tree v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    9597          125 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    9598          353 : }
    9599              : 
    9600              : /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
    9601              :    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
    9602              :    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
    9603              :    ATTRIBUTES are attributes to be applied to the structure.
    9604              : 
    9605              :    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
    9606              :    the struct was started.  */
    9607              : 
    9608              : tree
    9609      1177591 : finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
    9610              :                class c_struct_parse_info *enclosing_struct_parse_info,
    9611              :                tree *expr)
    9612              : {
    9613      1177591 :   tree x;
    9614      1177591 :   bool toplevel = file_scope == current_scope;
    9615              : 
    9616              :   /* If this type was previously laid out as a forward reference,
    9617              :      make sure we lay it out again.  */
    9618              : 
    9619      1177591 :   TYPE_SIZE (t) = NULL_TREE;
    9620              : 
    9621      1177591 :   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    9622              : 
    9623      1177591 :   if (pedantic)
    9624              :     {
    9625         7386 :       for (x = fieldlist; x; x = DECL_CHAIN (x))
    9626              :         {
    9627         7367 :           if (DECL_NAME (x) != NULL_TREE)
    9628              :             break;
    9629           25 :           if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9630              :             break;
    9631              :         }
    9632              : 
    9633         7368 :       if (x == NULL_TREE)
    9634              :         {
    9635           19 :           if (TREE_CODE (t) == UNION_TYPE)
    9636              :             {
    9637            5 :               if (fieldlist)
    9638            2 :                 pedwarn (loc, OPT_Wpedantic, "union has no named members");
    9639              :               else
    9640            3 :                 pedwarn (loc, OPT_Wpedantic, "union has no members");
    9641              :             }
    9642              :           else
    9643              :             {
    9644           14 :               if (fieldlist)
    9645            3 :                 pedwarn (loc, OPT_Wpedantic, "struct has no named members");
    9646              :               else
    9647           11 :                 pedwarn (loc, OPT_Wpedantic, "struct has no members");
    9648              :             }
    9649              :         }
    9650              :     }
    9651              : 
    9652              :   /* Install struct as DECL_CONTEXT of each field decl.
    9653              :      Also process specified field sizes, found in the DECL_INITIAL,
    9654              :      storing 0 there after the type has been changed to precision equal
    9655              :      to its width, rather than the precision of the specified standard
    9656              :      type.  (Correct layout requires the original type to have been preserved
    9657              :      until now.)  */
    9658              : 
    9659              :   bool saw_named_field = false;
    9660      5496321 :   for (x = fieldlist; x; x = DECL_CHAIN (x))
    9661              :     {
    9662              :       /* Whether this field is the last field of the structure or union.
    9663              :          for UNION, any field is the last field of it.  */
    9664      4318730 :       bool is_last_field = (DECL_CHAIN (x) == NULL_TREE)
    9665      4318730 :                             || (TREE_CODE (t) == UNION_TYPE);
    9666              : 
    9667      4318730 :       if (TREE_TYPE (x) == error_mark_node)
    9668           40 :         continue;
    9669              : 
    9670      4318690 :       DECL_CONTEXT (x) = t;
    9671              : 
    9672      4318690 :       tree t1 = strip_array_types (TREE_TYPE (x));
    9673              :       /* If any field is const, the structure type is pseudo-const.  */
    9674      4318690 :       if (TREE_READONLY (x))
    9675        64244 :         C_TYPE_FIELDS_READONLY (t) = 1;
    9676              :       else
    9677              :         {
    9678              :           /* A field that is pseudo-const makes the structure likewise.  */
    9679      4254446 :           if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1))
    9680          641 :             C_TYPE_FIELDS_READONLY (t) = 1;
    9681              :         }
    9682              : 
    9683              :       /* Any field that is volatile means variables of this type must be
    9684              :          treated in some ways as volatile.  */
    9685      4318690 :       if (TREE_THIS_VOLATILE (x))
    9686              :         {
    9687          475 :           C_TYPE_FIELDS_VOLATILE (t) = 1;
    9688          475 :           C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9689              :         }
    9690              : 
    9691              :       /* Any field that is volatile, restrict-qualified or atomic
    9692              :          means the type cannot be used for a constexpr object.  */
    9693      4318690 :       if (TYPE_QUALS (t1)
    9694      4318690 :           & (TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC))
    9695         1460 :         C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9696      4317230 :       else if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_NON_CONSTEXPR (t1))
    9697          179 :             C_TYPE_FIELDS_NON_CONSTEXPR (t) = 1;
    9698              : 
    9699              :       /* Any field of nominal variable size implies structure is too.  */
    9700      4318690 :       if (C_DECL_VARIABLE_SIZE (x))
    9701          651 :         C_TYPE_VARIABLE_SIZE (t) = 1;
    9702              : 
    9703              :       /* If any field is variably modified, record this fact. */
    9704      4318690 :       if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (x)))
    9705          709 :         C_TYPE_VARIABLY_MODIFIED (t) = 1;
    9706              : 
    9707      4318690 :       if (DECL_C_BIT_FIELD (x))
    9708              :         {
    9709        52589 :           unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
    9710        52589 :           DECL_SIZE (x) = bitsize_int (width);
    9711        52589 :           DECL_BIT_FIELD (x) = 1;
    9712              :         }
    9713              : 
    9714      4318690 :       if (TYPE_PACKED (t)
    9715      4324243 :           && (DECL_BIT_FIELD (x)
    9716         3235 :               || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
    9717         4442 :         DECL_PACKED (x) = 1;
    9718              : 
    9719              :       /* Detect flexible array member in an invalid context.  */
    9720      4318690 :       if (c_flexible_array_member_type_p (TREE_TYPE (x)))
    9721              :         {
    9722        85987 :           if (TREE_CODE (t) == UNION_TYPE)
    9723           31 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9724              :                      "flexible array member in union is a GCC extension");
    9725        85956 :           else if (!is_last_field)
    9726              :             {
    9727            3 :               error_at (DECL_SOURCE_LOCATION (x),
    9728              :                         "flexible array member not at end of struct");
    9729            3 :               TREE_TYPE (x) = error_mark_node;
    9730              :             }
    9731        85953 :           else if (!saw_named_field)
    9732           35 :             pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9733              :                      "flexible array member in a struct with no named "
    9734              :                      "members is a GCC extension");
    9735        85987 :           if (lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9736          133 :             C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9737              :         }
    9738              : 
    9739      4318690 :       if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE
    9740      4318690 :           && lookup_attribute ("counted_by", DECL_ATTRIBUTES (x)))
    9741          170 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9742              : 
    9743              :       /* If the field is an anonymous structure that includes a field
    9744              :          with counted_by attribute, this structure should also be marked
    9745              :          too.  */
    9746      8261597 :       if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9747       466147 :           && C_TYPE_FIELDS_HAS_COUNTED_BY (TREE_TYPE (x))
    9748           18 :           && DECL_NAME (x) == NULL_TREE
    9749      4318703 :           && c_type_tag (TREE_TYPE (x)) == NULL_TREE)
    9750           12 :         C_TYPE_FIELDS_HAS_COUNTED_BY (t) = 1;
    9751              : 
    9752        25344 :       if (pedantic && TREE_CODE (t) == RECORD_TYPE
    9753      4339771 :           && flexible_array_type_p (TREE_TYPE (x)))
    9754           18 :         pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
    9755              :                  "invalid use of structure with flexible array member");
    9756              : 
    9757              :       /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x.  */
    9758      4318690 :       DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x);
    9759              : 
    9760              :       /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t.
    9761              :          when x is an array and is the last field.
    9762              :          There is only one last_field for a structure type, but there might
    9763              :          be multiple last_fields for a union type, therefore we should ORed
    9764              :          the result for multiple last_fields.  */
    9765      4318690 :       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
    9766       705941 :         TYPE_INCLUDES_FLEXARRAY (t)
    9767      1411882 :           |= is_last_field && c_flexible_array_member_type_p (TREE_TYPE (x));
    9768              :       /* Recursively set TYPE_INCLUDES_FLEXARRAY for the context of x, t
    9769              :          when x is an union or record and is the last field.  */
    9770      3612749 :       else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9771       466147 :         TYPE_INCLUDES_FLEXARRAY (t)
    9772       932294 :           |= is_last_field && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x));
    9773              : 
    9774      4318690 :       if (warn_flex_array_member_not_at_end
    9775           56 :           && !is_last_field
    9776           22 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
    9777      4318702 :           && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x)))
    9778            5 :         warning_at (DECL_SOURCE_LOCATION (x),
    9779            5 :                     OPT_Wflex_array_member_not_at_end,
    9780              :                     "structure containing a flexible array member"
    9781              :                     " is not at the end of another structure");
    9782              : 
    9783      4318690 :       if (DECL_NAME (x)
    9784      4318690 :           || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
    9785              :         saw_named_field = true;
    9786              : 
    9787      7931439 :       if (AGGREGATE_TYPE_P (TREE_TYPE (x))
    9788      4784837 :           && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
    9789       448763 :         TYPE_TYPELESS_STORAGE (t) = true;
    9790              :     }
    9791              : 
    9792      1177591 :   detect_field_duplicates (fieldlist);
    9793              : 
    9794              :   /* Now we have the nearly final fieldlist.  Record it,
    9795              :      then lay out the structure or union (including the fields).  */
    9796              : 
    9797      1177591 :   TYPE_FIELDS (t) = fieldlist;
    9798              : 
    9799      1177591 :   maybe_apply_pragma_scalar_storage_order (t);
    9800              : 
    9801      1177591 :   layout_type (t);
    9802              : 
    9803      1177591 :   if (TYPE_SIZE_UNIT (t)
    9804      1177591 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    9805      1176995 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    9806      2354586 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    9807            1 :     error ("type %qT is too large", t);
    9808              : 
    9809              :   /* Give bit-fields their proper types and rewrite the type of array fields
    9810              :      with scalar component if the enclosing type has reverse storage order.  */
    9811      5496321 :   for (tree field = fieldlist; field; field = DECL_CHAIN (field))
    9812              :     {
    9813      4318730 :       if (TREE_CODE (field) == FIELD_DECL
    9814      4318730 :           && DECL_INITIAL (field)
    9815      4371329 :           && TREE_TYPE (field) != error_mark_node)
    9816              :         {
    9817        52589 :           unsigned HOST_WIDE_INT width
    9818        52589 :             = tree_to_uhwi (DECL_INITIAL (field));
    9819        52589 :           tree type = TREE_TYPE (field);
    9820        52589 :           if (VECTOR_TYPE_P (type))
    9821              :             {
    9822            2 :               error_at (DECL_SOURCE_LOCATION (field),
    9823              :                         "bit-field %qD has invalid type", field);
    9824            2 :               type = TREE_TYPE (type);
    9825            2 :               TREE_TYPE (field) = type;
    9826              :             }
    9827        52589 :           if (width != TYPE_PRECISION (type))
    9828              :             {
    9829        37889 :               if (TREE_CODE (type) == BITINT_TYPE
    9830        37959 :                   && width >= (TYPE_UNSIGNED (type) ? 1 : 2))
    9831          161 :                 TREE_TYPE (field)
    9832          322 :                   = build_bitint_type (width, TYPE_UNSIGNED (type));
    9833              :               else
    9834        37728 :                 TREE_TYPE (field)
    9835        37728 :                   = c_build_bitfield_integer_type (width,
    9836        37728 :                                                    TYPE_UNSIGNED (type));
    9837        37889 :               if (tree attr = c_hardbool_type_attr (type))
    9838          281 :                 decl_attributes (&TREE_TYPE (field),
    9839              :                                  copy_list (attr),
    9840              :                                  0, NULL_TREE);
    9841        37889 :               SET_DECL_MODE (field, TYPE_MODE (TREE_TYPE (field)));
    9842              :             }
    9843        52589 :           DECL_INITIAL (field) = NULL_TREE;
    9844              :         }
    9845      4266141 :       else if (TYPE_REVERSE_STORAGE_ORDER (t)
    9846          693 :                && TREE_CODE (field) == FIELD_DECL
    9847      4266834 :                && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
    9848              :         {
    9849          106 :           tree ftype = TREE_TYPE (field);
    9850          106 :           tree ctype = strip_array_types (ftype);
    9851          106 :           if (!RECORD_OR_UNION_TYPE_P (ctype) && TYPE_MODE (ctype) != QImode)
    9852              :             {
    9853           93 :               tree fmain_type = TYPE_MAIN_VARIANT (ftype);
    9854           93 :               tree *typep = &fmain_type;
    9855           95 :               do {
    9856           95 :                 *typep = build_distinct_type_copy (*typep);
    9857           95 :                 TYPE_REVERSE_STORAGE_ORDER (*typep) = 1;
    9858           95 :                 typep = &TREE_TYPE (*typep);
    9859           95 :               } while (TREE_CODE (*typep) == ARRAY_TYPE);
    9860           93 :               TREE_TYPE (field)
    9861          186 :                 = c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
    9862              :             }
    9863              :         }
    9864              : 
    9865              :       /* Warn on problematic type punning for storage order purposes.  */
    9866      4318730 :       if (TREE_CODE (t) == UNION_TYPE
    9867       853166 :           && TREE_CODE (field) == FIELD_DECL
    9868      5171896 :           && AGGREGATE_TYPE_P (TREE_TYPE (field)))
    9869              :         {
    9870       423797 :           tree ftype = TREE_TYPE (field);
    9871       423797 :           if (TREE_CODE (ftype) == ARRAY_TYPE)
    9872       312249 :             ftype = strip_array_types (ftype);
    9873       423797 :           if (RECORD_OR_UNION_TYPE_P (ftype)
    9874       423797 :               && TYPE_REVERSE_STORAGE_ORDER (ftype)
    9875       112042 :                  != TYPE_REVERSE_STORAGE_ORDER (t))
    9876            1 :             warning_at (DECL_SOURCE_LOCATION (field),
    9877            1 :                         OPT_Wscalar_storage_order,
    9878              :                         "type punning toggles scalar storage order");
    9879              :         }
    9880              :     }
    9881              : 
    9882              :   /* Now we have the truly final field list.
    9883              :      Store it in this type and in the variants.  */
    9884              : 
    9885      1177591 :   TYPE_FIELDS (t) = fieldlist;
    9886              : 
    9887              :   /* If there are lots of fields, sort so we can look through them fast.
    9888              :      We arbitrarily consider 16 or more elts to be "a lot".  */
    9889              : 
    9890      1177591 :   {
    9891      1177591 :     int len = 0;
    9892              : 
    9893      5054773 :     for (x = fieldlist; x; x = DECL_CHAIN (x))
    9894              :       {
    9895      3904969 :         if (len > 15 || DECL_NAME (x) == NULL)
    9896              :           break;
    9897      3877182 :         len += 1;
    9898              :       }
    9899              : 
    9900      1177591 :     if (len > 15)
    9901              :       {
    9902        22630 :         tree *field_array;
    9903        22630 :         struct lang_type *space;
    9904        22630 :         struct sorted_fields_type *space2;
    9905              : 
    9906        22630 :         len += list_length (x);
    9907              : 
    9908              :         /* Use the same allocation policy here that make_node uses, to
    9909              :            ensure that this lives as long as the rest of the struct decl.
    9910              :            All decls in an inline function need to be saved.  */
    9911              : 
    9912        22630 :         space = ((struct lang_type *)
    9913        22630 :                  ggc_internal_cleared_alloc (c_dialect_objc ()
    9914              :                                              ? sizeof (struct lang_type)
    9915              :                                              : offsetof (struct lang_type,
    9916              :                                                          info)));
    9917        22630 :         space2 = ((sorted_fields_type *)
    9918        45260 :                   ggc_internal_alloc (sizeof (struct sorted_fields_type)
    9919        22630 :                                       + len * sizeof (tree)));
    9920              : 
    9921        22630 :         len = 0;
    9922        22630 :         space->s = space2;
    9923        22630 :         field_array = &space2->elts[0];
    9924       791532 :         for (x = fieldlist; x; x = DECL_CHAIN (x))
    9925              :           {
    9926       772266 :             field_array[len++] = x;
    9927              : 
    9928              :             /* If there is anonymous struct or union, break out of the loop.  */
    9929       772266 :             if (DECL_NAME (x) == NULL)
    9930              :               break;
    9931              :           }
    9932              :         /* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
    9933        22630 :         if (x == NULL)
    9934              :           {
    9935        19266 :             TYPE_LANG_SPECIFIC (t) = space;
    9936        19266 :             TYPE_LANG_SPECIFIC (t)->s->len = len;
    9937        19266 :             field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
    9938        19266 :             qsort (field_array, len, sizeof (tree), field_decl_cmp);
    9939              :           }
    9940              :       }
    9941              :   }
    9942              : 
    9943              :   /* If this was supposed to be a transparent union, but we can't
    9944              :      make it one, warn and turn off the flag.  */
    9945      1177591 :   if (TREE_CODE (t) == UNION_TYPE
    9946       376936 :       && TYPE_TRANSPARENT_AGGR (t)
    9947      1177634 :       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
    9948              :     {
    9949           13 :       TYPE_TRANSPARENT_AGGR (t) = 0;
    9950           13 :       warning_at (loc, 0, "union cannot be made transparent");
    9951              :     }
    9952              : 
    9953              :   /* Check for consistency with previous definition.  */
    9954      1177591 :   if (flag_isoc23 && NULL != enclosing_struct_parse_info)
    9955              :     {
    9956       909128 :       tree vistype = previous_tag (t);
    9957       909128 :       if (vistype
    9958          124 :           && TREE_CODE (vistype) == TREE_CODE (t)
    9959       909252 :           && !C_TYPE_BEING_DEFINED (vistype))
    9960              :         {
    9961          104 :           TYPE_STUB_DECL (t) = TYPE_STUB_DECL (vistype);
    9962          104 :           if (c_type_variably_modified_p (t))
    9963              :             {
    9964            7 :               error ("redefinition of struct or union %qT with variably "
    9965              :                      "modified type", t);
    9966            7 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
    9967            7 :                 inform (struct_parse_info->refloc, "originally defined here");
    9968              :             }
    9969           97 :           else if (!comptypes_same_p (t, vistype))
    9970              :             {
    9971           38 :               error ("redefinition of struct or union %qT", t);
    9972           38 :               if (struct_parse_info->refloc != UNKNOWN_LOCATION)
    9973           38 :                 inform (struct_parse_info->refloc, "originally defined here");
    9974              :             }
    9975              :         }
    9976              :     }
    9977              : 
    9978      1177591 :   C_TYPE_BEING_DEFINED (t) = 0;
    9979              : 
    9980      1177591 :   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
    9981          674 :     for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
    9982          353 :       c_fixup_may_alias (x);
    9983              : 
    9984              :   /* Set type canonical based on equivalence class.  */
    9985      1177591 :   if (flag_isoc23 && !C_TYPE_VARIABLE_SIZE (t))
    9986              :     {
    9987       944731 :       if (c_struct_htab == NULL)
    9988        35830 :         c_struct_htab = hash_table<c_struct_hasher>::create_ggc (61);
    9989              : 
    9990       944731 :       hashval_t hash = c_struct_hasher::hash (t);
    9991              : 
    9992       944731 :       gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
    9993       944731 :       gcc_checking_assert (!TYPE_NAME (t)
    9994              :                            || TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE);
    9995              : 
    9996       944731 :       tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT);
    9997       944731 :       if (*e)
    9998        62751 :         TYPE_CANONICAL (t) = *e;
    9999              :       else
   10000              :         {
   10001       881980 :           TYPE_CANONICAL (t) = t;
   10002       881980 :           *e = t;
   10003              :         }
   10004       944731 :       c_update_type_canonical (t);
   10005              :     }
   10006              : 
   10007      1177591 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
   10008      2385898 :   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
   10009              :     {
   10010      1208307 :       TYPE_FIELDS (x) = TYPE_FIELDS (t);
   10011      1208307 :       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
   10012      1208307 :       TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
   10013      1208307 :       TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
   10014      1208307 :       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
   10015      1208307 :       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
   10016      1208307 :       C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);
   10017      1208307 :       C_TYPE_FIELDS_HAS_COUNTED_BY (x) = C_TYPE_FIELDS_HAS_COUNTED_BY (t);
   10018      1208307 :       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
   10019      1208307 :       C_TYPE_VARIABLY_MODIFIED (x) = C_TYPE_VARIABLY_MODIFIED (t);
   10020      1208307 :       C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
   10021      1208307 :       TYPE_INCLUDES_FLEXARRAY (x) = TYPE_INCLUDES_FLEXARRAY (t);
   10022              :     }
   10023              : 
   10024              :   /* Update type location to the one of the definition, instead of e.g.
   10025              :      a forward declaration.  */
   10026      1177591 :   if (TYPE_STUB_DECL (t))
   10027      1177591 :     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
   10028              : 
   10029              :   /* Finish debugging output for this type.  */
   10030      1177591 :   rest_of_type_compilation (t, toplevel);
   10031              : 
   10032      1177591 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10033              : 
   10034              :   /* Make sure a DECL_EXPR is created for structs with VLA members.
   10035              :      Because we do not know the context, we always pass expr
   10036              :      to force creation of a BIND_EXPR which is required in some
   10037              :      contexts.  */
   10038      1177591 :   if (c_type_variably_modified_p (t))
   10039          667 :     add_decl_expr (loc, t, expr, false);
   10040              : 
   10041      1177591 :   if (warn_cxx_compat)
   10042          575 :     warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
   10043              : 
   10044      1177591 :   if (NULL != enclosing_struct_parse_info)
   10045              :     {
   10046      1136326 :       delete struct_parse_info;
   10047              : 
   10048      1136326 :       struct_parse_info = enclosing_struct_parse_info;
   10049              : 
   10050              :       /* If this struct is defined inside a struct, add it to
   10051              :          struct_types.  */
   10052      1136326 :       if (warn_cxx_compat
   10053              :           && struct_parse_info != NULL
   10054          350 :           && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10055          345 :         struct_parse_info->struct_types.safe_push (t);
   10056              :      }
   10057              : 
   10058              :   /* Only when the enclosing struct/union type is not anonymous, do more
   10059              :      verification on the fields with counted_by attributes.  */
   10060      1177591 :   if (C_TYPE_FIELDS_HAS_COUNTED_BY (t) && c_type_tag (t) != NULL_TREE)
   10061          198 :     verify_counted_by_attribute (t, t);
   10062              : 
   10063      1177591 :   return t;
   10064              : }
   10065              : 
   10066              : static struct {
   10067              :   gt_pointer_operator new_value;
   10068              :   void *cookie;
   10069              : } resort_data;
   10070              : 
   10071              : /* This routine compares two fields like field_decl_cmp but using the
   10072              : pointer operator in resort_data.  */
   10073              : 
   10074              : static int
   10075         5386 : resort_field_decl_cmp (const void *x_p, const void *y_p)
   10076              : {
   10077         5386 :   const tree *const x = (const tree *) x_p;
   10078         5386 :   const tree *const y = (const tree *) y_p;
   10079              : 
   10080         5386 :   if (DECL_NAME (*x) == DECL_NAME (*y))
   10081              :     /* A nontype is "greater" than a type.  */
   10082            0 :     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
   10083         5386 :   if (DECL_NAME (*x) == NULL_TREE)
   10084              :     return -1;
   10085         5386 :   if (DECL_NAME (*y) == NULL_TREE)
   10086              :     return 1;
   10087         5386 :   {
   10088         5386 :     tree d1 = DECL_NAME (*x);
   10089         5386 :     tree d2 = DECL_NAME (*y);
   10090         5386 :     resort_data.new_value (&d1, &d1, resort_data.cookie);
   10091         5386 :     resort_data.new_value (&d2, &d2, resort_data.cookie);
   10092         5386 :     if (d1 < d2)
   10093         2717 :       return -1;
   10094              :   }
   10095         2669 :   return 1;
   10096              : }
   10097              : 
   10098              : /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
   10099              : 
   10100              : void
   10101            6 : resort_sorted_fields (void *obj,
   10102              :                       void * ARG_UNUSED (orig_obj),
   10103              :                       gt_pointer_operator new_value,
   10104              :                       void *cookie)
   10105              : {
   10106            6 :   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
   10107            6 :   resort_data.new_value = new_value;
   10108            6 :   resort_data.cookie = cookie;
   10109            6 :   qsort (&sf->elts[0], sf->len, sizeof (tree),
   10110              :          resort_field_decl_cmp);
   10111            6 : }
   10112              : 
   10113              : /* Lay out the type T, and its element type, and so on.  */
   10114              : 
   10115              : static void
   10116            0 : layout_array_type (tree t)
   10117              : {
   10118            0 :   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   10119            0 :     layout_array_type (TREE_TYPE (t));
   10120            0 :   layout_type (t);
   10121            0 : }
   10122              : 
   10123              : /* Begin compiling the definition of an enumeration type.
   10124              :    NAME is its name (or null if anonymous).
   10125              :    LOC is the enum's location.
   10126              :    FIXED_UNDERLYING_TYPE is the (C23) underlying type specified in the
   10127              :    definition.
   10128              :    Returns the type object, as yet incomplete.
   10129              :    Also records info about it so that build_enumerator
   10130              :    may be used to declare the individual values as they are read.  */
   10131              : 
   10132              : tree
   10133       180381 : start_enum (location_t loc, struct c_enum_contents *the_enum, tree name,
   10134              :             tree fixed_underlying_type, bool potential_nesting_p)
   10135              : {
   10136       180381 :   tree enumtype = NULL_TREE;
   10137       180381 :   location_t enumloc = UNKNOWN_LOCATION;
   10138              : 
   10139              :   /* If this is the real definition for a previous forward reference,
   10140              :      fill in the contents in the same object that used to be the
   10141              :      forward reference.  */
   10142              : 
   10143       180381 :   if (name != NULL_TREE)
   10144        71689 :     enumtype = lookup_tag (ENUMERAL_TYPE, name, true, &enumloc);
   10145              : 
   10146        71689 :   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   10147              :     {
   10148              :       /* If the type is currently being defined or if we have seen an
   10149              :          incomplete version which is now complete, this is a nested
   10150              :          redefinition.  The later happens if the redefinition occurs
   10151              :          inside the enum specifier itself.  */
   10152          178 :       if (C_TYPE_BEING_DEFINED (enumtype)
   10153          178 :           || (potential_nesting_p && TYPE_VALUES (enumtype) != NULL_TREE))
   10154            9 :         error_at (loc, "nested redefinition of %<enum %E%>", name);
   10155              : 
   10156              :       /* For C23 we allow redefinitions.  We set to zero and check for
   10157              :          consistency later.  */
   10158          339 :       if (flag_isoc23 && TYPE_VALUES (enumtype) != NULL_TREE)
   10159              :         enumtype = NULL_TREE;
   10160              :     }
   10161              : 
   10162       108844 :   if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   10163              :     {
   10164       180231 :       enumtype = make_node (ENUMERAL_TYPE);
   10165       180231 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10166       180231 :       SET_TYPE_STRUCTURAL_EQUALITY (enumtype);
   10167       180231 :       pushtag (loc, name, enumtype);
   10168       180231 :       if (fixed_underlying_type != NULL_TREE)
   10169              :         {
   10170              :           /* For an enum definition with a fixed underlying type, the
   10171              :              type is complete during the definition and the
   10172              :              enumeration constants have that type.  If there was a
   10173              :              tag, the type was completed in c_parser_enum_specifier.
   10174              :              If not, it must be completed here.  */
   10175           12 :           ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = true;
   10176           12 :           TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (fixed_underlying_type);
   10177           12 :           TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (fixed_underlying_type);
   10178           12 :           TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (fixed_underlying_type);
   10179           12 :           SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (fixed_underlying_type));
   10180           12 :           TYPE_SIZE (enumtype) = NULL_TREE;
   10181           12 :           TYPE_PRECISION (enumtype) = TYPE_PRECISION (fixed_underlying_type);
   10182           12 :           ENUM_UNDERLYING_TYPE (enumtype) = fixed_underlying_type;
   10183           12 :           TYPE_CANONICAL (enumtype) = TYPE_CANONICAL (fixed_underlying_type);
   10184           12 :           c_update_type_canonical (enumtype);
   10185           12 :           layout_type (enumtype);
   10186              :         }
   10187              :     }
   10188              :   /* Update type location to the one of the definition, instead of e.g.
   10189              :      a forward declaration.  */
   10190          150 :   else if (TYPE_STUB_DECL (enumtype))
   10191              :     {
   10192          150 :       enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
   10193          150 :       DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
   10194              :     }
   10195              : 
   10196       180381 :   C_TYPE_BEING_DEFINED (enumtype) = 1;
   10197              : 
   10198       180381 :   if (TYPE_VALUES (enumtype) != NULL_TREE)
   10199              :     {
   10200              :       /* This enum is a named one that has been declared already.  */
   10201            6 :       auto_diagnostic_group d;
   10202            6 :       error_at (loc, "redeclaration of %<enum %E%>", name);
   10203            6 :       if (enumloc != UNKNOWN_LOCATION)
   10204            6 :         inform (enumloc, "originally defined here");
   10205              : 
   10206              :       /* Completely replace its old definition.
   10207              :          The old enumerators remain defined, however.  */
   10208            6 :       TYPE_VALUES (enumtype) = NULL_TREE;
   10209            6 :     }
   10210              : 
   10211       180381 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype)
   10212       180381 :       && fixed_underlying_type == NULL_TREE)
   10213              :     {
   10214            3 :       error_at (loc, "%<enum%> declared with but defined without "
   10215              :                 "fixed underlying type");
   10216            3 :       ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false;
   10217              :     }
   10218              : 
   10219       180381 :   the_enum->enum_next_value = integer_zero_node;
   10220       180381 :   the_enum->enum_type = enumtype;
   10221       180381 :   the_enum->enum_overflow = 0;
   10222              : 
   10223       180381 :   if (flag_short_enums && !ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10224          106 :     for (tree v = TYPE_MAIN_VARIANT (enumtype); v; v = TYPE_NEXT_VARIANT (v))
   10225           53 :       TYPE_PACKED (v) = 1;
   10226              : 
   10227              :   /* FIXME: This will issue a warning for a use of a type defined
   10228              :      within sizeof in a statement expr.  This is not terribly serious
   10229              :      as C++ doesn't permit statement exprs within sizeof anyhow.  */
   10230       180381 :   if (warn_cxx_compat
   10231          127 :       && (in_sizeof || in_typeof || in_alignof || in_countof))
   10232            0 :     warning_at (loc, OPT_Wc___compat,
   10233              :                 "defining type in %qs expression is invalid in C++",
   10234              :                 (in_sizeof ? "sizeof"
   10235            0 :                  : in_typeof ? "typeof"
   10236            0 :                  : in_alignof ? "alignof"
   10237              :                  : "_Countof"));
   10238              : 
   10239       180381 :   if (in_underspecified_init)
   10240            6 :     error_at (loc, "%qT defined in underspecified object initializer",
   10241              :               enumtype);
   10242              : 
   10243       180381 :   return enumtype;
   10244              : }
   10245              : 
   10246              : /* After processing and defining all the values of an enumeration type,
   10247              :    install their decls in the enumeration type and finish it off.
   10248              :    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
   10249              :    and ATTRIBUTES are the specified attributes.
   10250              :    Returns ENUMTYPE.  */
   10251              : 
   10252              : tree
   10253       180381 : finish_enum (tree enumtype, tree values, tree attributes)
   10254              : {
   10255       180381 :   tree pair, tem;
   10256       180381 :   tree minnode = NULL_TREE, maxnode = NULL_TREE;
   10257       180381 :   int precision;
   10258       180381 :   signop sign;
   10259       180381 :   bool toplevel = (file_scope == current_scope);
   10260       180381 :   struct lang_type *lt;
   10261              : 
   10262       180381 :   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
   10263              : 
   10264              :   /* Calculate the maximum value of any enumerator in this type.  */
   10265              : 
   10266       180381 :   if (values == error_mark_node)
   10267           26 :     minnode = maxnode = integer_zero_node;
   10268              :   else
   10269              :     {
   10270       180355 :       minnode = maxnode = TREE_VALUE (values);
   10271      5709556 :       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
   10272              :         {
   10273      5529201 :           tree value = TREE_VALUE (pair);
   10274      5529201 :           if (tree_int_cst_lt (maxnode, value))
   10275      5380307 :             maxnode = value;
   10276      5529201 :           if (tree_int_cst_lt (value, minnode))
   10277        65046 :             minnode = value;
   10278              :         }
   10279              :     }
   10280              : 
   10281              :   /* Construct the final type of this enumeration.  It is the same
   10282              :      as one of the integral types - the narrowest one that fits, except
   10283              :      that normally we only go as narrow as int - and signed iff any of
   10284              :      the values are negative.  */
   10285       180381 :   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
   10286       180381 :   precision = MAX (tree_int_cst_min_precision (minnode, sign),
   10287              :                    tree_int_cst_min_precision (maxnode, sign));
   10288              : 
   10289       180381 :   bool wider_than_int =
   10290       180381 :     (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
   10291       180381 :      || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode));
   10292              : 
   10293              : 
   10294       180381 :   if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype))
   10295              :     {
   10296              :       /* If the precision of the type was specified with an attribute and it
   10297              :          was too small, give an error.  Otherwise, use it.  */
   10298       180262 :       if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes))
   10299              :         {
   10300           23 :           if (precision > TYPE_PRECISION (enumtype))
   10301              :             {
   10302            6 :               TYPE_PRECISION (enumtype) = 0;
   10303            6 :               error ("specified mode too small for enumerated values");
   10304              :             }
   10305              :           else
   10306           17 :             precision = TYPE_PRECISION (enumtype);
   10307              :         }
   10308              :       else
   10309       180239 :         TYPE_PRECISION (enumtype) = 0;
   10310              : 
   10311       180262 :       if (TYPE_PACKED (enumtype)
   10312       180183 :           || precision > TYPE_PRECISION (integer_type_node)
   10313       357441 :           || TYPE_PRECISION (enumtype))
   10314              :         {
   10315         3210 :           tem = c_common_type_for_size (precision, sign == UNSIGNED ? 1 : 0);
   10316         3095 :           if (tem == NULL)
   10317              :             {
   10318              :               /* This should only occur when both signed and unsigned
   10319              :                  values of maximum precision occur among the
   10320              :                  enumerators.  */
   10321            3 :               pedwarn (input_location, 0,
   10322              :                        "enumeration values exceed range of largest integer");
   10323            3 :               tem = widest_integer_literal_type_node;
   10324              :             }
   10325         3092 :           else if (precision > TYPE_PRECISION (intmax_type_node)
   10326            4 :                    && !tree_int_cst_lt (minnode,
   10327            4 :                                         TYPE_MIN_VALUE (intmax_type_node))
   10328         3095 :                    && !tree_int_cst_lt (TYPE_MAX_VALUE (uintmax_type_node),
   10329              :                                         maxnode))
   10330            2 :             pedwarn (input_location, OPT_Wpedantic,
   10331              :                      "enumeration values exceed range of %qs",
   10332              :                      sign == UNSIGNED ? "uintmax_t" : "intmax_t");
   10333              :         }
   10334              :       else
   10335       177167 :         tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
   10336              : 
   10337       180262 :       TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
   10338       180262 :       TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
   10339       180262 :       TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
   10340       180262 :       SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (tem));
   10341       180262 :       TYPE_SIZE (enumtype) = NULL_TREE;
   10342       180262 :       TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
   10343       180262 :       ENUM_UNDERLYING_TYPE (enumtype) =
   10344       180262 :         c_common_type_for_size (TYPE_PRECISION (tem), TYPE_UNSIGNED (tem));
   10345              : 
   10346       540786 :       TYPE_CANONICAL (enumtype) =
   10347       180262 :         TYPE_CANONICAL (ENUM_UNDERLYING_TYPE (enumtype));
   10348       180262 :       c_update_type_canonical (enumtype);
   10349              : 
   10350       180262 :       layout_type (enumtype);
   10351              :     }
   10352              : 
   10353       180381 :   if (values != error_mark_node)
   10354              :     {
   10355              :       /* Change the type of the enumerators to be the enum type.  We
   10356              :          need to do this irrespective of the size of the enum, for
   10357              :          proper type checking.  Replace the DECL_INITIALs of the
   10358              :          enumerators, and the value slots of the list, with copies
   10359              :          that have the enum type; they cannot be modified in place
   10360              :          because they may be shared (e.g.  integer_zero_node) Finally,
   10361              :          change the purpose slots to point to the names of the decls.  */
   10362      5889911 :       for (pair = values; pair; pair = TREE_CHAIN (pair))
   10363              :         {
   10364      5709556 :           tree enu = TREE_PURPOSE (pair);
   10365      5709556 :           tree ini = DECL_INITIAL (enu);
   10366              : 
   10367      5709556 :           TREE_TYPE (enu) = enumtype;
   10368              : 
   10369              :           /* Before C23, the ISO C Standard mandates enumerators to
   10370              :              have type int, even though the underlying type of an enum
   10371              :              type is unspecified.  However, C23 allows enumerators of
   10372              :              any integer type, and if an enumeration has any
   10373              :              enumerators wider than int, all enumerators have the
   10374              :              enumerated type after it is parsed.  Any enumerators that
   10375              :              fit in int are given type int in build_enumerator (which
   10376              :              is the correct type while the enumeration is being
   10377              :              parsed), so no conversions are needed here if all
   10378              :              enumerators fit in int.  If the enum has a fixed
   10379              :              underlying type, the correct type was also given in
   10380              :              build_enumerator.  */
   10381      5709556 :           if (!ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) && wider_than_int)
   10382        33781 :             ini = convert (enumtype, ini);
   10383              : 
   10384      5709556 :           DECL_INITIAL (enu) = ini;
   10385      5709556 :           TREE_PURPOSE (pair) = DECL_NAME (enu);
   10386              :           /* To match the C++ FE, store the CONST_DECL rather than just its
   10387              :              value.  */
   10388      5709556 :           TREE_VALUE (pair) = enu;
   10389              :         }
   10390              : 
   10391       180355 :       TYPE_VALUES (enumtype) = values;
   10392              :     }
   10393              : 
   10394              :   /* Record the min/max values so that we can warn about bit-field
   10395              :      enumerations that are too small for the values.  */
   10396       180381 :   lt = ((struct lang_type *)
   10397       180381 :         ggc_internal_cleared_alloc (c_dialect_objc ()
   10398              :                                     ? sizeof (struct lang_type)
   10399              :                                     : offsetof (struct lang_type, info)));
   10400       180381 :   lt->enum_min = minnode;
   10401       180381 :   lt->enum_max = maxnode;
   10402       180381 :   TYPE_LANG_SPECIFIC (enumtype) = lt;
   10403              : 
   10404              :   /* Fix up all variant types of this enum type.  */
   10405       180381 :   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (enumtype));
   10406       360772 :   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
   10407              :     {
   10408       180391 :       C_TYPE_INCOMPLETE_VARS (tem) = NULL_TREE;
   10409       180391 :       if (tem == enumtype)
   10410       180381 :         continue;
   10411           10 :       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
   10412           10 :       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
   10413           10 :       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
   10414           10 :       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
   10415           10 :       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
   10416           10 :       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
   10417           10 :       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
   10418           10 :       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
   10419           10 :       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
   10420           10 :       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
   10421           10 :       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
   10422           10 :       ENUM_UNDERLYING_TYPE (tem) = ENUM_UNDERLYING_TYPE (enumtype);
   10423           10 :       TYPE_PACKED (tem) = TYPE_PACKED (enumtype);
   10424              :     }
   10425              : 
   10426              :   /* Finish debugging output for this type.  */
   10427       180381 :   rest_of_type_compilation (enumtype, toplevel);
   10428              : 
   10429       180381 :   finish_incomplete_vars (incomplete_vars, toplevel);
   10430              : 
   10431              :   /* If this enum is defined inside a struct, add it to
   10432              :      struct_types.  */
   10433       180381 :   if (warn_cxx_compat
   10434          127 :       && struct_parse_info != NULL
   10435           42 :       && !in_sizeof && !in_typeof && !in_alignof && !in_countof)
   10436           42 :     struct_parse_info->struct_types.safe_push (enumtype);
   10437              : 
   10438              :   /* Check for consistency with previous definition */
   10439       180381 :   if (flag_isoc23)
   10440              :     {
   10441       142300 :       tree vistype = previous_tag (enumtype);
   10442       142300 :       if (vistype
   10443           33 :           && TREE_CODE (vistype) == TREE_CODE (enumtype)
   10444       142329 :           && !C_TYPE_BEING_DEFINED (vistype))
   10445              :         {
   10446           29 :           TYPE_STUB_DECL (enumtype) = TYPE_STUB_DECL (vistype);
   10447           29 :           if (!comptypes_same_p (enumtype, vistype))
   10448            3 :             error("conflicting redefinition of enum %qT", enumtype);
   10449              :         }
   10450              :     }
   10451              : 
   10452       180381 :   C_TYPE_BEING_DEFINED (enumtype) = 0;
   10453              : 
   10454       180381 :   return enumtype;
   10455              : }
   10456              : 
   10457              : /* Build and install a CONST_DECL for one value of the
   10458              :    current enumeration type (one that was begun with start_enum).
   10459              :    DECL_LOC is the location of the enumerator.
   10460              :    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
   10461              :    Return a tree-list containing the CONST_DECL and its value.
   10462              :    Assignment of sequential values by default is handled here.  */
   10463              : 
   10464              : tree
   10465      5709573 : build_enumerator (location_t decl_loc, location_t loc,
   10466              :                   struct c_enum_contents *the_enum, tree name, tree value)
   10467              : {
   10468      5709573 :   tree decl;
   10469      5709573 :   tree old_decl;
   10470              : 
   10471              :   /* Validate and default VALUE.  */
   10472              : 
   10473      5709573 :   if (value != NULL_TREE)
   10474              :     {
   10475              :       /* Don't issue more errors for error_mark_node (i.e. an
   10476              :          undeclared identifier) - just ignore the value expression.  */
   10477      3549731 :       if (value == error_mark_node)
   10478              :         value = NULL_TREE;
   10479      3549066 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
   10480              :         {
   10481            6 :           error_at (loc, "enumerator value for %qE is not an integer constant",
   10482              :                     name);
   10483            6 :           value = NULL_TREE;
   10484              :         }
   10485              :       else
   10486              :         {
   10487      3549060 :           if (TREE_CODE (value) != INTEGER_CST)
   10488              :             {
   10489           97 :               value = c_fully_fold (value, false, NULL);
   10490           97 :               if (TREE_CODE (value) == INTEGER_CST)
   10491           48 :                 pedwarn (loc, OPT_Wpedantic,
   10492              :                          "enumerator value for %qE is not an integer "
   10493              :                          "constant expression", name);
   10494              :             }
   10495      3549060 :           if (TREE_CODE (value) != INTEGER_CST)
   10496              :             {
   10497           49 :               error ("enumerator value for %qE is not an integer constant",
   10498              :                      name);
   10499           49 :               value = NULL_TREE;
   10500              :             }
   10501              :           else
   10502              :             {
   10503      3549011 :               value = default_conversion (value);
   10504      3549011 :               constant_expression_warning (value);
   10505              :             }
   10506              :         }
   10507              :     }
   10508              : 
   10509              :   /* Default based on previous value.  */
   10510              :   /* It should no longer be possible to have NON_LVALUE_EXPR
   10511              :      in the default.  */
   10512      3549066 :   if (value == NULL_TREE)
   10513              :     {
   10514      2160562 :       value = the_enum->enum_next_value;
   10515      2160562 :       if (the_enum->enum_overflow)
   10516            8 :         error_at (loc, "overflow in enumeration values");
   10517              :     }
   10518      5709573 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10519              :     {
   10520              :       /* Enumeration constants must fit in the fixed underlying type.  */
   10521          164 :       if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (the_enum->enum_type)))
   10522            4 :         error_at (loc,
   10523              :                   "enumerator value outside the range of underlying type");
   10524              :       /* Enumeration constants for an enum with fixed underlying type
   10525              :          have the enum type, both inside and outside the
   10526              :          definition.  */
   10527          164 :       value = convert (the_enum->enum_type, value);
   10528              :     }
   10529      5709409 :   else if (flag_isoc23
   10530      5292958 :            && (old_decl = lookup_name_in_scope (name, current_scope))
   10531           35 :            && old_decl != error_mark_node
   10532           35 :            && TREE_TYPE (old_decl)
   10533           35 :            && TREE_TYPE (TREE_TYPE (old_decl))
   10534      5709443 :            && TREE_CODE (old_decl) == CONST_DECL)
   10535              :     {
   10536              :       /* Enumeration constants in a redeclaration have the previous type.  */
   10537           34 :       tree previous_type = TREE_TYPE (DECL_INITIAL (old_decl));
   10538           34 :       if (!int_fits_type_p (value, previous_type))
   10539              :         {
   10540            2 :           error_at (loc, "value of redeclared enumerator outside the range "
   10541              :                          "of %qT", previous_type);
   10542            2 :           locate_old_decl (old_decl);
   10543              :         }
   10544           34 :       value = convert (previous_type, value);
   10545              :     }
   10546              :   else
   10547              :     {
   10548              :       /* Even though the underlying type of an enum is unspecified, the
   10549              :          type of enumeration constants is explicitly defined as int
   10550              :          (6.4.4.3/2 in the C99 Standard).  C23 allows any integer type, and
   10551              :          GCC allows such types for older standards as an extension.  */
   10552      5709375 :       bool warned_range = false;
   10553      5709375 :       if (!int_fits_type_p (value,
   10554      5709375 :                             (TYPE_UNSIGNED (TREE_TYPE (value))
   10555              :                              ? uintmax_type_node
   10556              :                              : intmax_type_node)))
   10557              :         /* GCC does not consider its types larger than intmax_t to be
   10558              :            extended integer types (although C23 would permit such types to
   10559              :            be considered extended integer types if all the features
   10560              :            required by <stdint.h> and <inttypes.h> macros, such as support
   10561              :            for integer constants and I/O, were present), so diagnose if
   10562              :            such a wider type is used.  (If the wider type arose from a
   10563              :            constant of such a type, that will also have been diagnosed,
   10564              :            but this is the only diagnostic in the case where it arises
   10565              :            from choosing a wider type automatically when adding 1
   10566              :            overflows.)  */
   10567           11 :         warned_range = pedwarn (loc, OPT_Wpedantic,
   10568              :                                 "enumerator value outside the range of %qs",
   10569           11 :                                 TYPE_UNSIGNED (TREE_TYPE (value))
   10570              :                                 ? "uintmax_t"
   10571              :                                 : "intmax_t");
   10572      5709375 :       if (!warned_range && !int_fits_type_p (value, integer_type_node))
   10573         5188 :         pedwarn_c11 (loc, OPT_Wpedantic,
   10574              :                      "ISO C restricts enumerator values to range of %<int%> "
   10575              :                      "before C23");
   10576              : 
   10577              :       /* The ISO C Standard mandates enumerators to have type int before
   10578              :          C23, even though the underlying type of an enum type is
   10579              :          unspecified.  C23 allows enumerators of any integer type.  During
   10580              :          the parsing of the enumeration, C23 specifies that constants
   10581              :          representable in int have type int, constants not representable
   10582              :          in int have the type of the given expression if any, and
   10583              :          constants not representable in int and derived by adding 1 to the
   10584              :          previous constant have the type of that constant unless the
   10585              :          addition would overflow or wraparound, in which case a wider type
   10586              :          of the same signedness is chosen automatically; after the
   10587              :          enumeration is parsed, all the constants have the type of the
   10588              :          enumeration if any do not fit in int.  */
   10589      5709375 :       if (int_fits_type_p (value, integer_type_node))
   10590      5704183 :         value = convert (integer_type_node, value);
   10591              :     }
   10592              : 
   10593              :   /* Set basis for default for next value.  */
   10594      5709573 :   if (ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10595              :     {
   10596          164 :       tree underlying_type = ENUM_UNDERLYING_TYPE (the_enum->enum_type);
   10597          164 :       if (TREE_CODE (underlying_type) == BOOLEAN_TYPE)
   10598              :         /* A value of 2 following a value of 1 overflows bool, but we
   10599              :            cannot carry out addition directly on bool without
   10600              :            promotion, and converting the result of arithmetic in a
   10601              :            wider type back to bool would not produce the right result
   10602              :            for this overflow check.  */
   10603           61 :         the_enum->enum_next_value = invert_truthvalue_loc (loc, value);
   10604              :       else
   10605          103 :         the_enum->enum_next_value
   10606          103 :           = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10607              :                              PLUS_EXPR, convert (underlying_type, value),
   10608              :                              convert (underlying_type, integer_one_node),
   10609              :                              false);
   10610              :     }
   10611              :   else
   10612              :     {
   10613              :       /* In a redeclaration the type can already be the enumeral type.  */
   10614      5709409 :       if (TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
   10615           12 :         value = convert (ENUM_UNDERLYING_TYPE (TREE_TYPE (value)), value);
   10616      5709409 :       the_enum->enum_next_value
   10617      5709409 :         = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10618              :                            PLUS_EXPR, value, integer_one_node, false);
   10619              :     }
   10620      5709573 :   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
   10621      5709573 :   if (the_enum->enum_overflow
   10622      5709573 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (the_enum->enum_type))
   10623              :     {
   10624              :       /* Choose a wider type with the same signedness if
   10625              :          available.  */
   10626         3727 :       int prec = TYPE_PRECISION (TREE_TYPE (value)) + 1;
   10627         3727 :       bool unsignedp = TYPE_UNSIGNED (TREE_TYPE (value));
   10628         3727 :       tree new_type = (unsignedp
   10629         3727 :                        ? long_unsigned_type_node
   10630              :                        : long_integer_type_node);
   10631         3727 :       if (prec > TYPE_PRECISION (new_type))
   10632         3359 :         new_type = (unsignedp
   10633         3359 :                     ? long_long_unsigned_type_node
   10634              :                     : long_long_integer_type_node);
   10635         3727 :       if (prec > TYPE_PRECISION (new_type))
   10636         2887 :         new_type = (unsignedp
   10637         2887 :                     ? widest_unsigned_literal_type_node
   10638              :                     : widest_integer_literal_type_node);
   10639         3727 :       if (prec <= TYPE_PRECISION (new_type))
   10640              :         {
   10641         3722 :           the_enum->enum_overflow = false;
   10642         3722 :           the_enum->enum_next_value
   10643         3722 :             = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
   10644              :                                PLUS_EXPR, convert (new_type, value),
   10645              :                                integer_one_node, false);
   10646         3722 :           gcc_assert (!tree_int_cst_lt (the_enum->enum_next_value, value));
   10647              :         }
   10648              :     }
   10649              : 
   10650              :   /* Now create a declaration for the enum value name.  */
   10651              : 
   10652      5709573 :   decl = build_decl (decl_loc, CONST_DECL, name, TREE_TYPE (value));
   10653      5709573 :   DECL_INITIAL (decl) = value;
   10654      5709573 :   DECL_CONTEXT (decl) = the_enum->enum_type;
   10655      5709573 :   pushdecl (decl);
   10656              : 
   10657      5709573 :   return tree_cons (decl, value, NULL_TREE);
   10658              : }
   10659              : 
   10660              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   10661              : 
   10662              : tree
   10663            0 : c_simulate_enum_decl (location_t loc, const char *name,
   10664              :                       vec<string_int_pair> *values_ptr)
   10665              : {
   10666            0 :   location_t saved_loc = input_location;
   10667            0 :   input_location = loc;
   10668              : 
   10669            0 :   struct c_enum_contents the_enum;
   10670            0 :   tree enumtype = start_enum (loc, &the_enum, get_identifier (name),
   10671              :                               NULL_TREE, false);
   10672              : 
   10673            0 :   tree value_chain = NULL_TREE;
   10674            0 :   string_int_pair *value;
   10675            0 :   vec<string_int_pair> values = *values_ptr;
   10676            0 :   unsigned int i;
   10677            0 :   FOR_EACH_VEC_ELT (values, i, value)
   10678              :     {
   10679            0 :       tree decl = build_enumerator (loc, loc, &the_enum,
   10680              :                                     get_identifier (value->first),
   10681              :                                     build_int_cst (integer_type_node,
   10682            0 :                                                    value->second));
   10683            0 :       TREE_CHAIN (decl) = value_chain;
   10684            0 :       value_chain = decl;
   10685              :     }
   10686              : 
   10687            0 :   finish_enum (enumtype, nreverse (value_chain), NULL_TREE);
   10688              : 
   10689            0 :   input_location = saved_loc;
   10690            0 :   return enumtype;
   10691              : }
   10692              : 
   10693              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   10694              : 
   10695              : tree
   10696            0 : c_simulate_record_decl (location_t loc, const char *name,
   10697              :                         array_slice<const tree> fields)
   10698              : {
   10699            0 :   location_t saved_loc = input_location;
   10700            0 :   input_location = loc;
   10701              : 
   10702            0 :   class c_struct_parse_info *struct_info;
   10703            0 :   tree ident = get_identifier (name);
   10704            0 :   tree type = start_struct (loc, RECORD_TYPE, ident, &struct_info);
   10705              : 
   10706            0 :   for (unsigned int i = 0; i < fields.size (); ++i)
   10707              :     {
   10708            0 :       DECL_FIELD_CONTEXT (fields[i]) = type;
   10709            0 :       if (i > 0)
   10710            0 :         DECL_CHAIN (fields[i - 1]) = fields[i];
   10711              :     }
   10712              : 
   10713            0 :   finish_struct (loc, type, fields[0], NULL_TREE, struct_info);
   10714              : 
   10715            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   10716            0 :   set_underlying_type (decl);
   10717            0 :   lang_hooks.decls.pushdecl (decl);
   10718              : 
   10719            0 :   input_location = saved_loc;
   10720            0 :   return type;
   10721              : }
   10722              : 
   10723              : /* Create the FUNCTION_DECL for a function definition.
   10724              :    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
   10725              :    the declaration; they describe the function's name and the type it returns,
   10726              :    but twisted together in a fashion that parallels the syntax of C.
   10727              : 
   10728              :    This function creates a binding context for the function body
   10729              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   10730              : 
   10731              :    Returns true on success.  If the DECLARATOR is not suitable for a function
   10732              :    (it defines a datum instead), we return false to report a parse error.  */
   10733              : 
   10734              : bool
   10735     36250360 : start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   10736              :                 tree attributes)
   10737              : {
   10738     36250360 :   tree decl1, old_decl;
   10739     36250360 :   tree restype, resdecl;
   10740     36250360 :   location_t loc;
   10741     36250360 :   location_t result_loc;
   10742     36250360 :   tree expr = NULL;
   10743              : 
   10744     36250360 :   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   10745     36250360 :   current_function_returns_null = 0;
   10746     36250360 :   current_function_returns_abnormally = 0;
   10747     36250360 :   warn_about_return_type = 0;
   10748     36250360 :   c_switch_stack = NULL;
   10749              : 
   10750              :   /* Indicate no valid break/continue context.  */
   10751     36250360 :   in_statement = 0;
   10752              : 
   10753     36250360 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
   10754              :                           &attributes, &expr, NULL, DEPRECATED_NORMAL);
   10755     36250360 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   10756              : 
   10757              :   /* If the declarator is not suitable for a function definition,
   10758              :      cause a syntax error.  */
   10759     36250360 :   if (decl1 == NULL_TREE
   10760     36250329 :       || TREE_CODE (decl1) != FUNCTION_DECL)
   10761              :     return false;
   10762              : 
   10763              :   /* Nested functions may have variably modified (return) type.
   10764              :      Make sure the size expression is evaluated at this point.  */
   10765     36250322 :   if (expr && !current_scope->parm_flag)
   10766           11 :     add_stmt (fold_convert (void_type_node, expr));
   10767              : 
   10768     36250322 :   loc = DECL_SOURCE_LOCATION (decl1);
   10769              : 
   10770              :   /* A nested function is not global.  */
   10771     36250322 :   if (current_function_decl != NULL_TREE)
   10772         1587 :     TREE_PUBLIC (decl1) = 0;
   10773              : 
   10774     36250322 :   c_decl_attributes (&decl1, attributes, 0);
   10775              : 
   10776     36250322 :   if (DECL_DECLARED_INLINE_P (decl1)
   10777     35560538 :       && DECL_UNINLINABLE (decl1)
   10778     36250332 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
   10779              :     {
   10780            3 :       auto_urlify_attributes sentinel;
   10781            3 :       warning_at (loc, OPT_Wattributes,
   10782              :                   "inline function %qD given attribute %qs",
   10783              :                   decl1, "noinline");
   10784            3 :     }
   10785              : 
   10786              :   /* Handle gnu_inline attribute.  */
   10787     36250322 :   if (declspecs->inline_p
   10788     35560541 :       && !flag_gnu89_inline
   10789     35526444 :       && TREE_CODE (decl1) == FUNCTION_DECL
   10790     71776766 :       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
   10791       158159 :           || current_function_decl))
   10792              :     {
   10793     35368357 :       if (declspecs->storage_class != csc_static)
   10794     35368351 :         DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
   10795              :     }
   10796              : 
   10797     36250322 :   announce_function (decl1);
   10798              : 
   10799     36250322 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
   10800              :     {
   10801            1 :       error_at (loc, "return type is an incomplete type");
   10802              :       /* Make it return void instead.  */
   10803            1 :       TREE_TYPE (decl1)
   10804            2 :         = c_build_function_type (void_type_node,
   10805            1 :                                  TYPE_ARG_TYPES (TREE_TYPE (decl1)),
   10806            1 :                                  TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl1)));
   10807              :     }
   10808              : 
   10809     36250322 :   if (warn_about_return_type)
   10810         1404 :     permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int
   10811            0 :                    : (warn_return_type > 0 ? OPT_Wreturn_type
   10812              :                       : OPT_Wimplicit_int),
   10813              :                    "return type defaults to %<int%>");
   10814              : 
   10815              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   10816              :      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
   10817     36250322 :   DECL_INITIAL (decl1) = error_mark_node;
   10818              : 
   10819              :   /* If this definition isn't a prototype and we had a prototype declaration
   10820              :      before, copy the arg type info from that prototype.  */
   10821     36250322 :   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
   10822     36250322 :   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
   10823     36021262 :     old_decl = NULL_TREE;
   10824              : 
   10825     36250322 :   current_function_prototype_locus = UNKNOWN_LOCATION;
   10826     36250322 :   current_function_prototype_built_in = false;
   10827     36250322 :   current_function_prototype_arg_types = NULL_TREE;
   10828     36250322 :   tree newtype = TREE_TYPE (decl1);
   10829     36250322 :   tree oldtype = old_decl ? TREE_TYPE (old_decl) : newtype;
   10830     36250322 :   if (!prototype_p (newtype))
   10831              :     {
   10832        13135 :       tree oldrt = TREE_TYPE (oldtype);
   10833        13135 :       tree newrt = TREE_TYPE (newtype);
   10834        13135 :       if (old_decl != NULL_TREE
   10835          319 :           && TREE_CODE (oldtype) == FUNCTION_TYPE
   10836          319 :           && comptypes (oldrt, newrt)
   10837        13435 :           && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype))
   10838              :         {
   10839          299 :           if (stdarg_p (oldtype))
   10840              :             {
   10841            1 :               auto_diagnostic_group d;
   10842            1 :               warning_at (loc, 0, "%q+D defined as variadic function "
   10843              :                           "without prototype", decl1);
   10844            1 :               locate_old_decl (old_decl);
   10845            1 :             }
   10846          299 :           TREE_TYPE (decl1) = composite_type (oldtype, newtype);
   10847          299 :           current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
   10848          299 :           current_function_prototype_built_in
   10849          299 :             = C_DECL_BUILTIN_PROTOTYPE (old_decl);
   10850          299 :           current_function_prototype_arg_types
   10851          299 :             = TYPE_ARG_TYPES (newtype);
   10852              :         }
   10853        13135 :       if (TREE_PUBLIC (decl1))
   10854              :         {
   10855              :           /* If there is an external prototype declaration of this
   10856              :              function, record its location but do not copy information
   10857              :              to this decl.  This may be an invisible declaration
   10858              :              (built-in or in a scope which has finished) or simply
   10859              :              have more refined argument types than any declaration
   10860              :              found above.  */
   10861        12720 :           struct c_binding *b;
   10862        12998 :           for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
   10863          717 :             if (B_IN_SCOPE (b, external_scope))
   10864              :               break;
   10865        12720 :           if (b)
   10866              :             {
   10867          439 :               tree ext_decl, ext_type;
   10868          439 :               ext_decl = b->decl;
   10869          439 :               ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
   10870          439 :               if (TREE_CODE (ext_type) == FUNCTION_TYPE
   10871          878 :                   && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
   10872          439 :                                 TREE_TYPE (ext_type)))
   10873              :                 {
   10874          419 :                   current_function_prototype_locus
   10875          419 :                     = DECL_SOURCE_LOCATION (ext_decl);
   10876          419 :                   current_function_prototype_built_in
   10877          419 :                     = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
   10878          419 :                   current_function_prototype_arg_types
   10879          419 :                     = TYPE_ARG_TYPES (ext_type);
   10880              :                 }
   10881              :             }
   10882              :         }
   10883              :     }
   10884              : 
   10885              :   /* Optionally warn about C23 compatibility.  */
   10886     36250322 :   if (warn_deprecated_non_prototype
   10887           34 :       && old_decl != NULL_TREE
   10888            5 :       && TREE_CODE (oldtype) == FUNCTION_TYPE
   10889            5 :       && !TYPE_ARG_TYPES (oldtype)
   10890            5 :       && !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype)
   10891     36250327 :       && (TYPE_ARG_TYPES (newtype)
   10892            3 :           && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != void_type_node))
   10893              :     {
   10894            3 :       bool warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
   10895              :                                 "ISO C23 does not allow defining"
   10896              :                                 " parameters for function %qE declared"
   10897              :                                 " without parameters",
   10898              :                                 decl1);
   10899            3 :       if (warned)
   10900            3 :         inform (DECL_SOURCE_LOCATION (old_decl), "declared here");
   10901              :     }
   10902              : 
   10903              :   /* Optionally warn of old-fashioned def with no previous prototype.  */
   10904     36250322 :   if (warn_strict_prototypes
   10905       107520 :       && old_decl != error_mark_node
   10906       107520 :       && !prototype_p (TREE_TYPE (decl1))
   10907     36250323 :       && C_DECL_ISNT_PROTOTYPE (old_decl))
   10908            1 :     warning_at (loc, OPT_Wstrict_prototypes,
   10909              :                 "function declaration isn%'t a prototype");
   10910              :   /* Optionally warn of any global def with no previous prototype.  */
   10911     36250321 :   else if (warn_missing_prototypes
   10912       107221 :            && old_decl != error_mark_node
   10913       107221 :            && TREE_PUBLIC (decl1)
   10914        74072 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10915        74036 :            && C_DECL_ISNT_PROTOTYPE (old_decl)
   10916     36250962 :            && !DECL_DECLARED_INLINE_P (decl1))
   10917            4 :     warning_at (loc, OPT_Wmissing_prototypes,
   10918              :                 "no previous prototype for %qD", decl1);
   10919              :   /* Optionally warn of any def with no previous prototype
   10920              :      if the function has already been used.  */
   10921     36250317 :   else if (warn_missing_prototypes
   10922       107217 :            && old_decl != NULL_TREE
   10923        74399 :            && old_decl != error_mark_node
   10924        74399 :            && TREE_USED (old_decl)
   10925     36257414 :            && !prototype_p (TREE_TYPE (old_decl)))
   10926            0 :     warning_at (loc, OPT_Wmissing_prototypes,
   10927              :                 "%qD was used with no prototype before its definition", decl1);
   10928              :   /* Optionally warn of any global def with no previous declaration.  */
   10929     36250317 :   else if (warn_missing_declarations
   10930            4 :            && TREE_PUBLIC (decl1)
   10931            3 :            && old_decl == NULL_TREE
   10932            3 :            && !MAIN_NAME_P (DECL_NAME (decl1))
   10933     36250320 :            && !DECL_DECLARED_INLINE_P (decl1))
   10934            2 :     warning_at (loc, OPT_Wmissing_declarations,
   10935              :                 "no previous declaration for %qD",
   10936              :                 decl1);
   10937              :   /* Optionally warn of any def with no previous declaration
   10938              :      if the function has already been used.  */
   10939     36250315 :   else if (warn_missing_declarations
   10940            2 :            && old_decl != NULL_TREE
   10941            0 :            && old_decl != error_mark_node
   10942            0 :            && TREE_USED (old_decl)
   10943     36250315 :            && C_DECL_IMPLICIT (old_decl))
   10944            0 :     warning_at (loc, OPT_Wmissing_declarations,
   10945              :                 "%qD was used with no declaration before its definition", decl1);
   10946              : 
   10947              :   /* This function exists in static storage.
   10948              :      (This does not mean `static' in the C sense!)  */
   10949     36250322 :   TREE_STATIC (decl1) = 1;
   10950              : 
   10951              :   /* This is the earliest point at which we might know the assembler
   10952              :      name of the function.  Thus, if it's set before this, die horribly.  */
   10953     36250322 :   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
   10954              : 
   10955              :   /* If #pragma weak was used, mark the decl weak now.  */
   10956     36250322 :   if (current_scope == file_scope)
   10957     36248735 :     maybe_apply_pragma_weak (decl1);
   10958              : 
   10959              :   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
   10960     36250322 :   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
   10961              :     {
   10962         3208 :       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
   10963         3208 :           != integer_type_node)
   10964            5 :         pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
   10965         3203 :       else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
   10966            1 :         pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
   10967              :                  decl1);
   10968              : 
   10969         3208 :       check_main_parameter_types (decl1);
   10970              : 
   10971         3208 :       if (!TREE_PUBLIC (decl1))
   10972            0 :         pedwarn (loc, OPT_Wmain,
   10973              :                  "%qD is normally a non-static function", decl1);
   10974              :     }
   10975              : 
   10976     36250322 :   tree parms = current_function_arg_info->parms;
   10977     36250322 :   if (old_decl)
   10978              :     {
   10979       229060 :       location_t origloc = DECL_SOURCE_LOCATION (old_decl);
   10980       229060 :       warn_parms_array_mismatch (origloc, old_decl, parms);
   10981              :     }
   10982              : 
   10983              :   /* To enable versions to be created across TU's we mark and mangle all
   10984              :      non-default versioned functions.  */
   10985     36250322 :   if (TREE_CODE (decl1) == FUNCTION_DECL
   10986              :       && !TARGET_HAS_FMV_TARGET_ATTRIBUTE
   10987              :       && get_target_version (decl1).is_valid ())
   10988              :     {
   10989              :       maybe_mark_function_versioned (decl1);
   10990              :       if (current_scope != file_scope)
   10991              :         error ("versioned definitions are only allowed at file scope");
   10992              :     }
   10993              : 
   10994              :   /* Record the decl so that the function name is defined.
   10995              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   10996              :      use the old decl.  */
   10997              : 
   10998     36250322 :   current_function_decl = pushdecl (decl1);
   10999              : 
   11000     36250322 :   if (tree access = build_attr_access_from_parms (parms, false))
   11001        57544 :     decl_attributes (&current_function_decl, access, ATTR_FLAG_INTERNAL,
   11002              :                      old_decl);
   11003              : 
   11004     36250322 :   push_scope ();
   11005     36250322 :   declare_parm_level ();
   11006              : 
   11007              :   /* Set the result decl source location to the location of the typespec.  */
   11008      4094127 :   result_loc = (declspecs->locations[cdw_typespec] == UNKNOWN_LOCATION
   11009     36250322 :                 ? loc : declspecs->locations[cdw_typespec]);
   11010     36250322 :   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11011     36250322 :   resdecl = build_decl (result_loc, RESULT_DECL, NULL_TREE, restype);
   11012     36250322 :   DECL_ARTIFICIAL (resdecl) = 1;
   11013     36250322 :   DECL_IGNORED_P (resdecl) = 1;
   11014     36250322 :   DECL_RESULT (current_function_decl) = resdecl;
   11015              : 
   11016     36250322 :   start_fname_decls ();
   11017              : 
   11018     36250322 :   return true;
   11019              : }
   11020              : 
   11021              : /* Subroutine of store_parm_decls which handles new-style function
   11022              :    definitions (prototype format). The parms already have decls, so we
   11023              :    need only record them as in effect and complain if any redundant
   11024              :    old-style parm decls were written.  */
   11025              : static void
   11026     36237200 : store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
   11027              : {
   11028     36237200 :   tree decl;
   11029     36237200 :   c_arg_tag *tag;
   11030     36237200 :   unsigned ix;
   11031              : 
   11032     36237200 :   if (current_scope->bindings)
   11033              :     {
   11034            7 :       error_at (DECL_SOURCE_LOCATION (fndecl),
   11035              :                 "old-style parameter declarations in prototyped "
   11036              :                 "function definition");
   11037              : 
   11038              :       /* Get rid of the old-style declarations.  */
   11039            7 :       pop_scope ();
   11040            7 :       push_scope ();
   11041              :     }
   11042              :   /* Don't issue this warning for nested functions, and don't issue this
   11043              :      warning if we got here because ARG_INFO_TYPES was error_mark_node
   11044              :      (this happens when a function definition has just an ellipsis in
   11045              :      its parameter list).  */
   11046     36237193 :   else if (!in_system_header_at (input_location)
   11047       639988 :            && !current_function_scope
   11048       638548 :            && arg_info->types != error_mark_node
   11049     36875741 :            && !arg_info->c23_empty_parens)
   11050       586750 :     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
   11051              :                 "traditional C rejects ISO C style function definitions");
   11052              : 
   11053              :   /* Now make all the parameter declarations visible in the function body.
   11054              :      We can bypass most of the grunt work of pushdecl.  */
   11055    136083111 :   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
   11056              :     {
   11057     99845911 :       DECL_CONTEXT (decl) = current_function_decl;
   11058     99845911 :       if (DECL_NAME (decl))
   11059              :         {
   11060     99845297 :           bind (DECL_NAME (decl), decl, current_scope,
   11061              :                 /*invisible=*/false, /*nested=*/false,
   11062              :                 UNKNOWN_LOCATION);
   11063     99845297 :           if (!TREE_USED (decl))
   11064     99827900 :             warn_if_shadowing (decl);
   11065              :         }
   11066              :       else
   11067          614 :         pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_name,
   11068              :                      "ISO C does not support omitting parameter names in "
   11069              :                      "function definitions before C23");
   11070              :     }
   11071              : 
   11072              :   /* Record the parameter list in the function declaration.  */
   11073     36237200 :   DECL_ARGUMENTS (fndecl) = arg_info->parms;
   11074              : 
   11075              :   /* Now make all the ancillary declarations visible, likewise.  */
   11076     36237256 :   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
   11077              :     {
   11078           56 :       DECL_CONTEXT (decl) = current_function_decl;
   11079           56 :       if (DECL_NAME (decl))
   11080            0 :         bind (DECL_NAME (decl), decl, current_scope,
   11081              :               /*invisible=*/false,
   11082            0 :               /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
   11083              :               UNKNOWN_LOCATION);
   11084              :     }
   11085              : 
   11086              :   /* And all the tag declarations.  */
   11087     36237310 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
   11088           56 :     if (tag->id)
   11089           23 :       bind (tag->id, tag->type, current_scope,
   11090              :             /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
   11091     36237200 : }
   11092              : 
   11093              : /* Subroutine of store_parm_decls which handles old-style function
   11094              :    definitions (separate parameter list and declarations).  */
   11095              : 
   11096              : static void
   11097        13122 : store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
   11098              : {
   11099        13122 :   struct c_binding *b;
   11100        13122 :   tree parm, decl, last;
   11101        13122 :   tree parmids = arg_info->parms;
   11102        13122 :   hash_set<tree> seen_args;
   11103              : 
   11104        13122 :   if (!in_system_header_at (input_location))
   11105              :     {
   11106        13119 :       if (flag_isoc23)
   11107         1349 :         pedwarn (DECL_SOURCE_LOCATION (fndecl),
   11108         1349 :                  OPT_Wold_style_definition, "old-style function definition");
   11109              :       else
   11110        11770 :         warning_at (DECL_SOURCE_LOCATION (fndecl),
   11111        11770 :                     OPT_Wold_style_definition,
   11112              :                     "old-style function definition");
   11113              :     }
   11114              : 
   11115        13122 :   if (current_scope->had_vla_unspec)
   11116            1 :     error ("%<[*]%> not allowed in other than function prototype scope");
   11117              : 
   11118              :   /* Match each formal parameter name with its declaration.  Save each
   11119              :      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
   11120        47397 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11121              :     {
   11122        34275 :       if (TREE_VALUE (parm) == NULL_TREE)
   11123              :         {
   11124            0 :           error_at (DECL_SOURCE_LOCATION (fndecl),
   11125              :                     "parameter name missing from parameter list");
   11126            0 :           TREE_PURPOSE (parm) = NULL_TREE;
   11127            0 :           continue;
   11128              :         }
   11129              : 
   11130        34275 :       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
   11131        34275 :       if (b && B_IN_CURRENT_SCOPE (b))
   11132              :         {
   11133        22655 :           decl = b->decl;
   11134              :           /* Skip erroneous parameters.  */
   11135        22655 :           if (decl == error_mark_node)
   11136            2 :             continue;
   11137              :           /* If we got something other than a PARM_DECL it is an error.  */
   11138        22653 :           if (TREE_CODE (decl) != PARM_DECL)
   11139              :             {
   11140            7 :               error_at (DECL_SOURCE_LOCATION (decl),
   11141              :                         "%qD declared as a non-parameter", decl);
   11142            7 :               continue;
   11143              :             }
   11144              :           /* If the declaration is already marked, we have a duplicate
   11145              :              name.  Complain and ignore the duplicate.  */
   11146        22646 :           else if (seen_args.contains (decl))
   11147              :             {
   11148            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11149              :                         "multiple parameters named %qD", decl);
   11150            0 :               TREE_PURPOSE (parm) = NULL_TREE;
   11151            0 :               continue;
   11152              :             }
   11153              :           /* If the declaration says "void", complain and turn it into
   11154              :              an int.  */
   11155        22646 :           else if (VOID_TYPE_P (TREE_TYPE (decl)))
   11156              :             {
   11157            0 :               error_at (DECL_SOURCE_LOCATION (decl),
   11158              :                         "parameter %qD declared with void type", decl);
   11159            0 :               TREE_TYPE (decl) = integer_type_node;
   11160            0 :               DECL_ARG_TYPE (decl) = integer_type_node;
   11161            0 :               layout_decl (decl, 0);
   11162              :             }
   11163        22646 :           warn_if_shadowing (decl);
   11164              :         }
   11165              :       /* If no declaration found, default to int.  */
   11166              :       else
   11167              :         {
   11168              :           /* FIXME diagnostics: This should be the location of the argument,
   11169              :              not the FNDECL.  E.g., for an old-style declaration
   11170              : 
   11171              :                int f10(v) { blah; }
   11172              : 
   11173              :              We should use the location of the V, not the F10.
   11174              :              Unfortunately, the V is an IDENTIFIER_NODE which has no
   11175              :              location.  In the future we need locations for c_arg_info
   11176              :              entries.
   11177              : 
   11178              :              See gcc.dg/Wshadow-3.c for an example of this problem. */
   11179        11620 :           decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
   11180        11620 :                              PARM_DECL, TREE_VALUE (parm), integer_type_node);
   11181        11620 :           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
   11182        11620 :           pushdecl (decl);
   11183        11620 :           warn_if_shadowing (decl);
   11184              : 
   11185        11620 :           if (flag_isoc99)
   11186          118 :             permerror_opt (DECL_SOURCE_LOCATION (decl),
   11187          118 :                            OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
   11188              :                            decl);
   11189              :           else
   11190        11502 :             warning_at (DECL_SOURCE_LOCATION (decl),
   11191        11502 :                         OPT_Wmissing_parameter_type,
   11192              :                         "type of %qD defaults to %<int%>", decl);
   11193              :         }
   11194              : 
   11195        34266 :       TREE_PURPOSE (parm) = decl;
   11196        34266 :       seen_args.add (decl);
   11197              :     }
   11198              : 
   11199              :   /* Now examine the parms chain for incomplete declarations
   11200              :      and declarations with no corresponding names.  */
   11201              : 
   11202        47476 :   for (b = current_scope->bindings; b; b = b->prev)
   11203              :     {
   11204        34354 :       parm = b->decl;
   11205        34354 :       if (TREE_CODE (parm) != PARM_DECL)
   11206           79 :         continue;
   11207              : 
   11208        34275 :       if (TREE_TYPE (parm) != error_mark_node
   11209        34275 :           && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
   11210              :         {
   11211            0 :           error_at (DECL_SOURCE_LOCATION (parm),
   11212              :                     "parameter %qD has incomplete type", parm);
   11213            0 :           TREE_TYPE (parm) = error_mark_node;
   11214              :         }
   11215              : 
   11216        34275 :       if (!seen_args.contains (parm))
   11217              :         {
   11218            9 :           error_at (DECL_SOURCE_LOCATION (parm),
   11219              :                     "declaration for parameter %qD but no such parameter",
   11220              :                     parm);
   11221              : 
   11222              :           /* Pretend the parameter was not missing.
   11223              :              This gets us to a standard state and minimizes
   11224              :              further error messages.  */
   11225            9 :           parmids = chainon (parmids, tree_cons (parm, 0, 0));
   11226              :         }
   11227              :     }
   11228              : 
   11229              :   /* Chain the declarations together in the order of the list of
   11230              :      names.  Store that chain in the function decl, replacing the
   11231              :      list of names.  Update the current scope to match.  */
   11232        13122 :   DECL_ARGUMENTS (fndecl) = NULL_TREE;
   11233              : 
   11234        13130 :   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
   11235         8681 :     if (TREE_PURPOSE (parm))
   11236              :       break;
   11237        13122 :   if (parm && TREE_PURPOSE (parm))
   11238              :     {
   11239         8673 :       last = TREE_PURPOSE (parm);
   11240         8673 :       DECL_ARGUMENTS (fndecl) = last;
   11241              : 
   11242        34276 :       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
   11243        25603 :         if (TREE_PURPOSE (parm))
   11244              :           {
   11245        25602 :             DECL_CHAIN (last) = TREE_PURPOSE (parm);
   11246        25603 :             last = TREE_PURPOSE (parm);
   11247              :           }
   11248         8673 :       DECL_CHAIN (last) = NULL_TREE;
   11249              :     }
   11250              : 
   11251              :   /* If there was a previous prototype,
   11252              :      set the DECL_ARG_TYPE of each argument according to
   11253              :      the type previously specified, and report any mismatches.  */
   11254              : 
   11255        13122 :   if (current_function_prototype_arg_types)
   11256              :     {
   11257          171 :       tree type;
   11258          171 :       for (parm = DECL_ARGUMENTS (fndecl),
   11259          171 :              type = current_function_prototype_arg_types;
   11260          373 :            parm || (type != NULL_TREE
   11261          166 :                     && TREE_VALUE (type) != error_mark_node
   11262          166 :                     && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
   11263          202 :            parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
   11264              :         {
   11265          212 :           if (parm == NULL_TREE
   11266          206 :               || type == NULL_TREE
   11267          418 :               || (TREE_VALUE (type) != error_mark_node
   11268          192 :                   && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
   11269              :             {
   11270           10 :               if (current_function_prototype_built_in)
   11271            6 :                 warning_at (DECL_SOURCE_LOCATION (fndecl),
   11272            6 :                             0, "number of arguments doesn%'t match "
   11273              :                             "built-in prototype");
   11274              :               else
   11275              :                 {
   11276              :                   /* FIXME diagnostics: This should be the location of
   11277              :                      FNDECL, but there is bug when a prototype is
   11278              :                      declared inside function context, but defined
   11279              :                      outside of it (e.g., gcc.dg/pr15698-2.c).  In
   11280              :                      which case FNDECL gets the location of the
   11281              :                      prototype, not the definition.  */
   11282            4 :                   error_at (input_location,
   11283              :                             "number of arguments doesn%'t match prototype");
   11284              : 
   11285            4 :                   error_at (current_function_prototype_locus,
   11286              :                             "prototype declaration");
   11287              :                 }
   11288              :               break;
   11289              :             }
   11290              :           /* Type for passing arg must be consistent with that
   11291              :              declared for the arg.  ISO C says we take the unqualified
   11292              :              type for parameters declared with qualified type.  */
   11293          202 :           if (TREE_TYPE (parm) != error_mark_node
   11294          201 :               && TREE_VALUE (type) != error_mark_node
   11295          389 :               && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11296          187 :                    != TYPE_ATOMIC (TREE_VALUE (type)))
   11297          185 :                   || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
   11298          185 :                                  TYPE_MAIN_VARIANT (TREE_VALUE (type)))))
   11299              :             {
   11300           36 :               if ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
   11301           36 :                    == TYPE_ATOMIC (TREE_VALUE (type)))
   11302           36 :                   && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
   11303           34 :                       == TYPE_MAIN_VARIANT (TREE_VALUE (type))))
   11304              :                 {
   11305              :                   /* Adjust argument to match prototype.  E.g. a previous
   11306              :                      `int foo(float);' prototype causes
   11307              :                      `int foo(x) float x; {...}' to be treated like
   11308              :                      `int foo(float x) {...}'.  This is particularly
   11309              :                      useful for argument types like uid_t.  */
   11310           17 :                   DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
   11311              : 
   11312              :                   /* ??? Is it possible to get here with a
   11313              :                      built-in prototype or will it always have
   11314              :                      been diagnosed as conflicting with an
   11315              :                      old-style definition and discarded?  */
   11316           17 :                   if (current_function_prototype_built_in)
   11317            2 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11318            2 :                                 OPT_Wpedantic, "promoted argument %qD "
   11319              :                                 "doesn%'t match built-in prototype", parm);
   11320              :                   else
   11321              :                     {
   11322           15 :                       pedwarn (DECL_SOURCE_LOCATION (parm),
   11323           15 :                                OPT_Wpedantic, "promoted argument %qD "
   11324              :                                "doesn%'t match prototype", parm);
   11325           15 :                       pedwarn (current_function_prototype_locus, OPT_Wpedantic,
   11326              :                                "prototype declaration");
   11327              :                     }
   11328              :                 }
   11329              :               else
   11330              :                 {
   11331           19 :                   if (current_function_prototype_built_in)
   11332           10 :                     warning_at (DECL_SOURCE_LOCATION (parm),
   11333           10 :                                 0, "argument %qD doesn%'t match "
   11334              :                                 "built-in prototype", parm);
   11335              :                   else
   11336              :                     {
   11337            9 :                       error_at (DECL_SOURCE_LOCATION (parm),
   11338              :                                 "argument %qD doesn%'t match prototype", parm);
   11339            9 :                       error_at (current_function_prototype_locus,
   11340              :                                 "prototype declaration");
   11341              :                     }
   11342              :                 }
   11343              :             }
   11344              :         }
   11345          171 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = NULL_TREE;
   11346              :     }
   11347              : 
   11348              :   /* Otherwise, create a prototype that would match.  */
   11349              : 
   11350              :   else
   11351              :     {
   11352        12951 :       tree actual = NULL_TREE, last = NULL_TREE, type;
   11353              : 
   11354        47020 :       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   11355              :         {
   11356        34069 :           type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
   11357        34069 :           if (last)
   11358        25552 :             TREE_CHAIN (last) = type;
   11359              :           else
   11360              :             actual = type;
   11361        34069 :           last = type;
   11362              :         }
   11363        12951 :       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
   11364        12951 :       if (last)
   11365         8517 :         TREE_CHAIN (last) = type;
   11366              :       else
   11367              :         actual = type;
   11368              : 
   11369              :       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
   11370              :          of the type of this function, but we need to avoid having this
   11371              :          affect the types of other similarly-typed functions, so we must
   11372              :          first force the generation of an identical (but separate) type
   11373              :          node for the relevant function type.  The new node we create
   11374              :          will be a variant of the main variant of the original function
   11375              :          type.  */
   11376              : 
   11377        12951 :       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
   11378              : 
   11379        12951 :       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
   11380              :     }
   11381        13122 : }
   11382              : 
   11383              : /* Store parameter declarations passed in ARG_INFO into the current
   11384              :    function declaration.  */
   11385              : 
   11386              : void
   11387            0 : store_parm_decls_from (struct c_arg_info *arg_info)
   11388              : {
   11389            0 :   current_function_arg_info = arg_info;
   11390            0 :   store_parm_decls ();
   11391            0 : }
   11392              : 
   11393              : /* Called by walk_tree to look for and update context-less labels
   11394              :    or labels with context in the parent function.  */
   11395              : 
   11396              : static tree
   11397         8135 : set_labels_context_r (tree *tp, int *walk_subtrees, void *data)
   11398              : {
   11399         8135 :   tree ctx = static_cast<tree>(data);
   11400         8135 :   if (TREE_CODE (*tp) == LABEL_EXPR
   11401         8135 :       && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE
   11402            2 :           || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx)))
   11403              :     {
   11404           72 :       DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx;
   11405           72 :       *walk_subtrees = 0;
   11406              :     }
   11407              : 
   11408         8135 :   return NULL_TREE;
   11409              : }
   11410              : 
   11411              : /* Store the parameter declarations into the current function declaration.
   11412              :    This is called after parsing the parameter declarations, before
   11413              :    digesting the body of the function.
   11414              : 
   11415              :    For an old-style definition, construct a prototype out of the old-style
   11416              :    parameter declarations and inject it into the function's type.  */
   11417              : 
   11418              : void
   11419     36250322 : store_parm_decls (void)
   11420              : {
   11421     36250322 :   tree fndecl = current_function_decl;
   11422     36250322 :   bool proto;
   11423              : 
   11424              :   /* The argument information block for FNDECL.  */
   11425     36250322 :   struct c_arg_info *arg_info = current_function_arg_info;
   11426     36250322 :   current_function_arg_info = 0;
   11427              : 
   11428              :   /* True if this definition is written with a prototype.  In C23, an
   11429              :      empty argument list was converted to (void) in grokparms; in
   11430              :      older C standard versions, it does not give the function a type
   11431              :      with a prototype for future calls.  */
   11432     36250322 :   proto = arg_info->types != 0 || arg_info->no_named_args_stdarg_p;
   11433              : 
   11434        13122 :   if (proto)
   11435     36237200 :     store_parm_decls_newstyle (fndecl, arg_info);
   11436              :   else
   11437        13122 :     store_parm_decls_oldstyle (fndecl, arg_info);
   11438              : 
   11439              :   /* The next call to push_scope will be a function body.  */
   11440              : 
   11441     36250322 :   next_is_function_body = true;
   11442              : 
   11443              :   /* Write a record describing this function definition to the prototypes
   11444              :      file (if requested).  */
   11445              : 
   11446     36250322 :   gen_aux_info_record (fndecl, 1, 0, proto);
   11447              : 
   11448              :   /* Initialize the RTL code for the function.  */
   11449     36250322 :   allocate_struct_function (fndecl, false);
   11450              : 
   11451     36250322 :   if (warn_unused_local_typedefs)
   11452      3115045 :     cfun->language = ggc_cleared_alloc<language_function> ();
   11453              : 
   11454              :   /* Begin the statement tree for this function.  */
   11455     36250322 :   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
   11456              : 
   11457              :   /* ??? Insert the contents of the pending sizes list into the function
   11458              :      to be evaluated.  The only reason left to have this is
   11459              :         void foo(int n, int array[n++])
   11460              :      because we throw away the array type in favor of a pointer type, and
   11461              :      thus won't naturally see the SAVE_EXPR containing the increment.  All
   11462              :      other pending sizes would be handled by gimplify_parameters.  */
   11463     36250322 :   if (arg_info->pending_sizes)
   11464              :     {
   11465              :       /* In very special circumstances, e.g. for code like
   11466              :            _Atomic int i = 5;
   11467              :            void f (int a[i += 2]) {}
   11468              :          we need to execute the atomic assignment on function entry.
   11469              :          But in this case, it is not just a straight store, it has the
   11470              :          op= form, which means that build_atomic_assign has generated
   11471              :          gotos, labels, etc.  Because at that time the function decl
   11472              :          for F has not been created yet, those labels do not have any
   11473              :          function context.  But we have the fndecl now, so update the
   11474              :          labels accordingly.  gimplify_expr would crash otherwise.
   11475              :          Or with nested functions the labels could be created with parent
   11476              :          function's context, while when the statement is emitted at the
   11477              :          start of the nested function, it needs the nested function's
   11478              :          context.  */
   11479          297 :       walk_tree_without_duplicates (&arg_info->pending_sizes,
   11480              :                                     set_labels_context_r, fndecl);
   11481          297 :       add_stmt (arg_info->pending_sizes);
   11482              :     }
   11483     36250322 : }
   11484              : 
   11485              : /* Store PARM_DECLs in PARMS into scope temporarily.  Used for
   11486              :    c_finish_omp_declare_simd for function prototypes.  No diagnostics
   11487              :    should be done.  */
   11488              : 
   11489              : void
   11490          249 : temp_store_parm_decls (tree fndecl, tree parms)
   11491              : {
   11492          249 :   push_scope ();
   11493          699 :   for (tree p = parms; p; p = DECL_CHAIN (p))
   11494              :     {
   11495          450 :       DECL_CONTEXT (p) = fndecl;
   11496          450 :       if (DECL_NAME (p))
   11497          328 :         bind (DECL_NAME (p), p, current_scope,
   11498              :               /*invisible=*/false, /*nested=*/false,
   11499              :               UNKNOWN_LOCATION);
   11500              :     }
   11501          249 : }
   11502              : 
   11503              : /* Undo what temp_store_parm_decls did.  */
   11504              : 
   11505              : void
   11506          249 : temp_pop_parm_decls (void)
   11507              : {
   11508              :   /* Clear all bindings in this temporary scope, so that
   11509              :      pop_scope doesn't create a BLOCK.  */
   11510          249 :   struct c_binding *b = current_scope->bindings;
   11511          249 :   current_scope->bindings = NULL;
   11512          582 :   for (; b; b = free_binding_and_advance (b))
   11513              :     {
   11514          333 :       gcc_assert (TREE_CODE (b->decl) == PARM_DECL
   11515              :                   || b->decl == error_mark_node);
   11516          333 :       gcc_assert (I_SYMBOL_BINDING (b->id) == b);
   11517          333 :       I_SYMBOL_BINDING (b->id) = b->shadowed;
   11518          333 :       if (b->shadowed && b->shadowed->u.type)
   11519            0 :         TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
   11520              :     }
   11521          249 :   pop_scope ();
   11522          249 : }
   11523              : 
   11524              : 
   11525              : /* Finish up a function declaration and compile that function
   11526              :    all the way to assembler language output.  Then free the storage
   11527              :    for the function definition.
   11528              : 
   11529              :    This is called after parsing the body of the function definition.  */
   11530              : 
   11531              : void
   11532     36250320 : finish_function (location_t end_loc)
   11533              : {
   11534     36250320 :   tree fndecl = current_function_decl;
   11535              : 
   11536     36250320 :   if (c_dialect_objc ())
   11537            0 :     objc_finish_function ();
   11538              : 
   11539     36250320 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
   11540     36250318 :     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   11541              : 
   11542              :   /* Must mark the RESULT_DECL as being in this function.  */
   11543              : 
   11544     36250320 :   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
   11545     36250320 :     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   11546              : 
   11547     36297809 :   if (MAIN_NAME_P (DECL_NAME (fndecl)) && !TREE_THIS_VOLATILE (fndecl)
   11548        47488 :       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
   11549     36297808 :       == integer_type_node && flag_isoc99)
   11550              :     {
   11551              :       /* Hack.  We don't want the middle-end to warn that this return
   11552              :          is unreachable, so we mark its location as special.  Using
   11553              :          UNKNOWN_LOCATION has the problem that it gets clobbered in
   11554              :          annotate_one_with_locus.  A cleaner solution might be to
   11555              :          ensure ! should_carry_locus_p (stmt), but that needs a flag.
   11556              :       */
   11557        46106 :       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
   11558              :     }
   11559              : 
   11560              :   /* Tie off the statement tree for this function.  */
   11561     36250320 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   11562              : 
   11563     36250320 :   finish_fname_decls ();
   11564              : 
   11565              :   /* Complain if there's no return statement only if option specified on
   11566              :      command line.  */
   11567     36250320 :   if (warn_return_type > 0
   11568      3115068 :       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
   11569      2919176 :       && !current_function_returns_value && !current_function_returns_null
   11570              :       /* Don't complain if we are no-return.  */
   11571           72 :       && !current_function_returns_abnormally
   11572              :       /* Don't complain if we are declared noreturn.  */
   11573           21 :       && !TREE_THIS_VOLATILE (fndecl)
   11574              :       /* Don't warn for main().  */
   11575           18 :       && !MAIN_NAME_P (DECL_NAME (fndecl))
   11576              :       /* Or if they didn't actually specify a return type.  */
   11577           17 :       && !C_FUNCTION_IMPLICIT_INT (fndecl)
   11578              :       /* Normally, with -Wreturn-type, flow will complain, but we might
   11579              :          optimize out static functions.  */
   11580           17 :       && !TREE_PUBLIC (fndecl)
   11581            6 :       && targetm.warn_func_return (fndecl)
   11582     39365388 :       && warning (OPT_Wreturn_type,
   11583              :                   "no return statement in function returning non-void"))
   11584            5 :     suppress_warning (fndecl, OPT_Wreturn_type);
   11585              : 
   11586              :   /* Complain about parameters that are only set, but never otherwise used.  */
   11587     36250320 :   if (warn_unused_but_set_parameter)
   11588              :     {
   11589      3050234 :       tree decl;
   11590              : 
   11591      3050234 :       for (decl = DECL_ARGUMENTS (fndecl);
   11592     11397920 :            decl;
   11593      8347686 :            decl = DECL_CHAIN (decl))
   11594      8347686 :         if (TREE_USED (decl)
   11595      8286983 :             && TREE_CODE (decl) == PARM_DECL
   11596      8286983 :             && !DECL_READ_P (decl)
   11597           47 :             && DECL_NAME (decl)
   11598           47 :             && !DECL_ARTIFICIAL (decl)
   11599      8347733 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_))
   11600           47 :           warning_at (DECL_SOURCE_LOCATION (decl),
   11601           47 :                       OPT_Wunused_but_set_parameter_,
   11602              :                       "parameter %qD set but not used", decl);
   11603              :     }
   11604              : 
   11605              :   /* Complain about locally defined typedefs that are not used in this
   11606              :      function.  */
   11607     36250320 :   maybe_warn_unused_local_typedefs ();
   11608              : 
   11609              :   /* Possibly warn about unused parameters.  */
   11610     36250320 :   if (warn_unused_parameter)
   11611      2956345 :     do_warn_unused_parameter (fndecl);
   11612              : 
   11613              :   /* Store the end of the function, so that we get good line number
   11614              :      info for the epilogue.  */
   11615     36250320 :   cfun->function_end_locus = end_loc;
   11616              : 
   11617              :   /* Finalize the ELF visibility for the function.  */
   11618     36250320 :   c_determine_visibility (fndecl);
   11619              : 
   11620              :   /* For GNU C extern inline functions disregard inline limits.  */
   11621     36250320 :   if (DECL_EXTERNAL (fndecl)
   11622     35396948 :       && DECL_DECLARED_INLINE_P (fndecl)
   11623     71647265 :       && (flag_gnu89_inline
   11624     35365941 :           || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
   11625     35396465 :     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
   11626              : 
   11627              :   /* Genericize before inlining.  Delay genericizing nested functions
   11628              :      until their parent function is genericized.  Since finalizing
   11629              :      requires GENERIC, delay that as well.  */
   11630              : 
   11631     72500640 :   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
   11632     72500638 :       && !undef_nested_function)
   11633              :     {
   11634     36250312 :       if (!decl_function_context (fndecl))
   11635              :         {
   11636     36248725 :           invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   11637     36248725 :           c_genericize (fndecl);
   11638              : 
   11639              :           /* ??? Objc emits functions after finalizing the compilation unit.
   11640              :              This should be cleaned up later and this conditional removed.  */
   11641     36248725 :           if (symtab->global_info_ready)
   11642              :             {
   11643            0 :               cgraph_node::add_new_function (fndecl, false);
   11644            0 :               return;
   11645              :             }
   11646     36248725 :           cgraph_node::finalize_function (fndecl, false);
   11647              :         }
   11648              :       else
   11649              :         {
   11650              :           /* Register this function with cgraph just far enough to get it
   11651              :             added to our parent's nested function list.  Handy, since the
   11652              :             C front end doesn't have such a list.  */
   11653         1587 :           (void) cgraph_node::get_create (fndecl);
   11654              :         }
   11655              :     }
   11656              : 
   11657     36250320 :   if (!decl_function_context (fndecl))
   11658     36248733 :     undef_nested_function = false;
   11659              : 
   11660     36250320 :   if (cfun->language != NULL)
   11661              :     {
   11662      3115044 :       ggc_free (cfun->language);
   11663      3115044 :       cfun->language = NULL;
   11664              :     }
   11665              : 
   11666              :   /* We're leaving the context of this function, so zap cfun.
   11667              :      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
   11668              :      tree_rest_of_compilation.  */
   11669     36250320 :   set_cfun (NULL);
   11670     36250320 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, current_function_decl);
   11671     36250320 :   current_function_decl = NULL;
   11672              : }
   11673              : 
   11674              : /* Check the declarations given in a for-loop for satisfying the C99
   11675              :    constraints.  If exactly one such decl is found, return it.  LOC is
   11676              :    the location of the opening parenthesis of the for loop.  The last
   11677              :    parameter allows you to control the "for loop initial declarations
   11678              :    are only allowed in C99 mode".  Normally, you should pass
   11679              :    flag_isoc99 as that parameter.  But in some cases (Objective-C
   11680              :    foreach loop, for example) we want to run the checks in this
   11681              :    function even if not in C99 mode, so we allow the caller to turn
   11682              :    off the error about not being in C99 mode.
   11683              : */
   11684              : 
   11685              : tree
   11686        25748 : check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
   11687              : {
   11688        25748 :   struct c_binding *b;
   11689        25748 :   tree one_decl = NULL_TREE;
   11690        25748 :   int n_decls = 0;
   11691              : 
   11692        25748 :   if (!turn_off_iso_c99_error)
   11693              :     {
   11694            1 :       static bool hint = true;
   11695              :       /* If we get here, declarations have been used in a for loop without
   11696              :          the C99 for loop scope.  This doesn't make much sense, so don't
   11697              :          allow it.  */
   11698            1 :       auto_diagnostic_group d;
   11699            1 :       error_at (loc, "%<for%> loop initial declarations "
   11700              :                 "are only allowed in C99 or C11 mode");
   11701            1 :       if (hint)
   11702              :         {
   11703            1 :           inform (loc,
   11704              :                   "use option %<-std=c99%>, %<-std=gnu99%>, %<-std=c11%> or "
   11705              :                   "%<-std=gnu11%> to compile your code");
   11706            1 :           hint = false;
   11707              :         }
   11708            1 :       return NULL_TREE;
   11709            1 :     }
   11710              :   else
   11711        25747 :     pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop "
   11712              :                  "initial declarations");
   11713              : 
   11714              :   /* C99 subclause 6.8.5 paragraph 3:
   11715              : 
   11716              :        [#3]  The  declaration  part  of  a for statement shall only
   11717              :        declare identifiers for objects having storage class auto or
   11718              :        register.
   11719              : 
   11720              :      It isn't clear whether, in this sentence, "identifiers" binds to
   11721              :      "shall only declare" or to "objects" - that is, whether all identifiers
   11722              :      declared must be identifiers for objects, or whether the restriction
   11723              :      only applies to those that are.  (A question on this in comp.std.c
   11724              :      in November 2000 received no answer.)  We implement the strictest
   11725              :      interpretation, to avoid creating an extension which later causes
   11726              :      problems.
   11727              : 
   11728              :      This constraint was removed in C23.  */
   11729              : 
   11730        51569 :   for (b = current_scope->bindings; b; b = b->prev)
   11731              :     {
   11732        25822 :       tree id = b->id;
   11733        25822 :       tree decl = b->decl;
   11734              : 
   11735        25822 :       if (!id)
   11736           27 :         continue;
   11737              : 
   11738        25795 :       switch (TREE_CODE (decl))
   11739              :         {
   11740        25747 :         case VAR_DECL:
   11741        25747 :           {
   11742        25747 :             location_t decl_loc = DECL_SOURCE_LOCATION (decl);
   11743        25747 :             if (TREE_STATIC (decl))
   11744            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11745              :                            "declaration of static variable %qD in %<for%> "
   11746              :                            "loop initial declaration", decl);
   11747        25742 :             else if (DECL_EXTERNAL (decl))
   11748            5 :               pedwarn_c11 (decl_loc, OPT_Wpedantic,
   11749              :                            "declaration of %<extern%> variable %qD in %<for%> "
   11750              :                            "loop initial declaration", decl);
   11751              :           }
   11752              :           break;
   11753              : 
   11754            6 :         case RECORD_TYPE:
   11755            6 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11756              :                        "%<struct %E%> declared in %<for%> loop initial "
   11757              :                        "declaration", id);
   11758            6 :           break;
   11759            5 :         case UNION_TYPE:
   11760            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11761              :                        "%<union %E%> declared in %<for%> loop initial "
   11762              :                        "declaration",
   11763              :                        id);
   11764            5 :           break;
   11765            5 :         case ENUMERAL_TYPE:
   11766            5 :           pedwarn_c11 (loc, OPT_Wpedantic,
   11767              :                        "%<enum %E%> declared in %<for%> loop "
   11768              :                        "initial declaration", id);
   11769            5 :           break;
   11770           32 :         default:
   11771           32 :           pedwarn_c11 (loc, OPT_Wpedantic, "declaration of non-variable "
   11772              :                        "%qD in %<for%> loop initial declaration", decl);
   11773              :         }
   11774              : 
   11775        25795 :       n_decls++;
   11776        25795 :       one_decl = decl;
   11777              :     }
   11778              : 
   11779        25747 :   return n_decls == 1 ? one_decl : NULL_TREE;
   11780              : }
   11781              : 
   11782              : /* Save and reinitialize the variables
   11783              :    used during compilation of a C function.  */
   11784              : 
   11785              : void
   11786         1615 : c_push_function_context (void)
   11787              : {
   11788         1615 :   struct language_function *p = cfun->language;
   11789              :   /* cfun->language might have been already allocated by the use of
   11790              :      -Wunused-local-typedefs.  In that case, just re-use it.  */
   11791         1615 :   if (p == NULL)
   11792         1559 :     cfun->language = p = ggc_cleared_alloc<language_function> ();
   11793              : 
   11794         1615 :   p->base.x_stmt_tree = c_stmt_tree;
   11795         1615 :   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
   11796         1615 :   p->x_in_statement = in_statement;
   11797         1615 :   p->x_switch_stack = c_switch_stack;
   11798         1615 :   p->loop_names = loop_names;
   11799         1615 :   loop_names = vNULL;
   11800         1615 :   p->loop_names_hash = loop_names_hash;
   11801         1615 :   loop_names_hash = NULL;
   11802         1615 :   p->arg_info = current_function_arg_info;
   11803         1615 :   p->returns_value = current_function_returns_value;
   11804         1615 :   p->returns_null = current_function_returns_null;
   11805         1615 :   p->returns_abnormally = current_function_returns_abnormally;
   11806         1615 :   p->warn_about_return_type = warn_about_return_type;
   11807              : 
   11808         1615 :   push_function_context ();
   11809         1615 : }
   11810              : 
   11811              : /* Restore the variables used during compilation of a C function.  */
   11812              : 
   11813              : void
   11814         1615 : c_pop_function_context (void)
   11815              : {
   11816         1615 :   struct language_function *p;
   11817              : 
   11818         1615 :   pop_function_context ();
   11819         1615 :   p = cfun->language;
   11820              : 
   11821              :   /* When -Wunused-local-typedefs is in effect, cfun->languages is
   11822              :      used to store data throughout the life time of the current cfun,
   11823              :      So don't deallocate it.  */
   11824         1615 :   if (!warn_unused_local_typedefs)
   11825         1559 :     cfun->language = NULL;
   11826              : 
   11827         1615 :   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
   11828         1615 :       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
   11829              :     {
   11830              :       /* Stop pointing to the local nodes about to be freed.  */
   11831              :       /* But DECL_INITIAL must remain nonzero so we know this
   11832              :          was an actual function definition.  */
   11833            0 :       DECL_INITIAL (current_function_decl) = error_mark_node;
   11834            0 :       DECL_ARGUMENTS (current_function_decl) = NULL_TREE;
   11835              :     }
   11836              : 
   11837         1615 :   c_stmt_tree = p->base.x_stmt_tree;
   11838         1615 :   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
   11839         1615 :   in_statement = p->x_in_statement;
   11840         1615 :   c_switch_stack = p->x_switch_stack;
   11841         1615 :   loop_names.release ();
   11842         1615 :   loop_names = p->loop_names;
   11843         1615 :   p->loop_names = vNULL;
   11844         1615 :   delete loop_names_hash;
   11845         1615 :   loop_names_hash = p->loop_names_hash;
   11846         1615 :   p->loop_names_hash = NULL;
   11847         1615 :   current_function_arg_info = p->arg_info;
   11848         1615 :   current_function_returns_value = p->returns_value;
   11849         1615 :   current_function_returns_null = p->returns_null;
   11850         1615 :   current_function_returns_abnormally = p->returns_abnormally;
   11851         1615 :   warn_about_return_type = p->warn_about_return_type;
   11852         1615 : }
   11853              : 
   11854              : /* The functions below are required for functionality of doing
   11855              :    function at once processing in the C front end. Currently these
   11856              :    functions are not called from anywhere in the C front end, but as
   11857              :    these changes continue, that will change.  */
   11858              : 
   11859              : /* Returns the stmt_tree (if any) to which statements are currently
   11860              :    being added.  If there is no active statement-tree, NULL is
   11861              :    returned.  */
   11862              : 
   11863              : stmt_tree
   11864    983942622 : current_stmt_tree (void)
   11865              : {
   11866    983942622 :   return &c_stmt_tree;
   11867              : }
   11868              : 
   11869              : /* Return the global value of T as a symbol.  */
   11870              : 
   11871              : tree
   11872      3912276 : identifier_global_value (tree t)
   11873              : {
   11874      3912276 :   struct c_binding *b;
   11875              : 
   11876      3913243 :   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
   11877      3906013 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11878      3905046 :       return b->decl;
   11879              : 
   11880              :   return NULL_TREE;
   11881              : }
   11882              : 
   11883              : /* Return the global value of tag T as a symbol.  */
   11884              : 
   11885              : tree
   11886           12 : identifier_global_tag (tree t)
   11887              : {
   11888           12 :   struct c_binding *b;
   11889              : 
   11890           12 :   for (b = I_TAG_BINDING (t); b; b = b->shadowed)
   11891           11 :     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
   11892           11 :       return b->decl;
   11893              : 
   11894              :   return NULL_TREE;
   11895              : }
   11896              : 
   11897              : /* Returns non-zero (result of __has_builtin) if NAME refers to a built-in
   11898              :    function or function-like operator.  */
   11899              : 
   11900              : int
   11901        24944 : names_builtin_p (const char *name)
   11902              : {
   11903        24944 :   tree id = get_identifier (name);
   11904        24944 :   if (tree decl = identifier_global_value (id))
   11905        24856 :     return TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_UNDECLARED_BUILTIN (decl);
   11906              : 
   11907              :   /* Also detect common reserved C words that aren't strictly built-in
   11908              :      functions.  */
   11909           88 :   switch (C_RID_CODE (id))
   11910              :     {
   11911              :     case RID_BUILTIN_ASSOC_BARRIER:
   11912              :     case RID_BUILTIN_CONVERTVECTOR:
   11913              :     case RID_BUILTIN_HAS_ATTRIBUTE:
   11914              :     case RID_BUILTIN_SHUFFLE:
   11915              :     case RID_BUILTIN_SHUFFLEVECTOR:
   11916              :     case RID_BUILTIN_STDC:
   11917              :     case RID_BUILTIN_COUNTED_BY_REF:
   11918              :     case RID_CHOOSE_EXPR:
   11919              :     case RID_OFFSETOF:
   11920              :     case RID_TYPES_COMPATIBLE_P:
   11921              :     case RID_C23_VA_START:
   11922              :     case RID_VA_ARG:
   11923              :       return 1;
   11924           67 :     default:
   11925           67 :       break;
   11926              :     }
   11927              : 
   11928           67 :   return 0;
   11929              : }
   11930              : 
   11931              : /* In C, the only C-linkage public declaration is at file scope.  */
   11932              : 
   11933              : tree
   11934            5 : c_linkage_bindings (tree name)
   11935              : {
   11936            5 :   return identifier_global_value (name);
   11937              : }
   11938              : 
   11939              : /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
   11940              :    otherwise the name is found in ridpointers from RID_INDEX.  */
   11941              : 
   11942              : void
   11943      3322890 : record_builtin_type (enum rid rid_index, const char *name, tree type)
   11944              : {
   11945      3322890 :   tree id, decl;
   11946      3322890 :   if (name == 0)
   11947      1550682 :     id = ridpointers[(int) rid_index];
   11948              :   else
   11949      1772208 :     id = get_identifier (name);
   11950      3322890 :   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
   11951      3322890 :   pushdecl (decl);
   11952      3322890 :   if (debug_hooks->type_decl)
   11953      3322890 :     debug_hooks->type_decl (decl, false);
   11954      3322890 : }
   11955              : 
   11956              : /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
   11957              : 
   11958              : struct c_parm *
   11959    123862825 : build_c_parm (struct c_declspecs *specs, tree attrs,
   11960              :               struct c_declarator *declarator,
   11961              :               location_t loc)
   11962              : {
   11963    123862825 :   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
   11964    123862825 :   ret->specs = specs;
   11965    123862825 :   ret->attrs = attrs;
   11966    123862825 :   ret->declarator = declarator;
   11967    123862825 :   ret->loc = loc;
   11968    123862825 :   return ret;
   11969              : }
   11970              : 
   11971              : /* Return a declarator with nested attributes.  TARGET is the inner
   11972              :    declarator to which these attributes apply.  ATTRS are the
   11973              :    attributes.  */
   11974              : 
   11975              : struct c_declarator *
   11976         6772 : build_attrs_declarator (tree attrs, struct c_declarator *target)
   11977              : {
   11978         6772 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   11979         6772 :   ret->kind = cdk_attrs;
   11980         6772 :   ret->declarator = target;
   11981         6772 :   ret->u.attrs = attrs;
   11982         6772 :   return ret;
   11983              : }
   11984              : 
   11985              : /* Return a declarator for a function with arguments specified by ARGS
   11986              :    and return type specified by TARGET.  */
   11987              : 
   11988              : struct c_declarator *
   11989     50496528 : build_function_declarator (struct c_arg_info *args,
   11990              :                            struct c_declarator *target)
   11991              : {
   11992     50496528 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   11993     50496528 :   ret->kind = cdk_function;
   11994     50496528 :   ret->declarator = target;
   11995     50496528 :   ret->u.arg_info = args;
   11996     50496528 :   return ret;
   11997              : }
   11998              : 
   11999              : /* Return a declarator for the identifier IDENT (which may be
   12000              :    NULL_TREE for an abstract declarator).  */
   12001              : 
   12002              : struct c_declarator *
   12003    313670663 : build_id_declarator (tree ident)
   12004              : {
   12005    313670663 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12006    313670663 :   ret->kind = cdk_id;
   12007    313670663 :   ret->declarator = 0;
   12008    313670663 :   ret->u.id.id = ident;
   12009    313670663 :   ret->u.id.attrs = NULL_TREE;
   12010              :   /* Default value - may get reset to a more precise location. */
   12011    313670663 :   ret->id_loc = input_location;
   12012    313670663 :   return ret;
   12013              : }
   12014              : 
   12015              : /* Return something to represent absolute declarators containing a *.
   12016              :    TARGET is the absolute declarator that the * contains.
   12017              :    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
   12018              :    to apply to the pointer type.  */
   12019              : 
   12020              : struct c_declarator *
   12021     18211090 : make_pointer_declarator (struct c_declspecs *type_quals_attrs,
   12022              :                          struct c_declarator *target)
   12023              : {
   12024     18211090 :   tree attrs;
   12025     18211090 :   int quals = 0;
   12026     18211090 :   struct c_declarator *itarget = target;
   12027     18211090 :   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
   12028     18211090 :   if (type_quals_attrs)
   12029              :     {
   12030     18211090 :       attrs = type_quals_attrs->attrs;
   12031     18211090 :       quals = quals_from_declspecs (type_quals_attrs);
   12032     18211090 :       if (attrs != NULL_TREE)
   12033         6500 :         itarget = build_attrs_declarator (attrs, target);
   12034              :     }
   12035     18211090 :   ret->kind = cdk_pointer;
   12036     18211090 :   ret->declarator = itarget;
   12037     18211090 :   ret->u.pointer_quals = quals;
   12038     18211090 :   return ret;
   12039              : }
   12040              : 
   12041              : /* Return a pointer to a structure for an empty list of declaration
   12042              :    specifiers.  */
   12043              : 
   12044              : struct c_declspecs *
   12045    454337417 : build_null_declspecs (void)
   12046              : {
   12047    454337417 :   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
   12048    454337417 :   memset (ret, 0, sizeof *ret);
   12049    454337417 :   ret->align_log = -1;
   12050    454337417 :   ret->typespec_word = cts_none;
   12051    454337417 :   ret->storage_class = csc_none;
   12052    454337417 :   ret->expr_const_operands = true;
   12053    454337417 :   ret->typespec_kind = ctsk_none;
   12054    454337417 :   ret->address_space = ADDR_SPACE_GENERIC;
   12055    454337417 :   return ret;
   12056              : }
   12057              : 
   12058              : /* Add the address space ADDRSPACE to the declaration specifiers
   12059              :    SPECS, returning SPECS.  */
   12060              : 
   12061              : struct c_declspecs *
   12062          177 : declspecs_add_addrspace (location_t location,
   12063              :                          struct c_declspecs *specs, addr_space_t as)
   12064              : {
   12065          177 :   specs->non_sc_seen_p = true;
   12066          177 :   specs->declspecs_seen_p = true;
   12067          177 :   specs->non_std_attrs_seen_p = true;
   12068              : 
   12069          177 :   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
   12070            0 :       && specs->address_space != as)
   12071            0 :     error ("incompatible address space qualifiers %qs and %qs",
   12072              :            c_addr_space_name (as),
   12073              :            c_addr_space_name (specs->address_space));
   12074              :   else
   12075              :     {
   12076          177 :       specs->address_space = as;
   12077          177 :       specs->locations[cdw_address_space] = location;
   12078              :     }
   12079          177 :   return specs;
   12080              : }
   12081              : 
   12082              : /* Add the type qualifier QUAL to the declaration specifiers SPECS,
   12083              :    returning SPECS.  */
   12084              : 
   12085              : struct c_declspecs *
   12086     16560856 : declspecs_add_qual (location_t loc,
   12087              :                     struct c_declspecs *specs, tree qual)
   12088              : {
   12089     16560856 :   enum rid i;
   12090     16560856 :   bool dupe = false;
   12091     16560856 :   specs->non_sc_seen_p = true;
   12092     16560856 :   specs->declspecs_seen_p = true;
   12093     16560856 :   specs->non_std_attrs_seen_p = true;
   12094     16560856 :   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
   12095              :               && C_IS_RESERVED_WORD (qual));
   12096     16560856 :   i = C_RID_CODE (qual);
   12097     16560856 :   location_t prev_loc = UNKNOWN_LOCATION;
   12098     16560856 :   switch (i)
   12099              :     {
   12100     13068462 :     case RID_CONST:
   12101     13068462 :       dupe = specs->const_p;
   12102     13068462 :       specs->const_p = true;
   12103     13068462 :       prev_loc = specs->locations[cdw_const];
   12104     13068462 :       specs->locations[cdw_const] = loc;
   12105     13068462 :       break;
   12106        96012 :     case RID_VOLATILE:
   12107        96012 :       dupe = specs->volatile_p;
   12108        96012 :       specs->volatile_p = true;
   12109        96012 :       prev_loc = specs->locations[cdw_volatile];
   12110        96012 :       specs->locations[cdw_volatile] = loc;
   12111        96012 :       break;
   12112      3376021 :     case RID_RESTRICT:
   12113      3376021 :       dupe = specs->restrict_p;
   12114      3376021 :       specs->restrict_p = true;
   12115      3376021 :       prev_loc = specs->locations[cdw_restrict];
   12116      3376021 :       specs->locations[cdw_restrict] = loc;
   12117      3376021 :       break;
   12118        20361 :     case RID_ATOMIC:
   12119        20361 :       dupe = specs->atomic_p;
   12120        20361 :       specs->atomic_p = true;
   12121        20361 :       prev_loc = specs->locations[cdw_atomic];
   12122        20361 :       specs->locations[cdw_atomic] = loc;
   12123        20361 :       break;
   12124            0 :     default:
   12125            0 :       gcc_unreachable ();
   12126              :     }
   12127     16560856 :   if (dupe)
   12128              :     {
   12129           56 :       bool warned = pedwarn_c90 (loc, OPT_Wpedantic,
   12130              :                                  "duplicate %qE declaration specifier", qual);
   12131           56 :       if (!warned
   12132           52 :           && warn_duplicate_decl_specifier
   12133           33 :           && prev_loc >= RESERVED_LOCATION_COUNT
   12134           33 :           && !from_macro_expansion_at (prev_loc)
   12135           77 :           && !from_macro_expansion_at (loc))
   12136           12 :         warning_at (loc, OPT_Wduplicate_decl_specifier,
   12137              :                     "duplicate %qE declaration specifier", qual);
   12138              :     }
   12139     16560856 :   return specs;
   12140              : }
   12141              : 
   12142              : /* Add the type specifier TYPE to the declaration specifiers SPECS,
   12143              :    returning SPECS.  */
   12144              : 
   12145              : struct c_declspecs *
   12146    331252179 : declspecs_add_type (location_t loc, struct c_declspecs *specs,
   12147              :                     struct c_typespec spec)
   12148              : {
   12149    331252179 :   tree type = spec.spec;
   12150    331252179 :   specs->non_sc_seen_p = true;
   12151    331252179 :   specs->declspecs_seen_p = true;
   12152    331252179 :   specs->non_std_attrs_seen_p = true;
   12153    331252179 :   specs->typespec_kind = spec.kind;
   12154    331252179 :   if (TREE_DEPRECATED (type))
   12155           56 :     specs->deprecated_p = true;
   12156    331252179 :   if (TREE_UNAVAILABLE (type))
   12157           40 :     specs->unavailable_p = true;
   12158              : 
   12159              :   /* As a type specifier is present, "auto" must be used as a storage
   12160              :      class specifier, not for type deduction.  */
   12161    331252179 :   if (specs->c23_auto_p)
   12162              :     {
   12163          115 :       specs->c23_auto_p = false;
   12164          115 :       if (specs->storage_class != csc_none)
   12165            1 :         error ("multiple storage classes in declaration specifiers");
   12166          114 :       else if (specs->thread_p)
   12167            1 :         error ("%qs used with %<auto%>",
   12168            1 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   12169          113 :       else if (specs->constexpr_p)
   12170              :         /* auto may only be used with another storage class specifier,
   12171              :            such as constexpr, if the type is inferred.  */
   12172            2 :         error ("%<auto%> used with %<constexpr%>");
   12173              :       else
   12174          111 :         specs->storage_class = csc_auto;
   12175              :     }
   12176              : 
   12177              :   /* Handle type specifier keywords.  */
   12178    331252179 :   if (TREE_CODE (type) == IDENTIFIER_NODE
   12179     82456246 :       && C_IS_RESERVED_WORD (type)
   12180    413708425 :       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
   12181              :     {
   12182     82456246 :       enum rid i = C_RID_CODE (type);
   12183     82456246 :       if (specs->type)
   12184              :         {
   12185           58 :           error_at (loc, "two or more data types in declaration specifiers");
   12186           58 :           return specs;
   12187              :         }
   12188     82456188 :       if ((int) i <= (int) RID_LAST_MODIFIER)
   12189              :         {
   12190              :           /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
   12191     21738941 :           bool dupe = false;
   12192     21738941 :           switch (i)
   12193              :             {
   12194     10715607 :             case RID_LONG:
   12195     10715607 :               if (specs->long_long_p)
   12196              :                 {
   12197          104 :                   error_at (loc, "%<long long long%> is too long for GCC");
   12198          104 :                   break;
   12199              :                 }
   12200     10715503 :               if (specs->long_p)
   12201              :                 {
   12202      2945812 :                   if (specs->typespec_word == cts_double)
   12203              :                     {
   12204           15 :                       error_at (loc,
   12205              :                                 "both %qs and %qs in declaration specifiers",
   12206              :                                 "long long", "double");
   12207           15 :                       break;
   12208              :                     }
   12209      2945797 :                   pedwarn_c90 (loc, OPT_Wlong_long,
   12210              :                                "ISO C90 does not support %<long long%>");
   12211      2945797 :                   specs->long_long_p = 1;
   12212      2945797 :                   specs->locations[cdw_long_long] = loc;
   12213      2945797 :                   break;
   12214              :                 }
   12215      7769691 :               if (specs->short_p)
   12216           77 :                 error_at (loc,
   12217              :                           "both %qs and %qs in declaration specifiers",
   12218              :                           "long", "short");
   12219      7769614 :               else if (specs->typespec_word == cts_auto_type)
   12220            1 :                 error_at (loc,
   12221              :                           "both %qs and %qs in declaration specifiers",
   12222              :                           "long", "__auto_type");
   12223              :               else if (specs->typespec_word == cts_void)
   12224            5 :                 error_at (loc,
   12225              :                           "both %qs and %qs in declaration specifiers",
   12226              :                           "long", "void");
   12227              :               else if (specs->typespec_word == cts_int_n)
   12228           19 :                 error_at (loc,
   12229              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12230           19 :                           "long", int_n_data[specs->u.int_n_idx].bitsize);
   12231              :               else if (specs->typespec_word == cts_bool)
   12232            3 :                 error_at (loc,
   12233              :                           "both %qs and %qs in declaration specifiers",
   12234              :                           "long", "_Bool");
   12235              :               else if (specs->typespec_word == cts_bitint)
   12236            3 :                 error_at (loc,
   12237              :                           "both %qs and %qs in declaration specifiers",
   12238              :                           "long", "_BitInt");
   12239              :               else if (specs->typespec_word == cts_char)
   12240           21 :                 error_at (loc,
   12241              :                           "both %qs and %qs in declaration specifiers",
   12242              :                           "long", "char");
   12243              :               else if (specs->typespec_word == cts_float)
   12244            7 :                 error_at (loc,
   12245              :                           "both %qs and %qs in declaration specifiers",
   12246              :                           "long", "float");
   12247              :               else if (specs->typespec_word == cts_floatn_nx)
   12248            0 :                 error_at (loc,
   12249              :                           "both %qs and %<_Float%d%s%> in declaration "
   12250              :                           "specifiers", "long",
   12251            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12252            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12253              :                           ? "x"
   12254              :                           : "");
   12255              :               else if (specs->typespec_word == cts_dfloat32)
   12256            4 :                 error_at (loc,
   12257              :                           "both %qs and %qs in declaration specifiers",
   12258              :                           "long", "_Decimal32");
   12259              :               else if (specs->typespec_word == cts_dfloat64)
   12260            4 :                 error_at (loc,
   12261              :                           "both %qs and %qs in declaration specifiers",
   12262              :                           "long", "_Decimal64");
   12263              :               else if (specs->typespec_word == cts_dfloat128)
   12264            4 :                 error_at (loc,
   12265              :                           "both %qs and %qs in declaration specifiers",
   12266              :                           "long", "_Decimal128");
   12267              :               else if (specs->typespec_word == cts_dfloat64x)
   12268            0 :                 error_at (loc,
   12269              :                           "both %qs and %qs in declaration specifiers",
   12270              :                           "long", "_Decimal64x");
   12271              :               else
   12272              :                 {
   12273      7769543 :                   specs->long_p = true;
   12274      7769543 :                   specs->locations[cdw_long] = loc;
   12275              :                 }
   12276              :               break;
   12277      1699772 :             case RID_SHORT:
   12278      1699772 :               dupe = specs->short_p;
   12279      1699772 :               if (specs->long_p)
   12280          197 :                 error_at (loc,
   12281              :                           "both %qs and %qs in declaration specifiers",
   12282              :                           "long", "short");
   12283      1699575 :               else if (specs->typespec_word == cts_auto_type)
   12284            1 :                 error_at (loc,
   12285              :                           "both %qs and %qs in declaration specifiers",
   12286              :                           "short", "__auto_type");
   12287              :               else if (specs->typespec_word == cts_void)
   12288            5 :                 error_at (loc,
   12289              :                           "both %qs and %qs in declaration specifiers",
   12290              :                           "short", "void");
   12291              :               else if (specs->typespec_word == cts_int_n)
   12292           19 :                 error_at (loc,
   12293              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12294           19 :                           "short", int_n_data[specs->u.int_n_idx].bitsize);
   12295              :               else if (specs->typespec_word == cts_bool)
   12296            3 :                 error_at (loc,
   12297              :                           "both %qs and %qs in declaration specifiers",
   12298              :                           "short", "_Bool");
   12299              :               else if (specs->typespec_word == cts_bitint)
   12300            1 :                 error_at (loc,
   12301              :                           "both %qs and %qs in declaration specifiers",
   12302              :                           "short", "_BitInt");
   12303              :               else if (specs->typespec_word == cts_char)
   12304           21 :                 error_at (loc,
   12305              :                           "both %qs and %qs in declaration specifiers",
   12306              :                           "short", "char");
   12307              :               else if (specs->typespec_word == cts_float)
   12308            7 :                 error_at (loc,
   12309              :                           "both %qs and %qs in declaration specifiers",
   12310              :                           "short", "float");
   12311              :               else if (specs->typespec_word == cts_double)
   12312            7 :                 error_at (loc,
   12313              :                           "both %qs and %qs in declaration specifiers",
   12314              :                           "short", "double");
   12315              :               else if (specs->typespec_word == cts_floatn_nx)
   12316            0 :                 error_at (loc,
   12317              :                           "both %qs and %<_Float%d%s%> in declaration "
   12318              :                           "specifiers", "short",
   12319            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12320            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12321              :                           ? "x"
   12322              :                           : "");
   12323              :               else if (specs->typespec_word == cts_dfloat32)
   12324            4 :                 error_at (loc,
   12325              :                           "both %qs and %qs in declaration specifiers",
   12326              :                           "short", "_Decimal32");
   12327              :               else if (specs->typespec_word == cts_dfloat64)
   12328            4 :                 error_at (loc,
   12329              :                           "both %qs and %qs in declaration specifiers",
   12330              :                           "short", "_Decimal64");
   12331              :               else if (specs->typespec_word == cts_dfloat128)
   12332            4 :                 error_at (loc,
   12333              :                           "both %qs and %qs in declaration specifiers",
   12334              :                           "short", "_Decimal128");
   12335              :               else if (specs->typespec_word == cts_dfloat64x)
   12336            0 :                 error_at (loc,
   12337              :                           "both %qs and %qs in declaration specifiers",
   12338              :                           "short", "_Decimal64x");
   12339              :               else
   12340              :                 {
   12341      1699499 :                   specs->short_p = true;
   12342      1699499 :                   specs->locations[cdw_short] = loc;
   12343              :                 }
   12344              :               break;
   12345       573663 :             case RID_SIGNED:
   12346       573663 :               dupe = specs->signed_p;
   12347       573663 :               if (specs->unsigned_p)
   12348          138 :                 error_at (loc,
   12349              :                           "both %qs and %qs in declaration specifiers",
   12350              :                           "signed", "unsigned");
   12351       573525 :               else if (specs->typespec_word == cts_auto_type)
   12352            1 :                 error_at (loc,
   12353              :                           "both %qs and %qs in declaration specifiers",
   12354              :                           "signed", "__auto_type");
   12355              :               else if (specs->typespec_word == cts_void)
   12356            5 :                 error_at (loc,
   12357              :                           "both %qs and %qs in declaration specifiers",
   12358              :                           "signed", "void");
   12359              :               else if (specs->typespec_word == cts_bool)
   12360            3 :                 error_at (loc,
   12361              :                           "both %qs and %qs in declaration specifiers",
   12362              :                           "signed", "_Bool");
   12363              :               else if (specs->typespec_word == cts_float)
   12364            7 :                 error_at (loc,
   12365              :                           "both %qs and %qs in declaration specifiers",
   12366              :                           "signed", "float");
   12367              :               else if (specs->typespec_word == cts_double)
   12368           21 :                 error_at (loc,
   12369              :                           "both %qs and %qs in declaration specifiers",
   12370              :                           "signed", "double");
   12371              :               else if (specs->typespec_word == cts_floatn_nx)
   12372            0 :                 error_at (loc,
   12373              :                           "both %qs and %<_Float%d%s%> in declaration "
   12374              :                           "specifiers", "signed",
   12375            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12376            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12377              :                           ? "x"
   12378              :                           : "");
   12379              :               else if (specs->typespec_word == cts_dfloat32)
   12380            4 :                 error_at (loc,
   12381              :                           "both %qs and %qs in declaration specifiers",
   12382              :                           "signed", "_Decimal32");
   12383              :               else if (specs->typespec_word == cts_dfloat64)
   12384            4 :                 error_at (loc,
   12385              :                           "both %qs and %qs in declaration specifiers",
   12386              :                           "signed", "_Decimal64");
   12387              :               else if (specs->typespec_word == cts_dfloat128)
   12388            4 :                 error_at (loc,
   12389              :                           "both %qs and %qs in declaration specifiers",
   12390              :                           "signed", "_Decimal128");
   12391              :               else if (specs->typespec_word == cts_dfloat64x)
   12392            0 :                 error_at (loc,
   12393              :                           "both %qs and %qs in declaration specifiers",
   12394              :                           "signed", "_Decimal64x");
   12395              :               else
   12396              :                 {
   12397       573476 :                   specs->signed_p = true;
   12398       573476 :                   specs->locations[cdw_signed] = loc;
   12399              :                 }
   12400              :               break;
   12401      6171952 :             case RID_UNSIGNED:
   12402      6171952 :               dupe = specs->unsigned_p;
   12403      6171952 :               if (specs->signed_p)
   12404          139 :                 error_at (loc,
   12405              :                           "both %qs and %qs in declaration specifiers",
   12406              :                           "signed", "unsigned");
   12407      6171813 :               else if (specs->typespec_word == cts_auto_type)
   12408            1 :                 error_at (loc,
   12409              :                           "both %qs and %qs in declaration specifiers",
   12410              :                           "unsigned", "__auto_type");
   12411              :               else if (specs->typespec_word == cts_void)
   12412            5 :                 error_at (loc,
   12413              :                           "both %qs and %qs in declaration specifiers",
   12414              :                           "unsigned", "void");
   12415              :               else if (specs->typespec_word == cts_bool)
   12416            3 :                 error_at (loc,
   12417              :                           "both %qs and %qs in declaration specifiers",
   12418              :                           "unsigned", "_Bool");
   12419              :               else if (specs->typespec_word == cts_float)
   12420            7 :                 error_at (loc,
   12421              :                           "both %qs and %qs in declaration specifiers",
   12422              :                           "unsigned", "float");
   12423              :               else if (specs->typespec_word == cts_double)
   12424           21 :                 error_at (loc,
   12425              :                           "both %qs and %qs in declaration specifiers",
   12426              :                           "unsigned", "double");
   12427              :               else if (specs->typespec_word == cts_floatn_nx)
   12428            0 :                 error_at (loc,
   12429              :                           "both %qs and %<_Float%d%s%> in declaration "
   12430              :                           "specifiers", "unsigned",
   12431            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12432            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12433              :                           ? "x"
   12434              :                           : "");
   12435              :               else if (specs->typespec_word == cts_dfloat32)
   12436            2 :                 error_at (loc,
   12437              :                           "both %qs and %qs in declaration specifiers",
   12438              :                           "unsigned", "_Decimal32");
   12439              :               else if (specs->typespec_word == cts_dfloat64)
   12440            2 :                 error_at (loc,
   12441              :                           "both %qs and %qs in declaration specifiers",
   12442              :                           "unsigned", "_Decimal64");
   12443              :               else if (specs->typespec_word == cts_dfloat128)
   12444            2 :                 error_at (loc,
   12445              :                           "both %qs and %qs in declaration specifiers",
   12446              :                           "unsigned", "_Decimal128");
   12447              :               else if (specs->typespec_word == cts_dfloat64x)
   12448            0 :                 error_at (loc,
   12449              :                           "both %qs and %qs in declaration specifiers",
   12450              :                           "unsigned", "_Decimal64x");
   12451              :               else
   12452              :                 {
   12453      6171770 :                   specs->unsigned_p = true;
   12454      6171770 :                   specs->locations[cdw_unsigned] = loc;
   12455              :                 }
   12456              :               break;
   12457      2577890 :             case RID_COMPLEX:
   12458      2577890 :               dupe = specs->complex_p;
   12459      2577890 :               if (!in_system_header_at (loc))
   12460        69038 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12461              :                              "ISO C90 does not support complex types");
   12462      2577890 :               if (specs->typespec_word == cts_auto_type)
   12463            1 :                 error_at (loc,
   12464              :                           "both %qs and %qs in declaration specifiers",
   12465              :                           "complex", "__auto_type");
   12466              :               else if (specs->typespec_word == cts_void)
   12467            2 :                 error_at (loc,
   12468              :                           "both %qs and %qs in declaration specifiers",
   12469              :                           "complex", "void");
   12470              :               else if (specs->typespec_word == cts_bool)
   12471            2 :                 error_at (loc,
   12472              :                           "both %qs and %qs in declaration specifiers",
   12473              :                           "complex", "_Bool");
   12474              :               else if (specs->typespec_word == cts_bitint)
   12475            1 :                 error_at (loc,
   12476              :                           "both %qs and %qs in declaration specifiers",
   12477              :                           "complex", "_BitInt");
   12478              :               else if (specs->typespec_word == cts_dfloat32)
   12479            1 :                 error_at (loc,
   12480              :                           "both %qs and %qs in declaration specifiers",
   12481              :                           "complex", "_Decimal32");
   12482              :               else if (specs->typespec_word == cts_dfloat64)
   12483            1 :                 error_at (loc,
   12484              :                           "both %qs and %qs in declaration specifiers",
   12485              :                           "complex", "_Decimal64");
   12486              :               else if (specs->typespec_word == cts_dfloat128)
   12487            1 :                 error_at (loc,
   12488              :                           "both %qs and %qs in declaration specifiers",
   12489              :                           "complex", "_Decimal128");
   12490              :               else if (specs->typespec_word == cts_dfloat64x)
   12491            0 :                 error_at (loc,
   12492              :                           "both %qs and %qs in declaration specifiers",
   12493              :                           "complex", "_Decimal64x");
   12494              :               else if (specs->typespec_word == cts_fract)
   12495            0 :                 error_at (loc,
   12496              :                           "both %qs and %qs in declaration specifiers",
   12497              :                           "complex", "_Fract");
   12498              :               else if (specs->typespec_word == cts_accum)
   12499            0 :                 error_at (loc,
   12500              :                           "both %qs and %qs in declaration specifiers",
   12501              :                           "complex", "_Accum");
   12502      2577881 :               else if (specs->saturating_p)
   12503            0 :                 error_at (loc,
   12504              :                           "both %qs and %qs in declaration specifiers",
   12505              :                           "complex", "_Sat");
   12506              :               else
   12507              :                 {
   12508      2577881 :                   specs->complex_p = true;
   12509      2577881 :                   specs->locations[cdw_complex] = loc;
   12510              :                 }
   12511              :               break;
   12512           57 :             case RID_SAT:
   12513           57 :               dupe = specs->saturating_p;
   12514           57 :               pedwarn (loc, OPT_Wpedantic,
   12515              :                        "ISO C does not support saturating types");
   12516           57 :               if (specs->typespec_word == cts_int_n)
   12517            0 :                 error_at (loc,
   12518              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12519            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12520              :               else if (specs->typespec_word == cts_auto_type)
   12521            0 :                 error_at (loc,
   12522              :                           "both %qs and %qs in declaration specifiers",
   12523              :                           "_Sat", "__auto_type");
   12524              :               else if (specs->typespec_word == cts_void)
   12525            0 :                 error_at (loc,
   12526              :                           "both %qs and %qs in declaration specifiers",
   12527              :                           "_Sat", "void");
   12528              :               else if (specs->typespec_word == cts_bool)
   12529            0 :                 error_at (loc,
   12530              :                           "both %qs and %qs in declaration specifiers",
   12531              :                           "_Sat", "_Bool");
   12532              :               else if (specs->typespec_word == cts_bitint)
   12533            0 :                 error_at (loc,
   12534              :                           "both %qs and %qs in declaration specifiers",
   12535              :                           "_Sat", "_BitInt");
   12536              :               else if (specs->typespec_word == cts_char)
   12537            0 :                 error_at (loc,
   12538              :                           "both %qs and %qs in declaration specifiers",
   12539              :                           "_Sat", "char");
   12540              :               else if (specs->typespec_word == cts_int)
   12541            0 :                 error_at (loc,
   12542              :                           "both %qs and %qs in declaration specifiers",
   12543              :                           "_Sat", "int");
   12544              :               else if (specs->typespec_word == cts_float)
   12545            0 :                 error_at (loc,
   12546              :                           "both %qs and %qs in declaration specifiers",
   12547              :                           "_Sat", "float");
   12548              :               else if (specs->typespec_word == cts_double)
   12549            0 :                 error_at (loc,
   12550              :                           "both %qs and %qs in declaration specifiers",
   12551              :                           "_Sat", "double");
   12552              :               else if (specs->typespec_word == cts_floatn_nx)
   12553            0 :                 error_at (loc,
   12554              :                           "both %qs and %<_Float%d%s%> in declaration "
   12555              :                           "specifiers", "_Sat",
   12556            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12557            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12558              :                           ? "x"
   12559              :                           : "");
   12560              :               else if (specs->typespec_word == cts_dfloat32)
   12561            0 :                 error_at (loc,
   12562              :                           "both %qs and %qs in declaration specifiers",
   12563              :                           "_Sat", "_Decimal32");
   12564              :               else if (specs->typespec_word == cts_dfloat64)
   12565            0 :                 error_at (loc,
   12566              :                           "both %qs and %qs in declaration specifiers",
   12567              :                           "_Sat", "_Decimal64");
   12568              :               else if (specs->typespec_word == cts_dfloat128)
   12569            0 :                 error_at (loc,
   12570              :                           "both %qs and %qs in declaration specifiers",
   12571              :                           "_Sat", "_Decimal128");
   12572              :               else if (specs->typespec_word == cts_dfloat64x)
   12573            0 :                 error_at (loc,
   12574              :                           "both %qs and %qs in declaration specifiers",
   12575              :                           "_Sat", "_Decimal64x");
   12576           57 :               else if (specs->complex_p)
   12577            0 :                 error_at (loc,
   12578              :                           "both %qs and %qs in declaration specifiers",
   12579              :                           "_Sat", "complex");
   12580              :               else
   12581              :                 {
   12582           57 :                   specs->saturating_p = true;
   12583           57 :                   specs->locations[cdw_saturating] = loc;
   12584              :                 }
   12585              :               break;
   12586            0 :             default:
   12587            0 :               gcc_unreachable ();
   12588              :             }
   12589              : 
   12590     21738941 :           if (dupe)
   12591          378 :             error_at (loc, "duplicate %qE", type);
   12592              : 
   12593     21738941 :           return specs;
   12594              :         }
   12595              :       else
   12596              :         {
   12597              :           /* "void", "_Bool", "char", "int", "float", "double",
   12598              :              "_FloatN", "_FloatNx", "_Decimal32", "__intN",
   12599              :              "_Decimal64", "_Decimal128", "_Fract", "_Accum", "_BitInt(N)" or
   12600              :              "__auto_type".  */
   12601     60717247 :           if (specs->typespec_word != cts_none)
   12602              :             {
   12603         2171 :               if (i == RID_BOOL)
   12604              :                 {
   12605          175 :                   auto_diagnostic_group d;
   12606          175 :                   if (specs->storage_class == csc_typedef)
   12607            4 :                     error_at (loc,
   12608              :                               "%qs cannot be defined via %<typedef%>",
   12609            2 :                               IDENTIFIER_POINTER (type));
   12610              :                   else
   12611          346 :                     error_at (loc,
   12612              :                               "%qs cannot be used here",
   12613          173 :                               IDENTIFIER_POINTER (type));
   12614          175 :                   add_note_about_new_keyword (loc, type);
   12615          175 :                 }
   12616              :               else
   12617         1996 :                 error_at (loc,
   12618              :                           "two or more data types in declaration specifiers");
   12619         2171 :               return specs;
   12620              :             }
   12621     60715076 :           switch (i)
   12622              :             {
   12623         1883 :             case RID_AUTO_TYPE:
   12624         1883 :               if (specs->long_p)
   12625            1 :                 error_at (loc,
   12626              :                           "both %qs and %qs in declaration specifiers",
   12627              :                           "long", "__auto_type");
   12628         1882 :               else if (specs->short_p)
   12629            1 :                 error_at (loc,
   12630              :                           "both %qs and %qs in declaration specifiers",
   12631              :                           "short", "__auto_type");
   12632         1881 :               else if (specs->signed_p)
   12633            1 :                 error_at (loc,
   12634              :                           "both %qs and %qs in declaration specifiers",
   12635              :                           "signed", "__auto_type");
   12636         1880 :               else if (specs->unsigned_p)
   12637            1 :                 error_at (loc,
   12638              :                           "both %qs and %qs in declaration specifiers",
   12639              :                           "unsigned", "__auto_type");
   12640         1879 :               else if (specs->complex_p)
   12641            1 :                 error_at (loc,
   12642              :                           "both %qs and %qs in declaration specifiers",
   12643              :                           "complex", "__auto_type");
   12644         1878 :               else if (specs->saturating_p)
   12645            0 :                 error_at (loc,
   12646              :                           "both %qs and %qs in declaration specifiers",
   12647              :                           "_Sat", "__auto_type");
   12648              :               else
   12649              :                 {
   12650         1878 :                   specs->typespec_word = cts_auto_type;
   12651         1878 :                   specs->locations[cdw_typespec] = loc;
   12652              :                 }
   12653         1883 :               return specs;
   12654        51681 :             case RID_INT_N_0:
   12655        51681 :             case RID_INT_N_1:
   12656        51681 :             case RID_INT_N_2:
   12657        51681 :             case RID_INT_N_3:
   12658        51681 :               specs->u.int_n_idx = i - RID_INT_N_0;
   12659        51681 :               if (!in_system_header_at (input_location)
   12660              :                   /* If the INT_N type ends in "__", and so is of the format
   12661              :                      "__intN__", don't pedwarn.  */
   12662        51681 :                   && (strncmp (IDENTIFIER_POINTER (type)
   12663        41069 :                                + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0))
   12664        41069 :                 pedwarn (loc, OPT_Wpedantic,
   12665              :                          "ISO C does not support %<__int%d%> types",
   12666        41069 :                          int_n_data[specs->u.int_n_idx].bitsize);
   12667              : 
   12668        51681 :               if (specs->long_p)
   12669           53 :                 error_at (loc,
   12670              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12671           53 :                           int_n_data[specs->u.int_n_idx].bitsize, "long");
   12672        51628 :               else if (specs->saturating_p)
   12673            0 :                 error_at (loc,
   12674              :                           "both %qs and %<__int%d%> in declaration specifiers",
   12675            0 :                           "_Sat", int_n_data[specs->u.int_n_idx].bitsize);
   12676        51628 :               else if (specs->short_p)
   12677           19 :                 error_at (loc,
   12678              :                           "both %<__int%d%> and %qs in declaration specifiers",
   12679           19 :                           int_n_data[specs->u.int_n_idx].bitsize, "short");
   12680        51609 :               else if (! int_n_enabled_p[specs->u.int_n_idx])
   12681              :                 {
   12682            0 :                   specs->typespec_word = cts_int_n;
   12683            0 :                   error_at (loc,
   12684              :                             "%<__int%d%> is not supported on this target",
   12685            0 :                             int_n_data[specs->u.int_n_idx].bitsize);
   12686              :                 }
   12687              :               else
   12688              :                 {
   12689        51609 :                   specs->typespec_word = cts_int_n;
   12690        51609 :                   specs->locations[cdw_typespec] = loc;
   12691              :                 }
   12692        51681 :               return specs;
   12693      7841239 :             case RID_VOID:
   12694      7841239 :               if (specs->long_p)
   12695           44 :                 error_at (loc,
   12696              :                           "both %qs and %qs in declaration specifiers",
   12697              :                           "long", "void");
   12698      7841195 :               else if (specs->short_p)
   12699           21 :                 error_at (loc,
   12700              :                           "both %qs and %qs in declaration specifiers",
   12701              :                           "short", "void");
   12702      7841174 :               else if (specs->signed_p)
   12703            5 :                 error_at (loc,
   12704              :                           "both %qs and %qs in declaration specifiers",
   12705              :                           "signed", "void");
   12706      7841169 :               else if (specs->unsigned_p)
   12707            5 :                 error_at (loc,
   12708              :                           "both %qs and %qs in declaration specifiers",
   12709              :                           "unsigned", "void");
   12710      7841164 :               else if (specs->complex_p)
   12711            2 :                 error_at (loc,
   12712              :                           "both %qs and %qs in declaration specifiers",
   12713              :                           "complex", "void");
   12714      7841162 :               else if (specs->saturating_p)
   12715            0 :                 error_at (loc,
   12716              :                           "both %qs and %qs in declaration specifiers",
   12717              :                           "_Sat", "void");
   12718              :               else
   12719              :                 {
   12720      7841162 :                   specs->typespec_word = cts_void;
   12721      7841162 :                   specs->locations[cdw_typespec] = loc;
   12722              :                 }
   12723      7841239 :               return specs;
   12724        85867 :             case RID_BOOL:
   12725        85867 :               if (!in_system_header_at (loc))
   12726        71388 :                 pedwarn_c90 (loc, OPT_Wpedantic,
   12727              :                              "ISO C90 does not support boolean types");
   12728        85867 :               if (specs->long_p)
   12729           27 :                 error_at (loc,
   12730              :                           "both %qs and %qs in declaration specifiers",
   12731              :                           "long", "_Bool");
   12732        85840 :               else if (specs->short_p)
   12733           11 :                 error_at (loc,
   12734              :                           "both %qs and %qs in declaration specifiers",
   12735              :                           "short", "_Bool");
   12736        85829 :               else if (specs->signed_p)
   12737            3 :                 error_at (loc,
   12738              :                           "both %qs and %qs in declaration specifiers",
   12739              :                           "signed", "_Bool");
   12740        85826 :               else if (specs->unsigned_p)
   12741            3 :                 error_at (loc,
   12742              :                           "both %qs and %qs in declaration specifiers",
   12743              :                           "unsigned", "_Bool");
   12744        85823 :               else if (specs->complex_p)
   12745            2 :                 error_at (loc,
   12746              :                           "both %qs and %qs in declaration specifiers",
   12747              :                           "complex", "_Bool");
   12748        85821 :               else if (specs->saturating_p)
   12749            0 :                 error_at (loc,
   12750              :                           "both %qs and %qs in declaration specifiers",
   12751              :                           "_Sat", "_Bool");
   12752              :               else
   12753              :                 {
   12754        85821 :                   specs->typespec_word = cts_bool;
   12755        85821 :                   specs->locations[cdw_typespec] = loc;
   12756              :                 }
   12757        85867 :               return specs;
   12758      9042500 :             case RID_CHAR:
   12759      9042500 :               if (specs->long_p)
   12760           44 :                 error_at (loc,
   12761              :                           "both %qs and %qs in declaration specifiers",
   12762              :                           "long", "char");
   12763      9042456 :               else if (specs->short_p)
   12764           21 :                 error_at (loc,
   12765              :                           "both %qs and %qs in declaration specifiers",
   12766              :                           "short", "char");
   12767      9042435 :               else if (specs->saturating_p)
   12768            0 :                 error_at (loc,
   12769              :                           "both %qs and %qs in declaration specifiers",
   12770              :                           "_Sat", "char");
   12771              :               else
   12772              :                 {
   12773      9042435 :                   specs->typespec_word = cts_char;
   12774      9042435 :                   specs->locations[cdw_typespec] = loc;
   12775              :                 }
   12776      9042500 :               return specs;
   12777     23822077 :             case RID_INT:
   12778     23822077 :               if (specs->saturating_p)
   12779            0 :                 error_at (loc,
   12780              :                           "both %qs and %qs in declaration specifiers",
   12781              :                           "_Sat", "int");
   12782              :               else
   12783              :                 {
   12784     23822077 :                   specs->typespec_word = cts_int;
   12785     23822077 :                   specs->locations[cdw_typespec] = loc;
   12786              :                 }
   12787     23822077 :               return specs;
   12788      3390552 :             case RID_FLOAT:
   12789      3390552 :               if (specs->long_p)
   12790           44 :                 error_at (loc,
   12791              :                           "both %qs and %qs in declaration specifiers",
   12792              :                           "long", "float");
   12793      3390508 :               else if (specs->short_p)
   12794           21 :                 error_at (loc,
   12795              :                           "both %qs and %qs in declaration specifiers",
   12796              :                           "short", "float");
   12797      3390487 :               else if (specs->signed_p)
   12798            5 :                 error_at (loc,
   12799              :                           "both %qs and %qs in declaration specifiers",
   12800              :                           "signed", "float");
   12801      3390482 :               else if (specs->unsigned_p)
   12802            5 :                 error_at (loc,
   12803              :                           "both %qs and %qs in declaration specifiers",
   12804              :                           "unsigned", "float");
   12805      3390477 :               else if (specs->saturating_p)
   12806            0 :                 error_at (loc,
   12807              :                           "both %qs and %qs in declaration specifiers",
   12808              :                           "_Sat", "float");
   12809              :               else
   12810              :                 {
   12811      3390477 :                   specs->typespec_word = cts_float;
   12812      3390477 :                   specs->locations[cdw_typespec] = loc;
   12813              :                 }
   12814      3390552 :               return specs;
   12815      6105705 :             case RID_DOUBLE:
   12816      6105705 :               if (specs->long_long_p)
   12817           22 :                 error_at (loc,
   12818              :                           "both %qs and %qs in declaration specifiers",
   12819              :                           "long long", "double");
   12820      6105683 :               else if (specs->short_p)
   12821           21 :                 error_at (loc,
   12822              :                           "both %qs and %qs in declaration specifiers",
   12823              :                           "short", "double");
   12824      6105662 :               else if (specs->signed_p)
   12825           13 :                 error_at (loc,
   12826              :                           "both %qs and %qs in declaration specifiers",
   12827              :                           "signed", "double");
   12828      6105649 :               else if (specs->unsigned_p)
   12829           13 :                 error_at (loc,
   12830              :                           "both %qs and %qs in declaration specifiers",
   12831              :                           "unsigned", "double");
   12832      6105636 :               else if (specs->saturating_p)
   12833            0 :                 error_at (loc,
   12834              :                           "both %qs and %qs in declaration specifiers",
   12835              :                           "_Sat", "double");
   12836              :               else
   12837              :                 {
   12838      6105636 :                   specs->typespec_word = cts_double;
   12839      6105636 :                   specs->locations[cdw_typespec] = loc;
   12840              :                 }
   12841      6105705 :               return specs;
   12842     10280230 :             CASE_RID_FLOATN_NX:
   12843     10280230 :               specs->u.floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
   12844     10280230 :               if (!in_system_header_at (input_location))
   12845        53738 :                 pedwarn_c11 (loc, OPT_Wpedantic,
   12846              :                              "ISO C does not support the %<_Float%d%s%> type"
   12847              :                              " before C23",
   12848        53738 :                              floatn_nx_types[specs->u.floatn_nx_idx].n,
   12849        53738 :                              floatn_nx_types[specs->u.floatn_nx_idx].extended
   12850              :                              ? "x"
   12851              :                              : "");
   12852              : 
   12853     10280230 :               if (specs->long_p)
   12854            0 :                 error_at (loc,
   12855              :                           "both %qs and %<_Float%d%s%> in declaration "
   12856              :                           "specifiers", "long",
   12857            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12858            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12859              :                           ? "x"
   12860              :                           : "");
   12861     10280230 :               else if (specs->short_p)
   12862            0 :                 error_at (loc,
   12863              :                           "both %qs and %<_Float%d%s%> in declaration "
   12864              :                           "specifiers", "short",
   12865            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12866            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12867              :                           ? "x"
   12868              :                           : "");
   12869     10280230 :               else if (specs->signed_p)
   12870            0 :                 error_at (loc,
   12871              :                           "both %qs and %<_Float%d%s%> in declaration "
   12872              :                           "specifiers", "signed",
   12873            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12874            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12875              :                           ? "x"
   12876              :                           : "");
   12877     10280230 :               else if (specs->unsigned_p)
   12878            0 :                 error_at (loc,
   12879              :                           "both %qs and %<_Float%d%s%> in declaration "
   12880              :                           "specifiers", "unsigned",
   12881            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12882            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12883              :                           ? "x"
   12884              :                           : "");
   12885     10280230 :               else if (specs->saturating_p)
   12886            0 :                 error_at (loc,
   12887              :                           "both %qs and %<_Float%d%s%> in declaration "
   12888              :                           "specifiers", "_Sat",
   12889            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].n,
   12890            0 :                           floatn_nx_types[specs->u.floatn_nx_idx].extended
   12891              :                           ? "x"
   12892              :                           : "");
   12893     10280230 :               else if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   12894              :                 {
   12895           88 :                   specs->typespec_word = cts_floatn_nx;
   12896          176 :                   error_at (loc,
   12897              :                             "%<_Float%d%s%> is not supported on this target",
   12898           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].n,
   12899           88 :                             floatn_nx_types[specs->u.floatn_nx_idx].extended
   12900              :                             ? "x"
   12901              :                             : "");
   12902              :                 }
   12903              :               else
   12904              :                 {
   12905     10280142 :                   specs->typespec_word = cts_floatn_nx;
   12906     10280142 :                   specs->locations[cdw_typespec] = loc;
   12907              :                 }
   12908     10280230 :               return specs;
   12909        47633 :             case RID_DFLOAT32:
   12910        47633 :             case RID_DFLOAT64:
   12911        47633 :             case RID_DFLOAT128:
   12912        47633 :             case RID_DFLOAT64X:
   12913        47633 :               {
   12914        47633 :                 const char *str;
   12915        47633 :                 if (i == RID_DFLOAT32)
   12916              :                   str = "_Decimal32";
   12917              :                 else if (i == RID_DFLOAT64)
   12918              :                   str = "_Decimal64";
   12919              :                 else if (i == RID_DFLOAT128)
   12920              :                   str = "_Decimal128";
   12921              :                 else
   12922        47633 :                   str = "_Decimal64x";
   12923        47633 :                 if (specs->long_long_p)
   12924           18 :                   error_at (loc,
   12925              :                             "both %qs and %qs in declaration specifiers",
   12926              :                             "long long", str);
   12927        47633 :                 if (specs->long_p)
   12928           33 :                   error_at (loc,
   12929              :                             "both %qs and %qs in declaration specifiers",
   12930              :                             "long", str);
   12931        47600 :                 else if (specs->short_p)
   12932           18 :                   error_at (loc,
   12933              :                             "both %qs and %qs in declaration specifiers",
   12934              :                             "short", str);
   12935        47582 :                 else if (specs->signed_p)
   12936            6 :                   error_at (loc,
   12937              :                             "both %qs and %qs in declaration specifiers",
   12938              :                             "signed", str);
   12939        47576 :                 else if (specs->unsigned_p)
   12940            3 :                   error_at (loc,
   12941              :                             "both %qs and %qs in declaration specifiers",
   12942              :                             "unsigned", str);
   12943        47573 :                 else if (specs->complex_p)
   12944            3 :                   error_at (loc,
   12945              :                             "both %qs and %qs in declaration specifiers",
   12946              :                             "complex", str);
   12947        47570 :                 else if (specs->saturating_p)
   12948            0 :                   error_at (loc,
   12949              :                             "both %qs and %qs in declaration specifiers",
   12950              :                             "_Sat", str);
   12951        47570 :                 else if (i == RID_DFLOAT32)
   12952        15957 :                   specs->typespec_word = cts_dfloat32;
   12953        31613 :                 else if (i == RID_DFLOAT64)
   12954        15832 :                   specs->typespec_word = cts_dfloat64;
   12955        15781 :                 else if (i == RID_DFLOAT128)
   12956        15734 :                   specs->typespec_word = cts_dfloat128;
   12957              :                 else
   12958           47 :                   specs->typespec_word = cts_dfloat64x;
   12959        47633 :                 specs->locations[cdw_typespec] = loc;
   12960              :               }
   12961        47633 :               if (!targetm.decimal_float_supported_p ())
   12962            0 :                 error_at (loc,
   12963              :                           "decimal floating-point not supported "
   12964              :                           "for this target");
   12965        47633 :               pedwarn_c11 (loc, OPT_Wpedantic,
   12966              :                            "ISO C does not support decimal floating-point "
   12967              :                            "before C23");
   12968        47633 :               return specs;
   12969           59 :             case RID_FRACT:
   12970           59 :             case RID_ACCUM:
   12971           59 :               {
   12972           59 :                 const char *str;
   12973           59 :                 if (i == RID_FRACT)
   12974              :                   str = "_Fract";
   12975              :                 else
   12976           29 :                   str = "_Accum";
   12977           59 :                 if (specs->complex_p)
   12978            0 :                   error_at (loc,
   12979              :                             "both %qs and %qs in declaration specifiers",
   12980              :                             "complex", str);
   12981           59 :                 else if (i == RID_FRACT)
   12982           30 :                     specs->typespec_word = cts_fract;
   12983              :                 else
   12984           29 :                     specs->typespec_word = cts_accum;
   12985           59 :                 specs->locations[cdw_typespec] = loc;
   12986              :               }
   12987           59 :               if (!targetm.fixed_point_supported_p ())
   12988           59 :                 error_at (loc,
   12989              :                           "fixed-point types not supported for this target");
   12990           59 :               pedwarn (loc, OPT_Wpedantic,
   12991              :                        "ISO C does not support fixed-point types");
   12992           59 :               return specs;
   12993        45650 :             case RID_BITINT:
   12994        45650 :               if (specs->long_p)
   12995            2 :                 error_at (loc,
   12996              :                           "both %qs and %qs in declaration specifiers",
   12997              :                           "long", "_BitInt");
   12998        45648 :               else if (specs->short_p)
   12999            1 :                 error_at (loc,
   13000              :                           "both %qs and %qs in declaration specifiers",
   13001              :                           "short", "_BitInt");
   13002        45647 :               else if (specs->complex_p)
   13003            1 :                 error_at (loc,
   13004              :                           "both %qs and %qs in declaration specifiers",
   13005              :                           "complex", "_BitInt");
   13006        45646 :               else if (specs->saturating_p)
   13007            0 :                 error_at (loc,
   13008              :                           "both %qs and %qs in declaration specifiers",
   13009              :                           "_Sat", "_BitInt");
   13010              :               else
   13011              :                 {
   13012        45646 :                   specs->typespec_word = cts_bitint;
   13013        45646 :                   specs->locations[cdw_typespec] = loc;
   13014        45646 :                   specs->u.bitint_prec = -1;
   13015        45646 :                   if (error_operand_p (spec.expr))
   13016            7 :                     return specs;
   13017        45646 :                   if (TREE_CODE (spec.expr) != INTEGER_CST
   13018        45646 :                       || !INTEGRAL_TYPE_P (TREE_TYPE (spec.expr)))
   13019              :                     {
   13020            1 :                       error_at (loc, "%<_BitInt%> argument is not an integer "
   13021              :                                      "constant expression");
   13022            1 :                       return specs;
   13023              :                     }
   13024        45645 :                   if (tree_int_cst_sgn (spec.expr) <= 0)
   13025              :                     {
   13026            4 :                       error_at (loc, "%<_BitInt%> argument %qE is not a "
   13027              :                                      "positive integer constant expression",
   13028              :                                 spec.expr);
   13029            4 :                       return specs;
   13030              :                     }
   13031        45641 :                   if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1)
   13032              :                     {
   13033            2 :                       error_at (loc, "%<_BitInt%> argument %qE is larger than "
   13034              :                                      "%<BITINT_MAXWIDTH%> %qd",
   13035              :                                 spec.expr, (int) WIDE_INT_MAX_PRECISION - 1);
   13036            2 :                       return specs;
   13037              :                     }
   13038        45639 :                   specs->u.bitint_prec = tree_to_uhwi (spec.expr);
   13039        45639 :                   struct bitint_info info;
   13040        45639 :                   if (!targetm.c.bitint_type_info (specs->u.bitint_prec,
   13041              :                                                    &info))
   13042              :                     {
   13043            0 :                       sorry_at (loc, "%<_BitInt(%d)%> is not supported on "
   13044              :                                      "this target", specs->u.bitint_prec);
   13045            0 :                       specs->u.bitint_prec = -1;
   13046            0 :                       return specs;
   13047              :                     }
   13048              :                 }
   13049        45643 :               return specs;
   13050              :             default:
   13051              :               /* ObjC reserved word "id", handled below.  */
   13052              :               break;
   13053              :             }
   13054              :         }
   13055              :     }
   13056              : 
   13057              :   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
   13058              :      form of ObjC type, cases such as "int" and "long" being handled
   13059              :      above), a TYPE (struct, union, enum and typeof specifiers) or an
   13060              :      ERROR_MARK.  In none of these cases may there have previously
   13061              :      been any type specifiers.  */
   13062    248795933 :   if (specs->type || specs->typespec_word != cts_none
   13063    248795921 :       || specs->long_p || specs->short_p || specs->signed_p
   13064    248795918 :       || specs->unsigned_p || specs->complex_p)
   13065           21 :     error_at (loc, "two or more data types in declaration specifiers");
   13066    248795912 :   else if (TREE_CODE (type) == TYPE_DECL)
   13067              :     {
   13068    245521809 :       mark_decl_used (type, false);
   13069    245521809 :       specs->type = TREE_TYPE (type);
   13070    245521809 :       if (TREE_TYPE (type) != error_mark_node)
   13071              :         {
   13072    245521796 :           specs->decl_attr = DECL_ATTRIBUTES (type);
   13073    245521796 :           specs->typedef_p = true;
   13074    245521796 :           specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
   13075    245521796 :           specs->locations[cdw_typedef] = loc;
   13076              : 
   13077              :           /* If this typedef name is defined in a struct, then a C++
   13078              :              lookup would return a different value.  */
   13079    245521796 :           if (warn_cxx_compat
   13080    245521796 :               && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
   13081            2 :             warning_at (loc, OPT_Wc___compat,
   13082              :                         "C++ lookup of %qD would return a field, not a type",
   13083              :                         type);
   13084              : 
   13085              :           /* If we are parsing a struct, record that a struct field
   13086              :              used a typedef.  */
   13087    245521796 :           if (warn_cxx_compat && struct_parse_info != NULL)
   13088         1751 :             struct_parse_info->typedefs_seen.safe_push (type);
   13089              :         }
   13090              :     }
   13091      3274103 :   else if (TREE_CODE (type) == IDENTIFIER_NODE)
   13092              :     {
   13093            0 :       tree t = lookup_name (type);
   13094            0 :       if (!t || TREE_CODE (t) != TYPE_DECL)
   13095            0 :         error_at (loc, "%qE fails to be a typedef or built in type", type);
   13096            0 :       else if (TREE_TYPE (t) == error_mark_node)
   13097              :         ;
   13098              :       else
   13099              :         {
   13100            0 :           specs->type = TREE_TYPE (t);
   13101            0 :           specs->locations[cdw_typespec] = loc;
   13102              :         }
   13103              :     }
   13104              :   else
   13105              :     {
   13106      3274103 :       if (TREE_CODE (type) != ERROR_MARK)
   13107              :         {
   13108      3273898 :           if (spec.kind == ctsk_typeof)
   13109              :             {
   13110       833228 :               specs->typedef_p = true;
   13111       833228 :               specs->locations[cdw_typedef] = loc;
   13112              :             }
   13113      3273898 :           if (spec.expr)
   13114              :             {
   13115          913 :               if (specs->expr)
   13116            0 :                 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
   13117              :                                       specs->expr, spec.expr);
   13118              :               else
   13119          913 :                 specs->expr = spec.expr;
   13120          913 :               specs->expr_const_operands &= spec.expr_const_operands;
   13121              :             }
   13122              :         }
   13123      3274103 :       specs->type = type;
   13124      3274103 :       if (spec.has_enum_type_specifier
   13125          169 :           && spec.kind != ctsk_tagdef)
   13126           49 :         specs->enum_type_specifier_ref_p = true;
   13127              :     }
   13128              : 
   13129              :   return specs;
   13130              : }
   13131              : 
   13132              : /* Add the storage class specifier or function specifier SCSPEC to the
   13133              :    declaration specifiers SPECS, returning SPECS.  */
   13134              : 
   13135              : struct c_declspecs *
   13136     90234833 : declspecs_add_scspec (location_t loc,
   13137              :                       struct c_declspecs *specs,
   13138              :                       tree scspec)
   13139              : {
   13140     90234833 :   enum rid i;
   13141     90234833 :   enum c_storage_class n = csc_none;
   13142     90234833 :   bool dupe = false;
   13143     90234833 :   specs->declspecs_seen_p = true;
   13144     90234833 :   specs->non_std_attrs_seen_p = true;
   13145     90234833 :   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
   13146              :               && C_IS_RESERVED_WORD (scspec));
   13147     90234833 :   i = C_RID_CODE (scspec);
   13148     90234833 :   if (specs->non_sc_seen_p)
   13149         2095 :     warning (OPT_Wold_style_declaration,
   13150              :              "%qE is not at beginning of declaration", scspec);
   13151     90234833 :   switch (i)
   13152              :     {
   13153     35561581 :     case RID_INLINE:
   13154              :       /* C99 permits duplicate inline.  Although of doubtful utility,
   13155              :          it seems simplest to permit it in gnu89 mode as well, as
   13156              :          there is also little utility in maintaining this as a
   13157              :          difference between gnu89 and C99 inline.  */
   13158     35561581 :       dupe = false;
   13159     35561581 :       specs->inline_p = true;
   13160     35561581 :       specs->locations[cdw_inline] = loc;
   13161     35561581 :       break;
   13162        23317 :     case RID_NORETURN:
   13163              :       /* Duplicate _Noreturn is permitted.  */
   13164        23317 :       dupe = false;
   13165        23317 :       specs->noreturn_p = true;
   13166        23317 :       specs->locations[cdw_noreturn] = loc;
   13167        23317 :       break;
   13168         2861 :     case RID_THREAD:
   13169         2861 :       dupe = specs->thread_p;
   13170         2861 :       if (specs->storage_class == csc_auto)
   13171            2 :         error ("%qE used with %<auto%>", scspec);
   13172         2859 :       else if (specs->storage_class == csc_register)
   13173            3 :         error ("%qE used with %<register%>", scspec);
   13174         2856 :       else if (specs->storage_class == csc_typedef)
   13175            2 :         error ("%qE used with %<typedef%>", scspec);
   13176         2854 :       else if (specs->constexpr_p)
   13177            2 :         error ("%qE used with %<constexpr%>", scspec);
   13178              :       else
   13179              :         {
   13180         2852 :           specs->thread_p = true;
   13181         2852 :           specs->thread_gnu_p = (strcmp (IDENTIFIER_POINTER (scspec),
   13182         2852 :                                          "__thread") == 0);
   13183              :           /* A diagnostic is not required for the use of this
   13184              :              identifier in the implementation namespace; only diagnose
   13185              :              it for the C11 spelling because of existing code using
   13186              :              the other spelling.  */
   13187         2852 :           if (!specs->thread_gnu_p)
   13188              :             {
   13189          116 :               if (flag_isoc99)
   13190          113 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13191              :                              "ISO C99 does not support %qE", scspec);
   13192              :               else
   13193            3 :                 pedwarn_c99 (loc, OPT_Wpedantic,
   13194              :                              "ISO C90 does not support %qE", scspec);
   13195              :             }
   13196         2852 :           specs->locations[cdw_thread] = loc;
   13197              :         }
   13198              :       break;
   13199          262 :     case RID_AUTO:
   13200          262 :       if (flag_isoc23
   13201          223 :           && specs->typespec_kind == ctsk_none
   13202          212 :           && specs->storage_class != csc_typedef)
   13203              :         {
   13204              :           /* "auto" potentially used for type deduction.  */
   13205          211 :           if (specs->c23_auto_p)
   13206            2 :             error ("duplicate %qE", scspec);
   13207          211 :           specs->c23_auto_p = true;
   13208          211 :           return specs;
   13209              :         }
   13210           51 :       n = csc_auto;
   13211              :       /* auto may only be used with another storage class specifier,
   13212              :          such as constexpr, if the type is inferred.  */
   13213           51 :       if (specs->constexpr_p)
   13214            2 :         error ("%qE used with %<constexpr%>", scspec);
   13215              :       break;
   13216     49910960 :     case RID_EXTERN:
   13217     49910960 :       n = csc_extern;
   13218              :       /* Diagnose "__thread extern".  */
   13219     49910960 :       if (specs->thread_p && specs->thread_gnu_p)
   13220            2 :         error ("%<__thread%> before %<extern%>");
   13221              :       break;
   13222              :     case RID_REGISTER:
   13223              :       n = csc_register;
   13224              :       break;
   13225       425493 :     case RID_STATIC:
   13226       425493 :       n = csc_static;
   13227              :       /* Diagnose "__thread static".  */
   13228       425493 :       if (specs->thread_p && specs->thread_gnu_p)
   13229            1 :         error ("%<__thread%> before %<static%>");
   13230              :       break;
   13231      4306612 :     case RID_TYPEDEF:
   13232      4306612 :       n = csc_typedef;
   13233      4306612 :       if (specs->c23_auto_p)
   13234              :         {
   13235            1 :           error ("%<typedef%> used with %<auto%>");
   13236            1 :           specs->c23_auto_p = false;
   13237              :         }
   13238              :       break;
   13239          616 :     case RID_CONSTEXPR:
   13240          616 :       dupe = specs->constexpr_p;
   13241          616 :       if (specs->storage_class == csc_extern)
   13242            1 :         error ("%qE used with %<extern%>", scspec);
   13243          615 :       else if (specs->storage_class == csc_typedef)
   13244            1 :         error ("%qE used with %<typedef%>", scspec);
   13245          614 :       else if (specs->storage_class == csc_auto)
   13246              :         /* auto may only be used with another storage class specifier,
   13247              :            such as constexpr, if the type is inferred.  */
   13248            2 :         error ("%qE used with %<auto%>", scspec);
   13249          612 :       else if (specs->thread_p)
   13250            4 :         error ("%qE used with %qs", scspec,
   13251            2 :                specs->thread_gnu_p ? "__thread" : "_Thread_local");
   13252              :       else
   13253          610 :         specs->constexpr_p = true;
   13254              :       break;
   13255            0 :     default:
   13256            0 :       gcc_unreachable ();
   13257              :     }
   13258     90234628 :   if (n != csc_none && n == specs->storage_class)
   13259              :     dupe = true;
   13260     90234614 :   if (dupe)
   13261              :     {
   13262           12 :       if (i == RID_THREAD)
   13263            2 :         error ("duplicate %<_Thread_local%> or %<__thread%>");
   13264              :       else
   13265           10 :         error ("duplicate %qE", scspec);
   13266              :     }
   13267     90234622 :   if (n != csc_none)
   13268              :     {
   13269     54646247 :       if (specs->storage_class != csc_none && n != specs->storage_class)
   13270              :         {
   13271            7 :           error ("multiple storage classes in declaration specifiers");
   13272              :         }
   13273              :       else
   13274              :         {
   13275     54646240 :           specs->storage_class = n;
   13276     54646240 :           specs->locations[cdw_storage_class] = loc;
   13277     54646240 :           if (n != csc_extern && n != csc_static && specs->thread_p)
   13278              :             {
   13279            8 :               error ("%qs used with %qE",
   13280            8 :                      specs->thread_gnu_p ? "__thread" : "_Thread_local",
   13281              :                      scspec);
   13282            8 :               specs->thread_p = false;
   13283              :             }
   13284     54646240 :           if (n != csc_auto && n != csc_register && n != csc_static
   13285     54217569 :               && specs->constexpr_p)
   13286              :             {
   13287            2 :               error ("%<constexpr%> used with %qE", scspec);
   13288            2 :               specs->constexpr_p = false;
   13289              :             }
   13290              :         }
   13291              :     }
   13292              :   return specs;
   13293              : }
   13294              : 
   13295              : /* Add the attributes ATTRS to the declaration specifiers SPECS,
   13296              :    returning SPECS.  */
   13297              : 
   13298              : struct c_declspecs *
   13299     35873310 : declspecs_add_attrs (location_t loc, struct c_declspecs *specs, tree attrs)
   13300              : {
   13301     35873310 :   specs->attrs = chainon (attrs, specs->attrs);
   13302     35873310 :   specs->locations[cdw_attributes] = loc;
   13303     35873310 :   specs->declspecs_seen_p = true;
   13304              :   /* In the case of standard attributes at the start of the
   13305              :      declaration, the caller will reset this.  */
   13306     35873310 :   specs->non_std_attrs_seen_p = true;
   13307     35873310 :   return specs;
   13308              : }
   13309              : 
   13310              : /* Add an _Alignas specifier (expression ALIGN, or type whose
   13311              :    alignment is ALIGN) to the declaration specifiers SPECS, returning
   13312              :    SPECS.  */
   13313              : struct c_declspecs *
   13314          202 : declspecs_add_alignas (location_t loc,
   13315              :                        struct c_declspecs *specs, tree align)
   13316              : {
   13317          202 :   specs->alignas_p = true;
   13318          202 :   specs->locations[cdw_alignas] = loc;
   13319          202 :   if (align == error_mark_node)
   13320              :     return specs;
   13321              : 
   13322              :   /* Only accept the alignment if it's valid and greater than
   13323              :      the current one.  Zero is invalid but by C11 required to
   13324              :      be silently ignored.  */
   13325          200 :   int align_log = check_user_alignment (align, false, /* warn_zero = */false);
   13326          200 :   if (align_log > specs->align_log)
   13327          167 :     specs->align_log = align_log;
   13328              :   return specs;
   13329              : }
   13330              : 
   13331              : /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
   13332              :    specifiers with any other type specifier to determine the resulting
   13333              :    type.  This is where ISO C checks on complex types are made, since
   13334              :    "_Complex long" is a prefix of the valid ISO C type "_Complex long
   13335              :    double".  Also apply postfix standard attributes to modify the type.  */
   13336              : 
   13337              : struct c_declspecs *
   13338    313689894 : finish_declspecs (struct c_declspecs *specs)
   13339              : {
   13340              :   /* If a type was specified as a whole, we have no modifiers and are
   13341              :      done.  */
   13342    313689894 :   if (specs->type != NULL_TREE)
   13343              :     {
   13344    248795866 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13345              :                   && !specs->signed_p && !specs->unsigned_p
   13346              :                   && !specs->complex_p && !specs->c23_auto_p);
   13347              : 
   13348              :       /* Set a dummy type.  */
   13349    248795866 :       if (TREE_CODE (specs->type) == ERROR_MARK)
   13350          181 :         specs->type = integer_type_node;
   13351    248795866 :       goto handle_postfix_attrs;
   13352              :     }
   13353              : 
   13354              :   /* If none of "void", "_Bool", "char", "int", "float" or "double"
   13355              :      has been specified, treat it as "int" unless "_Complex" is
   13356              :      present and there are no other specifiers.  If we just have
   13357              :      "_Complex", it is equivalent to "_Complex double", but e.g.
   13358              :      "_Complex short" is equivalent to "_Complex short int".  */
   13359     64894028 :   if (specs->typespec_word == cts_none)
   13360              :     {
   13361      4179430 :       if (specs->saturating_p)
   13362              :         {
   13363            1 :           error_at (specs->locations[cdw_saturating],
   13364              :                     "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
   13365            1 :           if (!targetm.fixed_point_supported_p ())
   13366            1 :             error_at (specs->locations[cdw_saturating],
   13367              :                       "fixed-point types not supported for this target");
   13368            1 :           specs->typespec_word = cts_fract;
   13369              :         }
   13370      4179429 :       else if (specs->long_p || specs->short_p
   13371       193586 :                || specs->signed_p || specs->unsigned_p)
   13372              :         {
   13373      4168989 :           specs->typespec_word = cts_int;
   13374              :         }
   13375        10440 :       else if (specs->complex_p)
   13376              :         {
   13377          130 :           specs->typespec_word = cts_double;
   13378          130 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13379              :                    "ISO C does not support plain %<complex%> meaning "
   13380              :                    "%<double complex%>");
   13381              :         }
   13382        10310 :       else if (specs->c23_auto_p)
   13383              :         {
   13384              :           /* Type to be filled in later, including applying postfix
   13385              :              attributes.  This warning only actually appears for
   13386              :              -Wc11-c23-compat in C23 mode; in older modes, there may
   13387              :              be a warning or pedwarn for implicit "int" instead, or
   13388              :              other errors for use of auto at file scope.  */
   13389           93 :           pedwarn_c11 (input_location, OPT_Wpedantic,
   13390              :                        "ISO C does not support %<auto%> type deduction "
   13391              :                        "before C23");
   13392           93 :           return specs;
   13393              :         }
   13394              :       else
   13395              :         {
   13396        10217 :           specs->typespec_word = cts_int;
   13397        10217 :           specs->default_int_p = true;
   13398              :           /* We don't diagnose this here because grokdeclarator will
   13399              :              give more specific diagnostics according to whether it is
   13400              :              a function definition.  */
   13401              :         }
   13402              :     }
   13403              : 
   13404              :   /* If "signed" was specified, record this to distinguish "int" and
   13405              :      "signed int" in the case of a bit-field with
   13406              :      -funsigned-bitfields.  */
   13407     64893935 :   specs->explicit_signed_p = specs->signed_p;
   13408              : 
   13409              :   /* Now compute the actual type.  */
   13410     64893935 :   gcc_assert (!specs->c23_auto_p);
   13411     64893935 :   switch (specs->typespec_word)
   13412              :     {
   13413         1878 :     case cts_auto_type:
   13414         1878 :       gcc_assert (!specs->long_p && !specs->short_p
   13415              :                   && !specs->signed_p && !specs->unsigned_p
   13416              :                   && !specs->complex_p);
   13417              :       /* Type to be filled in later.  */
   13418         1878 :       if (specs->postfix_attrs)
   13419            2 :         error ("%<__auto_type%> followed by %<[[]]%> attributes");
   13420              :       break;
   13421      7841162 :     case cts_void:
   13422      7841162 :       gcc_assert (!specs->long_p && !specs->short_p
   13423              :                   && !specs->signed_p && !specs->unsigned_p
   13424              :                   && !specs->complex_p);
   13425      7841162 :       specs->type = void_type_node;
   13426      7841162 :       break;
   13427        85821 :     case cts_bool:
   13428        85821 :       gcc_assert (!specs->long_p && !specs->short_p
   13429              :                   && !specs->signed_p && !specs->unsigned_p
   13430              :                   && !specs->complex_p);
   13431        85821 :       specs->type = boolean_type_node;
   13432        85821 :       break;
   13433      9042435 :     case cts_char:
   13434      9042435 :       gcc_assert (!specs->long_p && !specs->short_p);
   13435      9042435 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13436      9042435 :       if (specs->signed_p)
   13437       191738 :         specs->type = signed_char_type_node;
   13438      8850697 :       else if (specs->unsigned_p)
   13439       895945 :         specs->type = unsigned_char_type_node;
   13440              :       else
   13441      7954752 :         specs->type = char_type_node;
   13442      9042435 :       if (specs->complex_p)
   13443              :         {
   13444         3855 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13445              :                    "ISO C does not support complex integer types");
   13446         3855 :           specs->type = build_complex_type (specs->type);
   13447              :         }
   13448              :       break;
   13449        51609 :     case cts_int_n:
   13450        51609 :       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
   13451        51609 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13452        51609 :       if (! int_n_enabled_p[specs->u.int_n_idx])
   13453            0 :         specs->type = integer_type_node;
   13454              :       else
   13455        51609 :         specs->type = (specs->unsigned_p
   13456        51609 :                        ? int_n_trees[specs->u.int_n_idx].unsigned_type
   13457              :                        : int_n_trees[specs->u.int_n_idx].signed_type);
   13458        51609 :       if (specs->complex_p)
   13459              :         {
   13460          199 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13461              :                    "ISO C does not support complex integer types");
   13462          199 :           specs->type = build_complex_type (specs->type);
   13463              :         }
   13464              :       break;
   13465     28001281 :     case cts_int:
   13466     28001281 :       gcc_assert (!(specs->long_p && specs->short_p));
   13467     28001281 :       gcc_assert (!(specs->signed_p && specs->unsigned_p));
   13468     28001281 :       if (specs->long_long_p)
   13469      2945797 :         specs->type = (specs->unsigned_p
   13470      2945797 :                        ? long_long_unsigned_type_node
   13471              :                        : long_long_integer_type_node);
   13472     25055484 :       else if (specs->long_p)
   13473      2196966 :         specs->type = (specs->unsigned_p
   13474      2196966 :                        ? long_unsigned_type_node
   13475              :                        : long_integer_type_node);
   13476     22858518 :       else if (specs->short_p)
   13477      1699422 :         specs->type = (specs->unsigned_p
   13478      1699422 :                        ? short_unsigned_type_node
   13479              :                        : short_integer_type_node);
   13480              :       else
   13481     21159096 :         specs->type = (specs->unsigned_p
   13482     21159096 :                        ? unsigned_type_node
   13483              :                        : integer_type_node);
   13484     28001281 :       if (specs->complex_p)
   13485              :         {
   13486        14933 :           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
   13487              :                    "ISO C does not support complex integer types");
   13488        14933 :           specs->type = build_complex_type (specs->type);
   13489              :         }
   13490              :       break;
   13491      3390477 :     case cts_float:
   13492      3390477 :       gcc_assert (!specs->long_p && !specs->short_p
   13493              :                   && !specs->signed_p && !specs->unsigned_p);
   13494      6780954 :       specs->type = (specs->complex_p
   13495      3390477 :                      ? complex_float_type_node
   13496              :                      : float_type_node);
   13497      3390477 :       break;
   13498      6105766 :     case cts_double:
   13499      6105766 :       gcc_assert (!specs->long_long_p && !specs->short_p
   13500              :                   && !specs->signed_p && !specs->unsigned_p);
   13501      6105766 :       if (specs->long_p)
   13502              :         {
   13503      2626780 :           specs->type = (specs->complex_p
   13504      2626780 :                          ? complex_long_double_type_node
   13505              :                          : long_double_type_node);
   13506              :         }
   13507              :       else
   13508              :         {
   13509      3478986 :           specs->type = (specs->complex_p
   13510      3478986 :                          ? complex_double_type_node
   13511              :                          : double_type_node);
   13512              :         }
   13513              :       break;
   13514     10280230 :     case cts_floatn_nx:
   13515     10280230 :       gcc_assert (!specs->long_p && !specs->short_p
   13516              :                   && !specs->signed_p && !specs->unsigned_p);
   13517     10280230 :       if (FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx) == NULL_TREE)
   13518           88 :         specs->type = integer_type_node;
   13519     10280142 :       else if (specs->complex_p)
   13520      1555447 :         specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13521              :       else
   13522      8724695 :         specs->type = FLOATN_NX_TYPE_NODE (specs->u.floatn_nx_idx);
   13523              :       break;
   13524        47570 :     case cts_dfloat32:
   13525        47570 :     case cts_dfloat64:
   13526        47570 :     case cts_dfloat128:
   13527        47570 :     case cts_dfloat64x:
   13528        47570 :       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
   13529              :                   && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
   13530        47570 :       if (!targetm.decimal_float_supported_p ())
   13531            0 :         specs->type = integer_type_node;
   13532        47570 :       else if (specs->typespec_word == cts_dfloat32)
   13533        15957 :         specs->type = dfloat32_type_node;
   13534        31613 :       else if (specs->typespec_word == cts_dfloat64)
   13535        15832 :         specs->type = dfloat64_type_node;
   13536        15781 :       else if (specs->typespec_word == cts_dfloat128)
   13537        15734 :         specs->type = dfloat128_type_node;
   13538              :       else
   13539           47 :         specs->type = dfloat64x_type_node;
   13540              :       break;
   13541           31 :     case cts_fract:
   13542           31 :       gcc_assert (!specs->complex_p);
   13543           31 :       if (!targetm.fixed_point_supported_p ())
   13544           31 :         specs->type = integer_type_node;
   13545            0 :       else if (specs->saturating_p)
   13546              :         {
   13547            0 :           if (specs->long_long_p)
   13548            0 :             specs->type = specs->unsigned_p
   13549            0 :                           ? sat_unsigned_long_long_fract_type_node
   13550              :                           : sat_long_long_fract_type_node;
   13551            0 :           else if (specs->long_p)
   13552            0 :             specs->type = specs->unsigned_p
   13553            0 :                           ? sat_unsigned_long_fract_type_node
   13554              :                           : sat_long_fract_type_node;
   13555            0 :           else if (specs->short_p)
   13556            0 :             specs->type = specs->unsigned_p
   13557            0 :                           ? sat_unsigned_short_fract_type_node
   13558              :                           : sat_short_fract_type_node;
   13559              :           else
   13560            0 :             specs->type = specs->unsigned_p
   13561            0 :                           ? sat_unsigned_fract_type_node
   13562              :                           : sat_fract_type_node;
   13563              :         }
   13564              :       else
   13565              :         {
   13566            0 :           if (specs->long_long_p)
   13567            0 :             specs->type = specs->unsigned_p
   13568            0 :                           ? unsigned_long_long_fract_type_node
   13569              :                           : long_long_fract_type_node;
   13570            0 :           else if (specs->long_p)
   13571            0 :             specs->type = specs->unsigned_p
   13572            0 :                           ? unsigned_long_fract_type_node
   13573              :                           : long_fract_type_node;
   13574            0 :           else if (specs->short_p)
   13575            0 :             specs->type = specs->unsigned_p
   13576            0 :                           ? unsigned_short_fract_type_node
   13577              :                           : short_fract_type_node;
   13578              :           else
   13579            0 :             specs->type = specs->unsigned_p
   13580            0 :                           ? unsigned_fract_type_node
   13581              :                           : fract_type_node;
   13582              :         }
   13583              :       break;
   13584           29 :     case cts_accum:
   13585           29 :       gcc_assert (!specs->complex_p);
   13586           29 :       if (!targetm.fixed_point_supported_p ())
   13587           29 :         specs->type = integer_type_node;
   13588            0 :       else if (specs->saturating_p)
   13589              :         {
   13590            0 :           if (specs->long_long_p)
   13591            0 :             specs->type = specs->unsigned_p
   13592            0 :                           ? sat_unsigned_long_long_accum_type_node
   13593              :                           : sat_long_long_accum_type_node;
   13594            0 :           else if (specs->long_p)
   13595            0 :             specs->type = specs->unsigned_p
   13596            0 :                           ? sat_unsigned_long_accum_type_node
   13597              :                           : sat_long_accum_type_node;
   13598            0 :           else if (specs->short_p)
   13599            0 :             specs->type = specs->unsigned_p
   13600            0 :                           ? sat_unsigned_short_accum_type_node
   13601              :                           : sat_short_accum_type_node;
   13602              :           else
   13603            0 :             specs->type = specs->unsigned_p
   13604            0 :                           ? sat_unsigned_accum_type_node
   13605              :                           : sat_accum_type_node;
   13606              :         }
   13607              :       else
   13608              :         {
   13609            0 :           if (specs->long_long_p)
   13610            0 :             specs->type = specs->unsigned_p
   13611            0 :                           ? unsigned_long_long_accum_type_node
   13612              :                           : long_long_accum_type_node;
   13613            0 :           else if (specs->long_p)
   13614            0 :             specs->type = specs->unsigned_p
   13615            0 :                           ? unsigned_long_accum_type_node
   13616              :                           : long_accum_type_node;
   13617            0 :           else if (specs->short_p)
   13618            0 :             specs->type = specs->unsigned_p
   13619            0 :                           ? unsigned_short_accum_type_node
   13620              :                           : short_accum_type_node;
   13621              :           else
   13622            0 :             specs->type = specs->unsigned_p
   13623            0 :                           ? unsigned_accum_type_node
   13624              :                           : accum_type_node;
   13625              :         }
   13626              :       break;
   13627        45646 :     case cts_bitint:
   13628        45646 :       gcc_assert (!specs->long_p && !specs->short_p
   13629              :                   && !specs->complex_p);
   13630        45646 :       if (!specs->unsigned_p && specs->u.bitint_prec == 1)
   13631              :         {
   13632            2 :           error_at (specs->locations[cdw_typespec],
   13633              :                     "%<signed _BitInt%> argument must be at least 2");
   13634            2 :           specs->type = integer_type_node;
   13635            2 :           break;
   13636              :         }
   13637        45644 :       if (specs->u.bitint_prec == -1)
   13638            7 :         specs->type = integer_type_node;
   13639              :       else
   13640              :         {
   13641        67281 :           pedwarn_c11 (specs->locations[cdw_typespec], OPT_Wpedantic,
   13642              :                        "ISO C does not support %<%s_BitInt(%d)%> before C23",
   13643              :                        specs->unsigned_p ? "unsigned "
   13644        21644 :                        : specs->signed_p ? "signed " : "",
   13645              :                        specs->u.bitint_prec);
   13646        45637 :           specs->type = build_bitint_type (specs->u.bitint_prec,
   13647        45637 :                                            specs->unsigned_p);
   13648              :         }
   13649              :       break;
   13650            0 :     default:
   13651            0 :       gcc_unreachable ();
   13652              :     }
   13653    313689801 :  handle_postfix_attrs:
   13654    313689801 :   if (specs->type != NULL)
   13655              :     {
   13656    313687923 :       specs->postfix_attrs
   13657    313687923 :         = c_warn_type_attributes (specs->type, specs->postfix_attrs);
   13658    313687923 :       decl_attributes (&specs->type, specs->postfix_attrs, 0);
   13659    313687923 :       specs->postfix_attrs = NULL_TREE;
   13660              :     }
   13661              : 
   13662              :   return specs;
   13663              : }
   13664              : 
   13665              : /* Perform final processing on one file scope's declarations (or the
   13666              :    external scope's declarations), GLOBALS.  */
   13667              : 
   13668              : static void
   13669       209750 : c_write_global_declarations_1 (tree globals)
   13670              : {
   13671       209750 :   tree decl;
   13672       209750 :   bool reconsider;
   13673              : 
   13674              :   /* Process the decls in the order they were written.  */
   13675    383497241 :   for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13676              :     {
   13677              :       /* Check for used but undefined static functions using the C
   13678              :          standard's definition of "used", and set TREE_NO_WARNING so
   13679              :          that check_global_declaration doesn't repeat the check.  */
   13680    383287491 :       if (TREE_CODE (decl) == FUNCTION_DECL
   13681    365214683 :           && DECL_INITIAL (decl) == NULL_TREE
   13682    328966343 :           && DECL_EXTERNAL (decl)
   13683    328966338 :           && !TREE_PUBLIC (decl)
   13684    383287613 :           && !warning_suppressed_p (decl, OPT_Wunused))
   13685              :         {
   13686          117 :           if (C_DECL_USED (decl))
   13687              :             {
   13688           30 :               if (pedwarn (input_location, 0, "%q+F used but never defined",
   13689              :                            decl))
   13690           29 :                 suppress_warning (decl, OPT_Wunused);
   13691              :             }
   13692              :           /* For -Wunused-function warn about unused static prototypes.  */
   13693           87 :           else if (warn_unused_function
   13694            2 :                    && ! DECL_ARTIFICIAL (decl)
   13695           89 :                    && warning (OPT_Wunused_function,
   13696              :                                "%q+F declared %<static%> but never defined",
   13697              :                                decl))
   13698            2 :             suppress_warning (decl, OPT_Wunused);
   13699              :         }
   13700              : 
   13701    383287491 :       wrapup_global_declaration_1 (decl);
   13702              :     }
   13703              : 
   13704       243537 :   do
   13705              :     {
   13706       243537 :       reconsider = false;
   13707    496426131 :       for (decl = globals; decl; decl = DECL_CHAIN (decl))
   13708    496182594 :         reconsider |= wrapup_global_declaration_2 (decl);
   13709              :     }
   13710              :   while (reconsider);
   13711       209750 : }
   13712              : 
   13713              : /* Preserve the external declarations scope across a garbage collect.  */
   13714              : static GTY(()) tree ext_block;
   13715              : 
   13716              : /* Collect all references relevant to SOURCE_FILE.  */
   13717              : 
   13718              : static void
   13719           15 : collect_all_refs (const char *source_file)
   13720              : {
   13721           15 :   tree t;
   13722           15 :   unsigned i;
   13723              : 
   13724           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13725           15 :     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
   13726              : 
   13727           15 :   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
   13728           15 : }
   13729              : 
   13730              : /* Collect source file references at global level.  */
   13731              : 
   13732              : static void
   13733           15 : collect_source_refs (void)
   13734              : {
   13735           15 :   tree t;
   13736           15 :   tree decls;
   13737           15 :   tree decl;
   13738           15 :   unsigned i;
   13739              : 
   13740           30 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13741              :     {
   13742           15 :       decls = DECL_INITIAL (t);
   13743           82 :       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
   13744           67 :         if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13745           67 :           collect_source_ref (DECL_SOURCE_FILE (decl));
   13746              :     }
   13747              : 
   13748        44186 :   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
   13749        44171 :     if (!DECL_IS_UNDECLARED_BUILTIN (decl))
   13750           11 :       collect_source_ref (DECL_SOURCE_FILE (decl));
   13751           15 : }
   13752              : 
   13753              : /* Free attribute access data that are not needed by the middle end. */
   13754              : 
   13755              : static void
   13756       104875 : free_attr_access_data ()
   13757              : {
   13758       104875 :   struct cgraph_node *n;
   13759              : 
   13760              :   /* Iterate over all functions declared in the translation unit.  */
   13761     36354849 :   FOR_EACH_FUNCTION (n)
   13762              :     {
   13763    136128839 :       for (tree parm = DECL_ARGUMENTS (n->decl); parm; parm = TREE_CHAIN (parm))
   13764     99878865 :         if (tree attrs = DECL_ATTRIBUTES (parm))
   13765        97428 :           attr_access::free_lang_data (attrs);
   13766              : 
   13767     36249974 :       tree fntype = TREE_TYPE (n->decl);
   13768     36249974 :       if (!fntype || fntype == error_mark_node)
   13769            0 :         continue;
   13770     36249974 :       tree attrs = TYPE_ATTRIBUTES (fntype);
   13771     36249974 :       if (!attrs)
   13772     36015135 :         continue;
   13773              : 
   13774       234839 :       attr_access::free_lang_data (attrs);
   13775              :     }
   13776       104875 : }
   13777              : 
   13778              : /* Perform any final parser cleanups and generate initial debugging
   13779              :    information.  */
   13780              : 
   13781              : void
   13782       105206 : c_parse_final_cleanups (void)
   13783              : {
   13784       105206 :   tree t;
   13785       105206 :   unsigned i;
   13786              : 
   13787              :   /* We don't want to do this if generating a PCH.  */
   13788       105206 :   if (pch_file)
   13789       105206 :     return;
   13790              : 
   13791       104875 :   timevar_stop (TV_PHASE_PARSING);
   13792       104875 :   timevar_start (TV_PHASE_DEFERRED);
   13793              : 
   13794              :   /* Do the Objective-C stuff.  This is where all the Objective-C
   13795              :      module stuff gets generated (symtab, class/protocol/selector
   13796              :      lists etc).  */
   13797       104875 :   if (c_dialect_objc ())
   13798            0 :     objc_write_global_declarations ();
   13799              : 
   13800              :   /* Close the external scope.  */
   13801       104875 :   ext_block = pop_scope ();
   13802       104875 :   external_scope = 0;
   13803       104875 :   gcc_assert (!current_scope);
   13804              : 
   13805              :   /* Handle -fdump-ada-spec[-slim]. */
   13806       104875 :   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
   13807              :     {
   13808              :       /* Build a table of files to generate specs for */
   13809           15 :       collect_source_ref (main_input_filename);
   13810           15 :       if (!flag_dump_ada_spec_slim)
   13811           15 :         collect_source_refs ();
   13812              : 
   13813           15 :       dump_ada_specs (collect_all_refs, NULL);
   13814              :     }
   13815              : 
   13816              :   /* Process all file scopes in this compilation, and the external_scope,
   13817              :      through wrapup_global_declarations.  */
   13818       209750 :   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
   13819       104875 :     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
   13820       104875 :   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
   13821              : 
   13822              :   /* Call this to set cpp_implicit_aliases_done on all nodes.  This is
   13823              :      important for function multiversioning aliases to get resolved.  */
   13824       104875 :   symtab->process_same_body_aliases ();
   13825              : 
   13826       104875 :   if (!in_lto_p)
   13827       104875 :     free_attr_access_data ();
   13828              : 
   13829       104875 :   timevar_stop (TV_PHASE_DEFERRED);
   13830       104875 :   timevar_start (TV_PHASE_PARSING);
   13831              : 
   13832       104875 :   ext_block = NULL;
   13833              : }
   13834              : 
   13835              : /* Register reserved keyword WORD as qualifier for address space AS.  */
   13836              : 
   13837              : void
   13838       221526 : c_register_addr_space (const char *word, addr_space_t as)
   13839              : {
   13840       221526 :   int rid = RID_FIRST_ADDR_SPACE + as;
   13841       221526 :   tree id;
   13842              : 
   13843              :   /* Address space qualifiers are only supported
   13844              :      in C with GNU extensions enabled.  */
   13845       221526 :   if (c_dialect_objc () || flag_no_asm)
   13846              :     return;
   13847              : 
   13848       209184 :   id = get_identifier (word);
   13849       209184 :   C_SET_RID_CODE (id, rid);
   13850       209184 :   C_IS_RESERVED_WORD (id) = 1;
   13851       209184 :   ridpointers [rid] = id;
   13852              : }
   13853              : 
   13854              : /* Return identifier to look up for omp declare reduction.  */
   13855              : 
   13856              : tree
   13857         3254 : c_omp_reduction_id (enum tree_code reduction_code, tree reduction_id)
   13858              : {
   13859         3254 :   const char *p = NULL;
   13860         3254 :   switch (reduction_code)
   13861              :     {
   13862              :     case PLUS_EXPR: p = "+"; break;
   13863          267 :     case MULT_EXPR: p = "*"; break;
   13864          157 :     case MINUS_EXPR: p = "-"; break;
   13865           31 :     case BIT_AND_EXPR: p = "&"; break;
   13866           14 :     case BIT_XOR_EXPR: p = "^"; break;
   13867           92 :     case BIT_IOR_EXPR: p = "|"; break;
   13868           67 :     case TRUTH_ANDIF_EXPR: p = "&&"; break;
   13869           78 :     case TRUTH_ORIF_EXPR: p = "||"; break;
   13870           46 :     case MIN_EXPR: p = "min"; break;
   13871           83 :     case MAX_EXPR: p = "max"; break;
   13872              :     default:
   13873              :       break;
   13874              :     }
   13875              : 
   13876          835 :   if (p == NULL)
   13877              :     {
   13878          213 :       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
   13879            0 :         return error_mark_node;
   13880          213 :       p = IDENTIFIER_POINTER (reduction_id);
   13881              :     }
   13882              : 
   13883         3254 :   const char prefix[] = "omp declare reduction ";
   13884         3254 :   size_t lenp = sizeof (prefix);
   13885         3254 :   size_t len = strlen (p);
   13886         3254 :   char *name = XALLOCAVEC (char, lenp + len);
   13887         3254 :   memcpy (name, prefix, lenp - 1);
   13888         3254 :   memcpy (name + lenp - 1, p, len + 1);
   13889         3254 :   return get_identifier (name);
   13890              : }
   13891              : 
   13892              : /* Lookup REDUCTION_ID in the current scope, or create an artificial
   13893              :    VAR_DECL, bind it into the current scope and return it.  */
   13894              : 
   13895              : tree
   13896          161 : c_omp_reduction_decl (tree reduction_id)
   13897              : {
   13898          161 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13899          161 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   13900           47 :     return b->decl;
   13901              : 
   13902          114 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   13903              :                           reduction_id, integer_type_node);
   13904          114 :   DECL_ARTIFICIAL (decl) = 1;
   13905          114 :   DECL_EXTERNAL (decl) = 1;
   13906          114 :   TREE_STATIC (decl) = 1;
   13907          114 :   TREE_PUBLIC (decl) = 0;
   13908          114 :   bind (reduction_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   13909          114 :   return decl;
   13910              : }
   13911              : 
   13912              : /* Lookup REDUCTION_ID in the first scope where it has entry for TYPE.  */
   13913              : 
   13914              : tree
   13915          273 : c_omp_reduction_lookup (tree reduction_id, tree type)
   13916              : {
   13917          273 :   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
   13918          276 :   while (b)
   13919              :     {
   13920          274 :       tree t;
   13921          294 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   13922          291 :         if (comptypes (TREE_PURPOSE (t), type))
   13923          271 :           return TREE_VALUE (t);
   13924            3 :       b = b->shadowed;
   13925              :     }
   13926            2 :   return error_mark_node;
   13927              : }
   13928              : 
   13929              : /* Helper function called via walk_tree, to diagnose invalid
   13930              :    #pragma omp declare reduction combiners or initializers.  */
   13931              : 
   13932              : tree
   13933         1401 : c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
   13934              : {
   13935         1401 :   tree *vars = (tree *) data;
   13936         1401 :   if (SSA_VAR_P (*tp)
   13937          413 :       && !DECL_ARTIFICIAL (*tp)
   13938           24 :       && *tp != vars[0]
   13939           24 :       && *tp != vars[1])
   13940              :     {
   13941           24 :       location_t loc = DECL_SOURCE_LOCATION (vars[0]);
   13942           24 :       if (strcmp (IDENTIFIER_POINTER (DECL_NAME (vars[0])), "omp_out") == 0)
   13943           10 :         error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
   13944              :                        "variable %qD which is not %<omp_out%> nor %<omp_in%>",
   13945              :                   *tp);
   13946              :       else
   13947           14 :         error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
   13948              :                        "to variable %qD which is not %<omp_priv%> nor "
   13949              :                        "%<omp_orig%>",
   13950              :                   *tp);
   13951           24 :       return *tp;
   13952              :     }
   13953              :   return NULL_TREE;
   13954              : }
   13955              : 
   13956              : /* Return identifier to look up for omp declare mapper.  */
   13957              : 
   13958              : tree
   13959          615 : c_omp_mapper_id (tree mapper_id)
   13960              : {
   13961          615 :   const char *p = NULL;
   13962              : 
   13963          615 :   const char prefix[] = "omp declare mapper ";
   13964              : 
   13965          615 :   if (mapper_id == NULL_TREE)
   13966              :     p = "<default>";
   13967           19 :   else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
   13968           19 :     p = IDENTIFIER_POINTER (mapper_id);
   13969              :   else
   13970            0 :     return error_mark_node;
   13971              : 
   13972          615 :   size_t lenp = sizeof (prefix);
   13973          615 :   size_t len = strlen (p);
   13974          615 :   char *name = XALLOCAVEC (char, lenp + len);
   13975          615 :   memcpy (name, prefix, lenp - 1);
   13976          615 :   memcpy (name + lenp - 1, p, len + 1);
   13977          615 :   return get_identifier (name);
   13978              : }
   13979              : 
   13980              : /* Lookup MAPPER_ID in the current scope, or create an artificial
   13981              :    VAR_DECL, bind it into the current scope and return it.  */
   13982              : 
   13983              : tree
   13984           62 : c_omp_mapper_decl (tree mapper_id)
   13985              : {
   13986           62 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   13987           62 :   if (b != NULL && B_IN_CURRENT_SCOPE (b))
   13988           22 :     return b->decl;
   13989              : 
   13990           40 :   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
   13991              :                           mapper_id, integer_type_node);
   13992           40 :   DECL_ARTIFICIAL (decl) = 1;
   13993           40 :   DECL_EXTERNAL (decl) = 1;
   13994           40 :   TREE_STATIC (decl) = 1;
   13995           40 :   TREE_PUBLIC (decl) = 0;
   13996           40 :   bind (mapper_id, decl, current_scope, true, false, BUILTINS_LOCATION);
   13997           40 :   return decl;
   13998              : }
   13999              : 
   14000              : /* Lookup MAPPER_ID in the first scope where it has entry for TYPE.  */
   14001              : 
   14002              : tree
   14003         1781 : c_omp_mapper_lookup (tree mapper_id, tree type)
   14004              : {
   14005         1781 :   if (!RECORD_OR_UNION_TYPE_P (type))
   14006              :     return NULL_TREE;
   14007              : 
   14008          553 :   mapper_id = c_omp_mapper_id (mapper_id);
   14009              : 
   14010          553 :   struct c_binding *b = I_SYMBOL_BINDING (mapper_id);
   14011          559 :   while (b)
   14012              :     {
   14013           91 :       tree t;
   14014          110 :       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
   14015          104 :         if (comptypes (TREE_PURPOSE (t), type))
   14016           85 :           return TREE_VALUE (t);
   14017            6 :       b = b->shadowed;
   14018              :     }
   14019              :   return NULL_TREE;
   14020              : }
   14021              : 
   14022              : /* For C, we record a pointer to the mapper itself without wrapping it in an
   14023              :    artificial function or similar.  So, just return it.  */
   14024              : 
   14025              : tree
   14026           82 : c_omp_extract_mapper_directive (tree mapper)
   14027              : {
   14028           82 :   return mapper;
   14029              : }
   14030              : 
   14031              : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
   14032              :    nothing more complicated.  */
   14033              : 
   14034              : tree
   14035          365 : c_omp_map_array_section (location_t loc, tree t)
   14036              : {
   14037          365 :   tree low = TREE_OPERAND (t, 1);
   14038          365 :   tree len = TREE_OPERAND (t, 2);
   14039              : 
   14040          365 :   if (len && integer_onep (len))
   14041              :     {
   14042           63 :       t = TREE_OPERAND (t, 0);
   14043              : 
   14044           63 :       if (!low)
   14045            0 :         low = integer_zero_node;
   14046              : 
   14047           63 :       t = build_array_ref (loc, t, low);
   14048              :     }
   14049              : 
   14050          365 :   return t;
   14051              : }
   14052              : 
   14053              : /* Helper function for below function.  */
   14054              : 
   14055              : static tree
   14056        51327 : c_omp_scan_mapper_bindings_r (tree *tp, int *walk_subtrees, void *ptr)
   14057              : {
   14058        51327 :   tree t = *tp;
   14059        51327 :   omp_mapper_list<tree> *mlist = (omp_mapper_list<tree> *) ptr;
   14060        51327 :   tree aggr_type = NULL_TREE;
   14061              : 
   14062        51327 :   if (TREE_CODE (t) == SIZEOF_EXPR
   14063        51327 :       || TREE_CODE (t) == ALIGNOF_EXPR)
   14064              :     {
   14065            0 :       *walk_subtrees = 0;
   14066            0 :       return NULL_TREE;
   14067              :     }
   14068              : 
   14069        51327 :   if (TREE_CODE (t) == OMP_CLAUSE)
   14070              :     return NULL_TREE;
   14071              : 
   14072        48038 :   if (TREE_CODE (t) == COMPONENT_REF
   14073        48038 :       && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
   14074          362 :     aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
   14075        47676 :   else if ((TREE_CODE (t) == VAR_DECL
   14076              :             || TREE_CODE (t) == PARM_DECL
   14077              :             || TREE_CODE (t) == RESULT_DECL)
   14078         5328 :            && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
   14079          118 :     aggr_type = TREE_TYPE (t);
   14080              : 
   14081          480 :   if (aggr_type)
   14082              :     {
   14083          480 :       tree mapper_fn = c_omp_mapper_lookup (NULL_TREE, aggr_type);
   14084          480 :       if (mapper_fn)
   14085           65 :         mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
   14086              :     }
   14087              : 
   14088              :   return NULL_TREE;
   14089              : }
   14090              : 
   14091              : /* Scan an offload region's body, and record uses of struct- or union-typed
   14092              :    variables.  Add _mapper_binding_ fake clauses to *CLAUSES_PTR.  */
   14093              : 
   14094              : void
   14095         2037 : c_omp_scan_mapper_bindings (location_t loc, tree *clauses_ptr, tree body)
   14096              : {
   14097         2037 :   hash_set<omp_name_type<tree>> seen_types;
   14098         2037 :   auto_vec<tree> mappers;
   14099         2037 :   omp_mapper_list<tree> mlist (&seen_types, &mappers);
   14100              : 
   14101         2037 :   walk_tree_without_duplicates (&body, c_omp_scan_mapper_bindings_r, &mlist);
   14102              : 
   14103         2037 :   unsigned int i;
   14104         2037 :   tree mapper;
   14105         4113 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14106           39 :     c_omp_find_nested_mappers (&mlist, mapper);
   14107              : 
   14108         2102 :   FOR_EACH_VEC_ELT (mappers, i, mapper)
   14109              :     {
   14110           39 :       if (mapper == error_mark_node)
   14111            0 :         continue;
   14112           39 :       tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
   14113           39 :       tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
   14114              : 
   14115           39 :       tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
   14116           39 :       OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
   14117           39 :       OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
   14118           39 :       OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper;
   14119              : 
   14120           39 :       OMP_CLAUSE_CHAIN (c) = *clauses_ptr;
   14121           39 :       *clauses_ptr = c;
   14122              :     }
   14123         2037 : }
   14124              : 
   14125              : bool
   14126          225 : c_check_in_current_scope (tree decl)
   14127              : {
   14128          225 :   struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (decl));
   14129          225 :   return b != NULL && B_IN_CURRENT_SCOPE (b);
   14130              : }
   14131              : 
   14132              : /* Search for loop or switch names.  BEFORE_LABELS is last statement before
   14133              :    possible labels and SWITCH_P true for a switch, false for loops.
   14134              :    Searches through last statements in cur_stmt_list, stops when seeing
   14135              :    BEFORE_LABELs, or statement other than LABEL_EXPR or CASE_LABEL_EXPR.
   14136              :    Returns number of loop/switch names found and if any are found, sets
   14137              :    *LAST_P to the canonical loop/switch name LABEL_DECL.  */
   14138              : 
   14139              : int
   14140       511791 : c_get_loop_names (tree before_labels, bool switch_p, tree *last_p)
   14141              : {
   14142       511791 :   *last_p = NULL_TREE;
   14143      1023582 :   if (!building_stmt_list_p ()
   14144       511791 :       || !STATEMENT_LIST_HAS_LABEL (cur_stmt_list)
   14145       532367 :       || before_labels == void_list_node)
   14146       491215 :     return 0;
   14147              : 
   14148        20576 :   int ret = 0;
   14149        20576 :   tree last = NULL_TREE;
   14150        20576 :   for (tree_stmt_iterator tsi = tsi_last (cur_stmt_list);
   14151        28751 :        !tsi_end_p (tsi); tsi_prev (&tsi))
   14152              :     {
   14153        27894 :       tree stmt = tsi_stmt (tsi);
   14154        27894 :       if (stmt == before_labels)
   14155              :         break;
   14156         8175 :       else if (TREE_CODE (stmt) == LABEL_EXPR)
   14157              :         {
   14158         1087 :           if (last == NULL_TREE)
   14159          893 :             last = LABEL_EXPR_LABEL (stmt);
   14160              :           else
   14161              :             {
   14162          194 :               loop_names.safe_push (LABEL_EXPR_LABEL (stmt));
   14163          194 :               ++ret;
   14164              :             }
   14165              :         }
   14166         7088 :       else if (TREE_CODE (stmt) != CASE_LABEL_EXPR
   14167         4768 :                && TREE_CODE (stmt) != DEBUG_BEGIN_STMT)
   14168              :         break;
   14169              :     }
   14170        20576 :   if (last)
   14171              :     {
   14172          893 :       if (switch_p)
   14173          122 :         C_DECL_SWITCH_NAME (last) = 1;
   14174              :       else
   14175          771 :         C_DECL_LOOP_NAME (last) = 1;
   14176          893 :       loop_names.safe_push (last);
   14177          893 :       ++ret;
   14178          893 :       if (loop_names.length () > 16)
   14179              :         {
   14180           20 :           unsigned int first = 0, i;
   14181           20 :           tree l, c = NULL_TREE;
   14182           20 :           if (loop_names_hash == NULL)
   14183            8 :             loop_names_hash = new decl_tree_map (ret);
   14184              :           else
   14185           12 :             first = loop_names.length () - ret;
   14186          210 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14187              :             {
   14188          170 :               if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14189           48 :                 c = l;
   14190          170 :               gcc_checking_assert (c);
   14191          170 :               loop_names_hash->put (l, c);
   14192          170 :               if (i == first)
   14193              :                 break;
   14194              :             }
   14195              :         }
   14196          893 :       *last_p = last;
   14197              :     }
   14198              :   return ret;
   14199              : }
   14200              : 
   14201              : /* Undoes what get_loop_names did when it returned NUM_NAMES.  */
   14202              : 
   14203              : void
   14204          893 : c_release_loop_names (int num_names)
   14205              : {
   14206          893 :   unsigned len = loop_names.length () - num_names;
   14207          893 :   if (loop_names_hash)
   14208              :     {
   14209           20 :       if (len <= 16)
   14210              :         {
   14211            8 :           delete loop_names_hash;
   14212            8 :           loop_names_hash = NULL;
   14213              :         }
   14214              :       else
   14215              :         {
   14216           12 :           unsigned int i;
   14217           12 :           tree l;
   14218           42 :           FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14219              :             {
   14220           30 :               loop_names_hash->remove (l);
   14221           30 :               if (i == len)
   14222              :                 break;
   14223              :             }
   14224              :         }
   14225              :     }
   14226          893 :   loop_names.truncate (len);
   14227          893 : }
   14228              : 
   14229              : /* Finish processing of break or continue identifier operand.
   14230              :    NAME is the identifier operand of break or continue and
   14231              :    IS_BREAK is true iff it is break stmt.  Returns the operand
   14232              :    to use for BREAK_STMT or CONTINUE_STMT, either NULL_TREE or
   14233              :    canonical loop/switch name LABEL_DECL.  */
   14234              : 
   14235              : tree
   14236          316 : c_finish_bc_name (location_t loc, tree name, bool is_break)
   14237              : {
   14238          316 :   tree label = NULL_TREE, lab;
   14239          457 :   pedwarn_c23 (loc, OPT_Wpedantic,
   14240              :                "ISO C does not support %qs statement with an identifier "
   14241              :                "operand before C2Y", is_break ? "break" : "continue");
   14242              : 
   14243              :   /* If I_LABEL_DECL is NULL or not from current function, don't waste time
   14244              :      trying to find it among loop_names, it can't be there.  */
   14245          316 :   if (!loop_names.is_empty ()
   14246          296 :       && current_function_scope
   14247          296 :       && (lab = I_LABEL_DECL (name))
   14248          290 :       && DECL_CONTEXT (lab) == current_function_decl)
   14249              :     {
   14250          280 :       unsigned int i;
   14251          280 :       tree l, c = NULL_TREE;
   14252          280 :       if (loop_names_hash)
   14253              :         {
   14254           86 :           if (tree *val = loop_names_hash->get (lab))
   14255           86 :             label = *val;
   14256              :         }
   14257              :       else
   14258          565 :         FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14259              :           {
   14260          363 :             if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14261              :               c = l;
   14262          363 :             gcc_checking_assert (c);
   14263          363 :             if (l == lab)
   14264              :               {
   14265              :                 label = c;
   14266              :                 break;
   14267              :               }
   14268              :           }
   14269          280 :       if (label)
   14270          272 :         TREE_USED (lab) = 1;
   14271              :     }
   14272          272 :   if (label == NULL_TREE)
   14273              :     {
   14274           44 :       auto_vec<const char *> candidates;
   14275           44 :       unsigned int i;
   14276           44 :       tree l, c = NULL_TREE;
   14277          115 :       FOR_EACH_VEC_ELT_REVERSE (loop_names, i, l)
   14278              :         {
   14279           28 :           if (C_DECL_LOOP_NAME (l) || C_DECL_SWITCH_NAME (l))
   14280              :             c = l;
   14281           28 :           gcc_checking_assert (c);
   14282           42 :           if (is_break || C_DECL_LOOP_NAME (c))
   14283           25 :             candidates.safe_push (IDENTIFIER_POINTER (DECL_NAME (l)));
   14284              :         }
   14285           44 :       const char *hint = find_closest_string (IDENTIFIER_POINTER (name),
   14286              :                                               &candidates);
   14287           44 :       if (hint)
   14288              :         {
   14289           22 :           gcc_rich_location richloc (loc);
   14290           22 :           richloc.add_fixit_replace (hint);
   14291           22 :           if (is_break)
   14292           11 :             error_at (&richloc, "%<break%> statement operand %qE does not "
   14293              :                                 "refer to a named loop or %<switch%>; "
   14294              :                                 "did you mean %qs?", name, hint);
   14295              :           else
   14296           11 :             error_at (&richloc, "%<continue%> statement operand %qE does not "
   14297              :                                 "refer to a named loop; did you mean %qs?",
   14298              :                       name, hint);
   14299           22 :         }
   14300           22 :       else if (is_break)
   14301           12 :         error_at (loc, "%<break%> statement operand %qE does not refer to a "
   14302              :                        "named loop or %<switch%>", name);
   14303              :       else
   14304           10 :         error_at (loc, "%<continue%> statement operand %qE does not refer to "
   14305              :                        "a named loop", name);
   14306           44 :     }
   14307          272 :   else if (!C_DECL_LOOP_NAME (label) && !is_break)
   14308              :     {
   14309            2 :       auto_diagnostic_group d;
   14310            2 :       error_at (loc, "%<continue%> statement operand %qE refers to a named "
   14311              :                      "%<switch%>", name);
   14312            2 :       inform (DECL_SOURCE_LOCATION (label), "%<switch%> name defined here");
   14313            2 :       label = NULL_TREE;
   14314            2 :     }
   14315          270 :   else if (!C_DECL_LOOP_SWITCH_NAME_VALID (label))
   14316              :     {
   14317           18 :       auto_diagnostic_group d;
   14318           18 :       if (C_DECL_LOOP_NAME (label))
   14319              :         {
   14320           16 :           error_at (loc, "%qs statement operand %qE refers to a loop outside "
   14321              :                          "of its body", is_break ? "break" : "continue", name);
   14322           16 :           inform (DECL_SOURCE_LOCATION (label), "loop name defined here");
   14323              :         }
   14324              :       else
   14325              :         {
   14326            2 :           error_at (loc, "%<break%> statement operand %qE refers to a "
   14327              :                          "%<switch%> outside of its body", name);
   14328            2 :           inform (DECL_SOURCE_LOCATION (label),
   14329              :                   "%<switch%> name defined here");
   14330              :         }
   14331           18 :       label = NULL_TREE;
   14332           18 :     }
   14333          252 :   else if (label == loop_names.last () && (in_statement & IN_NAMED_STMT) != 0)
   14334              :     /* If it is just a fancy reference to the innermost construct, handle it
   14335              :        just like break; or continue; though tracking cheaply what is the
   14336              :        innermost loop for continue when nested in switches would require
   14337              :        another global variable and updating it.  */
   14338              :     label = NULL_TREE;
   14339              :   else
   14340           98 :     C_DECL_LOOP_SWITCH_NAME_USED (label) = 1;
   14341          316 :   return label;
   14342              : }
   14343              : 
   14344              : #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.