1. 01 Jan, 2019 1 commit
  2. 27 Nov, 2018 1 commit
    • PR preprocessor/83173: Enhance -fdump-internal-locations output · bc65bad2
      gcc/ChangeLog:
      2018-11-27  Mike Gulick  <mgulick@mathworks.com>
      
      	PR preprocessor/83173
      	* input.c (dump_location_info): Dump reason and included_from
      	fields from line_map_ordinary struct.  Fix indentation when
      	location > 5 digits.
      	* diagnostic-show-locus.c (num_digits, num_digits): Move to
      	diagnostic.c to allow it to be utilized by input.c.
      	* diagnostic.c (num_digits, selftest::test_num_digits): Moved
      	here.
      	(selftest::diagnostic_c_tests): Run selftest::test_num_digits.
      	* diagnostic.h (num_digits): Add extern definition.
      
      libcpp/ChangeLog:
      2018-11-27  Mike Gulick  <mgulick@mathworks.com>
      
      	PR preprocessor/83173
      	* location-example.txt: Update example -fdump-internal-locations
      	output.
      
      From-SVN: r266520
      Mike Gulick committed
  3. 15 Nov, 2018 1 commit
    • Machine-readable diagnostic output (PR other/19165) · 478dd60d
      This patch implements a -fdiagnostics-format=json option which
      converts the diagnostics to be output to stderr in a JSON format;
      see the documentation in invoke.texi.
      
      Logically-related diagnostics are nested at the JSON level, using
      the auto_diagnostic_group mechanism.
      
      gcc/ChangeLog:
      	PR other/19165
      	* Makefile.in (OBJS): Move json.o to...
      	(OBJS-libcommon): ...here and add diagnostic-format-json.o.
      	* common.opt (fdiagnostics-format=): New option.
      	(diagnostics_output_format): New enum.
      	* diagnostic-format-json.cc: New file.
      	* diagnostic.c (default_diagnostic_final_cb): New function, taken
      	from start of diagnostic_finish.
      	(diagnostic_initialize): Initialize final_cb to
      	default_diagnostic_final_cb.
      	(diagnostic_finish): Move "being treated as errors" messages to
      	default_diagnostic_final_cb.  Call any final_cb.
      	(default_diagnostic_finalizer): Add diagnostic_t param.
      	(diagnostic_report_diagnostic): Pass "orig_diag_kind" to
      	diagnostic_finalizer callback.
      	* diagnostic.h (enum diagnostics_output_format): New enum.
      	(diagnostic_finalizer_fn): Reimplement, adding diagnostic_t param.
      	(struct diagnostic_context): Add "final_cb".
      	(default_diagnostic_finalizer): Add diagnostic_t param.
      	(diagnostic_output_format_init): New decl.
      	* doc/invoke.texi (-fdiagnostics-format): New option.
      	* dwarf2out.c (gen_producer_string): Ignore
      	OPT_fdiagnostics_format_.
      	* gcc.c (driver_handle_option): Handle OPT_fdiagnostics_format_.
      	* lto-wrapper.c (append_diag_options): Ignore it.
      	* opts.c (common_handle_option): Handle it.
      
      gcc/c-family/ChangeLog:
      	PR other/19165
      	* c-opts.c (c_diagnostic_finalizer): Add diagnostic_t param.
      
      gcc/fortran/ChangeLog:
      	PR other/19165
      	* error.c (gfc_diagnostic_finalizer): Add diagnostic_t param.
      
      gcc/jit/ChangeLog:
      	PR other/19165
      	* dummy-frontend.c (jit_begin_diagnostic): Add diagnostic_t param.
      
      gcc/testsuite/ChangeLog:
      	PR other/19165
      	* c-c++-common/diagnostic-format-json-1.c: New test.
      	* c-c++-common/diagnostic-format-json-2.c: New test.
      	* c-c++-common/diagnostic-format-json-3.c: New test.
      	* c-c++-common/diagnostic-format-json-4.c: New test.
      	* c-c++-common/diagnostic-format-json-5.c: New test.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
      	(custom_diagnostic_finalizer): Add diagnostic_t param.
      	* gcc.dg/plugin/location_overflow_plugin.c
      	(verify_unpacked_ranges): Likewise.
      	(verify_no_columns): Likewise.
      	* gfortran.dg/diagnostic-format-json-1.F90: New test.
      	* gfortran.dg/diagnostic-format-json-2.F90: New test.
      	* gfortran.dg/diagnostic-format-json-3.F90: New test.
      
      From-SVN: r266186
      David Malcolm committed
  4. 15 Oct, 2018 1 commit
    • diagnostics: add minimum width to left margin for line numbers · 0141ab44
      This patch adds a minimum width to the left margin used for printing
      line numbers.   I set the default to 6.  Hence rather than:
      
      some-filename:9:1: some message
      9 | some source text
        | ^~~~~~~~~~~~~~~~
      some-filename:10:1: another message
      10 | more source text
         | ^~~~~~~~~~~~~~~~
      
      we now print:
      
      some-filename:9:42: some message
          9 | some source text
            | ^~~~~~~~~~~~~~~~
      some-filename:10:42: another message
         10 | more source text
            | ^~~~~~~~~~~~~~~~
      
      This implicitly fixes issues with margins failing to line up due
      to different lengths of the number when we haven't read the full
      file yet and so don't know the highest possible line number, for
      line numbers up to 99999.
      
      Doing so adds some whitespace on the left-hand side, for non-huge
      files, at least.  I believe that this makes it easier to see where each
      diagnostic starts, by visually breaking things up at the leftmost
      column; my hope is to make it easier for the eye to see the different
      diagnostics as if they were different "paragraphs".
      
      gcc/ChangeLog:
      	* common.opt (fdiagnostics-minimum-margin-width=): New option.
      	* diagnostic-show-locus.c (layout::layout): Apply the minimum
      	margin width.
      	(layout::start_annotation_line): Only print up to 3 of the
      	margin character, to avoid touching the left-hand side.
      	(selftest::test_diagnostic_show_locus_fixit_lines): Update for
      	minimum margin width, as set by test_diagnostic_context's ctor.
      	(selftest::test_fixit_insert_containing_newline): Likewise.
      	(selftest::test_fixit_insert_containing_newline_2): Likewise.
      	(selftest::test_line_numbers_multiline_range): Clear
      	dc.min_margin_width.
      	* diagnostic.c (diagnostic_initialize): Initialize
      	min_margin_width.
      	* diagnostic.h (struct diagnostic_context): Add field
      	"min_margin_width".
      	* doc/invoke.texi: Add -fdiagnostics-minimum-margin-width=.
      	* opts.c (common_handle_option): Handle
      	OPT_fdiagnostics_minimum_margin_width_.
      	* selftest-diagnostic.c
      	(selftest::test_diagnostic_context::test_diagnostic_context):
      	Initialize min_margin_width to 6.
      	* toplev.c (general_init): Initialize global_dc->min_margin_width.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/missing-header-fixit-3.c: Update expected indentation
      	to reflect minimum margin width.
      	* gcc.dg/missing-header-fixit-4.c: Likewise.
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c:
      	Likewise.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
      	Likewise.
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers-2.c:
      	New test.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add it.
      
      From-SVN: r265178
      David Malcolm committed
  5. 01 Oct, 2018 1 commit
  6. 20 Aug, 2018 1 commit
    • Add support for grouping of related diagnostics (PR other/84889) · 097f82ec
      We often emit logically-related groups of diagnostics.
      
      A relatively simple case is this:
      
        if (warning_at (body_loc, OPT_Wmultistatement_macros,
                        "macro expands to multiple statements"))
          inform (guard_loc, "some parts of macro expansion are not guarded by "
                  "this %qs clause", guard_tinfo_to_string (keyword));
      
      where the "note" diagnostic issued by the "inform" call
      is guarded by the -Wmultistatement_macros warning.
      
      More complicated examples can be seen in the C++ frontend,
      where e.g. print_z_candidates can lead to numerous "note"
      diagnostics being emitted.
      
      I'm looking at various ways to improve how we handle such related
      diagnostics, but, prior to this patch, there was no explicit
      relationship between these diagnostics: the diagnostics subsystem
      had no way of "knowing" that these were related.
      
      This patch introduces a simple way to group the diagnostics:
      an auto_diagnostic_group class: all diagnostics emitted within
      the lifetime of an auto_diagnostic_group instance are logically
      grouped.
      
      Hence in the above example, the two diagnostics can be grouped
      by simply adding an auto_diagnostic_group instance:
      
        auto_diagnostic_group d;
        if (warning_at (body_loc, OPT_Wmultistatement_macros,
                        "macro expands to multiple statements"))
          inform (guard_loc, "some parts of macro expansion are not guarded by "
                  "this %qs clause", guard_tinfo_to_string (keyword));
      
      Some more awkard cases are of the form:
      
        if (some_condition
            && warning_at (...)
            && more_conditions)
          inform (...);
      
      which thus need restructuring to:
      
        if (some_condition)
          {
            auto_diagnostic_group d;
            warning_at (...);
            if (more_conditions)
              inform (...);
          }
      
      so that the lifetime of the auto_diagnostic_group groups the
      warning_at and the inform call.
      
      Nesting is handled by simply tracking a nesting depth within the
      diagnostic_context.: all diagnostics are treated as grouped until the
      final auto_diagnostic_group is popped.
      
      diagnostic.c uses this internally, so that all diagnostics are part of
      a group - those that are "by themselves" are treated as being part of
      a group with one element.
      
      The diagnostic_context gains optional callbacks for displaying the
      start of a group (when the first diagnostic is emitted within it), and
      the end of a group (for when the group was non-empty); these callbacks
      are unused by default, but a test plugin demonstrates them (and verifies
      that the machinery is working).
      
      As noted above, I'm looking at various ways to use the grouping to
      improve how we output the diagnostics.
      
      FWIW, I experimented with a more involved implementation, of the form:
      
        diagnostic_group d;
        if (d.warning_at (body_loc, OPT_Wmultistatement_macros,
                          "macro expands to multiple statements"))
          d.inform (guard_loc, "some parts of macro expansion are not guarded by "
                    "this %qs clause", guard_tinfo_to_string (keyword));
      
      which had the advantage of allowing auto-detection of the places where
      groups were needed (by converting ::warning_at's return type to bool),
      but it was a much more invasive patch, especially when dealing with
      the places in the C++ frontend that can emit numerous notes after
      an error or warning (and thus having to pass the group around)
      Hence I went with this simpler approach.
      
      gcc/c-family/ChangeLog:
      	PR other/84889
      	* c-attribs.c (common_handle_aligned_attribute): Add
      	auto_diagnostic_group instance.
      	* c-indentation.c (warn_for_misleading_indentation): Likewise.
      	* c-opts.c (c_common_post_options): Likewise.
      	* c-warn.c (warn_logical_not_parentheses): Likewise.
      	(warn_duplicated_cond_add_or_warn): Likewise.
      	(warn_for_multistatement_macros): Likewise.
      
      gcc/c/ChangeLog:
      	PR other/84889
      	* c-decl.c (pushtag): Add auto_diagnostic_group instance.
      	(diagnose_mismatched_decls): Likewise, in various places.
      	(warn_if_shadowing): Likewise.
      	(implicit_decl_warning): Likewise.
      	(implicitly_declare): Likewise.
      	(undeclared_variable): Likewise.
      	(declare_label): Likewise.
      	(grokdeclarator): Likewise.
      	(start_function): Likewise.
      	* c-parser.c (c_parser_declaration_or_fndef): Likewise.
      	(c_parser_parameter_declaration): Likewise.
      	(c_parser_binary_expression): Likewise.
      	* c-typeck.c (c_expr_sizeof_expr): Likewise.
      	(parser_build_binary_op): Likewise.
      	(build_unary_op): Likewise.
      	(error_init): Likewise.
      	(pedwarn_init): Likewise.
      	(warning_init): Likewise.
      	(convert_for_assignment): Likewise.
      
      gcc/cp/ChangeLog:
      	PR other/84889
      	* call.c (build_user_type_conversion_1): Add auto_diagnostic_group
      	instance(s).
      	(print_error_for_call_failure): Likewise.
      	(build_op_call_1): Likewise.
      	(build_conditional_expr_1): Likewise.
      	(build_new_op_1): Likewise.
      	(build_op_delete_call): Likewise.
      	(convert_like_real): Likewise.
      	(build_over_call): Likewise.
      	(build_new_method_call_1): Likewise.
      	(joust): Likewise.
      	* class.c (check_tag): Likewise.
      	(finish_struct_anon_r): Likewise.
      	(one_inherited_ctor): Likewise.
      	(finalize_literal_type_property): Likewise.
      	(explain_non_literal_class): Likewise.
      	(find_flexarrays): Likewise.
      	(resolve_address_of_overloaded_function): Likewise.
      	* constexpr.c (ensure_literal_type_for_constexpr_object): Likewise.
      	(is_valid_constexpr_fn): Likewise.
      	(cx_check_missing_mem_inits): Likewise.
      	* cp-gimplify.c (cp_genericize_r): Likewise.
      	* cvt.c (maybe_warn_nodiscard): Likewise.
      	* decl.c (warn_extern_redeclared_static): Likewise.
      	(check_redeclaration_exception_specification): Likewise.
      	(check_no_redeclaration_friend_default_args): Likewise.
      	(duplicate_decls): Likewise.
      	(redeclaration_error_message): Likewise.
      	(warn_misplaced_attr_for_class_type): Likewise.
      	* decl2.c (finish_static_data_member_decl): Likewise.
      	(no_linkage_error): Likewise.
      	(cp_warn_deprecated_use): Likewise.
      	* error.c (qualified_name_lookup_error): Likewise.
      	* friend.c (make_friend_class): Likewise.
      	(do_friend): Likewise.
      	* init.c (perform_member_init): Likewise.
      	(build_new_1): Likewise.
      	(build_vec_delete_1): Likewise.
      	(build_delete): Likewise.
      	* lex.c (unqualified_name_lookup_error): Likewise.
      	* name-lookup.c (check_extern_c_conflict): Likewise.
      	(inform_shadowed): New function.
      	(check_local_shadow): Add auto_diagnostic_group instances,
      	replacing goto "inform_shadowed" label with call to subroutine.
      	(set_local_extern_decl_linkage): Add auto_diagnostic_group
      	instance(s).
      	* parser.c (cp_parser_diagnose_invalid_type_name): Likewise.
      	(cp_parser_namespace_name): Likewise.
      	* pt.c (check_specialization_namespace): Likewise.
      	(check_template_variable): Likewise.
      	(warn_spec_missing_attributes): Likewise.
      	(check_explicit_specialization): Likewise.
      	(process_partial_specialization): Likewise.
      	(lookup_template_class_1): Likewise.
      	(finish_template_variable): Likewise.
      	(do_auto_deduction): Likewise.
      	* search.c (check_final_overrider): Likewise.
      	(look_for_overrides_r): Likewise.
      	* tree.c (maybe_warn_parm_abi): Likewise.
      	* typeck.c (cxx_sizeof_expr): Likewise.
      	(cp_build_function_call_vec): Likewise.
      	(cp_build_binary_op): Likewise.
      	(convert_for_assignment): Likewise.
      	(maybe_warn_about_returning_address_of_local): Likewise.
      	* typeck2.c (abstract_virtuals_error_sfinae): Likewise.
      	(check_narrowing): Likewise.
      
      gcc/ChangeLog:
      	PR other/84889
      	* attribs.c (diag_attr_exclusions): Add auto_diagnostic_group instance.
      	(decl_attributes): Likewise.
      	* calls.c (maybe_warn_nonstring_arg): Add auto_diagnostic_group
      	instance.
      	* cgraphunit.c (maybe_diag_incompatible_alias): Likewise.
      	* diagnostic-core.h (class auto_diagnostic_group): New class.
      	* diagnostic.c (diagnostic_initialize): Initialize the new fields.
      	(diagnostic_report_diagnostic): Handle the first diagnostics within
      	a group.
      	(emit_diagnostic): Add auto_diagnostic_group instance.
      	(inform): Likewise.
      	(inform_n): Likewise.
      	(warning): Likewise.
      	(warning_at): Likewise.
      	(warning_n): Likewise.
      	(pedwarn): Likewise.
      	(permerror): Likewise.
      	(error): Likewise.
      	(error_n): Likewise.
      	(error_at): Likewise.
      	(sorry): Likewise.
      	(fatal_error): Likewise.
      	(internal_error): Likewise.
      	(internal_error_no_backtrace): Likewise.
      	(auto_diagnostic_group::auto_diagnostic_group): New ctor.
      	(auto_diagnostic_group::~auto_diagnostic_group): New dtor.
      	* diagnostic.h (struct diagnostic_context): Add fields
      	"diagnostic_group_nesting_depth",
      	"diagnostic_group_emission_count", "begin_group_cb",
      	"end_group_cb".
      	* gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior):
      	Add auto_diagnostic_group instance(s).
      	(find_explicit_erroneous_behavior): Likewise.
      	* gimple-ssa-warn-alloca.c (pass_walloca::execute): Likewise.
      	* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Likewise.
      	* gimplify.c (warn_implicit_fallthrough_r): Likewise.
      	(gimplify_va_arg_expr): Likewise.
      	* hsa-gen.c (HSA_SORRY_ATV): Likewise.
      	(HSA_SORRY_AT): Likewise.
      	* ipa-devirt.c (compare_virtual_tables): Likewise.
      	(warn_odr): Likewise.
      	* multiple_target.c (expand_target_clones): Likewise.
      	* opts-common.c (cmdline_handle_error): Likewise.
      	* reginfo.c (globalize_reg): Likewise.
      	* substring-locations.c (format_warning_n_va): Likewise.
      	* tree-inline.c (expand_call_inline): Likewise.
      	* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Likewise.
      	* tree-ssa-loop-niter.c
      	(do_warn_aggressive_loop_optimizations): Likewise.
      	* tree-ssa-uninit.c (warn_uninit): Likewise.
      	* tree.c (warn_deprecated_use): Likewise.
      
      gcc/testsuite/ChangeLog:
      	PR other/84889
      	* gcc.dg/plugin/diagnostic-group-test-1.c: New test.
      	* gcc.dg/plugin/diagnostic_group_plugin.c: New test.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new tests.
      
      From-SVN: r263675
      David Malcolm committed
  7. 15 Aug, 2018 1 commit
    • diagnostics: add labeling of source ranges · 96e6ae57
      This patch adds the ability to label source ranges within a rich_location,
      to be printed by diagnostic_show_locus.
      
      For example:
      
      pr69554-1.c:11:18: error: invalid operands to binary + (have 'const char *' and 'const char *')
      11 |   return (p + 1) + (q + 1);
         |          ~~~~~~~ ^ ~~~~~~~
         |             |         |
         |             |         const char *
         |             const char *
      
      The patch implements labels for various type mismatch errors in the C and
      C++ frontends, and in -Wformat.  I implemented it wherever accurate location
      information was guaranteed (there are other places that could benefit, but
      we need better location information in those places).
      
      The labels can be disabled via -fno-diagnostics-show-labels.
      
      Similarly:
      
      param-type-mismatch.C: In function 'int test_1(int, int, float)':
      param-type-mismatch.C:11:27: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
      11 |   return callee_1 (first, second, third);
         |                           ^~~~~~
         |                           |
         |                           int
      param-type-mismatch.C:7:43: note:   initializing argument 2 of 'int callee_1(int, const char*, float)'
      7 | extern int callee_1 (int one, const char *two, float three);
        |                               ~~~~~~~~~~~~^~~
      
      where the first "error" describing the bad argument gets a label
      describing the type inline (since it's non-obvious from "second").
      The "note" describing the type of the param of the callee *doesn't*
      get a label, since that information is explicit there in the
      source ("const char *two").
      
      The idea is that in any diagnostic where two aspects of the source aren't
      in sync it ought to be easier for the user if we directly show them the
      mismatching aspects inline (e.g. types).
      
      As well as type mismatch errors, perhaps labels could also be used for
      buffer overflow warnings, for describing the capacity of the destination
      buffer vs the size of what's being written:
      
        sprintf (buf, "filename: %s\n", file);
                 ^~~   ~~~~~~~~~~~^~~
                 |                |
                 capacity: 32     10 + strlen(file) + 2
      
      or somesuch.  Another idea might be for macro expansion warnings:
      
      warning: repeated side effects in macro expansion...
         x = MIN (p++, q++);
             ~~~~^~~~~~~~~~
      note: ...expanded here as
       #define MIN(X,Y) (X<Y?X:Y)
               ^~~ ~ ~   ~ ~ ~ ~
                   | |   | | | |
                   | |   | | | q++
                   | |   | | p++
                   | |   | q++
                   | q++ p++
                   p++
      
      The patch removes some logic from multiline.exp which special-cased
      lines ending with a '|' character (thus complicating testing of this
      patch).  I believe that this was a vestige from experiments I did to
      support strippng dg directives from the output; it was present in the
      earliest version of multiline.exp I posted:
        "[RFC, stage1] Richer source location information for gcc 6 (location ranges etc)"
          https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00837.html
      and I believe was neved used.
      
      gcc/c-family/ChangeLog:
      	* c-format.c: Include "selftest-diagnostic.h" and
      	"gcc-rich-location.h".
      	(format_warning_at_char): Pass NULL for new label params of
      	format_warning_va.
      	(class indirection_suffix): New class.
      	(class range_label_for_format_type_mismatch): New class.
      	(format_type_warning): Move logic for generating "*" suffix to
      	class indirection_suffix.  Create "fmt_label" and "param_label"
      	to show their types, and pass them to the
      	format_warning_at_substring calls.
      	(selftest::test_type_mismatch_range_labels): New test.
      	(selftest::c_format_c_tests): Call it.
      
      gcc/c/ChangeLog:
      	* c-objc-common.c: Include "gcc-rich-location.h".
      	(c_tree_printer): Move implemenation of '%T' to...
      	(print_type): ...this new function.
      	(range_label_for_type_mismatch::get_text): New function.
      	* c-typeck.c (convert_for_assignment): Add type labels to the rhs
      	range for the various ic_argpass cases.
      	(class maybe_range_label_for_tree_type_mismatch): New class.
      	(build_binary_op): Use it when calling binary_op_error.
      
      gcc/cp/ChangeLog:
      	* call.c: Include "gcc-rich-location.h".
      	(convert_like_real): Add range label for "invalid conversion"
      	diagnostic.
      	(perform_implicit_conversion_flags): Add type label to the
      	"could not convert" error.
      	* error.c: Include "gcc-rich-location.h".
      	(range_label_for_type_mismatch::get_text): New function.
      	* typeck.c (convert_for_assignment): Add type label to
      	the "cannot convert" error if a location is available.
      
      gcc/ChangeLog:
      	* common.opt (fdiagnostics-show-labels): New option.
      	* diagnostic-show-locus.c (class layout_range): Add field
      	"m_label".
      	(class layout): Add field "m_show_labels_p".
      	(layout_range::layout_range): Add param "label" and use it to
      	initialize m_label.
      	(make_range): Pass in NULL for new "label" param of layout_range's
      	ctor.
      	(layout::layout): Initialize m_show_labels_p.
      	(layout::maybe_add_location_range): Pass in loc_range->m_label
      	when constructing layout_range instances.
      	(struct line_label): New struct.
      	(layout::print_any_labels): New member function.
      	(layout::print_line): Call it if label-printing is enabled.
      	(selftest::test_one_liner_labels): New test.
      	(selftest::test_diagnostic_show_locus_one_liner): Call it.
      	* diagnostic.c (diagnostic_initialize): Initialize
      	context->show_labels_p.
      	* diagnostic.h (struct diagnostic_context): Add field
      	"show_labels_p".
      	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
      	-fno-diagnostics-show-labels.
      	* dwarf2out.c (gen_producer_string): Add
      	OPT_fdiagnostics_show_labels to the ignored options.
      	* gcc-rich-location.c (gcc_rich_location::add_expr): Add "label"
      	param.
      	(gcc_rich_location::maybe_add_expr): Likewise.
      	* gcc-rich-location.h (gcc_rich_location::gcc_rich_location): Add
      	label" param, defaulting to NULL.
      	(gcc_rich_location::add_expr): Add "label" param.
      	(gcc_rich_location::maybe_add_expr): Likewise.
      	(class text_range_label): New class.
      	(class range_label_for_type_mismatch): New class.
      	* gimple-ssa-sprintf.c (fmtwarn): Pass NULL for new label params
      	of format_warning_va.
      	(fmtwarn_n): Likewise for new params of format_warning_n_va.
      	* lto-wrapper.c (merge_and_complain): Add
      	OPT_fdiagnostics_show_labels to the "pick one setting" options.
      	(append_compiler_options): Likewise to the dropped options.
      	(append_diag_options): Likewise to the passed-on options.
      	* opts.c (common_handle_option): Handle the new option.
      	* selftest-diagnostic.c
      	(test_diagnostic_context::test_diagnostic_context): Enable
      	show_labels_p.
      	* substring-locations.c: Include "gcc-rich-location.h".
      	(format_warning_n_va): Add "fmt_label" and "param_label" params
      	and use them as appropriate.
      	(format_warning_va): Add "fmt_label" and "param_label" params,
      	passing them on to format_warning_n_va.
      	(format_warning_at_substring): Likewise.
      	(format_warning_at_substring_n): Likewise.
      	* substring-locations.h (format_warning_va): Add "fmt_label" and
      	"param_label" params.
      	(format_warning_n_va): Likewise.
      	(format_warning_at_substring): Likewise.
      	(format_warning_at_substring_n): Likewise.
      	* toplev.c (general_init): Initialize global_dc->show_labels_p.
      
      gcc/testsuite/ChangeLog:
      	* g++.dg/diagnostic/aka3.C: New test.
      	* g++.dg/diagnostic/param-type-mismatch-2.C: Update expected
      	output to show range labels.
      	* g++.dg/diagnostic/param-type-mismatch.C: Likewise.
      	* g++.dg/plugin/plugin.exp (plugin_test_list): Add...
      	* g++.dg/plugin/show-template-tree-color-labels.C: New test.
      	* gcc.dg/bad-binary-ops.c: Update expected output to show range
      	labels.  Add an "aka" example.
      	* gcc.dg/cpp/pr66415-1.c: Update expected output to show range
      	labels.
      	* gcc.dg/format/diagnostic-ranges.c: Likewise.
      	* gcc.dg/format/pr72858.c: Likewise.
      	* gcc.dg/format/pr78498.c: Likewise.
      	* gcc.dg/param-type-mismatch.c: Add "-Wpointer-sign" to options.
      	Update expected output to show range labels.  Add examples of
      	-Wincompatible-pointer-types and -Wpointer-sign for parameters.
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c:
      	Update expected output to show range labels.
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c: Likewise.
      	(test_very_wide_line): Adjust so that label is at left-clipping
      	boundary.
      	(test_very_wide_line_2): New test.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
      	Update expected output to show range labels.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color.c: Likewise.
      	* gcc.dg/plugin/diagnostic-test-show-locus-no-labels.c: New test.
      	* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update
      	for new param to gcc_rich_location::add_expr.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range):
      	Add "label" param.
      	(test_show_locus): Add examples of labels to various tests.  Tweak
      	the "very wide_line" test case and duplicate it, to cover the
      	boundary values for clipping of labels against the left-margin.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
      	diagnostic-test-show-locus-no-labels.c.
      	* gcc.dg/pr69554-1.c: Update expected output to show range labels.
      	Update line numbers of dg-locus directives.
      	* gcc.dg/pr69627.c:  Update expected output to show range labels.
      	* lib/multiline.exp (proc _build_multiline_regex): Remove
      	special-case handling of lines with trailing '|'.
      
      libcpp/ChangeLog:
      	* include/line-map.h (struct location_range): Add "m_label" field.
      	(class rich_location): Add description of labels to leading
      	comment.
      	(rich_location::rich_location): Add "label" param, defaulting to
      	NULL.
      	(rich_location::add_range): Likewise.
      	(struct label_text): New struct.
      	(class range_label): New abstract base class.
      	* line-map.c (rich_location::rich_location): Add "label" param;
      	use it.
      	(rich_location::add_range): Likewise.
      
      From-SVN: r263564
      David Malcolm committed
  8. 09 Aug, 2018 1 commit
    • diagnostics: add line numbers to source (PR other/84889) · 56b61d7f
      This patch adds a left margin to the lines of source (and annotations)
      printed by diagnostic_show_locus, so that e.g. rather than:
      
      test.c: In function 'test':
      test.c:12:15: error: 'struct foo' has no member named 'm_bar'; did you mean 'bar'?
         return ptr->m_bar;
                     ^~~~~
                     bar
      
      we print:
      
      test.c: In function 'test':
      test.c:12:15: error: 'struct foo' has no member named 'm_bar'; did you mean 'bar'?
      12 |   return ptr->m_bar;
         |               ^~~~~
         |               bar
      
      Similarly, for a multiline case (in C++ this time), this:
      
      bad-binary-ops.C: In function 'int test_2()':
      bad-binary-ops.C:26:4: error: no match for 'operator+' (operand types are 's' and 't')
         return (some_function ()
                 ~~~~~~~~~~~~~~~~
          + some_other_function ());
          ^~~~~~~~~~~~~~~~~~~~~~~~
      
      becomes:
      
      bad-binary-ops.C: In function 'int test_2()':
      bad-binary-ops.C:26:4: error: no match for 'operator+' (operand types are 's' and 't')
      25 |   return (some_function ()
         |           ~~~~~~~~~~~~~~~~
      26 |    + some_other_function ());
         |    ^~~~~~~~~~~~~~~~~~~~~~~~
      
      I believe this slightly improves the readability of the output, in that it:
      - distinguishes between the user's source code vs the annotation lines
        that we're adding (the underlinings and fix-it hints here)
      - shows the line numbers in another place (potentially helpful for
        multiline diagnostics, where the user can see the line numbers directly,
        rather than have to figure them out relative to the caret: in the 2nd
        example, note how the diagnostic is reported at line 26, but the first
        line printed is actually line 25)
      
      I'm not sure that this is the precise format we want to go with [1], but
      I think it's an improvement over the status quo, and we're in stage 1
      of gcc 9, so there's plenty of time to shake out issues.
      
      I've turned it on by default; it can be disabled via
      -fno-diagnostics-show-line-numbers (it's also turned off in the testsuite, to
      avoid breaking numerous existing test cases).
      
      [1] Some possible variants:
        - maybe just "LL|" rather than "LL | "
        - maybe ':' rather than '|'
        - maybe we should have some leading indentation, to better split up
          the diagnostics visually via the left-hand column
        - etc
      
      gcc/ChangeLog:
      	PR other/84889
      	* common.opt (fdiagnostics-show-line-numbers): New option.
      	* diagnostic-show-locus.c (class layout): Add fields
      	"m_show_line_numbers_p" and "m_linenum_width";
      	(num_digits): New function.
      	(test_num_digits): New function.
      	(layout::layout): Initialize new fields.  Update m_x_offset
      	logic to handle any left margin.
      	(layout::print_source_line): Print line number when requested.
      	(layout::start_annotation_line): New member function.
      	(layout::print_annotation_line): Call it.
      	(layout::print_leading_fixits): Likewise.
      	(layout::print_trailing_fixits): Likewise.  Update calls to
      	move_to_column for new parameter.
      	(layout::get_x_bound_for_row): Add "add_left_margin" param and use
      	it to potentially call start_annotation_line.
      	(layout::show_ruler): Call start_annotation_line.
      	(selftest::test_line_numbers_multiline_range): New selftest.
      	(selftest::diagnostic_show_locus_c_tests): Call test_num_digits
      	and selftest::test_line_numbers_multiline_range.
      	* diagnostic.c (diagnostic_initialize): Initialize
      	show_line_numbers_p.
      	* diagnostic.h (struct diagnostic_context): Add field
      	"show_line_numbers_p".
      	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
      	-fno-diagnostics-show-line-numbers.
      	* dwarf2out.c (gen_producer_string): Add
      	OPT_fdiagnostics_show_line_numbers to the ignored options.
      	* lto-wrapper.c (merge_and_complain): Likewise to the "pick
      	one setting" options.
      	(append_compiler_options): Likewise to the dropped options.
      	(append_diag_options): Likewise to the passed-on options.
      	* opts.c (common_handle_option): Handle the new option.
      	* toplev.c (general_init): Set up global_dc->show_line_numbers_p.
      
      gcc/testsuite/ChangeLog:
      	PR other/84889
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c: New
      	test.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
      	New test.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new tests.
      	* lib/prune.exp: Add -fno-diagnostics-show-line-numbers to
      	TEST_ALWAYS_FLAGS.
      
      From-SVN: r263450
      David Malcolm committed
  9. 03 Jan, 2018 1 commit
  10. 05 May, 2017 4 commits
    • Convert CARET_LINE_MARGIN to const int · ba82e6b5
      gcc/ChangeLog:
      	* diagnostic.h (CARET_LINE_MARGIN): Convert from macro to const
      	int.
      
      From-SVN: r247666
      David Malcolm committed
    • Convert diagnostic_override_option_index from macro to inline function · 62a77bdf
      gcc/ChangeLog:
      	* diagnostic.h (diagnostic_override_option_index): Convert from
      	macro to inline function.
      
      From-SVN: r247665
      David Malcolm committed
    • Get rid of macros for diagnostic_report_current_module · 26d5ed6c
      diagnostic.h has a couple of macros (diagnostic_last_module_changed
      and diagnostic_set_last_module) which are only used within
      diagnostic_report_current_module.
      
      This patch eliminates the macros in favor of static functions within
      diagnostic.c.
      
      No functional change intended.
      
      gcc/ChangeLog:
      	* diagnostic.c (last_module_changed_p): New function.
      	(set_last_module): New function.
      	(diagnostic_report_current_module): Convert macro usage to
      	the above functions.
      	* diagnostic.h (diagnostic_context::last_module): Strengthen
      	from const line_map * to const line_map_ordinary *.
      	(diagnostic_last_module_changed): Delete macro.
      	(diagnostic_set_last_module): Delete macro.
      
      From-SVN: r247664
      David Malcolm committed
    • Eliminate report_diagnostic macro · 56d35585
      This patch eliminates the report_diagnostic macro, manually
      expanding it in all sites in the code.
      
      No functional change intended.
      
      gcc/c-family/ChangeLog:
      	* c-common.c (c_cpp_error): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      
      gcc/c/ChangeLog:
      	* c-decl.c (warn_defaults_to): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      	* c-errors.c (pedwarn_c99): Likewise.
      	(pedwarn_c90): Likewise.
      
      gcc/cp/ChangeLog:
      	* error.c (pedwarn_cxx98): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      
      gcc/ChangeLog:
      	* diagnostic.c (diagnostic_impl): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      	(diagnostic_n_impl_richloc): Likewise.
      	* diagnostic.h (report_diagnostic): Delete macro.
      	* rtl-error.c (diagnostic_for_asm): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      	* substring-locations.c (format_warning_va): Likewise.
      
      gcc/fortran/ChangeLog:
      	* cpp.c (cb_cpp_error): Replace report_diagnostic
      	with diagnostic_report_diagnostic.
      	* error.c (gfc_warning): Likewise.
      	(gfc_warning_now_at): Likewise.
      	(gfc_warning_now): Likewise.
      	(gfc_warning_internal): Likewise.
      	(gfc_error_now): Likewise.
      	(gfc_fatal_error): Likewise.
      	(gfc_error_opt): Likewise.
      	(gfc_internal_error): Likewise.
      
      From-SVN: r247663
      David Malcolm committed
  11. 01 Jan, 2017 1 commit
  12. 05 Dec, 2016 1 commit
    • diagnostic.c (diagnostic_check_max_errors): New, broken out of ... · d0ea9f0a
      	gcc/
      	* diagnostic.c (diagnostic_check_max_errors): New, broken out of ...
      	(diagnostic_action_after_output): ... here.
      	(diagnostic_report_diagnostic): Call it for non-notes.
      	* diagnostic.h (struct diagnostic_context): Make max_errors signed
      	int.
      	(diagnostic_check_max_errors): Declare.
      
      	gcc/fortran/
      	* error.c (gfc_warning_check): Call diagnostic_check_max_errors.
      	(gfc_error_check): Likewise.
      
      	gcc/testsuite/
      	* c-c++-common/fmax_errors.c: Check notes after last error are
      	emitted.
      
      From-SVN: r243254
      Nathan Sidwell committed
  13. 02 Sep, 2016 1 commit
    • Add -fdiagnostics-generate-patch · 717ebe91
      gcc/ChangeLog:
      	* common.opt (fdiagnostics-generate-patch): New option.
      	* diagnostic.c: Include "edit-context.h".
      	(diagnostic_initialize): Initialize context->edit_context_ptr.
      	(diagnostic_finish): Delete context->edit_context_ptr.
      	(diagnostic_report_diagnostic): Add fix-it hints from the
      	diagnostic to context->edit_context_ptr, if any.
      	* diagnostic.h (class edit_context): Add forward decl.
      	(struct diagnostic_context): Add field "edit_context_ptr".
      	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
      	-fdiagnostics-generate-patch.
      	(-fdiagnostics-generate-patch): New item.
      	* toplev.c: Include "edit-context.h".
      	(process_options): Set global_dc->edit_context_ptr to a new
      	edit_context if the options need one.
      	(toplev::main): Handle -fdiagnostics-generate-patch by using
      	global_dc->edit_context_ptr.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c: New
      	test case.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
      	diagnostic-test-show-locus-generate-patch.c to the sources
      	for diagnostic_plugin_test_show_locus.c.
      
      From-SVN: r239965
      David Malcolm committed
  14. 31 Aug, 2016 1 commit
    • Remove arbitrary limits from rich_location · b816477a
      This patch eliminates the hard-coded limits within rich_location
      (up to 3 ranges, up to 2 fixits).  The common case is still
      handled by embedding the values inside rich_location - it only
      uses dynamic allocation if these limits are exceeded, so
      creation of rich_location instances on the stack should still
      be fast.  This is implemented via a new container class,
      semi_embedded_vec <T, N>.
      
      gcc/ChangeLog:
      	* diagnostic-show-locus.c (colorizer::begin_state): Support more
      	than 3 ranges per diagnostic by alternating between color 1 and
      	color 2.
      	(layout::layout): Replace use of rich_location::MAX_RANGES
      	with richloc->get_num_locations ().
      	(layout::calculate_line_spans): Replace use of
      	rich_location::MAX_RANGES with m_layout_ranges.length ().
      	(layout::print_annotation_line): Handle arbitrary numbers of
      	ranges in caret-printing by defaulting to '^'.
      	(selftest::test_one_liner_many_fixits): New function.
      	(test_diagnostic_show_locus_one_liner): Call it.
      	* diagnostic.c (diagnostic_initialize): Update for renaming
      	of rich_location::MAX_RANGES to
      	rich_location::STATICALLY_ALLOCATED_RANGES.
      	* diagnostic.h (struct diagnostic_context): Likewise.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
      	(test_many_nested_locations): New function.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
      	(test_show_locus): Handle "test_many_nested_locations".
      
      libcpp/ChangeLog:
      	* include/line-map.h (class semi_embedded_vec): New class.
      	(semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec): New ctor.
      	(semi_embedded_vec<T, NUM_EMBEDDED>::~semi_embedded_vec): New
      	dtor.
      	(semi_embedded_vec<T, NUM_EMBEDDED>::operator[]): New methods.
      	(semi_embedded_vec<T, NUM_EMBEDDED>::push): New method.
      	(semi_embedded_vec<T, NUM_EMBEDDED>::truncate): New method.
      	(rich_location::get_num_locations): Reimplement in terms of
      	m_ranges.
      	(rich_location::get_range): Make non-inline.
      	(rich_location::get_num_fixit_hints): Reimplement in terms of
      	m_fixit_hints.
      	(rich_location::add_fixit): New function.
      	(rich_location::MAX_RANGES): Rename to...
      	(rich_location::STATICALLY_ALLOCATED_RANGES): ...this.
      	(rich_location::MAX_FIXIT_HINTS): Rename to...
      	(rich_location::STATICALLY_ALLOCATED_RANGES): ...this, and make
      	private.
      	(rich_location::m_num_ranges): Eliminate in favor of...
      	(rich_location::m_ranges): ...this, converting from a fixed-size
      	array to a semi_embedded_vec.
      	(rich_location::m_num_fixit_hints): Eliminate in favor of...
      	(rich_location::m_fixit_hints): ...this, converting from a
      	fixed-size array to a semi_embedded_vec.
      	* line-map.c (rich_location::rich_location): Update for above
      	changes.
      	(rich_location::~rich_location): Likewise.
      	(rich_location::get_loc): Likewise.
      	(rich_location::get_range): New methods.
      	(rich_location::add_range): Update for above changes.
      	(rich_location::set_range): Likewise.
      	(rich_location::add_fixit_insert): Likewise.
      	(rich_location::add_fixit_replace): Likewise.
      	(rich_location::get_last_fixit_hint): Likewise.
      	(rich_location::reject_impossible_fixit): Likewise.
      	(rich_location::add_fixit): New method.
      
      From-SVN: r239879
      David Malcolm committed
  15. 18 Aug, 2016 1 commit
    • Allow calling diagnostic_show_locus without a diagnostic_info · cc015f3a
      Much of diagnostic-show-locus.c currently expects a diagnostic_info *,
      but it only uses the rich_location and the diagnostic_t.
      
      Change the signature of diagnostic_show_locus from:
      
        void
        diagnostic_show_locus (diagnostic_context *,
                               const diagnostic_info *);
      
      to:
      
        void
        diagnostic_show_locus (diagnostic_context *,
                               rich_location *richloc,
                               diagnostic_t diagnostic_kind);
      
      so that it can be used for things other than diagnostics.
      
      Use this flexibility to add selftests for diagnostic_show_locus.
      
      gcc/c-family/ChangeLog:
      	* c-opts.c (c_diagnostic_finalizer): Update for change to
      	diagnostic_show_locus.
      
      gcc/ChangeLog:
      	* diagnostic-show-locus.c (colorizer::colorizer): Replace diagnostic
      	param with diagnostic_kind.
      	(class colorizer): Similarly replace field m_diagnostic with
      	m_diagnostic_kind.
      	(colorizer::colorizer): Replace diagnostic
      	param with diagnostic_kind.
      	(colorizer::begin_state): Update for above field change.
      	(layout::layout): Replace diagnostic param with rich_location *
      	and diagnostic_kind.
      	(diagnostic_show_locus): Replace diagnostic param with richloc
      	and diagnostic_kind.
      	(class selftest::test_diagnostic_context): New class.
      	(selftest::test_diagnostic_show_locus_unknown_location): New
      	function.
      	(selftest::test_one_liner_simple_caret): New function.
      	(selftest::test_one_liner_caret_and_range): New function.
      	(selftest::test_one_liner_multiple_carets_and_ranges): New
      	function.
      	(selftest::test_one_liner_fixit_remove): New function.
      	(selftest::test_one_liner_fixit_replace): New function.
      	(selftest::test_diagnostic_show_locus_one_liner): New function.
      	(selftest::diagnostic_show_locus_c_tests): Call the new test
      	functions.
      	* diagnostic.c (diagnostic_initialize): Initialize
      	colorize_source_p, show_ruler_p and parseable_fixits_p.
      	(default_diagnostic_finalizer): Update for change to
      	diagnostic_show_locus.
      	(diagnostic_append_note): Likewise.
      	* diagnostic.h (diagnostic_show_locus): Replace
      	const diagnostic_info * param with location * and diagnostic_t.
      
      gcc/fortran/ChangeLog:
      	* error.c (gfc_diagnostic_starter): Update for change to
      	diagnostic_show_locus.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
      	(custom_diagnostic_finalizer): Update for change to
      	diagnostic_show_locus.
      
      From-SVN: r239586
      David Malcolm committed
  16. 22 Jun, 2016 1 commit
    • Implement -fdiagnostics-parseable-fixits · a93eac6a
      gcc/ChangeLog:
      	* common.opt (fdiagnostics-parseable-fixits): New option.
      	* diagnostic.c: Include "selftest.h".
      	(print_escaped_string): New function.
      	(print_parseable_fixits): New function.
      	(diagnostic_report_diagnostic): Call print_parseable_fixits.
      	(selftest::assert_print_escaped_string): New function.
      	(ASSERT_PRINT_ESCAPED_STRING_STREQ): New macro.
      	(selftest::test_print_escaped_string): New function.
      	(selftest::test_print_parseable_fixits_none): New function.
      	(selftest::test_print_parseable_fixits_insert): New function.
      	(selftest::test_print_parseable_fixits_remove): New function.
      	(selftest::test_print_parseable_fixits_replace): New function.
      	(selftest::diagnostic_c_tests): New function.
      	* diagnostic.h (struct diagnostic_context): Add field
      	"parseable_fixits_p".
      	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
      	-fdiagnostics-parseable-fixits.
      	(-fdiagnostics-parseable-fixits): New option.
      	* opts.c (common_handle_option): Handle
      	-fdiagnostics-parseable-fixits.
      	* selftest-run-tests.c (selftest::run_tests): Call
      	selftest::diagnostic_c_tests.
      	* selftest.h (selftest::diagnostic_c_tests): New prototype.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c: New
      	file.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
      	diagnostic-test-show-locus-parseable-fixits.c to sources for
      	diagnostic_plugin_test_show_locus.c.
      	* lib/gcc-defs.exp (freeform_regexps): New global.
      	(dg-regexp): New function.
      	(handle-dg-regexps): New function.
      	* lib/gcc-dg.exp (cleanup-after-saved-dg-test): Reset
      	freeform_regexps to the empty list.
      	* lib/prune.exp (prune_gcc_output): Call handle-dg-regexps.
      
      libcpp/ChangeLog:
      	* include/line-map.h (fixit_hint::get_start_loc): New pure virtual
      	function.
      	(fixit_hint::maybe_get_end_loc): Likewise.
      	(fixit_insert::get_start_loc): New function, implementing
      	fixit_hint::get_start_loc.
      	(fixit_insert::maybe_get_end_loc): New function, implementing
      	fixit_hint::maybe_get_end_loc.
      	(fixit_remove::get_start_loc): New function, implementing
      	fixit_hint::get_start_loc.
      	(fixit_remove::maybe_get_end_loc): New function, implementing
      	fixit_hint::maybe_get_end_loc.
      	(fixit_replace::get_start_loc): New function, implementing
      	fixit_hint::get_start_loc.
      	(fixit_replace::maybe_get_end_loc): New function, implementing
      	fixit_hint::maybe_get_end_loc.
      
      From-SVN: r237712
      David Malcolm committed
  17. 09 Jun, 2016 1 commit
  18. 10 May, 2016 1 commit
    • Add debugging ruler to diagnostic-show-locus.c · f3352cab
      When debugging diagnostic-show-locus.c, it's invaluable to have a
      "ruler" showing column numbers.
      
      This patch adds in support via a new "show_ruler_p" flag within
      the diagnostic_context.  There's no direct way for end-users to enable
      this, but plugins can enable it by setting the flag, so the
      plugin that tests the diagnostic subsystem uses this to verify that
      the ruler is correctly printed.
      
      gcc/ChangeLog:
      	* diagnostic-show-locus.c (layout::layout): Call show_ruler
      	if show_ruler_p was set on the context.
      	(layout::show_ruler): New method.
      	* diagnostic.h (struct diagnostic_context): Add field
      	"show_ruler_p".
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
      	(test_very_wide_line): Add ruler to expected output.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color.c
      	(test_very_wide_line): Likewise.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
      	(test_show_locus): Within the handling of "test_very_wide_line",
      	enable show_ruler_p on the diagnostic context.
      
      From-SVN: r236080
      David Malcolm committed
  19. 09 Mar, 2016 1 commit
    • PR c++/70105: Defer location expansion until diagnostic_show_locus · 40499f81
      gcc/ChangeLog:
      	PR c/68473
      	PR c++/70105
      	* diagnostic-show-locus.c (layout_range::layout_range): Replace
      	location_range param with three const expanded_locations * and a
      	bool.
      	(layout::layout): Replace call to
      	rich_location::lazily_expand_location with get_expanded_location.
      	Extract the range and perform location expansion here, passing
      	the results to the layout_range ctor.
      	* diagnostic.c (source_range::debug): Delete.
      	* diagnostic.h (diagnostic_expand_location): Reimplement in terms
      	of rich_location::get_expanded_location.
      	* gcc-rich-location.c (get_range_for_expr): Delete.
      	(gcc_rich_location::add_expr): Reimplement to avoid the
      	rich_location::add_range overload that took a location_range,
      	passing a location_t instead.
      
      gcc/testsuite/ChangeLog:
      	PR c/68473
      	PR c++/70105
      	* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree):
      	Drop range information from call to inform_at_rich_loc.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range):
      	New.
      	(test_show_locus): Replace calls to rich_location::add_range with
      	calls to add_range.  Rewrite the tests that used the now-defunct
      	rich_location ctor taking a source_range.  Simplify other tests
      	by replacing calls to COMBINE_LOCATION_DATA with calls to
      	make_location.
      
      libcpp/ChangeLog:
      	PR c/68473
      	PR c++/70105
      	* include/line-map.h (source_range::debug): Delete.
      	(struct location_range): Update comment.  Replace
      	expanded_location fields "m_start", "m_finish", and "m_caret" with
      	a source_location field: "m_loc".
      	(class rich_location): Reword comment.
      	(rich_location::get_loc): Reimplement in terms of a new overloaded
      	variant which takes an unsigned int.
      	(rich_location::get_loc_addr): Delete.
      	(rich_location::add_range): Drop params "start" and "finish" in
      	favor of param "loc".  Drop overloaded variants taking a
      	source_range or location_range *.
      	(rich_location::lazily_expand_location): Delete in favor of...
      	(rich_location::get_expanded_location): New decl.
      	(rich_location::m_loc): Delete field.
      	(rich_location::m_column_override): New field.
      	* line-map.c (rich_location::rich_location):  Drop name of
      	line_maps * param.  Update initializations for deletion of field
      	"m_loc" and addition of field "m_column_override".  Reimplement
      	body as a call to add_range.  Delete overloaded variant taking a
      	source_range.
      	(rich_location::get_loc): New function.
      	(rich_location::lazily_expand_location): Delete in favor of...
      	(rich_location::get_expanded_location): New function.
      	(rich_location::override_column): Reimplement.
      	(rich_location::add_range): Drop params "start" and "finish" in
      	favor of param "loc".  Eliminate location expansion in favor of
      	simply storing loc.  Drop overloaded variants taking a
      	source_range or location_range *.
      	(rich_location::set_range): Eliminate location expansion.
      
      From-SVN: r234087
      David Malcolm committed
  20. 12 Feb, 2016 1 commit
    • PR other/69554: avoid excessive source printing for widely-separated locations · 876217ae
      gcc/ChangeLog:
      	PR other/69554
      	* diagnostic-show-locus.c (struct line_span): New struct.
      	(layout::get_first_line): Delete.
      	(layout::get_last_line): Delete.
      	(layout::get_num_line_spans): New member function.
      	(layout::get_line_span): Likewise.
      	(layout::print_heading_for_line_span_index_p): Likewise.
      	(layout::get_expanded_location): Likewise.
      	(layout::calculate_line_spans): Likewise.
      	(layout::m_first_line): Delete.
      	(layout::m_last_line): Delete.
      	(layout::m_line_spans): New field.
      	(layout::layout): Update comment.  Replace m_first_line and
      	m_last_line with m_line_spans, replacing their initialization
      	with a call to calculate_line_spans.
      	(diagnostic_show_locus): When printing source lines and
      	annotations, rather than looping over a single span
      	of lines, instead loop over each line_span within
      	the layout, with an inner loop over the lines within them.
      	Call the context's start_span callback when changing line spans.
      	* diagnostic.c (diagnostic_initialize): Initialize start_span.
      	(diagnostic_build_prefix): Break out the building of the location
      	part of the string into...
      	(diagnostic_get_location_text): ...this new function, rewriting
      	it from nested ternary expressions to a sequence of "if"
      	statements.
      	(default_diagnostic_start_span_fn): New function.
      	* diagnostic.h (diagnostic_start_span_fn): New typedef.
      	(diagnostic_context::start_span): New field.
      	(default_diagnostic_start_span_fn): New prototype.
      
      gcc/fortran/ChangeLog:
      	PR other/69554
      	* error.c (gfc_diagnostic_start_span): New function.
      	(gfc_diagnostics_init): Initialize global_dc's start_span.
      
      gcc/testsuite/ChangeLog:
      	PR other/69554
      	* gcc.dg/pr69554-1.c: New test.
      	* gfortran.dg/pr69554-1.F90: New test.
      	* gfortran.dg/pr69554-2.F90: New test.
      	* lib/gcc-dg.exp (proc dg-locus): New function.
      	* lib/gfortran-dg.exp (proc gfortran-dg-test): Update comment to
      	distinguish between the caret-printing and non-caret-printing
      	cases.  If caret-printing has been explicitly enabled, bail out
      	without attempting to fix up the output.
      
      From-SVN: r233386
      David Malcolm committed
  21. 26 Jan, 2016 1 commit
    • PR other/69006: fix extra newlines after diagnostics · 01e1dea3
      gcc/c-family/ChangeLog:
      	PR other/69006
      	* c-opts.c (c_diagnostic_finalizer): Replace invocation of
      	pp_newline_and_flush with pp_flush.
      
      gcc/cp/ChangeLog:
      	PR other/69006
      	* error.c (print_instantiation_partial_context_line): Add missing
      	newlines from output for the t == NULL case.
      	(print_instantiation_partial_context): Remove call to pp_newline.
      
      gcc/ChangeLog:
      	PR other/69006
      	* diagnostic-show-locus.c (layout::print_source_line): Replace
      	call to pp_newline with call to layout::print_newline.
      	(layout::print_annotation_line): Likewise.
      	(layout::move_to_column): Likewise.
      	(layout::print_any_fixits): After printing any fixits, print a
      	trailing newline, if necessary.
      	(layout::print_newline): New method, resetting any colorization
      	before a newline.
      	(diagnostic_show_locus): Move the pp_newline to before the
      	early bailout.  Remove dummy block enclosing the layout instance.
      	* diagnostic.c (default_diagnostic_finalizer): Replace invocation
      	of pp_newline_and_flush with pp_flush.
      	(diagnostic_append_note): Delete use of pp_newline.
      	(diagnostic_append_note_at_rich_loc): Delete.
      	* diagnostic.h (diagnostic_append_note_at_rich_loc): Delete.
      	* pretty-print.h (output_buffer_append_r): Reset buff->line_length
      	when newline characters are added to the buffer.
      
      gcc/fortran/ChangeLog:
      	PR other/69006
      	* error.c (gfc_diagnostic_starter): Delete use of pp_newline.
      
      gcc/testsuite/ChangeLog:
      	PR other/69006
      	* g++.dg/ext/timevar1.C: Add dg-allow-blank-lines-in-output
      	directive.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color.c: Update
      	expected multiline output to reflect the colorization being
      	disabled before newlines.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
      	(custom_diagnostic_finalizer): Replace call to
      	pp_newline_and_flush with call to pp_flush.
      	* gcc.dg/unroll-2.c: Add dg-allow-blank-lines-in-output directive.
      	* gfortran.dg/implicit_class_1.f90: Likewise.
      	* lib/gcc-dg.exp (allow_blank_lines): New global.
      	(dg-allow-blank-lines-in-output): New procedure.
      	(gcc-dg-prune): Complain about blank lines in the output, unless
      	dg-allow-blank-lines-in-output was called.
      	* lib/multiline.exp (_build_multiline_regex): Only support
      	arbitrary followup text for non-blank-lines, not for blank lines.
      
      From-SVN: r232837
      David Malcolm committed
  22. 04 Jan, 2016 1 commit
  23. 06 Nov, 2015 1 commit
    • Reimplement diagnostic_show_locus, introducing rich_location classes · 8a645150
      gcc/ChangeLog:
      	* diagnostic-color.c (color_dict): Eliminate "caret"; add "range1"
      	and "range2".
      	(parse_gcc_colors): Update comment to describe default GCC_COLORS.
      	* diagnostic-core.h (warning_at_rich_loc): New declaration.
      	(error_at_rich_loc): New declaration.
      	(permerror_at_rich_loc): New declaration.
      	(inform_at_rich_loc): New declaration.
      	* diagnostic-show-locus.c (adjust_line): Delete.
      	(struct point_state): New struct.
      	(class colorizer): New class.
      	(class layout_point): New class.
      	(class layout_range): New class.
      	(struct line_bounds): New.
      	(class layout): New class.
      	(colorizer::colorizer): New ctor.
      	(colorizer::~colorizer): New dtor.
      	(layout::layout): New ctor.
      	(layout::print_source_line): New method.
      	(layout::print_annotation_line): New method.
      	(layout::get_state_at_point): New method.
      	(layout::get_x_bound_for_row): New method.
      	(diagnostic_show_locus): Reimplement in terms of class layout.
      	(diagnostic_print_caret_line): Delete.
      	* diagnostic.c (diagnostic_initialize): Replace
      	MAX_LOCATIONS_PER_MESSAGE with rich_location::MAX_RANGES.
      	(diagnostic_set_info_translated): Convert param from location_t
      	to rich_location *.  Eliminate calls to set_location on the
      	message in favor of storing the rich_location ptr there.
      	(diagnostic_set_info): Convert param from location_t to
      	rich_location *.
      	(diagnostic_build_prefix): Break out array into...
      	(diagnostic_kind_color): New variable.
      	(diagnostic_get_color_for_kind): New function.
      	(diagnostic_report_diagnostic): Colorize the option_text
      	using the color for the severity.
      	(diagnostic_append_note): Update for change in signature of
      	diagnostic_set_info.
      	(diagnostic_append_note_at_rich_loc): New function.
      	(emit_diagnostic): Update for change in signature of
      	diagnostic_set_info.
      	(inform): Likewise.
      	(inform_at_rich_loc): New function.
      	(inform_n): Update for change in signature of diagnostic_set_info.
      	(warning): Likewise.
      	(warning_at): Likewise.
      	(warning_at_rich_loc): New function.
      	(warning_n): Update for change in signature of diagnostic_set_info.
      	(pedwarn): Likewise.
      	(permerror): Likewise.
      	(permerror_at_rich_loc): New function.
      	(error): Update for change in signature of diagnostic_set_info.
      	(error_n): Likewise.
      	(error_at): Likewise.
      	(error_at_rich_loc): New function.
      	(sorry): Update for change in signature of diagnostic_set_info.
      	(fatal_error): Likewise.
      	(internal_error): Likewise.
      	(internal_error_no_backtrace): Likewise.
      	(source_range::debug): New function.
      	* diagnostic.h (struct diagnostic_info): Eliminate field
      	"override_column".  Add field "richloc".
      	(struct diagnostic_context): Add field "colorize_source_p".
      	(diagnostic_override_column): Delete.
      	(diagnostic_set_info): Convert param from location_t to
      	rich_location *.
      	(diagnostic_set_info_translated): Likewise.
      	(diagnostic_append_note_at_rich_loc): New function.
      	(diagnostic_num_locations): New function.
      	(diagnostic_expand_location): Get the location from the
      	rich_location.
      	(diagnostic_print_caret_line): Delete.
      	(diagnostic_get_color_for_kind): New declaration.
      	* genmatch.c (linemap_client_expand_location_to_spelling_point): New.
      	(error_cb): Update for change in signature of "error" callback.
      	(fatal_at): Likewise.
      	(warning_at): Likewise.
      	* input.c (linemap_client_expand_location_to_spelling_point): New.
      	* pretty-print.c (text_info::set_range): New method.
      	(text_info::get_location): New method.
      	* pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): Eliminate this macro.
      	(struct text_info): Eliminate "locations" array in favor of
      	"m_richloc", a rich_location *.
      	(textinfo::set_location): Add a "caret_p" param, and reimplement
      	in terms of a call to set_range.
      	(textinfo::get_location): Eliminate inline implementation in favor of
      	an out-of-line reimplementation.
      	(textinfo::set_range): New method.
      	* rtl-error.c (diagnostic_for_asm): Update for change in signature
      	of diagnostic_set_info.
      	* tree-diagnostic.c (default_tree_printer): Update for new
      	"caret_p" param for textinfo::set_location.
      	* tree-pretty-print.c (percent_K_format): Likewise.
      
      gcc/c-family/ChangeLog:
      	* c-common.c (c_cpp_error): Convert parameter from location_t to
      	rich_location *.  Eliminate the "column_override" parameter and
      	the call to diagnostic_override_column.
      	Update the "done_lexing" clause to set range 0
      	on the rich_location, rather than overwriting a location_t.
      	* c-common.h (c_cpp_error): Convert parameter from location_t to
      	rich_location *.  Eliminate the "column_override" parameter.
      
      gcc/c/ChangeLog:
      	* c-decl.c (warn_defaults_to): Update for change in signature
      	of diagnostic_set_info.
      	* c-errors.c (pedwarn_c99): Likewise.
      	(pedwarn_c90): Likewise.
      	* c-objc-common.c (c_tree_printer): Update for new "caret_p" param
      	for textinfo::set_location.
      
      gcc/cp/ChangeLog:
      	* error.c (cp_printer): Update for new "caret_p" param for
      	textinfo::set_location.
      	(pedwarn_cxx98): Update for change in signature of
      	diagnostic_set_info.
      
      gcc/fortran/ChangeLog:
      	* cpp.c (cb_cpp_error): Convert parameter from location_t to
      	rich_location *.  Eliminate the "column_override" parameter.
      	* error.c (gfc_warning): Update for change in signature of
      	diagnostic_set_info.
      	(gfc_format_decoder): Update handling of %C/%L for changes
      	to struct text_info.
      	(gfc_diagnostic_starter): Use richloc when determining whether to
      	print one locus or two.  When handling a location that will
      	involve a call to diagnostic_show_locus, only attempt to print the
      	locus for the primary location, and don't call into
      	diagnostic_print_caret_line.
      	(gfc_warning_now_at): Update for change in signature of
      	diagnostic_set_info.
      	(gfc_warning_now): Likewise.
      	(gfc_error_now): Likewise.
      	(gfc_fatal_error): Likewise.
      	(gfc_error): Likewise.
      	(gfc_internal_error): Likewise.
      
      gcc/testsuite/ChangeLog:
      	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c: New file.
      	* gcc.dg/plugin/diagnostic-test-show-locus-color.c: New file.
      	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: New file.
      	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.
      	* lib/gcc-dg.exp: Load multiline.exp.
      
      libcpp/ChangeLog:
      	* errors.c (cpp_diagnostic): Update for change in signature
      	of "error" callback.
      	(cpp_diagnostic_with_line): Likewise, calling override_column
      	on the rich_location.
      	* include/cpplib.h (struct cpp_callbacks): Within "error"
      	callback, convert param from source_location to rich_location *,
      	and drop column_override param.
      	* include/line-map.h (struct source_range): New struct.
      	(struct location_range): New struct.
      	(class rich_location): New class.
      	(linemap_client_expand_location_to_spelling_point): New declaration.
      	* line-map.c (rich_location::rich_location): New ctors.
      	(rich_location::lazily_expand_location): New method.
      	(rich_location::override_column): New method.
      	(rich_location::add_range): New methods.
      	(rich_location::set_range): New method.
      
      From-SVN: r229884
      David Malcolm committed
  24. 14 Sep, 2015 1 commit
    • The flag diagnostic_context::some_warnings_are_errors controls whether to give... · 0d179691
      The flag diagnostic_context::some_warnings_are_errors controls whether
      to give the message "all warnings being treated as errors". However, when
      warnings are buffered and then discarded, this flag is not reset. It turns
      out we do not need this flag at all, since we already count explicitly how
      many warnings were converted into errors, and this number is kept up to
      date for the buffered diagnostics used by Fortran.
      
      gcc/ChangeLog:
      
      2015-09-14  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/67460
      	* diagnostic.c (diagnostic_initialize): Do not set
      	some_warnings_are_errors.
      	(diagnostic_finish): Use DK_WERROR count instead.
      	(diagnostic_report_diagnostic): Do not set
      	some_warnings_are_errors.
      	* diagnostic.h (struct diagnostic_context): Remove
      	some_warnings_are_errors.
      
      gcc/testsuite/ChangeLog:
      
      2015-09-14  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/67460
      	* gfortran.dg/pr67460.f90: New test.
      
      From-SVN: r227760
      Manuel López-Ibáñez committed
  25. 16 May, 2015 1 commit
    • re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$… · 2a2703a2
      re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color)
      
      gcc/fortran/ChangeLog:
      
      2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      
      	Replace all calls to gfc_notify_std_1 with gfc_notify_std and
      	gfc_warning_1 with gfc_warning.
      	* decl.c (gfc_verify_c_interop_param): Here.
      	* resolve.c (resolve_branch): Here.
      	(resolve_fl_derived): Here.
      	* dependency.c (gfc_check_argument_var_dependency):
      	* scanner.c (preprocessor_line): Use gfc_warning_now_at. Fix line
      	counter and locations before and after warning.
      	* gfortran.h (gfc_warning_1, gfc_warning_now_1, gfc_notify_std_1):
      	Delete.
      	(gfc_warning_now_at): Declare.
      	* error.c (gfc_warning_1): Delete.
      	(gfc_notify_std_1): Delete.
      	(gfc_warning_now_1): Delete.
      	(gfc_format_decoder): Handle two locations.
      	(gfc_diagnostic_build_prefix): Rename as
      	gfc_diagnostic_build_kind_prefix.
      	(gfc_diagnostic_build_locus_prefix): Take an expanded_location
      	instead of diagnostic_info.
      	(gfc_diagnostic_build_locus_prefix): Add overload that takes two
      	expanded_location.
      	(gfc_diagnostic_starter): Handle two locations.
      	(gfc_warning_now_at): New.
      	(gfc_diagnostics_init): Initialize caret_chars array.
      	(gfc_diagnostics_finish): Reset caret_chars array to default.
      
      gcc/cp/ChangeLog:
      
      2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* error.c (cp_diagnostic_starter): Use diagnostic_location
      	function.
      	(cp_print_error_function): Likewise.
      	(cp_printer): Replace locus pointer with accessor function.
      
      gcc/c/ChangeLog:
      
      2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* c-objc-common.c (c_tree_printer): Replace locus pointer with
      	accessor function.
      
      gcc/ChangeLog:
      
      2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* tree-pretty-print.c (percent_K_format): Replace locus pointer
      	with accessor function.
      	* tree-diagnostic.c (diagnostic_report_current_function): Use
      	diagnostic_location function.
      	(maybe_unwind_expanded_macro_loc): Likewise.
      	(virt_loc_aware_diagnostic_finalizer): Likewise.
      	(default_tree_printer): Replace locus pointer with accessor function.
      	* diagnostic.c (diagnostic_initialize): Initialize caret_chars array.
      	(diagnostic_set_info_translated): Initialize second location.
      	(diagnostic_build_prefix): Use CARET_LINE_MARGIN.
      	(diagnostic_show_locus): Handle two locations. Call
      	diagnostic_print_caret_line.
      	(diagnostic_print_caret_line): New.
      	(default_diagnostic_starter): Use diagnostic_location function.
      	(diagnostic_report_diagnostic): Use diagnostic_location function.
      	(verbatim): Do not set text.locus.
      	* diagnostic.h (struct diagnostic_info): Remove location field.
      	(struct diagnostic_context): Make caret_chars an array of two.
      	(diagnostic_location): New inline.
      	(diagnostic_expand_location): Handle two locations.
      	(diagnostic_same_line): New inline.
      	(diagnostic_print_caret_line): Declare.
      	(CARET_LINE_MARGIN): New constant.
      	* pretty-print.c (pp_printf): Do not set text.locus.
      	(pp_verbatim): Do not set text.locus.
      	* pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): New constant.
      	(struct text_info): Replace locus pointer with locations
      	array. Add accessor functions.
      
      gcc/testsuite/ChangeLog:
      
      2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* lib/gfortran-dg.exp: Update regex to handle two locations for
      	the same diagnostic without caret.
      	* gfortran.dg/badline.f: Test also that line numbers are correct
      	before and after "left but not entered" warning.
      
      From-SVN: r223237
      Manuel López-Ibáñez committed
  26. 05 Jan, 2015 1 commit
  27. 11 Dec, 2014 2 commits
    • re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$… · c4100eae
      re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color)
      
      gcc/ChangeLog:
      
      2014-12-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* diagnostic.c (diagnostic_action_after_output): Make it extern.
      	Take diagnostic_t argument instead of diagnostic_info. Count also
      	DK_WERROR towards max_errors.
      	(diagnostic_report_diagnostic): Update call according to the above.
      	(error_recursion): Likewise.
      	* diagnostic.h (diagnostic_action_after_output): Declare.
      	* pretty-print.c (pp_formatted_text_data): Delete.
      	(pp_append_r): Call output_buffer_append_r.
      	(pp_formatted_text): Call output_buffer_formatted_text.
      	(pp_last_position_in_text): Call output_buffer_last_position_in_text.
      	* pretty-print.h (output_buffer_formatted_text): New.
      	(output_buffer_append_r): New.
      	(output_buffer_last_position_in_text): New.
      
      gcc/fortran/ChangeLog:
      
      2014-12-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* error.c (pp_error_buffer): New static variable.
      	(pp_warning_buffer): Make it a pointer.
      	(gfc_output_buffer_empty_p): New.
      	(gfc_error_init_1): Call gfc_buffer_error.
      	(gfc_buffer_error): Do not use pp_warning_buffer.flush_p as the
      	buffered_p flag.
      	(gfc_clear_warning): Likewise.
      	(gfc_warning_check): Call gfc_clear_warning. Only check the new
      	pp_warning_buffer if the old warning_buffer was empty. Call
      	diagnostic_action_after_output.
      	(gfc_error_1): Renamed from gfc_error.
      	(gfc_error): New.
      	(gfc_clear_error): Clear also pp_error_buffer.
      	(gfc_error_flag_test): Check also pp_error_buffer.
      	(gfc_error_check): Likewise. Only check the new pp_error_buffer
      	if the old error_buffer was empty.
      	(gfc_move_output_buffer_from_to): New.
      	(gfc_push_error): Use it here. Take also an output_buffer as argument.
      	(gfc_pop_error): Likewise.
      	(gfc_free_error): Likewise.
      	(gfc_diagnostics_init): Use XNEW and placement-new to init
      	pp_error_buffer and pp_warning_buffer. Set flush_p to false for
      	both pp_warning_buffer and pp_error_buffer.
      
      	* Update gfc_push_error, gfc_pop_error and gfc_free_error calls
      	according to the above changes.
      	* Use gfc_error_1 for all gfc_error calls that use multiple
      	locations.
      	* Use %qs instead of '%s' for many gfc_error calls.
      
      From-SVN: r218627
      Manuel López-Ibáñez committed
    • diagnostic.c (get_terminal_width): Renamed from · c9db45aa
      2014-12-11  Tobias Burnus  <burnus@net-b.de>
                  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      gcc/
              * diagnostic.c (get_terminal_width): Renamed from
              * getenv_columns,
              removed static, and additionally use ioctl to get width.
              (diagnostic_set_caret_max_width): Update call.
              * diagnostic.h (get_terminal_width): Add prototype.
              * opts.c (print_specific_help): Use it for x_help_columns.
              * doc/invoke.texi (fdiagnostics-show-caret): Document how the
              width is set.
      
      gcc/fortran/
              * error.c (gfc_get_terminal_width): Renamed from
              get_terminal_width and use same-named common function.
              (gfc_error_init_1): Update call.
      
      
      Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
      
      From-SVN: r218619
      Tobias Burnus committed
  28. 04 Dec, 2014 2 commits
    • error.c (gfc_diagnostic_build_locus_prefix): Use diagnostic_expand_location. · 99abe958
      gcc/fortran/ChangeLog:
      
      2014-12-05  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	* error.c (gfc_diagnostic_build_locus_prefix): Use
      	diagnostic_expand_location.
      
      gcc/ChangeLog:
      
      2014-12-05  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	* diagnostic.h (diagnostic_expand_location): New inline function.
      	* diagnostic.c (diagnostic_build_prefix): Use it.
      	(diagnostic_show_locus): Likewise.
      
      From-SVN: r218409
      Manuel López-Ibáñez committed
    • diagnostic.c (diagnostic_color_init): New. · 97aa8bb6
      gcc/ChangeLog:
      
      2014-12-04  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	* diagnostic.c (diagnostic_color_init): New.
      	* diagnostic.h: Declare.
      	* gcc.c (driver::global_initializations): Use it.
      	(driver_handle_option): Handle -fdiagnostics-color_.
      	* toplev.c: Do not include diagnostic-color.h.
      	(process_options): Do not initialize color diagnostics here.
      	* common.opt (fdiagnostics-color=): Add Driver.
      	* opts-global.c (init_options_once): Initialize color here.
      	* opts.c (common_handle_option): Use diagnostics_color_init.
      	* diagnostic-color.h: Fix comment.
      
      From-SVN: r218406
      Manuel López-Ibáñez committed
  29. 21 Aug, 2014 1 commit
    • re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$… · fbecdc83
      re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color)
      
      gcc/ChangeLog:
      
      2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* diagnostic.c: Set default caret.
      	(diagnostic_show_locus): Use it. Tell pretty-printer that a new
      	line is needed.
      	* diagnostic.h (struct diagnostic_context):
      
      
      gcc/fortran/ChangeLog:
      
      2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      	* error.c (gfc_diagnostic_build_locus_prefix): New function.
      	(gfc_diagnostic_starter): Follow Fortran FE diagnostics.
      	(gfc_diagnostic_finalizer): Do not call default finalizer.
      
      From-SVN: r214251
      Manuel López-Ibáñez committed
  30. 15 Aug, 2014 1 commit
    • re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$… · 8e54f6d3
      re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color)
      
      2014-08-15  Manuel López-Ibáñez  <manu@gcc.gnu.org>
      
      	PR fortran/44054
      gcc/
      	* diagnostic.c (build_message_string): Make it extern.
      	* diagnostic.h (build_message_string): Make it extern.
      c-family/
      	* c-format.c: Handle Fortran flags.
      fortran/
      	* gfortran.h: Define GCC_DIAG_STYLE.
      	(gfc_diagnostics_init,gfc_warning_cmdline): Declare.
      	* trans-array.c: Include gfortran.h before diagnostic-core.h.
      	* trans-expr.c: Likewise.
      	* trans-openmp.c: Likewise.
      	* trans-const.c: Likewise.
      	* trans.c: Likewise.
      	* trans-types.c: Likewise.
      	* f95-lang.c: Likewise.
      	* trans-decl.c: Likewise.
      	* trans-io.c: Likewise.
      	* trans-intrinsic.c: Likewise.
      	* error.c: Include diagnostic.h and diagnostic-color.h.
      	(gfc_diagnostic_build_prefix): New.
      	(gfc_diagnostic_starter): New.
      	(gfc_diagnostic_finalizer): New.
      	(gfc_warning_cmdline): New.
      	(gfc_diagnostics_init): New.
      	* gfc-diagnostic.def: New.
      	* options.c (gfc_init_options): Call gfc_diagnostics_init.
      	(gfc_post_options): Use gfc_warning_cmdline.
      
      From-SVN: r214024
      Manuel López-Ibáñez committed
  31. 23 Jan, 2014 1 commit
    • PR preprocessor/58580 - preprocessor goes OOM with warning for zero literals · 7ecc3eb9
      In this problem report, the compiler is fed a (bogus) translation unit
      in which some literals contain bytes whose value is zero.  The
      preprocessor detects that and proceeds to emit diagnostics for that
      king of bogus literals.  But then when the diagnostics machinery
      re-reads the input file again to display the bogus literals with a
      caret, it attempts to calculate the length of each of the lines it got
      using fgets.  The line length calculation is done using strlen.  But
      that doesn't work well when the content of the line can have several
      zero bytes.  The result is that the read_line never sees the end of
      the line because strlen repeatedly reports that the line ends before
      the end-of-line character; so read_line thinks its buffer for reading
      the line is too small; it thus increases the buffer, leading to a huge
      memory consumption and disaster.
      
      Here is what this patch does.
      
      location_get_source_line is modified to return the length of a source
      line that can now contain bytes with zero value.
      diagnostic_show_locus() is then modified to consider that a line can
      have characters of value zero, and so just shows a white space when
      instructed to display one of these characters.
      
      Additionally location_get_source_line is modified to avoid re-reading
      each and every line from the beginning of the file until it reaches
      the line number N that it is instructed to get; this was leading to
      annoying quadratic behaviour when reading adjacent lines near the end
      of (big) files.  So a cache is now associated to the file opened in
      text mode.  When the content of the file is read, that content is
      stashed in the file cache.  That file cache is searched for line
      delimiters.  A number of line positions are saved in the cache and a
      number of file caches are kept in memory.  That way when
      location_get_source_line is asked to read line N + 1, it just has to
      start reading from line N that it has already read.
      
      libcpp/ChangeLog:
      
      	* include/line-map.h (linemap_get_file_highest_location): Declare
      	new function.
      	* line-map.c (linemap_get_file_highest_location): Define it.
      
      gcc/ChangeLog:
      
      	* input.h (location_get_source_line): Take an additional line_size
      	parameter.
      	(void diagnostics_file_cache_fini): Declare new function.
      	* input.c (struct fcache): New type.
      	(fcache_tab_size, fcache_buffer_size, fcache_line_record_size):
      	New static constants.
      	(diagnostic_file_cache_init, total_lines_num)
      	(lookup_file_in_cache_tab, evicted_cache_tab_entry)
      	(add_file_to_cache_tab, lookup_or_add_file_to_cache_tab)
      	(needs_read, needs_grow, maybe_grow, read_data, maybe_read_data)
      	(get_next_line, read_next_line, goto_next_line, read_line_num):
      	New static function definitions.
      	(diagnostic_file_cache_fini): New function.
      	(location_get_source_line): Take an additional output line_len
      	parameter.  Re-write using lookup_or_add_file_to_cache_tab and
      	read_line_num.
      	* diagnostic.c (diagnostic_finish): Call
      	diagnostic_file_cache_fini.
      	(adjust_line): Take an additional input parameter for the length
      	of the line, rather than calculating it with strlen.
      	(diagnostic_show_locus): Adjust the use of
      	location_get_source_line and adjust_line with respect to their new
      	signature.  While displaying a line now, do not stop at the first
      	null byte.  Rather, display the zero byte as a space and keep
      	going until we reach the size of the line.
      	* Makefile.in: Add vec.o to OBJS-libcommon
      
      gcc/testsuite/ChangeLog:
      
      	* c-c++-common/cpp/warning-zero-in-literals-1.c: New test file.
      
      Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
      
      From-SVN: r206957
      Dodji Seketeli committed
  32. 02 Jan, 2014 1 commit
  33. 10 Dec, 2013 1 commit
    • cgraph.h (cgraph_node_set_iterator, [...]): Remove typedef. · 84562394
      	* gcc/cgraph.h (cgraph_node_set_iterator, varpool_node_set_iterator):
      	Remove typedef.
      	(cgraph_inline_failed_enum, cgraph_inline_failed_t): Remove typedef and
      	rename to cgraph_inline_failed_t.
      	* gcc/tree-ssa-alias.h (ao_ref_s, ao_ref): Remove typedef and rename
      	to ao_ref.
      	* gcc/reload.h (reg_equivs_s, reg_equivs_t): Remove typedef and rename
      	to reg_equivs_t.
      	* gcc/conditions.h (CC_STATUS): Remove typedef.
      	* gcc/bitmap.h (bitmap_obstack): Remove typedef.
      	(bitmap_element_def, bitmap_element): Remove typedef and rename to
      	bitmap_element.
      	(bitmap_head_def, bitmap_head): Remove typedef and rename to
      	bitmap_head.
      	(bitmap_iterator): Remove typedef.
      	* gcc/target.h (cumulative_args_t, print_switch_type,
      	secondary_reload_info): Remove typedef.
      	* gcc/dwarf2out.h (dw_cfi_oprnd_struct, dw_cfi_oprnd): Remove
      	dw_cfi_oprnd_struct alias.
      	(dw_cfi_struct, dw_cfi_node): Remove typedef and rename to dw_cfi_node.
      	(dw_fde_struct, dw_fde_node): Remove typedef and rename to dw_fde_node.
      	(cfa_loc, dw_cfa_location): Remove typedef and rename to
      	dw_cfa_location.
      	(dw_vec_struct, dw_vec_const): Remove typedef and rename to
      	dw_vec_const.
      	(dw_val_struct, dw_val_node): Remove typedef and rename to dw_val_node.
      	(dw_loc_descr_struct, dw_loc_descr_node): Remove typedef and rename to
      	dw_loc_descr_node.
      	* gcc/params.h (param_info, compiler_param): Remove typedef.
      	* gcc/opts.h (cl_deferred_param): Remove typedef.
      	* gcc/sreal.h (sreal): Remove typedef.
      	* gcc/ddg.h (dep_type, dep_data_type): Remove typedef.
      	* gcc/graphite-clast-to-gimple.h (cloog_prog_clast, bb_pbb_def): Remove
      	typedef.
      	* gcc/lto-streamer.h (lto_decl_stream_e_t, lto_encoder_entry,
      	lto_symtab_encoder_iterator, res_pair): Remove typedef.
      	* gcc/tree-affine.h (affine_tree_combination, aff_tree): Remove typedef
      	and rename to aff_tree.
      	* gcc/sched-int.h (region): Remove typedef.
      	* gcc/diagnostic.h (diagnostic_info,
      	diagnostic_classification_change_t): Remove typedef.
      	* gcc/tree-ssa-loop.h (affine_iv_d): Remove typedef and rename to
      	affine_iv.
      	* gcc/sbitmap.h (sbitmap_iterator): Remove typedef.
      	* gcc/ssa-iterators.h (immediate_use_iterator_d, imm_use_iterator):
      	Remove typedef and rename to imm_use_iterator.
      	(ssa_operand_iterator_d, ssa_op_iter): Remove typedef and rename to
      	ssa_op_iter.
      	* gcc/ggc-internal.h (ggc_statistics): Remove typedef.
      	* gcc/cselib.h (cselib_val_struct, cselib_val): Remove typedef and
      	rename to cselib_val.
      	* gcc/tree-core.h (alias_pair): Remove typedef.
      	(constructor_elt_d, constructor_elt): Remove typedef and rename to
      	constructor_elt.
      	(ssa_use_operand_d, ssa_use_operand_t): Remove typedef and rename to
      	ssa_use_operand_t.
      	* gcc/graphite-sese-to-poly.h (base_alias_pair): Remove typedef.
      	* gcc/tree-data-ref.h (conflict_function): Remove typedef.
      	* gcc/tree-inline.h (copy_body_data): Remove typedef.
      	* gcc/ipa-inline.h (condition, size_time_entry, inline_param_summary_t,
      	edge_growth_cache_entry): Remove typedef.
      	* gcc/regrename.h (operand_rr_info, insn_rr_info): Remove typedef.
      	* gcc/gimple-iterator.h (gimple_stmt_iterator_d, gimple_stmt_iterator):
      	Remove typedef and rename to gimple_stmt_iterator.
      	* gcc/basic-block.h (ce_if_block, ce_if_block_t): Remove typedef and
      	rename to ce_if_block.
      	(edge_iterator): Remove typedef.
      	* gcc/ipa-prop.h (ipa_agg_jf_item, ipa_agg_jf_item_t): Remove typedef
      	and rename to ipa_agg_jf_item.
      	(ipa_agg_jump_function_t, ipa_param_descriptor_t, ipa_node_params_t,
      	ipa_parm_adjustment_t): Remove typedef.
      	(ipa_jump_func, ipa_jump_func_t): Remove typedef and rename to
      	ipa_jump_func.
      	(ipa_edge_args, ipa_edge_args_t): Remove typedef and rename to
      	ipa_edge_args.
      	* gcc/gcov-io.h (gcov_bucket_type): Remove typedef.
      	(gcov_working_set_info, gcov_working_set_t): Remove typedef and rename
      	to gcov_working_set_t.
      	* gcc/ira-int.h (minmax_set_iterator, ira_allocno_iterator,
      	ira_object_iterator, ira_allocno_object_iterator, ira_pref_iterator,
      	ira_copy_iterator, ira_object_conflict_iterator): Remove typedef.
      	* gcc/tree-iterator.h (tree_stmt_iterator): Remove typedef.
      	* gcc/rtl.h (addr_diff_vec_flags, mem_attrs, reg_attrs,
      	replace_label_data): Remove typedef.
      	(rtunion_def, rtunion): Remove typedef and rename to rtunion.
      	* gcc/hard-reg-set.h (hard_reg_set_iterator): Remove typedef.
      	* gcc/sel-sched-ir.h (_list_iterator, sel_global_bb_info_def,
      	sel_region_bb_info_def, succ_iterator): Remove typedef.
      	(deps_where_def, deps_where_t): Remove typedef and rename to
      	deps_where_t.
      	* gcc/coretypes.h: Adapt forward declarations.
      	* gcc/tree-scalar-evolution.h: Likewise.
      	* gcc/tree-ssa-address.h: Likewise.
      	* gcc/tree-ssa-operands.h: Likewise.
      	* gcc/function.h: Likewise.
      	* gcc/config/frv/frv-protos.h: Likewise.
      	* gcc/targhooks.h: Likewise.
      	* gcc/basic_block.h: Likewise.
      	* gcc/rtl.def: Adapt documentation.
      	* gcc/doc/tm.texi: Likewise.
      	* gcc/ipa-cp.c: Adapt uses.
      	* gcc/bitmap.c: Likewise.
      	* gcc/dwarf2out.c: Likewise.
      	* gcc/target.def: Likewise.
      	* gcc/ipa-inline-analysis.c: Likewise.
      	* gcc/dwarf2cfi.c: Likewise.
      	* gcc/tree-ssa-loop-ivopts.c: Likewise.
      	* gcc/lto-cgraph.c: Likewise.
      	* gcc/config/frv/frv.c: Likewise.
      	* gcc/ifcvt.c: Likewise.
      	* gcc/ipa-prop.c: Likewise.
      
      From-SVN: r205863
      Oleg Endo committed
  34. 05 Aug, 2013 1 commit
    • pretty-print.h (pp_base): Remove. · b066401f
      	* pretty-print.h (pp_base): Remove.  Adjust dependent macros.
      	* diagnostic.h (diagnostic_flush_buffer): Adjust.
      	* pretty-print.c (pp_formatted_text_data): Likewise.
      	(pp_indent): Rename from pp_base_indent.
      	(pp_format): Rename from pp_base_format.
      	(pp_output_formatted_text): Rename from pp_base_output_formatted_text.
      	(pp_format_verbatim): Rename from pp_base_format_verbatim.
      	(pp_flush): Rename from pp_base_flush.
      	(pp_set_line_maximum_length): Rename from
      	pp_base_set_line_maximum_length.
      	(pp_clear_output_area): Rename from pp_base_clear_output_area.
      	(pp_set_prefix): Rename from pp_base_set_prefix.
      	(pp_destroy_prefix): Rename from pp_base_destroy_prefix.
      	(pp_emit_prefix): Rename from pp_base_emit_prefix.
      	(pp_append_text): Rename from pp_base_append_text.
      	(pp_formatted_text): Rename from pp_base_formatted_text.
      	(pp_last_position_in_text): Rename from pp_base_last_position_in_text.
      	(pp_remaining_character_count_for_line): Rename from
      	pp_base_remaining_character_count_for_line.
      	(pp_newline): Rename from pp_base_newline.
      	(pp_character): Rename from pp_base_character.
      	(pp_string): Rename from pp_base_string.
      	(pp_maybe_space): Rename from pp_base_maybe_space.
      	* asan.c (asan_pp_string): Adjust.
      	(asan_emit_stack_protection): Likewise.
      	(asan_add_global): Likewise.
      	* sched-vis.c (str_pattern_slim): Adjust pretty printer function call.
      	* tree-mudflap.c (mf_varname_tree): Likewise.
      	* tree-pretty-print.c (pp_tree_identifier): Rename from
      	pp_base_tree_identifier.
      	* tree-pretty-print.h (pp_tree_identifier): Remove macro definition.
      	Declare as function.
      
      c/
      	* c-objc-common.c (c_initialize_diagnostics): Don't call pp_base.
      
      c-family/
      	* c-pretty-print.h (c_pretty_printer): Derive from pretty_printer.
      	(pp_base): Remove.
      	(pp_c_base): Likewise.  Adjust users.
      	* c-pretty-print.c (pp_c_maybe_whitespace): Adjust.
      	(pp_c_whitespace): Do not call pp_base.
      	(pp_c_left_paren): Likewise.
      	(pp_c_right_paren): Likewise.
      	(pp_c_left_brace): Likewise.
      	(pp_c_right_brace): Likewise.
      	(pp_c_left_bracket): Likewise.
      	(pp_c_right_bracket): Likewise.
      	(pp_c_dot): Likewise.
      	(pp_c_ampersand): Likewise.
      	(pp_c_star): Likewise.
      	(pp_c_arrow): Likewise.
      	(pp_c_semicolon): Likewise.
      	(pp_c_complement): Likewise.
      	(pp_c_exclamation): Likewise.
      	(pp_c_direct_declarator): Likewise.
      	(pp_c_ws_string): Likewise.
      	(pp_c_identifier): Likewise.
      	(pp_c_statement): Likewise.
      	(print_c_tree): Likewise.
      
      cp/
      	* cxx-pretty-print.h (pp_c_base): Remove.
      	(cxx_pretty_printer): Derive from c_pretty_printer.
      	Adjust macros using pp_c_base.
      	* cp-objcp-common.c (cxx_initialize_diagnostics): Do not call pp_base.
      	* cxx-pretty-print.c (pp_cxx_nonconsecutive_character): Likewise.
      	(pp_cxx_colon_colon): Likewise.
      	(pp_cxx_separate_with): Likewise.
      	(pp_cxx_storage_class_specifier): Do not call pp_c_base.
      	(pp_cxx_expression_list): Likewise.
      	(pp_cxx_space_for_pointer_operator): Likewise.
      	(pp_cxx_init_declarator): Likewise.
      	(pp_cxx_call_argument_list): Likewise.
      	(pp_cxx_constant): Likewise.
      	(pp_cxx_postfix_expression): Likewise.
      	(pp_cxx_new_expression): Likewise.
      	(pp_cxx_unary_expression): Likewise.
      	(pp_cxx_cast_expression): Likewise.
      	(pp_cxx_conditional_expression): Likewise.
      	(pp_cxx_assignment_expression): Likewise.
      	(pp_cxx_expression): Likewise.
      	(pp_cxx_function_specifier): Likewise.
      	(pp_cxx_decl_specifier_seq): Likewise.
      	(pp_cxx_simple_type_specifier): Likewise.
      	(pp_cxx_type_specifier_seq): Likewise.
      	(pp_cxx_ptr_operator): Likewise.
      	(pp_cxx_parameter_declaration_clause): Likewise.
      	(pp_cxx_direct_declarator): Likewise.
      	(pp_cxx_direct_abstract_declarator): Likewise.
      	(pp_cxx_type_id): Likewise.
      	(pp_cxx_statement): Likewise.
      	(pp_cxx_pretty_printer_init): Tidy.
      	* error.c (init_error): Do not use pp_base.
      	(dump_aggr_type): Likewise.
      	(dump_type_prefix): Likewise.
      	(dump_type_suffix): Likewise.
      	(dump_global_iord): Likewise.
      	(dump_decl): Likewise.
      	(dump_function_decl): Likewise.
      	(dump_ref_qualifier): Likewise.
      	(reinit_cxx_pp): Likewise.
      	(decl_as_dwarf_string): Likewise.
      	(lang_decl_dwarf_name): Likewise.
      	(type_to_string): Likewise.
      	(cv_to_string): Likewise.
      	(cxx_print_error_function): Likewise.
      	(cp_diagnostic_starter): Likewise.
      	(cp_diagnostic_finalizer): Likewise.
      	(cp_print_error_function): Likewise.
      	(print_instantiation_context): Likewise.
      	(cp_printer): Likewise.
      
      From-SVN: r201479
      Gabriel Dos Reis committed
  35. 26 Apr, 2013 1 commit