Mercurial > hg > CbC > CbC_gcc
diff gcc/c-decl.c @ 57:326d9e06c2e3
modify c-parser.c
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 15 Feb 2010 00:54:17 +0900 |
parents | 9907f3135723 77e2b8dfacca |
children | 1b10fe6932e1 |
line wrap: on
line diff
--- a/gcc/c-decl.c Sun Feb 07 18:30:54 2010 +0900 +++ b/gcc/c-decl.c Mon Feb 15 00:54:17 2010 +0900 @@ -50,6 +50,7 @@ #include "timevar.h" #include "c-common.h" #include "c-pragma.h" +#include "c-lang.h" #include "langhooks.h" #include "tree-mudflap.h" #include "gimple.h" @@ -70,14 +71,15 @@ location_t cbc_return; #endif +#include "plugin.h" /* In grokdeclarator, distinguish syntactic contexts of declarators. */ enum decl_context -{ NORMAL, /* Ordinary declaration */ - FUNCDEF, /* Function definition */ - PARM, /* Declaration of parm before function body */ - FIELD, /* Declaration inside struct or union */ - TYPENAME}; /* Typename (inside cast or sizeof) */ +{ NORMAL, /* Ordinary declaration */ + FUNCDEF, /* Function definition */ + PARM, /* Declaration of parm before function body */ + FIELD, /* Declaration inside struct or union */ + TYPENAME}; /* Typename (inside cast or sizeof) */ /* States indicating how grokdeclarator() should handle declspecs marked with __attribute__((deprecated)). An object declared as @@ -97,9 +99,6 @@ /* File and line to appear in the eventual error message. */ location_t pending_invalid_xref_location; -/* True means we've initialized exception handling. */ -bool c_eh_initialized_p; - /* The file and line that the prototype came from if this is an old-style definition; used for diagnostics in store_parm_decls_oldstyle. */ @@ -185,7 +184,7 @@ suppress further errors about that identifier in the current function. - The ->type field stores the type of the declaration in this scope; + The ->u.type field stores the type of the declaration in this scope; if NULL, the type is the type of the ->decl field. This is only of relevance for objects with external or internal linkage which may be redeclared in inner scopes, forming composite types that only @@ -195,6 +194,9 @@ scope) stores whether an incomplete array type at file scope was completed at an inner scope to an array size other than 1. + The ->u.label field is used for labels. It points to a structure + which stores additional information used for warnings. + The depth field is copied from the scope structure that holds this decl. It is used to preserve the proper ordering of the ->shadowed field (see bind()) and also for a handful of special-case checks. @@ -204,18 +206,21 @@ in all such cases, the binding in the outer scope will have its invisible bit true. */ -struct c_binding GTY((chain_next ("%h.prev"))) -{ - tree decl; /* the decl bound */ - tree type; /* the type in this scope */ - tree id; /* the identifier it's bound to */ - struct c_binding *prev; /* the previous decl in this scope */ - struct c_binding *shadowed; /* the innermost decl shadowed by this one */ +struct GTY((chain_next ("%h.prev"))) c_binding { + union GTY(()) { /* first so GTY desc can use decl */ + tree GTY((tag ("0"))) type; /* the type in this scope */ + struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */ + } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u; + tree decl; /* the decl bound */ + tree id; /* the identifier it's bound to */ + struct c_binding *prev; /* the previous decl in this scope */ + struct c_binding *shadowed; /* the innermost decl shadowed by this one */ unsigned int depth : 28; /* depth of this scope */ BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */ BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */ BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */ - /* one free bit */ + BOOL_BITFIELD in_struct : 1; /* currently defined as struct field */ + location_t locus; /* location for nested bindings */ }; #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth) #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth) @@ -241,8 +246,7 @@ These describe the values of the identifier in the three different namespaces defined by the language. */ -struct lang_identifier GTY(()) -{ +struct GTY(()) lang_identifier { struct c_common_identifier common_id; struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */ struct c_binding *tag_binding; /* struct/union/enum tags */ @@ -255,16 +259,76 @@ /* The resulting tree type. */ -union lang_tree_node - GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), - chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : ((union lang_tree_node *) TREE_CHAIN (&%h.generic))"))) -{ +union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), + chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : ((union lang_tree_node *) TREE_CHAIN (&%h.generic))"))) lang_tree_node + { union tree_node GTY ((tag ("0"), - desc ("tree_node_structure (&%h)"))) + desc ("tree_node_structure (&%h)"))) generic; struct lang_identifier GTY ((tag ("1"))) identifier; }; +/* Track bindings and other things that matter for goto warnings. For + efficiency, we do not gather all the decls at the point of + definition. Instead, we point into the bindings structure. As + scopes are popped, we update these structures and gather the decls + that matter at that time. */ + +struct GTY(()) c_spot_bindings { + /* The currently open scope which holds bindings defined when the + label was defined or the goto statement was found. */ + struct c_scope *scope; + /* The bindings in the scope field which were defined at the point + of the label or goto. This lets us look at older or newer + bindings in the scope, as appropriate. */ + struct c_binding *bindings_in_scope; + /* The number of statement expressions that have started since this + label or goto statement was defined. This is zero if we are at + the same statement expression level. It is positive if we are in + a statement expression started since this spot. It is negative + if this spot was in a statement expression and we have left + it. */ + int stmt_exprs; + /* Whether we started in a statement expression but are no longer in + it. This is set to true if stmt_exprs ever goes negative. */ + bool left_stmt_expr; +}; + +/* This structure is used to keep track of bindings seen when a goto + statement is defined. This is only used if we see the goto + statement before we see the label. */ + +struct GTY(()) c_goto_bindings { + /* The location of the goto statement. */ + location_t loc; + /* The bindings of the goto statement. */ + struct c_spot_bindings goto_bindings; +}; + +typedef struct c_goto_bindings *c_goto_bindings_p; +DEF_VEC_P(c_goto_bindings_p); +DEF_VEC_ALLOC_P(c_goto_bindings_p,gc); + +/* The additional information we keep track of for a label binding. + These fields are updated as scopes are popped. */ + +struct GTY(()) c_label_vars { + /* The shadowed c_label_vars, when one label shadows another (which + can only happen using a __label__ declaration). */ + struct c_label_vars *shadowed; + /* The bindings when the label was defined. */ + struct c_spot_bindings label_bindings; + /* A list of decls that we care about: decls about which we should + warn if a goto branches to this label from later in the function. + Decls are added to this list as scopes are popped. We only add + the decls that matter. */ + VEC(tree,gc) *decls_in_scope; + /* A list of goto statements to this label. This is only used for + goto statements seen before the label was defined, so that we can + issue appropriate warnings for them. */ + VEC(c_goto_bindings_p,gc) *gotos; +}; + /* Each c_scope structure describes the complete contents of one scope. Four scopes are distinguished specially: the innermost or current scope, the innermost function scope, the file scope (always @@ -310,8 +374,7 @@ pop_scope relies on this. */ -struct c_scope GTY((chain_next ("%h.outer"))) -{ +struct GTY((chain_next ("%h.outer"))) c_scope { /* The scope containing this one. */ struct c_scope *outer; @@ -351,6 +414,14 @@ /* True means make a BLOCK for this scope no matter what. */ BOOL_BITFIELD keep : 1; + + /* True means that an unsuffixed float constant is _Decimal64. */ + BOOL_BITFIELD float_const_decimal64 : 1; + + /* True if this scope has any label bindings. This is used to speed + up searching for labels when popping scopes, particularly since + labels are normally only found at function scope. */ + BOOL_BITFIELD has_label_bindings : 1; }; /* The scope currently in effect. */ @@ -381,27 +452,53 @@ static GTY((deletable)) struct c_binding *binding_freelist; /* Append VAR to LIST in scope SCOPE. */ -#define SCOPE_LIST_APPEND(scope, list, decl) do { \ - struct c_scope *s_ = (scope); \ - tree d_ = (decl); \ - if (s_->list##_last) \ - BLOCK_CHAIN (s_->list##_last) = d_; \ - else \ - s_->list = d_; \ - s_->list##_last = d_; \ +#define SCOPE_LIST_APPEND(scope, list, decl) do { \ + struct c_scope *s_ = (scope); \ + tree d_ = (decl); \ + if (s_->list##_last) \ + BLOCK_CHAIN (s_->list##_last) = d_; \ + else \ + s_->list = d_; \ + s_->list##_last = d_; \ } while (0) /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */ -#define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \ - struct c_scope *t_ = (tscope); \ - struct c_scope *f_ = (fscope); \ - if (t_->to##_last) \ - BLOCK_CHAIN (t_->to##_last) = f_->from; \ - else \ - t_->to = f_->from; \ - t_->to##_last = f_->from##_last; \ +#define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \ + struct c_scope *t_ = (tscope); \ + struct c_scope *f_ = (fscope); \ + if (t_->to##_last) \ + BLOCK_CHAIN (t_->to##_last) = f_->from; \ + else \ + t_->to = f_->from; \ + t_->to##_last = f_->from##_last; \ } while (0) +/* A c_inline_static structure stores details of a static identifier + referenced in a definition of a function that may be an inline + definition if no subsequent declaration of that function uses + "extern" or does not use "inline". */ + +struct GTY((chain_next ("%h.next"))) c_inline_static { + /* The location for a diagnostic. */ + location_t location; + + /* The function that may be an inline definition. */ + tree function; + + /* The object or function referenced. */ + tree static_decl; + + /* What sort of reference this is. */ + enum c_inline_static_type type; + + /* The next such structure or NULL. */ + struct c_inline_static *next; +}; + +/* List of static identifiers used or referenced in functions that may + be inline definitions. */ +static GTY(()) struct c_inline_static *c_inline_statics; + /* True means unconditionally make a BLOCK for the next scope pushed. */ static bool keep_next_level_flag; @@ -412,13 +509,41 @@ static bool next_is_function_body; +/* A VEC of pointers to c_binding structures. */ + +typedef struct c_binding *c_binding_ptr; +DEF_VEC_P(c_binding_ptr); +DEF_VEC_ALLOC_P(c_binding_ptr,heap); + +/* Information that we keep for a struct or union while it is being + parsed. */ + +struct c_struct_parse_info +{ + /* If warn_cxx_compat, a list of types defined within this + struct. */ + VEC(tree,heap) *struct_types; + /* If warn_cxx_compat, a list of field names which have bindings, + and which are defined in this struct, but which are not defined + in any enclosing struct. This is used to clear the in_struct + field of the c_bindings structure. */ + VEC(c_binding_ptr,heap) *fields; + /* If warn_cxx_compat, a list of typedef names used when defining + fields in this struct. */ + VEC(tree,heap) *typedefs_seen; +}; + +/* Information for the struct or union currently being parsed, or + NULL if not parsing a struct or union. */ +static struct c_struct_parse_info *struct_parse_info; + /* Forward declarations. */ static tree lookup_name_in_scope (tree, struct c_scope *); -static tree c_make_fname_decl (tree, int); +static tree c_make_fname_decl (location_t, tree, int); static tree grokdeclarator (const struct c_declarator *, - struct c_declspecs *, - enum decl_context, bool, tree *, tree *, - enum deprecated_states); + struct c_declspecs *, + enum decl_context, bool, tree *, tree *, tree *, + bool *, enum deprecated_states); static tree grokparms (struct c_arg_info *, bool); static void layout_array_type (tree); @@ -434,7 +559,7 @@ if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR) { if (!EXPR_HAS_LOCATION (t)) - SET_EXPR_LOCATION (t, input_location); + SET_EXPR_LOCATION (t, input_location); } if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) @@ -458,8 +583,8 @@ { tree rid = ridpointers[C_RID_CODE (node)]; indent_to (file, indent + 4); - fprintf (file, "rid %p \"%s\"", - (void *) rid, IDENTIFIER_POINTER (rid)); + fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"", + (void *) rid, IDENTIFIER_POINTER (rid)); } } @@ -467,7 +592,8 @@ which may be any of several kinds of DECL or TYPE or error_mark_node, in the scope SCOPE. */ static void -bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested) +bind (tree name, tree decl, struct c_scope *scope, bool invisible, + bool nested, location_t locus) { struct c_binding *b, **here; @@ -486,8 +612,10 @@ b->invisible = invisible; b->nested = nested; b->inner_comp = 0; - - b->type = 0; + b->in_struct = 0; + b->locus = locus; + + b->u.type = NULL; b->prev = scope->bindings; scope->bindings = b; @@ -538,6 +666,24 @@ return prev; } +/* Bind a label. Like bind, but skip fields which aren't used for + labels, and add the LABEL_VARS value. */ +static void +bind_label (tree name, tree label, struct c_scope *scope, + struct c_label_vars *label_vars) +{ + struct c_binding *b; + + bind (name, label, scope, /*invisible=*/false, /*nested=*/false, + UNKNOWN_LOCATION); + + scope->has_label_bindings = true; + + b = scope->bindings; + gcc_assert (b->decl == label); + label_vars->shadowed = b->u.label; + b->u.label = label_vars; +} /* Hook called at end of compilation to assume 1 elt for a file-scope tentative array defn that wasn't complete before. */ @@ -549,17 +695,132 @@ { tree type = TREE_TYPE (decl); if (type != error_mark_node - && TREE_CODE (type) == ARRAY_TYPE - && !DECL_EXTERNAL (decl) - && TYPE_DOMAIN (type) == 0) - { - warning (0, "array %q+D assumed to have one element", decl); - - complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); - - layout_decl (decl, 0); - } - } + && TREE_CODE (type) == ARRAY_TYPE + && !DECL_EXTERNAL (decl) + && TYPE_DOMAIN (type) == 0) + { + warning_at (DECL_SOURCE_LOCATION (decl), + 0, "array %q+D assumed to have one element", decl); + + complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); + + layout_decl (decl, 0); + } + } +} + +/* Record that inline function FUNC contains a reference (location + LOC) to static DECL (file-scope or function-local according to + TYPE). */ + +void +record_inline_static (location_t loc, tree func, tree decl, + enum c_inline_static_type type) +{ + struct c_inline_static *csi = GGC_NEW (struct c_inline_static); + csi->location = loc; + csi->function = func; + csi->static_decl = decl; + csi->type = type; + csi->next = c_inline_statics; + c_inline_statics = csi; +} + +/* Check for references to static declarations in inline functions at + the end of the translation unit and diagnose them if the functions + are still inline definitions. */ + +static void +check_inline_statics (void) +{ + struct c_inline_static *csi; + for (csi = c_inline_statics; csi; csi = csi->next) + { + if (DECL_EXTERNAL (csi->function)) + switch (csi->type) + { + case csi_internal: + pedwarn (csi->location, 0, + "%qD is static but used in inline function %qD " + "which is not static", csi->static_decl, csi->function); + break; + case csi_modifiable: + pedwarn (csi->location, 0, + "%q+D is static but declared in inline function %qD " + "which is not static", csi->static_decl, csi->function); + break; + default: + gcc_unreachable (); + } + } + c_inline_statics = NULL; +} + +/* Fill in a c_spot_bindings structure. If DEFINING is true, set it + for the current state, otherwise set it to uninitialized. */ + +static void +set_spot_bindings (struct c_spot_bindings *p, bool defining) +{ + if (defining) + { + p->scope = current_scope; + p->bindings_in_scope = current_scope->bindings; + } + else + { + p->scope = NULL; + p->bindings_in_scope = NULL; + } + p->stmt_exprs = 0; + p->left_stmt_expr = false; +} + +/* Return true if we will want to say something if a goto statement + crosses DECL. */ + +static bool +decl_jump_unsafe (tree decl) +{ + if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) + return false; + + /* Always warn about crossing variably modified types. */ + if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL) + && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) + return true; + + /* Otherwise, only warn if -Wgoto-misses-init and this is an + initialized automatic decl. */ + if (warn_jump_misses_init + && TREE_CODE (decl) == VAR_DECL + && !TREE_STATIC (decl) + && DECL_INITIAL (decl) != NULL_TREE) + return true; + + return false; +} + +/* Update spot bindings P as we pop out of SCOPE. Return true if we + should push decls for a label. */ + +static bool +update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p) +{ + if (p->scope != scope) + { + /* This label or goto is defined in some other scope, or it is a + label which is not yet defined. There is nothing to + update. */ + return false; + } + + /* Adjust the spot bindings to refer to the bindings already defined + in the enclosing scope. */ + p->scope = scope->outer; + p->bindings_in_scope = p->scope->bindings; + + return true; } /* The Objective-C front-end often needs to determine the current scope. */ @@ -584,11 +845,11 @@ scope = scope->outer) { for (b = scope->bindings; b; b = b->prev) - objc_volatilize_decl (b->decl); + objc_volatilize_decl (b->decl); /* Do not climb up past the current function. */ if (scope->function_body) - break; + break; } } @@ -597,7 +858,9 @@ int global_bindings_p (void) { - return current_scope == file_scope && !c_override_global_bindings_to_false; + return (current_scope == file_scope && !c_override_global_bindings_to_false + ? -1 + : 0); } void @@ -606,6 +869,30 @@ keep_next_level_flag = true; } +/* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON. */ + +void +set_float_const_decimal64 (void) +{ + current_scope->float_const_decimal64 = true; +} + +/* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma. */ + +void +clear_float_const_decimal64 (void) +{ + current_scope->float_const_decimal64 = false; +} + +/* Return nonzero if an unsuffixed float constant is _Decimal64. */ + +bool +float_const_decimal64_p (void) +{ + return current_scope->float_const_decimal64; +} + /* Identify this scope as currently being filled with parameters. */ void @@ -620,15 +907,15 @@ if (next_is_function_body) { /* This is the transition from the parameters to the top level - of the function body. These are the same scope - (C99 6.2.1p4,6) so we do not push another scope structure. - next_is_function_body is set only by store_parm_decls, which - in turn is called when and only when we are about to - encounter the opening curly brace for the function body. - - The outermost block of a function always gets a BLOCK node, - because the debugging output routines expect that each - function has at least one BLOCK. */ + of the function body. These are the same scope + (C99 6.2.1p4,6) so we do not push another scope structure. + next_is_function_body is set only by store_parm_decls, which + in turn is called when and only when we are about to + encounter the opening curly brace for the function body. + + The outermost block of a function always gets a BLOCK node, + because the debugging output routines expect that each + function has at least one BLOCK. */ current_scope->parm_flag = false; current_scope->function_body = true; current_scope->keep = true; @@ -637,35 +924,109 @@ keep_next_level_flag = false; next_is_function_body = false; + + /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ + if (current_scope->outer) + current_scope->float_const_decimal64 + = current_scope->outer->float_const_decimal64; + else + current_scope->float_const_decimal64 = false; } else { struct c_scope *scope; if (scope_freelist) - { - scope = scope_freelist; - scope_freelist = scope->outer; - } + { + scope = scope_freelist; + scope_freelist = scope->outer; + } else - scope = GGC_CNEW (struct c_scope); + scope = GGC_CNEW (struct c_scope); + + /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ + if (current_scope) + scope->float_const_decimal64 = current_scope->float_const_decimal64; + else + scope->float_const_decimal64 = false; scope->keep = keep_next_level_flag; scope->outer = current_scope; - scope->depth = current_scope ? (current_scope->depth + 1) : 0; + scope->depth = current_scope ? (current_scope->depth + 1) : 0; /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but - possible. */ + possible. */ if (current_scope && scope->depth == 0) - { - scope->depth--; - sorry ("GCC supports only %u nested scopes", scope->depth); - } + { + scope->depth--; + sorry ("GCC supports only %u nested scopes", scope->depth); + } current_scope = scope; keep_next_level_flag = false; } } +/* This is called when we are leaving SCOPE. For each label defined + in SCOPE, add any appropriate decls to its decls_in_scope fields. + These are the decls whose initialization will be skipped by a goto + later in the function. */ + +static void +update_label_decls (struct c_scope *scope) +{ + struct c_scope *s; + + s = scope; + while (s != NULL) + { + if (s->has_label_bindings) + { + struct c_binding *b; + + for (b = s->bindings; b != NULL; b = b->prev) + { + struct c_label_vars *label_vars; + struct c_binding *b1; + unsigned int ix; + struct c_goto_bindings *g; + + if (TREE_CODE (b->decl) != LABEL_DECL) + continue; + label_vars = b->u.label; + + b1 = label_vars->label_bindings.bindings_in_scope; + if (update_spot_bindings (scope, &label_vars->label_bindings)) + { + /* This label is defined in this scope. */ + for (; b1 != NULL; b1 = b1->prev) + { + /* A goto from later in the function to this + label will never see the initialization of + B1, if any. Save it to issue a warning if + needed. */ + if (decl_jump_unsafe (b1->decl)) + VEC_safe_push (tree, gc, label_vars->decls_in_scope, + b1->decl); + } + } + + /* Update the bindings of any goto statements associated + with this label. */ + for (ix = 0; + VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); + ++ix) + update_spot_bindings (scope, &g->goto_bindings); + } + } + + /* Don't search beyond the current function. */ + if (s == current_function_scope) + break; + + s = s->outer; + } +} + /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */ static void @@ -691,7 +1052,7 @@ bool functionbody = scope->function_body; bool keep = functionbody || scope->keep || scope->bindings; - c_end_vm_scope (scope->depth); + update_label_decls (scope); /* If appropriate, create a BLOCK to record the decls for the life of this function. */ @@ -704,7 +1065,7 @@ /* In each subblock, record that this is its superior. */ for (p = scope->blocks; p; p = BLOCK_CHAIN (p)) - BLOCK_SUPERCONTEXT (p) = block; + BLOCK_SUPERCONTEXT (p) = block; BLOCK_VARS (block) = 0; } @@ -726,7 +1087,8 @@ context = current_function_decl; else if (scope == file_scope) { - tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0); + tree file_decl = build_decl (UNKNOWN_LOCATION, + TRANSLATION_UNIT_DECL, 0, 0); TREE_CHAIN (file_decl) = all_translation_units; all_translation_units = file_decl; context = file_decl; @@ -739,132 +1101,159 @@ { p = b->decl; switch (TREE_CODE (p)) - { - case LABEL_DECL: - /* Warnings for unused labels, errors for undefined labels. */ - if (TREE_USED (p) && !DECL_INITIAL (p)) - { - error ("label %q+D used but not defined", p); - DECL_INITIAL (p) = error_mark_node; - } - else - warn_for_unused_label (p); - - /* Labels go in BLOCK_VARS. */ - TREE_CHAIN (p) = BLOCK_VARS (block); - BLOCK_VARS (block) = p; - gcc_assert (I_LABEL_BINDING (b->id) == b); - I_LABEL_BINDING (b->id) = b->shadowed; - break; - - case ENUMERAL_TYPE: - case UNION_TYPE: - case RECORD_TYPE: - set_type_context (p, context); - - /* Types may not have tag-names, in which case the type - appears in the bindings list with b->id NULL. */ - if (b->id) - { - gcc_assert (I_TAG_BINDING (b->id) == b); - I_TAG_BINDING (b->id) = b->shadowed; - } - break; - - case FUNCTION_DECL: - /* Propagate TREE_ADDRESSABLE from nested functions to their - containing functions. */ - if (!TREE_ASM_WRITTEN (p) - && DECL_INITIAL (p) != 0 - && TREE_ADDRESSABLE (p) - && DECL_ABSTRACT_ORIGIN (p) != 0 - && DECL_ABSTRACT_ORIGIN (p) != p) - TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1; - if (!DECL_EXTERNAL (p) - && !DECL_INITIAL (p) - && scope != file_scope - && scope != external_scope) - { - error ("nested function %q+D declared but never defined", p); - undef_nested_function = true; - } - else if (DECL_DECLARED_INLINE_P (p) - && TREE_PUBLIC (p) - && !DECL_INITIAL (p)) - { - /* C99 6.7.4p6: "a function with external linkage... declared - with an inline function specifier ... shall also be defined - in the same translation unit." */ - if (!flag_gnu89_inline) - pedwarn (input_location, 0, - "inline function %q+D declared but never defined", p); - DECL_EXTERNAL (p) = 1; - } - - goto common_symbol; - - case VAR_DECL: - /* Warnings for unused variables. */ - if (!TREE_USED (p) - && !TREE_NO_WARNING (p) - && !DECL_IN_SYSTEM_HEADER (p) - && DECL_NAME (p) - && !DECL_ARTIFICIAL (p) - && scope != file_scope - && scope != external_scope) - warning (OPT_Wunused_variable, "unused variable %q+D", p); - - if (b->inner_comp) - { - error ("type of array %q+D completed incompatibly with" - " implicit initialization", p); - } - - /* Fall through. */ - case TYPE_DECL: - case CONST_DECL: - common_symbol: - /* All of these go in BLOCK_VARS, but only if this is the - binding in the home scope. */ - if (!b->nested) - { - TREE_CHAIN (p) = BLOCK_VARS (block); - BLOCK_VARS (block) = p; - } - /* If this is the file scope, and we are processing more - than one translation unit in this compilation, set - DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. - This makes same_translation_unit_p work, and causes - static declarations to be given disambiguating suffixes. */ - if (scope == file_scope && num_in_fnames > 1) - { - DECL_CONTEXT (p) = context; - if (TREE_CODE (p) == TYPE_DECL) - set_type_context (TREE_TYPE (p), context); - } - - /* Fall through. */ - /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have - already been put there by store_parm_decls. Unused- - parameter warnings are handled by function.c. - error_mark_node obviously does not go in BLOCK_VARS and - does not get unused-variable warnings. */ - case PARM_DECL: - case ERROR_MARK: - /* It is possible for a decl not to have a name. We get - here with b->id NULL in this case. */ - if (b->id) - { - gcc_assert (I_SYMBOL_BINDING (b->id) == b); - I_SYMBOL_BINDING (b->id) = b->shadowed; - if (b->shadowed && b->shadowed->type) - TREE_TYPE (b->shadowed->decl) = b->shadowed->type; - } - break; - - default: - gcc_unreachable (); - } + { + case LABEL_DECL: + /* Warnings for unused labels, errors for undefined labels. */ + if (TREE_USED (p) && !DECL_INITIAL (p)) + { + error ("label %q+D used but not defined", p); + DECL_INITIAL (p) = error_mark_node; + } + else + warn_for_unused_label (p); + + /* Labels go in BLOCK_VARS. */ + TREE_CHAIN (p) = BLOCK_VARS (block); + BLOCK_VARS (block) = p; + gcc_assert (I_LABEL_BINDING (b->id) == b); + I_LABEL_BINDING (b->id) = b->shadowed; + + /* Also pop back to the shadowed label_vars. */ + release_tree_vector (b->u.label->decls_in_scope); + b->u.label = b->u.label->shadowed; + break; + + case ENUMERAL_TYPE: + case UNION_TYPE: + case RECORD_TYPE: + set_type_context (p, context); + + /* Types may not have tag-names, in which case the type + appears in the bindings list with b->id NULL. */ + if (b->id) + { + gcc_assert (I_TAG_BINDING (b->id) == b); + I_TAG_BINDING (b->id) = b->shadowed; + } + break; + + case FUNCTION_DECL: + /* Propagate TREE_ADDRESSABLE from nested functions to their + containing functions. */ + if (!TREE_ASM_WRITTEN (p) + && DECL_INITIAL (p) != 0 + && TREE_ADDRESSABLE (p) + && DECL_ABSTRACT_ORIGIN (p) != 0 + && DECL_ABSTRACT_ORIGIN (p) != p) + TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1; + if (!DECL_EXTERNAL (p) + && !DECL_INITIAL (p) + && scope != file_scope + && scope != external_scope) + { + error ("nested function %q+D declared but never defined", p); + undef_nested_function = true; + } + else if (DECL_DECLARED_INLINE_P (p) + && TREE_PUBLIC (p) + && !DECL_INITIAL (p)) + { + /* C99 6.7.4p6: "a function with external linkage... declared + with an inline function specifier ... shall also be defined + in the same translation unit." */ + if (!flag_gnu89_inline) + pedwarn (input_location, 0, + "inline function %q+D declared but never defined", p); + DECL_EXTERNAL (p) = 1; + } + + goto common_symbol; + + case VAR_DECL: + /* Warnings for unused variables. */ + if (!TREE_USED (p) + && !TREE_NO_WARNING (p) + && !DECL_IN_SYSTEM_HEADER (p) + && DECL_NAME (p) + && !DECL_ARTIFICIAL (p) + && scope != file_scope + && scope != external_scope) + warning (OPT_Wunused_variable, "unused variable %q+D", p); + + if (b->inner_comp) + { + error ("type of array %q+D completed incompatibly with" + " implicit initialization", p); + } + + /* Fall through. */ + case TYPE_DECL: + case CONST_DECL: + common_symbol: + /* All of these go in BLOCK_VARS, but only if this is the + binding in the home scope. */ + if (!b->nested) + { + TREE_CHAIN (p) = BLOCK_VARS (block); + BLOCK_VARS (block) = p; + } + else if (VAR_OR_FUNCTION_DECL_P (p)) + { + /* For block local externs add a special + DECL_EXTERNAL decl for debug info generation. */ + tree extp = copy_node (p); + + DECL_EXTERNAL (extp) = 1; + TREE_STATIC (extp) = 0; + TREE_PUBLIC (extp) = 1; + DECL_INITIAL (extp) = NULL_TREE; + DECL_LANG_SPECIFIC (extp) = NULL; + DECL_CONTEXT (extp) = current_function_decl; + if (TREE_CODE (p) == FUNCTION_DECL) + { + DECL_RESULT (extp) = NULL_TREE; + DECL_SAVED_TREE (extp) = NULL_TREE; + DECL_STRUCT_FUNCTION (extp) = NULL; + } + if (b->locus != UNKNOWN_LOCATION) + DECL_SOURCE_LOCATION (extp) = b->locus; + TREE_CHAIN (extp) = BLOCK_VARS (block); + BLOCK_VARS (block) = extp; + } + /* If this is the file scope, and we are processing more + than one translation unit in this compilation, set + DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. + This makes same_translation_unit_p work, and causes + static declarations to be given disambiguating suffixes. */ + if (scope == file_scope && num_in_fnames > 1) + { + DECL_CONTEXT (p) = context; + if (TREE_CODE (p) == TYPE_DECL) + set_type_context (TREE_TYPE (p), context); + } + + /* Fall through. */ + /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have + already been put there by store_parm_decls. Unused- + parameter warnings are handled by function.c. + error_mark_node obviously does not go in BLOCK_VARS and + does not get unused-variable warnings. */ + case PARM_DECL: + case ERROR_MARK: + /* It is possible for a decl not to have a name. We get + here with b->id NULL in this case. */ + if (b->id) + { + gcc_assert (I_SYMBOL_BINDING (b->id) == b); + I_SYMBOL_BINDING (b->id) = b->shadowed; + if (b->shadowed && b->shadowed->u.type) + TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type; + } + break; + + default: + gcc_unreachable (); + } } @@ -877,12 +1266,12 @@ else if (scope->outer) { if (block) - SCOPE_LIST_APPEND (scope->outer, blocks, block); + SCOPE_LIST_APPEND (scope->outer, blocks, block); /* If we did not make a block for the scope just exited, any - blocks made for inner scopes must be carried forward so they - will later become subblocks of something else. */ + blocks made for inner scopes must be carried forward so they + will later become subblocks of something else. */ else if (scope->blocks) - SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks); + SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks); } /* Pop the current scope, and free the structure for reuse. */ @@ -912,7 +1301,7 @@ for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) bind (DECL_NAME (decl), decl, file_scope, - /*invisible=*/false, /*nested=*/true); + /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); } void @@ -928,6 +1317,8 @@ still works without it. */ finish_fname_decls (); + check_inline_statics (); + /* This is the point to write out a PCH if we're doing that. In that case we do not want to do anything else. */ if (pch_file) @@ -941,24 +1332,108 @@ file_scope = 0; maybe_apply_pending_pragma_weaks (); - cgraph_finalize_compilation_unit (); -} - +} + +/* Adjust the bindings for the start of a statement expression. */ + +void +c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings) +{ + struct c_scope *scope; + + for (scope = current_scope; scope != NULL; scope = scope->outer) + { + struct c_binding *b; + + if (!scope->has_label_bindings) + continue; + + for (b = scope->bindings; b != NULL; b = b->prev) + { + struct c_label_vars *label_vars; + unsigned int ix; + struct c_goto_bindings *g; + + if (TREE_CODE (b->decl) != LABEL_DECL) + continue; + label_vars = b->u.label; + ++label_vars->label_bindings.stmt_exprs; + for (ix = 0; + VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); + ++ix) + ++g->goto_bindings.stmt_exprs; + } + } + + if (switch_bindings != NULL) + ++switch_bindings->stmt_exprs; +} + +/* Adjust the bindings for the end of a statement expression. */ + +void +c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings) +{ + struct c_scope *scope; + + for (scope = current_scope; scope != NULL; scope = scope->outer) + { + struct c_binding *b; + + if (!scope->has_label_bindings) + continue; + + for (b = scope->bindings; b != NULL; b = b->prev) + { + struct c_label_vars *label_vars; + unsigned int ix; + struct c_goto_bindings *g; + + if (TREE_CODE (b->decl) != LABEL_DECL) + continue; + label_vars = b->u.label; + --label_vars->label_bindings.stmt_exprs; + if (label_vars->label_bindings.stmt_exprs < 0) + { + label_vars->label_bindings.left_stmt_expr = true; + label_vars->label_bindings.stmt_exprs = 0; + } + for (ix = 0; + VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); + ++ix) + { + --g->goto_bindings.stmt_exprs; + if (g->goto_bindings.stmt_exprs < 0) + { + g->goto_bindings.left_stmt_expr = true; + g->goto_bindings.stmt_exprs = 0; + } + } + } + } + + if (switch_bindings != NULL) + { + --switch_bindings->stmt_exprs; + gcc_assert (switch_bindings->stmt_exprs >= 0); + } +} /* Push a definition or a declaration of struct, union or enum tag "name". "type" should be the type node. - We assume that the tag "name" is not already defined. + We assume that the tag "name" is not already defined, and has a location + of LOC. Note that the definition may really be just a forward reference. In that case, the TYPE_SIZE will be zero. */ static void -pushtag (tree name, tree type) +pushtag (location_t loc, tree name, tree type) { /* Record the identifier as the type's name if it has none. */ if (name && !TYPE_NAME (type)) TYPE_NAME (type) = name; - bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false); + bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc); /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the tagged type we just added to the current scope. This fake @@ -967,11 +1442,33 @@ us a convenient place to record the "scope start" address for the tagged type. */ - TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); + TYPE_STUB_DECL (type) = pushdecl (build_decl (loc, + TYPE_DECL, NULL_TREE, type)); /* An approximation for now, so we can tell this is a function-scope tag. This will be updated in pop_scope. */ TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); + + if (warn_cxx_compat && name != NULL_TREE) + { + struct c_binding *b = I_SYMBOL_BINDING (name); + + if (b != NULL + && b->decl != NULL_TREE + && TREE_CODE (b->decl) == TYPE_DECL + && (B_IN_CURRENT_SCOPE (b) + || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) + && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) + != TYPE_MAIN_VARIANT (type))) + { + warning_at (loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), + b->decl); + if (b->locus != UNKNOWN_LOCATION) + inform (b->locus, "originally defined here"); + } + } } /* Subroutine of compare_decls. Allow harmless mismatches in return @@ -999,12 +1496,12 @@ while (oldargs || newargs) { if (!oldargs - || !newargs - || !TREE_VALUE (oldargs) - || !TREE_VALUE (newargs) - || TYPE_MODE (TREE_VALUE (oldargs)) - != TYPE_MODE (TREE_VALUE (newargs))) - return 0; + || !newargs + || !TREE_VALUE (oldargs) + || !TREE_VALUE (newargs) + || TYPE_MODE (TREE_VALUE (oldargs)) + != TYPE_MODE (TREE_VALUE (newargs))) + return 0; oldargs = TREE_CHAIN (oldargs); newargs = TREE_CHAIN (newargs); @@ -1019,15 +1516,15 @@ diagnostics. */ static void diagnose_arglist_conflict (tree newdecl, tree olddecl, - tree newtype, tree oldtype) + tree newtype, tree oldtype) { tree t; if (TREE_CODE (olddecl) != FUNCTION_DECL || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype)) || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0) - || - (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0))) + || + (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0))) return; t = TYPE_ARG_TYPES (oldtype); @@ -1038,19 +1535,19 @@ tree type = TREE_VALUE (t); if (TREE_CHAIN (t) == 0 - && TYPE_MAIN_VARIANT (type) != void_type_node) - { - inform (input_location, "a parameter list with an ellipsis can%'t match " - "an empty parameter name list declaration"); - break; - } + && TYPE_MAIN_VARIANT (type) != void_type_node) + { + inform (input_location, "a parameter list with an ellipsis can%'t match " + "an empty parameter name list declaration"); + break; + } if (c_type_promotes_to (type) != type) - { - inform (input_location, "an argument type that has a default promotion can%'t match " - "an empty parameter name list declaration"); - break; - } + { + inform (input_location, "an argument type that has a default promotion can%'t match " + "an empty parameter name list declaration"); + break; + } } } @@ -1076,38 +1573,38 @@ tree newargtype = TREE_VALUE (newargs); if (oldargtype == error_mark_node || newargtype == error_mark_node) - return false; + return false; oldargtype = TYPE_MAIN_VARIANT (oldargtype); newargtype = TYPE_MAIN_VARIANT (newargtype); if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype)) - break; + break; /* Reaching the end of just one list means the two decls don't - agree on the number of arguments. */ + agree on the number of arguments. */ if (END_OF_ARGLIST (oldargtype)) - { - error ("prototype for %q+D declares more arguments " - "than previous old-style definition", newdecl); - return false; - } + { + error ("prototype for %q+D declares more arguments " + "than previous old-style definition", newdecl); + return false; + } else if (END_OF_ARGLIST (newargtype)) - { - error ("prototype for %q+D declares fewer arguments " - "than previous old-style definition", newdecl); - return false; - } + { + error ("prototype for %q+D declares fewer arguments " + "than previous old-style definition", newdecl); + return false; + } /* Type for passing arg must be consistent with that declared - for the arg. */ + for the arg. */ else if (!comptypes (oldargtype, newargtype)) - { - error ("prototype for %q+D declares argument %d" - " with incompatible type", - newdecl, i); - return false; - } + { + error ("prototype for %q+D declares argument %d" + " with incompatible type", + newdecl, i); + return false; + } oldargs = TREE_CHAIN (oldargs); newargs = TREE_CHAIN (newargs); @@ -1117,7 +1614,7 @@ /* If we get here, no errors were found, but do issue a warning for this poor-style construct. */ warning (0, "prototype for %q+D follows non-prototype definition", - newdecl); + newdecl); return true; #undef END_OF_ARGLIST } @@ -1148,7 +1645,7 @@ static bool diagnose_mismatched_decls (tree newdecl, tree olddecl, - tree *newtypep, tree *oldtypep) + tree *newtypep, tree *oldtypep) { tree newtype, oldtype; bool pedwarned = false; @@ -1156,7 +1653,7 @@ bool retval = true; #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \ - && DECL_EXTERNAL (DECL)) + && DECL_EXTERNAL (DECL)) /* If we have error_mark_node for either decl or type, just discard the previous decl - we're in an error cascade already. */ @@ -1172,18 +1669,18 @@ if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) { if (!(TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl))) - { - error ("%q+D redeclared as different kind of symbol", newdecl); - locate_old_decl (olddecl); - } + && DECL_BUILT_IN (olddecl) + && !C_DECL_DECLARED_BUILTIN (olddecl))) + { + error ("%q+D redeclared as different kind of symbol", newdecl); + locate_old_decl (olddecl); + } else if (TREE_PUBLIC (newdecl)) - warning (0, "built-in function %q+D declared as non-function", - newdecl); + warning (0, "built-in function %q+D declared as non-function", + newdecl); else - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", newdecl); + warning (OPT_Wshadow, "declaration of %q+D shadows " + "a built-in function", newdecl); return false; } @@ -1199,71 +1696,98 @@ if (!comptypes (oldtype, newtype)) { if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) - { - /* Accept harmless mismatch in function types. - This is for the ffs and fprintf builtins. */ - tree trytype = match_builtin_function_types (newtype, oldtype); - - if (trytype && comptypes (newtype, trytype)) - *oldtypep = oldtype = trytype; - else - { - /* If types don't match for a built-in, throw away the - built-in. No point in calling locate_old_decl here, it - won't print anything. */ - warning (0, "conflicting types for built-in function %q+D", - newdecl); - return false; - } - } + && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) + { + /* Accept harmless mismatch in function types. + This is for the ffs and fprintf builtins. */ + tree trytype = match_builtin_function_types (newtype, oldtype); + + if (trytype && comptypes (newtype, trytype)) + *oldtypep = oldtype = trytype; + else + { + /* If types don't match for a built-in, throw away the + built-in. No point in calling locate_old_decl here, it + won't print anything. */ + warning (0, "conflicting types for built-in function %q+D", + newdecl); + return false; + } + } else if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_IS_BUILTIN (olddecl)) - { - /* A conflicting function declaration for a predeclared - function that isn't actually built in. Objective C uses - these. The new declaration silently overrides everything - but the volatility (i.e. noreturn) indication. See also - below. FIXME: Make Objective C use normal builtins. */ - TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); - return false; - } + && DECL_IS_BUILTIN (olddecl)) + { + /* A conflicting function declaration for a predeclared + function that isn't actually built in. Objective C uses + these. The new declaration silently overrides everything + but the volatility (i.e. noreturn) indication. See also + below. FIXME: Make Objective C use normal builtins. */ + TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); + return false; + } /* Permit void foo (...) to match int foo (...) if the latter is - the definition and implicit int was used. See - c-torture/compile/920625-2.c. */ + the definition and implicit int was used. See + c-torture/compile/920625-2.c. */ else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) - && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node - && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node - && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) - { - pedwarned = pedwarn (input_location, 0, - "conflicting types for %q+D", newdecl); - /* Make sure we keep void as the return type. */ - TREE_TYPE (newdecl) = *newtypep = newtype = oldtype; - C_FUNCTION_IMPLICIT_INT (newdecl) = 0; - } + && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node + && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) + { + pedwarned = pedwarn (input_location, 0, + "conflicting types for %q+D", newdecl); + /* Make sure we keep void as the return type. */ + TREE_TYPE (newdecl) = *newtypep = newtype = oldtype; + C_FUNCTION_IMPLICIT_INT (newdecl) = 0; + } /* Permit void foo (...) to match an earlier call to foo (...) with - no declared type (thus, implicitly int). */ + no declared type (thus, implicitly int). */ else if (TREE_CODE (newdecl) == FUNCTION_DECL - && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node - && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node - && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) - { - pedwarned = pedwarn (input_location, 0, - "conflicting types for %q+D", newdecl); - /* Make sure we keep void as the return type. */ - TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; - } + && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node + && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) + { + pedwarned = pedwarn (input_location, 0, + "conflicting types for %q+D", newdecl); + /* Make sure we keep void as the return type. */ + TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; + } else - { - if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype)) - error ("conflicting type qualifiers for %q+D", newdecl); - else - error ("conflicting types for %q+D", newdecl); - diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); - locate_old_decl (olddecl); - return false; - } + { + int new_quals = TYPE_QUALS (newtype); + int old_quals = TYPE_QUALS (oldtype); + + if (new_quals != old_quals) + { + addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals); + addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals); + if (new_addr != old_addr) + { + if (ADDR_SPACE_GENERIC_P (new_addr)) + error ("conflicting named address spaces (generic vs %s) " + "for %q+D", + c_addr_space_name (old_addr), newdecl); + else if (ADDR_SPACE_GENERIC_P (old_addr)) + error ("conflicting named address spaces (%s vs generic) " + "for %q+D", + c_addr_space_name (new_addr), newdecl); + else + error ("conflicting named address spaces (%s vs %s) " + "for %q+D", + c_addr_space_name (new_addr), + c_addr_space_name (old_addr), + newdecl); + } + + if (CLEAR_QUAL_ADDR_SPACE (new_quals) + != CLEAR_QUAL_ADDR_SPACE (old_quals)) + error ("conflicting type qualifiers for %q+D", newdecl); + } + else + error ("conflicting types for %q+D", newdecl); + diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); + locate_old_decl (olddecl); + return false; + } } /* Redeclaration of a type is a constraint violation (6.7.2.3p1), @@ -1272,10 +1796,10 @@ if (TREE_CODE (newdecl) == TYPE_DECL) { if (DECL_IN_SYSTEM_HEADER (newdecl) - || DECL_IN_SYSTEM_HEADER (olddecl) - || TREE_NO_WARNING (newdecl) - || TREE_NO_WARNING (olddecl)) - return true; /* Allow OLDDECL to continue in use. */ + || DECL_IN_SYSTEM_HEADER (olddecl) + || TREE_NO_WARNING (newdecl) + || TREE_NO_WARNING (olddecl)) + return true; /* Allow OLDDECL to continue in use. */ error ("redefinition of typedef %q+D", newdecl); locate_old_decl (olddecl); @@ -1293,211 +1817,224 @@ else if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* If you declare a built-in function name as static, or - define the built-in with an old-style definition (so we - can't validate the argument list) the built-in definition is - overridden, but optionally warn this was a bad choice of name. */ + define the built-in with an old-style definition (so we + can't validate the argument list) the built-in definition is + overridden, but optionally warn this was a bad choice of name. */ if (DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl) - && (!TREE_PUBLIC (newdecl) - || (DECL_INITIAL (newdecl) - && !TYPE_ARG_TYPES (TREE_TYPE (newdecl))))) - { - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", newdecl); - /* Discard the old built-in function. */ - return false; - } + && !C_DECL_DECLARED_BUILTIN (olddecl) + && (!TREE_PUBLIC (newdecl) + || (DECL_INITIAL (newdecl) + && !TYPE_ARG_TYPES (TREE_TYPE (newdecl))))) + { + warning (OPT_Wshadow, "declaration of %q+D shadows " + "a built-in function", newdecl); + /* Discard the old built-in function. */ + return false; + } if (DECL_INITIAL (newdecl)) - { - if (DECL_INITIAL (olddecl)) - { - /* If both decls are in the same TU and the new declaration - isn't overriding an extern inline reject the new decl. - In c99, no overriding is allowed in the same translation - unit. */ - if ((!DECL_EXTERN_INLINE (olddecl) - || DECL_EXTERN_INLINE (newdecl) - || (!flag_gnu89_inline - && (!DECL_DECLARED_INLINE_P (olddecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (olddecl))) - && (!DECL_DECLARED_INLINE_P (newdecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (newdecl)))) - ) - && same_translation_unit_p (newdecl, olddecl)) - { - error ("redefinition of %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } - } - } + { + if (DECL_INITIAL (olddecl)) + { + /* If both decls are in the same TU and the new declaration + isn't overriding an extern inline reject the new decl. + In c99, no overriding is allowed in the same translation + unit. */ + if ((!DECL_EXTERN_INLINE (olddecl) + || DECL_EXTERN_INLINE (newdecl) + || (!flag_gnu89_inline + && (!DECL_DECLARED_INLINE_P (olddecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (olddecl))) + && (!DECL_DECLARED_INLINE_P (newdecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (newdecl)))) + ) + && same_translation_unit_p (newdecl, olddecl)) + { + error ("redefinition of %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } + } + } /* If we have a prototype after an old-style function definition, - the argument types must be checked specially. */ + the argument types must be checked specially. */ else if (DECL_INITIAL (olddecl) - && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype) - && TYPE_ACTUAL_ARG_TYPES (oldtype) - && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) - { - locate_old_decl (olddecl); - return false; - } + && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype) + && TYPE_ACTUAL_ARG_TYPES (oldtype) + && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) + { + locate_old_decl (olddecl); + return false; + } /* A non-static declaration (even an "extern") followed by a - static declaration is undefined behavior per C99 6.2.2p3-5,7. - The same is true for a static forward declaration at block - scope followed by a non-static declaration/definition at file - scope. Static followed by non-static at the same scope is - not undefined behavior, and is the most convenient way to get - some effects (see e.g. what unwind-dw2-fde-glibc.c does to - the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but - we do diagnose it if -Wtraditional. */ + static declaration is undefined behavior per C99 6.2.2p3-5,7. + The same is true for a static forward declaration at block + scope followed by a non-static declaration/definition at file + scope. Static followed by non-static at the same scope is + not undefined behavior, and is the most convenient way to get + some effects (see e.g. what unwind-dw2-fde-glibc.c does to + the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but + we do diagnose it if -Wtraditional. */ if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl)) - { - /* Two exceptions to the rule. If olddecl is an extern - inline, or a predeclared function that isn't actually - built in, newdecl silently overrides olddecl. The latter - occur only in Objective C; see also above. (FIXME: Make - Objective C use normal builtins.) */ - if (!DECL_IS_BUILTIN (olddecl) - && !DECL_EXTERN_INLINE (olddecl)) - { - error ("static declaration of %q+D follows " - "non-static declaration", newdecl); - locate_old_decl (olddecl); - } - return false; - } + { + /* Two exceptions to the rule. If olddecl is an extern + inline, or a predeclared function that isn't actually + built in, newdecl silently overrides olddecl. The latter + occur only in Objective C; see also above. (FIXME: Make + Objective C use normal builtins.) */ + if (!DECL_IS_BUILTIN (olddecl) + && !DECL_EXTERN_INLINE (olddecl)) + { + error ("static declaration of %q+D follows " + "non-static declaration", newdecl); + locate_old_decl (olddecl); + } + return false; + } else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)) - { - if (DECL_CONTEXT (olddecl)) - { - error ("non-static declaration of %q+D follows " - "static declaration", newdecl); - locate_old_decl (olddecl); - return false; - } - else if (warn_traditional) - { - warned |= warning (OPT_Wtraditional, - "non-static declaration of %q+D " - "follows static declaration", newdecl); - } - } + { + if (DECL_CONTEXT (olddecl)) + { + error ("non-static declaration of %q+D follows " + "static declaration", newdecl); + locate_old_decl (olddecl); + return false; + } + else if (warn_traditional) + { + warned |= warning (OPT_Wtraditional, + "non-static declaration of %q+D " + "follows static declaration", newdecl); + } + } /* Make sure gnu_inline attribute is either not present, or - present on all inline decls. */ + present on all inline decls. */ if (DECL_DECLARED_INLINE_P (olddecl) - && DECL_DECLARED_INLINE_P (newdecl)) - { - bool newa = lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (newdecl)) != NULL; - bool olda = lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (olddecl)) != NULL; - if (newa != olda) - { - error ("%<gnu_inline%> attribute present on %q+D", - newa ? newdecl : olddecl); - error ("%Jbut not here", newa ? olddecl : newdecl); - } - } + && DECL_DECLARED_INLINE_P (newdecl)) + { + bool newa = lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (newdecl)) != NULL; + bool olda = lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (olddecl)) != NULL; + if (newa != olda) + { + error_at (input_location, "%<gnu_inline%> attribute present on %q+D", + newa ? newdecl : olddecl); + error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), + "but not here"); + } + } } else if (TREE_CODE (newdecl) == VAR_DECL) { /* Only variables can be thread-local, and all declarations must - agree on this property. */ + agree on this property. */ if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl)) - { - /* Nothing to check. Since OLDDECL is marked threadprivate - and NEWDECL does not have a thread-local attribute, we - will merge the threadprivate attribute into NEWDECL. */ - ; - } + { + /* Nothing to check. Since OLDDECL is marked threadprivate + and NEWDECL does not have a thread-local attribute, we + will merge the threadprivate attribute into NEWDECL. */ + ; + } else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)) - { - if (DECL_THREAD_LOCAL_P (newdecl)) - error ("thread-local declaration of %q+D follows " - "non-thread-local declaration", newdecl); - else - error ("non-thread-local declaration of %q+D follows " - "thread-local declaration", newdecl); - - locate_old_decl (olddecl); - return false; - } + { + if (DECL_THREAD_LOCAL_P (newdecl)) + error ("thread-local declaration of %q+D follows " + "non-thread-local declaration", newdecl); + else + error ("non-thread-local declaration of %q+D follows " + "thread-local declaration", newdecl); + + locate_old_decl (olddecl); + return false; + } /* Multiple initialized definitions are not allowed (6.9p3,5). */ if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl)) - { - error ("redefinition of %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } + { + error ("redefinition of %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } /* Objects declared at file scope: if the first declaration had - external linkage (even if it was an external reference) the - second must have external linkage as well, or the behavior is - undefined. If the first declaration had internal linkage, then - the second must too, or else be an external reference (in which - case the composite declaration still has internal linkage). - As for function declarations, we warn about the static-then- - extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */ + external linkage (even if it was an external reference) the + second must have external linkage as well, or the behavior is + undefined. If the first declaration had internal linkage, then + the second must too, or else be an external reference (in which + case the composite declaration still has internal linkage). + As for function declarations, we warn about the static-then- + extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */ if (DECL_FILE_SCOPE_P (newdecl) - && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl)) - { - if (DECL_EXTERNAL (newdecl)) - { - if (!DECL_FILE_SCOPE_P (olddecl)) - { - error ("extern declaration of %q+D follows " - "declaration with no linkage", newdecl); - locate_old_decl (olddecl); - return false; - } - else if (warn_traditional) - { - warned |= warning (OPT_Wtraditional, - "non-static declaration of %q+D " - "follows static declaration", newdecl); - } - } - else - { - if (TREE_PUBLIC (newdecl)) - error ("non-static declaration of %q+D follows " - "static declaration", newdecl); - else - error ("static declaration of %q+D follows " - "non-static declaration", newdecl); - - locate_old_decl (olddecl); - return false; - } - } + && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl)) + { + if (DECL_EXTERNAL (newdecl)) + { + if (!DECL_FILE_SCOPE_P (olddecl)) + { + error ("extern declaration of %q+D follows " + "declaration with no linkage", newdecl); + locate_old_decl (olddecl); + return false; + } + else if (warn_traditional) + { + warned |= warning (OPT_Wtraditional, + "non-static declaration of %q+D " + "follows static declaration", newdecl); + } + } + else + { + if (TREE_PUBLIC (newdecl)) + error ("non-static declaration of %q+D follows " + "static declaration", newdecl); + else + error ("static declaration of %q+D follows " + "non-static declaration", newdecl); + + locate_old_decl (olddecl); + return false; + } + } /* Two objects with the same name declared at the same block - scope must both be external references (6.7p3). */ + scope must both be external references (6.7p3). */ else if (!DECL_FILE_SCOPE_P (newdecl)) - { - if (DECL_EXTERNAL (newdecl)) - { - /* Extern with initializer at block scope, which will - already have received an error. */ - } - else if (DECL_EXTERNAL (olddecl)) - { - error ("declaration of %q+D with no linkage follows " - "extern declaration", newdecl); - locate_old_decl (olddecl); - } - else - { - error ("redeclaration of %q+D with no linkage", newdecl); - locate_old_decl (olddecl); - } - - return false; - } + { + if (DECL_EXTERNAL (newdecl)) + { + /* Extern with initializer at block scope, which will + already have received an error. */ + } + else if (DECL_EXTERNAL (olddecl)) + { + error ("declaration of %q+D with no linkage follows " + "extern declaration", newdecl); + locate_old_decl (olddecl); + } + else + { + error ("redeclaration of %q+D with no linkage", newdecl); + locate_old_decl (olddecl); + } + + return false; + } + + /* C++ does not permit a decl to appear multiple times at file + scope. */ + if (warn_cxx_compat + && DECL_FILE_SCOPE_P (newdecl) + && !DECL_EXTERNAL (newdecl) + && !DECL_EXTERNAL (olddecl)) + warned |= warning_at (DECL_SOURCE_LOCATION (newdecl), + OPT_Wc___compat, + ("duplicate declaration of %qD is " + "invalid in C++"), + newdecl); } /* warnings */ @@ -1507,70 +2044,70 @@ && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) { warned |= warning (0, "redeclaration of %q+D with different visibility " - "(old visibility preserved)", newdecl); + "(old visibility preserved)", newdecl); } if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* Diagnose inline __attribute__ ((noinline)) which is silly. */ if (DECL_DECLARED_INLINE_P (newdecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) - { - warned |= warning (OPT_Wattributes, - "inline declaration of %qD follows " - "declaration with attribute noinline", newdecl); - } + && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) + { + warned |= warning (OPT_Wattributes, + "inline declaration of %qD follows " + "declaration with attribute noinline", newdecl); + } else if (DECL_DECLARED_INLINE_P (olddecl) - && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) - { - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "noinline follows inline declaration ", newdecl); - } + && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) + { + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute " + "noinline follows inline declaration ", newdecl); + } } else /* PARM_DECL, VAR_DECL */ { /* Redeclaration of a parameter is a constraint violation (this is - not explicitly stated, but follows from C99 6.7p3 [no more than - one declaration of the same identifier with no linkage in the - same scope, except type tags] and 6.2.2p6 [parameters have no - linkage]). We must check for a forward parameter declaration, - indicated by TREE_ASM_WRITTEN on the old declaration - this is - an extension, the mandatory diagnostic for which is handled by - mark_forward_parm_decls. */ + not explicitly stated, but follows from C99 6.7p3 [no more than + one declaration of the same identifier with no linkage in the + same scope, except type tags] and 6.2.2p6 [parameters have no + linkage]). We must check for a forward parameter declaration, + indicated by TREE_ASM_WRITTEN on the old declaration - this is + an extension, the mandatory diagnostic for which is handled by + mark_forward_parm_decls. */ if (TREE_CODE (newdecl) == PARM_DECL - && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) - { - error ("redefinition of parameter %q+D", newdecl); - locate_old_decl (olddecl); - return false; - } + && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) + { + error ("redefinition of parameter %q+D", newdecl); + locate_old_decl (olddecl); + return false; + } } /* Optional warning for completely redundant decls. */ if (!warned && !pedwarned && warn_redundant_decls /* Don't warn about a function declaration followed by a - definition. */ + definition. */ && !(TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) /* Don't warn about redundant redeclarations of builtins. */ && !(TREE_CODE (newdecl) == FUNCTION_DECL - && !DECL_BUILT_IN (newdecl) - && DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl)) + && !DECL_BUILT_IN (newdecl) + && DECL_BUILT_IN (olddecl) + && !C_DECL_DECLARED_BUILTIN (olddecl)) /* Don't warn about an extern followed by a definition. */ && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) /* Don't warn about forward parameter decls. */ && !(TREE_CODE (newdecl) == PARM_DECL - && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) + && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) /* Don't warn about a variable definition following a declaration. */ && !(TREE_CODE (newdecl) == VAR_DECL - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) { warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D", - newdecl); + newdecl); } /* Report location of previous decl/defn. */ @@ -1591,11 +2128,11 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) { bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) != 0); + && DECL_INITIAL (newdecl) != 0); bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL - && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0); + && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0); bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL - && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0); + && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0); bool extern_changed = false; /* For real parm decl following a forward decl, rechain the old decl @@ -1607,8 +2144,8 @@ struct c_binding *b, **here; for (here = ¤t_scope->bindings; *here; here = &(*here)->prev) - if ((*here)->decl == olddecl) - goto found; + if ((*here)->decl == olddecl) + goto found; gcc_unreachable (); found: @@ -1632,11 +2169,11 @@ if (!comptypes (oldtype, TREE_TYPE (newdecl))) { if (TREE_TYPE (newdecl) != error_mark_node) - layout_type (TREE_TYPE (newdecl)); + layout_type (TREE_TYPE (newdecl)); if (TREE_CODE (newdecl) != FUNCTION_DECL - && TREE_CODE (newdecl) != TYPE_DECL - && TREE_CODE (newdecl) != CONST_DECL) - layout_decl (newdecl, 0); + && TREE_CODE (newdecl) != TYPE_DECL + && TREE_CODE (newdecl) != CONST_DECL) + layout_decl (newdecl, 0); } else { @@ -1645,10 +2182,10 @@ DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl); DECL_MODE (newdecl) = DECL_MODE (olddecl); if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) - { - DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); - DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); - } + { + DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); + DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); + } } /* Keep the old rtl since we can safely use it. */ @@ -1675,12 +2212,12 @@ && !DECL_IN_SYSTEM_HEADER (newdecl) ) DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS) - && DECL_IN_SYSTEM_HEADER (newdecl) - && !DECL_IN_SYSTEM_HEADER (olddecl)) + && DECL_IN_SYSTEM_HEADER (newdecl) + && !DECL_IN_SYSTEM_HEADER (olddecl)) DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl); else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0) - || (old_is_prototype && !new_is_prototype - && !C_DECL_BUILTIN_PROTOTYPE (olddecl))) + || (old_is_prototype && !new_is_prototype + && !C_DECL_BUILTIN_PROTOTYPE (olddecl))) DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); /* Merge the initialization information. */ @@ -1697,52 +2234,52 @@ if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)) { /* Merge the section attribute. - We want to issue an error if the sections conflict but that - must be done later in decl_attributes since we are called - before attributes are assigned. */ + We want to issue an error if the sections conflict but that + must be done later in decl_attributes since we are called + before attributes are assigned. */ if (DECL_SECTION_NAME (newdecl) == NULL_TREE) - DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); + DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); /* Copy the assembler name. - Currently, it can only be defined in the prototype. */ + Currently, it can only be defined in the prototype. */ COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); /* Use visibility of whichever declaration had it specified */ if (DECL_VISIBILITY_SPECIFIED (olddecl)) - { - DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); - DECL_VISIBILITY_SPECIFIED (newdecl) = 1; - } + { + DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); + DECL_VISIBILITY_SPECIFIED (newdecl) = 1; + } if (TREE_CODE (newdecl) == FUNCTION_DECL) - { - DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); - DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); - DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); - DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) - |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); - TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); - DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); - DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); - TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); - DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); - DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl); - } + { + DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); + DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); + DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); + DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) + |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); + TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); + DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); + DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); + TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); + DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); + DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl); + } /* Merge the storage class information. */ merge_weak (newdecl, olddecl); /* For functions, static overrides non-static. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) - { - TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); - /* This is since we don't automatically - copy the attributes of NEWDECL into OLDDECL. */ - TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); - /* If this clears `static', clear it in the identifier too. */ - if (!TREE_PUBLIC (olddecl)) - TREE_PUBLIC (DECL_NAME (olddecl)) = 0; - } + { + TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); + /* This is since we don't automatically + copy the attributes of NEWDECL into OLDDECL. */ + TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); + /* If this clears `static', clear it in the identifier too. */ + if (!TREE_PUBLIC (olddecl)) + TREE_PUBLIC (DECL_NAME (olddecl)) = 0; + } } /* In c99, 'extern' declaration before (or after) 'inline' means this @@ -1751,10 +2288,10 @@ if (TREE_CODE (newdecl) == FUNCTION_DECL && !flag_gnu89_inline && (DECL_DECLARED_INLINE_P (newdecl) - || DECL_DECLARED_INLINE_P (olddecl)) + || DECL_DECLARED_INLINE_P (olddecl)) && (!DECL_DECLARED_INLINE_P (newdecl) - || !DECL_DECLARED_INLINE_P (olddecl) - || !DECL_EXTERNAL (olddecl)) + || !DECL_DECLARED_INLINE_P (olddecl) + || !DECL_EXTERNAL (olddecl)) && DECL_EXTERNAL (newdecl) && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl)) && !current_function_decl) @@ -1768,10 +2305,10 @@ /* An extern decl does not override previous storage class. */ TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); if (!DECL_EXTERNAL (newdecl)) - { - DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); - DECL_COMMON (newdecl) = DECL_COMMON (olddecl); - } + { + DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); + DECL_COMMON (newdecl) = DECL_COMMON (olddecl); + } } else { @@ -1782,93 +2319,100 @@ if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* If we're redefining a function previously defined as extern - inline, make sure we emit debug info for the inline before we - throw it away, in case it was inlined into a function that - hasn't been written out yet. */ + inline, make sure we emit debug info for the inline before we + throw it away, in case it was inlined into a function that + hasn't been written out yet. */ if (new_is_definition && DECL_INITIAL (olddecl)) - /* The new defn must not be inline. */ - DECL_UNINLINABLE (newdecl) = 1; + /* The new defn must not be inline. */ + DECL_UNINLINABLE (newdecl) = 1; else - { - /* If either decl says `inline', this fn is inline, unless - its definition was passed already. */ - if (DECL_DECLARED_INLINE_P (newdecl) - || DECL_DECLARED_INLINE_P (olddecl)) - DECL_DECLARED_INLINE_P (newdecl) = 1; - - DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) - = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); - - DECL_DISREGARD_INLINE_LIMITS (newdecl) - = DECL_DISREGARD_INLINE_LIMITS (olddecl) - = (DECL_DISREGARD_INLINE_LIMITS (newdecl) - || DECL_DISREGARD_INLINE_LIMITS (olddecl)); - } + { + /* If either decl says `inline', this fn is inline, unless + its definition was passed already. */ + if (DECL_DECLARED_INLINE_P (newdecl) + || DECL_DECLARED_INLINE_P (olddecl)) + DECL_DECLARED_INLINE_P (newdecl) = 1; + + DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) + = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); + + DECL_DISREGARD_INLINE_LIMITS (newdecl) + = DECL_DISREGARD_INLINE_LIMITS (olddecl) + = (DECL_DISREGARD_INLINE_LIMITS (newdecl) + || DECL_DISREGARD_INLINE_LIMITS (olddecl)); + } if (DECL_BUILT_IN (olddecl)) - { - /* If redeclaring a builtin function, it stays built in. - But it gets tagged as having been declared. */ - DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); - DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); - C_DECL_DECLARED_BUILTIN (newdecl) = 1; - if (new_is_prototype) - C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0; - else - C_DECL_BUILTIN_PROTOTYPE (newdecl) - = C_DECL_BUILTIN_PROTOTYPE (olddecl); - } + { + /* If redeclaring a builtin function, it stays built in. + But it gets tagged as having been declared. */ + DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); + DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); + C_DECL_DECLARED_BUILTIN (newdecl) = 1; + if (new_is_prototype) + C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0; + else + C_DECL_BUILTIN_PROTOTYPE (newdecl) + = C_DECL_BUILTIN_PROTOTYPE (olddecl); + } /* Preserve function specific target and optimization options */ if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl) - && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl)) - DECL_FUNCTION_SPECIFIC_TARGET (newdecl) - = DECL_FUNCTION_SPECIFIC_TARGET (olddecl); + && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl)) + DECL_FUNCTION_SPECIFIC_TARGET (newdecl) + = DECL_FUNCTION_SPECIFIC_TARGET (olddecl); if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl) - && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)) - DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) - = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); + && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)) + DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) + = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); /* Also preserve various other info from the definition. */ if (!new_is_definition) - { - DECL_RESULT (newdecl) = DECL_RESULT (olddecl); - DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); - DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); - DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); - gimple_set_body (newdecl, gimple_body (olddecl)); - DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); - - /* See if we've got a function to instantiate from. */ - if (DECL_SAVED_TREE (olddecl)) - DECL_ABSTRACT_ORIGIN (newdecl) - = DECL_ABSTRACT_ORIGIN (olddecl); - } - } - - extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); - - /* Merge the USED information. */ - if (TREE_USED (olddecl)) - TREE_USED (newdecl) = 1; - else if (TREE_USED (newdecl)) - TREE_USED (olddecl) = 1; + { + tree t; + DECL_RESULT (newdecl) = DECL_RESULT (olddecl); + DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); + DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); + DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); + gimple_set_body (newdecl, gimple_body (olddecl)); + DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl)); + for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t)) + DECL_CONTEXT (t) = newdecl; + + /* See if we've got a function to instantiate from. */ + if (DECL_SAVED_TREE (olddecl)) + DECL_ABSTRACT_ORIGIN (newdecl) + = DECL_ABSTRACT_ORIGIN (olddecl); + } + } + + extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); + + /* Merge the USED information. */ + if (TREE_USED (olddecl)) + TREE_USED (newdecl) = 1; + else if (TREE_USED (newdecl)) + TREE_USED (olddecl) = 1; /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. - But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */ + But preserve OLDDECL's DECL_UID, DECL_CONTEXT and + DECL_ARGUMENTS (if appropriate). */ { unsigned olddecl_uid = DECL_UID (olddecl); tree olddecl_context = DECL_CONTEXT (olddecl); + tree olddecl_arguments = NULL; + if (TREE_CODE (olddecl) == FUNCTION_DECL) + olddecl_arguments = DECL_ARGUMENTS (olddecl); memcpy ((char *) olddecl + sizeof (struct tree_common), - (char *) newdecl + sizeof (struct tree_common), - sizeof (struct tree_decl_common) - sizeof (struct tree_common)); + (char *) newdecl + sizeof (struct tree_common), + sizeof (struct tree_decl_common) - sizeof (struct tree_common)); switch (TREE_CODE (olddecl)) { case FUNCTION_DECL: - gimple_set_body (olddecl, gimple_body (newdecl)); - /* fall through */ + gimple_set_body (olddecl, gimple_body (newdecl)); + /* fall through */ case FIELD_DECL: case VAR_DECL: @@ -1877,19 +2421,21 @@ case RESULT_DECL: case CONST_DECL: case TYPE_DECL: - memcpy ((char *) olddecl + sizeof (struct tree_decl_common), - (char *) newdecl + sizeof (struct tree_decl_common), - tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); - break; + memcpy ((char *) olddecl + sizeof (struct tree_decl_common), + (char *) newdecl + sizeof (struct tree_decl_common), + tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); + break; default: - memcpy ((char *) olddecl + sizeof (struct tree_decl_common), - (char *) newdecl + sizeof (struct tree_decl_common), - sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); + memcpy ((char *) olddecl + sizeof (struct tree_decl_common), + (char *) newdecl + sizeof (struct tree_decl_common), + sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); } DECL_UID (olddecl) = olddecl_uid; DECL_CONTEXT (olddecl) = olddecl_context; + if (TREE_CODE (olddecl) == FUNCTION_DECL) + DECL_ARGUMENTS (olddecl) = olddecl_arguments; } /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl @@ -1897,8 +2443,8 @@ flags and attributes. */ if (DECL_RTL_SET_P (olddecl) && (TREE_CODE (olddecl) == FUNCTION_DECL - || (TREE_CODE (olddecl) == VAR_DECL - && TREE_STATIC (olddecl)))) + || (TREE_CODE (olddecl) == VAR_DECL + && TREE_STATIC (olddecl)))) make_decl_rtl (olddecl); /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL, @@ -1951,96 +2497,36 @@ for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) if (b->decl && b->decl != new_decl && !b->invisible) { - tree old_decl = b->decl; - - if (old_decl == error_mark_node) - { - warning (OPT_Wshadow, "declaration of %q+D shadows previous " - "non-variable", new_decl); - break; - } - else if (TREE_CODE (old_decl) == PARM_DECL) - warning (OPT_Wshadow, "declaration of %q+D shadows a parameter", - new_decl); - else if (DECL_FILE_SCOPE_P (old_decl)) - warning (OPT_Wshadow, "declaration of %q+D shadows a global " - "declaration", new_decl); - else if (TREE_CODE (old_decl) == FUNCTION_DECL - && DECL_BUILT_IN (old_decl)) - { - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", new_decl); - break; - } - else - warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", - new_decl); - - warning (OPT_Wshadow, "%Jshadowed declaration is here", old_decl); - - break; + tree old_decl = b->decl; + + if (old_decl == error_mark_node) + { + warning (OPT_Wshadow, "declaration of %q+D shadows previous " + "non-variable", new_decl); + break; } -} - - -/* Subroutine of pushdecl. - - X is a TYPE_DECL for a typedef statement. Create a brand new - ..._TYPE node (which will be just a variant of the existing - ..._TYPE node with identical properties) and then install X - as the TYPE_NAME of this brand new (duplicate) ..._TYPE node. - - The whole point here is to end up with a situation where each - and every ..._TYPE node the compiler creates will be uniquely - associated with AT MOST one node representing a typedef name. - This way, even though the compiler substitutes corresponding - ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very - early on, later parts of the compiler can always do the reverse - translation and get back the corresponding typedef name. For - example, given: - - typedef struct S MY_TYPE; - MY_TYPE object; - - Later parts of the compiler might only know that `object' was of - type `struct S' if it were not for code just below. With this - code however, later parts of the compiler see something like: - - struct S' == struct S - typedef struct S' MY_TYPE; - struct S' object; - - And they can then deduce (from the node for type struct S') that - the original object declaration was: - - MY_TYPE object; - - Being able to do this is important for proper support of protoize, - and also for generating precise symbolic debugging information - which takes full account of the programmer's (typedef) vocabulary. - - Obviously, we don't want to generate a duplicate ..._TYPE node if - the TYPE_DECL node that we are now processing really represents a - standard built-in type. */ - -static void -clone_underlying_type (tree x) -{ - if (DECL_IS_BUILTIN (x)) - { - if (TYPE_NAME (TREE_TYPE (x)) == 0) - TYPE_NAME (TREE_TYPE (x)) = x; - } - else if (TREE_TYPE (x) != error_mark_node - && DECL_ORIGINAL_TYPE (x) == NULL_TREE) - { - tree tt = TREE_TYPE (x); - DECL_ORIGINAL_TYPE (x) = tt; - tt = build_variant_type_copy (tt); - TYPE_NAME (tt) = x; - TREE_USED (tt) = TREE_USED (x); - TREE_TYPE (x) = tt; - } + else if (TREE_CODE (old_decl) == PARM_DECL) + warning (OPT_Wshadow, "declaration of %q+D shadows a parameter", + new_decl); + else if (DECL_FILE_SCOPE_P (old_decl)) + warning (OPT_Wshadow, "declaration of %q+D shadows a global " + "declaration", new_decl); + else if (TREE_CODE (old_decl) == FUNCTION_DECL + && DECL_BUILT_IN (old_decl)) + { + warning (OPT_Wshadow, "declaration of %q+D shadows " + "a built-in function", new_decl); + break; + } + else + warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", + new_decl); + + warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow, + "shadowed declaration is here"); + + break; + } } /* Record a decl-node X as belonging to the current lexical scope. @@ -2058,25 +2544,21 @@ struct c_scope *scope = current_scope; struct c_binding *b; bool nested = false; + location_t locus = DECL_SOURCE_LOCATION (x); /* Must set DECL_CONTEXT for everything not at file scope or DECL_FILE_SCOPE_P won't work. Local externs don't count unless they have initializers (which generate code). */ if (current_function_decl && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL) - || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) + || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) DECL_CONTEXT (x) = current_function_decl; - /* If this is of variably modified type, prevent jumping into its - scope. */ - if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL) - && variably_modified_type_p (TREE_TYPE (x), NULL_TREE)) - c_begin_vm_scope (scope->depth); - /* Anonymous decls are just inserted in the scope. */ if (!name) { - bind (name, x, scope, /*invisible=*/false, /*nested=*/false); + bind (name, x, scope, /*invisible=*/false, /*nested=*/false, + locus); return x; } @@ -2095,49 +2577,49 @@ tree visdecl = b->decl; tree vistype = TREE_TYPE (visdecl); if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE - && COMPLETE_TYPE_P (TREE_TYPE (x))) - b->inner_comp = false; + && COMPLETE_TYPE_P (TREE_TYPE (x))) + b->inner_comp = false; b_use = b; b_ext = b; /* If this is an external linkage declaration, we should check - for compatibility with the type in the external scope before - setting the type at this scope based on the visible - information only. */ + for compatibility with the type in the external scope before + setting the type at this scope based on the visible + information only. */ if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl)) - { - while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) - b_ext = b_ext->shadowed; - if (b_ext) - { - b_use = b_ext; - if (b_use->type) - TREE_TYPE (b_use->decl) = b_use->type; - } - } + { + while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) + b_ext = b_ext->shadowed; + if (b_ext) + { + b_use = b_ext; + if (b_use->u.type) + TREE_TYPE (b_use->decl) = b_use->u.type; + } + } if (duplicate_decls (x, b_use->decl)) - { - if (b_use != b) - { - /* Save the updated type in the external scope and - restore the proper type for this scope. */ - tree thistype; - if (comptypes (vistype, type)) - thistype = composite_type (vistype, type); - else - thistype = TREE_TYPE (b_use->decl); - b_use->type = TREE_TYPE (b_use->decl); - if (TREE_CODE (b_use->decl) == FUNCTION_DECL - && DECL_BUILT_IN (b_use->decl)) - thistype - = build_type_attribute_variant (thistype, - TYPE_ATTRIBUTES - (b_use->type)); - TREE_TYPE (b_use->decl) = thistype; - } - return b_use->decl; - } + { + if (b_use != b) + { + /* Save the updated type in the external scope and + restore the proper type for this scope. */ + tree thistype; + if (comptypes (vistype, type)) + thistype = composite_type (vistype, type); + else + thistype = TREE_TYPE (b_use->decl); + b_use->u.type = TREE_TYPE (b_use->decl); + if (TREE_CODE (b_use->decl) == FUNCTION_DECL + && DECL_BUILT_IN (b_use->decl)) + thistype + = build_type_attribute_variant (thistype, + TYPE_ATTRIBUTES + (b_use->u.type)); + TREE_TYPE (b_use->decl) = thistype; + } + return b_use->decl; + } else - goto skip_external_and_shadow_checks; + goto skip_external_and_shadow_checks; } /* All declarations with external linkage, and all external @@ -2159,105 +2641,106 @@ tree visdecl = 0; bool type_saved = false; if (b && !B_IN_EXTERNAL_SCOPE (b) - && (TREE_CODE (b->decl) == FUNCTION_DECL - || TREE_CODE (b->decl) == VAR_DECL) - && DECL_FILE_SCOPE_P (b->decl)) - { - visdecl = b->decl; - vistype = TREE_TYPE (visdecl); - } + && (TREE_CODE (b->decl) == FUNCTION_DECL + || TREE_CODE (b->decl) == VAR_DECL) + && DECL_FILE_SCOPE_P (b->decl)) + { + visdecl = b->decl; + vistype = TREE_TYPE (visdecl); + } if (scope != file_scope - && !DECL_IN_SYSTEM_HEADER (x)) - warning (OPT_Wnested_externs, "nested extern declaration of %qD", x); + && !DECL_IN_SYSTEM_HEADER (x)) + warning (OPT_Wnested_externs, "nested extern declaration of %qD", x); while (b && !B_IN_EXTERNAL_SCOPE (b)) - { - /* If this decl might be modified, save its type. This is - done here rather than when the decl is first bound - because the type may change after first binding, through - being completed or through attributes being added. If we - encounter multiple such decls, only the first should have - its type saved; the others will already have had their - proper types saved and the types will not have changed as - their scopes will not have been re-entered. */ - if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) - { - b->type = TREE_TYPE (b->decl); - type_saved = true; - } - if (B_IN_FILE_SCOPE (b) - && TREE_CODE (b->decl) == VAR_DECL - && TREE_STATIC (b->decl) - && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE - && !TYPE_DOMAIN (TREE_TYPE (b->decl)) - && TREE_CODE (type) == ARRAY_TYPE - && TYPE_DOMAIN (type) - && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) - && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) - { - /* Array type completed in inner scope, which should be - diagnosed if the completion does not have size 1 and - it does not get completed in the file scope. */ - b->inner_comp = true; - } - b = b->shadowed; - } + { + /* If this decl might be modified, save its type. This is + done here rather than when the decl is first bound + because the type may change after first binding, through + being completed or through attributes being added. If we + encounter multiple such decls, only the first should have + its type saved; the others will already have had their + proper types saved and the types will not have changed as + their scopes will not have been re-entered. */ + if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) + { + b->u.type = TREE_TYPE (b->decl); + type_saved = true; + } + if (B_IN_FILE_SCOPE (b) + && TREE_CODE (b->decl) == VAR_DECL + && TREE_STATIC (b->decl) + && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE + && !TYPE_DOMAIN (TREE_TYPE (b->decl)) + && TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) + && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) + && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) + { + /* Array type completed in inner scope, which should be + diagnosed if the completion does not have size 1 and + it does not get completed in the file scope. */ + b->inner_comp = true; + } + b = b->shadowed; + } /* If a matching external declaration has been found, set its - type to the composite of all the types of that declaration. - After the consistency checks, it will be reset to the - composite of the visible types only. */ + type to the composite of all the types of that declaration. + After the consistency checks, it will be reset to the + composite of the visible types only. */ if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && b->type) - TREE_TYPE (b->decl) = b->type; + && b->u.type) + TREE_TYPE (b->decl) = b->u.type; /* The point of the same_translation_unit_p check here is, - we want to detect a duplicate decl for a construct like - foo() { extern bar(); } ... static bar(); but not if - they are in different translation units. In any case, - the static does not go in the externals scope. */ + we want to detect a duplicate decl for a construct like + foo() { extern bar(); } ... static bar(); but not if + they are in different translation units. In any case, + the static does not go in the externals scope. */ if (b - && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && duplicate_decls (x, b->decl)) - { - tree thistype; - if (vistype) - { - if (comptypes (vistype, type)) - thistype = composite_type (vistype, type); - else - thistype = TREE_TYPE (b->decl); - } - else - thistype = type; - b->type = TREE_TYPE (b->decl); - if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) - thistype - = build_type_attribute_variant (thistype, - TYPE_ATTRIBUTES (b->type)); - TREE_TYPE (b->decl) = thistype; - bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true); - return b->decl; - } + && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) + && duplicate_decls (x, b->decl)) + { + tree thistype; + if (vistype) + { + if (comptypes (vistype, type)) + thistype = composite_type (vistype, type); + else + thistype = TREE_TYPE (b->decl); + } + else + thistype = type; + b->u.type = TREE_TYPE (b->decl); + if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) + thistype + = build_type_attribute_variant (thistype, + TYPE_ATTRIBUTES (b->u.type)); + TREE_TYPE (b->decl) = thistype; + bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, + locus); + return b->decl; + } else if (TREE_PUBLIC (x)) - { - if (visdecl && !b && duplicate_decls (x, visdecl)) - { - /* An external declaration at block scope referring to a - visible entity with internal linkage. The composite - type will already be correct for this scope, so we - just need to fall through to make the declaration in - this scope. */ - nested = true; - x = visdecl; - } - else - { - bind (name, x, external_scope, /*invisible=*/true, - /*nested=*/false); - nested = true; - } - } + { + if (visdecl && !b && duplicate_decls (x, visdecl)) + { + /* An external declaration at block scope referring to a + visible entity with internal linkage. The composite + type will already be correct for this scope, so we + just need to fall through to make the declaration in + this scope. */ + nested = true; + x = visdecl; + } + else + { + bind (name, x, external_scope, /*invisible=*/true, + /*nested=*/false, locus); + nested = true; + } + } } if (TREE_CODE (x) != PARM_DECL) @@ -2265,9 +2748,9 @@ skip_external_and_shadow_checks: if (TREE_CODE (x) == TYPE_DECL) - clone_underlying_type (x); - - bind (name, x, scope, /*invisible=*/false, nested); + set_underlying_type (x); + + bind (name, x, scope, /*invisible=*/false, nested, locus); /* If x's type is incomplete because it's based on a structure or union which has not yet been fully declared, @@ -2284,16 +2767,16 @@ tree element = TREE_TYPE (x); while (TREE_CODE (element) == ARRAY_TYPE) - element = TREE_TYPE (element); + element = TREE_TYPE (element); element = TYPE_MAIN_VARIANT (element); if ((TREE_CODE (element) == RECORD_TYPE - || TREE_CODE (element) == UNION_TYPE) - && (TREE_CODE (x) != TYPE_DECL - || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) - && !COMPLETE_TYPE_P (element)) - C_TYPE_INCOMPLETE_VARS (element) - = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element)); + || TREE_CODE (element) == UNION_TYPE) + && (TREE_CODE (x) != TYPE_DECL + || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) + && !COMPLETE_TYPE_P (element)) + C_TYPE_INCOMPLETE_VARS (element) + = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element)); } return x; } @@ -2316,11 +2799,12 @@ if (TREE_PUBLIC (x)) { - bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false); + bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false, + UNKNOWN_LOCATION); nested = true; } if (file_scope) - bind (name, x, file_scope, /*invisible=*/false, nested); + bind (name, x, file_scope, /*invisible=*/false, nested, UNKNOWN_LOCATION); return x; } @@ -2333,25 +2817,25 @@ bool warned; if (flag_isoc99) - warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, - "implicit declaration of function %qE", id); - else - warned = warning (OPT_Wimplicit_function_declaration, - G_("implicit declaration of function %qE"), id); + warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, + "implicit declaration of function %qE", id); + else + warned = warning (OPT_Wimplicit_function_declaration, + G_("implicit declaration of function %qE"), id); if (olddecl && warned) - locate_old_decl (olddecl); - } -} - -/* Generate an implicit declaration for identifier FUNCTIONID as a + locate_old_decl (olddecl); + } +} + +/* Generate an implicit declaration for identifier FUNCTIONID at LOC as a function of type int (). */ #ifndef noCbC tree -implicitly_declare (tree functionid, int fun) +implicitly_declare (location_t loc, tree functionid, int fun) #else tree -implicitly_declare (tree functionid) +implicitly_declare (location_t loc, tree functionid) #endif { struct c_binding *b; @@ -2361,77 +2845,78 @@ for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed) { if (B_IN_SCOPE (b, external_scope)) - { - decl = b->decl; - break; - } + { + decl = b->decl; + break; + } } if (decl) { if (decl == error_mark_node) - return decl; + return decl; /* FIXME: Objective-C has weird not-really-builtin functions - which are supposed to be visible automatically. They wind up - in the external scope because they're pushed before the file - scope gets created. Catch this here and rebind them into the - file scope. */ + which are supposed to be visible automatically. They wind up + in the external scope because they're pushed before the file + scope gets created. Catch this here and rebind them into the + file scope. */ if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) - { - bind (functionid, decl, file_scope, - /*invisible=*/false, /*nested=*/true); - return decl; - } + { + bind (functionid, decl, file_scope, + /*invisible=*/false, /*nested=*/true, + DECL_SOURCE_LOCATION (decl)); + return decl; + } else - { - tree newtype = default_function_type; - if (b->type) - TREE_TYPE (decl) = b->type; - /* Implicit declaration of a function already declared - (somehow) in a different scope, or as a built-in. - If this is the first time this has happened, warn; - then recycle the old declaration but with the new type. */ - if (!C_DECL_IMPLICIT (decl)) - { - implicit_decl_warning (functionid, decl); - C_DECL_IMPLICIT (decl) = 1; - } - if (DECL_BUILT_IN (decl)) - { - newtype = build_type_attribute_variant (newtype, - TYPE_ATTRIBUTES - (TREE_TYPE (decl))); - if (!comptypes (newtype, TREE_TYPE (decl))) - { - warning (0, "incompatible implicit declaration of built-in" - " function %qD", decl); - newtype = TREE_TYPE (decl); - } - } - else - { - if (!comptypes (newtype, TREE_TYPE (decl))) - { - error ("incompatible implicit declaration of function %qD", - decl); - locate_old_decl (decl); - } - } - b->type = TREE_TYPE (decl); - TREE_TYPE (decl) = newtype; - bind (functionid, decl, current_scope, - /*invisible=*/false, /*nested=*/true); - return decl; - } + { + tree newtype = default_function_type; + if (b->u.type) + TREE_TYPE (decl) = b->u.type; + /* Implicit declaration of a function already declared + (somehow) in a different scope, or as a built-in. + If this is the first time this has happened, warn; + then recycle the old declaration but with the new type. */ + if (!C_DECL_IMPLICIT (decl)) + { + implicit_decl_warning (functionid, decl); + C_DECL_IMPLICIT (decl) = 1; + } + if (DECL_BUILT_IN (decl)) + { + newtype = build_type_attribute_variant (newtype, + TYPE_ATTRIBUTES + (TREE_TYPE (decl))); + if (!comptypes (newtype, TREE_TYPE (decl))) + { + warning_at (loc, 0, "incompatible implicit declaration of " + "built-in function %qD", decl); + newtype = TREE_TYPE (decl); + } + } + else + { + if (!comptypes (newtype, TREE_TYPE (decl))) + { + error_at (loc, "incompatible implicit declaration of function %qD", decl); + locate_old_decl (decl); + } + } + b->u.type = TREE_TYPE (decl); + TREE_TYPE (decl) = newtype; + bind (functionid, decl, current_scope, + /*invisible=*/false, /*nested=*/true, + DECL_SOURCE_LOCATION (decl)); + return decl; + } } /* Not seen before. */ #ifndef noCbC - decl = build_decl (FUNCTION_DECL, functionid, + decl = build_decl (loc, FUNCTION_DECL, functionid, fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type); #else - decl = build_decl (FUNCTION_DECL, functionid, default_function_type); + decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type); #endif DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; @@ -2464,45 +2949,55 @@ in an appropriate scope, which will suppress further errors for the same identifier. The error message should be given location LOC. */ void -undeclared_variable (tree id, location_t loc) +undeclared_variable (location_t loc, tree id) { static bool already = false; struct c_scope *scope; if (current_function_decl == 0) { - error ("%H%qE undeclared here (not in a function)", &loc, id); + error_at (loc, "%qE undeclared here (not in a function)", id); scope = current_scope; } else { - error ("%H%qE undeclared (first use in this function)", &loc, id); + error_at (loc, "%qE undeclared (first use in this function)", id); if (!already) - { - error ("%H(Each undeclared identifier is reported only once", &loc); - error ("%Hfor each function it appears in.)", &loc); - already = true; - } + { + error_at (loc, "(Each undeclared identifier is reported only once"); + error_at (loc, "for each function it appears in.)"); + already = true; + } /* If we are parsing old-style parameter decls, current_function_decl - will be nonnull but current_function_scope will be null. */ + will be nonnull but current_function_scope will be null. */ scope = current_function_scope ? current_function_scope : current_scope; } - bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false); + bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false, + UNKNOWN_LOCATION); } /* Subroutine of lookup_label, declare_label, define_label: construct a - LABEL_DECL with all the proper frills. */ + LABEL_DECL with all the proper frills. Also create a struct + c_label_vars initialized for the current scope. */ static tree -make_label (tree name, location_t location) -{ - tree label = build_decl (LABEL_DECL, name, void_type_node); +make_label (location_t location, tree name, bool defining, + struct c_label_vars **p_label_vars) +{ + tree label = build_decl (location, LABEL_DECL, name, void_type_node); + struct c_label_vars *label_vars; DECL_CONTEXT (label) = current_function_decl; DECL_MODE (label) = VOIDmode; - DECL_SOURCE_LOCATION (label) = location; + + label_vars = GGC_NEW (struct c_label_vars); + label_vars->shadowed = NULL; + set_spot_bindings (&label_vars->label_bindings, defining); + label_vars->decls_in_scope = make_tree_vector (); + label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0); + *p_label_vars = label_vars; return label; } @@ -2516,6 +3011,7 @@ lookup_label (tree name) { tree label; + struct c_label_vars *label_vars; if (current_function_decl == 0) { @@ -2528,22 +3024,96 @@ using __label__. */ label = I_LABEL_DECL (name); if (label && (DECL_CONTEXT (label) == current_function_decl - || C_DECLARED_LABEL_FLAG (label))) + || C_DECLARED_LABEL_FLAG (label))) { /* If the label has only been declared, update its apparent - location to point here, for better diagnostics if it - turns out not to have been defined. */ - if (!TREE_USED (label)) - DECL_SOURCE_LOCATION (label) = input_location; + location to point here, for better diagnostics if it + turns out not to have been defined. */ + if (DECL_INITIAL (label) == NULL_TREE) + DECL_SOURCE_LOCATION (label) = input_location; return label; } /* No label binding for that identifier; make one. */ - label = make_label (name, input_location); + label = make_label (input_location, name, false, &label_vars); /* Ordinary labels go in the current function scope. */ - bind (name, label, current_function_scope, - /*invisible=*/false, /*nested=*/false); + bind_label (name, label, current_function_scope, label_vars); + + return label; +} + +/* Issue a warning about DECL for a goto statement at GOTO_LOC going + to LABEL. */ + +static void +warn_about_goto (location_t goto_loc, tree label, tree decl) +{ + if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) + error_at (goto_loc, + "jump into scope of identifier with variably modified type"); + else + warning_at (goto_loc, OPT_Wjump_misses_init, + "jump skips variable initialization"); + inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label); + inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl); +} + +/* Look up a label because of a goto statement. This is like + lookup_label, but also issues any appropriate warnings. */ + +tree +lookup_label_for_goto (location_t loc, tree name) +{ + tree label; + struct c_label_vars *label_vars; + unsigned int ix; + tree decl; + + label = lookup_label (name); + if (label == NULL_TREE) + return NULL_TREE; + + /* If we are jumping to a different function, we can't issue any + useful warnings. */ + if (DECL_CONTEXT (label) != current_function_decl) + { + gcc_assert (C_DECLARED_LABEL_FLAG (label)); + return label; + } + + label_vars = I_LABEL_BINDING (name)->u.label; + + /* If the label has not yet been defined, then push this goto on a + list for possible later warnings. */ + if (label_vars->label_bindings.scope == NULL) + { + struct c_goto_bindings *g; + + g = GGC_NEW (struct c_goto_bindings); + g->loc = loc; + set_spot_bindings (&g->goto_bindings, true); + VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g); + return label; + } + + /* If there are any decls in label_vars->decls_in_scope, then this + goto has missed the declaration of the decl. This happens for a + case like + int i = 1; + lab: + ... + goto lab; + Issue a warning or error. */ + for (ix = 0; VEC_iterate (tree, label_vars->decls_in_scope, ix, decl); ++ix) + warn_about_goto (loc, label, decl); + + if (label_vars->label_bindings.left_stmt_expr) + { + error_at (loc, "jump into statement expression"); + inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label); + } + return label; } @@ -2556,6 +3126,7 @@ { struct c_binding *b = I_LABEL_BINDING (name); tree label; + struct c_label_vars *label_vars; /* Check to make sure that the label hasn't already been declared at this scope */ @@ -2568,15 +3139,74 @@ return b->decl; } - label = make_label (name, input_location); + label = make_label (input_location, name, false, &label_vars); C_DECLARED_LABEL_FLAG (label) = 1; /* Declared labels go in the current scope. */ - bind (name, label, current_scope, - /*invisible=*/false, /*nested=*/false); + bind_label (name, label, current_scope, label_vars); + return label; } +/* When we define a label, issue any appropriate warnings if there are + any gotos earlier in the function which jump to this label. */ + +static void +check_earlier_gotos (tree label, struct c_label_vars* label_vars) +{ + unsigned int ix; + struct c_goto_bindings *g; + + for (ix = 0; + VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); + ++ix) + { + struct c_binding *b; + struct c_scope *scope; + + /* We have a goto to this label. The goto is going forward. In + g->scope, the goto is going to skip any binding which was + defined after g->bindings_in_scope. */ + for (b = g->goto_bindings.scope->bindings; + b != g->goto_bindings.bindings_in_scope; + b = b->prev) + { + if (decl_jump_unsafe (b->decl)) + warn_about_goto (g->loc, label, b->decl); + } + + /* We also need to warn about decls defined in any scopes + between the scope of the label and the scope of the goto. */ + for (scope = label_vars->label_bindings.scope; + scope != g->goto_bindings.scope; + scope = scope->outer) + { + gcc_assert (scope != NULL); + if (scope == label_vars->label_bindings.scope) + b = label_vars->label_bindings.bindings_in_scope; + else + b = scope->bindings; + for (; b != NULL; b = b->prev) + { + if (decl_jump_unsafe (b->decl)) + warn_about_goto (g->loc, label, b->decl); + } + } + + if (g->goto_bindings.stmt_exprs > 0) + { + error_at (g->loc, "jump into statement expression"); + inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", + label); + } + } + + /* Now that the label is defined, we will issue warnings about + subsequent gotos to this label when we see them. */ + VEC_truncate (c_goto_bindings_p, label_vars->gotos, 0); + label_vars->gotos = NULL; +} + /* Define a label, specifying the location in the source file. Return the LABEL_DECL node for the label, if the definition is valid. Otherwise return 0. */ @@ -2589,68 +3219,135 @@ if there is a containing function with a declared label with the same name. */ tree label = I_LABEL_DECL (name); - struct c_label_list *nlist_se, *nlist_vm; if (label && ((DECL_CONTEXT (label) == current_function_decl - && DECL_INITIAL (label) != 0) - || (DECL_CONTEXT (label) != current_function_decl - && C_DECLARED_LABEL_FLAG (label)))) - { - error ("%Hduplicate label %qD", &location, label); + && DECL_INITIAL (label) != 0) + || (DECL_CONTEXT (label) != current_function_decl + && C_DECLARED_LABEL_FLAG (label)))) + { + error_at (location, "duplicate label %qD", label); locate_old_decl (label); return 0; } else if (label && DECL_CONTEXT (label) == current_function_decl) { + struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label; + /* The label has been used or declared already in this function, - but not defined. Update its location to point to this - definition. */ - if (C_DECL_UNDEFINABLE_STMT_EXPR (label)) - error ("%Jjump into statement expression", label); - if (C_DECL_UNDEFINABLE_VM (label)) - error ("%Jjump into scope of identifier with variably modified type", - label); + but not defined. Update its location to point to this + definition. */ DECL_SOURCE_LOCATION (label) = location; + set_spot_bindings (&label_vars->label_bindings, true); + + /* Issue warnings as required about any goto statements from + earlier in the function. */ + check_earlier_gotos (label, label_vars); } else { + struct c_label_vars *label_vars; + /* No label binding for that identifier; make one. */ - label = make_label (name, location); + label = make_label (location, name, true, &label_vars); /* Ordinary labels go in the current function scope. */ - bind (name, label, current_function_scope, - /*invisible=*/false, /*nested=*/false); + bind_label (name, label, current_function_scope, label_vars); } if (!in_system_header && lookup_name (name)) - warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace " - "for labels, identifier %qE conflicts", &location, name); - - nlist_se = XOBNEW (&parser_obstack, struct c_label_list); - nlist_se->next = label_context_stack_se->labels_def; - nlist_se->label = label; - label_context_stack_se->labels_def = nlist_se; - - nlist_vm = XOBNEW (&parser_obstack, struct c_label_list); - nlist_vm->next = label_context_stack_vm->labels_def; - nlist_vm->label = label; - label_context_stack_vm->labels_def = nlist_vm; + warning_at (location, OPT_Wtraditional, + "traditional C lacks a separate namespace " + "for labels, identifier %qE conflicts", name); /* Mark label as having been defined. */ DECL_INITIAL (label) = error_mark_node; return label; } +/* Get the bindings for a new switch statement. This is used to issue + warnings as appropriate for jumps from the switch to case or + default labels. */ + +struct c_spot_bindings * +c_get_switch_bindings (void) +{ + struct c_spot_bindings *switch_bindings; + + switch_bindings = XNEW (struct c_spot_bindings); + set_spot_bindings (switch_bindings, true); + return switch_bindings; +} + +void +c_release_switch_bindings (struct c_spot_bindings *bindings) +{ + gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr); + XDELETE (bindings); +} + +/* This is called at the point of a case or default label to issue + warnings about decls as needed. It returns true if it found an + error, not just a warning. */ + +bool +c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings, + location_t switch_loc, location_t case_loc) +{ + bool saw_error; + struct c_scope *scope; + + saw_error = false; + for (scope = current_scope; + scope != switch_bindings->scope; + scope = scope->outer) + { + struct c_binding *b; + + gcc_assert (scope != NULL); + for (b = scope->bindings; b != NULL; b = b->prev) + { + if (decl_jump_unsafe (b->decl)) + { + if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) + { + saw_error = true; + error_at (case_loc, + ("switch jumps into scope of identifier with " + "variably modified type")); + } + else + warning_at (case_loc, OPT_Wjump_misses_init, + "switch jumps over variable initialization"); + inform (switch_loc, "switch starts here"); + inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here", + b->decl); + } + } + } + + if (switch_bindings->stmt_exprs > 0) + { + saw_error = true; + error_at (case_loc, "switch jumps into statement expression"); + inform (switch_loc, "switch starts here"); + } + + return saw_error; +} + /* Given NAME, an IDENTIFIER_NODE, return the structure (or union or enum) definition for that name. If THISLEVEL_ONLY is nonzero, searches only the current_scope. CODE says which kind of type the caller wants; it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. + If PLOC is not NULL and this returns non-null, it sets *PLOC to the + location where the tag was defined. If the wrong kind of type is found, an error is reported. */ static tree -lookup_tag (enum tree_code code, tree name, int thislevel_only) +lookup_tag (enum tree_code code, tree name, int thislevel_only, + location_t *ploc) { struct c_binding *b = I_TAG_BINDING (name); int thislevel = 0; @@ -2663,12 +3360,12 @@ if (thislevel_only || TREE_CODE (b->decl) != code) { /* For our purposes, a tag in the external scope is the same as - a tag in the file scope. (Primarily relevant to Objective-C - and its builtin structure tags, which get pushed before the - file scope is created.) */ + a tag in the file scope. (Primarily relevant to Objective-C + and its builtin structure tags, which get pushed before the + file scope is created.) */ if (B_IN_CURRENT_SCOPE (b) - || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) - thislevel = 1; + || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) + thislevel = 1; } if (thislevel_only && !thislevel) @@ -2681,12 +3378,16 @@ pending_invalid_xref_location = input_location; /* If in the same binding level as a declaration as a tag - of a different type, this must not be allowed to - shadow that tag, so give the error immediately. - (For example, "struct foo; union foo;" is invalid.) */ + of a different type, this must not be allowed to + shadow that tag, so give the error immediately. + (For example, "struct foo; union foo;" is invalid.) */ if (thislevel) - pending_xref_error (); - } + pending_xref_error (); + } + + if (ploc != NULL) + *ploc = b->locus; + return b->decl; } @@ -2699,8 +3400,8 @@ pending_xref_error (void) { if (pending_invalid_xref != 0) - error ("%H%qE defined as wrong kind of tag", - &pending_invalid_xref_location, pending_invalid_xref); + error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag", + pending_invalid_xref); pending_invalid_xref = 0; } @@ -2768,8 +3469,8 @@ truthvalue_false_node = integer_zero_node; /* Even in C99, which has a real boolean type. */ - pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), - boolean_type_node)); + pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"), + boolean_type_node)); input_location = save_loc; @@ -2779,25 +3480,26 @@ start_fname_decls (); } -/* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the - decl, NAME is the initialization string and TYPE_DEP indicates whether - NAME depended on the type of the function. As we don't yet implement - delayed emission of static data, we mark the decl as emitted - so it is not placed in the output. Anything using it must therefore pull - out the STRING_CST initializer directly. FIXME. */ +/* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to + give the decl, NAME is the initialization string and TYPE_DEP + indicates whether NAME depended on the type of the function. As we + don't yet implement delayed emission of static data, we mark the + decl as emitted so it is not placed in the output. Anything using + it must therefore pull out the STRING_CST initializer directly. + FIXME. */ static tree -c_make_fname_decl (tree id, int type_dep) +c_make_fname_decl (location_t loc, tree id, int type_dep) { const char *name = fname_as_string (type_dep); tree decl, type, init; size_t length = strlen (name); type = build_array_type (char_type_node, - build_index_type (size_int (length))); + build_index_type (size_int (length))); type = c_build_qualified_type (type, TYPE_QUAL_CONST); - decl = build_decl (VAR_DECL, id, type); + decl = build_decl (loc, VAR_DECL, id, type); TREE_STATIC (decl) = 1; TREE_READONLY (decl) = 1; @@ -2812,21 +3514,21 @@ if (current_function_decl /* For invalid programs like this: - + void foo() const char* p = __FUNCTION__; - - the __FUNCTION__ is believed to appear in K&R style function - parameter declarator. In that case we still don't have - function_scope. */ + + the __FUNCTION__ is believed to appear in K&R style function + parameter declarator. In that case we still don't have + function_scope. */ && (!errorcount || current_function_scope)) { DECL_CONTEXT (decl) = current_function_decl; bind (id, decl, current_function_scope, - /*invisible=*/false, /*nested=*/false); - } - - finish_decl (decl, init, NULL_TREE); + /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); + } + + finish_decl (decl, loc, init, NULL_TREE, NULL_TREE); return decl; } @@ -2843,7 +3545,8 @@ /* Should never be called on a symbol with a preexisting meaning. */ gcc_assert (!I_SYMBOL_BINDING (id)); - bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false); + bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, + UNKNOWN_LOCATION); /* Builtins in the implementation namespace are made visible without needing to be explicitly declared. See push_file_scope. */ @@ -2868,7 +3571,8 @@ /* Should never be called on a symbol with a preexisting meaning. */ gcc_assert (!I_SYMBOL_BINDING (id)); - bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false); + bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, + UNKNOWN_LOCATION); /* Builtins in the implementation namespace are made visible without needing to be explicitly declared. See push_file_scope. */ @@ -2908,67 +3612,74 @@ enum tree_code code = TREE_CODE (value); if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) - /* Used to test also that TYPE_SIZE (value) != 0. - That caused warning for `struct foo;' at top level in the file. */ - { - tree name = TYPE_NAME (value); - tree t; - - found_tag = true; - - if (name == 0) - { - if (warned != 1 && code != ENUMERAL_TYPE) - /* Empty unnamed enum OK */ - { - pedwarn (input_location, 0, - "unnamed struct/union that defines no instances"); - warned = 1; - } - } - else if (!declspecs->tag_defined_p - && declspecs->storage_class != csc_none) - { - if (warned != 1) - pedwarn (input_location, 0, - "empty declaration with storage class specifier " - "does not redeclare tag"); - warned = 1; - pending_xref_error (); - } - else if (!declspecs->tag_defined_p - && (declspecs->const_p - || declspecs->volatile_p - || declspecs->restrict_p)) - { - if (warned != 1) - pedwarn (input_location, 0, - "empty declaration with type qualifier " - "does not redeclare tag"); - warned = 1; - pending_xref_error (); - } - else - { - pending_invalid_xref = 0; - t = lookup_tag (code, name, 1); - - if (t == 0) - { - t = make_node (code); - pushtag (name, t); - } - } - } + /* Used to test also that TYPE_SIZE (value) != 0. + That caused warning for `struct foo;' at top level in the file. */ + { + tree name = TYPE_NAME (value); + tree t; + + found_tag = true; + + if (declspecs->restrict_p) + { + error ("invalid use of %<restrict%>"); + warned = 1; + } + + if (name == 0) + { + if (warned != 1 && code != ENUMERAL_TYPE) + /* Empty unnamed enum OK */ + { + pedwarn (input_location, 0, + "unnamed struct/union that defines no instances"); + warned = 1; + } + } + else if (!declspecs->tag_defined_p + && declspecs->storage_class != csc_none) + { + if (warned != 1) + pedwarn (input_location, 0, + "empty declaration with storage class specifier " + "does not redeclare tag"); + warned = 1; + pending_xref_error (); + } + else if (!declspecs->tag_defined_p + && (declspecs->const_p + || declspecs->volatile_p + || declspecs->restrict_p + || declspecs->address_space)) + { + if (warned != 1) + pedwarn (input_location, 0, + "empty declaration with type qualifier " + "does not redeclare tag"); + warned = 1; + pending_xref_error (); + } else - { - if (warned != 1 && !in_system_header) - { - pedwarn (input_location, 0, - "useless type name in empty declaration"); - warned = 1; - } - } + { + pending_invalid_xref = 0; + t = lookup_tag (code, name, 1, NULL); + + if (t == 0) + { + t = make_node (code); + pushtag (input_location, name, t); + } + } + } + else + { + if (warned != 1 && !in_system_header) + { + pedwarn (input_location, 0, + "useless type name in empty declaration"); + warned = 1; + } + } } else if (warned != 1 && !in_system_header && declspecs->typedef_p) { @@ -3009,8 +3720,9 @@ } if (!warned && !in_system_header && (declspecs->const_p - || declspecs->volatile_p - || declspecs->restrict_p)) + || declspecs->volatile_p + || declspecs->restrict_p + || declspecs->address_space)) { warning (0, "useless type qualifier in empty declaration"); warned = 2; @@ -3019,7 +3731,7 @@ if (warned != 1) { if (!found_tag) - pedwarn (input_location, 0, "empty declaration"); + pedwarn (input_location, 0, "empty declaration"); } } @@ -3032,41 +3744,45 @@ quals_from_declspecs (const struct c_declspecs *specs) { int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0) - | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) - | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)); + | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) + | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0) + | (ENCODE_QUAL_ADDR_SPACE (specs->address_space))); gcc_assert (!specs->type - && !specs->decl_attr - && specs->typespec_word == cts_none - && specs->storage_class == csc_none - && !specs->typedef_p - && !specs->explicit_signed_p - && !specs->deprecated_p - && !specs->long_p - && !specs->long_long_p - && !specs->short_p - && !specs->signed_p - && !specs->unsigned_p - && !specs->complex_p - && !specs->inline_p - && !specs->thread_p); + && !specs->decl_attr + && specs->typespec_word == cts_none + && specs->storage_class == csc_none + && !specs->typedef_p + && !specs->explicit_signed_p + && !specs->deprecated_p + && !specs->long_p + && !specs->long_long_p + && !specs->short_p + && !specs->signed_p + && !specs->unsigned_p + && !specs->complex_p + && !specs->inline_p + && !specs->thread_p); return quals; } -/* Construct an array declarator. EXPR is the expression inside [], - or NULL_TREE. QUALS are the type qualifiers inside the [] (to be - applied to the pointer to which a parameter array is converted). - STATIC_P is true if "static" is inside the [], false otherwise. - VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified - length which is nevertheless a complete type, false otherwise. The - field for the contained declarator is left to be filled in by - set_array_declarator_inner. */ +/* Construct an array declarator. LOC is the location of the + beginning of the array (usually the opening brace). EXPR is the + expression inside [], or NULL_TREE. QUALS are the type qualifiers + inside the [] (to be applied to the pointer to which a parameter + array is converted). STATIC_P is true if "static" is inside the + [], false otherwise. VLA_UNSPEC_P is true if the array is [*], a + VLA of unspecified length which is nevertheless a complete type, + false otherwise. The field for the contained declarator is left to + be filled in by set_array_declarator_inner. */ struct c_declarator * -build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, - bool vla_unspec_p) +build_array_declarator (location_t loc, + tree expr, struct c_declspecs *quals, bool static_p, + bool vla_unspec_p) { struct c_declarator *declarator = XOBNEW (&parser_obstack, - struct c_declarator); + struct c_declarator); + declarator->id_loc = loc; declarator->kind = cdk_array; declarator->declarator = 0; declarator->u.array.dimen = expr; @@ -3085,22 +3801,23 @@ if (!flag_isoc99) { if (static_p || quals != NULL) - pedwarn (input_location, OPT_pedantic, - "ISO C90 does not support %<static%> or type " - "qualifiers in parameter array declarators"); + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support %<static%> or type " + "qualifiers in parameter array declarators"); if (vla_unspec_p) - pedwarn (input_location, OPT_pedantic, - "ISO C90 does not support %<[*]%> array declarators"); + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support %<[*]%> array declarators"); } if (vla_unspec_p) { if (!current_scope->parm_flag) - { - /* C99 6.7.5.2p4 */ - error ("%<[*]%> not allowed in other than function prototype scope"); - declarator->u.array.vla_unspec_p = false; - return NULL; - } + { + /* C99 6.7.5.2p4 */ + error_at (loc, "%<[*]%> not allowed in other than " + "function prototype scope"); + declarator->u.array.vla_unspec_p = false; + return NULL; + } current_scope->had_vla_unspec = true; } return declarator; @@ -3112,7 +3829,7 @@ struct c_declarator * set_array_declarator_inner (struct c_declarator *decl, - struct c_declarator *inner) + struct c_declarator *inner) { decl->declarator = inner; return decl; @@ -3139,16 +3856,21 @@ { complete_array_type (&type, elt, false); DECL_SIZE (decl) - = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); DECL_SIZE_UNIT (decl) - = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); + = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); } } -/* Decode a "typename", such as "int **", returning a ..._TYPE node. */ +/* Decode a "typename", such as "int **", returning a ..._TYPE node. + Set *EXPR, if EXPR not NULL, to any expression to be evaluated + before the type name, and set *EXPR_CONST_OPERANDS, if + EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may + appear in a constant expression. */ tree -groktypename (struct c_type_name *type_name) +groktypename (struct c_type_name *type_name, tree *expr, + bool *expr_const_operands) { tree type; tree attrs = type_name->specs->attrs; @@ -3156,7 +3878,8 @@ type_name->specs->attrs = NULL_TREE; type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME, - false, NULL, &attrs, DEPRECATED_NORMAL); + false, NULL, &attrs, expr, expr_const_operands, + DEPRECATED_NORMAL); /* Apply attributes. */ decl_attributes (&type, attrs, 0); @@ -3181,10 +3904,11 @@ tree start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, - bool initialized, tree attributes) + bool initialized, tree attributes) { tree decl; tree tem; + tree expr = NULL_TREE; enum deprecated_states deprecated_state = DEPRECATED_NORMAL; /* An object declared as __attribute__((deprecated)) suppresses @@ -3193,11 +3917,14 @@ deprecated_state = DEPRECATED_SUPPRESS; decl = grokdeclarator (declarator, declspecs, - NORMAL, initialized, NULL, &attributes, - deprecated_state); + NORMAL, initialized, NULL, &attributes, &expr, NULL, + deprecated_state); if (!decl) return 0; + if (expr) + add_stmt (expr); + if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) warning (OPT_Wmain, "%q+D is usually a function", decl); @@ -3208,64 +3935,64 @@ switch (TREE_CODE (decl)) { case TYPE_DECL: - error ("typedef %qD is initialized (use __typeof__ instead)", decl); - initialized = 0; - break; + error ("typedef %qD is initialized (use __typeof__ instead)", decl); + initialized = 0; + break; case FUNCTION_DECL: - error ("function %qD is initialized like a variable", decl); - initialized = 0; - break; + error ("function %qD is initialized like a variable", decl); + initialized = 0; + break; case PARM_DECL: - /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ - error ("parameter %qD is initialized", decl); - initialized = 0; - break; + /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ + error ("parameter %qD is initialized", decl); + initialized = 0; + break; default: - /* Don't allow initializations for incomplete types except for - arrays which might be completed by the initialization. */ - - /* This can happen if the array size is an undefined macro. - We already gave a warning, so we don't need another one. */ - if (TREE_TYPE (decl) == error_mark_node) - initialized = 0; - else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) - { - /* A complete type is ok if size is fixed. */ - - if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST - || C_DECL_VARIABLE_SIZE (decl)) - { - error ("variable-sized object may not be initialized"); - initialized = 0; - } - } - else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) - { - error ("variable %qD has initializer but incomplete type", decl); - initialized = 0; - } - else if (C_DECL_VARIABLE_SIZE (decl)) - { - /* Although C99 is unclear about whether incomplete arrays - of VLAs themselves count as VLAs, it does not make - sense to permit them to be initialized given that - ordinary VLAs may not be initialized. */ - error ("variable-sized object may not be initialized"); - initialized = 0; - } + /* Don't allow initializations for incomplete types except for + arrays which might be completed by the initialization. */ + + /* This can happen if the array size is an undefined macro. + We already gave a warning, so we don't need another one. */ + if (TREE_TYPE (decl) == error_mark_node) + initialized = 0; + else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) + { + /* A complete type is ok if size is fixed. */ + + if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST + || C_DECL_VARIABLE_SIZE (decl)) + { + error ("variable-sized object may not be initialized"); + initialized = 0; + } + } + else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) + { + error ("variable %qD has initializer but incomplete type", decl); + initialized = 0; + } + else if (C_DECL_VARIABLE_SIZE (decl)) + { + /* Although C99 is unclear about whether incomplete arrays + of VLAs themselves count as VLAs, it does not make + sense to permit them to be initialized given that + ordinary VLAs may not be initialized. */ + error ("variable-sized object may not be initialized"); + initialized = 0; + } } if (initialized) { if (current_scope == file_scope) - TREE_STATIC (decl) = 1; + TREE_STATIC (decl) = 1; /* Tell 'pushdecl' this is an initialized decl - even though we don't yet have the initializer expression. - Also tell 'finish_decl' it may store the real initializer. */ + even though we don't yet have the initializer expression. + Also tell 'finish_decl' it may store the real initializer. */ DECL_INITIAL (decl) = error_mark_node; } @@ -3301,12 +4028,12 @@ && !flag_gnu89_inline && TREE_CODE (decl) == FUNCTION_DECL && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl)) - || current_function_decl)) + || current_function_decl)) { if (declspecs->storage_class == csc_auto && current_scope != file_scope) - ; + ; else if (declspecs->storage_class != csc_static) - DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); + DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); } if (TREE_CODE (decl) == FUNCTION_DECL @@ -3315,18 +4042,18 @@ struct c_declarator *ce = declarator; if (ce->kind == cdk_pointer) - ce = declarator->declarator; + ce = declarator->declarator; if (ce->kind == cdk_function) - { - tree args = ce->u.arg_info->parms; - for (; args; args = TREE_CHAIN (args)) - { - tree type = TREE_TYPE (args); - if (type && INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (args) = integer_type_node; - } - } + { + tree args = ce->u.arg_info->parms; + for (; args; args = TREE_CHAIN (args)) + { + tree type = TREE_TYPE (args); + if (type && INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (args) = integer_type_node; + } + } } if (TREE_CODE (decl) == FUNCTION_DECL @@ -3334,7 +4061,7 @@ && DECL_UNINLINABLE (decl) && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) warning (OPT_Wattributes, "inline function %q+D given attribute noinline", - decl); + decl); /* C99 6.7.4p3: An inline definition of a function with external linkage shall not contain a definition of a modifiable object @@ -3345,9 +4072,8 @@ && !TREE_READONLY (decl) && DECL_DECLARED_INLINE_P (current_function_decl) && DECL_EXTERNAL (current_function_decl)) - pedwarn (input_location, 0, - "%q+D is static but declared in inline function %qD " - "which is not static", decl, current_function_decl); + record_inline_static (input_location, current_function_decl, + decl, csi_modifiable); /* Add this decl to the current scope. TEM may equal DECL or it may be a previous decl of the same name. */ @@ -3362,33 +4088,20 @@ return tem; } -/* Initialize EH if not initialized yet and exceptions are enabled. */ +/* Finish processing of a declaration; + install its initial value. + If ORIGTYPE is not NULL_TREE, it is the original type of INIT. + If the length of an array type is not known before, + it must be determined now, from the initial value, or it is an error. + + INIT_LOC is the location of the initial value. */ void -c_maybe_initialize_eh (void) -{ - if (!flag_exceptions || c_eh_initialized_p) - return; - - c_eh_initialized_p = true; - eh_personality_libfunc - = init_one_libfunc (USING_SJLJ_EXCEPTIONS - ? "__gcc_personality_sj0" - : "__gcc_personality_v0"); - default_init_unwind_resume_libfunc (); - using_eh_for_cleanups (); -} - -/* Finish processing of a declaration; - install its initial value. - If the length of an array type is not known before, - it must be determined now, from the initial value, or it is an error. */ - -void -finish_decl (tree decl, tree init, tree asmspec_tree) +finish_decl (tree decl, location_t init_loc, tree init, + tree origtype, tree asmspec_tree) { tree type; - int was_incomplete = (DECL_SIZE (decl) == 0); + bool was_incomplete = (DECL_SIZE (decl) == 0); const char *asmspec = 0; /* If a name was specified, get the string. */ @@ -3414,11 +4127,11 @@ init = 0; if (init) - store_init_value (decl, init); + store_init_value (init_loc, decl, init, origtype); if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == FIELD_DECL)) + || TREE_CODE (decl) == FUNCTION_DECL + || TREE_CODE (decl) == FIELD_DECL)) objc_check_decl (decl); type = TREE_TYPE (decl); @@ -3429,65 +4142,65 @@ && TREE_CODE (decl) != TYPE_DECL) { bool do_default - = (TREE_STATIC (decl) - /* Even if pedantic, an external linkage array - may have incomplete type at first. */ - ? pedantic && !TREE_PUBLIC (decl) - : !DECL_EXTERNAL (decl)); + = (TREE_STATIC (decl) + /* Even if pedantic, an external linkage array + may have incomplete type at first. */ + ? pedantic && !TREE_PUBLIC (decl) + : !DECL_EXTERNAL (decl)); int failure - = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), - do_default); + = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), + do_default); /* Get the completed type made by complete_array_type. */ type = TREE_TYPE (decl); switch (failure) - { - case 1: - error ("initializer fails to determine size of %q+D", decl); - break; - - case 2: - if (do_default) - error ("array size missing in %q+D", decl); - /* If a `static' var's size isn't known, - make it extern as well as static, so it does not get - allocated. - If it is not `static', then do not mark extern; - finish_incomplete_decl will give it a default size - and it will get allocated. */ - else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) - DECL_EXTERNAL (decl) = 1; - break; - - case 3: - error ("zero or negative size array %q+D", decl); - break; - - case 0: - /* For global variables, update the copy of the type that - exists in the binding. */ - if (TREE_PUBLIC (decl)) - { - struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); - while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) - b_ext = b_ext->shadowed; - if (b_ext) - { - if (b_ext->type) - b_ext->type = composite_type (b_ext->type, type); - else - b_ext->type = type; - } - } - break; - - default: - gcc_unreachable (); - } + { + case 1: + error ("initializer fails to determine size of %q+D", decl); + break; + + case 2: + if (do_default) + error ("array size missing in %q+D", decl); + /* If a `static' var's size isn't known, + make it extern as well as static, so it does not get + allocated. + If it is not `static', then do not mark extern; + finish_incomplete_decl will give it a default size + and it will get allocated. */ + else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) + DECL_EXTERNAL (decl) = 1; + break; + + case 3: + error ("zero or negative size array %q+D", decl); + break; + + case 0: + /* For global variables, update the copy of the type that + exists in the binding. */ + if (TREE_PUBLIC (decl)) + { + struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); + while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) + b_ext = b_ext->shadowed; + if (b_ext) + { + if (b_ext->u.type) + b_ext->u.type = composite_type (b_ext->u.type, type); + else + b_ext->u.type = type; + } + } + break; + + default: + gcc_unreachable (); + } if (DECL_INITIAL (decl)) - TREE_TYPE (DECL_INITIAL (decl)) = type; + TREE_TYPE (DECL_INITIAL (decl)) = type; layout_decl (decl, 0); } @@ -3495,45 +4208,45 @@ if (TREE_CODE (decl) == VAR_DECL) { if (init && TREE_CODE (init) == CONSTRUCTOR) - add_flexible_array_elts_to_size (decl, init); + add_flexible_array_elts_to_size (decl, init); if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node - && COMPLETE_TYPE_P (TREE_TYPE (decl))) - layout_decl (decl, 0); + && COMPLETE_TYPE_P (TREE_TYPE (decl))) + layout_decl (decl, 0); if (DECL_SIZE (decl) == 0 - /* Don't give an error if we already gave one earlier. */ - && TREE_TYPE (decl) != error_mark_node - && (TREE_STATIC (decl) - /* A static variable with an incomplete type - is an error if it is initialized. - Also if it is not file scope. - Otherwise, let it through, but if it is not `extern' - then it may cause an error message later. */ - ? (DECL_INITIAL (decl) != 0 - || !DECL_FILE_SCOPE_P (decl)) - /* An automatic variable with an incomplete type - is an error. */ - : !DECL_EXTERNAL (decl))) - { - error ("storage size of %q+D isn%'t known", decl); - TREE_TYPE (decl) = error_mark_node; - } + /* Don't give an error if we already gave one earlier. */ + && TREE_TYPE (decl) != error_mark_node + && (TREE_STATIC (decl) + /* A static variable with an incomplete type + is an error if it is initialized. + Also if it is not file scope. + Otherwise, let it through, but if it is not `extern' + then it may cause an error message later. */ + ? (DECL_INITIAL (decl) != 0 + || !DECL_FILE_SCOPE_P (decl)) + /* An automatic variable with an incomplete type + is an error. */ + : !DECL_EXTERNAL (decl))) + { + error ("storage size of %q+D isn%'t known", decl); + TREE_TYPE (decl) = error_mark_node; + } if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) - && DECL_SIZE (decl) != 0) - { - if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) - constant_expression_warning (DECL_SIZE (decl)); - else - { - error ("storage size of %q+D isn%'t constant", decl); - TREE_TYPE (decl) = error_mark_node; - } - } + && DECL_SIZE (decl) != 0) + { + if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) + constant_expression_warning (DECL_SIZE (decl)); + else + { + error ("storage size of %q+D isn%'t constant", decl); + TREE_TYPE (decl) = error_mark_node; + } + } if (TREE_USED (type)) - TREE_USED (decl) = 1; + TREE_USED (decl) = 1; } /* If this is a function and an assembler name is specified, reset DECL_RTL @@ -3542,7 +4255,7 @@ if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) { if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) - set_builtin_user_assembler_name (decl, asmspec); + set_builtin_user_assembler_name (decl, asmspec); set_user_assembler_name (decl, asmspec); } @@ -3557,97 +4270,98 @@ { /* Determine the ELF visibility. */ if (TREE_PUBLIC (decl)) - c_determine_visibility (decl); + c_determine_visibility (decl); /* This is a no-op in c-lang.c or something real in objc-act.c. */ if (c_dialect_objc ()) - objc_check_decl (decl); + objc_check_decl (decl); if (asmspec) - { - /* If this is not a static variable, issue a warning. - It doesn't make any sense to give an ASMSPEC for an - ordinary, non-register local variable. Historically, - GCC has accepted -- but ignored -- the ASMSPEC in - this case. */ - if (!DECL_FILE_SCOPE_P (decl) - && TREE_CODE (decl) == VAR_DECL - && !C_DECL_REGISTER (decl) - && !TREE_STATIC (decl)) - warning (0, "ignoring asm-specifier for non-static local " - "variable %q+D", decl); - else - set_user_assembler_name (decl, asmspec); - } + { + /* If this is not a static variable, issue a warning. + It doesn't make any sense to give an ASMSPEC for an + ordinary, non-register local variable. Historically, + GCC has accepted -- but ignored -- the ASMSPEC in + this case. */ + if (!DECL_FILE_SCOPE_P (decl) + && TREE_CODE (decl) == VAR_DECL + && !C_DECL_REGISTER (decl) + && !TREE_STATIC (decl)) + warning (0, "ignoring asm-specifier for non-static local " + "variable %q+D", decl); + else + set_user_assembler_name (decl, asmspec); + } if (DECL_FILE_SCOPE_P (decl)) - { - if (DECL_INITIAL (decl) == NULL_TREE - || DECL_INITIAL (decl) == error_mark_node) - /* Don't output anything - when a tentative file-scope definition is seen. - But at end of compilation, do output code for them. */ - DECL_DEFER_OUTPUT (decl) = 1; - rest_of_decl_compilation (decl, true, 0); - } + { + if (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + /* Don't output anything + when a tentative file-scope definition is seen. + But at end of compilation, do output code for them. */ + DECL_DEFER_OUTPUT (decl) = 1; + rest_of_decl_compilation (decl, true, 0); + } else - { - /* In conjunction with an ASMSPEC, the `register' - keyword indicates that we should place the variable - in a particular register. */ - if (asmspec && C_DECL_REGISTER (decl)) - { - DECL_HARD_REGISTER (decl) = 1; - /* This cannot be done for a structure with volatile - fields, on which DECL_REGISTER will have been - reset. */ - if (!DECL_REGISTER (decl)) - error ("cannot put object with volatile field into register"); - } - - if (TREE_CODE (decl) != FUNCTION_DECL) - { - /* If we're building a variable sized type, and we might be - reachable other than via the top of the current binding - level, then create a new BIND_EXPR so that we deallocate - the object at the right time. */ - /* Note that DECL_SIZE can be null due to errors. */ - if (DECL_SIZE (decl) - && !TREE_CONSTANT (DECL_SIZE (decl)) - && STATEMENT_LIST_HAS_LABEL (cur_stmt_list)) - { - tree bind; - bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); - TREE_SIDE_EFFECTS (bind) = 1; - add_stmt (bind); - BIND_EXPR_BODY (bind) = push_stmt_list (); - } - add_stmt (build_stmt (DECL_EXPR, decl)); - } - } + { + /* In conjunction with an ASMSPEC, the `register' + keyword indicates that we should place the variable + in a particular register. */ + if (asmspec && C_DECL_REGISTER (decl)) + { + DECL_HARD_REGISTER (decl) = 1; + /* This cannot be done for a structure with volatile + fields, on which DECL_REGISTER will have been + reset. */ + if (!DECL_REGISTER (decl)) + error ("cannot put object with volatile field into register"); + } + + if (TREE_CODE (decl) != FUNCTION_DECL) + { + /* If we're building a variable sized type, and we might be + reachable other than via the top of the current binding + level, then create a new BIND_EXPR so that we deallocate + the object at the right time. */ + /* Note that DECL_SIZE can be null due to errors. */ + if (DECL_SIZE (decl) + && !TREE_CONSTANT (DECL_SIZE (decl)) + && STATEMENT_LIST_HAS_LABEL (cur_stmt_list)) + { + tree bind; + bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); + TREE_SIDE_EFFECTS (bind) = 1; + add_stmt (bind); + BIND_EXPR_BODY (bind) = push_stmt_list (); + } + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), + DECL_EXPR, decl)); + } + } if (!DECL_FILE_SCOPE_P (decl)) - { - /* Recompute the RTL of a local array now - if it used to be an incomplete type. */ - if (was_incomplete - && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) - { - /* If we used it already as memory, it must stay in memory. */ - TREE_ADDRESSABLE (decl) = TREE_USED (decl); - /* If it's still incomplete now, no init will save it. */ - if (DECL_SIZE (decl) == 0) - DECL_INITIAL (decl) = 0; - } - } + { + /* Recompute the RTL of a local array now + if it used to be an incomplete type. */ + if (was_incomplete + && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) + { + /* If we used it already as memory, it must stay in memory. */ + TREE_ADDRESSABLE (decl) = TREE_USED (decl); + /* If it's still incomplete now, no init will save it. */ + if (DECL_SIZE (decl) == 0) + DECL_INITIAL (decl) = 0; + } + } } if (TREE_CODE (decl) == TYPE_DECL) { if (!DECL_FILE_SCOPE_P (decl) - && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) - add_stmt (build_stmt (DECL_EXPR, decl)); + && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); } @@ -3663,26 +4377,35 @@ { tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl)); if (attr) - { - tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); - tree cleanup_decl = lookup_name (cleanup_id); - tree cleanup; - - /* Build "cleanup(&decl)" for the destructor. */ - cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); - cleanup = build_tree_list (NULL_TREE, cleanup); - cleanup = build_function_call (cleanup_decl, cleanup); - - /* Don't warn about decl unused; the cleanup uses it. */ - TREE_USED (decl) = 1; - TREE_USED (cleanup_decl) = 1; - - /* Initialize EH, if we've been told to do so. */ - c_maybe_initialize_eh (); - - push_cleanup (decl, cleanup, false); - } - } + { + tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); + tree cleanup_decl = lookup_name (cleanup_id); + tree cleanup; + VEC(tree,gc) *vec; + + /* Build "cleanup(&decl)" for the destructor. */ + cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); + vec = VEC_alloc (tree, gc, 1); + VEC_quick_push (tree, vec, cleanup); + cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl), + cleanup_decl, vec, NULL); + VEC_free (tree, gc, vec); + + /* Don't warn about decl unused; the cleanup uses it. */ + TREE_USED (decl) = 1; + TREE_USED (cleanup_decl) = 1; + + push_cleanup (decl, cleanup, false); + } + } + + if (warn_cxx_compat + && TREE_CODE (decl) == VAR_DECL + && TREE_READONLY (decl) + && !DECL_EXTERNAL (decl) + && DECL_INITIAL (decl) == NULL_TREE) + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, + "uninitialized const %qD is invalid in C++", decl); } /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ @@ -3692,7 +4415,7 @@ { tree attrs = parm->attrs; tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, - NULL, &attrs, DEPRECATED_NORMAL); + NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL); decl_attributes (&decl, attrs, 0); @@ -3709,12 +4432,12 @@ tree decl; decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL, - &attrs, DEPRECATED_NORMAL); + &attrs, NULL, NULL, DEPRECATED_NORMAL); decl_attributes (&decl, attrs, 0); decl = pushdecl (decl); - finish_decl (decl, NULL_TREE, NULL_TREE); + finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE); } /* Mark all the parameter declarations to date as forward decls. @@ -3728,7 +4451,7 @@ if (pedantic && !current_scope->warned_forward_parm_decls) { pedwarn (input_location, OPT_pedantic, - "ISO C forbids forward parameter declarations"); + "ISO C forbids forward parameter declarations"); current_scope->warned_forward_parm_decls = true; } @@ -3739,11 +4462,12 @@ /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound literal, which may be an incomplete array type completed by the - initializer; INIT is a CONSTRUCTOR that initializes the compound - literal. */ + initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound + literal. NON_CONST is true if the initializers contain something + that cannot occur in a constant expression. */ tree -build_compound_literal (tree type, tree init) +build_compound_literal (location_t loc, tree type, tree init, bool non_const) { /* We do not use start_decl here because we have a type, not a declarator; and do not use finish_decl because the decl should be stored inside @@ -3755,7 +4479,7 @@ if (type == error_mark_node) return error_mark_node; - decl = build_decl (VAR_DECL, NULL_TREE, type); + decl = build_decl (loc, VAR_DECL, NULL_TREE, type); DECL_EXTERNAL (decl) = 0; TREE_PUBLIC (decl) = 0; TREE_STATIC (decl) = (current_scope == file_scope); @@ -3763,12 +4487,12 @@ TREE_USED (decl) = 1; TREE_TYPE (decl) = type; TREE_READONLY (decl) = TYPE_READONLY (type); - store_init_value (decl, init); + store_init_value (loc, decl, init, NULL_TREE); if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) { int failure = complete_array_type (&TREE_TYPE (decl), - DECL_INITIAL (decl), true); + DECL_INITIAL (decl), true); gcc_assert (!failure); type = TREE_TYPE (decl); @@ -3778,7 +4502,7 @@ if (type == error_mark_node || !COMPLETE_TYPE_P (type)) return error_mark_node; - stmt = build_stmt (DECL_EXPR, decl); + stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl); complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt); TREE_SIDE_EFFECTS (complit) = 1; @@ -3796,8 +4520,25 @@ rest_of_decl_compilation (decl, 1, 0); } + if (non_const) + { + complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit); + C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1; + } + return complit; } + +/* Check the type of a compound literal. Here we just check that it + is valid for C++. */ + +void +check_compound_literal_type (location_t loc, struct c_type_name *type_name) +{ + if (warn_cxx_compat && type_name->specs->tag_defined_p) + warning_at (loc, OPT_Wc___compat, + "defining a type in a compound literal is invalid in C++"); +} /* Determine whether TYPE is a structure with a flexible array member, or a union containing such a structure (possibly recursively). */ @@ -3811,21 +4552,21 @@ case RECORD_TYPE: x = TYPE_FIELDS (type); if (x == NULL_TREE) - return false; + return false; while (TREE_CHAIN (x) != NULL_TREE) - x = TREE_CHAIN (x); + x = TREE_CHAIN (x); if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE - && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE - && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE - && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) - return true; + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) + return true; return false; case UNION_TYPE: for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x)) - { - if (flexible_array_type_p (TREE_TYPE (x))) - return true; - } + { + if (flexible_array_type_p (TREE_TYPE (x))) + return true; + } return false; default: return false; @@ -3835,34 +4576,48 @@ /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME, replacing with appropriate values if they are invalid. */ static void -check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name) +check_bitfield_type_and_width (tree *type, tree *width, tree orig_name) { tree type_mv; unsigned int max_width; unsigned HOST_WIDE_INT w; - const char *name = orig_name ? orig_name: _("<anonymous>"); + const char *name = (orig_name + ? identifier_to_locale (IDENTIFIER_POINTER (orig_name)) + : _("<anonymous>")); /* Detect and ignore out of range field width and process valid field widths. */ - if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)) - || TREE_CODE (*width) != INTEGER_CST) + if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))) { error ("bit-field %qs width not an integer constant", name); *width = integer_one_node; } else { + if (TREE_CODE (*width) != INTEGER_CST) + { + *width = c_fully_fold (*width, false, NULL); + if (TREE_CODE (*width) == INTEGER_CST) + pedwarn (input_location, OPT_pedantic, + "bit-field %qs width not an integer constant expression", + name); + } + if (TREE_CODE (*width) != INTEGER_CST) + { + error ("bit-field %qs width not an integer constant", name); + *width = integer_one_node; + } constant_expression_warning (*width); if (tree_int_cst_sgn (*width) < 0) - { - error ("negative width in bit-field %qs", name); - *width = integer_one_node; - } + { + error ("negative width in bit-field %qs", name); + *width = integer_one_node; + } else if (integer_zerop (*width) && orig_name) - { - error ("zero width for bit-field %qs", name); - *width = integer_one_node; - } + { + error ("zero width for bit-field %qs", name); + *width = integer_one_node; + } } /* Detect invalid bit-field type. */ @@ -3880,7 +4635,7 @@ && type_mv != unsigned_type_node && type_mv != boolean_type_node) pedwarn (input_location, OPT_pedantic, - "type of bit-field %qs is a GCC extension", name); + "type of bit-field %qs is a GCC extension", name); max_width = TYPE_PRECISION (*type); @@ -3897,9 +4652,9 @@ { struct lang_type *lt = TYPE_LANG_SPECIFIC (*type); if (!lt - || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type)) - || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type))) - warning (0, "%qs is narrower than values of its type", name); + || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type)) + || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type))) + warning (0, "%qs is narrower than values of its type", name); } } @@ -3908,54 +4663,84 @@ /* Print warning about variable length array if necessary. */ static void -warn_variable_length_array (const char *name, tree size) +warn_variable_length_array (tree name, tree size) { int const_size = TREE_CONSTANT (size); if (!flag_isoc99 && pedantic && warn_vla != 0) { if (const_size) - { - if (name) - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array %qs whose size " - "can%'t be evaluated", - name); - else - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size " - "can%'t be evaluated"); - } + { + if (name) + pedwarn (input_location, OPT_Wvla, + "ISO C90 forbids array %qE whose size " + "can%'t be evaluated", + name); else - { - if (name) - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array %qs", - name); - else - pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); - } + pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size " + "can%'t be evaluated"); + } + else + { + if (name) + pedwarn (input_location, OPT_Wvla, + "ISO C90 forbids variable length array %qE", + name); + else + pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); + } } else if (warn_vla > 0) { if (const_size) { - if (name) - warning (OPT_Wvla, - "the size of array %qs can" - "%'t be evaluated", name); - else - warning (OPT_Wvla, - "the size of array can %'t be evaluated"); - } + if (name) + warning (OPT_Wvla, + "the size of array %qE can" + "%'t be evaluated", name); + else + warning (OPT_Wvla, + "the size of array can %'t be evaluated"); + } + else + { + if (name) + warning (OPT_Wvla, + "variable length array %qE is used", + name); else - { - if (name) - warning (OPT_Wvla, - "variable length array %qs is used", - name); - else - warning (OPT_Wvla, - "variable length array is used"); - } - } + warning (OPT_Wvla, + "variable length array is used"); + } + } +} + +/* Given a size SIZE that may not be a constant, return a SAVE_EXPR to + serve as the actual size-expression for a type or decl. This is + like variable_size in stor-layout.c, but we make global_bindings_p + return negative to avoid calls to that function from outside the + front end resulting in errors at file scope, then call this version + instead from front-end code. */ + +static tree +c_variable_size (tree size) +{ + tree save; + + if (TREE_CONSTANT (size)) + return size; + + size = save_expr (size); + + save = skip_simple_arithmetic (size); + + if (cfun && cfun->dont_save_pending_sizes_p) + return size; + + if (!global_bindings_p ()) + put_pending_size (save); + + return size; } /* Given declspecs and a declarator, @@ -3982,6 +4767,11 @@ DECL_ATTRS points to the list of attributes that should be added to this decl. Any nested attributes that belong on the decl itself will be added to this list. + If EXPR is not NULL, any expressions that need to be evaluated as + part of evaluating variably modified types will be stored in *EXPR. + If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be + set to indicate whether operands in *EXPR can be used in constant + expressions. DEPRECATED_STATE is a deprecated_states value indicating whether deprecation warnings should be suppressed. @@ -3994,9 +4784,10 @@ static tree grokdeclarator (const struct c_declarator *declarator, - struct c_declspecs *declspecs, - enum decl_context decl_context, bool initialized, tree *width, - tree *decl_attrs, enum deprecated_states deprecated_state) + struct c_declspecs *declspecs, + enum decl_context decl_context, bool initialized, tree *width, + tree *decl_attrs, tree *expr, bool *expr_const_operands, + enum deprecated_states deprecated_state) { tree type = declspecs->type; bool threadp = declspecs->thread_p; @@ -4005,10 +4796,10 @@ int restrictp; int volatilep; int type_quals = TYPE_UNQUALIFIED; - const char *name, *orig_name; + tree name = NULL_TREE; bool funcdef_flag = false; bool funcdef_syntax = false; - int size_varies = 0; + bool size_varies = false; tree decl_attr = declspecs->decl_attr; int array_ptr_quals = TYPE_UNQUALIFIED; tree array_ptr_attrs = NULL_TREE; @@ -4018,42 +4809,63 @@ bool bitfield = width != NULL; tree element_type; struct c_arg_info *arg_info = 0; + addr_space_t as1, as2, address_space; + location_t loc = UNKNOWN_LOCATION; + const char *errmsg; + tree expr_dummy; + bool expr_const_operands_dummy; + + if (expr == NULL) + expr = &expr_dummy; + if (expr_const_operands == NULL) + expr_const_operands = &expr_const_operands_dummy; + + *expr = declspecs->expr; + *expr_const_operands = declspecs->expr_const_operands; if (decl_context == FUNCDEF) funcdef_flag = true, decl_context = NORMAL; /* Look inside a declarator for the name being declared - and get it as a string, for an error message. */ + and get it as an IDENTIFIER_NODE, for an error message. */ { const struct c_declarator *decl = declarator; - name = 0; while (decl) switch (decl->kind) - { - case cdk_function: - case cdk_array: - case cdk_pointer: - funcdef_syntax = (decl->kind == cdk_function); - decl = decl->declarator; - break; - - case cdk_attrs: - decl = decl->declarator; - break; - - case cdk_id: - if (decl->u.id) - name = IDENTIFIER_POINTER (decl->u.id); - decl = 0; - break; - - default: - gcc_unreachable (); - } - orig_name = name; + { + case cdk_array: + loc = decl->id_loc; + /* FALL THRU. */ + + case cdk_function: + case cdk_pointer: + funcdef_syntax = (decl->kind == cdk_function); + decl = decl->declarator; + break; + + case cdk_attrs: + decl = decl->declarator; + break; + + case cdk_id: + loc = decl->id_loc; + if (decl->u.id) + name = decl->u.id; + decl = 0; + break; + + default: + gcc_unreachable (); + } if (name == 0) - name = "type name"; + { + gcc_assert (decl_context == PARM + || decl_context == TYPENAME + || (decl_context == FIELD + && declarator->kind == cdk_id)); + gcc_assert (!initialized); + } } /* A function definition's declarator must have the form of @@ -4069,31 +4881,41 @@ decl_context = PARM; if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS) - warn_deprecated_use (declspecs->type); + warn_deprecated_use (declspecs->type, declspecs->decl_attr); if ((decl_context == NORMAL || decl_context == FIELD) && current_scope == file_scope && variably_modified_type_p (type, NULL_TREE)) { - error ("variably modified %qs at file scope", name); + if (name) + error_at (loc, "variably modified %qE at file scope", name); + else + error_at (loc, "variably modified field at file scope"); type = integer_type_node; } - size_varies = C_TYPE_VARIABLE_SIZE (type); + size_varies = C_TYPE_VARIABLE_SIZE (type) != 0; /* Diagnose defaulting to "int". */ if (declspecs->default_int_p && !in_system_header) { /* Issue a warning if this is an ISO C 99 program or if - -Wreturn-type and this is a function, or if -Wimplicit; - prefer the former warning since it is more explicit. */ + -Wreturn-type and this is a function, or if -Wimplicit; + prefer the former warning since it is more explicit. */ if ((warn_implicit_int || warn_return_type || flag_isoc99) - && funcdef_flag) - warn_about_return_type = 1; - else - pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, - "type defaults to %<int%> in declaration of %qs", name); + && funcdef_flag) + warn_about_return_type = 1; + else + { + if (name) + pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, + "type defaults to %<int%> in declaration of %qE", + name); + else + pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, + "type defaults to %<int%> in type name"); + } } /* Adjust the type if a bit-field is being declared, @@ -4118,72 +4940,89 @@ constp = declspecs->const_p + TYPE_READONLY (element_type); restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type); volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type); + as1 = declspecs->address_space; + as2 = TYPE_ADDR_SPACE (element_type); + address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1; + if (pedantic && !flag_isoc99) { if (constp > 1) - pedwarn (input_location, OPT_pedantic, "duplicate %<const%>"); + pedwarn (loc, OPT_pedantic, "duplicate %<const%>"); if (restrictp > 1) - pedwarn (input_location, OPT_pedantic, "duplicate %<restrict%>"); + pedwarn (loc, OPT_pedantic, "duplicate %<restrict%>"); if (volatilep > 1) - pedwarn (input_location, OPT_pedantic, "duplicate %<volatile%>"); - } + pedwarn (loc, OPT_pedantic, "duplicate %<volatile%>"); + } + + if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2) + error_at (loc, "conflicting named address spaces (%s vs %s)", + c_addr_space_name (as1), c_addr_space_name (as2)); + if (!flag_gen_aux_info && (TYPE_QUALS (element_type))) type = TYPE_MAIN_VARIANT (type); type_quals = ((constp ? TYPE_QUAL_CONST : 0) - | (restrictp ? TYPE_QUAL_RESTRICT : 0) - | (volatilep ? TYPE_QUAL_VOLATILE : 0)); + | (restrictp ? TYPE_QUAL_RESTRICT : 0) + | (volatilep ? TYPE_QUAL_VOLATILE : 0) + | ENCODE_QUAL_ADDR_SPACE (address_space)); /* Warn about storage classes that are invalid for certain kinds of declarations (parameters, typenames, etc.). */ if (funcdef_flag && (threadp - || storage_class == csc_auto - || storage_class == csc_register - || storage_class == csc_typedef)) + || storage_class == csc_auto + || storage_class == csc_register + || storage_class == csc_typedef)) { if (storage_class == csc_auto) - pedwarn (input_location, - (current_scope == file_scope) ? 0 : OPT_pedantic, - "function definition declared %<auto%>"); + pedwarn (loc, + (current_scope == file_scope) ? 0 : OPT_pedantic, + "function definition declared %<auto%>"); if (storage_class == csc_register) - error ("function definition declared %<register%>"); + error_at (loc, "function definition declared %<register%>"); if (storage_class == csc_typedef) - error ("function definition declared %<typedef%>"); + error_at (loc, "function definition declared %<typedef%>"); if (threadp) - error ("function definition declared %<__thread%>"); + error_at (loc, "function definition declared %<__thread%>"); threadp = false; if (storage_class == csc_auto - || storage_class == csc_register - || storage_class == csc_typedef) - storage_class = csc_none; + || storage_class == csc_register + || storage_class == csc_typedef) + storage_class = csc_none; } else if (decl_context != NORMAL && (storage_class != csc_none || threadp)) { if (decl_context == PARM && storage_class == csc_register) - ; + ; else - { - switch (decl_context) - { - case FIELD: - error ("storage class specified for structure field %qs", - name); - break; - case PARM: - error ("storage class specified for parameter %qs", name); - break; - default: - error ("storage class specified for typename"); - break; - } - storage_class = csc_none; - threadp = false; - } + { + switch (decl_context) + { + case FIELD: + if (name) + error_at (loc, "storage class specified for structure " + "field %qE", name); + else + error_at (loc, "storage class specified for structure field"); + break; + case PARM: + if (name) + error_at (loc, "storage class specified for parameter %qE", + name); + else + error_at (loc, "storage class specified for unnamed parameter"); + break; + default: + error_at (loc, "storage class specified for typename"); + break; + } + storage_class = csc_none; + threadp = false; + } } else if (storage_class == csc_extern - && initialized - && !funcdef_flag) + && initialized + && !funcdef_flag) { /* 'extern' with initialization is invalid if not at file scope. */ if (current_scope == file_scope) @@ -4191,30 +5030,32 @@ /* It is fine to have 'extern const' when compiling at C and C++ intersection. */ if (!(warn_cxx_compat && constp)) - warning (0, "%qs initialized and declared %<extern%>", name); + warning_at (loc, 0, "%qE initialized and declared %<extern%>", + name); } else - error ("%qs has both %<extern%> and initializer", name); + error_at (loc, "%qE has both %<extern%> and initializer", name); } else if (current_scope == file_scope) { if (storage_class == csc_auto) - error ("file-scope declaration of %qs specifies %<auto%>", name); + error_at (loc, "file-scope declaration of %qE specifies %<auto%>", + name); if (pedantic && storage_class == csc_register) - pedwarn (input_location, OPT_pedantic, - "file-scope declaration of %qs specifies %<register%>", name); + pedwarn (input_location, OPT_pedantic, + "file-scope declaration of %qE specifies %<register%>", name); } else { if (storage_class == csc_extern && funcdef_flag) - error ("nested function %qs declared %<extern%>", name); + error_at (loc, "nested function %qE declared %<extern%>", name); else if (threadp && storage_class == csc_none) - { - error ("function-scope %qs implicitly auto and declared " - "%<__thread%>", - name); - threadp = false; - } + { + error_at (loc, "function-scope %qE implicitly auto and declared " + "%<__thread%>", + name); + threadp = false; + } } /* Now figure out the structure of the declarator proper. @@ -4230,359 +5071,445 @@ while (declarator && declarator->kind != cdk_id) { if (type == error_mark_node) - { - declarator = declarator->declarator; - continue; - } + { + declarator = declarator->declarator; + continue; + } /* Each level of DECLARATOR is either a cdk_array (for ...[..]), - a cdk_pointer (for *...), - a cdk_function (for ...(...)), - a cdk_attrs (for nested attributes), - or a cdk_id (for the name being declared - or the place in an absolute declarator - where the name was omitted). - For the last case, we have just exited the loop. - - At this point, TYPE is the type of elements of an array, - or for a function to return, or for a pointer to point to. - After this sequence of ifs, TYPE is the type of the - array or function or pointer, and DECLARATOR has had its - outermost layer removed. */ + a cdk_pointer (for *...), + a cdk_function (for ...(...)), + a cdk_attrs (for nested attributes), + or a cdk_id (for the name being declared + or the place in an absolute declarator + where the name was omitted). + For the last case, we have just exited the loop. + + At this point, TYPE is the type of elements of an array, + or for a function to return, or for a pointer to point to. + After this sequence of ifs, TYPE is the type of the + array or function or pointer, and DECLARATOR has had its + outermost layer removed. */ if (array_ptr_quals != TYPE_UNQUALIFIED - || array_ptr_attrs != NULL_TREE - || array_parm_static) - { - /* Only the innermost declarator (making a parameter be of - array type which is converted to pointer type) - may have static or type qualifiers. */ - error ("static or type qualifiers in non-parameter array declarator"); - array_ptr_quals = TYPE_UNQUALIFIED; - array_ptr_attrs = NULL_TREE; - array_parm_static = 0; - } + || array_ptr_attrs != NULL_TREE + || array_parm_static) + { + /* Only the innermost declarator (making a parameter be of + array type which is converted to pointer type) + may have static or type qualifiers. */ + error_at (loc, "static or type qualifiers in non-parameter array declarator"); + array_ptr_quals = TYPE_UNQUALIFIED; + array_ptr_attrs = NULL_TREE; + array_parm_static = 0; + } switch (declarator->kind) - { - case cdk_attrs: - { - /* A declarator with embedded attributes. */ - tree attrs = declarator->u.attrs; - const struct c_declarator *inner_decl; - int attr_flags = 0; - declarator = declarator->declarator; - inner_decl = declarator; - while (inner_decl->kind == cdk_attrs) - inner_decl = inner_decl->declarator; - if (inner_decl->kind == cdk_id) - attr_flags |= (int) ATTR_FLAG_DECL_NEXT; - else if (inner_decl->kind == cdk_function) - attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; - else if (inner_decl->kind == cdk_array) - attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; - returned_attrs = decl_attributes (&type, - chainon (returned_attrs, attrs), - attr_flags); - break; - } - case cdk_array: - { - tree itype = NULL_TREE; - tree size = declarator->u.array.dimen; - /* The index is a signed object `sizetype' bits wide. */ - tree index_type = c_common_signed_type (sizetype); - - array_ptr_quals = declarator->u.array.quals; - array_ptr_attrs = declarator->u.array.attrs; - array_parm_static = declarator->u.array.static_p; - array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p; - - declarator = declarator->declarator; - - /* Check for some types that there cannot be arrays of. */ - - if (VOID_TYPE_P (type)) - { - error ("declaration of %qs as array of voids", name); - type = error_mark_node; - } - - if (TREE_CODE (type) == FUNCTION_TYPE) - { - error ("declaration of %qs as array of functions", name); - type = error_mark_node; - } - - if (pedantic && !in_system_header && flexible_array_type_p (type)) - pedwarn (input_location, OPT_pedantic, - "invalid use of structure with flexible array member"); - - if (size == error_mark_node) - type = error_mark_node; - - if (type == error_mark_node) - continue; - - /* If size was specified, set ITYPE to a range-type for - that size. Otherwise, ITYPE remains null. finish_decl - may figure it out from an initial value. */ - - if (size) - { - /* Strip NON_LVALUE_EXPRs since we aren't using as an - lvalue. */ - STRIP_TYPE_NOPS (size); - - if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) - { - error ("size of array %qs has non-integer type", name); - size = integer_one_node; - } - - if (pedantic && integer_zerop (size)) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids zero-size array %qs", name); - - if (TREE_CODE (size) == INTEGER_CST) - { - constant_expression_warning (size); - if (tree_int_cst_sgn (size) < 0) - { - error ("size of array %qs is negative", name); - size = integer_one_node; - } - } - else if ((decl_context == NORMAL || decl_context == FIELD) - && current_scope == file_scope) - { - error ("variably modified %qs at file scope", name); - size = integer_one_node; - } - else - { - /* Make sure the array size remains visibly - nonconstant even if it is (eg) a const variable - with known value. */ - size_varies = 1; - warn_variable_length_array (orig_name, size); - } - - if (integer_zerop (size)) - { - /* A zero-length array cannot be represented with - an unsigned index type, which is what we'll - get with build_index_type. Create an - open-ended range instead. */ - itype = build_range_type (sizetype, size, NULL_TREE); - } - else - { - /* Arrange for the SAVE_EXPR on the inside of the - MINUS_EXPR, which allows the -1 to get folded - with the +1 that happens when building TYPE_SIZE. */ - if (size_varies) - size = variable_size (size); - - /* Compute the maximum valid index, that is, size - - 1. Do the calculation in index_type, so that - if it is a variable the computations will be - done in the proper mode. */ - itype = fold_build2 (MINUS_EXPR, index_type, - convert (index_type, size), - convert (index_type, - size_one_node)); - - /* If that overflowed, the array is too big. ??? - While a size of INT_MAX+1 technically shouldn't - cause an overflow (because we subtract 1), the - overflow is recorded during the conversion to - index_type, before the subtraction. Handling - this case seems like an unnecessary - complication. */ - if (TREE_CODE (itype) == INTEGER_CST - && TREE_OVERFLOW (itype)) - { - error ("size of array %qs is too large", name); - type = error_mark_node; - continue; - } - - itype = build_index_type (itype); - } - } - else if (decl_context == FIELD) - { - bool flexible_array_member = false; - if (array_parm_vla_unspec_p) - /* Field names can in fact have function prototype - scope so [*] is disallowed here through making - the field variably modified, not through being - something other than a declaration with function - prototype scope. */ - size_varies = 1; - else - { - const struct c_declarator *t = declarator; - while (t->kind == cdk_attrs) - t = t->declarator; - flexible_array_member = (t->kind == cdk_id); - } - if (flexible_array_member - && pedantic && !flag_isoc99 && !in_system_header) - pedwarn (input_location, OPT_pedantic, - "ISO C90 does not support flexible array members"); - - /* ISO C99 Flexible array members are effectively - identical to GCC's zero-length array extension. */ - if (flexible_array_member || array_parm_vla_unspec_p) - itype = build_range_type (sizetype, size_zero_node, - NULL_TREE); - } - else if (decl_context == PARM) - { - if (array_parm_vla_unspec_p) - { - itype = build_range_type (sizetype, size_zero_node, NULL_TREE); - size_varies = 1; - } - } - else if (decl_context == TYPENAME) - { - if (array_parm_vla_unspec_p) - { - /* C99 6.7.5.2p4 */ - warning (0, "%<[*]%> not in a declaration"); - /* We use this to avoid messing up with incomplete - array types of the same type, that would - otherwise be modified below. */ - itype = build_range_type (sizetype, size_zero_node, - NULL_TREE); - size_varies = 1; - } - } - - /* Complain about arrays of incomplete types. */ - if (!COMPLETE_TYPE_P (type)) - { - error ("array type has incomplete element type"); - type = error_mark_node; - } - else - /* When itype is NULL, a shared incomplete array type is - returned for all array of a given type. Elsewhere we - make sure we don't complete that type before copying - it, but here we want to make sure we don't ever - modify the shared type, so we gcc_assert (itype) - below. */ - type = build_array_type (type, itype); - - if (type != error_mark_node) - { - if (size_varies) - { - /* It is ok to modify type here even if itype is - NULL: if size_varies, we're in a - multi-dimensional array and the inner type has - variable size, so the enclosing shared array type - must too. */ - if (size && TREE_CODE (size) == INTEGER_CST) - type - = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); - C_TYPE_VARIABLE_SIZE (type) = 1; - } - - /* The GCC extension for zero-length arrays differs from - ISO flexible array members in that sizeof yields - zero. */ - if (size && integer_zerop (size)) - { - gcc_assert (itype); - TYPE_SIZE (type) = bitsize_zero_node; - TYPE_SIZE_UNIT (type) = size_zero_node; - } - if (array_parm_vla_unspec_p) - { - gcc_assert (itype); - /* The type is complete. C99 6.7.5.2p4 */ - TYPE_SIZE (type) = bitsize_zero_node; - TYPE_SIZE_UNIT (type) = size_zero_node; - } - } - - if (decl_context != PARM - && (array_ptr_quals != TYPE_UNQUALIFIED - || array_ptr_attrs != NULL_TREE - || array_parm_static)) - { - error ("static or type qualifiers in non-parameter array declarator"); - array_ptr_quals = TYPE_UNQUALIFIED; - array_ptr_attrs = NULL_TREE; - array_parm_static = 0; - } - break; - } - case cdk_function: - { - /* Say it's a definition only for the declarator closest - to the identifier, apart possibly from some - attributes. */ - bool really_funcdef = false; - tree arg_types; - if (funcdef_flag) - { - const struct c_declarator *t = declarator->declarator; - while (t->kind == cdk_attrs) - t = t->declarator; - really_funcdef = (t->kind == cdk_id); - } - - /* Declaring a function type. Make sure we have a valid - type for the function to return. */ - if (type == error_mark_node) - continue; - - size_varies = 0; - - /* Warn about some types functions can't return. */ - if (TREE_CODE (type) == FUNCTION_TYPE) - { - error ("%qs declared as function returning a function", name); - type = integer_type_node; - } - if (TREE_CODE (type) == ARRAY_TYPE) - { - error ("%qs declared as function returning an array", name); - type = integer_type_node; - } - - /* Construct the function type and go to the next - inner layer of declarator. */ - arg_info = declarator->u.arg_info; - arg_types = grokparms (arg_info, really_funcdef); - if (really_funcdef) - put_pending_sizes (arg_info->pending_sizes); - - /* Type qualifiers before the return type of the function - qualify the return type, not the function type. */ - if (type_quals) - { - /* Type qualifiers on a function return type are - normally permitted by the standard but have no - effect, so give a warning at -Wreturn-type. - Qualifiers on a void return type are banned on - function definitions in ISO C; GCC used to used - them for noreturn functions. */ - if (VOID_TYPE_P (type) && really_funcdef) - pedwarn (input_location, 0, - "function definition has qualified void return type"); - else - warning (OPT_Wignored_qualifiers, - "type qualifiers ignored on function return type"); - - type = c_build_qualified_type (type, type_quals); - } - type_quals = TYPE_UNQUALIFIED; + { + case cdk_attrs: + { + /* A declarator with embedded attributes. */ + tree attrs = declarator->u.attrs; + const struct c_declarator *inner_decl; + int attr_flags = 0; + declarator = declarator->declarator; + inner_decl = declarator; + while (inner_decl->kind == cdk_attrs) + inner_decl = inner_decl->declarator; + if (inner_decl->kind == cdk_id) + attr_flags |= (int) ATTR_FLAG_DECL_NEXT; + else if (inner_decl->kind == cdk_function) + attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; + else if (inner_decl->kind == cdk_array) + attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; + returned_attrs = decl_attributes (&type, + chainon (returned_attrs, attrs), + attr_flags); + break; + } + case cdk_array: + { + tree itype = NULL_TREE; + tree size = declarator->u.array.dimen; + /* The index is a signed object `sizetype' bits wide. */ + tree index_type = c_common_signed_type (sizetype); + + array_ptr_quals = declarator->u.array.quals; + array_ptr_attrs = declarator->u.array.attrs; + array_parm_static = declarator->u.array.static_p; + array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p; + + declarator = declarator->declarator; + + /* Check for some types that there cannot be arrays of. */ + + if (VOID_TYPE_P (type)) + { + if (name) + error_at (loc, "declaration of %qE as array of voids", name); + else + error_at (loc, "declaration of type name as array of voids"); + type = error_mark_node; + } + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + if (name) + error_at (loc, "declaration of %qE as array of functions", + name); + else + error_at (loc, "declaration of type name as array of " + "functions"); + type = error_mark_node; + } + + if (pedantic && !in_system_header && flexible_array_type_p (type)) + pedwarn (loc, OPT_pedantic, + "invalid use of structure with flexible array member"); + + if (size == error_mark_node) + type = error_mark_node; + + if (type == error_mark_node) + continue; + + /* If size was specified, set ITYPE to a range-type for + that size. Otherwise, ITYPE remains null. finish_decl + may figure it out from an initial value. */ + + if (size) + { + bool size_maybe_const = true; + bool size_int_const = (TREE_CODE (size) == INTEGER_CST + && !TREE_OVERFLOW (size)); + bool this_size_varies = false; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an + lvalue. */ + STRIP_TYPE_NOPS (size); + + if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) + { + if (name) + error_at (loc, "size of array %qE has non-integer type", + name); + else + error_at (loc, + "size of unnamed array has non-integer type"); + size = integer_one_node; + } + + size = c_fully_fold (size, false, &size_maybe_const); + + if (pedantic && size_maybe_const && integer_zerop (size)) + { + if (name) + pedwarn (loc, OPT_pedantic, + "ISO C forbids zero-size array %qE", name); + else + pedwarn (loc, OPT_pedantic, + "ISO C forbids zero-size array"); + } + + if (TREE_CODE (size) == INTEGER_CST && size_maybe_const) + { + constant_expression_warning (size); + if (tree_int_cst_sgn (size) < 0) + { + if (name) + error_at (loc, "size of array %qE is negative", name); + else + error_at (loc, "size of unnamed array is negative"); + size = integer_one_node; + } + /* Handle a size folded to an integer constant but + not an integer constant expression. */ + if (!size_int_const) + { + /* If this is a file scope declaration of an + ordinary identifier, this is invalid code; + diagnosing it here and not subsequently + treating the type as variable-length avoids + more confusing diagnostics later. */ + if ((decl_context == NORMAL || decl_context == FIELD) + && current_scope == file_scope) + pedwarn (input_location, 0, + "variably modified %qE at file scope", + name); + else + this_size_varies = size_varies = true; + warn_variable_length_array (name, size); + } + } + else if ((decl_context == NORMAL || decl_context == FIELD) + && current_scope == file_scope) + { + error_at (loc, "variably modified %qE at file scope", name); + size = integer_one_node; + } + else + { + /* Make sure the array size remains visibly + nonconstant even if it is (eg) a const variable + with known value. */ + this_size_varies = size_varies = true; + warn_variable_length_array (name, size); + } + + if (integer_zerop (size) && !this_size_varies) + { + /* A zero-length array cannot be represented with + an unsigned index type, which is what we'll + get with build_index_type. Create an + open-ended range instead. */ + itype = build_range_type (sizetype, size, NULL_TREE); + } + else + { + /* Arrange for the SAVE_EXPR on the inside of the + MINUS_EXPR, which allows the -1 to get folded + with the +1 that happens when building TYPE_SIZE. */ + if (size_varies) + size = c_variable_size (size); + if (this_size_varies && TREE_CODE (size) == INTEGER_CST) + size = build2 (COMPOUND_EXPR, TREE_TYPE (size), + integer_zero_node, size); + + /* Compute the maximum valid index, that is, size + - 1. Do the calculation in index_type, so that + if it is a variable the computations will be + done in the proper mode. */ + itype = fold_build2_loc (loc, MINUS_EXPR, index_type, + convert (index_type, size), + convert (index_type, + size_one_node)); + + /* If that overflowed, the array is too big. ??? + While a size of INT_MAX+1 technically shouldn't + cause an overflow (because we subtract 1), the + overflow is recorded during the conversion to + index_type, before the subtraction. Handling + this case seems like an unnecessary + complication. */ + if (TREE_CODE (itype) == INTEGER_CST + && TREE_OVERFLOW (itype)) + { + if (name) + error_at (loc, "size of array %qE is too large", + name); + else + error_at (loc, "size of unnamed array is too large"); + type = error_mark_node; + continue; + } + + itype = build_index_type (itype); + } + if (this_size_varies) + { + if (*expr) + *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size), + *expr, size); + else + *expr = size; + *expr_const_operands &= size_maybe_const; + } + } + else if (decl_context == FIELD) + { + bool flexible_array_member = false; + if (array_parm_vla_unspec_p) + /* Field names can in fact have function prototype + scope so [*] is disallowed here through making + the field variably modified, not through being + something other than a declaration with function + prototype scope. */ + size_varies = true; + else + { + const struct c_declarator *t = declarator; + while (t->kind == cdk_attrs) + t = t->declarator; + flexible_array_member = (t->kind == cdk_id); + } + if (flexible_array_member + && pedantic && !flag_isoc99 && !in_system_header) + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support flexible array members"); + + /* ISO C99 Flexible array members are effectively + identical to GCC's zero-length array extension. */ + if (flexible_array_member || array_parm_vla_unspec_p) + itype = build_range_type (sizetype, size_zero_node, + NULL_TREE); + } + else if (decl_context == PARM) + { + if (array_parm_vla_unspec_p) + { + itype = build_range_type (sizetype, size_zero_node, NULL_TREE); + size_varies = true; + } + } + else if (decl_context == TYPENAME) + { + if (array_parm_vla_unspec_p) + { + /* C99 6.7.5.2p4 */ + warning (0, "%<[*]%> not in a declaration"); + /* We use this to avoid messing up with incomplete + array types of the same type, that would + otherwise be modified below. */ + itype = build_range_type (sizetype, size_zero_node, + NULL_TREE); + size_varies = true; + } + } + + /* Complain about arrays of incomplete types. */ + if (!COMPLETE_TYPE_P (type)) + { + error_at (loc, "array type has incomplete element type"); + type = error_mark_node; + } + else + /* When itype is NULL, a shared incomplete array type is + returned for all array of a given type. Elsewhere we + make sure we don't complete that type before copying + it, but here we want to make sure we don't ever + modify the shared type, so we gcc_assert (itype) + below. */ + { + addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals); + if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type)) + type = build_qualified_type (type, + ENCODE_QUAL_ADDR_SPACE (as)); + + type = build_array_type (type, itype); + } + + if (type != error_mark_node) + { + if (size_varies) + { + /* It is ok to modify type here even if itype is + NULL: if size_varies, we're in a + multi-dimensional array and the inner type has + variable size, so the enclosing shared array type + must too. */ + if (size && TREE_CODE (size) == INTEGER_CST) + type + = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); + C_TYPE_VARIABLE_SIZE (type) = 1; + } + + /* The GCC extension for zero-length arrays differs from + ISO flexible array members in that sizeof yields + zero. */ + if (size && integer_zerop (size)) + { + gcc_assert (itype); + TYPE_SIZE (type) = bitsize_zero_node; + TYPE_SIZE_UNIT (type) = size_zero_node; + } + if (array_parm_vla_unspec_p) + { + gcc_assert (itype); + /* The type is complete. C99 6.7.5.2p4 */ + TYPE_SIZE (type) = bitsize_zero_node; + TYPE_SIZE_UNIT (type) = size_zero_node; + } + } + + if (decl_context != PARM + && (array_ptr_quals != TYPE_UNQUALIFIED + || array_ptr_attrs != NULL_TREE + || array_parm_static)) + { + error_at (loc, "static or type qualifiers in non-parameter array declarator"); + array_ptr_quals = TYPE_UNQUALIFIED; + array_ptr_attrs = NULL_TREE; + array_parm_static = 0; + } + break; + } + case cdk_function: + { + /* Say it's a definition only for the declarator closest + to the identifier, apart possibly from some + attributes. */ + bool really_funcdef = false; + tree arg_types; + if (funcdef_flag) + { + const struct c_declarator *t = declarator->declarator; + while (t->kind == cdk_attrs) + t = t->declarator; + really_funcdef = (t->kind == cdk_id); + } + + /* Declaring a function type. Make sure we have a valid + type for the function to return. */ + if (type == error_mark_node) + continue; + + size_varies = false; + + /* Warn about some types functions can't return. */ + if (TREE_CODE (type) == FUNCTION_TYPE) + { + if (name) + error_at (loc, "%qE declared as function returning a " + "function", name); + else + error_at (loc, "type name declared as function " + "returning a function"); + type = integer_type_node; + } + if (TREE_CODE (type) == ARRAY_TYPE) + { + if (name) + error_at (loc, "%qE declared as function returning an array", + name); + else + error_at (loc, "type name declared as function returning " + "an array"); + type = integer_type_node; + } + errmsg = targetm.invalid_return_type (type); + if (errmsg) + { + error (errmsg); + type = integer_type_node; + } + + /* Construct the function type and go to the next + inner layer of declarator. */ + arg_info = declarator->u.arg_info; + arg_types = grokparms (arg_info, really_funcdef); + if (really_funcdef) + put_pending_sizes (arg_info->pending_sizes); + + /* Type qualifiers before the return type of the function + qualify the return type, not the function type. */ + if (type_quals) + { + /* Type qualifiers on a function return type are + normally permitted by the standard but have no + effect, so give a warning at -Wreturn-type. + Qualifiers on a void return type are banned on + function definitions in ISO C; GCC used to used + them for noreturn functions. */ + if (VOID_TYPE_P (type) && really_funcdef) + pedwarn (loc, 0, + "function definition has qualified void return type"); + else + warning_at (loc, OPT_Wignored_qualifiers, + "type qualifiers ignored on function return type"); + + type = c_build_qualified_type (type, type_quals); + } + type_quals = TYPE_UNQUALIFIED; #ifndef noCbC if ( declspecs->typespec_word == cts_CbC_code ) @@ -4595,89 +5522,142 @@ type = build_function_type (type, arg_types); } - declarator = declarator->declarator; - - /* Set the TYPE_CONTEXTs for each tagged type which is local to - the formal parameter list of this FUNCTION_TYPE to point to - the FUNCTION_TYPE node itself. */ - { - tree link; - - for (link = arg_info->tags; - link; - link = TREE_CHAIN (link)) - TYPE_CONTEXT (TREE_VALUE (link)) = type; - } - break; - } - case cdk_pointer: - { - /* Merge any constancy or volatility into the target type - for the pointer. */ - - if (pedantic && TREE_CODE (type) == FUNCTION_TYPE - && type_quals) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids qualified function types"); - if (type_quals) - type = c_build_qualified_type (type, type_quals); - size_varies = 0; - - /* When the pointed-to type involves components of variable size, - care must be taken to ensure that the size evaluation code is - emitted early enough to dominate all the possible later uses - and late enough for the variables on which it depends to have - been assigned. - - This is expected to happen automatically when the pointed-to - type has a name/declaration of it's own, but special attention - is required if the type is anonymous. - - We handle the NORMAL and FIELD contexts here by attaching an - artificial TYPE_DECL to such pointed-to type. This forces the - sizes evaluation at a safe point and ensures it is not deferred - until e.g. within a deeper conditional context. - - We expect nothing to be needed here for PARM or TYPENAME. - Pushing a TYPE_DECL at this point for TYPENAME would actually - be incorrect, as we might be in the middle of an expression - with side effects on the pointed-to type size "arguments" prior - to the pointer declaration point and the fake TYPE_DECL in the - enclosing context would force the size evaluation prior to the - side effects. */ - - if (!TYPE_NAME (type) - && (decl_context == NORMAL || decl_context == FIELD) - && variably_modified_type_p (type, NULL_TREE)) - { - tree decl = build_decl (TYPE_DECL, NULL_TREE, type); - DECL_ARTIFICIAL (decl) = 1; - pushdecl (decl); - finish_decl (decl, NULL_TREE, NULL_TREE); - TYPE_NAME (type) = decl; - } - - type = build_pointer_type (type); - - /* Process type qualifiers (such as const or volatile) - that were given inside the `*'. */ - type_quals = declarator->u.pointer_quals; - - declarator = declarator->declarator; - break; - } - default: - gcc_unreachable (); - } + declarator = declarator->declarator; + + /* Set the TYPE_CONTEXTs for each tagged type which is local to + the formal parameter list of this FUNCTION_TYPE to point to + the FUNCTION_TYPE node itself. */ + { + tree link; + + for (link = arg_info->tags; + link; + link = TREE_CHAIN (link)) + TYPE_CONTEXT (TREE_VALUE (link)) = type; + } + break; + } + case cdk_pointer: + { + /* Merge any constancy or volatility into the target type + for the pointer. */ + + if (pedantic && TREE_CODE (type) == FUNCTION_TYPE + && type_quals) + pedwarn (loc, OPT_pedantic, + "ISO C forbids qualified function types"); + if (type_quals) + type = c_build_qualified_type (type, type_quals); + size_varies = false; + + /* When the pointed-to type involves components of variable size, + care must be taken to ensure that the size evaluation code is + emitted early enough to dominate all the possible later uses + and late enough for the variables on which it depends to have + been assigned. + + This is expected to happen automatically when the pointed-to + type has a name/declaration of it's own, but special attention + is required if the type is anonymous. + + We handle the NORMAL and FIELD contexts here by attaching an + artificial TYPE_DECL to such pointed-to type. This forces the + sizes evaluation at a safe point and ensures it is not deferred + until e.g. within a deeper conditional context. + + We expect nothing to be needed here for PARM or TYPENAME. + Pushing a TYPE_DECL at this point for TYPENAME would actually + be incorrect, as we might be in the middle of an expression + with side effects on the pointed-to type size "arguments" prior + to the pointer declaration point and the fake TYPE_DECL in the + enclosing context would force the size evaluation prior to the + side effects. */ + + if (!TYPE_NAME (type) + && (decl_context == NORMAL || decl_context == FIELD) + && variably_modified_type_p (type, NULL_TREE)) + { + tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); + DECL_ARTIFICIAL (decl) = 1; + pushdecl (decl); + finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); + TYPE_NAME (type) = decl; + } + + type = build_pointer_type (type); + + /* Process type qualifiers (such as const or volatile) + that were given inside the `*'. */ + type_quals = declarator->u.pointer_quals; + + declarator = declarator->declarator; + break; + } + default: + gcc_unreachable (); + } } *decl_attrs = chainon (returned_attrs, *decl_attrs); /* Now TYPE has the actual type, apart from any qualifiers in TYPE_QUALS. */ + /* Warn about address space used for things other than static memory or + pointers. */ + address_space = DECODE_QUAL_ADDR_SPACE (type_quals); + if (!ADDR_SPACE_GENERIC_P (address_space)) + { + if (decl_context == NORMAL) + { + switch (storage_class) + { + case csc_auto: + error ("%qs combined with %<auto%> qualifier for %qE", + c_addr_space_name (address_space), name); + break; + case csc_register: + error ("%qs combined with %<register%> qualifier for %qE", + c_addr_space_name (address_space), name); + break; + case csc_none: + if (current_function_scope) + { + error ("%qs specified for auto variable %qE", + c_addr_space_name (address_space), name); + break; + } + break; + case csc_static: + case csc_extern: + case csc_typedef: + break; + default: + gcc_unreachable (); + } + } + else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE) + { + if (name) + error ("%qs specified for parameter %qE", + c_addr_space_name (address_space), name); + else + error ("%qs specified for unnamed parameter", + c_addr_space_name (address_space)); + } + else if (decl_context == FIELD) + { + if (name) + error ("%qs specified for structure field %qE", + c_addr_space_name (address_space), name); + else + error ("%qs specified for structure field", + c_addr_space_name (address_space)); + } + } + /* Check the type and width of a bit-field. */ if (bitfield) - check_bitfield_type_and_width (&type, width, orig_name); + check_bitfield_type_and_width (&type, width, name); /* Did array size calculations overflow? */ @@ -4686,9 +5666,12 @@ && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST && TREE_OVERFLOW (TYPE_SIZE_UNIT (type))) { - error ("size of array %qs is too large", name); + if (name) + error_at (loc, "size of array %qE is too large", name); + else + error_at (loc, "size of unnamed array is too large"); /* If we proceed with the array type as it is, we'll eventually - crash in tree_low_cst(). */ + crash in tree_low_cst(). */ type = error_mark_node; } @@ -4698,17 +5681,37 @@ { tree decl; if (pedantic && TREE_CODE (type) == FUNCTION_TYPE - && type_quals) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids qualified function types"); + && type_quals) + pedwarn (loc, OPT_pedantic, + "ISO C forbids qualified function types"); if (type_quals) - type = c_build_qualified_type (type, type_quals); - decl = build_decl (TYPE_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; + type = c_build_qualified_type (type, type_quals); + decl = build_decl (declarator->id_loc, + TYPE_DECL, declarator->u.id, type); if (declspecs->explicit_signed_p) - C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; + C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; if (declspecs->inline_p) - pedwarn (input_location, 0,"typedef %q+D declared %<inline%>", decl); + pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl); + + if (warn_cxx_compat && declarator->u.id != NULL_TREE) + { + struct c_binding *b = I_TAG_BINDING (declarator->u.id); + + if (b != NULL + && b->decl != NULL_TREE + && (B_IN_CURRENT_SCOPE (b) + || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) + && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) + { + warning_at (declarator->id_loc, OPT_Wc___compat, + ("using %qD as both a typedef and a tag is " + "invalid in C++"), + decl); + if (b->locus != UNKNOWN_LOCATION) + inform (b->locus, "originally defined here"); + } + } + return decl; } @@ -4718,15 +5721,15 @@ if (decl_context == TYPENAME) { /* Note that the grammar rejects storage classes in typenames - and fields. */ + and fields. */ gcc_assert (storage_class == csc_none && !threadp - && !declspecs->inline_p); + && !declspecs->inline_p); if (pedantic && TREE_CODE (type) == FUNCTION_TYPE - && type_quals) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids const or volatile function types"); + && type_quals) + pedwarn (loc, OPT_pedantic, + "ISO C forbids const or volatile function types"); if (type_quals) - type = c_build_qualified_type (type, type_quals); + type = c_build_qualified_type (type, type_quals); return type; } @@ -4734,8 +5737,8 @@ && variably_modified_type_p (type, NULL_TREE)) { /* C99 6.7.2.1p8 */ - pedwarn (input_location, OPT_pedantic, - "a member of a structure or union cannot have a variably modified type"); + pedwarn (loc, OPT_pedantic, "a member of a structure or union cannot " + "have a variably modified type"); } /* Aside from typedefs and type names (handle above), @@ -4746,12 +5749,12 @@ if (VOID_TYPE_P (type) && decl_context != PARM && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) - && (storage_class == csc_extern - || (current_scope == file_scope - && !(storage_class == csc_static - || storage_class == csc_register))))) - { - error ("variable or field %qs declared void", name); + && (storage_class == csc_extern + || (current_scope == file_scope + && !(storage_class == csc_static + || storage_class == csc_register))))) + { + error_at (loc, "variable or field %qE declared void", name); type = integer_type_node; } @@ -4763,235 +5766,246 @@ if (decl_context == PARM) { - tree promoted_type; - - /* A parameter declared as an array of T is really a pointer to T. - One declared as a function is really a pointer to a function. */ - - if (TREE_CODE (type) == ARRAY_TYPE) - { - /* Transfer const-ness of array into that of type pointed to. */ - type = TREE_TYPE (type); - if (type_quals) - type = c_build_qualified_type (type, type_quals); - type = build_pointer_type (type); - type_quals = array_ptr_quals; - if (type_quals) - type = c_build_qualified_type (type, type_quals); - - /* We don't yet implement attributes in this context. */ - if (array_ptr_attrs != NULL_TREE) - warning (OPT_Wattributes, - "attributes in parameter array declarator ignored"); - - size_varies = 0; - } - else if (TREE_CODE (type) == FUNCTION_TYPE) - { - if (type_quals) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids qualified function types"); - if (type_quals) - type = c_build_qualified_type (type, type_quals); - type = build_pointer_type (type); - type_quals = TYPE_UNQUALIFIED; - } - else if (type_quals) - type = c_build_qualified_type (type, type_quals); - - decl = build_decl (PARM_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; - if (size_varies) - C_DECL_VARIABLE_SIZE (decl) = 1; - - /* Compute the type actually passed in the parmlist, - for the case where there is no prototype. - (For example, shorts and chars are passed as ints.) - When there is a prototype, this is overridden later. */ - - if (type == error_mark_node) - promoted_type = type; - else - promoted_type = c_type_promotes_to (type); - - DECL_ARG_TYPE (decl) = promoted_type; - if (declspecs->inline_p) - pedwarn (input_location, 0, "parameter %q+D declared %<inline%>", decl); + tree promoted_type; + + /* A parameter declared as an array of T is really a pointer to T. + One declared as a function is really a pointer to a function. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Transfer const-ness of array into that of type pointed to. */ + type = TREE_TYPE (type); + if (type_quals) + type = c_build_qualified_type (type, type_quals); + type = build_pointer_type (type); + type_quals = array_ptr_quals; + if (type_quals) + type = c_build_qualified_type (type, type_quals); + + /* We don't yet implement attributes in this context. */ + if (array_ptr_attrs != NULL_TREE) + warning_at (loc, OPT_Wattributes, + "attributes in parameter array declarator ignored"); + + size_varies = false; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + if (type_quals) + pedwarn (loc, OPT_pedantic, + "ISO C forbids qualified function types"); + if (type_quals) + type = c_build_qualified_type (type, type_quals); + type = build_pointer_type (type); + type_quals = TYPE_UNQUALIFIED; + } + else if (type_quals) + type = c_build_qualified_type (type, type_quals); + + decl = build_decl (declarator->id_loc, + PARM_DECL, declarator->u.id, type); + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; + + /* Compute the type actually passed in the parmlist, + for the case where there is no prototype. + (For example, shorts and chars are passed as ints.) + When there is a prototype, this is overridden later. */ + + if (type == error_mark_node) + promoted_type = type; + else + promoted_type = c_type_promotes_to (type); + + DECL_ARG_TYPE (decl) = promoted_type; + if (declspecs->inline_p) + pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl); } else if (decl_context == FIELD) { - /* Note that the grammar rejects storage classes in typenames - and fields. */ - gcc_assert (storage_class == csc_none && !threadp - && !declspecs->inline_p); - - /* Structure field. It may not be a function. */ - - if (TREE_CODE (type) == FUNCTION_TYPE) - { - error ("field %qs declared as a function", name); - type = build_pointer_type (type); - } - else if (TREE_CODE (type) != ERROR_MARK - && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) - { - error ("field %qs has incomplete type", name); - type = error_mark_node; - } - type = c_build_qualified_type (type, type_quals); - decl = build_decl (FIELD_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; - DECL_NONADDRESSABLE_P (decl) = bitfield; - if (bitfield && !declarator->u.id) - TREE_NO_WARNING (decl) = 1; - - if (size_varies) - C_DECL_VARIABLE_SIZE (decl) = 1; + /* Note that the grammar rejects storage classes in typenames + and fields. */ + gcc_assert (storage_class == csc_none && !threadp + && !declspecs->inline_p); + + /* Structure field. It may not be a function. */ + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error_at (loc, "field %qE declared as a function", name); + type = build_pointer_type (type); + } + else if (TREE_CODE (type) != ERROR_MARK + && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) + { + if (name) + error_at (loc, "field %qE has incomplete type", name); + else + error_at (loc, "unnamed field has incomplete type"); + type = error_mark_node; + } + type = c_build_qualified_type (type, type_quals); + decl = build_decl (declarator->id_loc, + FIELD_DECL, declarator->u.id, type); + DECL_NONADDRESSABLE_P (decl) = bitfield; + if (bitfield && !declarator->u.id) + TREE_NO_WARNING (decl) = 1; + + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; } else if (TREE_CODE (type) == FUNCTION_TYPE) { - if (storage_class == csc_register || threadp) - { - error ("invalid storage class for function %qs", name); - } - else if (current_scope != file_scope) - { - /* Function declaration not at file scope. Storage - classes other than `extern' are not allowed, C99 - 6.7.1p5, and `extern' makes no difference. However, - GCC allows 'auto', perhaps with 'inline', to support - nested functions. */ - if (storage_class == csc_auto) - pedwarn (input_location, OPT_pedantic, "invalid storage class for function %qs", name); - else if (storage_class == csc_static) - { - error ("invalid storage class for function %qs", name); - if (funcdef_flag) - storage_class = declspecs->storage_class = csc_none; - else - return 0; - } - } - - decl = build_decl (FUNCTION_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; - decl = build_decl_attribute_variant (decl, decl_attr); - - if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) - pedwarn (input_location, OPT_pedantic, - "ISO C forbids qualified function types"); - - /* GNU C interprets a volatile-qualified function type to indicate - that the function does not return. */ - if ((type_quals & TYPE_QUAL_VOLATILE) - && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) - warning (0, "%<noreturn%> function returns non-void value"); - - /* Every function declaration is an external reference - (DECL_EXTERNAL) except for those which are not at file - scope and are explicitly declared "auto". This is - forbidden by standard C (C99 6.7.1p5) and is interpreted by - GCC to signify a forward declaration of a nested function. */ - if (storage_class == csc_auto && current_scope != file_scope) - DECL_EXTERNAL (decl) = 0; - /* In C99, a function which is declared 'inline' with 'extern' - is not an external reference (which is confusing). It - means that the later definition of the function must be output - in this file, C99 6.7.4p6. In GNU C89, a function declared - 'extern inline' is an external reference. */ - else if (declspecs->inline_p && storage_class != csc_static) - DECL_EXTERNAL (decl) = ((storage_class == csc_extern) - == flag_gnu89_inline); - else - DECL_EXTERNAL (decl) = !initialized; - - /* Record absence of global scope for `static' or `auto'. */ - TREE_PUBLIC (decl) - = !(storage_class == csc_static || storage_class == csc_auto); - - /* For a function definition, record the argument information - block where store_parm_decls will look for it. */ - if (funcdef_flag) - current_function_arg_info = arg_info; - - if (declspecs->default_int_p) - C_FUNCTION_IMPLICIT_INT (decl) = 1; - - /* Record presence of `inline', if it is reasonable. */ - if (flag_hosted && MAIN_NAME_P (declarator->u.id)) - { - if (declspecs->inline_p) - pedwarn (input_location, 0, "cannot inline function %<main%>"); - } - else if (declspecs->inline_p) - /* Record that the function is declared `inline'. */ - DECL_DECLARED_INLINE_P (decl) = 1; + if (storage_class == csc_register || threadp) + { + error_at (loc, "invalid storage class for function %qE", name); + } + else if (current_scope != file_scope) + { + /* Function declaration not at file scope. Storage + classes other than `extern' are not allowed, C99 + 6.7.1p5, and `extern' makes no difference. However, + GCC allows 'auto', perhaps with 'inline', to support + nested functions. */ + if (storage_class == csc_auto) + pedwarn (loc, OPT_pedantic, + "invalid storage class for function %qE", name); + else if (storage_class == csc_static) + { + error_at (loc, "invalid storage class for function %qE", name); + if (funcdef_flag) + storage_class = declspecs->storage_class = csc_none; + else + return 0; + } + } + + decl = build_decl (declarator->id_loc, + FUNCTION_DECL, declarator->u.id, type); + decl = build_decl_attribute_variant (decl, decl_attr); + + if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) + pedwarn (loc, OPT_pedantic, + "ISO C forbids qualified function types"); + + /* GNU C interprets a volatile-qualified function type to indicate + that the function does not return. */ + if ((type_quals & TYPE_QUAL_VOLATILE) + && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) + warning_at (loc, 0, "%<noreturn%> function returns non-void value"); + + /* Every function declaration is an external reference + (DECL_EXTERNAL) except for those which are not at file + scope and are explicitly declared "auto". This is + forbidden by standard C (C99 6.7.1p5) and is interpreted by + GCC to signify a forward declaration of a nested function. */ + if (storage_class == csc_auto && current_scope != file_scope) + DECL_EXTERNAL (decl) = 0; + /* In C99, a function which is declared 'inline' with 'extern' + is not an external reference (which is confusing). It + means that the later definition of the function must be output + in this file, C99 6.7.4p6. In GNU C89, a function declared + 'extern inline' is an external reference. */ + else if (declspecs->inline_p && storage_class != csc_static) + DECL_EXTERNAL (decl) = ((storage_class == csc_extern) + == flag_gnu89_inline); + else + DECL_EXTERNAL (decl) = !initialized; + + /* Record absence of global scope for `static' or `auto'. */ + TREE_PUBLIC (decl) + = !(storage_class == csc_static || storage_class == csc_auto); + + /* For a function definition, record the argument information + block where store_parm_decls will look for it. */ + if (funcdef_flag) + current_function_arg_info = arg_info; + + if (declspecs->default_int_p) + C_FUNCTION_IMPLICIT_INT (decl) = 1; + + /* Record presence of `inline', if it is reasonable. */ + if (flag_hosted && MAIN_NAME_P (declarator->u.id)) + { + if (declspecs->inline_p) + pedwarn (loc, 0, "cannot inline function %<main%>"); + } + else if (declspecs->inline_p) + /* Record that the function is declared `inline'. */ + DECL_DECLARED_INLINE_P (decl) = 1; } else { - /* It's a variable. */ - /* An uninitialized decl with `extern' is a reference. */ - int extern_ref = !initialized && storage_class == csc_extern; - - type = c_build_qualified_type (type, type_quals); - - /* C99 6.2.2p7: It is invalid (compile-time undefined - behavior) to create an 'extern' declaration for a - variable if there is a global declaration that is - 'static' and the global declaration is not visible. - (If the static declaration _is_ currently visible, - the 'extern' declaration is taken to refer to that decl.) */ - if (extern_ref && current_scope != file_scope) - { - tree global_decl = identifier_global_value (declarator->u.id); - tree visible_decl = lookup_name (declarator->u.id); - - if (global_decl - && global_decl != visible_decl - && TREE_CODE (global_decl) == VAR_DECL - && !TREE_PUBLIC (global_decl)) - error ("variable previously declared %<static%> redeclared " - "%<extern%>"); - } - - decl = build_decl (VAR_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; - if (size_varies) - C_DECL_VARIABLE_SIZE (decl) = 1; - - if (declspecs->inline_p) - pedwarn (input_location, 0, "variable %q+D declared %<inline%>", decl); - - /* At file scope, an initialized extern declaration may follow - a static declaration. In that case, DECL_EXTERNAL will be - reset later in start_decl. */ - DECL_EXTERNAL (decl) = (storage_class == csc_extern); - - /* At file scope, the presence of a `static' or `register' storage - class specifier, or the absence of all storage class specifiers - makes this declaration a definition (perhaps tentative). Also, - the absence of `static' makes it public. */ - if (current_scope == file_scope) - { - TREE_PUBLIC (decl) = storage_class != csc_static; - TREE_STATIC (decl) = !extern_ref; - } - /* Not at file scope, only `static' makes a static definition. */ - else - { - TREE_STATIC (decl) = (storage_class == csc_static); - TREE_PUBLIC (decl) = extern_ref; - } - - if (threadp) - DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); + /* It's a variable. */ + /* An uninitialized decl with `extern' is a reference. */ + int extern_ref = !initialized && storage_class == csc_extern; + + type = c_build_qualified_type (type, type_quals); + + /* C99 6.2.2p7: It is invalid (compile-time undefined + behavior) to create an 'extern' declaration for a + variable if there is a global declaration that is + 'static' and the global declaration is not visible. + (If the static declaration _is_ currently visible, + the 'extern' declaration is taken to refer to that decl.) */ + if (extern_ref && current_scope != file_scope) + { + tree global_decl = identifier_global_value (declarator->u.id); + tree visible_decl = lookup_name (declarator->u.id); + + if (global_decl + && global_decl != visible_decl + && TREE_CODE (global_decl) == VAR_DECL + && !TREE_PUBLIC (global_decl)) + error_at (loc, "variable previously declared %<static%> " + "redeclared %<extern%>"); } - if (storage_class == csc_extern - && variably_modified_type_p (type, NULL_TREE)) + decl = build_decl (declarator->id_loc, + VAR_DECL, declarator->u.id, type); + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; + + if (declspecs->inline_p) + pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl); + + /* At file scope, an initialized extern declaration may follow + a static declaration. In that case, DECL_EXTERNAL will be + reset later in start_decl. */ + DECL_EXTERNAL (decl) = (storage_class == csc_extern); + + /* At file scope, the presence of a `static' or `register' storage + class specifier, or the absence of all storage class specifiers + makes this declaration a definition (perhaps tentative). Also, + the absence of `static' makes it public. */ + if (current_scope == file_scope) { - /* C99 6.7.5.2p2 */ - error ("object with variably modified type must have no linkage"); + TREE_PUBLIC (decl) = storage_class != csc_static; + TREE_STATIC (decl) = !extern_ref; + } + /* Not at file scope, only `static' makes a static definition. */ + else + { + TREE_STATIC (decl) = (storage_class == csc_static); + TREE_PUBLIC (decl) = extern_ref; + } + + if (threadp) + DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); + } + + if ((storage_class == csc_extern + || (storage_class == csc_none + && TREE_CODE (type) == FUNCTION_TYPE + && !funcdef_flag)) + && variably_modified_type_p (type, NULL_TREE)) + { + /* C99 6.7.5.2p2 */ + if (TREE_CODE (type) == FUNCTION_TYPE) + error_at (loc, "non-nested function with variably modified type"); + else + error_at (loc, "object with variably modified type must have " + "no linkage"); } /* Record `register' declaration for warnings on & @@ -4999,8 +6013,8 @@ if (storage_class == csc_register) { - C_DECL_REGISTER (decl) = 1; - DECL_REGISTER (decl) = 1; + C_DECL_REGISTER (decl) = 1; + DECL_REGISTER (decl) = 1; } /* Record constancy and volatility. */ @@ -5011,23 +6025,36 @@ will be ignored, and would even crash the compiler. Of course, this only makes sense on VAR,PARM, and RESULT decl's. */ if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)) - && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL - || TREE_CODE (decl) == RESULT_DECL)) + && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL)) { - /* It is not an error for a structure with volatile fields to - be declared register, but reset DECL_REGISTER since it - cannot actually go in a register. */ - int was_reg = C_DECL_REGISTER (decl); - C_DECL_REGISTER (decl) = 0; - DECL_REGISTER (decl) = 0; - c_mark_addressable (decl); - C_DECL_REGISTER (decl) = was_reg; + /* It is not an error for a structure with volatile fields to + be declared register, but reset DECL_REGISTER since it + cannot actually go in a register. */ + int was_reg = C_DECL_REGISTER (decl); + C_DECL_REGISTER (decl) = 0; + DECL_REGISTER (decl) = 0; + c_mark_addressable (decl); + C_DECL_REGISTER (decl) = was_reg; } /* This is the earliest point at which we might know the assembler name of a variable. Thus, if it's known before this, die horribly. */ gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); + if (warn_cxx_compat + && TREE_CODE (decl) == VAR_DECL + && TREE_PUBLIC (decl) + && TREE_STATIC (decl) + && (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) + && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE) + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, + ("non-local variable %qD with anonymous type is " + "questionable in C++"), + decl); + return decl; } } @@ -5060,7 +6087,7 @@ if (arg_types == 0 && !funcdef_flag && !in_system_header) warning (OPT_Wstrict_prototypes, - "function declaration isn%'t a prototype"); + "function declaration isn%'t a prototype"); if (arg_types == error_mark_node) return 0; /* don't set TYPE_ARG_TYPES in this case */ @@ -5068,7 +6095,7 @@ else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE) { if (!funcdef_flag) - pedwarn (input_location, 0, "parameter names (without types) in function declaration"); + pedwarn (input_location, 0, "parameter names (without types) in function declaration"); arg_info->parms = arg_info->types; arg_info->types = 0; @@ -5078,52 +6105,65 @@ { tree parm, type, typelt; unsigned int parmno; + const char *errmsg; /* If there is a parameter of incomplete type in a definition, - this is an error. In a declaration this is valid, and a - struct or union type may be completed later, before any calls - or definition of the function. In the case where the tag was - first declared within the parameter list, a warning has - already been given. If a parameter has void type, then - however the function cannot be defined or called, so - warn. */ + this is an error. In a declaration this is valid, and a + struct or union type may be completed later, before any calls + or definition of the function. In the case where the tag was + first declared within the parameter list, a warning has + already been given. If a parameter has void type, then + however the function cannot be defined or called, so + warn. */ for (parm = arg_info->parms, typelt = arg_types, parmno = 1; - parm; - parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) - { - type = TREE_VALUE (typelt); - if (type == error_mark_node) - continue; - - if (!COMPLETE_TYPE_P (type)) - { - if (funcdef_flag) - { - if (DECL_NAME (parm)) - error ("parameter %u (%q+D) has incomplete type", - parmno, parm); - else - error ("%Jparameter %u has incomplete type", - parm, parmno); - - TREE_VALUE (typelt) = error_mark_node; - TREE_TYPE (parm) = error_mark_node; - } - else if (VOID_TYPE_P (type)) - { - if (DECL_NAME (parm)) - warning (0, "parameter %u (%q+D) has void type", - parmno, parm); - else - warning (0, "%Jparameter %u has void type", - parm, parmno); - } - } - - if (DECL_NAME (parm) && TREE_USED (parm)) - warn_if_shadowing (parm); - } + parm; + parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) + { + type = TREE_VALUE (typelt); + if (type == error_mark_node) + continue; + + if (!COMPLETE_TYPE_P (type)) + { + if (funcdef_flag) + { + if (DECL_NAME (parm)) + error_at (input_location, + "parameter %u (%q+D) has incomplete type", + parmno, parm); + else + error_at (DECL_SOURCE_LOCATION (parm), + "parameter %u has incomplete type", + parmno); + + TREE_VALUE (typelt) = error_mark_node; + TREE_TYPE (parm) = error_mark_node; + } + else if (VOID_TYPE_P (type)) + { + if (DECL_NAME (parm)) + warning_at (input_location, 0, + "parameter %u (%q+D) has void type", + parmno, parm); + else + warning_at (DECL_SOURCE_LOCATION (parm), 0, + "parameter %u has void type", + parmno); + } + } + + errmsg = targetm.invalid_parameter_type (type); + if (errmsg) + { + error (errmsg); + TREE_VALUE (typelt) = error_mark_node; + TREE_TYPE (parm) = error_mark_node; + } + + if (DECL_NAME (parm) && TREE_USED (parm)) + warn_if_shadowing (parm); + } return arg_types; } } @@ -5141,7 +6181,7 @@ { struct c_binding *b = current_scope->bindings; struct c_arg_info *arg_info = XOBNEW (&parser_obstack, - struct c_arg_info); + struct c_arg_info); tree parms = 0; tree tags = 0; tree types = 0; @@ -5170,19 +6210,19 @@ (by 'const' or 'volatile'), or has a storage class specifier ('register'), then the behavior is undefined; issue an error. Typedefs for 'void' are OK (see DR#157). */ - if (b->prev == 0 /* one binding */ + if (b->prev == 0 /* one binding */ && TREE_CODE (b->decl) == PARM_DECL /* which is a parameter */ && !DECL_NAME (b->decl) /* anonymous */ && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */ { if (TREE_THIS_VOLATILE (b->decl) - || TREE_READONLY (b->decl) - || C_DECL_REGISTER (b->decl)) - error ("%<void%> as only parameter may not be qualified"); + || TREE_READONLY (b->decl) + || C_DECL_REGISTER (b->decl)) + error ("%<void%> as only parameter may not be qualified"); /* There cannot be an ellipsis. */ if (ellipsis) - error ("%<void%> must be the only parameter"); + error ("%<void%> must be the only parameter"); arg_info->types = void_list_node; return arg_info; @@ -5200,108 +6240,108 @@ const char *keyword; switch (TREE_CODE (decl)) - { - case PARM_DECL: - if (b->id) - { - gcc_assert (I_SYMBOL_BINDING (b->id) == b); - I_SYMBOL_BINDING (b->id) = b->shadowed; - } - - /* Check for forward decls that never got their actual decl. */ - if (TREE_ASM_WRITTEN (decl)) - error ("parameter %q+D has just a forward declaration", decl); - /* Check for (..., void, ...) and issue an error. */ - else if (VOID_TYPE_P (type) && !DECL_NAME (decl)) - { - if (!gave_void_only_once_err) - { - error ("%<void%> must be the only parameter"); - gave_void_only_once_err = true; - } - } - else - { - /* Valid parameter, add it to the list. */ - TREE_CHAIN (decl) = parms; - parms = decl; - - /* Since there is a prototype, args are passed in their - declared types. The back end may override this later. */ - DECL_ARG_TYPE (decl) = type; - types = tree_cons (0, type, types); - } - break; - - case ENUMERAL_TYPE: keyword = "enum"; goto tag; - case UNION_TYPE: keyword = "union"; goto tag; - case RECORD_TYPE: keyword = "struct"; goto tag; - tag: - /* Types may not have tag-names, in which case the type - appears in the bindings list with b->id NULL. */ - if (b->id) - { - gcc_assert (I_TAG_BINDING (b->id) == b); - I_TAG_BINDING (b->id) = b->shadowed; - } - - /* Warn about any struct, union or enum tags defined in a - parameter list. The scope of such types is limited to - the parameter list, which is rarely if ever desirable - (it's impossible to call such a function with type- - correct arguments). An anonymous union parm type is - meaningful as a GNU extension, so don't warn for that. */ - if (TREE_CODE (decl) != UNION_TYPE || b->id != 0) - { - if (b->id) - /* The %s will be one of 'struct', 'union', or 'enum'. */ - warning (0, "%<%s %E%> declared inside parameter list", - keyword, b->id); - else - /* The %s will be one of 'struct', 'union', or 'enum'. */ - warning (0, "anonymous %s declared inside parameter list", - keyword); - - if (!explained_incomplete_types) - { - warning (0, "its scope is only this definition or declaration," - " which is probably not what you want"); - explained_incomplete_types = true; - } - } - - tags = tree_cons (b->id, decl, tags); - break; - - case CONST_DECL: - case TYPE_DECL: - case FUNCTION_DECL: - /* CONST_DECLs appear here when we have an embedded enum, - and TYPE_DECLs appear here when we have an embedded struct - or union. No warnings for this - we already warned about the - type itself. FUNCTION_DECLs appear when there is an implicit - function declaration in the parameter list. */ - - TREE_CHAIN (decl) = others; - others = decl; - /* fall through */ - - case ERROR_MARK: - /* error_mark_node appears here when we have an undeclared - variable. Just throw it away. */ - if (b->id) - { - gcc_assert (I_SYMBOL_BINDING (b->id) == b); - I_SYMBOL_BINDING (b->id) = b->shadowed; - } - break; - - /* Other things that might be encountered. */ - case LABEL_DECL: - case VAR_DECL: - default: - gcc_unreachable (); - } + { + case PARM_DECL: + if (b->id) + { + gcc_assert (I_SYMBOL_BINDING (b->id) == b); + I_SYMBOL_BINDING (b->id) = b->shadowed; + } + + /* Check for forward decls that never got their actual decl. */ + if (TREE_ASM_WRITTEN (decl)) + error ("parameter %q+D has just a forward declaration", decl); + /* Check for (..., void, ...) and issue an error. */ + else if (VOID_TYPE_P (type) && !DECL_NAME (decl)) + { + if (!gave_void_only_once_err) + { + error ("%<void%> must be the only parameter"); + gave_void_only_once_err = true; + } + } + else + { + /* Valid parameter, add it to the list. */ + TREE_CHAIN (decl) = parms; + parms = decl; + + /* Since there is a prototype, args are passed in their + declared types. The back end may override this later. */ + DECL_ARG_TYPE (decl) = type; + types = tree_cons (0, type, types); + } + break; + + case ENUMERAL_TYPE: keyword = "enum"; goto tag; + case UNION_TYPE: keyword = "union"; goto tag; + case RECORD_TYPE: keyword = "struct"; goto tag; + tag: + /* Types may not have tag-names, in which case the type + appears in the bindings list with b->id NULL. */ + if (b->id) + { + gcc_assert (I_TAG_BINDING (b->id) == b); + I_TAG_BINDING (b->id) = b->shadowed; + } + + /* Warn about any struct, union or enum tags defined in a + parameter list. The scope of such types is limited to + the parameter list, which is rarely if ever desirable + (it's impossible to call such a function with type- + correct arguments). An anonymous union parm type is + meaningful as a GNU extension, so don't warn for that. */ + if (TREE_CODE (decl) != UNION_TYPE || b->id != 0) + { + if (b->id) + /* The %s will be one of 'struct', 'union', or 'enum'. */ + warning (0, "%<%s %E%> declared inside parameter list", + keyword, b->id); + else + /* The %s will be one of 'struct', 'union', or 'enum'. */ + warning (0, "anonymous %s declared inside parameter list", + keyword); + + if (!explained_incomplete_types) + { + warning (0, "its scope is only this definition or declaration," + " which is probably not what you want"); + explained_incomplete_types = true; + } + } + + tags = tree_cons (b->id, decl, tags); + break; + + case CONST_DECL: + case TYPE_DECL: + case FUNCTION_DECL: + /* CONST_DECLs appear here when we have an embedded enum, + and TYPE_DECLs appear here when we have an embedded struct + or union. No warnings for this - we already warned about the + type itself. FUNCTION_DECLs appear when there is an implicit + function declaration in the parameter list. */ + + TREE_CHAIN (decl) = others; + others = decl; + /* fall through */ + + case ERROR_MARK: + /* error_mark_node appears here when we have an undeclared + variable. Just throw it away. */ + if (b->id) + { + gcc_assert (I_SYMBOL_BINDING (b->id) == b); + I_SYMBOL_BINDING (b->id) = b->shadowed; + } + break; + + /* Other things that might be encountered. */ + case LABEL_DECL: + case VAR_DECL: + default: + gcc_unreachable (); + } b = free_binding_and_advance (b); } @@ -5315,17 +6355,24 @@ } /* Get the struct, enum or union (CODE says which) with tag NAME. - Define the tag as a forward-reference if it is not defined. - Return a c_typespec structure for the type specifier. */ + Define the tag as a forward-reference with location LOC if it is + not defined. Return a c_typespec structure for the type + specifier. */ struct c_typespec -parser_xref_tag (enum tree_code code, tree name) +parser_xref_tag (location_t loc, enum tree_code code, tree name) { struct c_typespec ret; + tree ref; + location_t refloc; + + ret.expr = NULL_TREE; + ret.expr_const_operands = true; + /* If a cross reference is requested, look up the type already defined for this tag and return it. */ - tree ref = lookup_tag (code, name, 0); + ref = lookup_tag (code, name, 0, &refloc); /* If this is the right type of tag, return what we found. (This reference will be shadowed by shadow_tag later if appropriate.) If this is the wrong type of tag, do not return it. If it was the @@ -5340,6 +6387,35 @@ ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref); if (ref && TREE_CODE (ref) == code) { + if (C_TYPE_DEFINED_IN_STRUCT (ref) + && loc != UNKNOWN_LOCATION + && warn_cxx_compat) + { + switch (code) + { + case ENUMERAL_TYPE: + warning_at (loc, OPT_Wc___compat, + ("enum type defined in struct or union " + "is not visible in C++")); + inform (refloc, "enum type defined here"); + break; + case RECORD_TYPE: + warning_at (loc, OPT_Wc___compat, + ("struct defined in struct or union " + "is not visible in C++")); + inform (refloc, "struct defined here"); + break; + case UNION_TYPE: + warning_at (loc, OPT_Wc___compat, + ("union defined in struct or union " + "is not visible in C++")); + inform (refloc, "union defined here"); + break; + default: + gcc_unreachable(); + } + } + ret.spec = ref; return ret; } @@ -5353,7 +6429,7 @@ if (code == ENUMERAL_TYPE) { /* Give the type a default layout like unsigned int - to avoid crashing if it does not get defined. */ + to avoid crashing if it does not get defined. */ SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node)); TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); TYPE_USER_ALIGN (ref) = 0; @@ -5363,7 +6439,7 @@ TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); } - pushtag (name, ref); + pushtag (loc, name, ref); ret.spec = ref; return ret; @@ -5376,43 +6452,56 @@ tree xref_tag (enum tree_code code, tree name) { - return parser_xref_tag (code, name).spec; + return parser_xref_tag (input_location, code, name).spec; } /* Make sure that the tag NAME is defined *in the current scope* at least as a forward reference. - CODE says which kind of tag NAME ought to be. */ + LOC is the location of the struct's definition. + CODE says which kind of tag NAME ought to be. + + This stores the current value of the file static STRUCT_PARSE_INFO + in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a + new c_struct_parse_info structure. The old value of + STRUCT_PARSE_INFO is restored in finish_struct. */ tree -start_struct (enum tree_code code, tree name) +start_struct (location_t loc, enum tree_code code, tree name, + struct c_struct_parse_info **enclosing_struct_parse_info) { /* If there is already a tag defined at this scope (as a forward reference), just return it. */ - tree ref = 0; - - if (name != 0) - ref = lookup_tag (code, name, 1); + tree ref = NULL_TREE; + location_t refloc = UNKNOWN_LOCATION; + + if (name != NULL_TREE) + ref = lookup_tag (code, name, 1, &refloc); if (ref && TREE_CODE (ref) == code) { if (TYPE_SIZE (ref)) - { - if (code == UNION_TYPE) - error ("redefinition of %<union %E%>", name); - else - error ("redefinition of %<struct %E%>", name); - /* Don't create structures using a name already in use. */ - ref = NULL_TREE; - } + { + if (code == UNION_TYPE) + error_at (loc, "redefinition of %<union %E%>", name); + else + error_at (loc, "redefinition of %<struct %E%>", name); + if (refloc != UNKNOWN_LOCATION) + inform (refloc, "originally defined here"); + /* Don't create structures using a name already in use. */ + ref = NULL_TREE; + } else if (C_TYPE_BEING_DEFINED (ref)) - { - if (code == UNION_TYPE) - error ("nested redefinition of %<union %E%>", name); - else - error ("nested redefinition of %<struct %E%>", name); - /* Don't create structures that contain themselves. */ - ref = NULL_TREE; - } + { + if (code == UNION_TYPE) + error_at (loc, "nested redefinition of %<union %E%>", name); + else + error_at (loc, "nested redefinition of %<struct %E%>", name); + /* Don't bother to report "originally defined here" for a + nested redefinition; the original definition should be + obvious. */ + /* Don't create structures that contain themselves. */ + ref = NULL_TREE; + } } /* Otherwise create a forward-reference just so the tag is in scope. */ @@ -5420,11 +6509,29 @@ if (ref == NULL_TREE || TREE_CODE (ref) != code) { ref = make_node (code); - pushtag (name, ref); + pushtag (loc, name, ref); } C_TYPE_BEING_DEFINED (ref) = 1; TYPE_PACKED (ref) = flag_pack_struct; + + *enclosing_struct_parse_info = struct_parse_info; + struct_parse_info = XNEW (struct c_struct_parse_info); + struct_parse_info->struct_types = VEC_alloc (tree, heap, 0); + struct_parse_info->fields = VEC_alloc (c_binding_ptr, heap, 0); + struct_parse_info->typedefs_seen = VEC_alloc (tree, heap, 0); + + /* FIXME: This will issue a warning for a use of a type defined + within a statement expr used within sizeof, et. al. This is not + terribly serious as C++ doesn't permit statement exprs within + sizeof anyhow. */ + if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof)) + warning_at (loc, OPT_Wc___compat, + "defining type in %qs expression is invalid in C++", + (in_sizeof + ? "sizeof" + : (in_typeof ? "typeof" : "alignof"))); + return ref; } @@ -5441,8 +6548,8 @@ tree grokfield (location_t loc, - struct c_declarator *declarator, struct c_declspecs *declspecs, - tree width, tree *decl_attrs) + struct c_declarator *declarator, struct c_declspecs *declspecs, + tree width, tree *decl_attrs) { tree value; @@ -5451,55 +6558,74 @@ { /* This is an unnamed decl. - If we have something of the form "union { list } ;" then this - is the anonymous union extension. Similarly for struct. - - If this is something of the form "struct foo;", then - If MS extensions are enabled, this is handled as an - anonymous struct. - Otherwise this is a forward declaration of a structure tag. - - If this is something of the form "foo;" and foo is a TYPE_DECL, then - If MS extensions are enabled and foo names a structure, then - again this is an anonymous struct. - Otherwise this is an error. - - Oh what a horrid tangled web we weave. I wonder if MS consciously - took this from Plan 9 or if it was an accident of implementation - that took root before someone noticed the bug... */ + If we have something of the form "union { list } ;" then this + is the anonymous union extension. Similarly for struct. + + If this is something of the form "struct foo;", then + If MS extensions are enabled, this is handled as an + anonymous struct. + Otherwise this is a forward declaration of a structure tag. + + If this is something of the form "foo;" and foo is a TYPE_DECL, then + If MS extensions are enabled and foo names a structure, then + again this is an anonymous struct. + Otherwise this is an error. + + Oh what a horrid tangled web we weave. I wonder if MS consciously + took this from Plan 9 or if it was an accident of implementation + that took root before someone noticed the bug... */ tree type = declspecs->type; bool type_ok = (TREE_CODE (type) == RECORD_TYPE - || TREE_CODE (type) == UNION_TYPE); + || TREE_CODE (type) == UNION_TYPE); bool ok = false; if (type_ok - && (flag_ms_extensions || !declspecs->typedef_p)) - { - if (flag_ms_extensions) - ok = true; - else if (flag_iso) - ok = false; - else if (TYPE_NAME (type) == NULL) - ok = true; - else - ok = false; - } + && (flag_ms_extensions || !declspecs->typedef_p)) + { + if (flag_ms_extensions) + ok = true; + else if (flag_iso) + ok = false; + else if (TYPE_NAME (type) == NULL) + ok = true; + else + ok = false; + } if (!ok) - { - pedwarn (loc, 0, "declaration does not declare anything"); - return NULL_TREE; - } + { + pedwarn (loc, 0, "declaration does not declare anything"); + return NULL_TREE; + } pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions"); } value = grokdeclarator (declarator, declspecs, FIELD, false, - width ? &width : NULL, decl_attrs, - DEPRECATED_NORMAL); - - finish_decl (value, NULL_TREE, NULL_TREE); + width ? &width : NULL, decl_attrs, NULL, NULL, + DEPRECATED_NORMAL); + + finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE); DECL_INITIAL (value) = width; + if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE) + { + /* If we currently have a binding for this field, set the + in_struct field in the binding, so that we warn about lookups + which find it. */ + struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value)); + if (b != NULL) + { + /* If the in_struct field is not yet set, push it on a list + to be cleared when this struct is finished. */ + if (!b->in_struct) + { + VEC_safe_push (c_binding_ptr, heap, + struct_parse_info->fields, b); + b->in_struct = 1; + } + } + } + return value; } @@ -5529,15 +6655,15 @@ if (timeout > 0) { for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x)) - if (DECL_NAME (x)) - { - for (y = fieldlist; y != x; y = TREE_CHAIN (y)) - if (DECL_NAME (y) == DECL_NAME (x)) - { - error ("duplicate member %q+D", x); - DECL_NAME (x) = NULL_TREE; - } - } + if (DECL_NAME (x)) + { + for (y = fieldlist; y != x; y = TREE_CHAIN (y)) + if (DECL_NAME (y) == DECL_NAME (x)) + { + error ("duplicate member %q+D", x); + DECL_NAME (x) = NULL_TREE; + } + } } else { @@ -5545,27 +6671,91 @@ void **slot; for (x = fieldlist; x ; x = TREE_CHAIN (x)) - if ((y = DECL_NAME (x)) != 0) - { - slot = htab_find_slot (htab, y, INSERT); - if (*slot) - { - error ("duplicate member %q+D", x); - DECL_NAME (x) = NULL_TREE; - } - *slot = y; - } + if ((y = DECL_NAME (x)) != 0) + { + slot = htab_find_slot (htab, y, INSERT); + if (*slot) + { + error ("duplicate member %q+D", x); + DECL_NAME (x) = NULL_TREE; + } + *slot = y; + } htab_delete (htab); } } +/* Finish up struct info used by -Wc++-compat. */ + +static void +warn_cxx_compat_finish_struct (tree fieldlist) +{ + unsigned int ix; + tree x; + struct c_binding *b; + + /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in + the current struct. We do this now at the end of the struct + because the flag is used to issue visibility warnings, and we + only want to issue those warnings if the type is referenced + outside of the struct declaration. */ + for (ix = 0; VEC_iterate (tree, struct_parse_info->struct_types, ix, x); ++ix) + C_TYPE_DEFINED_IN_STRUCT (x) = 1; + + /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of + typedefs used when declaring fields in this struct. If the name + of any of the fields is also a typedef name then the struct would + not parse in C++, because the C++ lookup rules say that the + typedef name would be looked up in the context of the struct, and + would thus be the field rather than the typedef. */ + if (!VEC_empty (tree, struct_parse_info->typedefs_seen) + && fieldlist != NULL_TREE) + { + /* Use a pointer_set using the name of the typedef. We can use + a pointer_set because identifiers are interned. */ + struct pointer_set_t *tset = pointer_set_create (); + + for (ix = 0; + VEC_iterate (tree, struct_parse_info->typedefs_seen, ix, x); + ++ix) + pointer_set_insert (tset, DECL_NAME (x)); + + for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x)) + { + if (pointer_set_contains (tset, DECL_NAME (x))) + { + warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat, + ("using %qD as both field and typedef name is " + "invalid in C++"), + x); + /* FIXME: It would be nice to report the location where + the typedef name is used. */ + } + } + + pointer_set_destroy (tset); + } + + /* For each field which has a binding and which was not defined in + an enclosing struct, clear the in_struct field. */ + for (ix = 0; + VEC_iterate (c_binding_ptr, struct_parse_info->fields, ix, b); + ++ix) + b->in_struct = 0; +} + /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. + LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. FIELDLIST is a chain of FIELD_DECL nodes for the fields. - ATTRIBUTES are attributes to be applied to the structure. */ + ATTRIBUTES are attributes to be applied to the structure. + + ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when + the struct was started. */ tree -finish_struct (tree t, tree fieldlist, tree attributes) +finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, + struct c_struct_parse_info *enclosing_struct_parse_info) { tree x; bool toplevel = file_scope == current_scope; @@ -5581,26 +6771,26 @@ if (pedantic) { for (x = fieldlist; x; x = TREE_CHAIN (x)) - if (DECL_NAME (x) != 0) - break; + if (DECL_NAME (x) != 0) + break; if (x == 0) - { - if (TREE_CODE (t) == UNION_TYPE) - { - if (fieldlist) - pedwarn (input_location, OPT_pedantic, "union has no named members"); - else - pedwarn (input_location, OPT_pedantic, "union has no members"); - } - else - { - if (fieldlist) - pedwarn (input_location, OPT_pedantic, "struct has no named members"); - else - pedwarn (input_location, OPT_pedantic, "struct has no members"); - } - } + { + if (TREE_CODE (t) == UNION_TYPE) + { + if (fieldlist) + pedwarn (loc, OPT_pedantic, "union has no named members"); + else + pedwarn (loc, OPT_pedantic, "union has no members"); + } + else + { + if (fieldlist) + pedwarn (loc, OPT_pedantic, "struct has no named members"); + else + pedwarn (loc, OPT_pedantic, "struct has no members"); + } + } } /* Install struct as DECL_CONTEXT of each field decl. @@ -5614,76 +6804,79 @@ for (x = fieldlist; x; x = TREE_CHAIN (x)) { if (TREE_TYPE (x) == error_mark_node) - continue; + continue; DECL_CONTEXT (x) = t; /* If any field is const, the structure type is pseudo-const. */ if (TREE_READONLY (x)) - C_TYPE_FIELDS_READONLY (t) = 1; + C_TYPE_FIELDS_READONLY (t) = 1; else - { - /* A field that is pseudo-const makes the structure likewise. */ - tree t1 = TREE_TYPE (x); - while (TREE_CODE (t1) == ARRAY_TYPE) - t1 = TREE_TYPE (t1); - if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) - && C_TYPE_FIELDS_READONLY (t1)) - C_TYPE_FIELDS_READONLY (t) = 1; - } + { + /* A field that is pseudo-const makes the structure likewise. */ + tree t1 = TREE_TYPE (x); + while (TREE_CODE (t1) == ARRAY_TYPE) + t1 = TREE_TYPE (t1); + if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (t1)) + C_TYPE_FIELDS_READONLY (t) = 1; + } /* Any field that is volatile means variables of this type must be - treated in some ways as volatile. */ + treated in some ways as volatile. */ if (TREE_THIS_VOLATILE (x)) - C_TYPE_FIELDS_VOLATILE (t) = 1; + C_TYPE_FIELDS_VOLATILE (t) = 1; /* Any field of nominal variable size implies structure is too. */ if (C_DECL_VARIABLE_SIZE (x)) - C_TYPE_VARIABLE_SIZE (t) = 1; + C_TYPE_VARIABLE_SIZE (t) = 1; if (DECL_INITIAL (x)) - { - unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1); - DECL_SIZE (x) = bitsize_int (width); - DECL_BIT_FIELD (x) = 1; - SET_DECL_C_BIT_FIELD (x); - } + { + unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1); + DECL_SIZE (x) = bitsize_int (width); + DECL_BIT_FIELD (x) = 1; + SET_DECL_C_BIT_FIELD (x); + } if (TYPE_PACKED (t) - && (DECL_BIT_FIELD (x) - || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)) - DECL_PACKED (x) = 1; + && (DECL_BIT_FIELD (x) + || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)) + DECL_PACKED (x) = 1; /* Detect flexible array member in an invalid context. */ if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE - && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE - && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE - && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) - { - if (TREE_CODE (t) == UNION_TYPE) - { - error ("%Jflexible array member in union", x); - TREE_TYPE (x) = error_mark_node; - } - else if (TREE_CHAIN (x) != NULL_TREE) - { - error ("%Jflexible array member not at end of struct", x); - TREE_TYPE (x) = error_mark_node; - } - else if (!saw_named_field) - { - error ("%Jflexible array member in otherwise empty struct", x); - TREE_TYPE (x) = error_mark_node; - } - } - - if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE - && flexible_array_type_p (TREE_TYPE (x))) - pedwarn (input_location, OPT_pedantic, - "%Jinvalid use of structure with flexible array member", x); + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) + { + if (TREE_CODE (t) == UNION_TYPE) + { + error_at (DECL_SOURCE_LOCATION (x), + "flexible array member in union"); + TREE_TYPE (x) = error_mark_node; + } + else if (TREE_CHAIN (x) != NULL_TREE) + { + error_at (DECL_SOURCE_LOCATION (x), + "flexible array member not at end of struct"); + TREE_TYPE (x) = error_mark_node; + } + else if (!saw_named_field) + { + error_at (DECL_SOURCE_LOCATION (x), + "flexible array member in otherwise empty struct"); + TREE_TYPE (x) = error_mark_node; + } + } + + if (pedantic && TREE_CODE (t) == RECORD_TYPE + && flexible_array_type_p (TREE_TYPE (x))) + pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic, + "invalid use of structure with flexible array member"); if (DECL_NAME (x)) - saw_named_field = 1; + saw_named_field = 1; } detect_field_duplicates (fieldlist); @@ -5700,21 +6893,21 @@ tree *fieldlistp = &fieldlist; while (*fieldlistp) if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp) - && TREE_TYPE (*fieldlistp) != error_mark_node) - { - unsigned HOST_WIDE_INT width - = tree_low_cst (DECL_INITIAL (*fieldlistp), 1); - tree type = TREE_TYPE (*fieldlistp); - if (width != TYPE_PRECISION (type)) - { - TREE_TYPE (*fieldlistp) - = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type)); - DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); - } - DECL_INITIAL (*fieldlistp) = 0; - } + && TREE_TYPE (*fieldlistp) != error_mark_node) + { + unsigned HOST_WIDE_INT width + = tree_low_cst (DECL_INITIAL (*fieldlistp), 1); + tree type = TREE_TYPE (*fieldlistp); + if (width != TYPE_PRECISION (type)) + { + TREE_TYPE (*fieldlistp) + = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type)); + DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); + } + DECL_INITIAL (*fieldlistp) = 0; + } else - fieldlistp = &TREE_CHAIN (*fieldlistp); + fieldlistp = &TREE_CHAIN (*fieldlistp); } /* Now we have the truly final field list. @@ -5730,46 +6923,46 @@ for (x = fieldlist; x; x = TREE_CHAIN (x)) { - if (len > 15 || DECL_NAME (x) == NULL) - break; - len += 1; + if (len > 15 || DECL_NAME (x) == NULL) + break; + len += 1; } if (len > 15) { - tree *field_array; - struct lang_type *space; - struct sorted_fields_type *space2; - - len += list_length (x); - - /* Use the same allocation policy here that make_node uses, to - ensure that this lives as long as the rest of the struct decl. - All decls in an inline function need to be saved. */ - - space = GGC_CNEW (struct lang_type); - space2 = GGC_NEWVAR (struct sorted_fields_type, - sizeof (struct sorted_fields_type) + len * sizeof (tree)); - - len = 0; - space->s = space2; - field_array = &space2->elts[0]; - for (x = fieldlist; x; x = TREE_CHAIN (x)) - { - field_array[len++] = x; - - /* If there is anonymous struct or union, break out of the loop. */ - if (DECL_NAME (x) == NULL) - break; - } - /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */ - if (x == NULL) - { - TYPE_LANG_SPECIFIC (t) = space; - TYPE_LANG_SPECIFIC (t)->s->len = len; - field_array = TYPE_LANG_SPECIFIC (t)->s->elts; - qsort (field_array, len, sizeof (tree), field_decl_cmp); - } + tree *field_array; + struct lang_type *space; + struct sorted_fields_type *space2; + + len += list_length (x); + + /* Use the same allocation policy here that make_node uses, to + ensure that this lives as long as the rest of the struct decl. + All decls in an inline function need to be saved. */ + + space = GGC_CNEW (struct lang_type); + space2 = GGC_NEWVAR (struct sorted_fields_type, + sizeof (struct sorted_fields_type) + len * sizeof (tree)); + + len = 0; + space->s = space2; + field_array = &space2->elts[0]; + for (x = fieldlist; x; x = TREE_CHAIN (x)) + { + field_array[len++] = x; + + /* If there is anonymous struct or union, break out of the loop. */ + if (DECL_NAME (x) == NULL) + break; + } + /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */ + if (x == NULL) + { + TYPE_LANG_SPECIFIC (t) = space; + TYPE_LANG_SPECIFIC (t)->s->len = len; + field_array = TYPE_LANG_SPECIFIC (t)->s->elts; + qsort (field_array, len, sizeof (tree), field_decl_cmp); + } } } @@ -5789,7 +6982,7 @@ && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) { TYPE_TRANSPARENT_UNION (t) = 0; - warning (0, "union cannot be made transparent"); + warning_at (loc, 0, "union cannot be made transparent"); } /* If this structure or union completes the type of any previous @@ -5800,19 +6993,24 @@ { tree decl = TREE_VALUE (x); if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) - layout_array_type (TREE_TYPE (decl)); + layout_array_type (TREE_TYPE (decl)); if (TREE_CODE (decl) != TYPE_DECL) - { - layout_decl (decl, 0); - if (c_dialect_objc ()) - objc_check_decl (decl); - rest_of_decl_compilation (decl, toplevel, 0); - if (!toplevel) - expand_decl (decl); - } + { + layout_decl (decl, 0); + if (c_dialect_objc ()) + objc_check_decl (decl); + rest_of_decl_compilation (decl, toplevel, 0); + if (!toplevel) + expand_decl (decl); + } } C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0; + /* Update type location to the one of the definition, instead of e.g. + a forward declaration. */ + if (TYPE_STUB_DECL (t)) + DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc; + /* Finish debugging output for this type. */ rest_of_type_compilation (t, toplevel); @@ -5820,7 +7018,25 @@ parsing parameters, then arrange for the size of a variable sized type to be bound now. */ if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE)) - add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t))); + add_stmt (build_stmt (loc, + DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t))); + + if (warn_cxx_compat) + warn_cxx_compat_finish_struct (fieldlist); + + VEC_free (tree, heap, struct_parse_info->struct_types); + VEC_free (c_binding_ptr, heap, struct_parse_info->fields); + VEC_free (tree, heap, struct_parse_info->typedefs_seen); + XDELETE (struct_parse_info); + + struct_parse_info = enclosing_struct_parse_info; + + /* If this struct is defined inside a struct, add it to + struct_types. */ + if (warn_cxx_compat + && struct_parse_info != NULL + && !in_sizeof && !in_typeof && !in_alignof) + VEC_safe_push (tree, heap, struct_parse_info->struct_types, t); return t; } @@ -5837,40 +7053,44 @@ /* Begin compiling the definition of an enumeration type. NAME is its name (or null if anonymous). + LOC is the enum's location. Returns the type object, as yet incomplete. Also records info about it so that build_enumerator may be used to declare the individual values as they are read. */ tree -start_enum (struct c_enum_contents *the_enum, tree name) -{ - tree enumtype = 0; +start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) +{ + tree enumtype = NULL_TREE; + location_t enumloc = UNKNOWN_LOCATION; /* If this is the real definition for a previous forward reference, fill in the contents in the same object that used to be the forward reference. */ - if (name != 0) - enumtype = lookup_tag (ENUMERAL_TYPE, name, 1); + if (name != NULL_TREE) + enumtype = lookup_tag (ENUMERAL_TYPE, name, 1, &enumloc); if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) { enumtype = make_node (ENUMERAL_TYPE); - pushtag (name, enumtype); + pushtag (loc, name, enumtype); } if (C_TYPE_BEING_DEFINED (enumtype)) - error ("nested redefinition of %<enum %E%>", name); + error_at (loc, "nested redefinition of %<enum %E%>", name); C_TYPE_BEING_DEFINED (enumtype) = 1; if (TYPE_VALUES (enumtype) != 0) { /* This enum is a named one that has been declared already. */ - error ("redeclaration of %<enum %E%>", name); + error_at (loc, "redeclaration of %<enum %E%>", name); + if (enumloc != UNKNOWN_LOCATION) + inform (enumloc, "originally defined here"); /* Completely replace its old definition. - The old enumerators remain defined, however. */ + The old enumerators remain defined, however. */ TYPE_VALUES (enumtype) = 0; } @@ -5880,6 +7100,16 @@ if (flag_short_enums) TYPE_PACKED (enumtype) = 1; + /* FIXME: This will issue a warning for a use of a type defined + within sizeof in a statement expr. This is not terribly serious + as C++ doesn't permit statement exprs within sizeof anyhow. */ + if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof)) + warning_at (loc, OPT_Wc___compat, + "defining type in %qs expression is invalid in C++", + (in_sizeof + ? "sizeof" + : (in_typeof ? "typeof" : "alignof"))); + return enumtype; } @@ -5908,13 +7138,13 @@ { minnode = maxnode = TREE_VALUE (values); for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) - { - tree value = TREE_VALUE (pair); - if (tree_int_cst_lt (maxnode, value)) - maxnode = value; - if (tree_int_cst_lt (value, minnode)) - minnode = value; - } + { + tree value = TREE_VALUE (pair); + if (tree_int_cst_lt (maxnode, value)) + maxnode = value; + if (tree_int_cst_lt (value, minnode)) + minnode = value; + } } /* Construct the final type of this enumeration. It is the same @@ -5923,16 +7153,16 @@ the values are negative. */ unsign = (tree_int_cst_sgn (minnode) >= 0); precision = MAX (tree_int_cst_min_precision (minnode, unsign), - tree_int_cst_min_precision (maxnode, unsign)); + tree_int_cst_min_precision (maxnode, unsign)); if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node)) { tem = c_common_type_for_size (precision, unsign); if (tem == NULL) - { - warning (0, "enumeration values exceed range of largest integer"); - tem = long_long_integer_type_node; - } + { + warning (0, "enumeration values exceed range of largest integer"); + tem = long_long_integer_type_node; + } } else tem = unsign ? unsigned_type_node : integer_type_node; @@ -5947,7 +7177,7 @@ if (TYPE_PRECISION (enumtype)) { if (precision > TYPE_PRECISION (enumtype)) - error ("specified mode too small for enumeral values"); + error ("specified mode too small for enumeral values"); } else TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem); @@ -5957,36 +7187,36 @@ if (values != error_mark_node) { /* Change the type of the enumerators to be the enum type. We - need to do this irrespective of the size of the enum, for - proper type checking. Replace the DECL_INITIALs of the - enumerators, and the value slots of the list, with copies - that have the enum type; they cannot be modified in place - because they may be shared (e.g. integer_zero_node) Finally, - change the purpose slots to point to the names of the decls. */ + need to do this irrespective of the size of the enum, for + proper type checking. Replace the DECL_INITIALs of the + enumerators, and the value slots of the list, with copies + that have the enum type; they cannot be modified in place + because they may be shared (e.g. integer_zero_node) Finally, + change the purpose slots to point to the names of the decls. */ for (pair = values; pair; pair = TREE_CHAIN (pair)) - { - tree enu = TREE_PURPOSE (pair); - tree ini = DECL_INITIAL (enu); - - TREE_TYPE (enu) = enumtype; - - /* The ISO C Standard mandates enumerators to have type int, - even though the underlying type of an enum type is - unspecified. However, GCC allows enumerators of any - integer type as an extensions. build_enumerator() - converts any enumerators that fit in an int to type int, - to avoid promotions to unsigned types when comparing - integers with enumerators that fit in the int range. - When -pedantic is given, build_enumerator() would have - already warned about those that don't fit. Here we - convert the rest to the enumerator type. */ - if (TREE_TYPE (ini) != integer_type_node) - ini = convert (enumtype, ini); - - DECL_INITIAL (enu) = ini; - TREE_PURPOSE (pair) = DECL_NAME (enu); - TREE_VALUE (pair) = ini; - } + { + tree enu = TREE_PURPOSE (pair); + tree ini = DECL_INITIAL (enu); + + TREE_TYPE (enu) = enumtype; + + /* The ISO C Standard mandates enumerators to have type int, + even though the underlying type of an enum type is + unspecified. However, GCC allows enumerators of any + integer type as an extensions. build_enumerator() + converts any enumerators that fit in an int to type int, + to avoid promotions to unsigned types when comparing + integers with enumerators that fit in the int range. + When -pedantic is given, build_enumerator() would have + already warned about those that don't fit. Here we + convert the rest to the enumerator type. */ + if (TREE_TYPE (ini) != integer_type_node) + ini = convert (enumtype, ini); + + DECL_INITIAL (enu) = ini; + TREE_PURPOSE (pair) = DECL_NAME (enu); + TREE_VALUE (pair) = ini; + } TYPE_VALUES (enumtype) = values; } @@ -6002,7 +7232,7 @@ for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) { if (tem == enumtype) - continue; + continue; TYPE_VALUES (tem) = TYPE_VALUES (enumtype); TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); @@ -6019,17 +7249,25 @@ /* Finish debugging output for this type. */ rest_of_type_compilation (enumtype, toplevel); + /* If this enum is defined inside a struct, add it to + struct_types. */ + if (warn_cxx_compat + && struct_parse_info != NULL + && !in_sizeof && !in_typeof && !in_alignof) + VEC_safe_push (tree, heap, struct_parse_info->struct_types, enumtype); + return enumtype; } /* Build and install a CONST_DECL for one value of the current enumeration type (one that was begun with start_enum). + LOC is the location of the enumerator. Return a tree-list containing the CONST_DECL and its value. Assignment of sequential values by default is handled here. */ tree -build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, - location_t value_loc) +build_enumerator (location_t loc, + struct c_enum_contents *the_enum, tree name, tree value) { tree decl, type; @@ -6038,20 +7276,37 @@ if (value != 0) { /* Don't issue more errors for error_mark_node (i.e. an - undeclared identifier) - just ignore the value expression. */ + undeclared identifier) - just ignore the value expression. */ if (value == error_mark_node) - value = 0; - else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)) - || TREE_CODE (value) != INTEGER_CST) - { - error ("enumerator value for %qE is not an integer constant", name); - value = 0; - } + value = 0; + else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) + { + error_at (loc, "enumerator value for %qE is not an integer constant", + name); + value = 0; + } else - { - value = default_conversion (value); - constant_expression_warning (value); - } + { + if (TREE_CODE (value) != INTEGER_CST) + { + value = c_fully_fold (value, false, NULL); + if (TREE_CODE (value) == INTEGER_CST) + pedwarn (loc, OPT_pedantic, + "enumerator value for %qE is not an integer " + "constant expression", name); + } + if (TREE_CODE (value) != INTEGER_CST) + { + error ("enumerator value for %qE is not an integer constant", + name); + value = 0; + } + else + { + value = default_conversion (value); + constant_expression_warning (value); + } + } } /* Default based on previous value. */ @@ -6061,15 +7316,15 @@ { value = the_enum->enum_next_value; if (the_enum->enum_overflow) - error ("overflow in enumeration values"); + error_at (loc, "overflow in enumeration values"); } /* Even though the underlying type of an enum is unspecified, the type of enumeration constants is explicitly defined as int (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as an extension. */ else if (!int_fits_type_p (value, integer_type_node)) - pedwarn (value_loc, OPT_pedantic, - "ISO C restricts enumerator values to range of %<int%>"); + pedwarn (loc, OPT_pedantic, + "ISO C restricts enumerator values to range of %<int%>"); /* The ISO C Standard mandates enumerators to have type int, even though the underlying type of an enum type is unspecified. @@ -6087,19 +7342,19 @@ the_enum->enum_next_value = build_binary_op (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location, - PLUS_EXPR, value, integer_one_node, 0); + PLUS_EXPR, value, integer_one_node, 0); the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value); /* Now create a declaration for the enum value name. */ type = TREE_TYPE (value); type = c_common_type_for_size (MAX (TYPE_PRECISION (type), - TYPE_PRECISION (integer_type_node)), - (TYPE_PRECISION (type) - >= TYPE_PRECISION (integer_type_node) - && TYPE_UNSIGNED (type))); - - decl = build_decl (CONST_DECL, name, type); + TYPE_PRECISION (integer_type_node)), + (TYPE_PRECISION (type) + >= TYPE_PRECISION (integer_type_node) + && TYPE_UNSIGNED (type))); + + decl = build_decl (loc, CONST_DECL, name, type); DECL_INITIAL (decl) = convert (type, value); pushdecl (decl); @@ -6129,7 +7384,7 @@ unsigned int size; if (type == void_type_node) - break; + break; type_size = TYPE_SIZE (type); size = TREE_INT_CST_LOW (type_size); @@ -6183,12 +7438,11 @@ int start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, - tree attributes) + tree attributes) { tree decl1, old_decl; tree restype, resdecl; - struct c_label_context_se *nstack_se; - struct c_label_context_vm *nstack_vm; + location_t loc; current_function_returns_value = 0; /* Assume, until we see it does. */ current_function_returns_null = 0; @@ -6196,33 +7450,20 @@ warn_about_return_type = 0; c_switch_stack = NULL; - nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se); - nstack_se->labels_def = NULL; - nstack_se->labels_used = NULL; - nstack_se->next = label_context_stack_se; - label_context_stack_se = nstack_se; - - nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm); - nstack_vm->labels_def = NULL; - nstack_vm->labels_used = NULL; - nstack_vm->scope = 0; - nstack_vm->next = label_context_stack_vm; - label_context_stack_vm = nstack_vm; - /* Indicate no valid break/continue context by setting these variables to some non-null, non-label value. We'll notice and emit the proper error message in c_finish_bc_stmt. */ c_break_label = c_cont_label = size_zero_node; decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, - &attributes, DEPRECATED_NORMAL); + &attributes, NULL, NULL, DEPRECATED_NORMAL); #ifndef noCbC cbc_return_f = NULL_TREE; cbc_env = NULL_TREE; if ( declspecs->typespec_word == cts_CbC_code ) { - cbc_set_codesegment(decl1); + cbc_set_codesegment(decl1); //CbC_IS_CODE_SEGMENT(TREE_TYPE(decl1)) = 1; } #endif @@ -6230,46 +7471,45 @@ /* If the declarator is not suitable for a function definition, cause a syntax error. */ if (decl1 == 0) - { - label_context_stack_se = label_context_stack_se->next; - label_context_stack_vm = label_context_stack_vm->next; - return 0; - } + return 0; + + loc = DECL_SOURCE_LOCATION (decl1); decl_attributes (&decl1, attributes, 0); if (DECL_DECLARED_INLINE_P (decl1) && DECL_UNINLINABLE (decl1) && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1))) - warning (OPT_Wattributes, "inline function %q+D given attribute noinline", - decl1); + warning_at (loc, OPT_Wattributes, + "inline function %qD given attribute noinline", + decl1); /* Handle gnu_inline attribute. */ if (declspecs->inline_p && !flag_gnu89_inline && TREE_CODE (decl1) == FUNCTION_DECL && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1)) - || current_function_decl)) + || current_function_decl)) { if (declspecs->storage_class != csc_static) - DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1); + DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1); } announce_function (decl1); if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) { - error ("return type is an incomplete type"); + error_at (loc, "return type is an incomplete type"); /* Make it return void instead. */ TREE_TYPE (decl1) - = build_function_type (void_type_node, - TYPE_ARG_TYPES (TREE_TYPE (decl1))); + = build_function_type (void_type_node, + TYPE_ARG_TYPES (TREE_TYPE (decl1))); } if (warn_about_return_type) - pedwarn_c99 (input_location, flag_isoc99 ? 0 - : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), - "return type defaults to %<int%>"); + pedwarn_c99 (loc, flag_isoc99 ? 0 + : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), + "return type defaults to %<int%>"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in pop_scope) with the BLOCK. */ @@ -6286,47 +7526,47 @@ if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) { if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE - && comptypes (TREE_TYPE (TREE_TYPE (decl1)), - TREE_TYPE (TREE_TYPE (old_decl)))) - { - TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), - TREE_TYPE (decl1)); - current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl); - current_function_prototype_built_in - = C_DECL_BUILTIN_PROTOTYPE (old_decl); - current_function_prototype_arg_types - = TYPE_ARG_TYPES (TREE_TYPE (decl1)); - } + && comptypes (TREE_TYPE (TREE_TYPE (decl1)), + TREE_TYPE (TREE_TYPE (old_decl)))) + { + TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), + TREE_TYPE (decl1)); + current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl); + current_function_prototype_built_in + = C_DECL_BUILTIN_PROTOTYPE (old_decl); + current_function_prototype_arg_types + = TYPE_ARG_TYPES (TREE_TYPE (decl1)); + } if (TREE_PUBLIC (decl1)) - { - /* If there is an external prototype declaration of this - function, record its location but do not copy information - to this decl. This may be an invisible declaration - (built-in or in a scope which has finished) or simply - have more refined argument types than any declaration - found above. */ - struct c_binding *b; - for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed) - if (B_IN_SCOPE (b, external_scope)) - break; - if (b) - { - tree ext_decl, ext_type; - ext_decl = b->decl; - ext_type = b->type ? b->type : TREE_TYPE (ext_decl); - if (TREE_CODE (ext_type) == FUNCTION_TYPE - && comptypes (TREE_TYPE (TREE_TYPE (decl1)), - TREE_TYPE (ext_type))) - { - current_function_prototype_locus - = DECL_SOURCE_LOCATION (ext_decl); - current_function_prototype_built_in - = C_DECL_BUILTIN_PROTOTYPE (ext_decl); - current_function_prototype_arg_types - = TYPE_ARG_TYPES (ext_type); - } - } - } + { + /* If there is an external prototype declaration of this + function, record its location but do not copy information + to this decl. This may be an invisible declaration + (built-in or in a scope which has finished) or simply + have more refined argument types than any declaration + found above. */ + struct c_binding *b; + for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed) + if (B_IN_SCOPE (b, external_scope)) + break; + if (b) + { + tree ext_decl, ext_type; + ext_decl = b->decl; + ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl); + if (TREE_CODE (ext_type) == FUNCTION_TYPE + && comptypes (TREE_TYPE (TREE_TYPE (decl1)), + TREE_TYPE (ext_type))) + { + current_function_prototype_locus + = DECL_SOURCE_LOCATION (ext_decl); + current_function_prototype_built_in + = C_DECL_BUILTIN_PROTOTYPE (ext_decl); + current_function_prototype_arg_types + = TYPE_ARG_TYPES (ext_type); + } + } + } } /* Optionally warn of old-fashioned def with no previous prototype. */ @@ -6334,40 +7574,42 @@ && old_decl != error_mark_node && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 && C_DECL_ISNT_PROTOTYPE (old_decl)) - warning (OPT_Wstrict_prototypes, - "function declaration isn%'t a prototype"); + warning_at (loc, OPT_Wstrict_prototypes, + "function declaration isn%'t a prototype"); /* Optionally warn of any global def with no previous prototype. */ else if (warn_missing_prototypes - && old_decl != error_mark_node - && TREE_PUBLIC (decl1) - && !MAIN_NAME_P (DECL_NAME (decl1)) - && C_DECL_ISNT_PROTOTYPE (old_decl)) - warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl1); + && old_decl != error_mark_node + && TREE_PUBLIC (decl1) + && !MAIN_NAME_P (DECL_NAME (decl1)) + && C_DECL_ISNT_PROTOTYPE (old_decl)) + warning_at (loc, OPT_Wmissing_prototypes, + "no previous prototype for %qD", decl1); /* Optionally warn of any def with no previous prototype if the function has already been used. */ else if (warn_missing_prototypes - && old_decl != 0 - && old_decl != error_mark_node - && TREE_USED (old_decl) - && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) - warning (OPT_Wmissing_prototypes, - "%q+D was used with no prototype before its definition", decl1); + && old_decl != 0 + && old_decl != error_mark_node + && TREE_USED (old_decl) + && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) + warning_at (loc, OPT_Wmissing_prototypes, + "%qD was used with no prototype before its definition", decl1); /* Optionally warn of any global def with no previous declaration. */ else if (warn_missing_declarations - && TREE_PUBLIC (decl1) - && old_decl == 0 - && !MAIN_NAME_P (DECL_NAME (decl1))) - warning (OPT_Wmissing_declarations, "no previous declaration for %q+D", - decl1); + && TREE_PUBLIC (decl1) + && old_decl == 0 + && !MAIN_NAME_P (DECL_NAME (decl1))) + warning_at (loc, OPT_Wmissing_declarations, + "no previous declaration for %qD", + decl1); /* Optionally warn of any def with no previous declaration if the function has already been used. */ else if (warn_missing_declarations - && old_decl != 0 - && old_decl != error_mark_node - && TREE_USED (old_decl) - && C_DECL_IMPLICIT (old_decl)) - warning (OPT_Wmissing_declarations, - "%q+D was used with no declaration before its definition", decl1); + && old_decl != 0 + && old_decl != error_mark_node + && TREE_USED (old_decl) + && C_DECL_IMPLICIT (old_decl)) + warning_at (loc, OPT_Wmissing_declarations, + "%qD was used with no declaration before its definition", decl1); /* This function exists in static storage. (This does not mean `static' in the C sense!) */ @@ -6389,13 +7631,14 @@ if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) { if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) - != integer_type_node) - pedwarn (input_location, OPT_Wmain, "return type of %q+D is not %<int%>", decl1); + != integer_type_node) + pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1); check_main_parameter_types (decl1); if (!TREE_PUBLIC (decl1)) - pedwarn (input_location, OPT_Wmain, "%q+D is normally a non-static function", decl1); + pedwarn (loc, OPT_Wmain, + "%qD is normally a non-static function", decl1); } /* Record the decl so that the function name is defined. @@ -6408,7 +7651,7 @@ declare_parm_level (); restype = TREE_TYPE (TREE_TYPE (current_function_decl)); - resdecl = build_decl (RESULT_DECL, NULL_TREE, restype); + resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype); DECL_ARTIFICIAL (resdecl) = 1; DECL_IGNORED_P (resdecl) = 1; DECL_RESULT (current_function_decl) = resdecl; @@ -6429,8 +7672,9 @@ if (current_scope->bindings) { - error ("%Jold-style parameter declarations in prototyped " - "function definition", fndecl); + error_at (DECL_SOURCE_LOCATION (fndecl), + "old-style parameter declarations in prototyped " + "function definition"); /* Get rid of the old-style declarations. */ pop_scope (); @@ -6441,10 +7685,9 @@ (this happens when a function definition has just an ellipsis in its parameter list). */ else if (!in_system_header && !current_function_scope - && arg_info->types != error_mark_node) - warning (OPT_Wtraditional, - "%Jtraditional C rejects ISO C style function definitions", - fndecl); + && arg_info->types != error_mark_node) + warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, + "traditional C rejects ISO C style function definitions"); /* Now make all the parameter declarations visible in the function body. We can bypass most of the grunt work of pushdecl. */ @@ -6452,14 +7695,15 @@ { DECL_CONTEXT (decl) = current_function_decl; if (DECL_NAME (decl)) - { - bind (DECL_NAME (decl), decl, current_scope, - /*invisible=*/false, /*nested=*/false); - if (!TREE_USED (decl)) - warn_if_shadowing (decl); - } + { + bind (DECL_NAME (decl), decl, current_scope, + /*invisible=*/false, /*nested=*/false, + UNKNOWN_LOCATION); + if (!TREE_USED (decl)) + warn_if_shadowing (decl); + } else - error ("%Jparameter name omitted", decl); + error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted"); } /* Record the parameter list in the function declaration. */ @@ -6470,15 +7714,15 @@ { DECL_CONTEXT (decl) = current_function_decl; if (DECL_NAME (decl)) - bind (DECL_NAME (decl), decl, current_scope, - /*invisible=*/false, /*nested=*/false); + bind (DECL_NAME (decl), decl, current_scope, + /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); } /* And all the tag declarations. */ for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) if (TREE_PURPOSE (decl)) bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, - /*invisible=*/false, /*nested=*/false); + /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); } /* Subroutine of store_parm_decls which handles old-style function @@ -6493,60 +7737,78 @@ struct pointer_set_t *seen_args = pointer_set_create (); if (!in_system_header) - warning (OPT_Wold_style_definition, "%Jold-style function definition", - fndecl); + warning_at (DECL_SOURCE_LOCATION (fndecl), + OPT_Wold_style_definition, "old-style function definition"); /* Match each formal parameter name with its declaration. Save each decl in the appropriate TREE_PURPOSE slot of the parmids chain. */ for (parm = parmids; parm; parm = TREE_CHAIN (parm)) { if (TREE_VALUE (parm) == 0) - { - error ("%Jparameter name missing from parameter list", fndecl); - TREE_PURPOSE (parm) = 0; - continue; - } + { + error_at (DECL_SOURCE_LOCATION (fndecl), + "parameter name missing from parameter list"); + TREE_PURPOSE (parm) = 0; + continue; + } b = I_SYMBOL_BINDING (TREE_VALUE (parm)); if (b && B_IN_CURRENT_SCOPE (b)) - { - decl = b->decl; - /* If we got something other than a PARM_DECL it is an error. */ - if (TREE_CODE (decl) != PARM_DECL) - error ("%q+D declared as a non-parameter", decl); - /* If the declaration is already marked, we have a duplicate - name. Complain and ignore the duplicate. */ - else if (pointer_set_contains (seen_args, decl)) - { - error ("multiple parameters named %q+D", decl); - TREE_PURPOSE (parm) = 0; - continue; - } - /* If the declaration says "void", complain and turn it into - an int. */ - else if (VOID_TYPE_P (TREE_TYPE (decl))) - { - error ("parameter %q+D declared with void type", decl); - TREE_TYPE (decl) = integer_type_node; - DECL_ARG_TYPE (decl) = integer_type_node; - layout_decl (decl, 0); - } - warn_if_shadowing (decl); - } + { + decl = b->decl; + /* If we got something other than a PARM_DECL it is an error. */ + if (TREE_CODE (decl) != PARM_DECL) + error_at (DECL_SOURCE_LOCATION (decl), + "%qD declared as a non-parameter", decl); + /* If the declaration is already marked, we have a duplicate + name. Complain and ignore the duplicate. */ + else if (pointer_set_contains (seen_args, decl)) + { + error_at (DECL_SOURCE_LOCATION (decl), + "multiple parameters named %qD", decl); + TREE_PURPOSE (parm) = 0; + continue; + } + /* If the declaration says "void", complain and turn it into + an int. */ + else if (VOID_TYPE_P (TREE_TYPE (decl))) + { + error_at (DECL_SOURCE_LOCATION (decl), + "parameter %qD declared with void type", decl); + TREE_TYPE (decl) = integer_type_node; + DECL_ARG_TYPE (decl) = integer_type_node; + layout_decl (decl, 0); + } + warn_if_shadowing (decl); + } /* If no declaration found, default to int. */ else - { - decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node); - DECL_ARG_TYPE (decl) = TREE_TYPE (decl); - DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl); - pushdecl (decl); - warn_if_shadowing (decl); - - if (flag_isoc99) - pedwarn (input_location, 0, "type of %q+D defaults to %<int%>", decl); - else - warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl); - } + { + /* FIXME diagnostics: This should be the location of the argument, + not the FNDECL. E.g., for an old-style declaration + + int f10(v) { blah; } + + We should use the location of the V, not the F10. + Unfortunately, the V is an IDENTIFIER_NODE which has no + location. In the future we need locations for c_arg_info + entries. + + See gcc.dg/Wshadow-3.c for an example of this problem. */ + decl = build_decl (DECL_SOURCE_LOCATION (fndecl), + PARM_DECL, TREE_VALUE (parm), integer_type_node); + DECL_ARG_TYPE (decl) = TREE_TYPE (decl); + pushdecl (decl); + warn_if_shadowing (decl); + + if (flag_isoc99) + pedwarn (DECL_SOURCE_LOCATION (decl), + 0, "type of %qD defaults to %<int%>", decl); + else + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Wmissing_parameter_type, + "type of %qD defaults to %<int%>", decl); + } TREE_PURPOSE (parm) = decl; pointer_set_insert (seen_args, decl); @@ -6559,24 +7821,27 @@ { parm = b->decl; if (TREE_CODE (parm) != PARM_DECL) - continue; + continue; if (TREE_TYPE (parm) != error_mark_node - && !COMPLETE_TYPE_P (TREE_TYPE (parm))) - { - error ("parameter %q+D has incomplete type", parm); - TREE_TYPE (parm) = error_mark_node; - } + && !COMPLETE_TYPE_P (TREE_TYPE (parm))) + { + error_at (DECL_SOURCE_LOCATION (parm), + "parameter %qD has incomplete type", parm); + TREE_TYPE (parm) = error_mark_node; + } if (!pointer_set_contains (seen_args, parm)) - { - error ("declaration for parameter %q+D but no such parameter", parm); - - /* Pretend the parameter was not missing. - This gets us to a standard state and minimizes - further error messages. */ - parmids = chainon (parmids, tree_cons (parm, 0, 0)); - } + { + error_at (DECL_SOURCE_LOCATION (parm), + "declaration for parameter %qD but no such parameter", + parm); + + /* Pretend the parameter was not missing. + This gets us to a standard state and minimizes + further error messages. */ + parmids = chainon (parmids, tree_cons (parm, 0, 0)); + } } /* Chain the declarations together in the order of the list of @@ -6593,11 +7858,11 @@ DECL_ARGUMENTS (fndecl) = last; for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm)) - if (TREE_PURPOSE (parm)) - { - TREE_CHAIN (last) = TREE_PURPOSE (parm); - last = TREE_PURPOSE (parm); - } + if (TREE_PURPOSE (parm)) + { + TREE_CHAIN (last) = TREE_PURPOSE (parm); + last = TREE_PURPOSE (parm); + } TREE_CHAIN (last) = 0; } @@ -6611,78 +7876,91 @@ { tree type; for (parm = DECL_ARGUMENTS (fndecl), - type = current_function_prototype_arg_types; - parm || (type && TREE_VALUE (type) != error_mark_node + type = current_function_prototype_arg_types; + parm || (type && TREE_VALUE (type) != error_mark_node && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node)); - parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) - { - if (parm == 0 || type == 0 - || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) - { - if (current_function_prototype_built_in) - warning (0, "number of arguments doesn%'t match " - "built-in prototype"); - else - { - error ("number of arguments doesn%'t match prototype"); - error ("%Hprototype declaration", - ¤t_function_prototype_locus); - } - break; - } - /* Type for passing arg must be consistent with that - declared for the arg. ISO C says we take the unqualified - type for parameters declared with qualified type. */ - if (TREE_TYPE (parm) != error_mark_node - && TREE_TYPE (type) != error_mark_node - && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)), - TYPE_MAIN_VARIANT (TREE_VALUE (type)))) - { - if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) - == TYPE_MAIN_VARIANT (TREE_VALUE (type))) - { - /* Adjust argument to match prototype. E.g. a previous - `int foo(float);' prototype causes - `int foo(x) float x; {...}' to be treated like - `int foo(float x) {...}'. This is particularly - useful for argument types like uid_t. */ - DECL_ARG_TYPE (parm) = TREE_TYPE (parm); - - if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl)) - && INTEGRAL_TYPE_P (TREE_TYPE (parm)) - && TYPE_PRECISION (TREE_TYPE (parm)) - < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (parm) = integer_type_node; - - /* ??? Is it possible to get here with a - built-in prototype or will it always have - been diagnosed as conflicting with an - old-style definition and discarded? */ - if (current_function_prototype_built_in) - warning (OPT_pedantic, "promoted argument %qD " - "doesn%'t match built-in prototype", parm); - else - { - pedwarn (input_location, OPT_pedantic, "promoted argument %qD " - "doesn%'t match prototype", parm); - pedwarn (current_function_prototype_locus, OPT_pedantic, - "prototype declaration"); - } - } - else - { - if (current_function_prototype_built_in) - warning (0, "argument %qD doesn%'t match " - "built-in prototype", parm); - else - { - error ("argument %qD doesn%'t match prototype", parm); - error ("%Hprototype declaration", - ¤t_function_prototype_locus); - } - } - } - } + parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) + { + if (parm == 0 || type == 0 + || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) + { + if (current_function_prototype_built_in) + warning_at (DECL_SOURCE_LOCATION (fndecl), + 0, "number of arguments doesn%'t match " + "built-in prototype"); + else + { + /* FIXME diagnostics: This should be the location of + FNDECL, but there is bug when a prototype is + declared inside function context, but defined + outside of it (e.g., gcc.dg/pr15698-2.c). In + which case FNDECL gets the location of the + prototype, not the definition. */ + error_at (input_location, + "number of arguments doesn%'t match prototype"); + + error_at (current_function_prototype_locus, + "prototype declaration"); + } + break; + } + /* Type for passing arg must be consistent with that + declared for the arg. ISO C says we take the unqualified + type for parameters declared with qualified type. */ + if (TREE_TYPE (parm) != error_mark_node + && TREE_TYPE (type) != error_mark_node + && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)), + TYPE_MAIN_VARIANT (TREE_VALUE (type)))) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) + == TYPE_MAIN_VARIANT (TREE_VALUE (type))) + { + /* Adjust argument to match prototype. E.g. a previous + `int foo(float);' prototype causes + `int foo(x) float x; {...}' to be treated like + `int foo(float x) {...}'. This is particularly + useful for argument types like uid_t. */ + DECL_ARG_TYPE (parm) = TREE_TYPE (parm); + + if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl)) + && INTEGRAL_TYPE_P (TREE_TYPE (parm)) + && TYPE_PRECISION (TREE_TYPE (parm)) + < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (parm) = integer_type_node; + + /* ??? Is it possible to get here with a + built-in prototype or will it always have + been diagnosed as conflicting with an + old-style definition and discarded? */ + if (current_function_prototype_built_in) + warning_at (DECL_SOURCE_LOCATION (parm), + OPT_pedantic, "promoted argument %qD " + "doesn%'t match built-in prototype", parm); + else + { + pedwarn (DECL_SOURCE_LOCATION (parm), + OPT_pedantic, "promoted argument %qD " + "doesn%'t match prototype", parm); + pedwarn (current_function_prototype_locus, OPT_pedantic, + "prototype declaration"); + } + } + else + { + if (current_function_prototype_built_in) + warning_at (DECL_SOURCE_LOCATION (parm), + 0, "argument %qD doesn%'t match " + "built-in prototype", parm); + else + { + error_at (DECL_SOURCE_LOCATION (parm), + "argument %qD doesn%'t match prototype", parm); + error_at (current_function_prototype_locus, + "prototype declaration"); + } + } + } + } TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; } @@ -6693,27 +7971,27 @@ tree actual = 0, last = 0, type; for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) - { - type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); - if (last) - TREE_CHAIN (last) = type; - else - actual = type; - last = type; - } + { + type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); + if (last) + TREE_CHAIN (last) = type; + else + actual = type; + last = type; + } type = tree_cons (NULL_TREE, void_type_node, NULL_TREE); if (last) - TREE_CHAIN (last) = type; + TREE_CHAIN (last) = type; else - actual = type; + actual = type; /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES - of the type of this function, but we need to avoid having this - affect the types of other similarly-typed functions, so we must - first force the generation of an identical (but separate) type - node for the relevant function type. The new node we create - will be a variant of the main variant of the original function - type. */ + of the type of this function, but we need to avoid having this + affect the types of other similarly-typed functions, so we must + first force the generation of an identical (but separate) type + node for the relevant function type. The new node we create + will be a variant of the main variant of the original function + type. */ TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl)); @@ -6777,7 +8055,7 @@ /* ??? Insert the contents of the pending sizes list into the function to be evaluated. The only reason left to have this is - void foo(int n, int array[n++]) + void foo(int n, int array[n++]) because we throw away the array type in favor of a pointer type, and thus won't naturally see the SAVE_EXPR containing the increment. All other pending sizes would be handled by gimplify_parameters. */ @@ -6794,27 +8072,6 @@ cfun->dont_save_pending_sizes_p = 1; } -/* Emit diagnostics that require gimple input for detection. Operate on - FNDECL and all its nested functions. */ - -static void -c_gimple_diagnostics_recursively (tree fndecl) -{ - struct cgraph_node *cgn; - gimple_seq body = gimple_body (fndecl); - - /* Handle attribute((warn_unused_result)). Relies on gimple input. */ - c_warn_unused_result (body); - - /* Notice when OpenMP structured block constraints are violated. */ - if (flag_openmp) - diagnose_omp_structured_block_errors (fndecl); - - /* Finalize all nested functions now. */ - cgn = cgraph_node (fndecl); - for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) - c_gimple_diagnostics_recursively (cgn->decl); -} /* Finish up a function declaration and compile that function all the way to assembler language output. The free the storage @@ -6827,20 +8084,17 @@ { tree fndecl = current_function_decl; - label_context_stack_se = label_context_stack_se->next; - label_context_stack_vm = label_context_stack_vm->next; - if (TREE_CODE (fndecl) == FUNCTION_DECL && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) { tree args = DECL_ARGUMENTS (fndecl); for (; args; args = TREE_CHAIN (args)) - { - tree type = TREE_TYPE (args); - if (INTEGRAL_TYPE_P (type) - && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (args) = integer_type_node; - } + { + tree type = TREE_TYPE (args); + if (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (args) = integer_type_node; + } } if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node) @@ -6855,14 +8109,13 @@ && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) == integer_type_node && flag_isoc99) { - tree stmt = c_finish_return (integer_zero_node); /* Hack. We don't want the middle-end to warn that this return - is unreachable, so we mark its location as special. Using - UNKNOWN_LOCATION has the problem that it gets clobbered in - annotate_one_with_locus. A cleaner solution might be to - ensure ! should_carry_locus_p (stmt), but that needs a flag. + is unreachable, so we mark its location as special. Using + UNKNOWN_LOCATION has the problem that it gets clobbered in + annotate_one_with_locus. A cleaner solution might be to + ensure ! should_carry_locus_p (stmt), but that needs a flag. */ - SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); + c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE); } /* Tie off the statement tree for this function. */ @@ -6876,8 +8129,6 @@ && !current_function_returns_value && !current_function_returns_null /* Don't complain if we are no-return. */ && !current_function_returns_abnormally - /* Don't complain if we are declared noreturn. */ - && !TREE_THIS_VOLATILE (fndecl) /* Don't warn for main(). */ && !MAIN_NAME_P (DECL_NAME (fndecl)) /* Or if they didn't actually specify a return type. */ @@ -6887,7 +8138,7 @@ && !TREE_PUBLIC (fndecl)) { warning (OPT_Wreturn_type, - "no return statement in function returning non-void"); + "no return statement in function returning non-void"); TREE_NO_WARNING (fndecl) = 1; } @@ -6899,7 +8150,7 @@ c_determine_visibility (fndecl); /* For GNU C extern inline functions disregard inline limits. */ - if (DECL_EXTERNAL (fndecl) + if (DECL_EXTERNAL (fndecl) && DECL_DECLARED_INLINE_P (fndecl)) DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; @@ -6911,27 +8162,26 @@ && !undef_nested_function) { if (!decl_function_context (fndecl)) - { - c_genericize (fndecl); - c_gimple_diagnostics_recursively (fndecl); - - /* ??? Objc emits functions after finalizing the compilation unit. - This should be cleaned up later and this conditional removed. */ - if (cgraph_global_info_ready) - { - cgraph_add_new_function (fndecl, false); - return; - } - - cgraph_finalize_function (fndecl, false); - } + { + invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl); + c_genericize (fndecl); + + /* ??? Objc emits functions after finalizing the compilation unit. + This should be cleaned up later and this conditional removed. */ + if (cgraph_global_info_ready) + { + cgraph_add_new_function (fndecl, false); + return; + } + cgraph_finalize_function (fndecl, false); + } else - { - /* Register this function with cgraph just far enough to get it - added to our parent's nested function list. Handy, since the - C front end doesn't have such a list. */ - (void) cgraph_node (fndecl); - } + { + /* Register this function with cgraph just far enough to get it + added to our parent's nested function list. Handy, since the + C front end doesn't have such a list. */ + (void) cgraph_node (fndecl); + } } if (!decl_function_context (fndecl)) @@ -6945,10 +8195,11 @@ } /* Check the declarations given in a for-loop for satisfying the C99 - constraints. If exactly one such decl is found, return it. */ + constraints. If exactly one such decl is found, return it. LOC is + the location of the opening parenthesis of the for loop. */ tree -check_for_loop_decls (void) +check_for_loop_decls (location_t loc) { struct c_binding *b; tree one_decl = NULL_TREE; @@ -6958,15 +8209,16 @@ { static bool hint = true; /* If we get here, declarations have been used in a for loop without - the C99 for loop scope. This doesn't make much sense, so don't - allow it. */ - error ("%<for%> loop initial declarations are only allowed in C99 mode"); + the C99 for loop scope. This doesn't make much sense, so don't + allow it. */ + error_at (loc, "%<for%> loop initial declarations " + "are only allowed in C99 mode"); if (hint) - { - inform (input_location, - "use option -std=c99 or -std=gnu99 to compile your code"); - hint = false; - } + { + inform (loc, + "use option -std=c99 or -std=gnu99 to compile your code"); + hint = false; + } return NULL_TREE; } /* C99 subclause 6.8.5 paragraph 3: @@ -6989,35 +8241,42 @@ tree decl = b->decl; if (!id) - continue; + continue; switch (TREE_CODE (decl)) - { - case VAR_DECL: - if (TREE_STATIC (decl)) - error ("declaration of static variable %q+D in %<for%> loop " - "initial declaration", decl); - else if (DECL_EXTERNAL (decl)) - error ("declaration of %<extern%> variable %q+D in %<for%> loop " - "initial declaration", decl); - break; - - case RECORD_TYPE: - error ("%<struct %E%> declared in %<for%> loop initial declaration", - id); - break; - case UNION_TYPE: - error ("%<union %E%> declared in %<for%> loop initial declaration", - id); - break; - case ENUMERAL_TYPE: - error ("%<enum %E%> declared in %<for%> loop initial declaration", - id); - break; - default: - error ("declaration of non-variable %q+D in %<for%> loop " - "initial declaration", decl); - } + { + case VAR_DECL: + { + location_t decl_loc = DECL_SOURCE_LOCATION (decl); + if (TREE_STATIC (decl)) + error_at (decl_loc, + "declaration of static variable %qD in %<for%> loop " + "initial declaration", decl); + else if (DECL_EXTERNAL (decl)) + error_at (decl_loc, + "declaration of %<extern%> variable %qD in %<for%> loop " + "initial declaration", decl); + } + break; + + case RECORD_TYPE: + error_at (loc, + "%<struct %E%> declared in %<for%> loop initial " + "declaration", id); + break; + case UNION_TYPE: + error_at (loc, + "%<union %E%> declared in %<for%> loop initial declaration", + id); + break; + case ENUMERAL_TYPE: + error_at (loc, "%<enum %E%> declared in %<for%> loop " + "initial declaration", id); + break; + default: + error_at (loc, "declaration of non-variable " + "%qD in %<for%> loop initial declaration", decl); + } n_decls++; one_decl = decl; @@ -7065,7 +8324,7 @@ { /* Stop pointing to the local nodes about to be freed. */ /* But DECL_INITIAL must remain nonzero so we know this - was an actual function definition. */ + was an actual function definition. */ DECL_INITIAL (current_function_decl) = error_mark_node; DECL_ARGUMENTS (current_function_decl) = 0; } @@ -7081,21 +8340,6 @@ warn_about_return_type = p->warn_about_return_type; } -/* Copy the DECL_LANG_SPECIFIC data associated with DECL. */ - -void -c_dup_lang_specific_decl (tree decl) -{ - struct lang_decl *ld; - - if (!DECL_LANG_SPECIFIC (decl)) - return; - - ld = GGC_NEW (struct lang_decl); - memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl)); - DECL_LANG_SPECIFIC (decl) = ld; -} - /* The functions below are required for functionality of doing function at once processing in the C front end. Currently these functions are not called from anywhere in the C front end, but as @@ -7114,7 +8358,7 @@ /* Return the global value of T as a symbol. */ tree -identifier_global_value (tree t) +identifier_global_value (tree t) { struct c_binding *b; @@ -7136,7 +8380,7 @@ id = ridpointers[(int) rid_index]; else id = get_identifier (name); - decl = build_decl (TYPE_DECL, id, type); + decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type); pushdecl (decl); if (debug_hooks->type_decl) debug_hooks->type_decl (decl, false); @@ -7154,7 +8398,7 @@ struct c_parm * build_c_parm (struct c_declspecs *specs, tree attrs, - struct c_declarator *declarator) + struct c_declarator *declarator) { struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm); ret->specs = specs; @@ -7182,7 +8426,7 @@ struct c_declarator * build_function_declarator (struct c_arg_info *args, - struct c_declarator *target) + struct c_declarator *target) { struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator); ret->kind = cdk_function; @@ -7213,7 +8457,7 @@ struct c_declarator * make_pointer_declarator (struct c_declspecs *type_quals_attrs, - struct c_declarator *target) + struct c_declarator *target) { tree attrs; int quals = 0; @@ -7224,7 +8468,7 @@ attrs = type_quals_attrs->attrs; quals = quals_from_declspecs (type_quals_attrs); if (attrs != NULL_TREE) - itarget = build_attrs_declarator (attrs, target); + itarget = build_attrs_declarator (attrs, target); } ret->kind = cdk_pointer; ret->declarator = itarget; @@ -7240,10 +8484,12 @@ { struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs); ret->type = 0; + ret->expr = 0; ret->decl_attr = 0; ret->attrs = 0; ret->typespec_word = cts_none; ret->storage_class = csc_none; + ret->expr_const_operands = true; ret->declspecs_seen_p = false; ret->type_seen_p = false; ret->non_sc_seen_p = false; @@ -7264,9 +8510,29 @@ ret->volatile_p = false; ret->restrict_p = false; ret->saturating_p = false; + ret->address_space = ADDR_SPACE_GENERIC; return ret; } +/* Add the address space ADDRSPACE to the declaration specifiers + SPECS, returning SPECS. */ + +struct c_declspecs * +declspecs_add_addrspace (struct c_declspecs *specs, addr_space_t as) +{ + specs->non_sc_seen_p = true; + specs->declspecs_seen_p = true; + + if (!ADDR_SPACE_GENERIC_P (specs->address_space) + && specs->address_space != as) + error ("incompatible address space qualifiers %qs and %qs", + c_addr_space_name (as), + c_addr_space_name (specs->address_space)); + else + specs->address_space = as; + return specs; +} + /* Add the type qualifier QUAL to the declaration specifiers SPECS, returning SPECS. */ @@ -7278,7 +8544,7 @@ specs->non_sc_seen_p = true; specs->declspecs_seen_p = true; gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE - && C_IS_RESERVED_WORD (qual)); + && C_IS_RESERVED_WORD (qual)); i = C_RID_CODE (qual); switch (i) { @@ -7306,7 +8572,8 @@ returning SPECS. */ struct c_declspecs * -declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec) +declspecs_add_type (location_t loc, struct c_declspecs *specs, + struct c_typespec spec) { tree type = spec.spec; specs->non_sc_seen_p = true; @@ -7322,457 +8589,562 @@ { enum rid i = C_RID_CODE (type); if (specs->type) - { - error ("two or more data types in declaration specifiers"); - return specs; - } + { + error_at (loc, "two or more data types in declaration specifiers"); + return specs; + } if ((int) i <= (int) RID_LAST_MODIFIER) - { - /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ - bool dupe = false; - switch (i) - { - case RID_LONG: - if (specs->long_long_p) - { - error ("%<long long long%> is too long for GCC"); - break; - } - if (specs->long_p) - { - if (specs->typespec_word == cts_double) - { - error ("both %<long long%> and %<double%> in " - "declaration specifiers"); - break; - } - if (pedantic && !flag_isoc99 && !in_system_header) - pedwarn (input_location, OPT_Wlong_long, "ISO C90 does not support %<long long%>"); - specs->long_long_p = 1; - break; - } - if (specs->short_p) - error ("both %<long%> and %<short%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_void) - error ("both %<long%> and %<void%> in " - "declaration specifiers"); + { + /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ + bool dupe = false; + switch (i) + { + case RID_LONG: + if (specs->long_long_p) + { + error_at (loc, "%<long long long%> is too long for GCC"); + break; + } + if (specs->long_p) + { + if (specs->typespec_word == cts_double) + { + error_at (loc, + ("both %<long long%> and %<double%> in " + "declaration specifiers")); + break; + } + pedwarn_c90 (loc, OPT_Wlong_long, + "ISO C90 does not support %<long long%>"); + specs->long_long_p = 1; + break; + } + if (specs->short_p) + error_at (loc, + ("both %<long%> and %<short%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<long%> and %<void%> in " + "declaration specifiers")); #ifndef noCbC - else if (specs->typespec_word == cts_CbC_code) - error ("both %<long%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_CbC_code) + error_at (loc, + ("both %<long%> and %<void%> in " + "declaration specifiers")); #endif - else if (specs->typespec_word == cts_bool) - error ("both %<long%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_char) - error ("both %<long%> and %<char%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_float) - error ("both %<long%> and %<float%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat32) - error ("both %<long%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<long%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<long%> and %<_Decimal128%> in " - "declaration specifiers"); - else - specs->long_p = true; - break; - case RID_SHORT: - dupe = specs->short_p; - if (specs->long_p) - error ("both %<long%> and %<short%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_void) - error ("both %<short%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<long%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_char) + error_at (loc, + ("both %<long%> and %<char%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_float) + error_at (loc, + ("both %<long%> and %<float%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat32) + error_at (loc, + ("both %<long%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<long%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<long%> and %<_Decimal128%> in " + "declaration specifiers")); + else + specs->long_p = true; + break; + case RID_SHORT: + dupe = specs->short_p; + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<short%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<short%> and %<void%> in " + "declaration specifiers")); #ifndef noCbC - else if (specs->typespec_word == cts_CbC_code) - error ("both %<short%> and %<void%> in " - "declaration specifiers"); -#endif - else if (specs->typespec_word == cts_bool) - error ("both %<short%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_char) - error ("both %<short%> and %<char%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_float) - error ("both %<short%> and %<float%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_double) - error ("both %<short%> and %<double%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat32) - error ("both %<short%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<short%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<short%> and %<_Decimal128%> in " - "declaration specifiers"); - else - specs->short_p = true; - break; - case RID_SIGNED: - dupe = specs->signed_p; - if (specs->unsigned_p) - error ("both %<signed%> and %<unsigned%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_void) - error ("both %<signed%> and %<void%> in " - "declaration specifiers"); -#ifndef noCbC - else if (specs->typespec_word == cts_CbC_code) - error ("both %<signed%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_CbC_code) + error_at (loc, + ("both %<short%> and %<void%> in " + "declaration specifiers")); #endif - else if (specs->typespec_word == cts_bool) - error ("both %<signed%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_float) - error ("both %<signed%> and %<float%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_double) - error ("both %<signed%> and %<double%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat32) - error ("both %<signed%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<signed%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<signed%> and %<_Decimal128%> in " - "declaration specifiers"); - else - specs->signed_p = true; - break; - case RID_UNSIGNED: - dupe = specs->unsigned_p; - if (specs->signed_p) - error ("both %<signed%> and %<unsigned%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_void) - error ("both %<unsigned%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<short%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_char) + error_at (loc, + ("both %<short%> and %<char%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_float) + error_at (loc, + ("both %<short%> and %<float%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_double) + error_at (loc, + ("both %<short%> and %<double%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat32) + error_at (loc, + ("both %<short%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<short%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<short%> and %<_Decimal128%> in " + "declaration specifiers")); + else + specs->short_p = true; + break; + case RID_SIGNED: + dupe = specs->signed_p; + if (specs->unsigned_p) + error_at (loc, + ("both %<signed%> and %<unsigned%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<signed%> and %<void%> in " + "declaration specifiers")); #ifndef noCbC - else if (specs->typespec_word == cts_CbC_code) - error ("both %<unsigned%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_CbC_code) + error_at (loc, + ("both %<signed%> and %<void%> in " + "declaration specifiers")); #endif - else if (specs->typespec_word == cts_bool) - error ("both %<unsigned%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_float) - error ("both %<unsigned%> and %<float%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_double) - error ("both %<unsigned%> and %<double%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<signed%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_float) + error_at (loc, + ("both %<signed%> and %<float%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_double) + error_at (loc, + ("both %<signed%> and %<double%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat32) + error_at (loc, + ("both %<signed%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<signed%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<signed%> and %<_Decimal128%> in " + "declaration specifiers")); + else + specs->signed_p = true; + break; + case RID_UNSIGNED: + dupe = specs->unsigned_p; + if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<unsigned%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<unsigned%> and %<void%> in " + "declaration specifiers")); +#ifndef noCbC + else if (specs->typespec_word == cts_CbC_code) + error_at (loc, + ("both %<unsigned%> and %<void%> in " + "declaration specifiers")); +#endif + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<unsigned%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_float) + error_at (loc, + ("both %<unsigned%> and %<float%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_double) + error_at (loc, + ("both %<unsigned%> and %<double%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_dfloat32) - error ("both %<unsigned%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<unsigned%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<unsigned%> and %<_Decimal128%> in " - "declaration specifiers"); - else - specs->unsigned_p = true; - break; - case RID_COMPLEX: - dupe = specs->complex_p; - if (!flag_isoc99 && !in_system_header) - pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types"); - if (specs->typespec_word == cts_void) - error ("both %<complex%> and %<void%> in " - "declaration specifiers"); + error_at (loc, + ("both %<unsigned%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<unsigned%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<unsigned%> and %<_Decimal128%> in " + "declaration specifiers")); + else + specs->unsigned_p = true; + break; + case RID_COMPLEX: + dupe = specs->complex_p; + if (!flag_isoc99 && !in_system_header) + pedwarn (loc, OPT_pedantic, + "ISO C90 does not support complex types"); + if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<complex%> and %<void%> in " + "declaration specifiers")); #ifndef noCbC - else if (specs->typespec_word == cts_CbC_code) - error ("both %<complex%> and %<void%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_CbC_code) + error_at (loc, + ("both %<complex%> and %<void%> in " + "declaration specifiers")); #endif - else if (specs->typespec_word == cts_bool) - error ("both %<complex%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat32) - error ("both %<complex%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<complex%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<complex%> and %<_Decimal128%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_fract) - error ("both %<complex%> and %<_Fract%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_accum) - error ("both %<complex%> and %<_Accum%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<complex%> and %<_Sat%> in " - "declaration specifiers"); - else - specs->complex_p = true; - break; - case RID_SAT: - dupe = specs->saturating_p; - pedwarn (input_location, OPT_pedantic, "ISO C does not support saturating types"); - if (specs->typespec_word == cts_void) - error ("both %<_Sat%> and %<void%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_bool) - error ("both %<_Sat%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_char) - error ("both %<_Sat%> and %<char%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_int) - error ("both %<_Sat%> and %<int%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_float) - error ("both %<_Sat%> and %<float%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_double) - error ("both %<_Sat%> and %<double%> in " - "declaration specifiers"); + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<complex%> and %<_Bool%> in " + "declaration specifiers")); else if (specs->typespec_word == cts_dfloat32) - error ("both %<_Sat%> and %<_Decimal32%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat64) - error ("both %<_Sat%> and %<_Decimal64%> in " - "declaration specifiers"); - else if (specs->typespec_word == cts_dfloat128) - error ("both %<_Sat%> and %<_Decimal128%> in " - "declaration specifiers"); - else if (specs->complex_p) - error ("both %<_Sat%> and %<complex%> in " - "declaration specifiers"); - else - specs->saturating_p = true; - break; - default: - gcc_unreachable (); - } - - if (dupe) - error ("duplicate %qE", type); - - return specs; - } + error_at (loc, + ("both %<complex%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<complex%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<complex%> and %<_Decimal128%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_fract) + error_at (loc, + ("both %<complex%> and %<_Fract%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_accum) + error_at (loc, + ("both %<complex%> and %<_Accum%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<complex%> and %<_Sat%> in " + "declaration specifiers")); + else + specs->complex_p = true; + break; + case RID_SAT: + dupe = specs->saturating_p; + pedwarn (loc, OPT_pedantic, + "ISO C does not support saturating types"); + if (specs->typespec_word == cts_void) + error_at (loc, + ("both %<_Sat%> and %<void%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_bool) + error_at (loc, + ("both %<_Sat%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_char) + error_at (loc, + ("both %<_Sat%> and %<char%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_int) + error_at (loc, + ("both %<_Sat%> and %<int%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_float) + error_at (loc, + ("both %<_Sat%> and %<float%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_double) + error_at (loc, + ("both %<_Sat%> and %<double%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat32) + error_at (loc, + ("both %<_Sat%> and %<_Decimal32%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat64) + error_at (loc, + ("both %<_Sat%> and %<_Decimal64%> in " + "declaration specifiers")); + else if (specs->typespec_word == cts_dfloat128) + error_at (loc, + ("both %<_Sat%> and %<_Decimal128%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both %<_Sat%> and %<complex%> in " + "declaration specifiers")); + else + specs->saturating_p = true; + break; + default: + gcc_unreachable (); + } + + if (dupe) + error_at (loc, "duplicate %qE", type); + + return specs; + } else - { - /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", - "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ - if (specs->typespec_word != cts_none) - { - error ("two or more data types in declaration specifiers"); - return specs; - } - switch (i) - { - case RID_VOID: - if (specs->long_p) - error ("both %<long%> and %<void%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<void%> in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both %<signed%> and %<void%> in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<void%> in " - "declaration specifiers"); - else if (specs->complex_p) - error ("both %<complex%> and %<void%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<_Sat%> and %<void%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_void; - return specs; + { + /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", + "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ + if (specs->typespec_word != cts_none) + { + error_at (loc, + "two or more data types in declaration specifiers"); + return specs; + } + switch (i) + { + case RID_VOID: + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<void%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<void%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<void%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both %<unsigned%> and %<void%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both %<complex%> and %<void%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<void%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_void; + return specs; #ifndef noCbC - case RID_CbC_CODE: - if (specs->long_p) - error ("both %<long%> and %<void%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<void%> in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both %<signed%> and %<void%> in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<void%> in " - "declaration specifiers"); - else if (specs->complex_p) - error ("both %<complex%> and %<void%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_CbC_code; - return specs; + case RID_CbC_CODE: + if (specs->long_p) + error ("both %<long%> and %<void%> in " + "declaration specifiers"); + else if (specs->short_p) + error ("both %<short%> and %<void%> in " + "declaration specifiers"); + else if (specs->signed_p) + error ("both %<signed%> and %<void%> in " + "declaration specifiers"); + else if (specs->unsigned_p) + error ("both %<unsigned%> and %<void%> in " + "declaration specifiers"); + else if (specs->complex_p) + error ("both %<complex%> and %<void%> in " + "declaration specifiers"); + else + specs->typespec_word = cts_CbC_code; + return specs; #endif - case RID_BOOL: - if (specs->long_p) - error ("both %<long%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both %<signed%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->complex_p) - error ("both %<complex%> and %<_Bool%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<_Sat%> and %<_Bool%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_bool; - return specs; - case RID_CHAR: - if (specs->long_p) - error ("both %<long%> and %<char%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<char%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<_Sat%> and %<char%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_char; - return specs; - case RID_INT: - if (specs->saturating_p) - error ("both %<_Sat%> and %<int%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_int; - return specs; - case RID_FLOAT: - if (specs->long_p) - error ("both %<long%> and %<float%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<float%> in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both %<signed%> and %<float%> in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<float%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<_Sat%> and %<float%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_float; - return specs; - case RID_DOUBLE: - if (specs->long_long_p) - error ("both %<long long%> and %<double%> in " - "declaration specifiers"); - else if (specs->short_p) - error ("both %<short%> and %<double%> in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both %<signed%> and %<double%> in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<double%> in " - "declaration specifiers"); - else if (specs->saturating_p) - error ("both %<_Sat%> and %<double%> in " - "declaration specifiers"); - else - specs->typespec_word = cts_double; - return specs; - case RID_DFLOAT32: - case RID_DFLOAT64: - case RID_DFLOAT128: - { - const char *str; - if (i == RID_DFLOAT32) - str = "_Decimal32"; - else if (i == RID_DFLOAT64) - str = "_Decimal64"; - else - str = "_Decimal128"; - if (specs->long_long_p) - error ("both %<long long%> and %<%s%> in " - "declaration specifiers", str); - if (specs->long_p) - error ("both %<long%> and %<%s%> in " - "declaration specifiers", str); - else if (specs->short_p) - error ("both %<short%> and %<%s%> in " - "declaration specifiers", str); - else if (specs->signed_p) - error ("both %<signed%> and %<%s%> in " - "declaration specifiers", str); - else if (specs->unsigned_p) - error ("both %<unsigned%> and %<%s%> in " - "declaration specifiers", str); + case RID_BOOL: + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both %<unsigned%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both %<complex%> and %<_Bool%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<_Bool%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_bool; + return specs; + case RID_CHAR: + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<char%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<char%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<char%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_char; + return specs; + case RID_INT: + if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<int%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_int; + return specs; + case RID_FLOAT: + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<float%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<float%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<float%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both %<unsigned%> and %<float%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<float%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_float; + return specs; + case RID_DOUBLE: + if (specs->long_long_p) + error_at (loc, + ("both %<long long%> and %<double%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<double%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<double%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both %<unsigned%> and %<double%> in " + "declaration specifiers")); + else if (specs->saturating_p) + error_at (loc, + ("both %<_Sat%> and %<double%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_double; + return specs; + case RID_DFLOAT32: + case RID_DFLOAT64: + case RID_DFLOAT128: + { + const char *str; + if (i == RID_DFLOAT32) + str = "_Decimal32"; + else if (i == RID_DFLOAT64) + str = "_Decimal64"; + else + str = "_Decimal128"; + if (specs->long_long_p) + error_at (loc, + ("both %<long long%> and %<%s%> in " + "declaration specifiers"), + str); + if (specs->long_p) + error_at (loc, + ("both %<long%> and %<%s%> in " + "declaration specifiers"), + str); + else if (specs->short_p) + error_at (loc, + ("both %<short%> and %<%s%> in " + "declaration specifiers"), + str); + else if (specs->signed_p) + error_at (loc, + ("both %<signed%> and %<%s%> in " + "declaration specifiers"), + str); + else if (specs->unsigned_p) + error_at (loc, + ("both %<unsigned%> and %<%s%> in " + "declaration specifiers"), + str); else if (specs->complex_p) - error ("both %<complex%> and %<%s%> in " - "declaration specifiers", str); + error_at (loc, + ("both %<complex%> and %<%s%> in " + "declaration specifiers"), + str); else if (specs->saturating_p) - error ("both %<_Sat%> and %<%s%> in " - "declaration specifiers", str); - else if (i == RID_DFLOAT32) - specs->typespec_word = cts_dfloat32; - else if (i == RID_DFLOAT64) - specs->typespec_word = cts_dfloat64; - else - specs->typespec_word = cts_dfloat128; - } - if (!targetm.decimal_float_supported_p ()) - error ("decimal floating point not supported for this target"); - pedwarn (input_location, OPT_pedantic, - "ISO C does not support decimal floating point"); - return specs; - case RID_FRACT: - case RID_ACCUM: - { - const char *str; - if (i == RID_FRACT) - str = "_Fract"; - else - str = "_Accum"; + error_at (loc, + ("both %<_Sat%> and %<%s%> in " + "declaration specifiers"), + str); + else if (i == RID_DFLOAT32) + specs->typespec_word = cts_dfloat32; + else if (i == RID_DFLOAT64) + specs->typespec_word = cts_dfloat64; + else + specs->typespec_word = cts_dfloat128; + } + if (!targetm.decimal_float_supported_p ()) + error_at (loc, + ("decimal floating point not supported " + "for this target")); + pedwarn (loc, OPT_pedantic, + "ISO C does not support decimal floating point"); + return specs; + case RID_FRACT: + case RID_ACCUM: + { + const char *str; + if (i == RID_FRACT) + str = "_Fract"; + else + str = "_Accum"; if (specs->complex_p) - error ("both %<complex%> and %<%s%> in " - "declaration specifiers", str); - else if (i == RID_FRACT) - specs->typespec_word = cts_fract; - else - specs->typespec_word = cts_accum; - } - if (!targetm.fixed_point_supported_p ()) - error ("fixed-point types not supported for this target"); - pedwarn (input_location, OPT_pedantic, - "ISO C does not support fixed-point types"); - return specs; - default: - /* ObjC reserved word "id", handled below. */ - break; - } - } + error_at (loc, + ("both %<complex%> and %<%s%> in " + "declaration specifiers"), + str); + else if (i == RID_FRACT) + specs->typespec_word = cts_fract; + else + specs->typespec_word = cts_accum; + } + if (!targetm.fixed_point_supported_p ()) + error_at (loc, + "fixed-point types not supported for this target"); + pedwarn (loc, OPT_pedantic, + "ISO C does not support fixed-point types"); + return specs; + default: + /* ObjC reserved word "id", handled below. */ + break; + } + } } /* Now we have a typedef (a TYPE_DECL node), an identifier (some @@ -7783,35 +9155,59 @@ if (specs->type || specs->typespec_word != cts_none || specs->long_p || specs->short_p || specs->signed_p || specs->unsigned_p || specs->complex_p) - error ("two or more data types in declaration specifiers"); + error_at (loc, "two or more data types in declaration specifiers"); else if (TREE_CODE (type) == TYPE_DECL) { if (TREE_TYPE (type) == error_mark_node) - ; /* Allow the type to default to int to avoid cascading errors. */ + ; /* Allow the type to default to int to avoid cascading errors. */ else - { - specs->type = TREE_TYPE (type); - specs->decl_attr = DECL_ATTRIBUTES (type); - specs->typedef_p = true; - specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); - } + { + specs->type = TREE_TYPE (type); + specs->decl_attr = DECL_ATTRIBUTES (type); + specs->typedef_p = true; + specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); + + /* If this typedef name is defined in a struct, then a C++ + lookup would return a different value. */ + if (warn_cxx_compat + && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct) + warning_at (loc, OPT_Wc___compat, + "C++ lookup of %qD would return a field, not a type", + type); + + /* If we are parsing a struct, record that a struct field + used a typedef. */ + if (warn_cxx_compat && struct_parse_info != NULL) + VEC_safe_push (tree, heap, struct_parse_info->typedefs_seen, type); + } } else if (TREE_CODE (type) == IDENTIFIER_NODE) { tree t = lookup_name (type); if (!t || TREE_CODE (t) != TYPE_DECL) - error ("%qE fails to be a typedef or built in type", type); + error_at (loc, "%qE fails to be a typedef or built in type", type); else if (TREE_TYPE (t) == error_mark_node) - ; + ; else - specs->type = TREE_TYPE (t); + specs->type = TREE_TYPE (t); } else if (TREE_CODE (type) != ERROR_MARK) { if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) - specs->tag_defined_p = true; + specs->tag_defined_p = true; if (spec.kind == ctsk_typeof) - specs->typedef_p = true; + { + specs->typedef_p = true; + if (spec.expr) + { + if (specs->expr) + specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr), + specs->expr, spec.expr); + else + specs->expr = spec.expr; + specs->expr_const_operands &= spec.expr_const_operands; + } + } specs->type = type; } @@ -7829,31 +9225,31 @@ bool dupe = false; specs->declspecs_seen_p = true; gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE - && C_IS_RESERVED_WORD (scspec)); + && C_IS_RESERVED_WORD (scspec)); i = C_RID_CODE (scspec); if (specs->non_sc_seen_p) - warning (OPT_Wold_style_declaration, + warning (OPT_Wold_style_declaration, "%qE is not at beginning of declaration", scspec); switch (i) { case RID_INLINE: /* C99 permits duplicate inline. Although of doubtful utility, - it seems simplest to permit it in gnu89 mode as well, as - there is also little utility in maintaining this as a - difference between gnu89 and C99 inline. */ + it seems simplest to permit it in gnu89 mode as well, as + there is also little utility in maintaining this as a + difference between gnu89 and C99 inline. */ dupe = false; specs->inline_p = true; break; case RID_THREAD: dupe = specs->thread_p; if (specs->storage_class == csc_auto) - error ("%<__thread%> used with %<auto%>"); + error ("%<__thread%> used with %<auto%>"); else if (specs->storage_class == csc_register) - error ("%<__thread%> used with %<register%>"); + error ("%<__thread%> used with %<register%>"); else if (specs->storage_class == csc_typedef) - error ("%<__thread%> used with %<typedef%>"); + error ("%<__thread%> used with %<typedef%>"); else - specs->thread_p = true; + specs->thread_p = true; break; case RID_AUTO: n = csc_auto; @@ -7862,7 +9258,7 @@ n = csc_extern; /* Diagnose "__thread extern". */ if (specs->thread_p) - error ("%<__thread%> before %<extern%>"); + error ("%<__thread%> before %<extern%>"); break; case RID_REGISTER: n = csc_register; @@ -7871,7 +9267,7 @@ n = csc_static; /* Diagnose "__thread static". */ if (specs->thread_p) - error ("%<__thread%> before %<static%>"); + error ("%<__thread%> before %<static%>"); break; case RID_TYPEDEF: n = csc_typedef; @@ -7886,18 +9282,18 @@ if (n != csc_none) { if (specs->storage_class != csc_none && n != specs->storage_class) - { - error ("multiple storage classes in declaration specifiers"); - } + { + error ("multiple storage classes in declaration specifiers"); + } else - { - specs->storage_class = n; - if (n != csc_extern && n != csc_static && specs->thread_p) - { - error ("%<__thread%> used with %qE", scspec); - specs->thread_p = false; - } - } + { + specs->storage_class = n; + if (n != csc_extern && n != csc_static && specs->thread_p) + { + error ("%<__thread%> used with %qE", scspec); + specs->thread_p = false; + } + } } return specs; } @@ -7927,8 +9323,8 @@ if (specs->type != NULL_TREE) { gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p - && !specs->complex_p); + && !specs->signed_p && !specs->unsigned_p + && !specs->complex_p); return specs; } @@ -7940,32 +9336,32 @@ if (specs->typespec_word == cts_none) { if (specs->saturating_p) - { - error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>"); - if (!targetm.fixed_point_supported_p ()) - error ("fixed-point types not supported for this target"); - specs->typespec_word = cts_fract; - } + { + error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>"); + if (!targetm.fixed_point_supported_p ()) + error ("fixed-point types not supported for this target"); + specs->typespec_word = cts_fract; + } else if (specs->long_p || specs->short_p - || specs->signed_p || specs->unsigned_p) - { - specs->typespec_word = cts_int; - } + || specs->signed_p || specs->unsigned_p) + { + specs->typespec_word = cts_int; + } else if (specs->complex_p) - { - specs->typespec_word = cts_double; - pedwarn (input_location, OPT_pedantic, - "ISO C does not support plain %<complex%> meaning " - "%<double complex%>"); - } + { + specs->typespec_word = cts_double; + pedwarn (input_location, OPT_pedantic, + "ISO C does not support plain %<complex%> meaning " + "%<double complex%>"); + } else - { - specs->typespec_word = cts_int; - specs->default_int_p = true; - /* We don't diagnose this here because grokdeclarator will - give more specific diagnostics according to whether it is - a function definition. */ - } + { + specs->typespec_word = cts_int; + specs->default_int_p = true; + /* We don't diagnose this here because grokdeclarator will + give more specific diagnostics according to whether it is + a function definition. */ + } } /* If "signed" was specified, record this to distinguish "int" and @@ -7981,178 +9377,178 @@ case cts_CbC_code: #endif gcc_assert (!specs->long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p - && !specs->complex_p); + && !specs->signed_p && !specs->unsigned_p + && !specs->complex_p); specs->type = void_type_node; break; case cts_bool: gcc_assert (!specs->long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p - && !specs->complex_p); + && !specs->signed_p && !specs->unsigned_p + && !specs->complex_p); specs->type = boolean_type_node; break; case cts_char: gcc_assert (!specs->long_p && !specs->short_p); gcc_assert (!(specs->signed_p && specs->unsigned_p)); if (specs->signed_p) - specs->type = signed_char_type_node; + specs->type = signed_char_type_node; else if (specs->unsigned_p) - specs->type = unsigned_char_type_node; + specs->type = unsigned_char_type_node; else - specs->type = char_type_node; + specs->type = char_type_node; if (specs->complex_p) - { - pedwarn (input_location, OPT_pedantic, - "ISO C does not support complex integer types"); - specs->type = build_complex_type (specs->type); - } + { + pedwarn (input_location, OPT_pedantic, + "ISO C does not support complex integer types"); + specs->type = build_complex_type (specs->type); + } break; case cts_int: gcc_assert (!(specs->long_p && specs->short_p)); gcc_assert (!(specs->signed_p && specs->unsigned_p)); if (specs->long_long_p) - specs->type = (specs->unsigned_p - ? long_long_unsigned_type_node - : long_long_integer_type_node); + specs->type = (specs->unsigned_p + ? long_long_unsigned_type_node + : long_long_integer_type_node); else if (specs->long_p) - specs->type = (specs->unsigned_p - ? long_unsigned_type_node - : long_integer_type_node); + specs->type = (specs->unsigned_p + ? long_unsigned_type_node + : long_integer_type_node); else if (specs->short_p) - specs->type = (specs->unsigned_p - ? short_unsigned_type_node - : short_integer_type_node); + specs->type = (specs->unsigned_p + ? short_unsigned_type_node + : short_integer_type_node); else - specs->type = (specs->unsigned_p - ? unsigned_type_node - : integer_type_node); + specs->type = (specs->unsigned_p + ? unsigned_type_node + : integer_type_node); if (specs->complex_p) - { - pedwarn (input_location, OPT_pedantic, - "ISO C does not support complex integer types"); - specs->type = build_complex_type (specs->type); - } + { + pedwarn (input_location, OPT_pedantic, + "ISO C does not support complex integer types"); + specs->type = build_complex_type (specs->type); + } break; case cts_float: gcc_assert (!specs->long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p); + && !specs->signed_p && !specs->unsigned_p); specs->type = (specs->complex_p - ? complex_float_type_node - : float_type_node); + ? complex_float_type_node + : float_type_node); break; case cts_double: gcc_assert (!specs->long_long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p); + && !specs->signed_p && !specs->unsigned_p); if (specs->long_p) - { - specs->type = (specs->complex_p - ? complex_long_double_type_node - : long_double_type_node); - } + { + specs->type = (specs->complex_p + ? complex_long_double_type_node + : long_double_type_node); + } else - { - specs->type = (specs->complex_p - ? complex_double_type_node - : double_type_node); - } + { + specs->type = (specs->complex_p + ? complex_double_type_node + : double_type_node); + } break; case cts_dfloat32: case cts_dfloat64: case cts_dfloat128: gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p - && !specs->signed_p && !specs->unsigned_p && !specs->complex_p); + && !specs->signed_p && !specs->unsigned_p && !specs->complex_p); if (specs->typespec_word == cts_dfloat32) - specs->type = dfloat32_type_node; + specs->type = dfloat32_type_node; else if (specs->typespec_word == cts_dfloat64) - specs->type = dfloat64_type_node; + specs->type = dfloat64_type_node; else - specs->type = dfloat128_type_node; + specs->type = dfloat128_type_node; break; case cts_fract: gcc_assert (!specs->complex_p); if (!targetm.fixed_point_supported_p ()) - specs->type = integer_type_node; + specs->type = integer_type_node; else if (specs->saturating_p) - { - if (specs->long_long_p) - specs->type = specs->unsigned_p - ? sat_unsigned_long_long_fract_type_node - : sat_long_long_fract_type_node; - else if (specs->long_p) - specs->type = specs->unsigned_p - ? sat_unsigned_long_fract_type_node - : sat_long_fract_type_node; - else if (specs->short_p) - specs->type = specs->unsigned_p - ? sat_unsigned_short_fract_type_node - : sat_short_fract_type_node; - else - specs->type = specs->unsigned_p - ? sat_unsigned_fract_type_node - : sat_fract_type_node; - } + { + if (specs->long_long_p) + specs->type = specs->unsigned_p + ? sat_unsigned_long_long_fract_type_node + : sat_long_long_fract_type_node; + else if (specs->long_p) + specs->type = specs->unsigned_p + ? sat_unsigned_long_fract_type_node + : sat_long_fract_type_node; + else if (specs->short_p) + specs->type = specs->unsigned_p + ? sat_unsigned_short_fract_type_node + : sat_short_fract_type_node; + else + specs->type = specs->unsigned_p + ? sat_unsigned_fract_type_node + : sat_fract_type_node; + } else - { - if (specs->long_long_p) - specs->type = specs->unsigned_p - ? unsigned_long_long_fract_type_node - : long_long_fract_type_node; - else if (specs->long_p) - specs->type = specs->unsigned_p - ? unsigned_long_fract_type_node - : long_fract_type_node; - else if (specs->short_p) - specs->type = specs->unsigned_p - ? unsigned_short_fract_type_node - : short_fract_type_node; - else - specs->type = specs->unsigned_p - ? unsigned_fract_type_node - : fract_type_node; - } + { + if (specs->long_long_p) + specs->type = specs->unsigned_p + ? unsigned_long_long_fract_type_node + : long_long_fract_type_node; + else if (specs->long_p) + specs->type = specs->unsigned_p + ? unsigned_long_fract_type_node + : long_fract_type_node; + else if (specs->short_p) + specs->type = specs->unsigned_p + ? unsigned_short_fract_type_node + : short_fract_type_node; + else + specs->type = specs->unsigned_p + ? unsigned_fract_type_node + : fract_type_node; + } break; case cts_accum: gcc_assert (!specs->complex_p); if (!targetm.fixed_point_supported_p ()) - specs->type = integer_type_node; + specs->type = integer_type_node; else if (specs->saturating_p) - { - if (specs->long_long_p) - specs->type = specs->unsigned_p - ? sat_unsigned_long_long_accum_type_node - : sat_long_long_accum_type_node; - else if (specs->long_p) - specs->type = specs->unsigned_p - ? sat_unsigned_long_accum_type_node - : sat_long_accum_type_node; - else if (specs->short_p) - specs->type = specs->unsigned_p - ? sat_unsigned_short_accum_type_node - : sat_short_accum_type_node; - else - specs->type = specs->unsigned_p - ? sat_unsigned_accum_type_node - : sat_accum_type_node; - } + { + if (specs->long_long_p) + specs->type = specs->unsigned_p + ? sat_unsigned_long_long_accum_type_node + : sat_long_long_accum_type_node; + else if (specs->long_p) + specs->type = specs->unsigned_p + ? sat_unsigned_long_accum_type_node + : sat_long_accum_type_node; + else if (specs->short_p) + specs->type = specs->unsigned_p + ? sat_unsigned_short_accum_type_node + : sat_short_accum_type_node; + else + specs->type = specs->unsigned_p + ? sat_unsigned_accum_type_node + : sat_accum_type_node; + } else - { - if (specs->long_long_p) - specs->type = specs->unsigned_p - ? unsigned_long_long_accum_type_node - : long_long_accum_type_node; - else if (specs->long_p) - specs->type = specs->unsigned_p - ? unsigned_long_accum_type_node - : long_accum_type_node; - else if (specs->short_p) - specs->type = specs->unsigned_p - ? unsigned_short_accum_type_node - : short_accum_type_node; - else - specs->type = specs->unsigned_p - ? unsigned_accum_type_node - : accum_type_node; - } + { + if (specs->long_long_p) + specs->type = specs->unsigned_p + ? unsigned_long_long_accum_type_node + : long_long_accum_type_node; + else if (specs->long_p) + specs->type = specs->unsigned_p + ? unsigned_long_accum_type_node + : long_accum_type_node; + else if (specs->short_p) + specs->type = specs->unsigned_p + ? unsigned_short_accum_type_node + : short_accum_type_node; + else + specs->type = specs->unsigned_p + ? unsigned_accum_type_node + : accum_type_node; + } break; default: gcc_unreachable (); @@ -8175,17 +9571,17 @@ for (decl = globals; decl; decl = TREE_CHAIN (decl)) { /* Check for used but undefined static functions using the C - standard's definition of "used", and set TREE_NO_WARNING so - that check_global_declarations doesn't repeat the check. */ + standard's definition of "used", and set TREE_NO_WARNING so + that check_global_declarations doesn't repeat the check. */ if (TREE_CODE (decl) == FUNCTION_DECL - && DECL_INITIAL (decl) == 0 - && DECL_EXTERNAL (decl) - && !TREE_PUBLIC (decl) - && C_DECL_USED (decl)) - { - pedwarn (input_location, 0, "%q+F used but never defined", decl); - TREE_NO_WARNING (decl) = 1; - } + && DECL_INITIAL (decl) == 0 + && DECL_EXTERNAL (decl) + && !TREE_PUBLIC (decl) + && C_DECL_USED (decl)) + { + pedwarn (input_location, 0, "%q+F used but never defined", decl); + TREE_NO_WARNING (decl) = 1; + } wrapup_global_declaration_1 (decl); } @@ -8194,7 +9590,7 @@ { reconsider = false; for (decl = globals; decl; decl = TREE_CHAIN (decl)) - reconsider |= wrapup_global_declaration_2 (decl); + reconsider |= wrapup_global_declaration_2 (decl); } while (reconsider); @@ -8226,9 +9622,9 @@ if (pch_file) return; - /* Don't waste time on further processing if -fsyntax-only or we've - encountered errors. */ - if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in)) + /* Don't waste time on further processing if -fsyntax-only. + Continue for warning and errors issued during lowering though. */ + if (flag_syntax_only) return; /* Close the external scope. */ @@ -8242,10 +9638,10 @@ int flags; FILE * stream = dump_begin (TDI_tu, &flags); if (stream && tmp) - { - dump_node (tmp, flags & ~TDF_SLIM, stream); - dump_end (TDI_tu, stream); - } + { + dump_node (tmp, flags & ~TDF_SLIM, stream); + dump_end (TDI_tu, stream); + } } /* Process all file scopes in this compilation, and the external_scope, @@ -8256,7 +9652,7 @@ /* We're done parsing; proceed to optimize and emit assembly. FIXME: shouldn't be the front end's responsibility to call this. */ - cgraph_optimize (); + cgraph_finalize_compilation_unit (); /* After cgraph has had a chance to emit everything that's going to be emitted, output debug information for globals. */ @@ -8264,7 +9660,7 @@ { timevar_push (TV_SYMOUT); for (t = all_translation_units; t; t = TREE_CHAIN (t)) - c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); + c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); c_write_global_declarations_2 (BLOCK_VARS (ext_block)); timevar_pop (TV_SYMOUT); }