gcc/gcc/diagnostic.h

591 lines
21 KiB
C
Raw Permalink Normal View History

/* Various declarations for language-independent diagnostics subroutines.
2022-01-03 10:42:10 +01:00
Copyright (C) 2000-2022 Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
Makefile.in, [...]: replace "GNU CC" with "GCC". * Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, builtin-types.def, builtins.c, builtins.def, c-aux-info.c, c-common.c, c-common.def, c-common.h, c-convert.c, c-decl.c, c-dump.c, c-dump.h, c-errors.c, c-format.c, c-lang.c, c-lex.c, c-lex.h, c-parse.in, c-pragma.c, c-pragma.h, c-semantics.c, c-tree.h, c-typeck.c, caller-save.c, calls.c, collect2.c, collect2.h, combine.c, conditions.h, config.gcc, configure.frag, configure.in, conflict.c, convert.c, convert.h, cppspec.c, crtstuff.c, cse.c, cselib.c, cselib.h, dbxout.c, dbxout.h, defaults.h, dependence.c, df.c, df.h, diagnostic.c, diagnostic.h, doloop.c, dominance.c, dwarf.h, dwarf2.h, dwarf2asm.c, dwarf2asm.h, dwarf2out.c, dwarf2out.h, dwarfout.c, emit-rtl.c, errors.c, errors.h, except.c, except.h, exgettext, explow.c, expmed.c, expr.c, expr.h, final.c, fixproto, flags.h, flow.c, fold-const.c, fp-test.c, function.c, function.h, gbl-ctors.h, gcc.c, gcc.h, gcc.hlp, gccspec.c, gcov-io.h, gcse.c, genattr.c, genattrtab.c, gencheck.c, gencodes.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, genmultilib, genopinit.c, genoutput.c, genpeep.c, genrecog.c, gensupport.c, gensupport.h, ggc-callbacks.c, ggc-common.c, ggc-none.c, ggc-page.c, ggc-simple.c, ggc.h, global.c, graph.c, graph.h, gthr-aix.h, gthr-dce.h, gthr-posix.h, gthr-rtems.h, gthr-single.h, gthr-solaris.h, gthr-vxworks.h, gthr-win32.h, gthr.h, haifa-sched.c, halfpic.c, halfpic.h, hard-reg-set.h, hwint.h, ifcvt.c, input.h, insn-addr.h, integrate.c, integrate.h, jump.c, lcm.c, libgcc2.c, libgcc2.h, lists.c, local-alloc.c, loop.c, loop.h, machmode.def, machmode.h, main.c, mbchar.c, mbchar.h, mips-tdump.c, mips-tfile.c, mklibgcc.in, mkmap-flat.awk, mkmap-symver.awk, optabs.c, output.h, params.c, params.def, params.h, predict.c, predict.def, predict.h, prefix.c, prefix.h, print-rtl.c, print-tree.c, profile.c, protoize.c, read-rtl.c, real.c, real.h, recog.c, recog.h, reg-stack.c, regclass.c, regmove.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, reorg.c, resource.c, resource.h, rtl.c, rtl.def, rtl.h, rtlanal.c, sbitmap.c, sbitmap.h, sched-deps.c, sched-ebb.c, sched-int.h, sched-rgn.c, sched-vis.c, sdbout.c, sdbout.h, sibcall.c, simplify-rtx.c, ssa-ccp.c, ssa-dce.c, ssa.c, ssa.h, stmt.c, stor-layout.c, stringpool.c, system.h, timevar.c, timevar.def, timevar.h, tlink.c, toplev.c, toplev.h, tree.c, tree.def, tree.h, tsystem.h, unroll.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h, unwind.inc, varasm.c, varray.c, varray.h, xcoffout.c, xcoffout.h: replace "GNU CC" with "GCC". From-SVN: r45105
2001-08-22 16:35:51 +02:00
This file is part of GCC.
Makefile.in, [...]: replace "GNU CC" with "GCC". * Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, builtin-types.def, builtins.c, builtins.def, c-aux-info.c, c-common.c, c-common.def, c-common.h, c-convert.c, c-decl.c, c-dump.c, c-dump.h, c-errors.c, c-format.c, c-lang.c, c-lex.c, c-lex.h, c-parse.in, c-pragma.c, c-pragma.h, c-semantics.c, c-tree.h, c-typeck.c, caller-save.c, calls.c, collect2.c, collect2.h, combine.c, conditions.h, config.gcc, configure.frag, configure.in, conflict.c, convert.c, convert.h, cppspec.c, crtstuff.c, cse.c, cselib.c, cselib.h, dbxout.c, dbxout.h, defaults.h, dependence.c, df.c, df.h, diagnostic.c, diagnostic.h, doloop.c, dominance.c, dwarf.h, dwarf2.h, dwarf2asm.c, dwarf2asm.h, dwarf2out.c, dwarf2out.h, dwarfout.c, emit-rtl.c, errors.c, errors.h, except.c, except.h, exgettext, explow.c, expmed.c, expr.c, expr.h, final.c, fixproto, flags.h, flow.c, fold-const.c, fp-test.c, function.c, function.h, gbl-ctors.h, gcc.c, gcc.h, gcc.hlp, gccspec.c, gcov-io.h, gcse.c, genattr.c, genattrtab.c, gencheck.c, gencodes.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, genmultilib, genopinit.c, genoutput.c, genpeep.c, genrecog.c, gensupport.c, gensupport.h, ggc-callbacks.c, ggc-common.c, ggc-none.c, ggc-page.c, ggc-simple.c, ggc.h, global.c, graph.c, graph.h, gthr-aix.h, gthr-dce.h, gthr-posix.h, gthr-rtems.h, gthr-single.h, gthr-solaris.h, gthr-vxworks.h, gthr-win32.h, gthr.h, haifa-sched.c, halfpic.c, halfpic.h, hard-reg-set.h, hwint.h, ifcvt.c, input.h, insn-addr.h, integrate.c, integrate.h, jump.c, lcm.c, libgcc2.c, libgcc2.h, lists.c, local-alloc.c, loop.c, loop.h, machmode.def, machmode.h, main.c, mbchar.c, mbchar.h, mips-tdump.c, mips-tfile.c, mklibgcc.in, mkmap-flat.awk, mkmap-symver.awk, optabs.c, output.h, params.c, params.def, params.h, predict.c, predict.def, predict.h, prefix.c, prefix.h, print-rtl.c, print-tree.c, profile.c, protoize.c, read-rtl.c, real.c, real.h, recog.c, recog.h, reg-stack.c, regclass.c, regmove.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, reorg.c, resource.c, resource.h, rtl.c, rtl.def, rtl.h, rtlanal.c, sbitmap.c, sbitmap.h, sched-deps.c, sched-ebb.c, sched-int.h, sched-rgn.c, sched-vis.c, sdbout.c, sdbout.h, sibcall.c, simplify-rtx.c, ssa-ccp.c, ssa-dce.c, ssa.c, ssa.h, stmt.c, stor-layout.c, stringpool.c, system.h, timevar.c, timevar.def, timevar.h, tlink.c, toplev.c, toplev.h, tree.c, tree.def, tree.h, tsystem.h, unroll.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h, unwind.inc, varasm.c, varray.c, varray.h, xcoffout.c, xcoffout.h: replace "GNU CC" with "GCC". From-SVN: r45105
2001-08-22 16:35:51 +02:00
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Makefile.in, [...]: replace "GNU CC" with "GCC". * Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, builtin-types.def, builtins.c, builtins.def, c-aux-info.c, c-common.c, c-common.def, c-common.h, c-convert.c, c-decl.c, c-dump.c, c-dump.h, c-errors.c, c-format.c, c-lang.c, c-lex.c, c-lex.h, c-parse.in, c-pragma.c, c-pragma.h, c-semantics.c, c-tree.h, c-typeck.c, caller-save.c, calls.c, collect2.c, collect2.h, combine.c, conditions.h, config.gcc, configure.frag, configure.in, conflict.c, convert.c, convert.h, cppspec.c, crtstuff.c, cse.c, cselib.c, cselib.h, dbxout.c, dbxout.h, defaults.h, dependence.c, df.c, df.h, diagnostic.c, diagnostic.h, doloop.c, dominance.c, dwarf.h, dwarf2.h, dwarf2asm.c, dwarf2asm.h, dwarf2out.c, dwarf2out.h, dwarfout.c, emit-rtl.c, errors.c, errors.h, except.c, except.h, exgettext, explow.c, expmed.c, expr.c, expr.h, final.c, fixproto, flags.h, flow.c, fold-const.c, fp-test.c, function.c, function.h, gbl-ctors.h, gcc.c, gcc.h, gcc.hlp, gccspec.c, gcov-io.h, gcse.c, genattr.c, genattrtab.c, gencheck.c, gencodes.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, genmultilib, genopinit.c, genoutput.c, genpeep.c, genrecog.c, gensupport.c, gensupport.h, ggc-callbacks.c, ggc-common.c, ggc-none.c, ggc-page.c, ggc-simple.c, ggc.h, global.c, graph.c, graph.h, gthr-aix.h, gthr-dce.h, gthr-posix.h, gthr-rtems.h, gthr-single.h, gthr-solaris.h, gthr-vxworks.h, gthr-win32.h, gthr.h, haifa-sched.c, halfpic.c, halfpic.h, hard-reg-set.h, hwint.h, ifcvt.c, input.h, insn-addr.h, integrate.c, integrate.h, jump.c, lcm.c, libgcc2.c, libgcc2.h, lists.c, local-alloc.c, loop.c, loop.h, machmode.def, machmode.h, main.c, mbchar.c, mbchar.h, mips-tdump.c, mips-tfile.c, mklibgcc.in, mkmap-flat.awk, mkmap-symver.awk, optabs.c, output.h, params.c, params.def, params.h, predict.c, predict.def, predict.h, prefix.c, prefix.h, print-rtl.c, print-tree.c, profile.c, protoize.c, read-rtl.c, real.c, real.h, recog.c, recog.h, reg-stack.c, regclass.c, regmove.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, reorg.c, resource.c, resource.h, rtl.c, rtl.def, rtl.h, rtlanal.c, sbitmap.c, sbitmap.h, sched-deps.c, sched-ebb.c, sched-int.h, sched-rgn.c, sched-vis.c, sdbout.c, sdbout.h, sibcall.c, simplify-rtx.c, ssa-ccp.c, ssa-dce.c, ssa.c, ssa.h, stmt.c, stor-layout.c, stringpool.c, system.h, timevar.c, timevar.def, timevar.h, tlink.c, toplev.c, toplev.h, tree.c, tree.def, tree.h, tsystem.h, unroll.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h, unwind.inc, varasm.c, varray.c, varray.h, xcoffout.c, xcoffout.h: replace "GNU CC" with "GCC". From-SVN: r45105
2001-08-22 16:35:51 +02:00
version.
Makefile.in, [...]: replace "GNU CC" with "GCC". * Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, builtin-types.def, builtins.c, builtins.def, c-aux-info.c, c-common.c, c-common.def, c-common.h, c-convert.c, c-decl.c, c-dump.c, c-dump.h, c-errors.c, c-format.c, c-lang.c, c-lex.c, c-lex.h, c-parse.in, c-pragma.c, c-pragma.h, c-semantics.c, c-tree.h, c-typeck.c, caller-save.c, calls.c, collect2.c, collect2.h, combine.c, conditions.h, config.gcc, configure.frag, configure.in, conflict.c, convert.c, convert.h, cppspec.c, crtstuff.c, cse.c, cselib.c, cselib.h, dbxout.c, dbxout.h, defaults.h, dependence.c, df.c, df.h, diagnostic.c, diagnostic.h, doloop.c, dominance.c, dwarf.h, dwarf2.h, dwarf2asm.c, dwarf2asm.h, dwarf2out.c, dwarf2out.h, dwarfout.c, emit-rtl.c, errors.c, errors.h, except.c, except.h, exgettext, explow.c, expmed.c, expr.c, expr.h, final.c, fixproto, flags.h, flow.c, fold-const.c, fp-test.c, function.c, function.h, gbl-ctors.h, gcc.c, gcc.h, gcc.hlp, gccspec.c, gcov-io.h, gcse.c, genattr.c, genattrtab.c, gencheck.c, gencodes.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, genmultilib, genopinit.c, genoutput.c, genpeep.c, genrecog.c, gensupport.c, gensupport.h, ggc-callbacks.c, ggc-common.c, ggc-none.c, ggc-page.c, ggc-simple.c, ggc.h, global.c, graph.c, graph.h, gthr-aix.h, gthr-dce.h, gthr-posix.h, gthr-rtems.h, gthr-single.h, gthr-solaris.h, gthr-vxworks.h, gthr-win32.h, gthr.h, haifa-sched.c, halfpic.c, halfpic.h, hard-reg-set.h, hwint.h, ifcvt.c, input.h, insn-addr.h, integrate.c, integrate.h, jump.c, lcm.c, libgcc2.c, libgcc2.h, lists.c, local-alloc.c, loop.c, loop.h, machmode.def, machmode.h, main.c, mbchar.c, mbchar.h, mips-tdump.c, mips-tfile.c, mklibgcc.in, mkmap-flat.awk, mkmap-symver.awk, optabs.c, output.h, params.c, params.def, params.h, predict.c, predict.def, predict.h, prefix.c, prefix.h, print-rtl.c, print-tree.c, profile.c, protoize.c, read-rtl.c, real.c, real.h, recog.c, recog.h, reg-stack.c, regclass.c, regmove.c, regrename.c, regs.h, reload.c, reload.h, reload1.c, reorg.c, resource.c, resource.h, rtl.c, rtl.def, rtl.h, rtlanal.c, sbitmap.c, sbitmap.h, sched-deps.c, sched-ebb.c, sched-int.h, sched-rgn.c, sched-vis.c, sdbout.c, sdbout.h, sibcall.c, simplify-rtx.c, ssa-ccp.c, ssa-dce.c, ssa.c, ssa.h, stmt.c, stor-layout.c, stringpool.c, system.h, timevar.c, timevar.def, timevar.h, tlink.c, toplev.c, toplev.h, tree.c, tree.def, tree.h, tsystem.h, unroll.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h, unwind.inc, varasm.c, varray.c, varray.h, xcoffout.c, xcoffout.h: replace "GNU CC" with "GCC". From-SVN: r45105
2001-08-22 16:35:51 +02:00
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_DIAGNOSTIC_H
#define GCC_DIAGNOSTIC_H
Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. * calls.c (try_to_integrate): Don't use xxx_with_decl. (expand_call): Likewise. * dwarfout.c (output_reg_number): Likewise. * expr.c (expand_expr): Likewise. * function.c (assign_temp): Likewise. (uninitialized_vars_warning): Likewise. (setjmp_args_warning): Likewise. (expand_function_end): Likewise. * stmt.c (fixup_gotos): Likewise. (warn_about_unused_variables): Likewise. (expand_end_bindings): Likewise. * stor-layout.c (layout_decl): Likewise. (place_field): Likewise. * toplev.c (check_global_declarations): Likewise. (rest_of_handle_inlining): Likewise. (default_tree_printer): New function. (general_init): Initialize diagnostic machinery before routing signals to the ICE machinery. Set default tree printer. * toplev.h (pedwarn_with_decl): Remove declaration. (warning_with_decl): Likewise. (error_with_decl): Likewise. (pedwarn): Remove attribute for the time being. * tree-inline.c (expand_call_inline): Don't use xxx_with_decl. * varasm.c (named_section): Likewise. (make_decl_rtl): Likewise. (assemble_variable): Likewise. (merge_weak): Likewise. (declare_weak): Likewise. * diagnostic.h: Move non-diagnostic stuff into pretty-print.h. * diagnostic.c: Move non-diagnostic stuff into pretty-print.c. (format_with_decl): Remove. (diagnostic_for_decl): Likewise. (pedwarn_with_decl): Likewise. (warning_with_decl): Likewise. (error_with_decl): Likewise. (diagnostic_initialize): Adjust. (diagnostic_count_diagnostic): Likewise. (announce_function): Likewise. (lhd_print_error_function): Likewise. (diagnostic_report_current_module): Likewise. (default_diagnostic_starter): Likewise. (diagnostic_report_diagnostic): Likewise. (default_diagnostic_finalizer): Likewise. (verbatim): Likewise. (error): Likewise. (warning): Likewise. * opts.c (common_handle_option): Likewise. * pretty-print.c: New file. * c-pretty-print.h (pp_base): Override. * c-pretty-print.c: Adjust use of macros throughout. (pp_buffer): New macro. (pp_newline): Likewise. * c-objc-common.c (c_tree_printer): Adjust prototype. Tidy. * Makefile.in (DIAGNOSTIC_H): New variable. (c-errors.o): Use it. (c-objc-common.o): Likewise. (c-common.o): Likewise. (c-opts.o): Likewise. (c-format.o): Likewise. (diagnostic.o): Likewise. (opts.o): Likewise. (toplev.o): Likewise. (rtl-error.o): Likewise. (dwarf2out.o): Likewise. (jump.o): Likewise. (pretty-print.o): New rule. cp/ * Make-lang.in (cp/error.o): Depend on DIAGNOSTIC_H. * error.c: Use the new pretty-printer fraamework. From-SVN: r69773
2003-07-25 11:52:32 +02:00
#include "pretty-print.h"
diagnostic-core.h: New. * diagnostic-core.h: New. Contents moved from diagnostic.h and toplev.h. * diagnostic.c: Don't include toplev.h. (progname): Define. Moved from toplev.c. (seen_error): New function. * diagnostic.h: Include diagnostic-core.h. (diagnostic_t, emit_diagnostic): Don't declare here. * toplev.c (progname): Move to toplev.c. (emit_debug_global_declarations, compile_file, finalize, do_compile, toplev_main): Use seen_error. * toplev.h: Include diagnostic-core.h. (trim_filename, GCC_DIAG_STYLE, ATTRIBUTE_GCC_DIAG, internal_error, warning, warning_at, error, error_n, error_at, fatal_error, pedwarn, permerror, sorry, inform, inform_n, verbatim, fnotice, progname): Move to diagnostic-core.h. * builtins.c: Include diagnostic-core.h instead of diagnostic.h. (expand_builtin_expect): Use seen_error. * c-decl.c: Include diagnostic-core.h instead of diagnostic.h. (c_make_fname_decl, c_write_global_declarations): Use seen_error. * c-format.c: Include diagnostic-core.h instead of diagnostic.h. * c-gimplify.c: Include diagnostic-core.h instead of diagnostic.h. * c-lang.c: Include diagnostic-core.h instead of diagnostic.h. * c-lex.c (c_lex_with_flags, interpret_float): Don't increment errorcount for errors. * c-opts.c (c_common_finish): Use seen_error. * cgraph.c: Include diagnostic-core.h instead of diagnostic.h. * cgraphunit.c (verify_cgraph_node, verify_cgraph, cgraph_output_pending_asms, cgraph_optimize): Use seen_error. * coverage.c: Include diagnostic-core.h instead of diagnostic.h. (get_coverage_counts): Use seen_error. * dwarf2out.c (dwarf2out_finish): Use seen_error. * gimplify.c (gimplify_var_or_parm_decl, gimple_push_cleanup, gimplify_body): Use seen_error. * ipa-inline.c (cgraph_early_inlining): Use seen_error. * ipa-pure-const.c (gate_pure_const): Use seen_error. * ipa-reference.c (gate_reference): Use seen_error. * jump.c: Include diagnostic-core.h instead of diagnostic.h. * lambda-code.c: Include diagnostic-core.h instead of diagnostic.h. * lto-cgraph.c: Include diagnostic-core.h instead of diagnostic.h. * lto-compress.c: Include diagnostic-core.h instead of diagnostic.h. * lto-section-in.c: Include diagnostic-core.h instead of diagnostic.h. * lto-streamer-out.c: Include diagnostic-core.h instead of diagnostic.h. * lto-streamer.c: Include diagnostic-core.h instead of diagnostic.h. (gate_lto_out): Use seen_error. * matrix-reorg.c: Include diagnostic-core.h instead of diagnostic.h. * omega.c: Include diagnostic-core.h instead of diagnostic.h. * omp-low.c: Include diagnostic-core.h instead of diagnostic.h. (gate_expand_omp, lower_omp_1): Use seen_error. * passes.c: Include diagnostic-core.h instead of diagnostic.h. (rest_of_decl_compilation, rest_of_type_compilation, gate_rest_of_compilation, ipa_write_summaries): Use seen_error. * tree-cfg.c (label_to_block_fn): Use seen_error. * tree-inline.c (optimize_inline_calls): Use seen_error. * tree-mudflap.c (mudflap_finish_file): Use seen_error. * tree-optimize.c (gate_all_optimizations, gate_all_early_local_passes, gate_all_early_optimizations): Use seen_error. * tree-ssa-structalias.c (gate_ipa_pta): Use seen_error. * varpool.c: Include diagnostic-core.h instead of diagnostic.h. (varpool_remove_unreferenced_decls, varpool_assemble_pending_decls): Use seen_error. * Makefile.in (DIAGNOSTIC_CORE_H): Define. (TOPLEV_H, DIAGNOSTIC_H): Update. (c-decl.o, c-lang.o, c-format.o, lto-compress.o, lto-cgraph.o, lto-streamer-out.o, lto-section-in.o, lto-streamer.o, c-gimplify.o, omp-low.o, omega.o, diagnostic.o, passes.o, builtins.o, jump.o, cgraph.o, varpool.o, matrix-reorg.o, coverage.o, lambda-code.o): Update dependencies. cp: * call.c: Include diagnostic-core.h instead of diagnostic.h. * cp-lang.c: Don't include diagnostic.h * name-lookup.c: Include diagnostic-core.h instead of diagnostic.h. (cp_emit_debug_info_for_using): Use seen_error. * optimize.c: Include diagnostic-core.h instead of diagnostic.h. * parser.c: Include diagnostic-core.h instead of diagnostic.h. * pt.c (iterative_hash_template_arg): Use seen_error. * repo.c: Include diagnostic-core.h instead of diagnostic.h. * typeck2.c: Include diagnostic-core.h instead of diagnostic.h. * Make-lang.in (cp/cp-lang.o, cp/typeck2.o, cp/call.o, cp/repo.o, cp/optimize.o, cp/parser.o, cp/name-lookup.o): Update dependencies. lto: * lto.c: Include diagnostic-core.h instead of diagnostic.h. (read_cgraph_and_symbols, lto_main): Use seen_error. * Make-lang.in (lto/lto.o): Update dependencies. objc: * objc-act.c: Include diagnostic-core.h instead of diagnostic.h. * Make-lang.in (objc/objc-act.o): Update dependencies. From-SVN: r159947
2010-05-27 22:16:07 +02:00
#include "diagnostic-core.h"
diagnostics: Support conversion of tabs to spaces [PR49973] [PR86904] Supports conversion of tabs to spaces when outputting diagnostics. Also adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to control how the column number is output, thereby resolving the two PRs. gcc/c-family/ChangeLog: PR other/86904 * c-indentation.c (should_warn_for_misleading_indentation): Get global tabstop from the new source. * c-opts.c (c_common_handle_option): Remove handling of -ftabstop, which is now a common option. * c.opt: Likewise. gcc/ChangeLog: PR preprocessor/49973 PR other/86904 * common.opt: Handle -ftabstop here instead of in c-family options. Add -fdiagnostics-column-unit= and -fdiagnostics-column-origin= options. * opts.c (common_handle_option): Handle the new options. * diagnostic-format-json.cc (json_from_expanded_location): Add diagnostic_context argument. Use it to convert column numbers as per the new options. (json_from_location_range): Likewise. (json_from_fixit_hint): Likewise. (json_end_diagnostic): Pass the new context argument to helper functions above. Add "column-origin" field to the output. (test_unknown_location): Add the new context argument to calls to helper functions. (test_bad_endpoints): Likewise. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Support tabstop parameter. (layout_point::layout_point): Make use of class exploc_with_display_col. (layout_range::layout_range): Likewise. (struct line_bounds): Clarify that the units are now always display columns. Rename members accordingly. Add constructor. (layout::print_source_line): Add support for tab expansion. (make_range): Adapt to class layout_range changes. (layout::maybe_add_location_range): Likewise. (layout::layout): Adapt to class exploc_with_display_col changes. (layout::calculate_x_offset_display): Support tabstop parameter. (layout::print_annotation_line): Adapt to struct line_bounds changes. (layout::print_line): Likewise. (line_label::line_label): Add diagnostic_context argument. (get_affected_range): Likewise. (get_printed_columns): Likewise. (layout::print_any_labels): Adapt to struct line_label changes. (class correction): Add m_tabstop member. (correction::correction): Add tabstop argument. (correction::compute_display_cols): Use m_tabstop. (class line_corrections): Add m_context member. (line_corrections::line_corrections): Add diagnostic_context argument. (line_corrections::add_hint): Use m_context to handle tabstops. (layout::print_trailing_fixits): Adapt to class line_corrections changes. (test_layout_x_offset_display_utf8): Support tabstop parameter. (test_layout_x_offset_display_tab): New selftest. (test_one_liner_colorized_utf8): Likewise. (test_tab_expansion): Likewise. (test_diagnostic_show_locus_one_liner_utf8): Call the new tests. (diagnostic_show_locus_c_tests): Likewise. (test_overlapped_fixit_printing): Adapt to helper class and function changes. (test_overlapped_fixit_printing_utf8): Likewise. (test_overlapped_fixit_printing_2): Likewise. * diagnostic.h (enum diagnostics_column_unit): New enum. (struct diagnostic_context): Add members for the new options. (diagnostic_converted_column): Declare. (json_from_expanded_location): Add new context argument. * diagnostic.c (diagnostic_initialize): Initialize new members. (diagnostic_converted_column): New function. (maybe_line_and_column): Be willing to output a column of 0. (diagnostic_get_location_text): Convert column number as per the new options. (diagnostic_report_current_module): Likewise. (assert_location_text): Add origin and column_unit arguments for testing the new functionality. (test_diagnostic_get_location_text): Test the new functionality. * doc/invoke.texi: Document the new options and behavior. * input.h (location_compute_display_column): Add tabstop argument. * input.c (location_compute_display_column): Likewise. (test_cpp_utf8): Add selftests for tab expansion. * tree-diagnostic-path.cc (default_tree_make_json_for_path): Pass the new context argument to json_from_expanded_location(). libcpp/ChangeLog: PR preprocessor/49973 PR other/86904 * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, which is now handled by diagnostic_context. (class cpp_display_width_computation): New class. (cpp_byte_column_to_display_column): Add optional tabstop argument. (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * charset.c (cpp_display_width_computation::cpp_display_width_computation): New function. (cpp_display_width_computation::advance_display_cols): Likewise. (compute_next_display_width): Removed and implemented this functionality in a new function... (cpp_display_width_computation::process_next_codepoint): ...here. (cpp_byte_column_to_display_column): Added tabstop argument. Reimplemented in terms of class cpp_display_width_computation. (cpp_display_column_to_byte_column): Likewise. * init.c (cpp_create_reader): Remove handling of -ftabstop, which is now handled by diagnostic_context. gcc/testsuite/ChangeLog: PR preprocessor/49973 PR other/86904 * c-c++-common/Wmisleading-indentation-3.c: Adjust expected output for new defaults. * c-c++-common/Wmisleading-indentation.c: Likewise. * c-c++-common/diagnostic-format-json-1.c: Likewise. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise. * c-c++-common/diagnostic-format-json-5.c: Likewise. * c-c++-common/missing-close-symbol.c: Likewise. * g++.dg/diagnostic/bad-binary-ops.C: Likewise. * g++.dg/parse/error4.C: Likewise. * g++.old-deja/g++.brendan/crash11.C: Likewise. * g++.old-deja/g++.pt/overload2.C: Likewise. * g++.old-deja/g++.robertl/eb109.C: Likewise. * gcc.dg/analyzer/malloc-paths-9.c: Likewise. * gcc.dg/bad-binary-ops.c: Likewise. * gcc.dg/format/branch-1.c: Likewise. * gcc.dg/format/pr79210.c: Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. * gcc.dg/plugin/diagnostic-test-string-literals-1.c: Likewise. * gcc.dg/redecl-4.c: Likewise. * gfortran.dg/diagnostic-format-json-1.F90: Likewise. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. * go.dg/arrayclear.go: Add a comment explaining why adding a comment was necessary to work around a dejagnu bug. * c-c++-common/diagnostic-units-1.c: New test. * c-c++-common/diagnostic-units-2.c: New test. * c-c++-common/diagnostic-units-3.c: New test. * c-c++-common/diagnostic-units-4.c: New test. * c-c++-common/diagnostic-units-5.c: New test. * c-c++-common/diagnostic-units-6.c: New test. * c-c++-common/diagnostic-units-7.c: New test. * c-c++-common/diagnostic-units-8.c: New test.
2020-07-14 18:05:56 +02:00
/* An enum for controlling what units to use for the column number
when diagnostics are output, used by the -fdiagnostics-column-unit option.
Tabs will be expanded or not according to the value of -ftabstop. The origin
(default 1) is controlled by -fdiagnostics-column-origin. */
enum diagnostics_column_unit
{
/* The default from GCC 11 onwards: display columns. */
DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
/* The behavior in GCC 10 and earlier: simple bytes. */
DIAGNOSTICS_COLUMN_UNIT_BYTE
};
diagnostics: escape non-ASCII source bytes for certain diagnostics This patch adds support to GCC's diagnostic subsystem for escaping certain bytes and Unicode characters when quoting source code. Specifically, this patch adds a new flag rich_location::m_escape_on_output which is a hint from a diagnostic that non-ASCII bytes in the pertinent lines of the user's source code should be escaped when printed. The patch sets this for the following diagnostics: - when complaining about stray bytes in the program (when these are non-printable) - when complaining about "null character(s) ignored"); - for -Wnormalized= (and generate source ranges for such warnings) The escaping is controlled by a new option: -fdiagnostics-escape-format=[unicode|bytes] For example, consider a diagnostic involing a source line containing the string "before" followed by the Unicode character U+03C0 ("GREEK SMALL LETTER PI", with UTF-8 encoding 0xCF 0x80) followed by the byte 0xBF (a stray UTF-8 trailing byte), followed by the string "after", where the diagnostic highlights the U+03C0 character. By default, this line will be printed verbatim to the user when reporting a diagnostic at it, as: beforeπXafter ^ (using X for the stray byte to avoid putting invalid UTF-8 in this commit message) If the diagnostic sets the "escape" flag, it will be printed as: before<U+03C0><BF>after ^~~~~~~~ with -fdiagnostics-escape-format=unicode (the default), or as: before<CF><80><BF>after ^~~~~~~~ if the user supplies -fdiagnostics-escape-format=bytes. This only affects how the source is printed; it does not affect how column numbers that are printed (as per -fdiagnostics-column-unit= and -fdiagnostics-column-origin=). gcc/c-family/ChangeLog: * c-lex.c (c_lex_with_flags): When complaining about non-printable CPP_OTHER tokens, set the "escape on output" flag. gcc/ChangeLog: * common.opt (fdiagnostics-escape-format=): New. (diagnostics_escape_format): New enum. (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE): New enum value. (DIAGNOSTICS_ESCAPE_FORMAT_BYTES): Likewise. * diagnostic-format-json.cc (json_end_diagnostic): Add "escape-source" attribute. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Replace "tabstop" param with a cpp_char_column_policy and add an "aspect" param. Use these to compute m_display_col accordingly. (struct char_display_policy): New struct. (layout::m_policy): New field. (layout::m_escape_on_output): New field. (def_policy): New function. (make_range): Update for changes to exploc_with_display_col ctor. (default_print_decoded_ch): New. (width_per_escaped_byte): New. (escape_as_bytes_width): New. (escape_as_bytes_print): New. (escape_as_unicode_width): New. (escape_as_unicode_print): New. (make_policy): New. (layout::layout): Initialize new fields. Update m_exploc ctor call for above change to ctor. (layout::maybe_add_location_range): Update for changes to exploc_with_display_col ctor. (layout::calculate_x_offset_display): Update for change to cpp_display_width. (layout::print_source_line): Pass policy to cpp_display_width_computation. Capture cpp_decoded_char when calling process_next_codepoint. Move printing of source code to m_policy.m_print_cb. (line_label::line_label): Pass in policy rather than context. (layout::print_any_labels): Update for change to line_label ctor. (get_affected_range): Pass in policy rather than context, updating calls to location_compute_display_column accordingly. (get_printed_columns): Likewise, also for cpp_display_width. (correction::correction): Pass in policy rather than tabstop. (correction::compute_display_cols): Pass m_policy rather than m_tabstop to cpp_display_width. (correction::m_tabstop): Replace with... (correction::m_policy): ...this. (line_corrections::line_corrections): Pass in policy rather than context. (line_corrections::m_context): Replace with... (line_corrections::m_policy): ...this. (line_corrections::add_hint): Update to use m_policy rather than m_context. (line_corrections::add_hint): Likewise. (layout::print_trailing_fixits): Likewise. (selftest::test_display_widths): New. (selftest::test_layout_x_offset_display_utf8): Update to use policy rather than tabstop. (selftest::test_one_liner_labels_utf8): Add test of escaping source lines. (selftest::test_diagnostic_show_locus_one_liner_utf8): Update to use policy rather than tabstop. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_utf8): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_tab_expansion): Likewise. (selftest::test_escaping_bytes_1): New. (selftest::test_escaping_bytes_2): New. (selftest::diagnostic_show_locus_c_tests): Call the new tests. * diagnostic.c (diagnostic_initialize): Initialize context->escape_format. (convert_column_unit): Update to use default character width policy. (selftest::test_diagnostic_get_location_text): Likewise. * diagnostic.h (enum diagnostics_escape_format): New enum. (diagnostic_context::escape_format): New field. * doc/invoke.texi (-fdiagnostics-escape-format=): New option. (-fdiagnostics-format=): Add "escape-source" attribute to examples of JSON output, and document it. * input.c (location_compute_display_column): Pass in "policy" rather than "tabstop", passing to cpp_byte_column_to_display_column. (selftest::test_cpp_utf8): Update to use cpp_char_column_policy. * input.h (class cpp_char_column_policy): New forward decl. (location_compute_display_column): Pass in "policy" rather than "tabstop". * opts.c (common_handle_option): Handle OPT_fdiagnostics_escape_format_. * selftest.c (temp_source_file::temp_source_file): New ctor overload taking a size_t. * selftest.h (temp_source_file::temp_source_file): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/diagnostic-format-json-1.c: Add regexp to consume "escape-source" attribute. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise, twice. * c-c++-common/diagnostic-format-json-5.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: New test. * gcc.dg/cpp/warn-normalized-4-unicode.c: New test. * gcc.dg/encoding-issues-bytes.c: New test. * gcc.dg/encoding-issues-unicode.c: New test. * gfortran.dg/diagnostic-format-json-1.F90: Add regexp to consume "escape-source" attribute. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. libcpp/ChangeLog: * charset.c (convert_escape): Use encoding_rich_location when complaining about nonprintable unknown escape sequences. (cpp_display_width_computation::::cpp_display_width_computation): Pass in policy rather than tabstop. (cpp_display_width_computation::process_next_codepoint): Add "out" param and populate *out if non-NULL. (cpp_display_width_computation::advance_display_cols): Pass NULL to process_next_codepoint. (cpp_byte_column_to_display_column): Pass in policy rather than tabstop. Pass NULL to process_next_codepoint. (cpp_display_column_to_byte_column): Pass in policy rather than tabstop. * errors.c (cpp_diagnostic_get_current_location): New function, splitting out the logic from... (cpp_diagnostic): ...here. (cpp_warning_at): New function. (cpp_pedwarning_at): New function. * include/cpplib.h (cpp_warning_at): New decl for rich_location. (cpp_pedwarning_at): Likewise. (struct cpp_decoded_char): New. (struct cpp_char_column_policy): New. (cpp_display_width_computation::cpp_display_width_computation): Replace "tabstop" param with "policy". (cpp_display_width_computation::process_next_codepoint): Add "out" param. (cpp_display_width_computation::m_tabstop): Replace with... (cpp_display_width_computation::m_policy): ...this. (cpp_byte_column_to_display_column): Replace "tabstop" param with "policy". (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * include/line-map.h (rich_location::escape_on_output_p): New. (rich_location::set_escape_on_output): New. (rich_location::m_escape_on_output): New. * internal.h (cpp_diagnostic_get_current_location): New decl. (class encoding_rich_location): New. * lex.c (skip_whitespace): Use encoding_rich_location when complaining about null characters. (warn_about_normalization): Generate a source range when complaining about improperly normalized tokens, rather than just a point, and use encoding_rich_location so that the source code is escaped on printing. * line-map.c (rich_location::rich_location): Initialize m_escape_on_output. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-10-19 00:55:31 +02:00
/* An enum for controlling how to print non-ASCII characters/bytes when
a diagnostic suggests escaping the source code on output. */
enum diagnostics_escape_format
{
/* Escape non-ASCII Unicode characters in the form <U+XXXX> and
non-UTF-8 bytes in the form <XX>. */
DIAGNOSTICS_ESCAPE_FORMAT_UNICODE,
/* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
encoding of non-ASCII Unicode characters). */
DIAGNOSTICS_ESCAPE_FORMAT_BYTES
};
Machine-readable diagnostic output (PR other/19165) 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
2018-11-15 15:32:41 +01:00
/* Enum for overriding the standard output format. */
enum diagnostics_output_format
{
/* The default: textual output. */
DIAGNOSTICS_OUTPUT_FORMAT_TEXT,
/* JSON-based output. */
DIAGNOSTICS_OUTPUT_FORMAT_JSON
};
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
/* An enum for controlling how diagnostic_paths should be printed. */
enum diagnostic_path_format
{
/* Don't print diagnostic_paths. */
DPF_NONE,
/* Print diagnostic_paths by emitting a separate "note" for every event
in the path. */
DPF_SEPARATE_EVENTS,
/* Print diagnostic_paths by consolidating events together where they
are close enough, and printing such runs of events with multiple
calls to diagnostic_show_locus, showing the individual events in
each run via labels in the source. */
DPF_INLINE_EVENTS
};
Add GCC_EXTRA_DIAGNOSTIC_OUTPUT environment variable for fix-it hints GCC has had the ability to emit fix-it hints in machine-readable form since GCC 7 via -fdiagnostics-parseable-fixits and -fdiagnostics-generate-patch. The former emits additional specially-formatted lines to stderr; the option and its format were directly taken from a pre-existing option in clang. Ideally this could be used by IDEs so that the user can select specific fix-it hints and have the IDE apply them to the user's source code (perhaps turning them into clickable elements, perhaps with an "Apply All" option, etc). Eclipse CDT has supported this option in this way for a few years: https://bugs.eclipse.org/bugs/show_bug.cgi?id=497670 As a user of Emacs I would like Emacs to support such a feature. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25987 tracks supporting GCC fix-it output in Emacs. The discussion there identifies two issues with the existing option: (a) columns in the output are specified as byte-offsets within the line (for exact compatibility with the option in clang), whereas emacs would prefer to consume them as what GCC 11 calls "display columns". https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-column-unit (b) injecting a command-line option into the build is a fiddly manual step, varying between build systems. It's far easier for the user if Emacs simply sets an environment variable when compiling, GCC uses this to enable the option if it recognizes the value, and the emacs compilation buffer decodes the additional lines of output and adds appropriate widgets. In some ways it is a workaround for not having a language server. Doing it this way means that for the various combinations of older and newer GCC and older and newer Emacs that a sufficiently modern combination of both can automatically support the rich fix-it UI, whereas other combinations will either not provide the envvar, or silently ignore it, gracefully doing nothing extra. Hence this patch adds a new GCC_EXTRA_DIAGNOSTIC_OUTPUT environment variable to GCC which enables output of machine-parseable fix-it hints. GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v1 is equivalent to the existing -fdiagnostics-parseable-fixits option. GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v2 is the same, but changes the column output mode to "display columns" rather than bytes, as required by Emacs. The discussion in that Emacs bug has some concerns about the encoding of these lines, and, indeed, the encoding of GCC's stderr in general: currently we emit a mixture of bytes and UTF-8; I believe we emit filenames as bytes, diagnostic messages as UTF-8, and quote source code in the original encoding (PR other/93067 covers converting it to UTF-8 on output). This patch prints octal-escaped bytes for bytes within filenames and replacement text that aren't printable (as per -fdiagnostics-parseable-fixits). gcc/ChangeLog: * diagnostic.c (diagnostic_initialize): Eliminate parseable_fixits_p in favor of initializing extra_output_kind from GCC_EXTRA_DIAGNOSTIC_OUTPUT. (convert_column_unit): New function, split out from... (diagnostic_converted_column): ...this. (print_parseable_fixits): Add "column_unit" and "tabstop" params. Use them to call convert_column_unit on the column values. (diagnostic_report_diagnostic): Eliminate conditional on parseable_fixits_p in favor of a switch statement on extra_output_kind, passing the appropriate values to the new params of print_parseable_fixits. (selftest::test_print_parseable_fixits_none): Update for new params of print_parseable_fixits. (selftest::test_print_parseable_fixits_insert): Likewise. (selftest::test_print_parseable_fixits_remove): Likewise. (selftest::test_print_parseable_fixits_replace): Likewise. (selftest::test_print_parseable_fixits_bytes_vs_display_columns): New. (selftest::diagnostic_c_tests): Call it. * diagnostic.h (enum diagnostics_extra_output_kind): New. (diagnostic_context::parseable_fixits_p): Delete field in favor of... (diagnostic_context::extra_output_kind): ...this new field. * doc/invoke.texi (Environment Variables): Add GCC_EXTRA_DIAGNOSTIC_OUTPUT. * opts.c (common_handle_option): Update handling of OPT_fdiagnostics_parseable_fixits for change to diagnostic_context fields. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-GCC_EXTRA_DIAGNOSTIC_OUTPUT-fixits-v1.c: New file. * gcc.dg/plugin/diagnostic-test-show-locus-GCC_EXTRA_DIAGNOSTIC_OUTPUT-fixits-v2.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add them.
2021-01-14 22:25:02 +01:00
/* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT,
and for -fdiagnostics-parseable-fixits. */
enum diagnostics_extra_output_kind
{
/* No extra output, or an unrecognized value. */
EXTRA_DIAGNOSTIC_OUTPUT_none,
/* Emit fix-it hints using the "fixits-v1" format, equivalent to
-fdiagnostics-parseable-fixits. */
EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1,
/* Emit fix-it hints using the "fixits-v2" format. */
EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
};
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
its context and its KIND (ice, error, warning, note, ...) See complete
list in diagnostic.def. */
cgraph.h (cgraph_node_set_iterator, [...]): Remove typedef. * 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
2013-12-10 17:48:44 +01:00
struct diagnostic_info
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
{
diagnostic_info ()
: message (), richloc (), metadata (), x_data (), kind (), option_index (),
m_iinfo ()
{ }
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
/* Text to be formatted. */
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
text_info message;
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
/* The location at which the diagnostic is to be reported. */
rich_location *richloc;
Add diagnostic_metadata and CWE support This patch adds support for associating a diagnostic message with an optional diagnostic_metadata object, so that plugins can add extra data to their diagnostics (e.g. mapping a diagnostic to a taxonomy or coding standard such as from CERT or MISRA). Currently this only supports associating a CWE identifier with a diagnostic (which is what I'm using for the warnings in the analyzer patch kit), but adding a diagnostic_metadata class allows for future growth in this area without an explosion of further "warning_at" overloads for all of the different kinds of custom data that a plugin might want to add. This version of the patch renames the overly-general -fdiagnostics-show-metadata to -fdiagnostics-show-cwe and adds test coverage for it via a plugin. It also adds a note to the documentation that no GCC diagnostics currently use this; it's a feature for plugins (and, at some point, I hope, the analyzer). gcc/ChangeLog: * common.opt (fdiagnostics-show-cwe): Add. * diagnostic-core.h (class diagnostic_metadata): New forward decl. (warning_at): Add overload taking a const diagnostic_metadata &. (emit_diagnostic_valist): Add overload taking a const diagnostic_metadata *. * diagnostic-format-json.cc: Include "diagnostic-metadata.h". (json_from_metadata): New function. (json_end_diagnostic): Call it to add "metadata" child for diagnostics with metadata. (diagnostic_output_format_init): Clear context->show_cwe. * diagnostic-metadata.h: New file. * diagnostic.c: Include "diagnostic-metadata.h". (diagnostic_impl): Add const diagnostic_metadata * param. (diagnostic_n_impl): Likewise. (diagnostic_initialize): Initialize context->show_cwe. (diagnostic_set_info_translated): Initialize diagnostic->metadata. (get_cwe_url): New function. (print_any_cwe): New function. (diagnostic_report_diagnostic): Call print_any_cwe if the diagnostic has non-NULL metadata. (emit_diagnostic): Pass NULL as the metadata in the call to diagnostic_impl. (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist): New overload taking a const diagnostic_metadata *. (inform): Pass NULL as the metadata in the call to diagnostic_impl. (inform_n): Likewise for diagnostic_n_impl. (warning): Likewise. (warning_at): Likewise. Add overload that takes a const diagnostic_metadata &. (warning_n): Pass NULL as the metadata in the call to diagnostic_n_impl. (pedwarn): Likewise for diagnostic_impl. (permerror): Likewise. (error): Likewise. (error_n): Likewise. (error_at): Likewise. (sorry): Likewise. (sorry_at): Likewise. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. * diagnostic.h (diagnostic_info::metadata): New field. (diagnostic_context::show_cwe): New field. * doc/invoke.texi (-fno-diagnostics-show-cwe): New option. * opts.c (common_handle_option): Handle OPT_fdiagnostics_show_cwe. * toplev.c (general_init): Initialize global_dc->show_cwe. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-metadata.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_metadata.c: New test plugin. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add them. From-SVN: r279556
2019-12-19 00:58:49 +01:00
/* An optional bundle of metadata associated with the diagnostic
(or NULL). */
const diagnostic_metadata *metadata;
diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. * diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. (diagnostic_initialize): Initialize x_data not last_function. (diagnostic_report_current_function): Move to tree-diagnostic.c. (default_diagnostic_starter): Call diagnostic_report_current_module not diagnostic_report_current_function. (diagnostic_report_diagnostic): Initialize x_data not abstract_origin. (verbatim): Likewise. * diagnostic.h (struct diagnostic_info): Change abstract_origin to x_data. (struct diagnostic_context): Change last_function to x_data. (diagnostic_auxiliary_data): Replace with diagnostic_context_auxiliary_data and diagnostic_info_auxiliary_data. (diagnostic_last_function_changed, diagnostic_set_last_function, diagnostic_report_current_function): Move to tree-diagnostic.h. (print_declaration, dump_generic_node, print_generic_stmt, print_generic_stmt_indented, print_generic_expr, print_generic_decl, debug_c_tree, dump_omp_clauses, print_call_name, debug_generic_expr, debug_generic_stmt, debug_tree_chain, default_tree_printer): Move to tree-pretty-print.h. (debug_gimple_stmt, debug_gimple_seq, print_gimple_seq, print_gimple_stmt, print_gimple_expr, dump_gimple_stmt): Move to gimple-pretty-print.h. * pretty-print.c: Don't include tree.h (pp_base_format): Don't handle %K here. (pp_base_tree_identifier): Move to tree-pretty-print.c. * pretty-print.h (text_info): Change abstract_origin to x_data. (pp_tree_identifier, pp_unsupported_tree, pp_base_tree_identifier): Move to tree-pretty-print.h. * gimple-pretty-print.h, tree-diagnostic.c, tree-diagnostic.h, tree-pretty-print.h: New files. * tree-pretty-print.c: Include tree-pretty-print.h. (percent_K_format): New. Moved from pretty-print.c. (pp_base_tree_identifier): Move from pretty-print.c. * c-objc-common.c: Include tree-pretty-print.h. (c_tree_printer): Handle %K here. * langhooks.c: Include tree-diagnostic.h. (lhd_print_error_function): Use diagnostic_abstract_origin macro. * toplev.c: Include tree-diagnostic.h and tree-pretty-print.h. (default_tree_printer): Handle %K using percent_K_format. (general_init): Use default_tree_diagnostic_starter. * tree.c: Include tree-diagnostic.h and tree-pretty-print.h. (free_lang_data): Use default_tree_diagnostic_starter. * c-pretty-print.c: Include tree-pretty-print.h. * cfgexpand.c: Include tree-pretty-print.h and gimple-pretty-print.h. * cgraphunit.c: Include tree-pretty-print.h and gimple-pretty-print.h. * dwarf2out.c: Include tree-pretty-print.h. * except.c: Include tree-pretty-print.h. * gimple-pretty-print.c: Include tree-pretty-print.h and gimple-pretty-print.h. * gimplify.c: Include tree-pretty-print.h. * graphite-poly.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-cp.c: Include tree-pretty-print.h. * ipa-inline.c: Include gimple-pretty-print.h. * ipa-prop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-pure-const.c: Include gimple-pretty-print.h. * ipa-struct-reorg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-type-escape.c: Include tree-pretty-print.h. * print-rtl.c: Include tree-pretty-print.h. * print-tree.c: Include gimple-pretty-print.h. * sese.c: Include tree-pretty-print.h. * tree-affine.c: Include tree-pretty-print.h. * tree-browser.c: Include tree-pretty-print.h. * tree-call-cdce.c: Include gimple-pretty-print.h. * tree-cfg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-chrec.c: Include tree-pretty-print.h. * tree-data-ref.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-dfa.c: Include tree-pretty-print.h. * tree-if-conv.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-inline.c: Include tree-pretty-print.h. * tree-into-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-nrv.c: Include tree-pretty-print.h. * tree-object-size.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-outof-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-parloops.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-predcom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-scalar-evolution.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-sra.c: Include tree-pretty-print.h. * tree-ssa-address.c: Include tree-pretty-print.h. * tree-ssa-alias.c: Include tree-pretty-print.h. * tree-ssa-ccp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-coalesce.c: Include tree-pretty-print.h. * tree-ssa-copy.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-copyrename.c: Include tree-pretty-print.h. * tree-ssa-dce.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dse.c: Include gimple-pretty-print.h. * tree-ssa-forwprop.c: Include tree-pretty-print.h. * tree-ssa-ifcombine.c: Include tree-pretty-print.h. * tree-ssa-live.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-im.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivcanon.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivopts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-niter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-prefetch.c: Include tree-pretty-print.h. * tree-ssa-math-opts.c: Include gimple-pretty-print.h. * tree-ssa-operands.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-phiprop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-pre.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-propagate.c: Include gimple-pretty-print.h. * tree-ssa-reassoc.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sccvn.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sink.c: Include gimple-pretty-print.h. * tree-ssa-ter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-uninit.c: Include gimple-pretty-print.h. * tree-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-stdarg.c: Include gimple-pretty-print.h. * tree-switch-conversion.c: Include gimple-pretty-print.h. * tree-tailcall.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-data-refs.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop-manip.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-patterns.c: Include gimple-pretty-print.h. * tree-vect-slp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-stmts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vectorizer.c: Include tree-pretty-print.h. * tree-vrp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * value-prof.c: Include tree-pretty-print.h and gimple-pretty-print.h. * var-tracking.c: Include tree-pretty-print.h. * Makefile.in (OBJS-common): Add tree-diagnostic.o. (tree-diagnostic.o): New dependencies. (c-objc-common.o, c-pretty-print.o, langhooks.o, tree.o, tree-inline.o, print-tree.o, stor-layout.o, tree-ssa-uninit.o, tree-ssa.o, tree-into-ssa.o, tree-ssa-ter.o, tree-ssa-coalesce.o, tree-outof-ssa.o, tree-ssa-forwprop.o, tree-ssa-phiprop.o, tree-ssa-ifcombine.o, tree-nrv.o, tree-ssa-copy.o, tree-ssa-propagate.o, tree-ssa-dom.o, tree-ssa-uncprop.o, tree-ssa-live.o, tree-ssa-copyrename.o, tree-ssa-pre.o, tree-ssa-sccvn.o, tree-vrp.o, tree-cfg.o, tree-tailcall.o, tree-ssa-sink.o, tree-if-conv.o, tree-dfa.o, tree-ssa-operands.o, tree-ssa-address.o, tree-ssa-loop-niter.o, tree-ssa-loop-ivcanon.o, tree-ssa-loop-prefetch.o, tree-predcom.o, tree-ssa-loop-ivopts.o, tree-affine.o, tree-ssa-loop-im.o, tree-ssa-math-opts.o, tree-ssa-alias.o, tree-ssa-reassoc.o, gimplify.o, tree-browser.o, tree-chrec.o, tree-scalar-evolution.o, tree-data-ref.o, sese.o, graphite-poly.o, tree-vect-loop.o, tree-vect-loop-manip.o, tree-vect-patterns.o, tree-vect-slp.o, tree-vect-stmts.o, tree-vect-data-refs.o, tree-vectorizer.o, tree-parloops.o, tree-stdarg.o, tree-object-size.o, gimple-pretty-print.o, tree-pretty-print.o, diagnostic.o, toplev.o, print-rtl.o, except.o, dwarf2out.o, cgraphunit.o, ipa-prop.o, ipa-cp.o, ipa-inline.o, ipa-pure-const.o, ipa-type-escape.o, ipa-struct-reorg.o, tree-ssa-dce.o, tree-call-cdce.o, tree-ssa-ccp.o, tree-sra.o, tree-switch-conversion.o, var-tracking.o, value-prof.o, cfgexpand.o, pretty-print.o): Update dependencies. cp: * error.c: Include tree-diagnostic.h and tree-pretty-print.h. (cp_print_error_function): Use diagnostic_abstract_origin macro. (cp_printer): Handle %K here using percent_K_format. * cxx-pretty-print.c: Include tree-pretty-print.h. * Make-lang.in (cp/error.o, cp/cxx-pretty-print.o): Update dependencies. From-SVN: r159685
2010-05-22 00:34:26 +02:00
/* Auxiliary data for client. */
void *x_data;
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* The kind of diagnostic it is about. */
diagnostic_t kind;
/* Which OPT_* directly controls this diagnostic. */
int option_index;
/* Inlining context containing locations for each call site along
the inlining stack. */
struct inlining_info
{
/* Locations along the inlining stack. */
auto_vec<location_t, 8> m_ilocs;
/* The abstract origin of the location. */
void *m_ao;
/* Set if every M_ILOCS element is in a system header. */
bool m_allsyslocs;
} m_iinfo;
cgraph.h (cgraph_node_set_iterator, [...]): Remove typedef. * 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
2013-12-10 17:48:44 +01:00
};
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* Each time a diagnostic's classification is changed with a pragma,
we record the change and the location of the change in an array of
these structs. */
cgraph.h (cgraph_node_set_iterator, [...]): Remove typedef. * 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
2013-12-10 17:48:44 +01:00
struct diagnostic_classification_change_t
{
location_t location;
int option;
diagnostic_t kind;
cgraph.h (cgraph_node_set_iterator, [...]): Remove typedef. * 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
2013-12-10 17:48:44 +01:00
};
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* Forward declarations. */
typedef void (*diagnostic_starter_fn) (diagnostic_context *,
diagnostic_info *);
PR other/69554: avoid excessive source printing for widely-separated locations 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
2016-02-12 20:18:03 +01:00
typedef void (*diagnostic_start_span_fn) (diagnostic_context *,
expanded_location);
Machine-readable diagnostic output (PR other/19165) 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
2018-11-15 15:32:41 +01:00
typedef void (*diagnostic_finalizer_fn) (diagnostic_context *,
diagnostic_info *,
diagnostic_t);
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
class edit_context;
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
namespace json { class value; }
/* This data structure bundles altogether any information relevant to
the context of a diagnostic message. */
struct diagnostic_context
{
/* Where most of the diagnostic formatting work is done. */
Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. * calls.c (try_to_integrate): Don't use xxx_with_decl. (expand_call): Likewise. * dwarfout.c (output_reg_number): Likewise. * expr.c (expand_expr): Likewise. * function.c (assign_temp): Likewise. (uninitialized_vars_warning): Likewise. (setjmp_args_warning): Likewise. (expand_function_end): Likewise. * stmt.c (fixup_gotos): Likewise. (warn_about_unused_variables): Likewise. (expand_end_bindings): Likewise. * stor-layout.c (layout_decl): Likewise. (place_field): Likewise. * toplev.c (check_global_declarations): Likewise. (rest_of_handle_inlining): Likewise. (default_tree_printer): New function. (general_init): Initialize diagnostic machinery before routing signals to the ICE machinery. Set default tree printer. * toplev.h (pedwarn_with_decl): Remove declaration. (warning_with_decl): Likewise. (error_with_decl): Likewise. (pedwarn): Remove attribute for the time being. * tree-inline.c (expand_call_inline): Don't use xxx_with_decl. * varasm.c (named_section): Likewise. (make_decl_rtl): Likewise. (assemble_variable): Likewise. (merge_weak): Likewise. (declare_weak): Likewise. * diagnostic.h: Move non-diagnostic stuff into pretty-print.h. * diagnostic.c: Move non-diagnostic stuff into pretty-print.c. (format_with_decl): Remove. (diagnostic_for_decl): Likewise. (pedwarn_with_decl): Likewise. (warning_with_decl): Likewise. (error_with_decl): Likewise. (diagnostic_initialize): Adjust. (diagnostic_count_diagnostic): Likewise. (announce_function): Likewise. (lhd_print_error_function): Likewise. (diagnostic_report_current_module): Likewise. (default_diagnostic_starter): Likewise. (diagnostic_report_diagnostic): Likewise. (default_diagnostic_finalizer): Likewise. (verbatim): Likewise. (error): Likewise. (warning): Likewise. * opts.c (common_handle_option): Likewise. * pretty-print.c: New file. * c-pretty-print.h (pp_base): Override. * c-pretty-print.c: Adjust use of macros throughout. (pp_buffer): New macro. (pp_newline): Likewise. * c-objc-common.c (c_tree_printer): Adjust prototype. Tidy. * Makefile.in (DIAGNOSTIC_H): New variable. (c-errors.o): Use it. (c-objc-common.o): Likewise. (c-common.o): Likewise. (c-opts.o): Likewise. (c-format.o): Likewise. (diagnostic.o): Likewise. (opts.o): Likewise. (toplev.o): Likewise. (rtl-error.o): Likewise. (dwarf2out.o): Likewise. (jump.o): Likewise. (pretty-print.o): New rule. cp/ * Make-lang.in (cp/error.o): Depend on DIAGNOSTIC_H. * error.c: Use the new pretty-printer fraamework. From-SVN: r69773
2003-07-25 11:52:32 +02:00
pretty_printer *printer;
input.c: move file caching globals to a new file_cache class This moves some global state from input.c to a new file_cache class, of which an instance is owned by global_dc. Various state is also made private. No functional change intended. gcc/ChangeLog: * diagnostic.h (diagnostic_context::m_file_cache): New field. * input.c (class fcache): Rename to... (class file_cache_slot): ...this, making most members private and prefixing fields with "m_". (file_cache_slot::get_file_path): New accessor. (file_cache_slot::get_use_count): New accessor. (file_cache_slot::missing_trailing_newline_p): New accessor. (file_cache_slot::inc_use_count): New. (fcache_buffer_size): Move to... (file_cache_slot::buffer_size): ...here. (fcache_line_record_size): Move to... (file_cache_slot::line_record_size): ...here. (fcache_tab): Delete, in favor of global_dc->m_file_cache. (fcache_tab_size): Move to file_cache::num_file_slots. (diagnostic_file_cache_init): Update for move of fcache_tab to global_dc->m_file_cache. (diagnostic_file_cache_fini): Likewise. (lookup_file_in_cache_tab): Convert to... (file_cache::lookup_file): ...this. (diagnostics_file_cache_forcibly_evict_file): Update for move of fcache_tab to global_dc->m_file_cache, moving most of implementation to... (file_cache::forcibly_evict_file): ...this new function and... (file_cache_slot::evict): ...this new function. (evicted_cache_tab_entry): Convert to... (file_cache::evicted_cache_tab_entry): ...this. (add_file_to_cache_tab): Convert to... (file_cache::add_file): ...this, moving bulk of implementation to... (file_cache_slot::create): ..this new function. (file_cache::file_cache): New. (file_cache::~file_cache): New. (lookup_or_add_file_to_cache_tab): Convert to... (file_cache::lookup_or_add_file): ..this new function. (fcache::fcache): Rename to... (file_cache_slot::file_cache_slot): ...this, adding "m_" prefixes to fields. (fcache::~fcache): Rename to... (file_cache_slot::~file_cache_slot): ...this, adding "m_" prefixes to fields. (needs_read): Convert to... (file_cache_slot::needs_read_p): ...this. (needs_grow): Convert to... (file_cache_slot::needs_grow_p): ...this. (maybe_grow): Convert to... (file_cache_slot::maybe_grow): ...this. (read_data): Convert to... (file_cache_slot::read_data): ...this. (maybe_read_data): Convert to... (file_cache_slot::maybe_read_data): ...this. (get_next_line): Convert to... (file_cache_slot::get_next_line): ...this. (goto_next_line): Convert to... (file_cache_slot::goto_next_line): ...this. (read_line_num): Convert to... (file_cache_slot::read_line_num): ...this. (location_get_source_line): Update for moving of globals to global_dc->m_file_cache. (location_missing_trailing_newline): Likewise. * input.h (class file_cache_slot): New forward decl. (class file_cache): New. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-07-01 23:44:51 +02:00
/* Cache of source code. */
file_cache *m_file_cache;
/* The number of times we have issued diagnostics. */
int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
/* True if it has been requested that warnings be treated as errors. */
bool warning_as_error_requested;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* The number of option indexes that can be passed to warning() et
al. */
int n_opts;
/* For each option index that can be passed to warning() et al
(OPT_* from options.h when using this code with the core GCC
options), this array may contain a new kind that the diagnostic
should be changed to before reporting, or DK_UNSPECIFIED to leave
it as the reported kind, or DK_IGNORED to not report it at
all. */
diagnostic_t *classify_diagnostic;
/* History of all changes to the classifications above. This list
is stored in location-order, so we can search it, either
binary-wise or end-to-front, to find the most recent
classification for a given diagnostic, given the location of the
diagnostic. */
diagnostic_classification_change_t *classification_history;
/* The size of the above array. */
int n_classification_history;
/* For pragma push/pop. */
int *push_list;
int n_push;
/* True if we should print the source line with a caret indicating
the location. */
bool show_caret;
/* Maximum width of the source line printed. */
int caret_max_width;
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
/* Character used for caret diagnostics. */
Remove arbitrary limits from rich_location 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
2016-08-31 02:35:01 +02:00
char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
Add diagnostic_metadata and CWE support This patch adds support for associating a diagnostic message with an optional diagnostic_metadata object, so that plugins can add extra data to their diagnostics (e.g. mapping a diagnostic to a taxonomy or coding standard such as from CERT or MISRA). Currently this only supports associating a CWE identifier with a diagnostic (which is what I'm using for the warnings in the analyzer patch kit), but adding a diagnostic_metadata class allows for future growth in this area without an explosion of further "warning_at" overloads for all of the different kinds of custom data that a plugin might want to add. This version of the patch renames the overly-general -fdiagnostics-show-metadata to -fdiagnostics-show-cwe and adds test coverage for it via a plugin. It also adds a note to the documentation that no GCC diagnostics currently use this; it's a feature for plugins (and, at some point, I hope, the analyzer). gcc/ChangeLog: * common.opt (fdiagnostics-show-cwe): Add. * diagnostic-core.h (class diagnostic_metadata): New forward decl. (warning_at): Add overload taking a const diagnostic_metadata &. (emit_diagnostic_valist): Add overload taking a const diagnostic_metadata *. * diagnostic-format-json.cc: Include "diagnostic-metadata.h". (json_from_metadata): New function. (json_end_diagnostic): Call it to add "metadata" child for diagnostics with metadata. (diagnostic_output_format_init): Clear context->show_cwe. * diagnostic-metadata.h: New file. * diagnostic.c: Include "diagnostic-metadata.h". (diagnostic_impl): Add const diagnostic_metadata * param. (diagnostic_n_impl): Likewise. (diagnostic_initialize): Initialize context->show_cwe. (diagnostic_set_info_translated): Initialize diagnostic->metadata. (get_cwe_url): New function. (print_any_cwe): New function. (diagnostic_report_diagnostic): Call print_any_cwe if the diagnostic has non-NULL metadata. (emit_diagnostic): Pass NULL as the metadata in the call to diagnostic_impl. (emit_diagnostic_valist): Likewise. (emit_diagnostic_valist): New overload taking a const diagnostic_metadata *. (inform): Pass NULL as the metadata in the call to diagnostic_impl. (inform_n): Likewise for diagnostic_n_impl. (warning): Likewise. (warning_at): Likewise. Add overload that takes a const diagnostic_metadata &. (warning_n): Pass NULL as the metadata in the call to diagnostic_n_impl. (pedwarn): Likewise for diagnostic_impl. (permerror): Likewise. (error): Likewise. (error_n): Likewise. (error_at): Likewise. (sorry): Likewise. (sorry_at): Likewise. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. * diagnostic.h (diagnostic_info::metadata): New field. (diagnostic_context::show_cwe): New field. * doc/invoke.texi (-fno-diagnostics-show-cwe): New option. * opts.c (common_handle_option): Handle OPT_fdiagnostics_show_cwe. * toplev.c (general_init): Initialize global_dc->show_cwe. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-metadata.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_metadata.c: New test plugin. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add them. From-SVN: r279556
2019-12-19 00:58:49 +01:00
/* True if we should print any CWE identifiers associated with
diagnostics. */
bool show_cwe;
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
/* How should diagnostic_path objects be printed. */
enum diagnostic_path_format path_format;
/* True if we should print stack depths when printing diagnostic paths. */
bool show_path_depths;
/* True if we should print the command line option which controls
each diagnostic, if known. */
bool show_option_requested;
/* True if we should raise a SIGABRT on errors. */
bool abort_on_error;
/* True if we should show the column number on diagnostics. */
bool show_column;
/* True if pedwarns are errors. */
bool pedantic_errors;
/* True if permerrors are warnings. */
bool permissive;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* The index of the option to associate with turning permerrors into
warnings. */
int opt_permissive;
/* True if errors are fatal. */
bool fatal_errors;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* True if all warnings should be disabled. */
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
bool dc_inhibit_warnings;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* True if warnings should be given in system headers. */
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
bool dc_warn_system_headers;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* Maximum number of errors to report. */
int max_errors;
/* This function is called before any message is printed out. It is
responsible for preparing message prefix and such. For example, it
might say:
In file included from "/usr/local/include/curses.h:5:
from "/home/gdr/src/nifty_printer.h:56:
...
*/
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
diagnostic_starter_fn begin_diagnostic;
PR other/69554: avoid excessive source printing for widely-separated locations 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
2016-02-12 20:18:03 +01:00
/* This function is called by diagnostic_show_locus in between
disjoint spans of source code, so that the context can print
something to indicate that a new span of source code has begun. */
diagnostic_start_span_fn start_span;
/* This function is called after the diagnostic message is printed. */
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
diagnostic_finalizer_fn end_diagnostic;
/* Client hook to report an internal error. */
void (*internal_error) (diagnostic_context *, const char *, va_list *);
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* Client hook to say whether the option controlling a diagnostic is
enabled. Returns nonzero if enabled, zero if disabled. */
int (*option_enabled) (int, unsigned, void *);
opt-functions.awk (static_var): Update comment. * opt-functions.awk (static_var): Update comment. (var_ref): Return offsetof expression or -1, not variable address. * optc-gen.awk: Generate structure field initializers instead of static variables. Expect -1 for missing variables instead of null pointer. Add gcc_options parameters to generated functions. * opth-gen.awk: Generate structure fields for static variables. Add gcc_options parameters to generated functions. * common.opt (optimize, optimize_size): Add variables. * config/i386/i386-c.c (ix86_pragma_target_parse): Pass &global_options to cl_target_option_restore. * config/i386/i386.c (ix86_valid_target_attribute_p): Pass &global_options to cl_optimization_restore, cl_target_option_save and cl_target_option_restore. (ix86_set_current_function): Pass &global_options to cl_target_option_restore. * config/pdp11/pdp11.h (optimize): Remove. * config/rs6000/rs6000.h (optimize): Remove. * config/sh/sh.h (optimize): Remove. * config/xtensa/xtensa.h (optimize): Remove. * coretypes.h (struct gcc_options): Declare. * diagnostic.c (diagnostic_initialize): Initialize context->option_state. (diagnostic_report_diagnostic): Pass option_state to option_enabled hook. * diagnostic.h (diagnostic_context.option_enabled): Add void * parameter. (diagnostic_context.option_state): New field. * final.c (final_start_function, final, final_scan_insn): Rename optimize parameter to optimize_p. * flags.h (optimize, optimize_size): Remove. * function.c (invoke_set_current_function_hook): Pass &global_options to cl_optimization_restore. * gcc.c (driver_handle_option): Take gcc_options parameter. Assert that it is &global_options. (process_command): Pass &global_options to read_cmdline_option. * ipa-pure-const.c (suggest_attribute): Pass &global_options to option_enabled. * lto-opts.c (lto_reissue_options): Use option_flag_var. Pass &global_options to set_option. * opts-common.c (handle_option, handle_generated_option, read_cmdline_option, set_option): Take explicit gcc_options parameters. Use option_flag_var. (option_flag_var): New. * opts.c (common_handle_option, lang_handle_option, target_handle_option): Take gcc_options parameter. Assert that it is &global_options. (read_cmdline_options): Pass &global_options to read_cmdline_option. (print_filtered_help): Use option_flag_var. Pass &global_options to option_enabled. (common_handle_option): Use option_flag_var. (option_enabled): Take opts parameter. Use option_flag_var. (get_option_state): Take gcc_options parameter. Use option_flag_var. Pass gcc_options parameter to option_enabled. (enable_warning_as_error): Pass &global_options to handle_generated_option. * opts.h (struct cl_option): Change flag_var to flag_var_offset. (cl_option_handler_func.handler): Take gcc_options parameter. (option_enabled, get_option_state, set_option, handle_option, handle_generated_option, read_cmdline_option): Take gcc_options parameters. * toplev.c (optimize, optimize_size): Remove. (print_switch_values): Pass &global_options to option_enabled. (option_affects_pch_p): Use option_flag_var. Pass &global_options to get_option_state. (general_init): Initialize global_dc->option_state. * tree.c (build_optimization_node): Pass &global_options to cl_optimization_save. (build_target_option_node): Pass &global_options to cl_target_option_save. c-family: * c-common.c (handle_optimize_attribute): Pass &global_options to cl_optimization_save and cl_optimization_restore. * c-opts.c (c_common_handle_option): Pass &global_options to handle_generated_option. * c-pragma.c (handle_pragma_diagnostic): Use option_flag_var. (handle_pragma_pop_options, handle_pragma_reset_options): Pass &global_options to cl_optimization_restore. From-SVN: r164751
2010-09-30 15:53:12 +02:00
/* Client information to pass as second argument to
option_enabled. */
void *option_state;
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
/* Client hook to return the name of an option that controls a
diagnostic. Returns malloced memory. The first diagnostic_t
argument is the kind of diagnostic before any reclassification
(of warnings as errors, etc.); the second is the kind after any
reclassification. May return NULL if no name is to be printed.
May be passed 0 as well as the index of a particular option. */
char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t);
Documentation hyperlinks for [-Wname-of-option] (PR 87488) This patch uses the support for pretty-printing escaped URLs added in the previous patch (PR 87488) so that in a sufficiently capable terminal the [-Wname-of-option] emitted at the end of each diagnostic becomes a hyperlink to the documentation for that option on the GCC website. I've tested it with Fedora 30's GNOME Terminal (3.32.2 with VTE 0.56.3); the option text is printed with a dotted underline, hovering shows the URL, and on right-clicking it offers menu items to visit/copy the URL. gcc/ChangeLog: PR 87488 * Makefile.in (CFLAGS-opts.o): Pass in DOCUMENTATION_ROOT_URL via -D. * configure.ac (--with-documentation-root-url): New option. * configure: Regenerate. * diagnostic-format-json.cc (json_end_diagnostic): If there is an option URL, add it as a new string field of the diagnostic option. * diagnostic.c (diagnostic_initialize): Initialize get_option_url. (print_option_information): If get_option_url is non-NULL, call it, and if the result is non-NULL, potentially emit an escape sequence to markup the option text with the resulting URL. * diagnostic.h (diagnostic_context::get_option_url): New callback. * doc/invoke.texi (-fdiagnostics-format=): Add "option_url" to example of JSON output. * opts-diagnostic.h (get_option_url): New decl. * opts.c (get_option_url): New function. * toplev.c (general_init): Initialize the get_option_url callback. gcc/testsuite/ChangeLog: PR 87488 * c-c++-common/diagnostic-format-json-2.c: Expect an "option_url" field. * c-c++-common/diagnostic-format-json-3.c: Likewise. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. * jit.dg/test-error-array-bounds.c (create_code): Ensure that error messages don't contain escaped URLs. From-SVN: r276843
2019-10-10 19:03:46 +02:00
/* Client hook to return a URL describing the option that controls
a diagnostic. Returns malloced memory. May return NULL if no URL
is available. May be passed 0 as well as the index of a
particular option. */
char *(*get_option_url) (diagnostic_context *, int);
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
void (*print_path) (diagnostic_context *, const diagnostic_path *);
json::value *(*make_json_for_path) (diagnostic_context *, const diagnostic_path *);
diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. * diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. (diagnostic_initialize): Initialize x_data not last_function. (diagnostic_report_current_function): Move to tree-diagnostic.c. (default_diagnostic_starter): Call diagnostic_report_current_module not diagnostic_report_current_function. (diagnostic_report_diagnostic): Initialize x_data not abstract_origin. (verbatim): Likewise. * diagnostic.h (struct diagnostic_info): Change abstract_origin to x_data. (struct diagnostic_context): Change last_function to x_data. (diagnostic_auxiliary_data): Replace with diagnostic_context_auxiliary_data and diagnostic_info_auxiliary_data. (diagnostic_last_function_changed, diagnostic_set_last_function, diagnostic_report_current_function): Move to tree-diagnostic.h. (print_declaration, dump_generic_node, print_generic_stmt, print_generic_stmt_indented, print_generic_expr, print_generic_decl, debug_c_tree, dump_omp_clauses, print_call_name, debug_generic_expr, debug_generic_stmt, debug_tree_chain, default_tree_printer): Move to tree-pretty-print.h. (debug_gimple_stmt, debug_gimple_seq, print_gimple_seq, print_gimple_stmt, print_gimple_expr, dump_gimple_stmt): Move to gimple-pretty-print.h. * pretty-print.c: Don't include tree.h (pp_base_format): Don't handle %K here. (pp_base_tree_identifier): Move to tree-pretty-print.c. * pretty-print.h (text_info): Change abstract_origin to x_data. (pp_tree_identifier, pp_unsupported_tree, pp_base_tree_identifier): Move to tree-pretty-print.h. * gimple-pretty-print.h, tree-diagnostic.c, tree-diagnostic.h, tree-pretty-print.h: New files. * tree-pretty-print.c: Include tree-pretty-print.h. (percent_K_format): New. Moved from pretty-print.c. (pp_base_tree_identifier): Move from pretty-print.c. * c-objc-common.c: Include tree-pretty-print.h. (c_tree_printer): Handle %K here. * langhooks.c: Include tree-diagnostic.h. (lhd_print_error_function): Use diagnostic_abstract_origin macro. * toplev.c: Include tree-diagnostic.h and tree-pretty-print.h. (default_tree_printer): Handle %K using percent_K_format. (general_init): Use default_tree_diagnostic_starter. * tree.c: Include tree-diagnostic.h and tree-pretty-print.h. (free_lang_data): Use default_tree_diagnostic_starter. * c-pretty-print.c: Include tree-pretty-print.h. * cfgexpand.c: Include tree-pretty-print.h and gimple-pretty-print.h. * cgraphunit.c: Include tree-pretty-print.h and gimple-pretty-print.h. * dwarf2out.c: Include tree-pretty-print.h. * except.c: Include tree-pretty-print.h. * gimple-pretty-print.c: Include tree-pretty-print.h and gimple-pretty-print.h. * gimplify.c: Include tree-pretty-print.h. * graphite-poly.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-cp.c: Include tree-pretty-print.h. * ipa-inline.c: Include gimple-pretty-print.h. * ipa-prop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-pure-const.c: Include gimple-pretty-print.h. * ipa-struct-reorg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-type-escape.c: Include tree-pretty-print.h. * print-rtl.c: Include tree-pretty-print.h. * print-tree.c: Include gimple-pretty-print.h. * sese.c: Include tree-pretty-print.h. * tree-affine.c: Include tree-pretty-print.h. * tree-browser.c: Include tree-pretty-print.h. * tree-call-cdce.c: Include gimple-pretty-print.h. * tree-cfg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-chrec.c: Include tree-pretty-print.h. * tree-data-ref.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-dfa.c: Include tree-pretty-print.h. * tree-if-conv.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-inline.c: Include tree-pretty-print.h. * tree-into-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-nrv.c: Include tree-pretty-print.h. * tree-object-size.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-outof-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-parloops.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-predcom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-scalar-evolution.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-sra.c: Include tree-pretty-print.h. * tree-ssa-address.c: Include tree-pretty-print.h. * tree-ssa-alias.c: Include tree-pretty-print.h. * tree-ssa-ccp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-coalesce.c: Include tree-pretty-print.h. * tree-ssa-copy.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-copyrename.c: Include tree-pretty-print.h. * tree-ssa-dce.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dse.c: Include gimple-pretty-print.h. * tree-ssa-forwprop.c: Include tree-pretty-print.h. * tree-ssa-ifcombine.c: Include tree-pretty-print.h. * tree-ssa-live.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-im.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivcanon.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivopts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-niter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-prefetch.c: Include tree-pretty-print.h. * tree-ssa-math-opts.c: Include gimple-pretty-print.h. * tree-ssa-operands.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-phiprop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-pre.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-propagate.c: Include gimple-pretty-print.h. * tree-ssa-reassoc.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sccvn.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sink.c: Include gimple-pretty-print.h. * tree-ssa-ter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-uninit.c: Include gimple-pretty-print.h. * tree-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-stdarg.c: Include gimple-pretty-print.h. * tree-switch-conversion.c: Include gimple-pretty-print.h. * tree-tailcall.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-data-refs.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop-manip.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-patterns.c: Include gimple-pretty-print.h. * tree-vect-slp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-stmts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vectorizer.c: Include tree-pretty-print.h. * tree-vrp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * value-prof.c: Include tree-pretty-print.h and gimple-pretty-print.h. * var-tracking.c: Include tree-pretty-print.h. * Makefile.in (OBJS-common): Add tree-diagnostic.o. (tree-diagnostic.o): New dependencies. (c-objc-common.o, c-pretty-print.o, langhooks.o, tree.o, tree-inline.o, print-tree.o, stor-layout.o, tree-ssa-uninit.o, tree-ssa.o, tree-into-ssa.o, tree-ssa-ter.o, tree-ssa-coalesce.o, tree-outof-ssa.o, tree-ssa-forwprop.o, tree-ssa-phiprop.o, tree-ssa-ifcombine.o, tree-nrv.o, tree-ssa-copy.o, tree-ssa-propagate.o, tree-ssa-dom.o, tree-ssa-uncprop.o, tree-ssa-live.o, tree-ssa-copyrename.o, tree-ssa-pre.o, tree-ssa-sccvn.o, tree-vrp.o, tree-cfg.o, tree-tailcall.o, tree-ssa-sink.o, tree-if-conv.o, tree-dfa.o, tree-ssa-operands.o, tree-ssa-address.o, tree-ssa-loop-niter.o, tree-ssa-loop-ivcanon.o, tree-ssa-loop-prefetch.o, tree-predcom.o, tree-ssa-loop-ivopts.o, tree-affine.o, tree-ssa-loop-im.o, tree-ssa-math-opts.o, tree-ssa-alias.o, tree-ssa-reassoc.o, gimplify.o, tree-browser.o, tree-chrec.o, tree-scalar-evolution.o, tree-data-ref.o, sese.o, graphite-poly.o, tree-vect-loop.o, tree-vect-loop-manip.o, tree-vect-patterns.o, tree-vect-slp.o, tree-vect-stmts.o, tree-vect-data-refs.o, tree-vectorizer.o, tree-parloops.o, tree-stdarg.o, tree-object-size.o, gimple-pretty-print.o, tree-pretty-print.o, diagnostic.o, toplev.o, print-rtl.o, except.o, dwarf2out.o, cgraphunit.o, ipa-prop.o, ipa-cp.o, ipa-inline.o, ipa-pure-const.o, ipa-type-escape.o, ipa-struct-reorg.o, tree-ssa-dce.o, tree-call-cdce.o, tree-ssa-ccp.o, tree-sra.o, tree-switch-conversion.o, var-tracking.o, value-prof.o, cfgexpand.o, pretty-print.o): Update dependencies. cp: * error.c: Include tree-diagnostic.h and tree-pretty-print.h. (cp_print_error_function): Use diagnostic_abstract_origin macro. (cp_printer): Handle %K here using percent_K_format. * cxx-pretty-print.c: Include tree-pretty-print.h. * Make-lang.in (cp/error.o, cp/cxx-pretty-print.o): Update dependencies. From-SVN: r159685
2010-05-22 00:34:26 +02:00
/* Auxiliary data for client. */
void *x_data;
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* Used to detect that the last caret was printed at the same location. */
location_t last_location;
/* Used to detect when the input file stack has changed since last
described. */
const line_map_ordinary *last_module;
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
int lock;
/* A copy of lang_hooks.option_lang_mask (). */
unsigned lang_mask;
bool inhibit_notes_p;
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
/* When printing source code, should the characters at carets and ranges
be colorized? (assuming colorization is on at all).
This should be true for frontends that generate range information
(so that the ranges of code are colorized),
and false for frontends that merely specify points within the
source code (to avoid e.g. colorizing just the first character in
a token, which would look strange). */
bool colorize_source_p;
diagnostics: add labeling of source ranges 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
2018-08-15 20:09:35 +02:00
/* When printing source code, should labelled ranges be printed? */
bool show_labels_p;
diagnostics: add line numbers to source (PR other/84889) 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
2018-08-09 17:32:13 +02:00
/* When printing source code, should there be a left-hand margin
showing line numbers? */
bool show_line_numbers_p;
diagnostics: add minimum width to left margin for line numbers 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
2018-10-16 00:16:59 +02:00
/* If printing source code, what should the minimum width of the margin
be? Line numbers will be right-aligned, and padded to this width. */
int min_margin_width;
/* Usable by plugins; if true, print a debugging ruler above the
source output. */
bool show_ruler_p;
Implement -fdiagnostics-parseable-fixits 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
2016-06-22 16:42:30 +02:00
/* True if -freport-bug option is used. */
bool report_bug;
Add GCC_EXTRA_DIAGNOSTIC_OUTPUT environment variable for fix-it hints GCC has had the ability to emit fix-it hints in machine-readable form since GCC 7 via -fdiagnostics-parseable-fixits and -fdiagnostics-generate-patch. The former emits additional specially-formatted lines to stderr; the option and its format were directly taken from a pre-existing option in clang. Ideally this could be used by IDEs so that the user can select specific fix-it hints and have the IDE apply them to the user's source code (perhaps turning them into clickable elements, perhaps with an "Apply All" option, etc). Eclipse CDT has supported this option in this way for a few years: https://bugs.eclipse.org/bugs/show_bug.cgi?id=497670 As a user of Emacs I would like Emacs to support such a feature. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25987 tracks supporting GCC fix-it output in Emacs. The discussion there identifies two issues with the existing option: (a) columns in the output are specified as byte-offsets within the line (for exact compatibility with the option in clang), whereas emacs would prefer to consume them as what GCC 11 calls "display columns". https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-column-unit (b) injecting a command-line option into the build is a fiddly manual step, varying between build systems. It's far easier for the user if Emacs simply sets an environment variable when compiling, GCC uses this to enable the option if it recognizes the value, and the emacs compilation buffer decodes the additional lines of output and adds appropriate widgets. In some ways it is a workaround for not having a language server. Doing it this way means that for the various combinations of older and newer GCC and older and newer Emacs that a sufficiently modern combination of both can automatically support the rich fix-it UI, whereas other combinations will either not provide the envvar, or silently ignore it, gracefully doing nothing extra. Hence this patch adds a new GCC_EXTRA_DIAGNOSTIC_OUTPUT environment variable to GCC which enables output of machine-parseable fix-it hints. GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v1 is equivalent to the existing -fdiagnostics-parseable-fixits option. GCC_EXTRA_DIAGNOSTIC_OUTPUT=fixits-v2 is the same, but changes the column output mode to "display columns" rather than bytes, as required by Emacs. The discussion in that Emacs bug has some concerns about the encoding of these lines, and, indeed, the encoding of GCC's stderr in general: currently we emit a mixture of bytes and UTF-8; I believe we emit filenames as bytes, diagnostic messages as UTF-8, and quote source code in the original encoding (PR other/93067 covers converting it to UTF-8 on output). This patch prints octal-escaped bytes for bytes within filenames and replacement text that aren't printable (as per -fdiagnostics-parseable-fixits). gcc/ChangeLog: * diagnostic.c (diagnostic_initialize): Eliminate parseable_fixits_p in favor of initializing extra_output_kind from GCC_EXTRA_DIAGNOSTIC_OUTPUT. (convert_column_unit): New function, split out from... (diagnostic_converted_column): ...this. (print_parseable_fixits): Add "column_unit" and "tabstop" params. Use them to call convert_column_unit on the column values. (diagnostic_report_diagnostic): Eliminate conditional on parseable_fixits_p in favor of a switch statement on extra_output_kind, passing the appropriate values to the new params of print_parseable_fixits. (selftest::test_print_parseable_fixits_none): Update for new params of print_parseable_fixits. (selftest::test_print_parseable_fixits_insert): Likewise. (selftest::test_print_parseable_fixits_remove): Likewise. (selftest::test_print_parseable_fixits_replace): Likewise. (selftest::test_print_parseable_fixits_bytes_vs_display_columns): New. (selftest::diagnostic_c_tests): Call it. * diagnostic.h (enum diagnostics_extra_output_kind): New. (diagnostic_context::parseable_fixits_p): Delete field in favor of... (diagnostic_context::extra_output_kind): ...this new field. * doc/invoke.texi (Environment Variables): Add GCC_EXTRA_DIAGNOSTIC_OUTPUT. * opts.c (common_handle_option): Update handling of OPT_fdiagnostics_parseable_fixits for change to diagnostic_context fields. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-GCC_EXTRA_DIAGNOSTIC_OUTPUT-fixits-v1.c: New file. * gcc.dg/plugin/diagnostic-test-show-locus-GCC_EXTRA_DIAGNOSTIC_OUTPUT-fixits-v2.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add them.
2021-01-14 22:25:02 +01:00
/* Used to specify additional diagnostic output to be emitted after the
rest of the diagnostic. This is for implementing
-fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */
enum diagnostics_extra_output_kind extra_output_kind;
diagnostics: Support conversion of tabs to spaces [PR49973] [PR86904] Supports conversion of tabs to spaces when outputting diagnostics. Also adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to control how the column number is output, thereby resolving the two PRs. gcc/c-family/ChangeLog: PR other/86904 * c-indentation.c (should_warn_for_misleading_indentation): Get global tabstop from the new source. * c-opts.c (c_common_handle_option): Remove handling of -ftabstop, which is now a common option. * c.opt: Likewise. gcc/ChangeLog: PR preprocessor/49973 PR other/86904 * common.opt: Handle -ftabstop here instead of in c-family options. Add -fdiagnostics-column-unit= and -fdiagnostics-column-origin= options. * opts.c (common_handle_option): Handle the new options. * diagnostic-format-json.cc (json_from_expanded_location): Add diagnostic_context argument. Use it to convert column numbers as per the new options. (json_from_location_range): Likewise. (json_from_fixit_hint): Likewise. (json_end_diagnostic): Pass the new context argument to helper functions above. Add "column-origin" field to the output. (test_unknown_location): Add the new context argument to calls to helper functions. (test_bad_endpoints): Likewise. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Support tabstop parameter. (layout_point::layout_point): Make use of class exploc_with_display_col. (layout_range::layout_range): Likewise. (struct line_bounds): Clarify that the units are now always display columns. Rename members accordingly. Add constructor. (layout::print_source_line): Add support for tab expansion. (make_range): Adapt to class layout_range changes. (layout::maybe_add_location_range): Likewise. (layout::layout): Adapt to class exploc_with_display_col changes. (layout::calculate_x_offset_display): Support tabstop parameter. (layout::print_annotation_line): Adapt to struct line_bounds changes. (layout::print_line): Likewise. (line_label::line_label): Add diagnostic_context argument. (get_affected_range): Likewise. (get_printed_columns): Likewise. (layout::print_any_labels): Adapt to struct line_label changes. (class correction): Add m_tabstop member. (correction::correction): Add tabstop argument. (correction::compute_display_cols): Use m_tabstop. (class line_corrections): Add m_context member. (line_corrections::line_corrections): Add diagnostic_context argument. (line_corrections::add_hint): Use m_context to handle tabstops. (layout::print_trailing_fixits): Adapt to class line_corrections changes. (test_layout_x_offset_display_utf8): Support tabstop parameter. (test_layout_x_offset_display_tab): New selftest. (test_one_liner_colorized_utf8): Likewise. (test_tab_expansion): Likewise. (test_diagnostic_show_locus_one_liner_utf8): Call the new tests. (diagnostic_show_locus_c_tests): Likewise. (test_overlapped_fixit_printing): Adapt to helper class and function changes. (test_overlapped_fixit_printing_utf8): Likewise. (test_overlapped_fixit_printing_2): Likewise. * diagnostic.h (enum diagnostics_column_unit): New enum. (struct diagnostic_context): Add members for the new options. (diagnostic_converted_column): Declare. (json_from_expanded_location): Add new context argument. * diagnostic.c (diagnostic_initialize): Initialize new members. (diagnostic_converted_column): New function. (maybe_line_and_column): Be willing to output a column of 0. (diagnostic_get_location_text): Convert column number as per the new options. (diagnostic_report_current_module): Likewise. (assert_location_text): Add origin and column_unit arguments for testing the new functionality. (test_diagnostic_get_location_text): Test the new functionality. * doc/invoke.texi: Document the new options and behavior. * input.h (location_compute_display_column): Add tabstop argument. * input.c (location_compute_display_column): Likewise. (test_cpp_utf8): Add selftests for tab expansion. * tree-diagnostic-path.cc (default_tree_make_json_for_path): Pass the new context argument to json_from_expanded_location(). libcpp/ChangeLog: PR preprocessor/49973 PR other/86904 * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, which is now handled by diagnostic_context. (class cpp_display_width_computation): New class. (cpp_byte_column_to_display_column): Add optional tabstop argument. (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * charset.c (cpp_display_width_computation::cpp_display_width_computation): New function. (cpp_display_width_computation::advance_display_cols): Likewise. (compute_next_display_width): Removed and implemented this functionality in a new function... (cpp_display_width_computation::process_next_codepoint): ...here. (cpp_byte_column_to_display_column): Added tabstop argument. Reimplemented in terms of class cpp_display_width_computation. (cpp_display_column_to_byte_column): Likewise. * init.c (cpp_create_reader): Remove handling of -ftabstop, which is now handled by diagnostic_context. gcc/testsuite/ChangeLog: PR preprocessor/49973 PR other/86904 * c-c++-common/Wmisleading-indentation-3.c: Adjust expected output for new defaults. * c-c++-common/Wmisleading-indentation.c: Likewise. * c-c++-common/diagnostic-format-json-1.c: Likewise. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise. * c-c++-common/diagnostic-format-json-5.c: Likewise. * c-c++-common/missing-close-symbol.c: Likewise. * g++.dg/diagnostic/bad-binary-ops.C: Likewise. * g++.dg/parse/error4.C: Likewise. * g++.old-deja/g++.brendan/crash11.C: Likewise. * g++.old-deja/g++.pt/overload2.C: Likewise. * g++.old-deja/g++.robertl/eb109.C: Likewise. * gcc.dg/analyzer/malloc-paths-9.c: Likewise. * gcc.dg/bad-binary-ops.c: Likewise. * gcc.dg/format/branch-1.c: Likewise. * gcc.dg/format/pr79210.c: Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. * gcc.dg/plugin/diagnostic-test-string-literals-1.c: Likewise. * gcc.dg/redecl-4.c: Likewise. * gfortran.dg/diagnostic-format-json-1.F90: Likewise. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. * go.dg/arrayclear.go: Add a comment explaining why adding a comment was necessary to work around a dejagnu bug. * c-c++-common/diagnostic-units-1.c: New test. * c-c++-common/diagnostic-units-2.c: New test. * c-c++-common/diagnostic-units-3.c: New test. * c-c++-common/diagnostic-units-4.c: New test. * c-c++-common/diagnostic-units-5.c: New test. * c-c++-common/diagnostic-units-6.c: New test. * c-c++-common/diagnostic-units-7.c: New test. * c-c++-common/diagnostic-units-8.c: New test.
2020-07-14 18:05:56 +02:00
/* What units to use when outputting the column number. */
enum diagnostics_column_unit column_unit;
/* The origin for the column number (1-based or 0-based typically). */
int column_origin;
/* The size of the tabstop for tab expansion. */
int tabstop;
diagnostics: escape non-ASCII source bytes for certain diagnostics This patch adds support to GCC's diagnostic subsystem for escaping certain bytes and Unicode characters when quoting source code. Specifically, this patch adds a new flag rich_location::m_escape_on_output which is a hint from a diagnostic that non-ASCII bytes in the pertinent lines of the user's source code should be escaped when printed. The patch sets this for the following diagnostics: - when complaining about stray bytes in the program (when these are non-printable) - when complaining about "null character(s) ignored"); - for -Wnormalized= (and generate source ranges for such warnings) The escaping is controlled by a new option: -fdiagnostics-escape-format=[unicode|bytes] For example, consider a diagnostic involing a source line containing the string "before" followed by the Unicode character U+03C0 ("GREEK SMALL LETTER PI", with UTF-8 encoding 0xCF 0x80) followed by the byte 0xBF (a stray UTF-8 trailing byte), followed by the string "after", where the diagnostic highlights the U+03C0 character. By default, this line will be printed verbatim to the user when reporting a diagnostic at it, as: beforeπXafter ^ (using X for the stray byte to avoid putting invalid UTF-8 in this commit message) If the diagnostic sets the "escape" flag, it will be printed as: before<U+03C0><BF>after ^~~~~~~~ with -fdiagnostics-escape-format=unicode (the default), or as: before<CF><80><BF>after ^~~~~~~~ if the user supplies -fdiagnostics-escape-format=bytes. This only affects how the source is printed; it does not affect how column numbers that are printed (as per -fdiagnostics-column-unit= and -fdiagnostics-column-origin=). gcc/c-family/ChangeLog: * c-lex.c (c_lex_with_flags): When complaining about non-printable CPP_OTHER tokens, set the "escape on output" flag. gcc/ChangeLog: * common.opt (fdiagnostics-escape-format=): New. (diagnostics_escape_format): New enum. (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE): New enum value. (DIAGNOSTICS_ESCAPE_FORMAT_BYTES): Likewise. * diagnostic-format-json.cc (json_end_diagnostic): Add "escape-source" attribute. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Replace "tabstop" param with a cpp_char_column_policy and add an "aspect" param. Use these to compute m_display_col accordingly. (struct char_display_policy): New struct. (layout::m_policy): New field. (layout::m_escape_on_output): New field. (def_policy): New function. (make_range): Update for changes to exploc_with_display_col ctor. (default_print_decoded_ch): New. (width_per_escaped_byte): New. (escape_as_bytes_width): New. (escape_as_bytes_print): New. (escape_as_unicode_width): New. (escape_as_unicode_print): New. (make_policy): New. (layout::layout): Initialize new fields. Update m_exploc ctor call for above change to ctor. (layout::maybe_add_location_range): Update for changes to exploc_with_display_col ctor. (layout::calculate_x_offset_display): Update for change to cpp_display_width. (layout::print_source_line): Pass policy to cpp_display_width_computation. Capture cpp_decoded_char when calling process_next_codepoint. Move printing of source code to m_policy.m_print_cb. (line_label::line_label): Pass in policy rather than context. (layout::print_any_labels): Update for change to line_label ctor. (get_affected_range): Pass in policy rather than context, updating calls to location_compute_display_column accordingly. (get_printed_columns): Likewise, also for cpp_display_width. (correction::correction): Pass in policy rather than tabstop. (correction::compute_display_cols): Pass m_policy rather than m_tabstop to cpp_display_width. (correction::m_tabstop): Replace with... (correction::m_policy): ...this. (line_corrections::line_corrections): Pass in policy rather than context. (line_corrections::m_context): Replace with... (line_corrections::m_policy): ...this. (line_corrections::add_hint): Update to use m_policy rather than m_context. (line_corrections::add_hint): Likewise. (layout::print_trailing_fixits): Likewise. (selftest::test_display_widths): New. (selftest::test_layout_x_offset_display_utf8): Update to use policy rather than tabstop. (selftest::test_one_liner_labels_utf8): Add test of escaping source lines. (selftest::test_diagnostic_show_locus_one_liner_utf8): Update to use policy rather than tabstop. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_utf8): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_tab_expansion): Likewise. (selftest::test_escaping_bytes_1): New. (selftest::test_escaping_bytes_2): New. (selftest::diagnostic_show_locus_c_tests): Call the new tests. * diagnostic.c (diagnostic_initialize): Initialize context->escape_format. (convert_column_unit): Update to use default character width policy. (selftest::test_diagnostic_get_location_text): Likewise. * diagnostic.h (enum diagnostics_escape_format): New enum. (diagnostic_context::escape_format): New field. * doc/invoke.texi (-fdiagnostics-escape-format=): New option. (-fdiagnostics-format=): Add "escape-source" attribute to examples of JSON output, and document it. * input.c (location_compute_display_column): Pass in "policy" rather than "tabstop", passing to cpp_byte_column_to_display_column. (selftest::test_cpp_utf8): Update to use cpp_char_column_policy. * input.h (class cpp_char_column_policy): New forward decl. (location_compute_display_column): Pass in "policy" rather than "tabstop". * opts.c (common_handle_option): Handle OPT_fdiagnostics_escape_format_. * selftest.c (temp_source_file::temp_source_file): New ctor overload taking a size_t. * selftest.h (temp_source_file::temp_source_file): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/diagnostic-format-json-1.c: Add regexp to consume "escape-source" attribute. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise, twice. * c-c++-common/diagnostic-format-json-5.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: New test. * gcc.dg/cpp/warn-normalized-4-unicode.c: New test. * gcc.dg/encoding-issues-bytes.c: New test. * gcc.dg/encoding-issues-unicode.c: New test. * gfortran.dg/diagnostic-format-json-1.F90: Add regexp to consume "escape-source" attribute. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. libcpp/ChangeLog: * charset.c (convert_escape): Use encoding_rich_location when complaining about nonprintable unknown escape sequences. (cpp_display_width_computation::::cpp_display_width_computation): Pass in policy rather than tabstop. (cpp_display_width_computation::process_next_codepoint): Add "out" param and populate *out if non-NULL. (cpp_display_width_computation::advance_display_cols): Pass NULL to process_next_codepoint. (cpp_byte_column_to_display_column): Pass in policy rather than tabstop. Pass NULL to process_next_codepoint. (cpp_display_column_to_byte_column): Pass in policy rather than tabstop. * errors.c (cpp_diagnostic_get_current_location): New function, splitting out the logic from... (cpp_diagnostic): ...here. (cpp_warning_at): New function. (cpp_pedwarning_at): New function. * include/cpplib.h (cpp_warning_at): New decl for rich_location. (cpp_pedwarning_at): Likewise. (struct cpp_decoded_char): New. (struct cpp_char_column_policy): New. (cpp_display_width_computation::cpp_display_width_computation): Replace "tabstop" param with "policy". (cpp_display_width_computation::process_next_codepoint): Add "out" param. (cpp_display_width_computation::m_tabstop): Replace with... (cpp_display_width_computation::m_policy): ...this. (cpp_byte_column_to_display_column): Replace "tabstop" param with "policy". (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * include/line-map.h (rich_location::escape_on_output_p): New. (rich_location::set_escape_on_output): New. (rich_location::m_escape_on_output): New. * internal.h (cpp_diagnostic_get_current_location): New decl. (class encoding_rich_location): New. * lex.c (skip_whitespace): Use encoding_rich_location when complaining about null characters. (warn_about_normalization): Generate a source range when complaining about improperly normalized tokens, rather than just a point, and use encoding_rich_location so that the source code is escaped on printing. * line-map.c (rich_location::rich_location): Initialize m_escape_on_output. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-10-19 00:55:31 +02:00
/* How should non-ASCII/non-printable bytes be escaped when
a diagnostic suggests escaping the source code on output. */
enum diagnostics_escape_format escape_format;
/* If non-NULL, an edit_context to which fix-it hints should be
applied, for generating patches. */
edit_context *edit_context_ptr;
Add support for grouping of related diagnostics (PR other/84889) 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
2018-08-20 23:06:46 +02:00
/* How many diagnostic_group instances are currently alive. */
int diagnostic_group_nesting_depth;
/* How many diagnostics have been emitted since the bottommost
diagnostic_group was pushed. */
int diagnostic_group_emission_count;
/* Optional callbacks for handling diagnostic groups. */
/* If non-NULL, this will be called immediately before the first
time a diagnostic is emitted within a stack of groups. */
void (*begin_group_cb) (diagnostic_context * context);
/* If non-NULL, this will be called when a stack of groups is
popped if any diagnostics were emitted within that group. */
void (*end_group_cb) (diagnostic_context * context);
Machine-readable diagnostic output (PR other/19165) 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
2018-11-15 15:32:41 +01:00
/* Callback for final cleanup. */
void (*final_cb) (diagnostic_context *context);
/* Callback to set the locations of call sites along the inlining
stack corresponding to a diagnostic location. Needed to traverse
the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
of a diagnostic's location. */
void (*set_locations_cb)(diagnostic_context *, diagnostic_info *);
/* Include files that diagnostic_report_current_module has already listed the
include path for. */
hash_set<location_t, false, location_hash> *includes_seen;
};
static inline void
diagnostic_inhibit_notes (diagnostic_context * context)
{
context->inhibit_notes_p = true;
}
/* Client supplied function to announce a diagnostic. */
#define diagnostic_starter(DC) (DC)->begin_diagnostic
/* Client supplied function called after a diagnostic message is
displayed. */
#define diagnostic_finalizer(DC) (DC)->end_diagnostic
diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. * diagnostic.c: Don't include tm.h, tree.h, tm_p.h, langhooks.h or langhooks-def.h. (diagnostic_initialize): Initialize x_data not last_function. (diagnostic_report_current_function): Move to tree-diagnostic.c. (default_diagnostic_starter): Call diagnostic_report_current_module not diagnostic_report_current_function. (diagnostic_report_diagnostic): Initialize x_data not abstract_origin. (verbatim): Likewise. * diagnostic.h (struct diagnostic_info): Change abstract_origin to x_data. (struct diagnostic_context): Change last_function to x_data. (diagnostic_auxiliary_data): Replace with diagnostic_context_auxiliary_data and diagnostic_info_auxiliary_data. (diagnostic_last_function_changed, diagnostic_set_last_function, diagnostic_report_current_function): Move to tree-diagnostic.h. (print_declaration, dump_generic_node, print_generic_stmt, print_generic_stmt_indented, print_generic_expr, print_generic_decl, debug_c_tree, dump_omp_clauses, print_call_name, debug_generic_expr, debug_generic_stmt, debug_tree_chain, default_tree_printer): Move to tree-pretty-print.h. (debug_gimple_stmt, debug_gimple_seq, print_gimple_seq, print_gimple_stmt, print_gimple_expr, dump_gimple_stmt): Move to gimple-pretty-print.h. * pretty-print.c: Don't include tree.h (pp_base_format): Don't handle %K here. (pp_base_tree_identifier): Move to tree-pretty-print.c. * pretty-print.h (text_info): Change abstract_origin to x_data. (pp_tree_identifier, pp_unsupported_tree, pp_base_tree_identifier): Move to tree-pretty-print.h. * gimple-pretty-print.h, tree-diagnostic.c, tree-diagnostic.h, tree-pretty-print.h: New files. * tree-pretty-print.c: Include tree-pretty-print.h. (percent_K_format): New. Moved from pretty-print.c. (pp_base_tree_identifier): Move from pretty-print.c. * c-objc-common.c: Include tree-pretty-print.h. (c_tree_printer): Handle %K here. * langhooks.c: Include tree-diagnostic.h. (lhd_print_error_function): Use diagnostic_abstract_origin macro. * toplev.c: Include tree-diagnostic.h and tree-pretty-print.h. (default_tree_printer): Handle %K using percent_K_format. (general_init): Use default_tree_diagnostic_starter. * tree.c: Include tree-diagnostic.h and tree-pretty-print.h. (free_lang_data): Use default_tree_diagnostic_starter. * c-pretty-print.c: Include tree-pretty-print.h. * cfgexpand.c: Include tree-pretty-print.h and gimple-pretty-print.h. * cgraphunit.c: Include tree-pretty-print.h and gimple-pretty-print.h. * dwarf2out.c: Include tree-pretty-print.h. * except.c: Include tree-pretty-print.h. * gimple-pretty-print.c: Include tree-pretty-print.h and gimple-pretty-print.h. * gimplify.c: Include tree-pretty-print.h. * graphite-poly.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-cp.c: Include tree-pretty-print.h. * ipa-inline.c: Include gimple-pretty-print.h. * ipa-prop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-pure-const.c: Include gimple-pretty-print.h. * ipa-struct-reorg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * ipa-type-escape.c: Include tree-pretty-print.h. * print-rtl.c: Include tree-pretty-print.h. * print-tree.c: Include gimple-pretty-print.h. * sese.c: Include tree-pretty-print.h. * tree-affine.c: Include tree-pretty-print.h. * tree-browser.c: Include tree-pretty-print.h. * tree-call-cdce.c: Include gimple-pretty-print.h. * tree-cfg.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-chrec.c: Include tree-pretty-print.h. * tree-data-ref.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-dfa.c: Include tree-pretty-print.h. * tree-if-conv.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-inline.c: Include tree-pretty-print.h. * tree-into-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-nrv.c: Include tree-pretty-print.h. * tree-object-size.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-outof-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-parloops.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-predcom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-scalar-evolution.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-sra.c: Include tree-pretty-print.h. * tree-ssa-address.c: Include tree-pretty-print.h. * tree-ssa-alias.c: Include tree-pretty-print.h. * tree-ssa-ccp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-coalesce.c: Include tree-pretty-print.h. * tree-ssa-copy.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-copyrename.c: Include tree-pretty-print.h. * tree-ssa-dce.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dom.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-dse.c: Include gimple-pretty-print.h. * tree-ssa-forwprop.c: Include tree-pretty-print.h. * tree-ssa-ifcombine.c: Include tree-pretty-print.h. * tree-ssa-live.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-im.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivcanon.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-ivopts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-niter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-loop-prefetch.c: Include tree-pretty-print.h. * tree-ssa-math-opts.c: Include gimple-pretty-print.h. * tree-ssa-operands.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-phiprop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-pre.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-propagate.c: Include gimple-pretty-print.h. * tree-ssa-reassoc.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sccvn.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-sink.c: Include gimple-pretty-print.h. * tree-ssa-ter.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-ssa-uninit.c: Include gimple-pretty-print.h. * tree-ssa.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-stdarg.c: Include gimple-pretty-print.h. * tree-switch-conversion.c: Include gimple-pretty-print.h. * tree-tailcall.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-data-refs.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop-manip.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-loop.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-patterns.c: Include gimple-pretty-print.h. * tree-vect-slp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vect-stmts.c: Include tree-pretty-print.h and gimple-pretty-print.h. * tree-vectorizer.c: Include tree-pretty-print.h. * tree-vrp.c: Include tree-pretty-print.h and gimple-pretty-print.h. * value-prof.c: Include tree-pretty-print.h and gimple-pretty-print.h. * var-tracking.c: Include tree-pretty-print.h. * Makefile.in (OBJS-common): Add tree-diagnostic.o. (tree-diagnostic.o): New dependencies. (c-objc-common.o, c-pretty-print.o, langhooks.o, tree.o, tree-inline.o, print-tree.o, stor-layout.o, tree-ssa-uninit.o, tree-ssa.o, tree-into-ssa.o, tree-ssa-ter.o, tree-ssa-coalesce.o, tree-outof-ssa.o, tree-ssa-forwprop.o, tree-ssa-phiprop.o, tree-ssa-ifcombine.o, tree-nrv.o, tree-ssa-copy.o, tree-ssa-propagate.o, tree-ssa-dom.o, tree-ssa-uncprop.o, tree-ssa-live.o, tree-ssa-copyrename.o, tree-ssa-pre.o, tree-ssa-sccvn.o, tree-vrp.o, tree-cfg.o, tree-tailcall.o, tree-ssa-sink.o, tree-if-conv.o, tree-dfa.o, tree-ssa-operands.o, tree-ssa-address.o, tree-ssa-loop-niter.o, tree-ssa-loop-ivcanon.o, tree-ssa-loop-prefetch.o, tree-predcom.o, tree-ssa-loop-ivopts.o, tree-affine.o, tree-ssa-loop-im.o, tree-ssa-math-opts.o, tree-ssa-alias.o, tree-ssa-reassoc.o, gimplify.o, tree-browser.o, tree-chrec.o, tree-scalar-evolution.o, tree-data-ref.o, sese.o, graphite-poly.o, tree-vect-loop.o, tree-vect-loop-manip.o, tree-vect-patterns.o, tree-vect-slp.o, tree-vect-stmts.o, tree-vect-data-refs.o, tree-vectorizer.o, tree-parloops.o, tree-stdarg.o, tree-object-size.o, gimple-pretty-print.o, tree-pretty-print.o, diagnostic.o, toplev.o, print-rtl.o, except.o, dwarf2out.o, cgraphunit.o, ipa-prop.o, ipa-cp.o, ipa-inline.o, ipa-pure-const.o, ipa-type-escape.o, ipa-struct-reorg.o, tree-ssa-dce.o, tree-call-cdce.o, tree-ssa-ccp.o, tree-sra.o, tree-switch-conversion.o, var-tracking.o, value-prof.o, cfgexpand.o, pretty-print.o): Update dependencies. cp: * error.c: Include tree-diagnostic.h and tree-pretty-print.h. (cp_print_error_function): Use diagnostic_abstract_origin macro. (cp_printer): Handle %K here using percent_K_format. * cxx-pretty-print.c: Include tree-pretty-print.h. * Make-lang.in (cp/error.o, cp/cxx-pretty-print.o): Update dependencies. From-SVN: r159685
2010-05-22 00:34:26 +02:00
/* Extension hooks for client. */
#define diagnostic_context_auxiliary_data(DC) (DC)->x_data
#define diagnostic_info_auxiliary_data(DI) (DI)->x_data
Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. Remove pedwarn_with_decl, warning_with_decl and error_with_decl from GCC. * calls.c (try_to_integrate): Don't use xxx_with_decl. (expand_call): Likewise. * dwarfout.c (output_reg_number): Likewise. * expr.c (expand_expr): Likewise. * function.c (assign_temp): Likewise. (uninitialized_vars_warning): Likewise. (setjmp_args_warning): Likewise. (expand_function_end): Likewise. * stmt.c (fixup_gotos): Likewise. (warn_about_unused_variables): Likewise. (expand_end_bindings): Likewise. * stor-layout.c (layout_decl): Likewise. (place_field): Likewise. * toplev.c (check_global_declarations): Likewise. (rest_of_handle_inlining): Likewise. (default_tree_printer): New function. (general_init): Initialize diagnostic machinery before routing signals to the ICE machinery. Set default tree printer. * toplev.h (pedwarn_with_decl): Remove declaration. (warning_with_decl): Likewise. (error_with_decl): Likewise. (pedwarn): Remove attribute for the time being. * tree-inline.c (expand_call_inline): Don't use xxx_with_decl. * varasm.c (named_section): Likewise. (make_decl_rtl): Likewise. (assemble_variable): Likewise. (merge_weak): Likewise. (declare_weak): Likewise. * diagnostic.h: Move non-diagnostic stuff into pretty-print.h. * diagnostic.c: Move non-diagnostic stuff into pretty-print.c. (format_with_decl): Remove. (diagnostic_for_decl): Likewise. (pedwarn_with_decl): Likewise. (warning_with_decl): Likewise. (error_with_decl): Likewise. (diagnostic_initialize): Adjust. (diagnostic_count_diagnostic): Likewise. (announce_function): Likewise. (lhd_print_error_function): Likewise. (diagnostic_report_current_module): Likewise. (default_diagnostic_starter): Likewise. (diagnostic_report_diagnostic): Likewise. (default_diagnostic_finalizer): Likewise. (verbatim): Likewise. (error): Likewise. (warning): Likewise. * opts.c (common_handle_option): Likewise. * pretty-print.c: New file. * c-pretty-print.h (pp_base): Override. * c-pretty-print.c: Adjust use of macros throughout. (pp_buffer): New macro. (pp_newline): Likewise. * c-objc-common.c (c_tree_printer): Adjust prototype. Tidy. * Makefile.in (DIAGNOSTIC_H): New variable. (c-errors.o): Use it. (c-objc-common.o): Likewise. (c-common.o): Likewise. (c-opts.o): Likewise. (c-format.o): Likewise. (diagnostic.o): Likewise. (opts.o): Likewise. (toplev.o): Likewise. (rtl-error.o): Likewise. (dwarf2out.o): Likewise. (jump.o): Likewise. (pretty-print.o): New rule. cp/ * Make-lang.in (cp/error.o): Depend on DIAGNOSTIC_H. * error.c: Use the new pretty-printer fraamework. From-SVN: r69773
2003-07-25 11:52:32 +02:00
/* Same as pp_format_decoder. Works on 'diagnostic_context *'. */
pretty-print.h (pp_set_line_maximum_length): Make macro. * pretty-print.h (pp_set_line_maximum_length): Make macro. (pp_set_prefix): Likewise. (pp_destroy_prefix): Likewise. (pp_remaining_character_count_for_line): Likewise. (pp_clear_output_area): Likewise. (pp_formatted_text): Likewise. (pp_last_position_in_text): Likewise. (pp_emit_prefix): Likewise. (pp_append_text): Likewise. (pp_flush): Likewise. (pp_format_text): Likewise. (pp_format_verbatim): Likewise. (pp_tree_identifier): Tidy. * pretty-print.c (pp_base_format_text): Rename from pp_format_text. (pp_base_format_verbatim): Rename from pp_format_verbatim. (pp_base_flush): Rename from pp_flush. (pp_base_set_line_maximum_length): Rename from pp_set_line_maximum_length. (pp_base_clear_output_area): Rename from pp_clear_output_area. (pp_base_set_prefix): Rename from pp_set_prefix. (pp_base_destroy_prefix): Rename from pp_destroy_prefix. (pp_base_emit_prefix): Rename from pp_emit_prefix. (pp_base_append_text): Rename from pp_append_text. (pp_base_formatted_text): Rename from pp_formatted_text. (pp_base_last_position_in_text): Rename from pp_last_position_in_text. (pp_base_remaining_character_count_for_line): Rename from pp_remaining_character_count_for_line. * diagnostic.h (diagnostic_format_decoder): Tidy. (diagnostic_flush_buffer): Likewise. * c-pretty-print.h: (pp_c_string_literal): Declare. (pp_c_real_literal): Likewise. (pp_c_integer_literal): Likewise. * c-pretty-print.c (pp_c_char): Use pp_string in lieu of pp_identifier. (pp_c_character_literal): Tidy. (pp_c_string_literal): Make public. (pp_c_bool_literal): Likewise. (pp_c_integer_literal): Likewise. (pp_c_real_literal): Likewise. * Makefile.in (C_PRETTY_PRINT_H): New variable. (c-pretty-print.o): Update dependence. cp/ * cxx-pretty-print.h: New file. * cxx-pretty-print.c: Likewise. * error.c (scratch_pretty_printer): Change type. (init_error): Tidy. (dump_aggr_type): Likewise. (dump_global_iord): Likewise. (dump_expr): Likewise. (dump_char): Remove. * cp-lang.c (LANG_HOOKS_INITIALIZE_DIAGNOSTITCS): Define. (cxx_initialize_diagnostics): New function. * Make-lang.in (CXX_OBJS): Add cp/cxx-pretty-print.o (CXX_PRETTY_PRINT_H): New variable. (cp/cxx-pretty-print.o): New rule. (cp/cp-lang.o): Update dependence. (cp/error.o): Likewise. From-SVN: r70182
2003-08-05 21:23:14 +02:00
#define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder)
/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
pretty-print.h (PP_NL_ARGMAX): New. gcc: * pretty-print.h (PP_NL_ARGMAX): New. (text_info): Add locus. (struct chunk_info): New. (output_buffer): Add formatted_obstack, chunk_obstack, and cur_chunk_array. Change obstack to a pointer. (pp_wrapping_mode_t, pp_wrapping_mode, pp_set_verbatim_wrapping): New. (struct pretty_print_info): Replace ideal_maximum_length and prefixing_rule with wrapping. (pp_line_cutoff, pp_prefixing_rule): Update to match. Update prototypes and wrapper macros throughout. * pretty-print.c (pp_formatted_text_data, pp_append_r) (pp_base_clear_output_area, pp_construct, pp_base_formatted_text) (pp_base_last_position_in_text, pp_base_newline, pp_base_character): Update for changes to pp structure. (pp_base_prepare_to_format, pp_base_format_text): Delete. (pp_base_format, pp_base_output_formatted_text): New functions. (pp_base_format_verbatim): Use pp_set_verbatim_wrapping. (pp_verbatim): Clear text.locus. (pp_printf): Likewise. Use pp_format and pp_output_formatted_text. * c-objc-common.c (c_tree_printer): Update function signature. * diagnostic.c (diagnostic_initialize): Update for changes to pp structure. (diagnostic_report_diagnostic): Call pp_format and then pp_output_formatted_text. (verbatim): Clear text.locus. * diagnostic.h (diagnostic_prefixing_rule, diagnostic_line_cutoff): Update for changes to pp structure. * c-lang.c: No need to include c-pretty-print.h. * Makefile.in: Remove bogus line containing only a tab. (c-lang.o): Update dependencies. * toplev.c (announce_function): Don't use verbatim. (default_tree_printer): Update signature. * objc/objc-lang.c: No need to include c-pretty-print.h. * objc/Make-lang.in: Update dependencies. gcc/cp: * cp-lang.c: No need to include cxx-pretty-print.h. * error.c (cp_printer): Update signature. No need to process flags. (print_instantiation_partial_context): Output last newline with pp_base_newline. * Make-lang.in: Update dependencies. gcc/objcp: * objcp-lang.c: No need to include cxx-pretty-print.h. * Make-lang.in: Update dependencies. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r101481
2005-07-01 01:09:06 +02:00
#define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule)
/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
#define diagnostic_abort_on_error(DC) \
(DC)->abort_on_error = true
/* This diagnostic_context is used by front-ends that directly output
diagnostic.c (output_maximum_width): Remove. 2000-06-06 Gabriel Dos Reis <gdr@codesourcery.com> * diagnostic.c (output_maximum_width): Remove. (doing_line_wrapping): Tweak. (diagnostic_buffer): New object. (global_output_buffer): New object. (output_destroy_prefix): New function. (default_initialize_buffer): Likewise. (reshape_diagnostic_buffer): Likewise. (initialize_diagnostics): Likewise. (output_clear): Tweak. (line_wrapper_printf): Adjust call to init_output_buffer. (vline_wrapper_message_with_location): Likewise. Use output_destroy_prefix. (v_message_with_decl): Likewise. * diagnostic.h (struct output_buffer): Constify prefix. (init_output_buffer, output_get_prefix): Constify. (diagnostic_message_length_per_line): Likewise. (reshape_diagnostic_buffer): Declare. (default_initialize_buffer): Declare. (initialize_diagnostics): Declare. (diagnostic_buffer): Declare new obbject. * toplev.c: #include diagnostic.h (display_help): Document diagnostic formatting options. (decode_f_option): Handle diagnostic formatting options. (main): Setup initialization for diagnostic messages outputter. * toplev.h (set_message_length): Remove. * Makefile.in (toplev.o): Depends upon diagnostic.h * invoke.texi : Document diagnostics formatting options. cp/ 2000-06-06 Gabriel Dos Reis <gdr@codesourcery.com> * lex.c (lang_init_options): Tweak. * decl2.c: Remove #inclusion of diagnostic.h (lang_decode_option): Move diagnostic formatting options to toplevel. * lang-options.h: Remove documentation for diagnostic options. * Makefile.in (lex.o): Depends upon diagnostic.h From-SVN: r34435
2000-06-06 22:11:40 +02:00
diagnostic messages without going through `error', `warning',
and similar functions. */
extern diagnostic_context *global_dc;
diagnostic.c (output_maximum_width): Remove. 2000-06-06 Gabriel Dos Reis <gdr@codesourcery.com> * diagnostic.c (output_maximum_width): Remove. (doing_line_wrapping): Tweak. (diagnostic_buffer): New object. (global_output_buffer): New object. (output_destroy_prefix): New function. (default_initialize_buffer): Likewise. (reshape_diagnostic_buffer): Likewise. (initialize_diagnostics): Likewise. (output_clear): Tweak. (line_wrapper_printf): Adjust call to init_output_buffer. (vline_wrapper_message_with_location): Likewise. Use output_destroy_prefix. (v_message_with_decl): Likewise. * diagnostic.h (struct output_buffer): Constify prefix. (init_output_buffer, output_get_prefix): Constify. (diagnostic_message_length_per_line): Likewise. (reshape_diagnostic_buffer): Declare. (default_initialize_buffer): Declare. (initialize_diagnostics): Declare. (diagnostic_buffer): Declare new obbject. * toplev.c: #include diagnostic.h (display_help): Document diagnostic formatting options. (decode_f_option): Handle diagnostic formatting options. (main): Setup initialization for diagnostic messages outputter. * toplev.h (set_message_length): Remove. * Makefile.in (toplev.o): Depends upon diagnostic.h * invoke.texi : Document diagnostics formatting options. cp/ 2000-06-06 Gabriel Dos Reis <gdr@codesourcery.com> * lex.c (lang_init_options): Tweak. * decl2.c: Remove #inclusion of diagnostic.h (lang_decode_option): Move diagnostic formatting options to toplevel. * lang-options.h: Remove documentation for diagnostic options. * Makefile.in (lex.o): Depends upon diagnostic.h From-SVN: r34435
2000-06-06 22:11:40 +02:00
/* Returns whether the diagnostic framework has been intialized already and is
ready for use. */
#define diagnostic_ready_p() (global_dc->printer != NULL)
/* The total count of a KIND of diagnostics emitted so far. */
#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
Makefile.in (c-parse.o): Depend on diagnostic.h gcc/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Makefile.in (c-parse.o): Depend on diagnostic.h (dwarf2out.o): Likewise. * dwarf2out.c: #include diagnostic.h * toplev.h (warningcount, errorcount, sorrycount): Remove declarations. * toplev.c (warningcount, errorcount, sorrycount): Remove definitions. * diagnostic.h (struct output_buffer): Reorder fields. (diagnostic_kind_count): New macro. (errorcount, warningcount, sorrycount): Define as macros. (diagnostic_report_warnings_p): New macro. (output_state): Add diagnostic_count field. * diagnostic.c (warningcount, errorcount, inhibit_warnings): Remove tentative declaration. (count_error): Use diagnostic_report_warnings_p. * c-parse.in: #include diagnostic.h ch/ 2001-06-10 Gabriel Dos Reis <gdr@codesourcery.com> * decl.c: #include diagnostic.h * actions.c: #include diagnostic.h * Makefile.in (actions.o): Depend on diagnostic.h (decl.o): Depend on diagnostic.h cp/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Make-lang.in (cp/call.o): Depend on diagnostic.h (cp/typeck.o): Depend on diagnostic.h (cp/typeck2.o): Depend on diagnostic.h (cp/repo.o): Depend on dignostic.h * typeck.c: #include diagnostic.h (convert_for_initialization): Remove extern declaration for warningcount and errorcount. * call.c: #include diagnostic.h (convert_like_real): Remove extern declaration for warnincount and errorcount. * repo.c: #include diagnostic.h * typeck2.c: #include diagnostic.h From-SVN: r43140
2001-06-10 15:48:04 +02:00
/* The number of errors that have been issued so far. Ideally, these
would take a diagnostic_context as an argument. */
#define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
Makefile.in (c-parse.o): Depend on diagnostic.h gcc/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Makefile.in (c-parse.o): Depend on diagnostic.h (dwarf2out.o): Likewise. * dwarf2out.c: #include diagnostic.h * toplev.h (warningcount, errorcount, sorrycount): Remove declarations. * toplev.c (warningcount, errorcount, sorrycount): Remove definitions. * diagnostic.h (struct output_buffer): Reorder fields. (diagnostic_kind_count): New macro. (errorcount, warningcount, sorrycount): Define as macros. (diagnostic_report_warnings_p): New macro. (output_state): Add diagnostic_count field. * diagnostic.c (warningcount, errorcount, inhibit_warnings): Remove tentative declaration. (count_error): Use diagnostic_report_warnings_p. * c-parse.in: #include diagnostic.h ch/ 2001-06-10 Gabriel Dos Reis <gdr@codesourcery.com> * decl.c: #include diagnostic.h * actions.c: #include diagnostic.h * Makefile.in (actions.o): Depend on diagnostic.h (decl.o): Depend on diagnostic.h cp/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Make-lang.in (cp/call.o): Depend on diagnostic.h (cp/typeck.o): Depend on diagnostic.h (cp/typeck2.o): Depend on diagnostic.h (cp/repo.o): Depend on dignostic.h * typeck.c: #include diagnostic.h (convert_for_initialization): Remove extern declaration for warningcount and errorcount. * call.c: #include diagnostic.h (convert_like_real): Remove extern declaration for warnincount and errorcount. * repo.c: #include diagnostic.h * typeck2.c: #include diagnostic.h From-SVN: r43140
2001-06-10 15:48:04 +02:00
/* Similarly, but for warnings. */
#define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
/* Similarly, but for warnings promoted to errors. */
#define werrorcount diagnostic_kind_count (global_dc, DK_WERROR)
Makefile.in (c-parse.o): Depend on diagnostic.h gcc/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Makefile.in (c-parse.o): Depend on diagnostic.h (dwarf2out.o): Likewise. * dwarf2out.c: #include diagnostic.h * toplev.h (warningcount, errorcount, sorrycount): Remove declarations. * toplev.c (warningcount, errorcount, sorrycount): Remove definitions. * diagnostic.h (struct output_buffer): Reorder fields. (diagnostic_kind_count): New macro. (errorcount, warningcount, sorrycount): Define as macros. (diagnostic_report_warnings_p): New macro. (output_state): Add diagnostic_count field. * diagnostic.c (warningcount, errorcount, inhibit_warnings): Remove tentative declaration. (count_error): Use diagnostic_report_warnings_p. * c-parse.in: #include diagnostic.h ch/ 2001-06-10 Gabriel Dos Reis <gdr@codesourcery.com> * decl.c: #include diagnostic.h * actions.c: #include diagnostic.h * Makefile.in (actions.o): Depend on diagnostic.h (decl.o): Depend on diagnostic.h cp/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Make-lang.in (cp/call.o): Depend on diagnostic.h (cp/typeck.o): Depend on diagnostic.h (cp/typeck2.o): Depend on diagnostic.h (cp/repo.o): Depend on dignostic.h * typeck.c: #include diagnostic.h (convert_for_initialization): Remove extern declaration for warningcount and errorcount. * call.c: #include diagnostic.h (convert_like_real): Remove extern declaration for warnincount and errorcount. * repo.c: #include diagnostic.h * typeck2.c: #include diagnostic.h From-SVN: r43140
2001-06-10 15:48:04 +02:00
/* Similarly, but for sorrys. */
#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
Makefile.in (c-parse.o): Depend on diagnostic.h gcc/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Makefile.in (c-parse.o): Depend on diagnostic.h (dwarf2out.o): Likewise. * dwarf2out.c: #include diagnostic.h * toplev.h (warningcount, errorcount, sorrycount): Remove declarations. * toplev.c (warningcount, errorcount, sorrycount): Remove definitions. * diagnostic.h (struct output_buffer): Reorder fields. (diagnostic_kind_count): New macro. (errorcount, warningcount, sorrycount): Define as macros. (diagnostic_report_warnings_p): New macro. (output_state): Add diagnostic_count field. * diagnostic.c (warningcount, errorcount, inhibit_warnings): Remove tentative declaration. (count_error): Use diagnostic_report_warnings_p. * c-parse.in: #include diagnostic.h ch/ 2001-06-10 Gabriel Dos Reis <gdr@codesourcery.com> * decl.c: #include diagnostic.h * actions.c: #include diagnostic.h * Makefile.in (actions.o): Depend on diagnostic.h (decl.o): Depend on diagnostic.h cp/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Make-lang.in (cp/call.o): Depend on diagnostic.h (cp/typeck.o): Depend on diagnostic.h (cp/typeck2.o): Depend on diagnostic.h (cp/repo.o): Depend on dignostic.h * typeck.c: #include diagnostic.h (convert_for_initialization): Remove extern declaration for warningcount and errorcount. * call.c: #include diagnostic.h (convert_like_real): Remove extern declaration for warnincount and errorcount. * repo.c: #include diagnostic.h * typeck2.c: #include diagnostic.h From-SVN: r43140
2001-06-10 15:48:04 +02:00
/* Returns nonzero if warnings should be emitted. */
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
#define diagnostic_report_warnings_p(DC, LOC) \
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
(!(DC)->dc_inhibit_warnings \
&& !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers))
Makefile.in (c-parse.o): Depend on diagnostic.h gcc/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Makefile.in (c-parse.o): Depend on diagnostic.h (dwarf2out.o): Likewise. * dwarf2out.c: #include diagnostic.h * toplev.h (warningcount, errorcount, sorrycount): Remove declarations. * toplev.c (warningcount, errorcount, sorrycount): Remove definitions. * diagnostic.h (struct output_buffer): Reorder fields. (diagnostic_kind_count): New macro. (errorcount, warningcount, sorrycount): Define as macros. (diagnostic_report_warnings_p): New macro. (output_state): Add diagnostic_count field. * diagnostic.c (warningcount, errorcount, inhibit_warnings): Remove tentative declaration. (count_error): Use diagnostic_report_warnings_p. * c-parse.in: #include diagnostic.h ch/ 2001-06-10 Gabriel Dos Reis <gdr@codesourcery.com> * decl.c: #include diagnostic.h * actions.c: #include diagnostic.h * Makefile.in (actions.o): Depend on diagnostic.h (decl.o): Depend on diagnostic.h cp/ 2001-06-10 Mark Mitchell <mark@codesourcery.com> Gabriel Dos Reis <gdr@codesourcery.com> * Make-lang.in (cp/call.o): Depend on diagnostic.h (cp/typeck.o): Depend on diagnostic.h (cp/typeck2.o): Depend on diagnostic.h (cp/repo.o): Depend on dignostic.h * typeck.c: #include diagnostic.h (convert_for_initialization): Remove extern declaration for warningcount and errorcount. * call.c: #include diagnostic.h (convert_like_real): Remove extern declaration for warnincount and errorcount. * repo.c: #include diagnostic.h * typeck2.c: #include diagnostic.h From-SVN: r43140
2001-06-10 15:48:04 +02:00
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
/* Override the option index to be used for reporting a
diagnostic. */
static inline void
diagnostic_override_option_index (diagnostic_info *info, int optidx)
{
info->option_index = optidx;
}
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
/* Diagnostic related functions. */
diagnostic.c: Don't include opts.h. * diagnostic.c: Don't include opts.h. (permissive_error_option): Define. (diagnostic_initialize): Take n_opts parameter. Allocate memory for classify_diagnostic. Don't use memset for classify_diagnostic. Initialize new and recently added fields. (diagnostic_classify_diagnostic): Use context->n_opts instead of N_OPTS. (diagnostic_report_diagnostic): Pass context parameter to diagnostic_report_warnings_p. Use option_enabled and option_name hooks from context. (emit_diagnostic): Use permissive_error_option. (permerror): Likewise. * diagnostic.h: Don't include options.h. (struct diagnostic_context): Add n_opts, opt_permissive, inhibit_warnings, warn_system_headers, option_enabled and option_name fields. Change classify_diagnostic to a pointer. * opts-diagnostic.h: New file. * opts.c: Include opts-diagnostic.h. (common_handle_option): Set global_dc fields for -Wfatal-errors, -Wsystem-headers, -fshow-column, -pedantic-errors and -w. (option_name): New function. * c-opts.c (c_common_init_options): Set global_dc->opt_permissive. (c_common_handle_option): Set global_dc->permissive for -fpermissive. * c-common.c (c_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. * toplev.c: Include opts-diagnostic.h. (general_init): Update call to diagnostic_initialize. Set global_dc->show_column, global_dc->option_enabled and global_dc->option_name. (process_options): Don't set global_dc fields here. * Makefile.in (DIAGNOSTIC_H): Remove options.h. (diagnostic.o, opts.o, toplev.o): Update dependencies. fortran: * cpp.c (cb_cpp_error): Save and restore global_dc->warn_system_headers, not variable warn_system_headers. From-SVN: r159869
2010-05-26 15:40:53 +02:00
extern void diagnostic_initialize (diagnostic_context *, int);
extern void diagnostic_color_init (diagnostic_context *, int value = -1);
pretty-print: support URL escape sequences (PR 87488) https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda describes an emerging standard for embedding URLs in escape sequences for marking up text output. This is supported e.g. by recent releases of GNOME Terminal. This patch adds support to our pretty-printing framework for emitting URLs. A followup patch uses this to add URLs to the pertinent documentation for the output of -fdiagnostics-show-option. gcc/ChangeLog: PR 87488 * common.opt (fdiagnostics-urls=): New option. (diagnostic-url.h): Add SourceInclude. (diagnostic_url_rule): New enum. * diagnostic-color.c: Include "diagnostic-url.h". (diagnostic_urls_enabled_p): New function. * diagnostic-url.h: New file. * diagnostic.c: Include "diagnostic-url.h". (diagnostic_urls_init): New function. * diagnostic.h (diagnostic_urls_init): New decl. * doc/invoke.texi (Diagnostic Message Formatting Options): Add -fdiagnostics-urls to the list. (-fdiagnostics-urls): New option. * gcc.c (driver_handle_option): Handle OPT_fdiagnostics_urls_. (driver::global_initializations): Call diagnostic_urls_init. * opts-global.c (init_options_once): Likewise. * opts.c (common_handle_option): Handle OPT_fdiagnostics_urls_. * pretty-print.c (pretty_printer::pretty_printer): Initialize show_urls. (pp_begin_url): New function. (pp_end_url): New function. (selftest::test_urls): New selftest. (selftest::pretty_print_c_tests): Call it. * pretty-print.h (pretty_printer::show_urls): New field. (pp_begin_url): New decl. (pp_end_url): New decl. gcc/testsuite/ChangeLog: PR 87488 * lib/prune.exp (TEST_ALWAYS_FLAGS): Add -fdiagnostics-urls=never. From-SVN: r276841
2019-10-10 18:57:30 +02:00
extern void diagnostic_urls_init (diagnostic_context *, int value = -1);
re PR other/42965 (no "warnings being treated as errors" for individual -Werror=x options) 2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org> PR 42965 * diagnostic.c (diagnostic_initialize): Initialize some_warnings_are_errors. (diagnostic_finish): New. (diagnostic_action_after_output): Call it before exiting. (diagnostic_report_diagnostic): Do not print message here. Set some_warnings_are_errors. * diagnostic.h (diagnostic_context): Delete issue_warnings_are_errors_message. Add some_warnings_are_errors. (diagnostic_finish): Declare. * toplev.c (toplev_main): Call it before exit. testsuite/ * gcc.dg/Werror-6.c: Adjust. * gcc.dg/Werror-implicit-function-declaration.c: Likewise. * gcc.dg/Werror-4.c: Likewise. * gcc.dg/Wdeclaration-after-statement-3.c: Likewise. * gcc.dg/Wswitch-enum-error.c: Likewise. * gcc.dg/Wpointer-arith.c: Likewise. * gcc.dg/Wfatal.c: Likewise. * gcc.dg/Wswitch-error.c: Likewise. * g++.dg/warn/unused-result1-Werror.c: Likewise. * gcc.dg/Werror-9.c: Delete. Duplicate of Werror-4.c. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-variadic-2.c: Likewise. * gcc.dg/cpp/warning-directive-2.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-multichar-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * g++.dg/cpp/warning-directive-2.C: Likewise. * gfortran.dg/warning-directive-2.F90: Likewise. From-SVN: r158168
2010-04-09 17:45:52 +02:00
extern void diagnostic_finish (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *, location_t);
Allow calling diagnostic_show_locus without a diagnostic_info 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
2016-08-18 21:12:54 +02:00
extern void diagnostic_show_locus (diagnostic_context *,
rich_location *richloc,
diagnostic_t diagnostic_kind);
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
extern void diagnostic_show_any_path (diagnostic_context *, diagnostic_info *);
diagnostics: Support for -finput-charset [PR93067] Adds the logic to handle -finput-charset in layout_get_source_line(), so that source lines are converted from their input encodings prior to being output by diagnostics machinery. Also adds the ability to strip a UTF-8 BOM similarly. gcc/c-family/ChangeLog: PR other/93067 * c-opts.c (c_common_input_charset_cb): New function. (c_common_post_options): Call new function diagnostic_initialize_input_context(). gcc/d/ChangeLog: PR other/93067 * d-lang.cc (d_input_charset_callback): New function. (d_init): Call new function diagnostic_initialize_input_context(). gcc/fortran/ChangeLog: PR other/93067 * cpp.c (gfc_cpp_post_options): Call new function diagnostic_initialize_input_context(). gcc/ChangeLog: PR other/93067 * coretypes.h (typedef diagnostic_input_charset_callback): Declare. * diagnostic.c (diagnostic_initialize_input_context): New function. * diagnostic.h (diagnostic_initialize_input_context): Declare. * input.c (default_charset_callback): New function. (file_cache::initialize_input_context): New function. (file_cache_slot::create): Added ability to convert the input according to the input context. (file_cache::file_cache): Initialize the new input context. (class file_cache_slot): Added new m_alloc_offset member. (file_cache_slot::file_cache_slot): Initialize the new member. (file_cache_slot::~file_cache_slot): Handle potentially offset buffer. (file_cache_slot::maybe_grow): Likewise. (file_cache_slot::needs_read_p): Handle NULL fp, which is now possible. (file_cache_slot::get_next_line): Likewise. * input.h (class file_cache): Added input context member. libcpp/ChangeLog: PR other/93067 * charset.c (init_iconv_desc): Adapt to permit PFILE argument to be NULL. (_cpp_convert_input): Likewise. Also move UTF-8 BOM logic to... (cpp_check_utf8_bom): ...here. New function. (cpp_input_conversion_is_trivial): New function. * files.c (read_file_guts): Allow PFILE argument to be NULL. Add INPUT_CHARSET argument as an alternate source of this information. (read_file): Pass the new argument to read_file_guts. (cpp_get_converted_source): New function. * include/cpplib.h (struct cpp_converted_source): Declare. (cpp_get_converted_source): Declare. (cpp_input_conversion_is_trivial): Declare. (cpp_check_utf8_bom): Declare. gcc/testsuite/ChangeLog: PR other/93067 * gcc.dg/diagnostic-input-charset-1.c: New test. * gcc.dg/diagnostic-input-utf8-bom.c: New test.
2021-08-25 01:30:44 +02:00
/* Because we read source files a second time after the frontend did it the
first time, we need to know how the frontend handled things like character
set conversion and UTF-8 BOM stripping, in order to make everything
consistent. This function needs to be called by each frontend that requires
non-default behavior, to inform the diagnostics infrastructure how input is
to be processed. The default behavior is to do no conversion and not to
strip a UTF-8 BOM.
The callback should return the input charset to be used to convert the given
file's contents to UTF-8, or it should return NULL if no conversion is needed
for this file. SHOULD_SKIP_BOM only applies in case no conversion was
performed, and if true, it will cause a UTF-8 BOM to be skipped at the
beginning of the file. (In case a conversion was performed, the BOM is
rather skipped as part of the conversion process.) */
void diagnostic_initialize_input_context (diagnostic_context *context,
diagnostic_input_charset_callback ccb,
bool should_skip_bom);
/* Force diagnostics controlled by OPTIDX to be kind KIND. */
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
int /* optidx */,
diagnostic_t /* kind */,
location_t);
extern void diagnostic_push_diagnostics (diagnostic_context *, location_t);
extern void diagnostic_pop_diagnostics (diagnostic_context *, location_t);
re PR other/36901 (pedwarn() + -pedantic-errors + -w (inhibit_warnings) should not emit errors) 2008-08-09 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR 36901 * diagnostic.def (DK_PEDWARN, DK_PERMERROR): New. * diagnostic.c (pedantic_warning_kind, permissive_error_kind): Moved from diagnostic.h (diagnostic_report_diagnostic): Return bool. Handle DK_PEDWARN and DK_PERMERROR. (emit_diagnostic): New. (warning0, pedwarn0): Delete. (warning, warning_at, pedwarn, permerror): Return bool. * diagnostic.h (pedantic_warning_kind, permissive_error_kind): Moved to diagnostic.c. (struct diagnostic_context): Use correct type for classify_diagnostic. (diagnostic_report_diagnostic): Update declaration. (emit_diagnostic): Declare. * errors.c (warning): Return bool. * errors.h (warning): Update declaration. * toplev.h (warning0, pedwarn0): Delete. (warning, warning_at, pedwarn, permerror): Return bool. * c-errors.c (pedwarn_c99, pedwarn_c90): Use DK_PEDWARN. * c-decl.c (locate_old_decl): Delete 'diag' argument. Always use inform. Update all calls. (diagnose_mismatched_decls): Check return value of warning/pedwarn before giving informative note. (implicit_decl_warning): Likewise. * c-typeck.c (build_function_call): Likewise. * tree-sssa.c (warn_uninit): Likewise. * builtins.c (gimplify_va_arg_expr): Likewise. fortran/ * f95-lang.c (gfc_mark_addressable): Use "pedwarn (0," instead of 'pedwarn0'. cp/ * cp-tree.h (struct diagnostic_context, struct diagnostic_info): Delete forward declarations. Check that toplev.h has not been included before this file. Include toplev.h and diagnostic.h. * error.c (cp_cpp_error): Use DK_PEDWARN. (cxx_incomplete_type_diagnostic): Update declaration. (cxx_incomplete_type_error): Use DK_ERROR. * typeck2.c (cxx_incomplete_type_diagnostic): Take a diagnostic_t as argument. Use emit_diagnostic. (cxx_incomplete_type_error): Use DK_ERROR. (add_exception_specifier): Use diagnostic_t instead of custom codes. * typeck.c (complete_type_or_else): Update call to cxx_incomplete_type_diagnostic. * init.c (build_delete): Likewise. * call.c (diagnostic_fn_t): Remove unused typedef. (build_temp): Pass a pointer to diagnostic_t. (convert_like_real): Use emit_diagnostic. (joust): Check return value of warning before giving informative note. * friend.c (do_friend): Check return value of warning before giving informative note. * parser.c (cp_parser_template_id): Likewise. testsuite/ * gcc.dg/pr36901-1.c: New. * gcc.dg/pr36901-3.c: New. * gcc.dg/pr36901-2.c: New. * gcc.dg/pr36901-4.c: New. * gcc.dg/pr36901-system.h: New. * gcc.dg/pr36901.h: New. * gcc.target/powerpc/altivec-macros.c: Update. * gcc.target/i386/regparm.c: Update. * gcc.dg/funcdef-var-1.c: Update. * gcc.dg/parm-mismatch-1.c: Update. * gcc.dg/attr-noinline.c: Update. * gcc.dg/wtr-static-1.c: Update. * gcc.dg/redecl-11.c: Update. * gcc.dg/pr27953.c: Update. * gcc.dg/proto-1.c: Update. * gcc.dg/decl-3.c: Update. * gcc.dg/redecl-13.c: Update. * gcc.dg/pr15360-1.c: Update. * gcc.dg/redecl-15.c: Update. * gcc.dg/enum-compat-1.c: Update. * gcc.dg/dll-3.c: Update. * gcc.dg/array-5.c: Update. * gcc.dg/Wredundant-decls-2.c: Update. * gcc.dg/inline4.c: Update. * gcc.dg/redecl-2.c: Update. * gcc.dg/inline-14.c: Update. * gcc.dg/tls/diag-3.c: Update. * gcc.dg/funcdef-var-2.c: Update. * gcc.dg/20041213-1.c: Update. * gcc.dg/old-style-then-proto-1.c: Update. * gcc.dg/decl-2.c: Update. * gcc.dg/redecl-12.c: Update. * gcc.dg/decl-4.c: Update. * gcc.dg/Wshadow-1.c: Update. * gcc.dg/transparent-union-2.c: Update. * gcc.dg/visibility-7.c: Update. * gcc.dg/dll-2.c: Update. * gcc.dg/redecl-16.c: Update. * gcc.dg/inline1.c: Update. * gcc.dg/decl-8.c: Update. * gcc.dg/nested-redef-1.c: Update. * gcc.dg/inline3.c: Update. * gcc.dg/redecl-1.c: Update. * gcc.dg/inline5.c: Update. * gcc.dg/pr35899.c: Update. * gcc.dg/noncompile/label-lineno-1.c: Update. * gcc.dg/noncompile/label-1.c: Update. * gcc.dg/noncompile/20020220-1.c: Update. * gcc.dg/noncompile/redecl-1.c: Update. * gcc.dg/redecl-5.c: Update. * gcc.dg/qual-return-3.c: Update. * gcc.dg/label-decl-4.c: Update. From-SVN: r138893
2008-08-09 01:57:19 +02:00
extern bool diagnostic_report_diagnostic (diagnostic_context *,
diagnostic_info *);
#ifdef ATTRIBUTE_GCC_DIAG
extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
va_list *, rich_location *,
diagnostic_t)
ATTRIBUTE_GCC_DIAG(2,0);
extern void diagnostic_append_note (diagnostic_context *, location_t,
const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
#endif
extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *);
[multiple changes] 2009-09-01 Diego Novillo <dnovillo@google.com> * c-lang.c (lang_hooks): Remove const qualifier. java/ChangeLog * lang.c (lang_hooks): Remove const qualifier. objc/ChangeLog * objc-lang.c (lang_hooks): Remove const qualifier. objcp/ChangeLog * objcp-lang.c (lang_hooks): Remove const qualifier. ada/ChangeLog * gcc-interface/misc.c (lang_hooks): Remove const qualifier. fortran/ChangeLog * f95-lang.c (lang_hooks): Remove const qualifier. cp/ChangeLog * cp-lang.c (lang_hooks): Remove const qualifier. 2009-09-01 Diego Novillo <dnovillo@google.com> * cgraph.c (cgraph_node_for_decl): New. * cgraph.h (cgraph_node_for_decl): Declare. * tree.c (host_integerp): Return 0 if T is NULL. 2009-09-01 Diego Novillo <dnovillo@google.com> * tree.h (struct alias_pair): Move from varasm.c. (alias_pairs): Likewise. (TYPE_MAXVAL): Define. (TYPE_MINVAL): Define. (iterative_hash_host_wide_int): Declare. (remove_unreachable_alias_pairs): Declare. * tree-pass.h (pass_ipa_free_lang_data): Declare. * diagnostic.c (default_diagnostic_starter): Make extern. (default_diagnostic_finalizer): Make extern. * diagnostic.h (default_diagnostic_starter): Declare. (default_diagnostic_finalizer): Declare. (default_tree_printer): Declare. * toplev.c (default_tree_printer): Make extern. 2009-09-01 Richard Guenther <rguenther@suse.de> Diego Novillo <dnovillo@google.com> * cgraph.c (cgraph_add_new_function): Remove gimplification. * cgraphunit.c (cgraph_expand_function): Do not emit associated thunks from here. (cgraph_emit_thunks): New. (cgraph_optimize): Call it. Return if any IPA pass finds an error. * varasm.c (finish_aliases_1): Ignore errorneous aliases used by thunks. 2009-09-01 Simon Baldwin <simonb@google.com> Rafael Espindola <espindola@google.com> Richard Guenther <rguenther@suse.de> Doug Kwan <dougkwan@google.com> Diego Novillo <dnovillo@google.com> * tree.c: Include tree-pass.h, langhooks-def.h, diagnostic.h, cgraph.h, timevar.h, except.h and debug.h. (free_lang_data_in_type): New. (need_assembler_name_p): New. (free_lang_data_in_block): New. (free_lang_data_in_decl): New. (struct free_lang_data_d): New. (add_tree_to_fld_list): New. (find_decls_types_r): New. (get_eh_types_for_runtime): New. (find_decls_types_in_eh_region): New. (find_decls_types_in_node): New. (find_decls_types_in_var): New. (free_lang_data_in_cgraph): New. (free_lang_data): New. (gate_free_lang_data): New. (pass_ipa_free_lang_data): New. 2009-09-01 Diego Novillo <dnovillo@google.com> * timevar.def (TV_IPA_FREE_LANG_DATA): Define. * langhooks.h (struct lang_hooks): Add field free_lang_data. (lang_hooks): Remove const qualifier. * ipa.c (cgraph_remove_unreachable_nodes): Call remove_unreachable_alias_pairs. * except.c (add_type_for_runtime): Check if TYPE has already been converted. (lookup_type_for_runtime): Likewise. (check_handled): Handle converted types. * varasm.c (remove_unreachable_alias_pairs): New. * gimple.c: Include demangle.h. (gimple_decl_printable_name): New. (gimple_fold_obj_type_ref): New. * gimple.h (gimple_decl_printable_name): Declare. (gimple_fold_obj_type_ref): Declare. * passes.c (init_optimization_passes): Add pass pass_ipa_free_lang_data. * langhooks-def.h (LANG_HOOKS_FREE_LANG_DATA): Define. (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_FREE_LANG_DATA. testsuite/ChangeLog 2009-09-01 Diego Novillo <dnovillo@google.com> * gcc.dg/gomp/combined-1.c: Adjust expected pattern. * g++.dg/tree-prof/inline_mismatch_args.C: Likewise. * g++.dg/warn/unit-1.C: Likewise. * g++.dg/ipa/iinline-1.C: Likewise. * g++.dg/template/cond2.C: Adjust expected line location for the error. * g++.dg/template/pr35240.C: Likewise. cp/ChangeLog 2009-09-01 Doug Kwan <dougkwan@google.com> * tree.c (cp_fix_function_decl_p): New. (cp_free_lang_data): New. 2009-09-01 Diego Novillo <dnovillo@google.com> * Make-lang.in (decl2.o): Add dependency on $(POINTER_SET_H). * decl2.c: Include pointer-set.h. (collect_candidates_for_java_method_aliases): New. (cp_write_global_declarations): Call it. Add local variable CANDIDATES. If set, call build_java_method_aliases. (build_java_method_aliases): Add argument CANDIDATES. Use it to determine if FNDECL should get a hidden alias. * cp-objcp-common.h (LANG_HOOKS_FREE_LANG_DATA): Define. * cp-tree.h (cp_free_lang_data): Declare. 2009-09-03 Richard Guenther <rguenther@suse.de> * method.c (use_thunk): Use cgraph_finalize_function to hand off thunks to the cgraph. * semantics.c (emit_associated_thunks): Do not emit thunks for really extern functions. From-SVN: r151360
2009-09-03 06:07:12 +02:00
void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
PR other/69554: avoid excessive source printing for widely-separated locations 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
2016-02-12 20:18:03 +01:00
void default_diagnostic_start_span_fn (diagnostic_context *,
expanded_location);
Machine-readable diagnostic output (PR other/19165) 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
2018-11-15 15:32:41 +01:00
void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *,
diagnostic_t);
void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
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
2014-12-11 16:13:33 +01:00
void diagnostic_action_after_output (diagnostic_context *, diagnostic_t);
void diagnostic_check_max_errors (diagnostic_context *, bool flush = false);
PR preprocessor/58580 - preprocessor goes OOM with warning for zero literals 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
2014-01-23 10:13:08 +01:00
void diagnostic_file_cache_fini (void);
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
int get_terminal_width (void);
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
2015-05-16 14:31:00 +02:00
/* Return the location associated to this diagnostic. Parameter WHICH
specifies which location. By default, expand the first one. */
static inline location_t
diagnostic_location (const diagnostic_info * diagnostic, int which = 0)
{
return diagnostic->message.get_location (which);
}
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
/* Return the number of locations to be printed in DIAGNOSTIC. */
static inline unsigned int
diagnostic_num_locations (const diagnostic_info * diagnostic)
{
return diagnostic->message.m_richloc->get_num_locations ();
}
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
2015-05-16 14:31:00 +02:00
/* Expand the location of this diagnostic. Use this function for
consistency. Parameter WHICH specifies which location. By default,
expand the first one. */
static inline expanded_location
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
2015-05-16 14:31:00 +02:00
diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0)
{
PR c++/70105: Defer location expansion until diagnostic_show_locus 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
2016-03-09 19:14:43 +01:00
return diagnostic->richloc->get_expanded_location (which);
}
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
2015-05-16 14:31:00 +02:00
/* This is somehow the right-side margin of a caret line, that is, we
print at least these many characters after the position pointed at
by the caret. */
const int CARET_LINE_MARGIN = 10;
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
2015-05-16 14:31:00 +02:00
/* Return true if the two locations can be represented within the same
caret line. This is used to build a prefix and also to determine
whether to print one or two caret lines. */
static inline bool
diagnostic_same_line (const diagnostic_context *context,
expanded_location s1, expanded_location s2)
{
return s2.column && s1.line == s2.line
&& context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column);
}
Reimplement diagnostic_show_locus, introducing rich_location classes 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
2015-11-06 20:50:50 +01:00
extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
diagnostics: Support conversion of tabs to spaces [PR49973] [PR86904] Supports conversion of tabs to spaces when outputting diagnostics. Also adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to control how the column number is output, thereby resolving the two PRs. gcc/c-family/ChangeLog: PR other/86904 * c-indentation.c (should_warn_for_misleading_indentation): Get global tabstop from the new source. * c-opts.c (c_common_handle_option): Remove handling of -ftabstop, which is now a common option. * c.opt: Likewise. gcc/ChangeLog: PR preprocessor/49973 PR other/86904 * common.opt: Handle -ftabstop here instead of in c-family options. Add -fdiagnostics-column-unit= and -fdiagnostics-column-origin= options. * opts.c (common_handle_option): Handle the new options. * diagnostic-format-json.cc (json_from_expanded_location): Add diagnostic_context argument. Use it to convert column numbers as per the new options. (json_from_location_range): Likewise. (json_from_fixit_hint): Likewise. (json_end_diagnostic): Pass the new context argument to helper functions above. Add "column-origin" field to the output. (test_unknown_location): Add the new context argument to calls to helper functions. (test_bad_endpoints): Likewise. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Support tabstop parameter. (layout_point::layout_point): Make use of class exploc_with_display_col. (layout_range::layout_range): Likewise. (struct line_bounds): Clarify that the units are now always display columns. Rename members accordingly. Add constructor. (layout::print_source_line): Add support for tab expansion. (make_range): Adapt to class layout_range changes. (layout::maybe_add_location_range): Likewise. (layout::layout): Adapt to class exploc_with_display_col changes. (layout::calculate_x_offset_display): Support tabstop parameter. (layout::print_annotation_line): Adapt to struct line_bounds changes. (layout::print_line): Likewise. (line_label::line_label): Add diagnostic_context argument. (get_affected_range): Likewise. (get_printed_columns): Likewise. (layout::print_any_labels): Adapt to struct line_label changes. (class correction): Add m_tabstop member. (correction::correction): Add tabstop argument. (correction::compute_display_cols): Use m_tabstop. (class line_corrections): Add m_context member. (line_corrections::line_corrections): Add diagnostic_context argument. (line_corrections::add_hint): Use m_context to handle tabstops. (layout::print_trailing_fixits): Adapt to class line_corrections changes. (test_layout_x_offset_display_utf8): Support tabstop parameter. (test_layout_x_offset_display_tab): New selftest. (test_one_liner_colorized_utf8): Likewise. (test_tab_expansion): Likewise. (test_diagnostic_show_locus_one_liner_utf8): Call the new tests. (diagnostic_show_locus_c_tests): Likewise. (test_overlapped_fixit_printing): Adapt to helper class and function changes. (test_overlapped_fixit_printing_utf8): Likewise. (test_overlapped_fixit_printing_2): Likewise. * diagnostic.h (enum diagnostics_column_unit): New enum. (struct diagnostic_context): Add members for the new options. (diagnostic_converted_column): Declare. (json_from_expanded_location): Add new context argument. * diagnostic.c (diagnostic_initialize): Initialize new members. (diagnostic_converted_column): New function. (maybe_line_and_column): Be willing to output a column of 0. (diagnostic_get_location_text): Convert column number as per the new options. (diagnostic_report_current_module): Likewise. (assert_location_text): Add origin and column_unit arguments for testing the new functionality. (test_diagnostic_get_location_text): Test the new functionality. * doc/invoke.texi: Document the new options and behavior. * input.h (location_compute_display_column): Add tabstop argument. * input.c (location_compute_display_column): Likewise. (test_cpp_utf8): Add selftests for tab expansion. * tree-diagnostic-path.cc (default_tree_make_json_for_path): Pass the new context argument to json_from_expanded_location(). libcpp/ChangeLog: PR preprocessor/49973 PR other/86904 * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, which is now handled by diagnostic_context. (class cpp_display_width_computation): New class. (cpp_byte_column_to_display_column): Add optional tabstop argument. (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * charset.c (cpp_display_width_computation::cpp_display_width_computation): New function. (cpp_display_width_computation::advance_display_cols): Likewise. (compute_next_display_width): Removed and implemented this functionality in a new function... (cpp_display_width_computation::process_next_codepoint): ...here. (cpp_byte_column_to_display_column): Added tabstop argument. Reimplemented in terms of class cpp_display_width_computation. (cpp_display_column_to_byte_column): Likewise. * init.c (cpp_create_reader): Remove handling of -ftabstop, which is now handled by diagnostic_context. gcc/testsuite/ChangeLog: PR preprocessor/49973 PR other/86904 * c-c++-common/Wmisleading-indentation-3.c: Adjust expected output for new defaults. * c-c++-common/Wmisleading-indentation.c: Likewise. * c-c++-common/diagnostic-format-json-1.c: Likewise. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise. * c-c++-common/diagnostic-format-json-5.c: Likewise. * c-c++-common/missing-close-symbol.c: Likewise. * g++.dg/diagnostic/bad-binary-ops.C: Likewise. * g++.dg/parse/error4.C: Likewise. * g++.old-deja/g++.brendan/crash11.C: Likewise. * g++.old-deja/g++.pt/overload2.C: Likewise. * g++.old-deja/g++.robertl/eb109.C: Likewise. * gcc.dg/analyzer/malloc-paths-9.c: Likewise. * gcc.dg/bad-binary-ops.c: Likewise. * gcc.dg/format/branch-1.c: Likewise. * gcc.dg/format/pr79210.c: Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. * gcc.dg/plugin/diagnostic-test-string-literals-1.c: Likewise. * gcc.dg/redecl-4.c: Likewise. * gfortran.dg/diagnostic-format-json-1.F90: Likewise. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. * go.dg/arrayclear.go: Add a comment explaining why adding a comment was necessary to work around a dejagnu bug. * c-c++-common/diagnostic-units-1.c: New test. * c-c++-common/diagnostic-units-2.c: New test. * c-c++-common/diagnostic-units-3.c: New test. * c-c++-common/diagnostic-units-4.c: New test. * c-c++-common/diagnostic-units-5.c: New test. * c-c++-common/diagnostic-units-6.c: New test. * c-c++-common/diagnostic-units-7.c: New test. * c-c++-common/diagnostic-units-8.c: New test.
2020-07-14 18:05:56 +02:00
extern int diagnostic_converted_column (diagnostic_context *context,
expanded_location s);
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
2015-05-16 14:31:00 +02:00
toplev.h (report_error_function): Remove. * toplev.h (report_error_function): Remove. * diagnostic.h (location_t): New datatype. (text_info): Likewise. (diagnostic_info): Likewise. (output_prefix): New macro. (diagnostic_last_function_changed): Likewise. (diagnostic_set_last_function): Likewise. (diagnostic_last_module_changed): Likewise. (diagnostic_set_last_module): Likewise. (report_diagnostic): Now macro. (diagnostic_set_info): Declare. * diagnostic.c (report_problematic_module): Rename to diagnostic_repor_current_module. (set_diagnostic_context): Remove. (count_error): Rename to diagnostic_error_count. (error_function_changed): Remove. (record_last_error_function): Likewise. (error_module_changed): Likewise. (record_last_error_module): Likewise. (context_as_prefix): Rename to diagnostic_build_prefix. (flush_diagnostic_buffer): Rename to diagnostic_flush_buffer. (diagnostic_set_info): New function. * objc/objc-act.c: #include diagnostic.h (error_with_ivar): Adjust call to count_error. (warn_with_method): Likewise. * objc/Make-lang.in (objc-act.o): Depend on diagnostic.h cp/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * error.c (cp_diagnostic_starter): Adjust call. (maybe_print_instantiation_context): Change prototype to take a 'diagnostic_info *'. (print_instantiation_full_context): Likewise. (print_instantiation_partial_context): Likewise. (cp_diagnostic_starter): Likewise. (cp_diagnostic_finalizer): Likewise. (cp_print_error_function): Likewise. (cp_printer): Take a secondary parameter as a 'text_info *'. Remove output_state savings. Adjust calls. f/ 2002-06-04 Gabriel Dos Reis <gdr@codesourcery.com> * bad.c (ffebad_start_): Adjust call to count_error. * Make-lang.in (f/bad.o): Depend on diagnostic.h * bad.c: #include diagnostic.h From-SVN: r54291
2002-06-05 21:35:45 +02:00
/* Pure text formatting support functions. */
extern char *file_name_as_prefix (diagnostic_context *, const char *);
extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
Machine-readable diagnostic output (PR other/19165) 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
2018-11-15 15:32:41 +01:00
extern void diagnostic_output_format_init (diagnostic_context *,
enum diagnostics_output_format);
/* Compute the number of digits in the decimal representation of an integer. */
extern int num_digits (int);
diagnostics: Support conversion of tabs to spaces [PR49973] [PR86904] Supports conversion of tabs to spaces when outputting diagnostics. Also adds -fdiagnostics-column-unit and -fdiagnostics-column-origin options to control how the column number is output, thereby resolving the two PRs. gcc/c-family/ChangeLog: PR other/86904 * c-indentation.c (should_warn_for_misleading_indentation): Get global tabstop from the new source. * c-opts.c (c_common_handle_option): Remove handling of -ftabstop, which is now a common option. * c.opt: Likewise. gcc/ChangeLog: PR preprocessor/49973 PR other/86904 * common.opt: Handle -ftabstop here instead of in c-family options. Add -fdiagnostics-column-unit= and -fdiagnostics-column-origin= options. * opts.c (common_handle_option): Handle the new options. * diagnostic-format-json.cc (json_from_expanded_location): Add diagnostic_context argument. Use it to convert column numbers as per the new options. (json_from_location_range): Likewise. (json_from_fixit_hint): Likewise. (json_end_diagnostic): Pass the new context argument to helper functions above. Add "column-origin" field to the output. (test_unknown_location): Add the new context argument to calls to helper functions. (test_bad_endpoints): Likewise. * diagnostic-show-locus.c (exploc_with_display_col::exploc_with_display_col): Support tabstop parameter. (layout_point::layout_point): Make use of class exploc_with_display_col. (layout_range::layout_range): Likewise. (struct line_bounds): Clarify that the units are now always display columns. Rename members accordingly. Add constructor. (layout::print_source_line): Add support for tab expansion. (make_range): Adapt to class layout_range changes. (layout::maybe_add_location_range): Likewise. (layout::layout): Adapt to class exploc_with_display_col changes. (layout::calculate_x_offset_display): Support tabstop parameter. (layout::print_annotation_line): Adapt to struct line_bounds changes. (layout::print_line): Likewise. (line_label::line_label): Add diagnostic_context argument. (get_affected_range): Likewise. (get_printed_columns): Likewise. (layout::print_any_labels): Adapt to struct line_label changes. (class correction): Add m_tabstop member. (correction::correction): Add tabstop argument. (correction::compute_display_cols): Use m_tabstop. (class line_corrections): Add m_context member. (line_corrections::line_corrections): Add diagnostic_context argument. (line_corrections::add_hint): Use m_context to handle tabstops. (layout::print_trailing_fixits): Adapt to class line_corrections changes. (test_layout_x_offset_display_utf8): Support tabstop parameter. (test_layout_x_offset_display_tab): New selftest. (test_one_liner_colorized_utf8): Likewise. (test_tab_expansion): Likewise. (test_diagnostic_show_locus_one_liner_utf8): Call the new tests. (diagnostic_show_locus_c_tests): Likewise. (test_overlapped_fixit_printing): Adapt to helper class and function changes. (test_overlapped_fixit_printing_utf8): Likewise. (test_overlapped_fixit_printing_2): Likewise. * diagnostic.h (enum diagnostics_column_unit): New enum. (struct diagnostic_context): Add members for the new options. (diagnostic_converted_column): Declare. (json_from_expanded_location): Add new context argument. * diagnostic.c (diagnostic_initialize): Initialize new members. (diagnostic_converted_column): New function. (maybe_line_and_column): Be willing to output a column of 0. (diagnostic_get_location_text): Convert column number as per the new options. (diagnostic_report_current_module): Likewise. (assert_location_text): Add origin and column_unit arguments for testing the new functionality. (test_diagnostic_get_location_text): Test the new functionality. * doc/invoke.texi: Document the new options and behavior. * input.h (location_compute_display_column): Add tabstop argument. * input.c (location_compute_display_column): Likewise. (test_cpp_utf8): Add selftests for tab expansion. * tree-diagnostic-path.cc (default_tree_make_json_for_path): Pass the new context argument to json_from_expanded_location(). libcpp/ChangeLog: PR preprocessor/49973 PR other/86904 * include/cpplib.h (struct cpp_options): Removed support for -ftabstop, which is now handled by diagnostic_context. (class cpp_display_width_computation): New class. (cpp_byte_column_to_display_column): Add optional tabstop argument. (cpp_display_width): Likewise. (cpp_display_column_to_byte_column): Likewise. * charset.c (cpp_display_width_computation::cpp_display_width_computation): New function. (cpp_display_width_computation::advance_display_cols): Likewise. (compute_next_display_width): Removed and implemented this functionality in a new function... (cpp_display_width_computation::process_next_codepoint): ...here. (cpp_byte_column_to_display_column): Added tabstop argument. Reimplemented in terms of class cpp_display_width_computation. (cpp_display_column_to_byte_column): Likewise. * init.c (cpp_create_reader): Remove handling of -ftabstop, which is now handled by diagnostic_context. gcc/testsuite/ChangeLog: PR preprocessor/49973 PR other/86904 * c-c++-common/Wmisleading-indentation-3.c: Adjust expected output for new defaults. * c-c++-common/Wmisleading-indentation.c: Likewise. * c-c++-common/diagnostic-format-json-1.c: Likewise. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise. * c-c++-common/diagnostic-format-json-5.c: Likewise. * c-c++-common/missing-close-symbol.c: Likewise. * g++.dg/diagnostic/bad-binary-ops.C: Likewise. * g++.dg/parse/error4.C: Likewise. * g++.old-deja/g++.brendan/crash11.C: Likewise. * g++.old-deja/g++.pt/overload2.C: Likewise. * g++.old-deja/g++.robertl/eb109.C: Likewise. * gcc.dg/analyzer/malloc-paths-9.c: Likewise. * gcc.dg/bad-binary-ops.c: Likewise. * gcc.dg/format/branch-1.c: Likewise. * gcc.dg/format/pr79210.c: Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c: Likewise. * gcc.dg/plugin/diagnostic-test-string-literals-1.c: Likewise. * gcc.dg/redecl-4.c: Likewise. * gfortran.dg/diagnostic-format-json-1.F90: Likewise. * gfortran.dg/diagnostic-format-json-2.F90: Likewise. * gfortran.dg/diagnostic-format-json-3.F90: Likewise. * go.dg/arrayclear.go: Add a comment explaining why adding a comment was necessary to work around a dejagnu bug. * c-c++-common/diagnostic-units-1.c: New test. * c-c++-common/diagnostic-units-2.c: New test. * c-c++-common/diagnostic-units-3.c: New test. * c-c++-common/diagnostic-units-4.c: New test. * c-c++-common/diagnostic-units-5.c: New test. * c-c++-common/diagnostic-units-6.c: New test. * c-c++-common/diagnostic-units-7.c: New test. * c-c++-common/diagnostic-units-8.c: New test.
2020-07-14 18:05:56 +02:00
extern json::value *json_from_expanded_location (diagnostic_context *context,
location_t loc);
Add diagnostic paths This patch adds support for associating a "diagnostic_path" with a diagnostic: a sequence of events predicted by the compiler that leads to the problem occurring, with their locations in the user's source, text descriptions, and stack information (for handling interprocedural paths). For example, the following (hypothetical) error has a 3-event intraprocedural path: test.c: In function 'demo': test.c:29:5: error: passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter 29 | PyList_Append(list, item); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 'demo': events 1-3 | | 25 | list = PyList_New(0); | | ^~~~~~~~~~~~~ | | | | | (1) when 'PyList_New' fails, returning NULL | 26 | | 27 | for (i = 0; i < count; i++) { | | ~~~ | | | | | (2) when 'i < count' | 28 | item = PyLong_FromLong(random()); | 29 | PyList_Append(list, item); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 | The patch adds a new "%@" format code for printing event IDs, so that in the above, the description of event (3) mentions event (1), showing the user where the bogus NULL value comes from (the event IDs are colorized to draw the user's attention to them). There is a separation between data vs presentation: the above shows how the diagnostic-printing code has consolidated the path into a single run of events, since all the events are near each other and within the same function; more complicated examples (such as interprocedural paths) might be printed as multiple runs of events. Examples of how interprocedural paths are printed can be seen in the test suite (which uses a plugin to exercise the code without relying on specific warnings using this functionality). Other output formats include - JSON, - printing each event as a separate "note", and - to not emit paths. gcc/ChangeLog: * Makefile.in (OBJS): Add tree-diagnostic-path.o. * common.opt (fdiagnostics-path-format=): New option. (diagnostic_path_format): New enum. (fdiagnostics-show-path-depths): New option. * coretypes.h (diagnostic_event_id_t): New forward decl. * diagnostic-color.c (color_dict): Add "path". * diagnostic-event-id.h: New file. * diagnostic-format-json.cc (json_from_expanded_location): Make non-static. (json_end_diagnostic): Call context->make_json_for_path if it exists and the diagnostic has a path. (diagnostic_output_format_init): Clear context->print_path. * diagnostic-path.h: New file. * diagnostic-show-locus.c (colorizer::set_range): Special-case when printing a run of events in a diagnostic_path so that they all get the same color. (layout::m_diagnostic_path_p): New field. (layout::layout): Initialize it. (layout::print_any_labels): Don't colorize the label text for an event in a diagnostic_path. (gcc_rich_location::add_location_if_nearby): Add "restrict_to_current_line_spans" and "label" params. Pass the former to layout.maybe_add_location_range; pass the latter when calling add_range. * diagnostic.c: Include "diagnostic-path.h". (diagnostic_initialize): Initialize context->path_format and context->show_path_depths. (diagnostic_show_any_path): New function. (diagnostic_path::interprocedural_p): New function. (diagnostic_report_diagnostic): Call diagnostic_show_any_path. (simple_diagnostic_path::num_events): New function. (simple_diagnostic_path::get_event): New function. (simple_diagnostic_path::add_event): New function. (simple_diagnostic_event::simple_diagnostic_event): New ctor. (simple_diagnostic_event::~simple_diagnostic_event): New dtor. (debug): New overload taking a diagnostic_path *. * diagnostic.def (DK_DIAGNOSTIC_PATH): New. * diagnostic.h (enum diagnostic_path_format): New enum. (json::value): New forward decl. (diagnostic_context::path_format): New field. (diagnostic_context::show_path_depths): New field. (diagnostic_context::print_path): New callback field. (diagnostic_context::make_json_for_path): New callback field. (diagnostic_show_any_path): New decl. (json_from_expanded_location): New decl. * doc/invoke.texi (-fdiagnostics-path-format=): New option. (-fdiagnostics-show-path-depths): New option. (-fdiagnostics-color): Add "path" to description of default GCC_COLORS; describe it. (-fdiagnostics-format=json): Document how diagnostic paths are represented in the JSON output format. * gcc-rich-location.h (gcc_rich_location::add_location_if_nearby): Add optional params "restrict_to_current_line_spans" and "label". * opts.c (common_handle_option): Handle OPT_fdiagnostics_path_format_ and OPT_fdiagnostics_show_path_depths. * pretty-print.c: Include "diagnostic-event-id.h". (pp_format): Implement "%@" format code for printing diagnostic_event_id_t *. (selftest::test_pp_format): Add tests for "%@". * selftest-run-tests.c (selftest::run_tests): Call selftest::tree_diagnostic_path_cc_tests. * selftest.h (selftest::tree_diagnostic_path_cc_tests): New decl. * toplev.c (general_init): Initialize global_dc->path_format and global_dc->show_path_depths. * tree-diagnostic-path.cc: New file. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Make non-static. Drop "diagnostic" param in favor of storing the original value of "where" and re-using it. (virt_loc_aware_diagnostic_finalizer): Update for dropped param of maybe_unwind_expanded_macro_loc. (tree_diagnostics_defaults): Initialize context->print_path and context->make_json_for_path. * tree-diagnostic.h (default_tree_diagnostic_path_printer): New decl. (default_tree_make_json_for_path): New decl. (maybe_unwind_expanded_macro_loc): New decl. gcc/c-family/ChangeLog: * c-format.c (local_event_ptr_node): New. (PP_FORMAT_CHAR_TABLE): Add entry for "%@". (init_dynamic_diag_info): Initialize local_event_ptr_node. * c-format.h (T_EVENT_PTR): New define. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (diagnostic_event_id_t): New typedef. (test_diag): Add coverage of "%@". * gcc.dg/plugin/diagnostic-path-format-default.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-1.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-2.c: New test. * gcc.dg/plugin/diagnostic-path-format-inline-events-3.c: New test. * gcc.dg/plugin/diagnostic-path-format-none.c: New test. * gcc.dg/plugin/diagnostic-test-paths-1.c: New test. * gcc.dg/plugin/diagnostic-test-paths-2.c: New test. * gcc.dg/plugin/diagnostic-test-paths-3.c: New test. * gcc.dg/plugin/diagnostic-test-paths-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: New. * gcc.dg/plugin/plugin.exp: Add the new plugin and test cases. libcpp/ChangeLog: * include/line-map.h (class diagnostic_path): New forward decl. (rich_location::get_path): New accessor. (rich_location::set_path): New function. (rich_location::m_path): New field. * line-map.c (rich_location::rich_location): Initialize m_path. From-SVN: r280142
2020-01-10 22:22:12 +01:00
extern bool warning_enabled_at (location_t, int);
#endif /* ! GCC_DIAGNOSTIC_H */