diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2009-06-12 22:06:47 +0000 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2009-06-12 22:06:47 +0000 |
commit | a0e5a6139d05c3a0bcd1e7506764377dd3915566 (patch) | |
tree | 67f495ddc3964a90084152e177995da72e7bce30 /gcc/c-typeck.c | |
parent | a4e77de6c21b2ec9daf1b1c113838ed63b56396f (diff) |
gcc/java/
* java-gimplify.c (java_gimplify_block): New argument to
build_empty_stmt.
* expr.c (force_evaluation_order): Same.
* typeck.c: Add location to build_decl or PUSH_FIELD calls.
* class.c: Same.
* decl.c: Same.
* jcf-parse.c: Same.
* constants.c: Same.
* resource.c: Same.
* except.c: Same.
* builtins.c: Same.
* expr.c: Same.
* java-tree.h (PUSH_FIELD): Add location field.
gcc/objc/
* objc-act.c (finish_var_decl): Pass location to finish_decl.
(objc_get_parm_info): Same.
(get_super_receiver): Same.
* objc-act.c (objc_build_component_ref): Pass location to
build_compound_ref.
(build_module_initializer_routine): Pass location to
c_end_compound_stmt.
(objc_generate_static_init_call): Pass location to build_stmt.
(build_typed_selector_reference): New location argument.
(build_selector_reference): Same.
(objc_substitute_decl): Pass location to build_array_ref.
(next_sjlj_build_try_catch_finally): Pass location to build_stmt.
(objc_begin_catch_clause): Same.
(objc_finish_try_stmt): Same.
(objc_finish_catch_clause): Pass location to c_end_compound_stmt.
(objc_build_throw_stmt): New argument.
(generate_shared_structures): Pass location to build_c_cast.
(objc_build_message_expr): Use local location.
(objc_finish_message_expr): Use input_location.
(build_objc_method_call): New argument.
(objc_build_selector_expr): Same.
(get_super_receiver): Pass location to build_c_cast,
build_modify_expr, build_compound_expr.
* objc-act.c: Add location to all calls to start_struct, build_decl,
finish_struct.
gcc/
* tree-pretty-print.c (dump_generic_node): Dump column numbers.
* gimple-pretty-print.c (dump_gimple_stmt): Same.
* gimplify.c (gimplify_modify_expr): Set location for GIMPLE_ASSIGNs
created.
* c-parser.c (c_parser_binary_expression): Use current column while
building binary operations.
* common.opt (fshow-column): Enable by default.
* tree-vrp.c (check_array_ref): Use warning_at.
(check_array_bounds): Use location from call back if expr has no
location.
* tree.h: Add location argument to maybe_fold_*.
* tree-ssa-ccp.c (ccp_fold): Pass location to maybe_fold_*.
(maybe_fold_offset_to_array_ref): Add location argument and use it.
(maybe_fold_offset_to_component_ref): Same.
(maybe_fold_offset_to_reference): Same.
(maybe_fold_offset_to_address): Same.
(maybe_fold_stmt_indirect): Same.
(maybe_fold_stmt_addition): Same.
(fold_stmt_r): Pass location to maybe_fold_*.
(fold_gimple_assign): Same.
* c-tree.h: Add location argument to finish_decl,
default_function_array_conversion, store_init_value.
* c-decl.c (define_label): Use error_at.
(c_make_fname_decl): Pass location to finish_decl.
(finish_decl): New location argument.
(build_compound_literal): Pass location to store_init_value.
(grokdeclarator): Pass location to finish_decl.
(grokfield): Same.
* c-typeck.c (array_to_pointer_conversion): New location argument.
(function_to_pointer_conversion): Same.
(default_function_array_conversion): Same.
(parser_build_unary_op): Pass location to overflow_warning.
(parser_build_binary_op): Same. Use warning_at.
(build_unary_op): Pass location to array_to_pointer_conversion.
(build_c_cast): Pass location to digest_init.
(build_modify_expr): New location argument.
(convert_for_assignment): Same.
(store_init_value): Same.
(digest_init): Same.
(output_init_element): Pass location to digest_init and
array_to_pointer_conversion.
(c_finish_return): Pass location to convert_for_assignment.
* gimplify.c (gimplify_conversion): Pass location to
maybe_fold_offset_to_address.
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Pass location
to maybe_fold_stmt_addition.
* c-omp.c (c_finish_omp_atomic): Pass new location to
build_modify_expr.
(c_finish_omp_for): Same.
* c-common.c (overflow_warning): New argument.
* c-common.h: New argument to build_modify_expr, overflow_warning.
* c-parser.c (c_parser_declaration_or_fndef): Pass location to
finish_decl.
(c_parser_initializer): Pass location to
default_function_array_conversion.
(c_parser_initelt): Same.
(c_parser_initval): Same.
(c_parser_asm_operands): Same.
(c_parser_expr_no_commas): Same. Pass location to build_modify_expr.
(c_parser_conditional_expression): Same.
(c_parser_binary_expression): Add location info to stack. Use it.
(c_parser_unary_expression): Pass location to
default_function_array_conversion, parser_build_unary_op,
build_indirect_ref, c_parser_postfix_expression_after_primary.
(c_parser_postfix_expression_after_primary): New location argument.
Use it.
(c_parser_expression_conv): Pass location to
default_function_array_conversion.
(c_parser_expr_list): Same.
(c_parser_omp_atomic): Same.
(c_parser_omp_for_loop): Same.
* c-tree.h: (struct c_declarator): Add comment to id_loc.
(build_array_declarator): New argument.
* c-decl.c (build_array_declarator): Add location argument.
(grokdeclarator): Set id_loc for cdk_array.
* c-parser.c (c_parser_direct_declarator_inner): Pass location to
build_array_declarator.
* tree.c (build_omp_clause): Add location argument.
* tree.h (OMP_CLAUSE_HAS_LOCATION): New macro.
(OMP_CLAUSE_LOCATION): New macro.
(struct tree_omp_clause): Add location field.
(build_omp_clause): Add argument.
* testsuite/gcc.dg/gomp/for-1.c: Fix column.
* cp/pt.c (tsubst_omp_for_iterator): Pass location to
build_omp_clause.
* cp/parser.c (cp_parser_omp_var_list_no_open): Same.
(cp_parser_omp_clause_collapse): Same.
(cp_parser_omp_clause_default): Same.
(cp_parser_omp_clause_if): Same.
(cp_parser_omp_clause_nowait): Same.
(cp_parser_omp_clause_num_threads): Same.
(cp_parser_omp_clause_ordered): Same.
(cp_parser_omp_clause_schedule): Same.
(cp_parser_omp_clause_untied): Same.
(cp_parser_omp_for_loop): Same.
(cp_parser_omp_parallel): Pass location to c_split_parallel_clauses.
* c-tree.h (c_start_case): Add location argument.
(c_process_expr_stmt): Same.
(c_finish_goto_*): Same.
* tree-parloops.c (initialize_reductions): Pass location to
build_omp_clause.
(create_parallel_loop): Same.
* fortran/trans-openmp.c (gfc_trans_omp_variable_list): Same.
(gfc_trans_omp_reduction_list): Same.
(gfc_trans_omp_clauses): Same.
(gfc_trans_omp_do): Same.
* c-typeck.c (c_finish_goto_label): Same.
(c_finish_goto_ptr): New location argument.
(c_start_case): Same.
(emit_side_effect_warnings): Same.
(c_process_expr_stmt): Same.
(c_finish_stmt_expr): Same.
(c_finish_omp_clauses): Use error_at instead of error.
* gimplify.c (gimplify_adjust_omp_clauses_1): Pass location to
build_omp_clause.
* c-omp.c (c_split_parallel_clauses): New location argument.
* tree-nested.c (convert_nonlocal_reference_stmt): Pass location
to build_omp_clause.
(convert_local_reference_stmt): Same.
(convert_gimple_call): Same.
* c-common.h (c_split_parallel_clauses): New argument.
* c-parser.c (c_parser_statement_after_labels): Pass location to
c_finish_goto_label.
(c_parser_switch_statement): Pass location to c_start_case.
(c_parser_for_statement): Pass location to c_finish_expr_stmt,
and c_process_expr_stmt.
(c_parser_omp_variable_list): Add location argument.
(c_parser_omp_clause_collapse): Pass location to
build_omp_clause.
(c_parser_omp_clause_default): Same.
(c_parser_omp_clause_if): Same.
(c_parser_omp_clause_num_threads): Same.
(-c_parser_omp_clause_ordered): Same.
(c_parser_omp_clause_reduction): Pass location to
c_parser_omp_variable_list.
(c_parser_omp_clause_schedule): Pass location to build_omp_clause.
(c_parser_omp_clause_untied): Same.
(c_parser_omp_for_loop): Pass location to c_process_expr_stmt.
(c_parser_omp_parallel): Pass location to
c_split_parallel_clauses.
* c-tree.h (check_for_loop_decls, undeclared_variable,
build_component_ref, build_array_ref, build_external_ref,
c_expr_sizeof_expr, c_expr_sizeof_type, parser_build_unary_op,
build_conditional_expr, build_compound_expr, c_cast_expr,
build_c_cast, build_asm_expr, c_end_compound_stmt, c_finish_stmt_expr,
c_finish_return, c_finish_omp_parallel, c_finish_omp_task): New
argument.
* c-semantics.c (build_stmt): Same.
(build_case_label): Same.
* c-decl.c (c_finish_incomplete_decl): Pass location on down.
(undeclared_variable): New argument.
(make_label): Same.
(lookup_label): Pass location on down.
(define_label): Same.
(finish_decl): Same.
(build_compound_literal): Same.
(finish_struct): Same.
(finish_function): Do not set location here.
(check_for_loop_decls): New argument.
* tree.c (save_expr): Set location.
(build_empty_stmt): New argument.
* tree.h (build_empty_stmt): New argument to build_empty_stmt.
(CAN_HAVE_LOCATION_P): Make sure we have a non empty node.
* builtins.c (gimplify_va_arg_expr): Use locations.
(expand_builtin_sync_operation): Same.
* c-typeck.c (build_component_ref): New argument.
(build_array_ref): Same.
(build_external_ref): Same.
(c_expr_sizeof_expr): Same.
(c_expr_sizeof_type): Same.
(parser_build_unary_op): Same.
(build_conditional_expr): Same.
(build_compound_expr): Pass location on down.
(build_compound_expr): New argument.
(build_c_cast): Same.
(c_cast_expr): Same.
(build_asm_expr): Same.
(c_finish_return): Same.
(c_process_expr_stmt): Pass location on down.
(c_finish_stmt_expr): New argument.
(push_clenaup): Same.
(c_finish_omp_parallel): Same.
(c_finish_omp_task): Same.
* gimplify.c (gimplify_call_expr): Pass location on down.
* c-omp.c (c_finish_omp_master): New argument.
(c_finish_omp_critical): Same.
(c_finish_omp_ordered): Same.
(c_finish_omp_barrier): Same.
(-c_finish_omp_taskwait): Same.
(c_finish_omp_atomic): Same.
(c_finish_omp_flush): Same.
* tree-inline.c (copy_tree_body_r): Pass location on down.
(inline_forbidden_p): Remove use of input_location.
* c-gimplify.c (c_build_bind_expr): New argument.
* c-common.c (c_common_truthvalue_conversion): Pass location on down.
(c_sizeof_or_alignof_type): New argument.
(c_alignof_expr): Same.
(build_va_arg): Same.
(c_add_case_label): Same.
* c-common.h (c_sizeof_or_alignof_type, c_alignof_expr,
c_sizeof, c_alignof, build_va_arg, build_stmt, build_case_label,
c_build_bind_expr, objc_build_selector_expr, objc_build_throw_stmt,
c_finish_omp_master, c_finish_omp_critical, c_finish_omp_ordered,
c_finish_omp_barrier, c_finish_omp_atomic, c_finish_omp_flush,
c_finish_omp_taskwait, c_finish_omp_for, c_split_parallel_clauses):
New argument.
* stub-objc.c (objc_build_selector_expr): Same.
(objc_build_throw_stmt): Same.
* c-parser.c (c_parser_declaration_or_fndef): Pass location on down.
(c_parser_initelt): Same.
(c_parser_compound_statement): Same.
(c_parser_compound_statement_nostart): Same.
(c_parser_label): Same.
(c_parser_statement_after_labels): Same.
(c_parser_if_body): Same.
(c_parser_else_body): Same.
(c_parser_if_statement): Same.
(c_parser_switch_statement): Same.
(c_parser_while_statement): Same.
(c_parser_do_statement): Same.
(c_parser_for_statement): Same.
(c_parser_asm_statement): Same.
(c_parser_conditional_expression): Same.
(c_parser_binary_expression): Same.
(c_parser_cast_expression): Same.
(c_parser_unary_expression): Same.
(c_parser_sizeof_expression): Same.
(c_parser_alignof_expression): Same.
(c_parser_postfix_expression): Same.
(c_parser_expression): Same.
(c_parser_objc_receiver): Same.
(c_parser_omp_variable_list): Same.
(c_parser_omp_structured_block): Same.
(c_parser_omp_atomic): New argument.
(c_parser_omp_barrier): Same.
(c_parser_omp_critical): Same.
(c_parser_omp_flush): Pass location on down.
(c_parser_omp_for_loop): New argument.
(c_parser_omp_for): Same.
(c_parser_omp_master): Same.
(c_parser_omp_ordered): Same.
(c_parser_omp_sections_scope): Same.
(c_parser_omp_sections): Same.
(c_parser_omp_parallel): Same.
(c_parser_omp_single): Same.
(c_parser_omp_task): Same.
(c_parser_omp_taskwait): Pass location on down.
(c_parser_omp_construct): Same.
(c_parser_omp_threadprivate): Same.
* dwarf2asm.c, targhooks.c, optabs.c, tree.c, tree.h, target.h,
builtins.c, omp-low.c, cgraphunit.c, tree-call-cdce.c,
tree-ssa-alias.c, gimple-low.c, c-tree.h, expr.c, tree-parloops.c,
c-decl.c, tree-eh.c, langhooks.c, function.c, stor-layout.c,
c-typeck.c, gimplify.c, c-pragma.c, expmed.c, except.c, coverage.c,
emit-rtl.c, cfgexpand.c, tree-mudflap.c, varasm.c, tree-nested.c,
rtl.h, tree-inline.c, tree-profile.c, c-common.c, c-common.h,
tree-switch-conversion.c, tree-cfg.c, ipa-struct-reorg.c, c-parser.c,
config/i386/i386.c, stmt.c:
Add location argument to the following function definitions and/or
function calls: build_decl, objcp_start_struct, objcp_finish_struct,
start_struct, finish_struct, PUSH_FIELD, create_artificial_label,
cp_make_fname_decl, pushtag, implicitly_declare, c_make_fname_decl,
build_compound_literal, parser_xref_tag, resolve_overloaded_builtin,
do_case, c_finish_bc_stmt, build_compound_literal,
build_function_call.
* c-decl.c (build_compound_literal): Add location argument.
Make all diagnostic calls use location.
(start_struct): Same.
(finish_struct): Same.
(start_enum): Same.
(build_enumerator): Same.
(start_function): Same.
(grokdeclarator): Make all diagnostic calls use location.
(store_parm_decls_oldstyle): Same.
* c-typeck.c (build_function_call): Add location argument.
Make all diagnostic calls use location.
(do_case): Same.
(c_finish_bc_stmt): Same.
* tree-nested.c (get_trampoline_type): Add argument.
Pass location to build_decl.
(lookup_tramp_for_decl): Pass location to get_trampoline_type.
* rtl.h (RTL_LOCATION): New.
* c-common.c (c_add_case_label): Add location argument.
Make all diagnostic calls use location.
* c-common.h: Add location argument to make_fname_decl, do_case,
c_add_case_label, build_function_call, resolve_overloaded_builtin.
* c-parser.c (c_parser_enum_specifier): Rename ident_loc to enum_loc.
Set it appropriately for every case. Pass enum_loc to start_enum
call. Pass value_loc first to build_enumerator. Pass enum_loc to
parser_xref_tag.
(c_parser_struct_or_union_specifier): Save location. Use it for
start_struct, finish_struct, and parser_xref_tag.
gcc/testsuite/
* gcc.dg/old-style-prom-3.c: Add column info.
* gcc.dg/overflow-warn-1.c
* gcc.dg/gomp/pr27415.c
* gcc.dg/gomp/for-1.c: Same.
* gcc.dg/enum-compat-1.c: Same.
* gcc.dg/c99-tag-3.c: Same.
* gcc.dg/Wredundant-decls-2.c: Same.
* gcc.dg/func-ptr-conv-1.c: Same.
* gcc.dg/asm-wide-1.c: Same.
* gcc.dg/nofixed-point-2.c: Same.
* gcc.dg/cpp/line3.c: Same.
* gcc.dg/array-10.c: Same.
* gcc.dg/c99-vla-jump-1.c: Same.
* gcc.dg/pr20368-1.c: Same.
* gcc.dg/Wshadow-3.c: Same.
* gcc.dg/c90-const-expr-8.c: Same.
* gcc.dg/label-decl-2.c: Same.
* gcc.dg/dremf-type-compat-2.c: Same.
* gcc.dg/c90-const-expr-5.c: Same.
* gcc.dg/builtins-30.c: Same.
* gcc.dg/Warray-bounds.c: Same.
* gcc.dg/Wcxx-compat-2.c: Same.
* gcc.dg/tree-ssa/col-1.c: Same.
* gcc.dg/old-style-prom-2.c: Same.
* gcc.dg/cast-function-1.c: Same.
* gcc.dg/pr15698-1.c: Same.
* gcc.dg/dremf-type-compat-3.c: Same.
* gcc.dg/vla-8.c: Same.
* gcc.dg/gomp/pr27415.c: Move firstprivate diagnostics to correct
line.
* gcc.dg/label-decl-2.c: Move label diagnostic to correct line.
* gcc.dg/old-style-prom-3.c: Check for error on the correct line.
* gcc.dg/enum-compat-1.c: Same.
* gcc.dg/dremf-type-compat-2.c: Same.
* gcc.dg/old-style-prom-2.c: Same.
* gcc.dg/pr15698-1.c: Same.
* gcc.dg/pr20368-1.c: Same.
* gcc.dg/dremf-type-compat-3.c: Same.
* gcc.dg/builtins-30.c: Same. Test for columns.
gcc/objcp/
* objcp-decl.h (c_end_compound_stmt): New argument.
* objcp-decl.c (objcp_start_struct): Add argument.
(objcp_finish_struct): Same.
gcc/cp/
* typeck.c (cp_build_binary_op): Pass location to overflow_warning.
(build_modify_expr): New arg.
* semantics.c (finish_unary_op_expr): Pass location to
overflow_warning.
(handle_omp_for_class_iterator): Pass location to build_modify_expr.
* typeck.c (cxx_sizeof_or_alignof_type): Pass location to
c_sizeof_or_alignof_type.
(build_array_ref): New argument.
(build_compound_expr): Same.
(build_const_cast): Same.
(build_ptrmemfunc): Pass location to build_c_cast.
* init.c (avoid_placement_new_aliasing): Pass location to
build_stmt.
(build_vec_delete_1): Pass location to cp_build_modify_expr,
build_compound_expr.
* class.c (build_vtbl_ref_1): Pass location to build_array_ref.
* decl.c (poplevel): Pass location to c_build_bind_expr.
(finish_case_label): Pass location to build_case_label.
(finish_constructor_body): Same.
(finish_destructor_body): Pass location to build_stmt.
(cxx_maybe_build_cleanup): Same, but to build_compound_expr.
* call.c (build_new_op): Pass location to build_array_ref.
(build_x_va_arg): Pass location to build_va_arg.
* except.c (expand_end_catch_block): Pass location to
build_stmt.
* cp-tree.h (build_array_ref): New argument.
(build_compound_expr): Same.
(build_c_cast): Same.
* cp-gimplify.c (gimplify_if_stmt): Pass location on down.
(gimplify_switch_stmt): Same.
* typeck2.c (split_nonconstant_init_1): Same.
* pt.c (tsubst_copy): Same.
* semantics.c (add_decl_expr): Same.
(do_poplevel): Same.
(push_cleanup): Same.
(finish_goto_stmt): Same.
(finish_expr_stmt): Same.
(begin_if_stmt): Same.
(begin_while_stmt): Same.
(begin_do_stmt): Same.
(finish_return_stmt): Same.
(begin_for_stmt): Same.
(finish_break_stmt): Same.
(finish_continue_stmt): Same.
(begin_switch_stmt): Same.
(begin_try_block): Same.
(begin_handler): Same.
(finish_asm_stmt): Same.
(finish_label_stmt): Same.
(finish_stmt_expr_expr): Same.
(finalize_nrv_r): Same.
(finish_omp_atomic): Same.
* name-lookup.c (do_using_directive): Same.
* decl2.c (grok_array_decl): Same.
* parser.c (cp_parser_cast_expression): Same.
(cp_parser_selection_statement): Same.
(cp_parser_implicitly_scoped_statement): Same.
(cp_parser_objc_selector_expression): Same.
(cp_parser_objc_synchronized_statement): Same.
(cp_parser_objc_throw_statement): Same.
(cp_parser_omp_critical): Same.
(cp_parser_omp_master): Same.
* typeck.c (build_function_call): Add location argument.
* init.c: Add location argument to all build_decl calls.
* class.c: Same.
* method.c: Same.
* rtti.c: Same.
* tree.c: Same.
* pt.c: Same.
* semantics.c: Same.
* lex.c: Same.
* decl2.c: Same.
* cp-gimplify.c: Same.
* decl.c: Same.
(cp_make_fname_decl): Add location argument. Pass location ot
build_decl.
(finish_case_label): Same.
* cp-tree.h (finish_case_label): Add location argument.
* parser.c (cp_parser_label_for_labeled_statement): Pass location to
finish_case_label.
gcc/fortran/
* trans-array.c (gfc_trans_allocate_array_storage): Pass
location on down.
(gfc_trans_array_constructor_value): Same.
(gfc_trans_scalarized_loop_end): Same.
(gfc_conv_ss_startstride): Same.
(gfc_trans_g77_array): Same.
(gfc_trans_dummy_array_bias): Same.
(gfc_conv_array_parameter): Same.
(structure_alloc_comps): Same.
* trans-expr.c (gfc_conv_function_call): Same.
(fill_with_spaces): Same.
(gfc_trans_string_copy): Same.
(gfc_trans_scalar_assign): Same.
* trans-stmt.c (gfc_trans_goto): Same.
(gfc_trans_if_1): Same.
(gfc_trans_simple_do): Same.
(gfc_trans_do): Same.
(gfc_trans_do_while): Same.
(gfc_trans_logical_select): Same.
(gfc_trans_select): Same.
(gfc_trans_forall_loop): Same.
(gfc_trans_nested_forall_loop): Same.
(generate_loop_for_temp_to_lhs): Same.
(generate_loop_for_rhs_to_temp): Same.
(gfc_trans_forall_1): Same.
(gfc_trans_where_assign): Same.
(gfc_trans_where_3): Same.
(gfc_trans_allocate): Same.
* trans.c (gfc_finish_block): Same.
(gfc_trans_runtime_check): Same.
(gfc_call_malloc): Same.
(gfc_allocate_with_status): Same.
(gfc_call_free): Same.
(gfc_deallocate_with_status): Same.
(gfc_call_realloc): Same.
(gfc_trans_code): Same.
* trans-decl.c (gfc_init_default_dt): Same.
(gfc_generate_constructors): Same.
* trans-io.c (gfc_trans_io_runtime_check): Same.
* trans-intrinsic.c (gfc_conv_intrinsic_ctime): Same.
(gfc_conv_intrinsic_fdate): Same.
(gfc_conv_intrinsic_ttynam): Same.
(gfc_conv_intrinsic_minmax): Same.
(gfc_conv_intrinsic_minmax_char): Same.
(gfc_conv_intrinsic_anyall): Same.
(gfc_conv_intrinsic_count): Same.
(gfc_conv_intrinsic_arith): Same.
(gfc_conv_intrinsic_minmaxloc): Same.
(gfc_conv_intrinsic_minmaxval): Same.
(gfc_conv_intrinsic_rrspacing): Same.
(gfc_conv_intrinsic_array_transfer): Same.
(gfc_conv_intrinsic_trim): Same.
(gfc_conv_intrinsic_repeat): Same.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@148442 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r-- | gcc/c-typeck.c | 555 |
1 files changed, 326 insertions, 229 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 6c86b92de6d..978e95c4b45 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -98,7 +98,7 @@ static void push_member_name (tree); static int spelling_length (void); static char *print_spelling (char *); static void warning_init (int, const char *); -static tree digest_init (tree, tree, tree, bool, bool, int); +static tree digest_init (location_t, tree, tree, tree, bool, bool, int); static void output_init_element (tree, tree, bool, tree, tree, int, bool); static void output_pending_init_elements (int); static int set_designator (int); @@ -1659,7 +1659,7 @@ decl_constant_value (tree decl) /* Convert the array expression EXP to a pointer. */ static tree -array_to_pointer_conversion (tree exp) +array_to_pointer_conversion (location_t loc, tree exp) { tree orig_exp = exp; tree type = TREE_TYPE (exp); @@ -1679,13 +1679,13 @@ array_to_pointer_conversion (tree exp) if (TREE_CODE (exp) == INDIRECT_REF) return convert (ptrtype, TREE_OPERAND (exp, 0)); - adr = build_unary_op (EXPR_LOCATION (exp), ADDR_EXPR, exp, 1); + adr = build_unary_op (loc, ADDR_EXPR, exp, 1); return convert (ptrtype, adr); } /* Convert the function expression EXP to a pointer. */ static tree -function_to_pointer_conversion (tree exp) +function_to_pointer_conversion (location_t loc, tree exp) { tree orig_exp = exp; @@ -1696,15 +1696,17 @@ function_to_pointer_conversion (tree exp) if (TREE_NO_WARNING (orig_exp)) TREE_NO_WARNING (exp) = 1; - return build_unary_op (EXPR_LOCATION (exp), ADDR_EXPR, exp, 0); + return build_unary_op (loc, ADDR_EXPR, exp, 0); } /* Perform the default conversion of arrays and functions to pointers. Return the result of converting EXP. For any other expression, just - return EXP. */ + return EXP. + + LOC is the location of the expression. */ struct c_expr -default_function_array_conversion (struct c_expr exp) +default_function_array_conversion (location_t loc, struct c_expr exp) { tree orig_exp = exp.value; tree type = TREE_TYPE (exp.value); @@ -1739,11 +1741,11 @@ default_function_array_conversion (struct c_expr exp) return exp; } - exp.value = array_to_pointer_conversion (exp.value); + exp.value = array_to_pointer_conversion (loc, exp.value); } break; case FUNCTION_TYPE: - exp.value = function_to_pointer_conversion (exp.value); + exp.value = function_to_pointer_conversion (loc, exp.value); break; default: break; @@ -1944,11 +1946,12 @@ lookup_field (tree decl, tree component) return tree_cons (NULL_TREE, field, NULL_TREE); } -/* Make an expression to refer to the COMPONENT field of - structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */ +/* Make an expression to refer to the COMPONENT field of structure or + union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the + location of the COMPONENT_REF. */ tree -build_component_ref (tree datum, tree component) +build_component_ref (location_t loc, tree datum, tree component) { tree type = TREE_TYPE (datum); enum tree_code code = TREE_CODE (type); @@ -1973,7 +1976,7 @@ build_component_ref (tree datum, tree component) if (!field) { - error ("%qT has no member named %qE", type, component); + error_at (loc, "%qT has no member named %qE", type, component); return error_mark_node; } @@ -2006,6 +2009,7 @@ build_component_ref (tree datum, tree component) ref = build3 (COMPONENT_REF, subtype, datum, subdatum, NULL_TREE); + SET_EXPR_LOCATION (ref, loc); if (TREE_READONLY (subdatum) || (use_datum_quals && TREE_READONLY (datum))) TREE_READONLY (ref) = 1; @@ -2025,8 +2029,9 @@ build_component_ref (tree datum, tree component) return ref; } else if (code != ERROR_MARK) - error ("request for member %qE in something not a structure or union", - component); + error_at (loc, + "request for member %qE in something not a structure or union", + component); return error_mark_node; } @@ -2113,7 +2118,7 @@ build_indirect_ref (location_t loc, tree ptr, const char *errorstring) LOC is the location to use for the returned expression. */ tree -build_array_ref (tree array, tree index, location_t loc) +build_array_ref (location_t loc, tree array, tree index) { tree ret; bool swapped = false; @@ -2243,7 +2248,7 @@ build_array_ref (tree array, tree index, location_t loc) for CONST_DECLs defined as enum constants. If the type of the identifier is not available, *TYPE is set to NULL. */ tree -build_external_ref (tree id, int fun, location_t loc, tree *type) +build_external_ref (location_t loc, tree id, int fun, tree *type) { tree ref; tree decl = lookup_name (id); @@ -2260,14 +2265,14 @@ build_external_ref (tree id, int fun, location_t loc, tree *type) } else if (fun) /* Implicit function declaration. */ - ref = implicitly_declare (id); + ref = implicitly_declare (loc, id); else if (decl == error_mark_node) /* Don't complain about something that's already been complained about. */ return error_mark_node; else { - undeclared_variable (id, loc); + undeclared_variable (loc, id); return error_mark_node; } @@ -2393,7 +2398,7 @@ pop_maybe_used (bool used) /* Return the result of sizeof applied to EXPR. */ struct c_expr -c_expr_sizeof_expr (struct c_expr expr) +c_expr_sizeof_expr (location_t loc, struct c_expr expr) { struct c_expr ret; if (expr.value == error_mark_node) @@ -2408,7 +2413,7 @@ c_expr_sizeof_expr (struct c_expr expr) bool expr_const_operands = true; tree folded_expr = c_fully_fold (expr.value, require_constant_value, &expr_const_operands); - ret.value = c_sizeof (TREE_TYPE (folded_expr)); + ret.value = c_sizeof (loc, TREE_TYPE (folded_expr)); ret.original_code = ERROR_MARK; ret.original_type = NULL; if (c_vla_type_p (TREE_TYPE (folded_expr))) @@ -2417,6 +2422,7 @@ c_expr_sizeof_expr (struct c_expr expr) ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value), folded_expr, ret.value); C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands; + SET_EXPR_LOCATION (ret.value, loc); } pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr))); } @@ -2424,17 +2430,18 @@ c_expr_sizeof_expr (struct c_expr expr) } /* Return the result of sizeof applied to T, a structure for the type - name passed to sizeof (rather than the type itself). */ + name passed to sizeof (rather than the type itself). LOC is the + location of the original expression. */ struct c_expr -c_expr_sizeof_type (struct c_type_name *t) +c_expr_sizeof_type (location_t loc, struct c_type_name *t) { tree type; struct c_expr ret; tree type_expr = NULL_TREE; bool type_expr_const = true; type = groktypename (t, &type_expr, &type_expr_const); - ret.value = c_sizeof (type); + ret.value = c_sizeof (loc, type); ret.original_code = ERROR_MARK; ret.original_type = NULL; if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST) @@ -2459,12 +2466,13 @@ c_expr_sizeof_type (struct c_type_name *t) } /* Build a function call to function FUNCTION with parameters PARAMS. + The function call is at LOC. PARAMS is a list--a chain of TREE_LIST nodes--in which the TREE_VALUE of each node is a parameter-expression. FUNCTION's data type may be a function type or a pointer-to-function. */ tree -build_function_call (tree function, tree params) +build_function_call (location_t loc, tree function, tree params) { VEC(tree,gc) *vec; tree ret; @@ -2472,7 +2480,7 @@ build_function_call (tree function, tree params) vec = VEC_alloc (tree, gc, list_length (params)); for (; params; params = TREE_CHAIN (params)) VEC_quick_push (tree, vec, TREE_VALUE (params)); - ret = build_function_call_vec (function, vec, NULL); + ret = build_function_call_vec (loc, function, vec, NULL); VEC_free (tree, gc, vec); return ret; } @@ -2486,7 +2494,7 @@ build_function_call (tree function, tree params) PARAMS. */ tree -build_function_call_vec (tree function, VEC(tree,gc) *params, +build_function_call_vec (location_t loc, tree function, VEC(tree,gc) *params, VEC(tree,gc) *origtypes) { tree fntype, fundecl = 0; @@ -2506,7 +2514,7 @@ build_function_call_vec (tree function, VEC(tree,gc) *params, resolve_overloaded_builtin and targetm.resolve_overloaded_builtin handle all the type checking. The result is a complete expression that implements this function call. */ - tem = resolve_overloaded_builtin (function, params); + tem = resolve_overloaded_builtin (loc, function, params); if (tem) return tem; @@ -2514,7 +2522,7 @@ build_function_call_vec (tree function, VEC(tree,gc) *params, fundecl = function; } if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) - function = function_to_pointer_conversion (function); + function = function_to_pointer_conversion (loc, function); /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF expressions, like those used for ObjC messenger dispatches. */ @@ -2532,7 +2540,7 @@ build_function_call_vec (tree function, VEC(tree,gc) *params, if (!(TREE_CODE (fntype) == POINTER_TYPE && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)) { - error ("called object %qE is not a function", function); + error_at (loc, "called object %qE is not a function", function); return error_mark_node; } @@ -2561,17 +2569,17 @@ build_function_call_vec (tree function, VEC(tree,gc) *params, && !comptypes (fntype, TREE_TYPE (tem))) { tree return_type = TREE_TYPE (fntype); - tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP], + tree trap = build_function_call (loc, built_in_decls[BUILT_IN_TRAP], NULL_TREE); int i; /* This situation leads to run-time undefined behavior. We can't, therefore, simply error unless we can prove that all possible executions of the program must execute the code. */ - if (warning (0, "function called through a non-compatible type")) + if (warning_at (loc, 0, "function called through a non-compatible type")) /* We can, however, treat "undefined" any way we please. Call abort to encourage the user to fix the program. */ - inform (input_location, "if this code is reached, the program will abort"); + inform (loc, "if this code is reached, the program will abort"); /* Before the abort, allow the function arguments to exit or call longjmp. */ for (i = 0; i < nargs; i++) @@ -2590,7 +2598,7 @@ build_function_call_vec (tree function, VEC(tree,gc) *params, tree rhs; if (AGGREGATE_TYPE_P (return_type)) - rhs = build_compound_literal (return_type, + rhs = build_compound_literal (loc, return_type, build_constructor (return_type, 0), false); else @@ -2856,7 +2864,8 @@ convert_arguments (tree typelist, VEC(tree,gc) *values, and the actual arg is that enum type. */ ; else if (formal_prec != TYPE_PRECISION (type1)) - warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " + warning (OPT_Wtraditional_conversion, + "passing argument %d of %qE " "with different width due to prototype", argnum, rname); else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1)) @@ -2879,11 +2888,13 @@ convert_arguments (tree typelist, VEC(tree,gc) *values, && TYPE_UNSIGNED (valtype)) ; else if (TYPE_UNSIGNED (type)) - warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " + warning (OPT_Wtraditional_conversion, + "passing argument %d of %qE " "as unsigned due to prototype", argnum, rname); else - warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " + warning (OPT_Wtraditional_conversion, + "passing argument %d of %qE " "as signed due to prototype", argnum, rname); } } @@ -2957,7 +2968,7 @@ convert_arguments (tree typelist, VEC(tree,gc) *values, */ struct c_expr -parser_build_unary_op (enum tree_code code, struct c_expr arg, location_t loc) +parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg) { struct c_expr result; @@ -2966,7 +2977,7 @@ parser_build_unary_op (enum tree_code code, struct c_expr arg, location_t loc) result.original_type = NULL; if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value)) - overflow_warning (result.value); + overflow_warning (loc, result.value); return result; } @@ -3020,16 +3031,18 @@ parser_build_binary_op (location_t location, enum tree_code code, { if ((code1 == STRING_CST && !integer_zerop (arg2.value)) || (code2 == STRING_CST && !integer_zerop (arg1.value))) - warning (OPT_Waddress, "comparison with string literal results in unspecified behavior"); + warning_at (location, OPT_Waddress, + "comparison with string literal results in unspecified behavior"); } else if (TREE_CODE_CLASS (code) == tcc_comparison && (code1 == STRING_CST || code2 == STRING_CST)) - warning (OPT_Waddress, "comparison with string literal results in unspecified behavior"); + warning_at (location, OPT_Waddress, + "comparison with string literal results in unspecified behavior"); if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg1.value) && !TREE_OVERFLOW_P (arg2.value)) - overflow_warning (result.value); + overflow_warning (location, result.value); /* Warn about comparisons of different enum types. */ if (warn_enum_compare @@ -3478,7 +3491,8 @@ build_unary_op (location_t location, return error_mark_node; return build_binary_op (location, PLUS_EXPR, (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE - ? array_to_pointer_conversion (op0) + ? array_to_pointer_conversion (location, + op0) : op0), TREE_OPERAND (arg, 1), 1); } @@ -3755,7 +3769,7 @@ c_mark_addressable (tree exp) IFEXP_BCP then the condition is a call to __builtin_constant_p, and if folded to an integer constant then the unselected half may contain arbitrary operations not normally permitted in constant - expressions. */ + expressions. Set the location of the expression to LOC. */ tree build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, @@ -3983,7 +3997,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, result_type = void_type_node; else { - error ("type mismatch in conditional expression"); + error_at (colon_loc, "type mismatch in conditional expression"); return error_mark_node; } } @@ -4032,14 +4046,17 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, if (ep_result_type) ret = build1 (EXCESS_PRECISION_EXPR, ep_result_type, ret); + protected_set_expr_location (ret, colon_loc); return ret; } /* Return a compound expression that performs two expressions and - returns the value of the second of them. */ + returns the value of the second of them. + + LOC is the location of the COMPOUND_EXPR. */ tree -build_compound_expr (tree expr1, tree expr2) +build_compound_expr (location_t loc, tree expr1, tree expr2) { bool expr1_int_operands, expr2_int_operands; tree eptype = NULL_TREE; @@ -4075,8 +4092,8 @@ build_compound_expr (tree expr1, tree expr2) && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1))) ; /* (void) a, (void) b, c */ else - warning (OPT_Wunused_value, - "left-hand operand of comma expression has no effect"); + warning_at (loc, OPT_Wunused_value, + "left-hand operand of comma expression has no effect"); } } @@ -4085,7 +4102,7 @@ build_compound_expr (tree expr1, tree expr2) `foo() + bar(), baz()' the result of the `+' operator is not used, so we should issue a warning. */ else if (warn_unused_value) - warn_if_unused_value (expr1, input_location); + warn_if_unused_value (expr1, loc); if (expr2 == error_mark_node) return error_mark_node; @@ -4100,6 +4117,7 @@ build_compound_expr (tree expr1, tree expr2) if (eptype) ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret); + protected_set_expr_location (ret, loc); return ret; } @@ -4190,10 +4208,11 @@ handle_warn_cast_qual (tree type, tree otype) while (TREE_CODE (in_type) == POINTER_TYPE); } -/* Build an expression representing a cast to type TYPE of expression EXPR. */ +/* Build an expression representing a cast to type TYPE of expression EXPR. + LOC is the location of the cast-- typically the open paren of the cast. */ tree -build_c_cast (tree type, tree expr) +build_c_cast (location_t loc, tree type, tree expr) { tree value; @@ -4215,13 +4234,13 @@ build_c_cast (tree type, tree expr) if (TREE_CODE (type) == ARRAY_TYPE) { - error ("cast specifies array type"); + error_at (loc, "cast specifies array type"); return error_mark_node; } if (TREE_CODE (type) == FUNCTION_TYPE) { - error ("cast specifies function type"); + error_at (loc, "cast specifies function type"); return error_mark_node; } @@ -4236,7 +4255,7 @@ build_c_cast (tree type, tree expr) { if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C forbids casting nonscalar to the same type"); } else if (TREE_CODE (type) == UNION_TYPE) @@ -4253,15 +4272,14 @@ build_c_cast (tree type, tree expr) { tree t; - pedwarn (input_location, OPT_pedantic, - "ISO C forbids casts to union type"); - t = digest_init (type, + pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type"); + t = digest_init (loc, type, build_constructor_single (type, field, value), NULL_TREE, false, true, 0); TREE_CONSTANT (t) = TREE_CONSTANT (value); return t; } - error ("cast to union type from type not present in union"); + error_at (loc, "cast to union type from type not present in union"); return error_mark_node; } else @@ -4269,7 +4287,11 @@ build_c_cast (tree type, tree expr) tree otype, ovalue; if (type == void_type_node) - return build1 (CONVERT_EXPR, type, value); + { + tree t = build1 (CONVERT_EXPR, type, value); + SET_EXPR_LOCATION (t, loc); + return t; + } otype = TREE_TYPE (value); @@ -4291,8 +4313,8 @@ build_c_cast (tree type, tree expr) || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE) && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) - warning (OPT_Wcast_align, - "cast increases required alignment of target type"); + warning_at (loc, OPT_Wcast_align, + "cast increases required alignment of target type"); if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (otype) == POINTER_TYPE @@ -4302,21 +4324,23 @@ build_c_cast (tree type, tree expr) of cases such as SIG_*, warn about converting constant pointers to integers. In some cases it may cause unwanted sign extension, and a warning is appropriate. */ - warning (OPT_Wpointer_to_int_cast, - "cast from pointer to integer of different size"); + warning_at (loc, OPT_Wpointer_to_int_cast, + "cast from pointer to integer of different size"); if (TREE_CODE (value) == CALL_EXPR && TREE_CODE (type) != TREE_CODE (otype)) - warning (OPT_Wbad_function_cast, "cast from function call of type %qT " - "to non-matching type %qT", otype, type); + warning_at (loc, OPT_Wbad_function_cast, + "cast from function call of type %qT " + "to non-matching type %qT", otype, type); if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (otype) == INTEGER_TYPE && TYPE_PRECISION (type) != TYPE_PRECISION (otype) /* Don't warn about converting any constant. */ && !TREE_CONSTANT (value)) - warning (OPT_Wint_to_pointer_cast, "cast to pointer from integer " - "of different size"); + warning_at (loc, + OPT_Wint_to_pointer_cast, "cast to pointer from integer " + "of different size"); if (warn_strict_aliasing <= 2) strict_aliasing_warning (otype, type, expr); @@ -4329,7 +4353,7 @@ build_c_cast (tree type, tree expr) && TREE_CODE (otype) == POINTER_TYPE && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) - pedwarn (input_location, OPT_pedantic, "ISO C forbids " + pedwarn (loc, OPT_pedantic, "ISO C forbids " "conversion of function pointer to object pointer type"); if (pedantic @@ -4338,7 +4362,7 @@ build_c_cast (tree type, tree expr) && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE && !null_pointer_constant_p (value)) - pedwarn (input_location, OPT_pedantic, "ISO C forbids " + pedwarn (loc, OPT_pedantic, "ISO C forbids " "conversion of object pointer to function pointer type"); ovalue = value; @@ -4382,12 +4406,16 @@ build_c_cast (tree type, tree expr) || TREE_CODE (expr) == COMPLEX_CST))) value = build1 (NOP_EXPR, type, value); + if (CAN_HAVE_LOCATION_P (value)) + SET_EXPR_LOCATION (value, loc); return value; } -/* Interpret a cast of expression EXPR to type TYPE. */ +/* Interpret a cast of expression EXPR to type TYPE. LOC is the + location of the open paren of the cast, or the position of the cast + expr. */ tree -c_cast_expr (struct c_type_name *type_name, tree expr, location_t loc) +c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr) { tree type; tree type_expr = NULL_TREE; @@ -4402,11 +4430,12 @@ c_cast_expr (struct c_type_name *type_name, tree expr, location_t loc) type = groktypename (type_name, &type_expr, &type_expr_const); warn_strict_prototypes = saved_wsp; - ret = build_c_cast (type, expr); + ret = build_c_cast (loc, type, expr); if (type_expr) { ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret); C_MAYBE_CONST_EXPR_NON_CONST (ret) = !type_expr_const; + SET_EXPR_LOCATION (ret, loc); } if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret)) @@ -4429,11 +4458,13 @@ c_cast_expr (struct c_type_name *type_name, tree expr, location_t loc) If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS, which may differ from TREE_TYPE (RHS) for an enum value. - LOCATION is the location of the MODIFYCODE operator. */ + LOCATION is the location of the MODIFYCODE operator. + RHS_LOC is the location of the RHS. */ tree build_modify_expr (location_t location, tree lhs, tree lhs_origtype, - enum tree_code modifycode, tree rhs, tree rhs_origtype) + enum tree_code modifycode, + location_t rhs_loc, tree rhs, tree rhs_origtype) { tree result; tree newrhs; @@ -4463,7 +4494,7 @@ build_modify_expr (location_t location, tree lhs, tree lhs_origtype, if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR) { tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs), - lhs_origtype, modifycode, rhs, + lhs_origtype, modifycode, rhs_loc, rhs, rhs_origtype); if (inner == error_mark_node) return error_mark_node; @@ -4596,6 +4627,7 @@ build_modify_expr (location_t location, tree lhs, tree lhs_origtype, ERRTYPE says whether it is argument passing, assignment, initialization or return. + LOCATION is the location of the RHS. FUNCTION is a tree for the function being called. PARMNUM is the number of the argument, for printing in error messages. */ @@ -4634,14 +4666,14 @@ convert_for_assignment (location_t location, tree type, tree rhs, /* This macro is used to emit diagnostics to ensure that all format strings are complete sentences, visible to gettext and checked at compile time. */ -#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ +#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ do { \ switch (errtype) \ { \ case ic_argpass: \ if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ - inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ - ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ + inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ + ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ "expected %qT but argument is of type %qT", \ type, rhstype); \ break; \ @@ -4652,7 +4684,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, pedwarn (LOCATION, OPT, IN); \ break; \ case ic_return: \ - pedwarn (LOCATION, OPT, RE); \ + pedwarn (LOCATION, OPT, RE); \ break; \ default: \ gcc_unreachable (); \ @@ -4723,7 +4755,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, an unprototyped function, it is compile-time undefined; making it a constraint in that case was rejected in DR#252. */ - error ("void value not ignored as it ought to be"); + error_at (location, "void value not ignored as it ought to be"); return error_mark_node; } rhs = require_complete_type (rhs); @@ -4737,12 +4769,13 @@ convert_for_assignment (location_t location, tree type, tree rhs, { if (!lvalue_p (rhs)) { - error ("cannot pass rvalue to reference parameter"); + error_at (location, "cannot pass rvalue to reference parameter"); return error_mark_node; } if (!c_mark_addressable (rhs)) return error_mark_node; rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs); + SET_EXPR_LOCATION (rhs, location); /* We already know that these two types are compatible, but they may not be exactly identical. In fact, `TREE_TYPE (type)' is @@ -4750,9 +4783,13 @@ convert_for_assignment (location_t location, tree type, tree rhs, likely to be va_list, a typedef to __builtin_va_list, which is different enough that it will cause problems later. */ if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type)) - rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs); + { + rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs); + SET_EXPR_LOCATION (rhs, location); + } rhs = build1 (NOP_EXPR, type, rhs); + SET_EXPR_LOCATION (rhs, location); return rhs; } /* Some types can interconvert without explicit casts. */ @@ -4859,7 +4896,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, function where an ordinary one is wanted, but not vice-versa. */ if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE " "makes qualified function " "pointer from unqualified"), @@ -4873,7 +4910,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, "pointer from unqualified")); } else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE discards " "qualifiers from pointer target type"), G_("assignment discards qualifiers " @@ -4887,7 +4924,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, } if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) - pedwarn (input_location, OPT_pedantic, + pedwarn (location, OPT_pedantic, "ISO C prohibits argument conversion to union type"); rhs = fold_convert (TREE_TYPE (memb), rhs); @@ -4921,8 +4958,9 @@ convert_for_assignment (location_t location, tree type, tree rhs, where NULL is typically defined in C to be '(void *) 0'. */ if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl)) - warning (OPT_Wc___compat, "request for implicit conversion from " - "%qT to %qT not permitted in C++", rhstype, type); + warning_at (location, OPT_Wc___compat, + "request for implicit conversion " + "from %qT to %qT not permitted in C++", rhstype, type); /* Check if the right-hand side has a format attribute but the left-hand side doesn't. */ @@ -4932,25 +4970,25 @@ convert_for_assignment (location_t location, tree type, tree rhs, switch (errtype) { case ic_argpass: - warning (OPT_Wmissing_format_attribute, - "argument %d of %qE might be " - "a candidate for a format attribute", - parmnum, rname); + warning_at (location, OPT_Wmissing_format_attribute, + "argument %d of %qE might be " + "a candidate for a format attribute", + parmnum, rname); break; case ic_assign: - warning (OPT_Wmissing_format_attribute, - "assignment left-hand side might be " - "a candidate for a format attribute"); + warning_at (location, OPT_Wmissing_format_attribute, + "assignment left-hand side might be " + "a candidate for a format attribute"); break; case ic_init: - warning (OPT_Wmissing_format_attribute, - "initialization left-hand side might be " - "a candidate for a format attribute"); + warning_at (location, OPT_Wmissing_format_attribute, + "initialization left-hand side might be " + "a candidate for a format attribute"); break; case ic_return: - warning (OPT_Wmissing_format_attribute, - "return type might be " - "a candidate for a format attribute"); + warning_at (location, OPT_Wmissing_format_attribute, + "return type might be " + "a candidate for a format attribute"); break; default: gcc_unreachable (); @@ -4972,7 +5010,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, (VOID_TYPE_P (ttr) && !null_pointer_constant && TREE_CODE (ttl) == FUNCTION_TYPE))) - WARN_FOR_ASSIGNMENT (input_location, OPT_pedantic, + WARN_FOR_ASSIGNMENT (location, OPT_pedantic, G_("ISO C forbids passing argument %d of " "%qE between function pointer " "and %<void *%>"), @@ -4993,7 +5031,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, qualifier are acceptable if the 'volatile' has been added in by the Objective-C EH machinery. */ if (!objc_type_quals_match (ttl, ttr)) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE discards " "qualifiers from pointer target type"), G_("assignment discards qualifiers " @@ -5010,7 +5048,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, ; /* If there is a mismatch, do warn. */ else if (warn_pointer_sign) - WARN_FOR_ASSIGNMENT (input_location, OPT_Wpointer_sign, + WARN_FOR_ASSIGNMENT (location, OPT_Wpointer_sign, G_("pointer targets in passing argument " "%d of %qE differ in signedness"), G_("pointer targets in assignment " @@ -5028,7 +5066,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, it is okay to use a const or volatile function where an ordinary one is wanted, but not vice-versa. */ if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE makes " "qualified function pointer " "from unqualified"), @@ -5043,7 +5081,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, else /* Avoid warning about the volatile ObjC EH puts on decls. */ if (!objc_ok) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE from " "incompatible pointer type"), G_("assignment from incompatible pointer type"), @@ -5057,7 +5095,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, { /* ??? This should not be an error when inlining calls to unprototyped functions. */ - error ("invalid use of non-lvalue array"); + error_at (location, "invalid use of non-lvalue array"); return error_mark_node; } else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) @@ -5066,7 +5104,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, or one that results from arithmetic, even including a cast to integer type. */ if (!null_pointer_constant) - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE makes " "pointer from integer without a cast"), G_("assignment makes pointer from integer " @@ -5080,7 +5118,7 @@ convert_for_assignment (location_t location, tree type, tree rhs, } else if (codel == INTEGER_TYPE && coder == POINTER_TYPE) { - WARN_FOR_ASSIGNMENT (input_location, 0, + WARN_FOR_ASSIGNMENT (location, 0, G_("passing argument %d of %qE makes integer " "from pointer without a cast"), G_("assignment makes integer from pointer " @@ -5104,22 +5142,24 @@ convert_for_assignment (location_t location, tree type, tree rhs, switch (errtype) { case ic_argpass: - error ("incompatible type for argument %d of %qE", parmnum, rname); + error_at (location, "incompatible type for argument %d of %qE", parmnum, rname); inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) ? DECL_SOURCE_LOCATION (fundecl) : input_location, "expected %qT but argument is of type %qT", type, rhstype); break; case ic_assign: - error ("incompatible types when assigning to type %qT from type %qT", - type, rhstype); + error_at (location, "incompatible types when assigning to type %qT from " + "type %qT", type, rhstype); break; case ic_init: - error ("incompatible types when initializing type %qT using type %qT", - type, rhstype); + error_at (location, + "incompatible types when initializing type %qT using type %qT", + type, rhstype); break; case ic_return: - error ("incompatible types when returning type %qT but %qT was expected", - rhstype, type); + error_at (location, + "incompatible types when returning type %qT but %qT was " + "expected", rhstype, type); break; default: gcc_unreachable (); @@ -5155,10 +5195,12 @@ valid_compound_expr_initializer (tree value, tree endtype) store it in the declaration DECL, and print any error messages that are appropriate. If ORIGTYPE is not NULL_TREE, it is the original type of INIT. - If the init is invalid, store an ERROR_MARK. */ + If the init is invalid, store an ERROR_MARK. + + INIT_LOC is the location of the initial value. */ void -store_init_value (tree decl, tree init, tree origtype) +store_init_value (location_t init_loc, tree decl, tree init, tree origtype) { tree value, type; bool npc = false; @@ -5173,7 +5215,8 @@ store_init_value (tree decl, tree init, tree origtype) if (init) npc = null_pointer_constant_p (init); - value = digest_init (type, init, origtype, npc, true, TREE_STATIC (decl)); + value = digest_init (init_loc, type, init, origtype, npc, + true, TREE_STATIC (decl)); /* Store the expression if valid; else report error. */ @@ -5414,12 +5457,15 @@ maybe_warn_string_init (tree type, struct c_expr expr) unparenthesized or we should not warn here for it being parenthesized. For other types of INIT, STRICT_STRING is not used. + INIT_LOC is the location of the INIT. + REQUIRE_CONSTANT requests an error if non-constant initializers or elements are seen. */ static tree -digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, - bool strict_string, int require_constant) +digest_init (location_t init_loc, tree type, tree init, tree origtype, + bool null_pointer_constant, bool strict_string, + int require_constant) { enum tree_code code = TREE_CODE (type); tree inside_init = init; @@ -5469,7 +5515,7 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, maybe_warn_string_init (type, expr); if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) - pedwarn_init (input_location, OPT_pedantic, + pedwarn_init (init_loc, OPT_pedantic, "initialization of a flexible array member"); if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), @@ -5511,7 +5557,7 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, TREE_STRING_LENGTH (inside_init) - (TYPE_PRECISION (typ1) / BITS_PER_UNIT))) - pedwarn_init (input_location, 0, + pedwarn_init (init_loc, 0, "initializer-string for array of chars is too long"); return inside_init; @@ -5582,7 +5628,8 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, { if (TREE_CODE (inside_init) == STRING_CST || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) - inside_init = array_to_pointer_conversion (inside_init); + inside_init = array_to_pointer_conversion + (init_loc, inside_init); else { error_init ("invalid use of non-lvalue array"); @@ -5627,7 +5674,7 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, if (inside_init == error_mark_node) error_init ("initializer element is not constant"); else - pedwarn_init (input_location, OPT_pedantic, + pedwarn_init (init_loc, OPT_pedantic, "initializer element is not constant"); if (flag_pedantic_errors) inside_init = error_mark_node; @@ -5640,13 +5687,13 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, inside_init = error_mark_node; } else if (require_constant && !maybe_const) - pedwarn_init (input_location, 0, + pedwarn_init (init_loc, 0, "initializer element is not a constant expression"); /* Added to enable additional -Wmissing-format-attribute warnings. */ if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE) - inside_init = convert_for_assignment (input_location, type, - inside_init, origtype, + inside_init = convert_for_assignment (init_loc, type, inside_init, + origtype, ic_init, null_pointer_constant, NULL_TREE, NULL_TREE, 0); return inside_init; @@ -5661,13 +5708,13 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE && (TREE_CODE (init) == STRING_CST || TREE_CODE (init) == COMPOUND_LITERAL_EXPR)) - inside_init = init = array_to_pointer_conversion (init); + inside_init = init = array_to_pointer_conversion (init_loc, init); if (semantic_type) inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type, inside_init); inside_init - = convert_for_assignment (input_location, type, inside_init, origtype, - ic_init, null_pointer_constant, + = convert_for_assignment (init_loc, type, inside_init, origtype, + ic_init, null_pointer_constant, NULL_TREE, NULL_TREE, 0); /* Check to see if we have already given an error message. */ @@ -5686,7 +5733,7 @@ digest_init (tree type, tree init, tree origtype, bool null_pointer_constant, inside_init = error_mark_node; } else if (require_constant && !maybe_const) - pedwarn_init (input_location, 0, + pedwarn_init (init_loc, 0, "initializer element is not a constant expression"); return inside_init; @@ -7092,7 +7139,7 @@ output_init_element (tree value, tree origtype, bool strict_string, tree type, && INTEGRAL_TYPE_P (TREE_TYPE (type))) && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)), TYPE_MAIN_VARIANT (type))) - value = array_to_pointer_conversion (value); + value = array_to_pointer_conversion (input_location, value); if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR && require_constant_value && !flag_isoc99 && pending) @@ -7171,8 +7218,8 @@ output_init_element (tree value, tree origtype, bool strict_string, tree type, if (semantic_type) value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); - value = digest_init (type, value, origtype, npc, strict_string, - require_constant_value); + value = digest_init (input_location, type, value, origtype, npc, + strict_string, require_constant_value); if (value == error_mark_node) { constructor_erroneous = 1; @@ -7831,8 +7878,8 @@ build_asm_stmt (tree cv_qualifier, tree args) string in the asm expression -- asm("blah") and asm("blah" : ) are subtly different. We use a ASM_EXPR node to represent this. */ tree -build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers, - bool simple) +build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, + tree clobbers, bool simple) { tree tail; tree args; @@ -7916,7 +7963,7 @@ build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers, TREE_VALUE (tail) = input; } - args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers); + args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers); /* asm statements without outputs, including simple ones, are treated as volatile. */ @@ -7926,10 +7973,11 @@ build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers, return args; } -/* Generate a goto statement to LABEL. */ +/* Generate a goto statement to LABEL. LOC is the location of the + GOTO. */ tree -c_finish_goto_label (tree label) +c_finish_goto_label (location_t loc, tree label) { tree decl = lookup_label (label); if (!decl) @@ -7937,13 +7985,14 @@ c_finish_goto_label (tree label) if (C_DECL_UNJUMPABLE_STMT_EXPR (decl)) { - error ("jump into statement expression"); + error_at (loc, "jump into statement expression"); return NULL_TREE; } if (C_DECL_UNJUMPABLE_VM (decl)) { - error ("jump into scope of identifier with variably modified type"); + error_at (loc, + "jump into scope of identifier with variably modified type"); return NULL_TREE; } @@ -7971,33 +8020,43 @@ c_finish_goto_label (tree label) } TREE_USED (decl) = 1; - return add_stmt (build1 (GOTO_EXPR, void_type_node, decl)); + { + tree t = build1 (GOTO_EXPR, void_type_node, decl); + SET_EXPR_LOCATION (t, loc); + return add_stmt (t); + } } -/* Generate a computed goto statement to EXPR. */ +/* Generate a computed goto statement to EXPR. LOC is the location of + the GOTO. */ tree -c_finish_goto_ptr (tree expr) +c_finish_goto_ptr (location_t loc, tree expr) { - pedwarn (input_location, OPT_pedantic, "ISO C forbids %<goto *expr;%>"); + tree t; + pedwarn (loc, OPT_pedantic, "ISO C forbids %<goto *expr;%>"); expr = c_fully_fold (expr, false, NULL); expr = convert (ptr_type_node, expr); - return add_stmt (build1 (GOTO_EXPR, void_type_node, expr)); + t = build1 (GOTO_EXPR, void_type_node, expr); + SET_EXPR_LOCATION (t, loc); + return add_stmt (t); } /* Generate a C `return' statement. RETVAL is the expression for what - to return, or a null pointer for `return;' with no value. If - ORIGTYPE is not NULL_TREE, it is the original type of RETVAL. */ + to return, or a null pointer for `return;' with no value. LOC is + the location of the return statement. If ORIGTYPE is not NULL_TREE, it + is the original type of RETVAL. */ tree -c_finish_return (tree retval, tree origtype) +c_finish_return (location_t loc, tree retval, tree origtype) { tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt; bool no_warning = false; bool npc = false; if (TREE_THIS_VOLATILE (current_function_decl)) - warning (0, "function declared %<noreturn%> has a %<return%> statement"); + warning_at (loc, 0, + "function declared %<noreturn%> has a %<return%> statement"); if (retval) { @@ -8019,7 +8078,7 @@ c_finish_return (tree retval, tree origtype) if ((warn_return_type || flag_isoc99) && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) { - pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wreturn_type, + pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wreturn_type, "%<return%> with no value, in " "function returning non-void"); no_warning = true; @@ -8029,17 +8088,17 @@ c_finish_return (tree retval, tree origtype) { current_function_returns_null = 1; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) - pedwarn (input_location, 0, + pedwarn (loc, 0, "%<return%> with a value, in function returning void"); else - pedwarn (input_location, OPT_pedantic, "ISO C forbids " + pedwarn (loc, OPT_pedantic, "ISO C forbids " "%<return%> with expression, in function returning void"); } else { - tree t = convert_for_assignment (input_location, valtype, retval, - origtype, ic_return, npc, - NULL_TREE, NULL_TREE, 0); + tree t = convert_for_assignment (loc, valtype, retval, origtype, + ic_return, + npc, NULL_TREE, NULL_TREE, 0); tree res = DECL_RESULT (current_function_decl); tree inner; @@ -8092,7 +8151,8 @@ c_finish_return (tree retval, tree origtype) && !DECL_EXTERNAL (inner) && !TREE_STATIC (inner) && DECL_CONTEXT (inner) == current_function_decl) - warning (0, "function returns address of local variable"); + warning_at (loc, + 0, "function returns address of local variable"); break; default: @@ -8103,12 +8163,13 @@ c_finish_return (tree retval, tree origtype) } retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t); + SET_EXPR_LOCATION (retval, loc); if (warn_sequence_point) verify_sequence_points (retval); } - ret_stmt = build_stmt (RETURN_EXPR, retval); + ret_stmt = build_stmt (loc, RETURN_EXPR, retval); TREE_NO_WARNING (ret_stmt) |= no_warning; return add_stmt (ret_stmt); } @@ -8151,10 +8212,13 @@ struct c_switch { struct c_switch *c_switch_stack; /* Start a C switch statement, testing expression EXP. Return the new - SWITCH_EXPR. */ + SWITCH_EXPR. SWITCH_LOC is the location of the `switch'. + SWITCH_COND_LOC is the location of the switch's condition. */ tree -c_start_case (tree exp) +c_start_case (location_t switch_loc, + location_t switch_cond_loc, + tree exp) { tree orig_type = error_mark_node; struct c_switch *cs; @@ -8167,7 +8231,7 @@ c_start_case (tree exp) { if (orig_type != error_mark_node) { - error ("switch quantity not an integer"); + error_at (switch_cond_loc, "switch quantity not an integer"); orig_type = error_mark_node; } exp = integer_zero_node; @@ -8179,8 +8243,9 @@ c_start_case (tree exp) if (!in_system_header && (type == long_integer_type_node || type == long_unsigned_type_node)) - warning (OPT_Wtraditional, "%<long%> switch expression not " - "converted to %<int%> in ISO C"); + warning_at (switch_cond_loc, + OPT_Wtraditional, "%<long%> switch expression not " + "converted to %<int%> in ISO C"); exp = c_fully_fold (exp, false, NULL); exp = default_conversion (exp); @@ -8193,6 +8258,7 @@ c_start_case (tree exp) /* Add this new SWITCH_EXPR to the stack. */ cs = XNEW (struct c_switch); cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE); + SET_EXPR_LOCATION (cs->switch_expr, switch_loc); cs->orig_type = orig_type; cs->cases = splay_tree_new (case_compare, NULL, NULL); cs->blocked_stmt_expr = 0; @@ -8203,10 +8269,10 @@ c_start_case (tree exp) return add_stmt (cs->switch_expr); } -/* Process a case label. */ +/* Process a case label at location LOC. */ tree -do_case (tree low_value, tree high_value) +do_case (location_t loc, tree low_value, tree high_value) { tree label = NULL_TREE; @@ -8229,7 +8295,7 @@ do_case (tree low_value, tree high_value) if (c_switch_stack && !c_switch_stack->blocked_stmt_expr && !c_switch_stack->blocked_vm) { - label = c_add_case_label (c_switch_stack->cases, + label = c_add_case_label (loc, c_switch_stack->cases, SWITCH_COND (c_switch_stack->switch_expr), c_switch_stack->orig_type, low_value, high_value); @@ -8239,25 +8305,26 @@ do_case (tree low_value, tree high_value) else if (c_switch_stack && c_switch_stack->blocked_stmt_expr) { if (low_value) - error ("case label in statement expression not containing " - "enclosing switch statement"); + error_at (loc, "case label in statement expression not containing " + "enclosing switch statement"); else - error ("%<default%> label in statement expression not containing " - "enclosing switch statement"); + error_at (loc, "%<default%> label in statement expression not containing " + "enclosing switch statement"); } else if (c_switch_stack && c_switch_stack->blocked_vm) { if (low_value) - error ("case label in scope of identifier with variably modified " - "type not containing enclosing switch statement"); + error_at (loc, "case label in scope of identifier with variably " + "modified type not containing enclosing switch statement"); else - error ("%<default%> label in scope of identifier with variably " - "modified type not containing enclosing switch statement"); + error_at (loc, "%<default%> label in scope of identifier with " + "variably modified type not containing enclosing switch " + "statement"); } else if (low_value) - error ("case label not within a switch statement"); + error_at (loc, "case label not within a switch statement"); else - error ("%<default%> label not within a switch statement"); + error_at (loc, "%<default%> label not within a switch statement"); return label; } @@ -8278,10 +8345,7 @@ c_finish_case (tree body) gcc_assert (!cs->blocked_stmt_expr); /* Emit warnings as needed. */ - if (EXPR_HAS_LOCATION (cs->switch_expr)) - switch_location = EXPR_LOCATION (cs->switch_expr); - else - switch_location = input_location; + switch_location = EXPR_LOCATION (cs->switch_expr); c_do_switch_warnings (cs->cases, switch_location, TREE_TYPE (cs->switch_expr), SWITCH_COND (cs->switch_expr)); @@ -8418,7 +8482,7 @@ c_finish_loop (location_t start_locus, tree cond, tree incr, tree body, } tree -c_finish_bc_stmt (tree *label_p, bool is_break) +c_finish_bc_stmt (location_t loc, tree *label_p, bool is_break) { bool skip; tree label = *label_p; @@ -8435,7 +8499,7 @@ c_finish_bc_stmt (tree *label_p, bool is_break) if (!label) { if (!skip) - *label_p = label = create_artificial_label (); + *label_p = label = create_artificial_label (loc); } else if (TREE_CODE (label) == LABEL_DECL) ; @@ -8443,14 +8507,14 @@ c_finish_bc_stmt (tree *label_p, bool is_break) { case 0: if (is_break) - error ("break statement not within loop or switch"); + error_at (loc, "break statement not within loop or switch"); else - error ("continue statement not within a loop"); + error_at (loc, "continue statement not within a loop"); return NULL_TREE; case 1: gcc_assert (is_break); - error ("break statement used with OpenMP for loop"); + error_at (loc, "break statement used with OpenMP for loop"); return NULL_TREE; default: @@ -8469,25 +8533,25 @@ c_finish_bc_stmt (tree *label_p, bool is_break) /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */ static void -emit_side_effect_warnings (tree expr) +emit_side_effect_warnings (location_t loc, tree expr) { if (expr == error_mark_node) ; else if (!TREE_SIDE_EFFECTS (expr)) { if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) - warning (OPT_Wunused_value, "%Hstatement with no effect", - EXPR_HAS_LOCATION (expr) ? EXPR_LOCUS (expr) : &input_location); + warning_at (loc, OPT_Wunused_value, "statement with no effect"); } else - warn_if_unused_value (expr, input_location); + warn_if_unused_value (expr, loc); } /* Process an expression as if it were a complete statement. Emit - diagnostics, but do not call ADD_STMT. */ + diagnostics, but do not call ADD_STMT. LOC is the location of the + statement. */ tree -c_process_expr_stmt (tree expr) +c_process_expr_stmt (location_t loc, tree expr) { if (!expr) return NULL_TREE; @@ -8500,33 +8564,34 @@ c_process_expr_stmt (tree expr) if (TREE_TYPE (expr) != error_mark_node && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr)) && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE) - error ("expression statement has incomplete type"); + error_at (loc, "expression statement has incomplete type"); /* If we're not processing a statement expression, warn about unused values. Warnings for statement expressions will be emitted later, once we figure out which is the result. */ if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list) && warn_unused_value) - emit_side_effect_warnings (expr); + emit_side_effect_warnings (loc, expr); /* If the expression is not of a type to which we cannot assign a line number, wrap the thing in a no-op NOP_EXPR. */ if (DECL_P (expr) || CONSTANT_CLASS_P (expr)) - expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr); - - if (CAN_HAVE_LOCATION_P (expr)) - SET_EXPR_LOCATION (expr, input_location); + { + expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr); + SET_EXPR_LOCATION (expr, loc); + } return expr; } -/* Emit an expression as a statement. */ +/* Emit an expression as a statement. LOC is the location of the + expression. */ tree -c_finish_expr_stmt (tree expr) +c_finish_expr_stmt (location_t loc, tree expr) { if (expr) - return add_stmt (c_process_expr_stmt (expr)); + return add_stmt (c_process_expr_stmt (loc, expr)); else return NULL; } @@ -8569,14 +8634,17 @@ c_begin_stmt_expr (void) return ret; } +/* LOC is the location of the compound statement to which this body + belongs. */ + tree -c_finish_stmt_expr (tree body) +c_finish_stmt_expr (location_t loc, tree body) { tree last, type, tmp, val; tree *last_p; struct c_label_list *dlist, *glist, *glist_prev = NULL; - body = c_end_compound_stmt (body, true); + body = c_end_compound_stmt (loc, body, true); if (c_switch_stack) { gcc_assert (c_switch_stack->blocked_stmt_expr != 0); @@ -8625,7 +8693,13 @@ c_finish_stmt_expr (tree body) if (warn_unused_value) { for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i)) - emit_side_effect_warnings (tsi_stmt (i)); + { + location_t tloc; + tree t = tsi_stmt (i); + + tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc; + emit_side_effect_warnings (tloc, t); + } } else i = tsi_last (last); @@ -8682,7 +8756,11 @@ c_finish_stmt_expr (tree body) *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val); SET_EXPR_LOCUS (*last_p, EXPR_LOCUS (last)); - return build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE); + { + tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE); + SET_EXPR_LOCATION (t, loc); + return t; + } } /* Begin the scope of an identifier of variably modified type, scope @@ -8771,8 +8849,12 @@ c_begin_compound_stmt (bool do_scope) return stmt; } +/* End a compound statement. STMT is the statement. LOC is the + location of the compound statement-- this is usually the location + of the opening brace. */ + tree -c_end_compound_stmt (tree stmt, bool do_scope) +c_end_compound_stmt (location_t loc, tree stmt, bool do_scope) { tree block = NULL; @@ -8784,7 +8866,7 @@ c_end_compound_stmt (tree stmt, bool do_scope) } stmt = pop_stmt_list (stmt); - stmt = c_build_bind_expr (block, stmt); + stmt = c_build_bind_expr (loc, block, stmt); /* If this compound statement is nested immediately inside a statement expression, then force a BIND_EXPR to be created. Otherwise we'll @@ -8797,6 +8879,7 @@ c_end_compound_stmt (tree stmt, bool do_scope) { stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL); TREE_SIDE_EFFECTS (stmt) = 1; + SET_EXPR_LOCATION (stmt, loc); } return stmt; @@ -8807,14 +8890,14 @@ c_end_compound_stmt (tree stmt, bool do_scope) meant to apply to normal control flow transfer. */ void -push_cleanup (tree ARG_UNUSED (decl), tree cleanup, bool eh_only) +push_cleanup (tree decl, tree cleanup, bool eh_only) { enum tree_code code; tree stmt, list; bool stmt_expr; code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR; - stmt = build_stmt (code, NULL, cleanup); + stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup); add_stmt (stmt); stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list); list = push_stmt_list (); @@ -9749,19 +9832,21 @@ c_begin_omp_parallel (void) return block; } -/* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound statement. */ +/* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound + statement. LOC is the location of the OMP_PARALLEL. */ tree -c_finish_omp_parallel (tree clauses, tree block) +c_finish_omp_parallel (location_t loc, tree clauses, tree block) { tree stmt; - block = c_end_compound_stmt (block, true); + block = c_end_compound_stmt (loc, block, true); stmt = make_node (OMP_PARALLEL); TREE_TYPE (stmt) = void_type_node; OMP_PARALLEL_CLAUSES (stmt) = clauses; OMP_PARALLEL_BODY (stmt) = block; + SET_EXPR_LOCATION (stmt, loc); return add_stmt (stmt); } @@ -9779,19 +9864,21 @@ c_begin_omp_task (void) return block; } -/* Generate OMP_TASK, with CLAUSES and BLOCK as its compound statement. */ +/* Generate OMP_TASK, with CLAUSES and BLOCK as its compound + statement. LOC is the location of the #pragma. */ tree -c_finish_omp_task (tree clauses, tree block) +c_finish_omp_task (location_t loc, tree clauses, tree block) { tree stmt; - block = c_end_compound_stmt (block, true); + block = c_end_compound_stmt (loc, block, true); stmt = make_node (OMP_TASK); TREE_TYPE (stmt) = void_type_node; OMP_TASK_CLAUSES (stmt) = clauses; OMP_TASK_BODY (stmt) = block; + SET_EXPR_LOCATION (stmt, loc); return add_stmt (stmt); } @@ -9837,7 +9924,8 @@ c_finish_omp_clauses (tree clauses) if (AGGREGATE_TYPE_P (TREE_TYPE (t)) || POINTER_TYPE_P (TREE_TYPE (t))) { - error ("%qE has invalid type for %<reduction%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE has invalid type for %<reduction%>", t); remove = true; } else if (FLOAT_TYPE_P (TREE_TYPE (t))) @@ -9871,8 +9959,9 @@ c_finish_omp_clauses (tree clauses) } if (r_name) { - error ("%qE has invalid type for %<reduction(%s)%>", - t, r_name); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE has invalid type for %<reduction(%s)%>", + t, r_name); remove = true; } } @@ -9887,7 +9976,8 @@ c_finish_omp_clauses (tree clauses) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t)) { - error ("%qE must be %<threadprivate%> for %<copyin%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE must be %<threadprivate%> for %<copyin%>", t); remove = true; } goto check_dup_generic; @@ -9896,14 +9986,16 @@ c_finish_omp_clauses (tree clauses) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) { - error ("%qE is not a variable in clause %qs", t, name); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %qs", t, name); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) { - error ("%qE appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE appears more than once in data clauses", t); remove = true; } else @@ -9917,13 +10009,15 @@ c_finish_omp_clauses (tree clauses) need_implicitly_determined = true; if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) { - error ("%qE is not a variable in clause %<firstprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %<firstprivate%>", t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) { - error ("%qE appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE appears more than once in data clauses", t); remove = true; } else @@ -9937,13 +10031,15 @@ c_finish_omp_clauses (tree clauses) need_implicitly_determined = true; if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) { - error ("%qE is not a variable in clause %<lastprivate%>", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is not a variable in clause %<lastprivate%>", t); remove = true; } else if (bitmap_bit_p (&generic_head, DECL_UID (t)) || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) { - error ("%qE appears more than once in data clauses", t); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE appears more than once in data clauses", t); remove = true; } else @@ -9997,8 +10093,9 @@ c_finish_omp_clauses (tree clauses) } if (share_name) { - error ("%qE is predetermined %qs for %qs", - t, share_name, name); + error_at (OMP_CLAUSE_LOCATION (c), + "%qE is predetermined %qs for %qs", + t, share_name, name); remove = true; } } @@ -10082,10 +10179,10 @@ c_build_qualified_type (tree type, int type_quals) /* Build a VA_ARG_EXPR for the C parser. */ tree -c_build_va_arg (tree expr, tree type, location_t loc) +c_build_va_arg (location_t loc, tree expr, tree type) { if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE) warning_at (loc, OPT_Wc___compat, "C++ requires promoted type, not enum type, in %<va_arg%>"); - return build_va_arg (expr, type); + return build_va_arg (loc, expr, type); } |