diff options
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 574 |
1 files changed, 332 insertions, 242 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 9159b3cf6e7..03d6dbd892b 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -443,7 +443,7 @@ static bool next_is_function_body; /* 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 *, tree *, @@ -584,7 +584,8 @@ c_finish_incomplete_decl (tree decl) && !DECL_EXTERNAL (decl) && TYPE_DOMAIN (type) == 0) { - warning (0, "array %q+D assumed to have one element", decl); + 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); @@ -843,7 +844,8 @@ pop_scope (void) 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; @@ -1089,13 +1091,14 @@ pop_file_scope (void) /* 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, location_t loc) +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)) @@ -1109,7 +1112,8 @@ pushtag (tree name, tree type, location_t loc) 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. */ @@ -2457,11 +2461,11 @@ implicit_decl_warning (tree id, tree olddecl) } } -/* Generate an implicit declaration for identifier FUNCTIONID as a +/* Generate an implicit declaration for identifier FUNCTIONID at LOC as a function of type int (). */ tree -implicitly_declare (tree functionid) +implicitly_declare (location_t loc, tree functionid) { struct c_binding *b; tree decl = 0; @@ -2514,8 +2518,8 @@ implicitly_declare (tree functionid) (TREE_TYPE (decl))); if (!comptypes (newtype, TREE_TYPE (decl))) { - warning (0, "incompatible implicit declaration of built-in" - " function %qD", decl); + warning_at (loc, 0, "incompatible implicit declaration of " + "built-in function %qD", decl); newtype = TREE_TYPE (decl); } } @@ -2523,8 +2527,7 @@ implicitly_declare (tree functionid) { if (!comptypes (newtype, TREE_TYPE (decl))) { - error ("incompatible implicit declaration of function %qD", - decl); + error_at (loc, "incompatible implicit declaration of function %qD", decl); locate_old_decl (decl); } } @@ -2538,7 +2541,7 @@ implicitly_declare (tree functionid) } /* Not seen before. */ - decl = build_decl (FUNCTION_DECL, functionid, default_function_type); + decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type); DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; C_DECL_IMPLICIT (decl) = 1; @@ -2570,7 +2573,7 @@ implicitly_declare (tree functionid) 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; @@ -2603,13 +2606,12 @@ undeclared_variable (tree id, location_t loc) LABEL_DECL with all the proper frills. */ static tree -make_label (tree name, location_t location) +make_label (location_t location, tree name) { - tree label = build_decl (LABEL_DECL, name, void_type_node); + tree label = build_decl (location, LABEL_DECL, name, void_type_node); DECL_CONTEXT (label) = current_function_decl; DECL_MODE (label) = VOIDmode; - DECL_SOURCE_LOCATION (label) = location; return label; } @@ -2646,7 +2648,7 @@ lookup_label (tree name) } /* No label binding for that identifier; make one. */ - label = make_label (name, input_location); + label = make_label (input_location, name); /* Ordinary labels go in the current function scope. */ bind (name, label, current_function_scope, @@ -2675,7 +2677,7 @@ declare_label (tree name) return b->decl; } - label = make_label (name, input_location); + label = make_label (input_location, name); C_DECLARED_LABEL_FLAG (label) = 1; /* Declared labels go in the current scope. */ @@ -2704,7 +2706,7 @@ define_label (location_t location, tree name) || (DECL_CONTEXT (label) != current_function_decl && C_DECLARED_LABEL_FLAG (label)))) { - error ("%Hduplicate label %qD", &location, label); + error_at (location, "duplicate label %qD", label); locate_old_decl (label); return 0; } @@ -2714,16 +2716,16 @@ define_label (location_t location, tree name) but not defined. Update its location to point to this definition. */ if (C_DECL_UNDEFINABLE_STMT_EXPR (label)) - error ("%Jjump into statement expression", label); + error_at (location, "jump into statement expression"); if (C_DECL_UNDEFINABLE_VM (label)) - error ("%Jjump into scope of identifier with variably modified type", - label); + error_at (location, + "jump into scope of identifier with variably modified type"); DECL_SOURCE_LOCATION (label) = location; } else { /* No label binding for that identifier; make one. */ - label = make_label (name, location); + label = make_label (location, name); /* Ordinary labels go in the current function scope. */ bind (name, label, current_function_scope, @@ -2731,8 +2733,9 @@ define_label (location_t location, tree name) } if (!in_system_header && lookup_name (name)) - warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace " - "for labels, identifier %qE conflicts", &location, name); + warning_at (location, OPT_Wtraditional, + "traditional C lacks a separate namespace " + "for labels, identifier %qE conflicts", name); nlist_se = XOBNEW (&parser_obstack, struct c_label_list); nlist_se->next = label_context_stack_se->labels_def; @@ -2882,7 +2885,7 @@ c_init_decl_processing (void) truthvalue_false_node = integer_zero_node; /* Even in C99, which has a real boolean type. */ - pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), + pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"), boolean_type_node)); input_location = save_loc; @@ -2893,15 +2896,16 @@ c_init_decl_processing (void) 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; @@ -2911,7 +2915,7 @@ c_make_fname_decl (tree id, int type_dep) 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; @@ -2940,7 +2944,7 @@ c_make_fname_decl (tree id, int type_dep) /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); } - finish_decl (decl, init, NULL_TREE, NULL_TREE); + finish_decl (decl, loc, init, NULL_TREE, NULL_TREE); return decl; } @@ -3078,7 +3082,7 @@ shadow_tag_warned (const struct c_declspecs *declspecs, int warned) if (t == 0) { t = make_node (code); - pushtag (name, t, input_location); + pushtag (input_location, name, t); } } } @@ -3174,21 +3178,24 @@ quals_from_declspecs (const struct c_declspecs *specs) 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, +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); + declarator->id_loc = loc; declarator->kind = cdk_array; declarator->declarator = 0; declarator->u.array.dimen = expr; @@ -3207,11 +3214,11 @@ build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, if (!flag_isoc99) { if (static_p || quals != NULL) - pedwarn (input_location, OPT_pedantic, + 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, + pedwarn (loc, OPT_pedantic, "ISO C90 does not support %<[*]%> array declarators"); } if (vla_unspec_p) @@ -3219,7 +3226,8 @@ build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, if (!current_scope->parm_flag) { /* C99 6.7.5.2p4 */ - error ("%<[*]%> not allowed in other than function prototype scope"); + error_at (loc, "%<[*]%> not allowed in other than " + "function prototype scope"); declarator->u.array.vla_unspec_p = false; return NULL; } @@ -3514,10 +3522,13 @@ c_maybe_initialize_eh (void) 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. */ + it must be determined now, from the initial value, or it is an error. + + INIT_LOC is the location of the initial value. */ void -finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree) +finish_decl (tree decl, location_t init_loc, tree init, + tree origtype, tree asmspec_tree) { tree type; bool was_incomplete = (DECL_SIZE (decl) == 0); @@ -3539,7 +3550,7 @@ finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree) init = 0; if (init) - store_init_value (decl, init, origtype); + store_init_value (init_loc, decl, init, origtype); if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL @@ -3747,7 +3758,8 @@ finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree) add_stmt (bind); BIND_EXPR_BODY (bind) = push_stmt_list (); } - add_stmt (build_stmt (DECL_EXPR, decl)); + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), + DECL_EXPR, decl)); } } @@ -3772,7 +3784,7 @@ finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree) { if (!DECL_FILE_SCOPE_P (decl) && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) - add_stmt (build_stmt (DECL_EXPR, decl)); + add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); } @@ -3798,7 +3810,8 @@ finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree) 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 (cleanup_decl, vec, NULL); + 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. */ @@ -3842,7 +3855,7 @@ push_parm_decl (const struct c_parm *parm) decl = pushdecl (decl); - finish_decl (decl, NULL_TREE, 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. @@ -3867,12 +3880,12 @@ mark_forward_parm_decls (void) /* 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 + 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, bool non_const) +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 @@ -3884,7 +3897,7 @@ build_compound_literal (tree type, tree init, bool non_const) 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); @@ -3892,7 +3905,7 @@ build_compound_literal (tree type, tree init, bool non_const) TREE_USED (decl) = 1; TREE_TYPE (decl) = type; TREE_READONLY (decl) = TYPE_READONLY (type); - store_init_value (decl, init, NULL_TREE); + store_init_value (loc, decl, init, NULL_TREE); if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) { @@ -3907,7 +3920,7 @@ build_compound_literal (tree type, tree init, bool non_const) 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; @@ -3938,7 +3951,7 @@ build_compound_literal (tree type, tree init, bool non_const) is valid for C++. */ void -check_compound_literal_type (struct c_type_name *type_name, location_t loc) +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, @@ -4202,6 +4215,7 @@ grokdeclarator (const struct c_declarator *declarator, bool bitfield = width != NULL; tree element_type; struct c_arg_info *arg_info = 0; + location_t loc = UNKNOWN_LOCATION; const char *errmsg; tree expr_dummy; bool expr_const_operands_dummy; @@ -4225,8 +4239,11 @@ grokdeclarator (const struct c_declarator *declarator, while (decl) switch (decl->kind) { - case cdk_function: case cdk_array: + loc = decl->id_loc; + /* FALL THRU. */ + + case cdk_function: case cdk_pointer: funcdef_syntax = (decl->kind == cdk_function); decl = decl->declarator; @@ -4237,6 +4254,7 @@ grokdeclarator (const struct c_declarator *declarator, break; case cdk_id: + loc = decl->id_loc; if (decl->u.id) name = decl->u.id; decl = 0; @@ -4275,9 +4293,9 @@ grokdeclarator (const struct c_declarator *declarator, && variably_modified_type_p (type, NULL_TREE)) { if (name) - error ("variably modified %qE at file scope", name); + error_at (loc, "variably modified %qE at file scope", name); else - error ("variably modified field at file scope"); + error_at (loc, "variably modified field at file scope"); type = integer_type_node; } @@ -4296,7 +4314,7 @@ grokdeclarator (const struct c_declarator *declarator, else { if (name) - pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, + pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, "type defaults to %<int%> in declaration of %qE", name); else @@ -4330,11 +4348,11 @@ grokdeclarator (const struct c_declarator *declarator, 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 (!flag_gen_aux_info && (TYPE_QUALS (element_type))) type = TYPE_MAIN_VARIANT (type); @@ -4352,15 +4370,15 @@ grokdeclarator (const struct c_declarator *declarator, || storage_class == csc_typedef)) { if (storage_class == csc_auto) - pedwarn (input_location, + 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 @@ -4377,19 +4395,20 @@ grokdeclarator (const struct c_declarator *declarator, { case FIELD: if (name) - error ("storage class specified for structure field %qE", - name); + error_at (loc, "storage class specified for structure " + "field %qE", name); else - error ("storage class specified for structure field"); + error_at (loc, "storage class specified for structure field"); break; case PARM: if (name) - error ("storage class specified for parameter %qE", name); + error_at (loc, "storage class specified for parameter %qE", + name); else - error ("storage class specified for unnamed parameter"); + error_at (loc, "storage class specified for unnamed parameter"); break; default: - error ("storage class specified for typename"); + error_at (loc, "storage class specified for typename"); break; } storage_class = csc_none; @@ -4406,15 +4425,17 @@ grokdeclarator (const struct c_declarator *declarator, /* It is fine to have 'extern const' when compiling at C and C++ intersection. */ if (!(warn_cxx_compat && constp)) - warning (0, "%qE initialized and declared %<extern%>", name); + warning_at (loc, 0, "%qE initialized and declared %<extern%>", + name); } else - error ("%qE 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 %qE 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 %qE specifies %<register%>", name); @@ -4422,12 +4443,12 @@ grokdeclarator (const struct c_declarator *declarator, else { if (storage_class == csc_extern && funcdef_flag) - error ("nested function %qE declared %<extern%>", name); + error_at (loc, "nested function %qE declared %<extern%>", name); else if (threadp && storage_class == csc_none) { - error ("function-scope %qE implicitly auto and declared " - "%<__thread%>", - name); + error_at (loc, "function-scope %qE implicitly auto and declared " + "%<__thread%>", + name); threadp = false; } } @@ -4472,7 +4493,7 @@ grokdeclarator (const struct c_declarator *declarator, /* 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"); + 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; @@ -4520,23 +4541,25 @@ grokdeclarator (const struct c_declarator *declarator, if (VOID_TYPE_P (type)) { if (name) - error ("declaration of %qE as array of voids", name); + error_at (loc, "declaration of %qE as array of voids", name); else - error ("declaration of type name as array of voids"); + error_at (loc, "declaration of type name as array of voids"); type = error_mark_node; } if (TREE_CODE (type) == FUNCTION_TYPE) { if (name) - error ("declaration of %qE as array of functions", name); + error_at (loc, "declaration of %qE as array of functions", + name); else - error ("declaration of type name as array of functions"); + 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 (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "invalid use of structure with flexible array member"); if (size == error_mark_node) @@ -4563,9 +4586,11 @@ grokdeclarator (const struct c_declarator *declarator, if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) { if (name) - error ("size of array %qE has non-integer type", name); + error_at (loc, "size of array %qE has non-integer type", + name); else - error ("size of unnamed array has non-integer type"); + error_at (loc, + "size of unnamed array has non-integer type"); size = integer_one_node; } @@ -4574,10 +4599,10 @@ grokdeclarator (const struct c_declarator *declarator, if (pedantic && size_maybe_const && integer_zerop (size)) { if (name) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C forbids zero-size array %qE", name); else - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C forbids zero-size array"); } @@ -4587,9 +4612,9 @@ grokdeclarator (const struct c_declarator *declarator, if (tree_int_cst_sgn (size) < 0) { if (name) - error ("size of array %qE is negative", name); + error_at (loc, "size of array %qE is negative", name); else - error ("size of unnamed array is negative"); + error_at (loc, "size of unnamed array is negative"); size = integer_one_node; } /* Handle a size folded to an integer constant but @@ -4614,7 +4639,7 @@ grokdeclarator (const struct c_declarator *declarator, else if ((decl_context == NORMAL || decl_context == FIELD) && current_scope == file_scope) { - error ("variably modified %qE at file scope", name); + error_at (loc, "variably modified %qE at file scope", name); size = integer_one_node; } else @@ -4665,9 +4690,10 @@ grokdeclarator (const struct c_declarator *declarator, && TREE_OVERFLOW (itype)) { if (name) - error ("size of array %qE is too large", name); + error_at (loc, "size of array %qE is too large", + name); else - error ("size of unnamed array is too large"); + error_at (loc, "size of unnamed array is too large"); type = error_mark_node; continue; } @@ -4703,7 +4729,7 @@ grokdeclarator (const struct c_declarator *declarator, } if (flexible_array_member && pedantic && !flag_isoc99 && !in_system_header) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C90 does not support flexible array members"); /* ISO C99 Flexible array members are effectively @@ -4738,7 +4764,7 @@ grokdeclarator (const struct c_declarator *declarator, /* Complain about arrays of incomplete types. */ if (!COMPLETE_TYPE_P (type)) { - error ("array type has incomplete element type"); + error_at (loc, "array type has incomplete element type"); type = error_mark_node; } else @@ -4788,7 +4814,7 @@ grokdeclarator (const struct c_declarator *declarator, || array_ptr_attrs != NULL_TREE || array_parm_static)) { - error ("static or type qualifiers in non-parameter array declarator"); + 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; @@ -4821,19 +4847,21 @@ grokdeclarator (const struct c_declarator *declarator, if (TREE_CODE (type) == FUNCTION_TYPE) { if (name) - error ("%qE declared as function returning a function", - name); + error_at (loc, "%qE declared as function returning a " + "function", name); else - error ("type name declared as function " - "returning a function"); + error_at (loc, "type name declared as function " + "returning a function"); type = integer_type_node; } if (TREE_CODE (type) == ARRAY_TYPE) { if (name) - error ("%qE declared as function returning an array", name); + error_at (loc, "%qE declared as function returning an array", + name); else - error ("type name declared as function returning an array"); + error_at (loc, "type name declared as function returning " + "an array"); type = integer_type_node; } errmsg = targetm.invalid_return_type (type); @@ -4861,10 +4889,10 @@ grokdeclarator (const struct c_declarator *declarator, function definitions in ISO C; GCC used to used them for noreturn functions. */ if (VOID_TYPE_P (type) && really_funcdef) - pedwarn (input_location, 0, + pedwarn (loc, 0, "function definition has qualified void return type"); else - warning (OPT_Wignored_qualifiers, + warning_at (loc, OPT_Wignored_qualifiers, "type qualifiers ignored on function return type"); type = c_build_qualified_type (type, type_quals); @@ -4894,7 +4922,7 @@ grokdeclarator (const struct c_declarator *declarator, if (pedantic && TREE_CODE (type) == FUNCTION_TYPE && type_quals) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C forbids qualified function types"); if (type_quals) type = c_build_qualified_type (type, type_quals); @@ -4927,10 +4955,10 @@ grokdeclarator (const struct c_declarator *declarator, && (decl_context == NORMAL || decl_context == FIELD) && variably_modified_type_p (type, NULL_TREE)) { - tree decl = build_decl (TYPE_DECL, NULL_TREE, type); + tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); DECL_ARTIFICIAL (decl) = 1; pushdecl (decl); - finish_decl (decl, NULL_TREE, NULL_TREE, NULL_TREE); + finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); TYPE_NAME (type) = decl; } @@ -4964,9 +4992,9 @@ grokdeclarator (const struct c_declarator *declarator, && TREE_OVERFLOW (TYPE_SIZE_UNIT (type))) { if (name) - error ("size of array %qE is too large", name); + error_at (loc, "size of array %qE is too large", name); else - error ("size of unnamed array is too large"); + 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(). */ type = error_mark_node; @@ -4979,16 +5007,16 @@ grokdeclarator (const struct c_declarator *declarator, tree decl; if (pedantic && TREE_CODE (type) == FUNCTION_TYPE && type_quals) - pedwarn (input_location, OPT_pedantic, + 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; + decl = build_decl (declarator->id_loc, + TYPE_DECL, declarator->u.id, type); if (declspecs->explicit_signed_p) 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) { @@ -5023,7 +5051,7 @@ grokdeclarator (const struct c_declarator *declarator, && !declspecs->inline_p); if (pedantic && TREE_CODE (type) == FUNCTION_TYPE && type_quals) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C forbids const or volatile function types"); if (type_quals) type = c_build_qualified_type (type, type_quals); @@ -5034,8 +5062,8 @@ grokdeclarator (const struct c_declarator *declarator, && 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), @@ -5051,7 +5079,7 @@ grokdeclarator (const struct c_declarator *declarator, && !(storage_class == csc_static || storage_class == csc_register))))) { - error ("variable or field %qE declared void", name); + error_at (loc, "variable or field %qE declared void", name); type = integer_type_node; } @@ -5081,15 +5109,15 @@ grokdeclarator (const struct c_declarator *declarator, /* We don't yet implement attributes in this context. */ if (array_ptr_attrs != NULL_TREE) - warning (OPT_Wattributes, - "attributes in parameter array declarator ignored"); + warning_at (loc, 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, + pedwarn (loc, OPT_pedantic, "ISO C forbids qualified function types"); if (type_quals) type = c_build_qualified_type (type, type_quals); @@ -5099,8 +5127,8 @@ grokdeclarator (const struct c_declarator *declarator, 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; + decl = build_decl (declarator->id_loc, + PARM_DECL, declarator->u.id, type); if (size_varies) C_DECL_VARIABLE_SIZE (decl) = 1; @@ -5116,7 +5144,7 @@ grokdeclarator (const struct c_declarator *declarator, DECL_ARG_TYPE (decl) = promoted_type; if (declspecs->inline_p) - pedwarn (input_location, 0, "parameter %q+D declared %<inline%>", decl); + pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl); } else if (decl_context == FIELD) { @@ -5129,21 +5157,21 @@ grokdeclarator (const struct c_declarator *declarator, if (TREE_CODE (type) == FUNCTION_TYPE) { - error ("field %qE declared as a function", name); + 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 ("field %qE has incomplete type", name); + error_at (loc, "field %qE has incomplete type", name); else - error ("unnamed field has incomplete type"); + error_at (loc, "unnamed field has incomplete type"); 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 = 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; @@ -5155,7 +5183,7 @@ grokdeclarator (const struct c_declarator *declarator, { if (storage_class == csc_register || threadp) { - error ("invalid storage class for function %qE", name); + error_at (loc, "invalid storage class for function %qE", name); } else if (current_scope != file_scope) { @@ -5165,11 +5193,11 @@ grokdeclarator (const struct c_declarator *declarator, GCC allows 'auto', perhaps with 'inline', to support nested functions. */ if (storage_class == csc_auto) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "invalid storage class for function %qE", name); else if (storage_class == csc_static) { - error ("invalid storage class for function %qE", name); + error_at (loc, "invalid storage class for function %qE", name); if (funcdef_flag) storage_class = declspecs->storage_class = csc_none; else @@ -5177,19 +5205,19 @@ grokdeclarator (const struct c_declarator *declarator, } } - decl = build_decl (FUNCTION_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; + 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 (input_location, OPT_pedantic, + 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 (0, "%<noreturn%> function returns non-void value"); + 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 @@ -5225,7 +5253,7 @@ grokdeclarator (const struct c_declarator *declarator, if (flag_hosted && MAIN_NAME_P (declarator->u.id)) { if (declspecs->inline_p) - pedwarn (input_location, 0, "cannot inline function %<main%>"); + pedwarn (loc, 0, "cannot inline function %<main%>"); } else if (declspecs->inline_p) /* Record that the function is declared `inline'. */ @@ -5254,17 +5282,17 @@ grokdeclarator (const struct c_declarator *declarator, && global_decl != visible_decl && TREE_CODE (global_decl) == VAR_DECL && !TREE_PUBLIC (global_decl)) - error ("variable previously declared %<static%> redeclared " - "%<extern%>"); + error_at (loc, "variable previously declared %<static%> " + "redeclared %<extern%>"); } - decl = build_decl (VAR_DECL, declarator->u.id, type); - DECL_SOURCE_LOCATION (decl) = declarator->id_loc; + 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 (input_location, 0, "variable %q+D declared %<inline%>", decl); + 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 @@ -5299,9 +5327,10 @@ grokdeclarator (const struct c_declarator *declarator, { /* C99 6.7.5.2p2 */ if (TREE_CODE (type) == FUNCTION_TYPE) - error ("non-nested function with variably modified type"); + error_at (loc, "non-nested function with variably modified type"); else - error ("object with variably modified type must have no linkage"); + error_at (loc, "object with variably modified type must have " + "no linkage"); } /* Record `register' declaration for warnings on & @@ -5634,11 +5663,12 @@ get_parm_info (bool ellipsis) } /* 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, location_t loc) +parser_xref_tag (location_t loc, enum tree_code code, tree name) { struct c_typespec ret; tree ref; @@ -5717,7 +5747,7 @@ parser_xref_tag (enum tree_code code, tree name, location_t loc) TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); } - pushtag (name, ref, loc); + pushtag (loc, name, ref); ret.spec = ref; return ret; @@ -5730,11 +5760,12 @@ parser_xref_tag (enum tree_code code, tree name, location_t loc) tree xref_tag (enum tree_code code, tree name) { - return parser_xref_tag (code, name, UNKNOWN_LOCATION).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. + 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 IN_STRUCT in @@ -5744,8 +5775,9 @@ xref_tag (enum tree_code code, tree name) finish_struct. */ tree -start_struct (enum tree_code code, tree name, bool *enclosing_in_struct, - VEC(tree,heap) **enclosing_struct_types, location_t loc) +start_struct (location_t loc, enum tree_code code, tree name, + bool *enclosing_in_struct, + VEC(tree,heap) **enclosing_struct_types) { /* If there is already a tag defined at this scope (as a forward reference), just return it. */ @@ -5787,7 +5819,7 @@ start_struct (enum tree_code code, tree name, bool *enclosing_in_struct, if (ref == NULL_TREE || TREE_CODE (ref) != code) { ref = make_node (code); - pushtag (name, ref, loc); + pushtag (loc, name, ref); } C_TYPE_BEING_DEFINED (ref) = 1; @@ -5881,7 +5913,7 @@ grokfield (location_t loc, width ? &width : NULL, decl_attrs, NULL, NULL, DEPRECATED_NORMAL); - finish_decl (value, NULL_TREE, NULL_TREE, NULL_TREE); + finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE); DECL_INITIAL (value) = width; return value; @@ -5945,6 +5977,7 @@ detect_field_duplicates (tree fieldlist) } /* 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. @@ -5954,7 +5987,7 @@ detect_field_duplicates (tree fieldlist) for any type defined in the current struct. */ tree -finish_struct (tree t, tree fieldlist, tree attributes, +finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, bool enclosing_in_struct, VEC(tree,heap) *enclosing_struct_types) { @@ -5981,16 +6014,16 @@ finish_struct (tree t, tree fieldlist, tree attributes, if (TREE_CODE (t) == UNION_TYPE) { if (fieldlist) - pedwarn (input_location, OPT_pedantic, "union has no named members"); + pedwarn (loc, OPT_pedantic, "union has no named members"); else - pedwarn (input_location, OPT_pedantic, "union has no members"); + pedwarn (loc, OPT_pedantic, "union has no members"); } else { if (fieldlist) - pedwarn (input_location, OPT_pedantic, "struct has no named members"); + pedwarn (loc, OPT_pedantic, "struct has no named members"); else - pedwarn (input_location, OPT_pedantic, "struct has no members"); + pedwarn (loc, OPT_pedantic, "struct has no members"); } } } @@ -6054,24 +6087,28 @@ finish_struct (tree t, tree fieldlist, tree attributes, { if (TREE_CODE (t) == UNION_TYPE) { - error ("%Jflexible array member in union", x); + error_at (DECL_SOURCE_LOCATION (x), + "%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); + error_at (DECL_SOURCE_LOCATION (x), + "%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); + error_at (DECL_SOURCE_LOCATION (x), + "%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, + pedwarn (loc, OPT_pedantic, "%Jinvalid use of structure with flexible array member", x); if (DECL_NAME (x)) @@ -6181,7 +6218,7 @@ finish_struct (tree t, tree fieldlist, tree attributes, && (!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 @@ -6212,7 +6249,8 @@ finish_struct (tree t, tree fieldlist, tree attributes, 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))); /* 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 @@ -6247,12 +6285,13 @@ layout_array_type (tree t) /* 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, location_t loc) +start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) { tree enumtype = NULL_TREE; location_t enumloc = UNKNOWN_LOCATION; @@ -6267,7 +6306,7 @@ start_enum (struct c_enum_contents *the_enum, tree name, location_t loc) if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) { enumtype = make_node (ENUMERAL_TYPE); - pushtag (name, enumtype, loc); + pushtag (loc, name, enumtype); } if (C_TYPE_BEING_DEFINED (enumtype)) @@ -6452,12 +6491,13 @@ finish_enum (tree enumtype, tree values, tree attributes) /* 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; @@ -6471,7 +6511,8 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, value = 0; else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) { - error ("enumerator value for %qE is not an integer constant", name); + error_at (loc, "enumerator value for %qE is not an integer constant", + name); value = 0; } else @@ -6480,7 +6521,7 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, { value = c_fully_fold (value, false, NULL); if (TREE_CODE (value) == INTEGER_CST) - pedwarn (value_loc, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "enumerator value for %qE is not an integer " "constant expression", name); } @@ -6505,14 +6546,14 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, { 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, + pedwarn (loc, OPT_pedantic, "ISO C restricts enumerator values to range of %<int%>"); /* The ISO C Standard mandates enumerators to have type int, even @@ -6543,7 +6584,7 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, >= TYPE_PRECISION (integer_type_node) && TYPE_UNSIGNED (type))); - decl = build_decl (CONST_DECL, name, type); + decl = build_decl (loc, CONST_DECL, name, type); DECL_INITIAL (decl) = convert (type, value); pushdecl (decl); @@ -6571,6 +6612,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, 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; @@ -6608,13 +6650,16 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, 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 @@ -6631,7 +6676,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, 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, @@ -6639,7 +6684,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, } if (warn_about_return_type) - pedwarn_c99 (input_location, flag_isoc99 ? 0 + pedwarn_c99 (loc, flag_isoc99 ? 0 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), "return type defaults to %<int%>"); @@ -6706,15 +6751,16 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, && 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); + 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 @@ -6722,15 +6768,16 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, && 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); + 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); + 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 @@ -6738,8 +6785,8 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, && 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); + 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!) */ @@ -6762,12 +6809,13 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, { 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); + 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. @@ -6780,7 +6828,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, 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; @@ -6866,8 +6914,8 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) 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. */ @@ -6875,7 +6923,8 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) { if (TREE_VALUE (parm) == 0) { - error ("%Jparameter name missing from parameter list", fndecl); + error_at (DECL_SOURCE_LOCATION (fndecl), + "parameter name missing from parameter list"); TREE_PURPOSE (parm) = 0; continue; } @@ -6886,12 +6935,14 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) 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); + 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 ("multiple parameters named %q+D", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "multiple parameters named %qD", decl); TREE_PURPOSE (parm) = 0; continue; } @@ -6899,7 +6950,8 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) an int. */ else if (VOID_TYPE_P (TREE_TYPE (decl))) { - error ("parameter %q+D declared with void 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); @@ -6909,16 +6961,30 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) /* If no declaration found, default to int. */ else { - decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node); + /* 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); - 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); + pedwarn (DECL_SOURCE_LOCATION (decl), + 0, "type of %qD defaults to %<int%>", decl); else - warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl); + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Wmissing_parameter_type, + "type of %qD defaults to %<int%>", decl); } TREE_PURPOSE (parm) = decl; @@ -6937,13 +7003,16 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) if (TREE_TYPE (parm) != error_mark_node && !COMPLETE_TYPE_P (TREE_TYPE (parm))) { - error ("parameter %q+D has incomplete 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); + 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 @@ -6993,13 +7062,22 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) || 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"); + warning_at (DECL_SOURCE_LOCATION (fndecl), + 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); + /* 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; } @@ -7032,11 +7110,13 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) 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); + warning_at (DECL_SOURCE_LOCATION (parm), + OPT_pedantic, "promoted argument %qD " + "doesn%'t match built-in prototype", parm); else { - pedwarn (input_location, OPT_pedantic, "promoted argument %qD " + pedwarn (DECL_SOURCE_LOCATION (parm), + OPT_pedantic, "promoted argument %qD " "doesn%'t match prototype", parm); pedwarn (current_function_prototype_locus, OPT_pedantic, "prototype declaration"); @@ -7045,13 +7125,15 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) else { if (current_function_prototype_built_in) - warning (0, "argument %qD doesn%'t match " - "built-in prototype", parm); + warning_at (DECL_SOURCE_LOCATION (parm), + 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); + error_at (DECL_SOURCE_LOCATION (parm), + "argument %qD doesn%'t match prototype", parm); + error_at (current_function_prototype_locus, + "prototype declaration"); } } } @@ -7228,14 +7310,13 @@ finish_function (void) && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) == integer_type_node && flag_isoc99) { - tree stmt = c_finish_return (integer_zero_node, NULL_TREE); /* 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. */ - SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); + c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE); } /* Tie off the statement tree for this function. */ @@ -7315,10 +7396,11 @@ finish_function (void) } /* 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; @@ -7330,10 +7412,11 @@ check_for_loop_decls (void) /* 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"); + error_at (loc, "%<for%> loop initial declarations " + "are only allowed in C99 mode"); if (hint) { - inform (input_location, + inform (loc, "use option -std=c99 or -std=gnu99 to compile your code"); hint = false; } @@ -7364,29 +7447,36 @@ check_for_loop_decls (void) 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); + { + 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 ("%<struct %E%> declared in %<for%> loop initial declaration", - id); + error_at (loc, + "%<struct %E%> declared in %<for%> loop initial " + "declaration", id); break; case UNION_TYPE: - error ("%<union %E%> declared in %<for%> loop initial declaration", - id); + error_at (loc, + "%<union %E%> declared in %<for%> loop initial declaration", + id); break; case ENUMERAL_TYPE: - error ("%<enum %E%> declared in %<for%> loop initial declaration", - id); + error_at (loc, "%<enum %E%> declared in %<for%> loop " + "initial declaration", id); break; default: - error ("declaration of non-variable %q+D in %<for%> loop " - "initial declaration", decl); + error_at (loc, "declaration of non-variable " + "%qD in %<for%> loop initial declaration", decl); } n_decls++; @@ -7506,7 +7596,7 @@ record_builtin_type (enum rid rid_index, const char *name, tree type) 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); |