re PR fortran/44054 (Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color)

2014-08-15  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
gcc/
	* diagnostic.c (build_message_string): Make it extern.
	* diagnostic.h (build_message_string): Make it extern.
c-family/
	* c-format.c: Handle Fortran flags.
fortran/
	* gfortran.h: Define GCC_DIAG_STYLE.
	(gfc_diagnostics_init,gfc_warning_cmdline): Declare.
	* trans-array.c: Include gfortran.h before diagnostic-core.h.
	* trans-expr.c: Likewise.
	* trans-openmp.c: Likewise.
	* trans-const.c: Likewise.
	* trans.c: Likewise.
	* trans-types.c: Likewise.
	* f95-lang.c: Likewise.
	* trans-decl.c: Likewise.
	* trans-io.c: Likewise.
	* trans-intrinsic.c: Likewise.
	* error.c: Include diagnostic.h and diagnostic-color.h.
	(gfc_diagnostic_build_prefix): New.
	(gfc_diagnostic_starter): New.
	(gfc_diagnostic_finalizer): New.
	(gfc_warning_cmdline): New.
	(gfc_diagnostics_init): New.
	* gfc-diagnostic.def: New.
	* options.c (gfc_init_options): Call gfc_diagnostics_init.
	(gfc_post_options): Use gfc_warning_cmdline.

From-SVN: r214024
This commit is contained in:
Manuel López-Ibáñez 2014-08-15 15:10:15 +00:00
parent 363785f63e
commit 8e54f6d3ba
20 changed files with 222 additions and 36 deletions

View File

@ -1,3 +1,9 @@
2014-08-15 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR fortran/44054
* diagnostic.c (build_message_string): Make it extern.
* diagnostic.h (build_message_string): Make it extern.
2014-08-15 Vladimir Makarov <vmakarov@redhat.com>
* config/rs6000/rs6000.c (rs6000_emit_move): Use SDmode for

View File

@ -1,3 +1,8 @@
2014-08-15 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR fortran/44054
* c-format.c: Handle Fortran flags.
2014-08-12 Igor Zamyatin <igor.zamyatin@intel.com>
PR other/61962

View File

@ -510,11 +510,7 @@ static const format_flag_pair gcc_diag_flag_pairs[] =
#define gcc_tdiag_flag_pairs gcc_diag_flag_pairs
#define gcc_cdiag_flag_pairs gcc_diag_flag_pairs
#define gcc_cxxdiag_flag_pairs gcc_diag_flag_pairs
static const format_flag_pair gcc_gfc_flag_pairs[] =
{
{ 0, 0, 0, 0 }
};
#define gcc_gfc_flag_pairs gcc_diag_flag_pairs
static const format_flag_spec gcc_diag_flag_specs[] =
{
@ -529,6 +525,7 @@ static const format_flag_spec gcc_diag_flag_specs[] =
#define gcc_tdiag_flag_specs gcc_diag_flag_specs
#define gcc_cdiag_flag_specs gcc_diag_flag_specs
#define gcc_cxxdiag_flag_specs gcc_diag_flag_specs
#define gcc_gfc_flag_specs gcc_diag_flag_specs
static const format_flag_spec scanf_flag_specs[] =
{
@ -741,7 +738,7 @@ static const format_char_info gcc_gfc_char_table[] =
{ "di", 0, STD_C89, { T89_I, BADLEN, BADLEN, T89_L, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "", NULL },
{ "u", 0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "", NULL },
{ "c", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "", NULL },
{ "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
{ "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "cR", NULL },
/* gfc conversion specifiers. */
@ -750,6 +747,8 @@ static const format_char_info gcc_gfc_char_table[] =
/* This will require a "locus" at runtime. */
{ "L", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "R", NULL },
/* These will require nothing. */
{ "<>",0, STD_C89, NOARGUMENTS, "", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
};
@ -846,8 +845,8 @@ static const format_kind_info format_types_orig[] =
0, 0, 'p', 0, 'L', 0,
NULL, &integer_type_node
},
{ "gcc_gfc", gcc_gfc_length_specs, gcc_gfc_char_table, "", NULL,
NULL, gcc_gfc_flag_pairs,
{ "gcc_gfc", gcc_gfc_length_specs, gcc_gfc_char_table, "q+#", NULL,
gcc_gfc_flag_specs, gcc_gfc_flag_pairs,
FMT_FLAG_ARG_CONVERT,
0, 0, 0, 0, 0, 0,
NULL, NULL

View File

@ -41,8 +41,6 @@ along with GCC; see the file COPYING3. If not see
#define permissive_error_option(DC) ((DC)->opt_permissive)
/* Prototypes. */
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
static void diagnostic_action_after_output (diagnostic_context *,
@ -59,7 +57,7 @@ diagnostic_context *global_dc = &global_diagnostic_context;
/* Return a malloc'd string containing MSG formatted a la printf. The
caller is responsible for freeing the memory. */
static char *
char *
build_message_string (const char *msg, ...)
{
char *str;

View File

@ -296,4 +296,7 @@ void diagnostic_file_cache_fini (void);
/* 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;
#endif /* ! GCC_DIAGNOSTIC_H */

View File

@ -1,3 +1,28 @@
2014-08-15 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR fortran/44054
* gfortran.h: Define GCC_DIAG_STYLE.
(gfc_diagnostics_init,gfc_warning_cmdline): Declare.
* trans-array.c: Include gfortran.h before diagnostic-core.h.
* trans-expr.c: Likewise.
* trans-openmp.c: Likewise.
* trans-const.c: Likewise.
* trans.c: Likewise.
* trans-types.c: Likewise.
* f95-lang.c: Likewise.
* trans-decl.c: Likewise.
* trans-io.c: Likewise.
* trans-intrinsic.c: Likewise.
* error.c: Include diagnostic.h and diagnostic-color.h.
(gfc_diagnostic_build_prefix): New.
(gfc_diagnostic_starter): New.
(gfc_diagnostic_finalizer): New.
(gfc_warning_cmdline): New.
(gfc_diagnostics_init): New.
* gfc-diagnostic.def: New.
* options.c (gfc_init_options): Call gfc_diagnostics_init.
(gfc_post_options): Use gfc_warning_cmdline.
2014-08-15 Jakub Jelinek <jakub@redhat.com>
Tobias Burnus <burnus@net-b.de>

View File

@ -38,6 +38,8 @@ along with GCC; see the file COPYING3. If not see
# include <sys/ioctl.h>
#endif
#include "diagnostic.h"
#include "diagnostic-color.h"
static int suppress_errors = 0;
@ -956,6 +958,83 @@ gfc_warning_now (const char *gmsgid, ...)
buffer_flag = i;
}
/* Return a malloc'd string describing a location. The caller is
responsible for freeing the memory. */
static char *
gfc_diagnostic_build_prefix (diagnostic_context *context,
const diagnostic_info *diagnostic)
{
static const char *const diagnostic_kind_text[] = {
#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
#include "gfc-diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND
"must-not-happen"
};
static const char *const diagnostic_kind_color[] = {
#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
#include "gfc-diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND
NULL
};
gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
const char *text = _(diagnostic_kind_text[diagnostic->kind]);
const char *text_cs = "", *text_ce = "";
pretty_printer *pp = context->printer;
if (diagnostic_kind_color[diagnostic->kind])
{
text_cs = colorize_start (pp_show_color (pp),
diagnostic_kind_color[diagnostic->kind]);
text_ce = colorize_stop (pp_show_color (pp));
}
const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
const char *locus_ce = colorize_stop (pp_show_color (pp));
expanded_location s = expand_location_to_spelling_point (diagnostic->location);
if (diagnostic->override_column)
s.column = diagnostic->override_column;
return (s.file == NULL
? build_message_string ("%s%s:%s %s%s%s: ", locus_cs, progname, locus_ce,
text_cs, text, text_ce)
: !strcmp (s.file, N_("<built-in>"))
? build_message_string ("%s%s:%s %s%s%s: ", locus_cs, s.file, locus_ce,
text_cs, text, text_ce)
: context->show_column
? build_message_string ("%s%s:%d:%d:%s %s%s%s: ", locus_cs, s.file, s.line,
s.column, locus_ce, text_cs, text, text_ce)
: build_message_string ("%s%s:%d:%s %s%s%s: ", locus_cs, s.file, s.line, locus_ce,
text_cs, text, text_ce));
}
static void
gfc_diagnostic_starter (diagnostic_context *context,
diagnostic_info *diagnostic)
{
pp_set_prefix (context->printer, gfc_diagnostic_build_prefix (context,
diagnostic));
}
static void
gfc_diagnostic_finalizer (diagnostic_context *context ATTRIBUTE_UNUSED,
diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
{
}
/* Give a warning about the command-line. */
void
gfc_warning_cmdline (const char *gmsgid, ...)
{
va_list argp;
diagnostic_info diagnostic;
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION,
DK_WARNING);
report_diagnostic (&diagnostic);
va_end (argp);
}
/* Clear the warning flag. */
@ -1205,3 +1284,10 @@ gfc_errors_to_warnings (int f)
{
warnings_not_errors = (f == 1) ? 1 : 0;
}
void
gfc_diagnostics_init (void)
{
diagnostic_starter (global_dc) = gfc_diagnostic_starter;
diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
}

View File

@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
#include "ansidecl.h"
#include "system.h"
#include "coretypes.h"
#include "gfortran.h"
#include "tree.h"
#include "flags.h"
#include "langhooks.h"
@ -38,10 +39,9 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "target.h"
#include "debug.h"
#include "diagnostic.h"
#include "diagnostic.h" /* For errorcount/warningcount */
#include "dumpfile.h"
#include "cgraph.h"
#include "gfortran.h"
#include "cpp.h"
#include "trans.h"
#include "trans-types.h"

View File

@ -0,0 +1,47 @@
/* Copyright (C) 2001-2014 Free Software Foundation, Inc.
This file is part of GCC.
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
version.
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/>. */
/* DK_UNSPECIFIED must be first so it has a value of zero. We never
assign this kind to an actual diagnostic, we only use this in
variables that can hold a kind, to mean they have yet to have a
kind specified. I.e. they're uninitialized. Within the diagnostic
machinery, this kind also means "don't change the existing kind",
meaning "no change is specified". */
DEFINE_DIAGNOSTIC_KIND (DK_UNSPECIFIED, "", NULL)
/* If a diagnostic is set to DK_IGNORED, it won't get reported at all.
This is used by the diagnostic machinery when it wants to disable a
diagnostic without disabling the option which causes it. */
DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "", NULL)
/* The remainder are real diagnostic types. */
DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error", "error")
DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error", "error")
DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "Error", "error")
DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented", "error")
DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "Warning", "warning")
DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism", "warning")
DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note", "note")
DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug", "note")
/* These two would be re-classified as DK_WARNING or DK_ERROR, so the
prefix does not matter. */
DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn", NULL)
DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror", NULL)
/* This one is just for counting DK_WARNING promoted to DK_ERROR
due to -Werror and -Werror=warning. */
DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error", NULL)

View File

@ -31,6 +31,19 @@ along with GCC; see the file COPYING3. If not see
#error "gfortran.h must be included after coretypes.h"
#endif
/* In order for the format checking to accept the Fortran front end
diagnostic framework extensions, you must include this file before
diagnostic-core.h, not after. We override the definition of GCC_DIAG_STYLE
in c-common.h. */
#undef GCC_DIAG_STYLE
#define GCC_DIAG_STYLE __gcc_gfc__
#if defined(GCC_DIAGNOSTIC_CORE_H)
#error \
In order for the format checking to accept the Fortran front end diagnostic \
framework extensions, you must include this file before diagnostic-core.h, \
not after.
#endif
/* Declarations common to the front-end and library are put in
libgfortran/libgfortran_frontend.h */
#include "libgfortran.h"
@ -2672,12 +2685,15 @@ typedef struct gfc_error_buf
} gfc_error_buf;
void gfc_error_init_1 (void);
void gfc_diagnostics_init(void);
void gfc_buffer_error (int);
const char *gfc_print_wide_char (gfc_char_t);
void gfc_warning (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
void gfc_warning_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
void gfc_warning_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2);
void gfc_clear_warning (void);
void gfc_warning_check (void);

View File

@ -173,6 +173,7 @@ gfc_init_options (unsigned int decoded_options_count,
/* Initialize cpp-related options. */
gfc_cpp_init_options (decoded_options_count, decoded_options);
gfc_diagnostics_init ();
}
@ -352,8 +353,8 @@ gfc_post_options (const char **pfilename)
if (gfc_current_form == FORM_UNKNOWN)
{
gfc_current_form = FORM_FREE;
gfc_warning_now ("Reading file '%s' as free form",
(filename[0] == '\0') ? "<stdin>" : filename);
gfc_warning_cmdline ("Reading file %qs as free form",
(filename[0] == '\0') ? "<stdin>" : filename);
}
}
@ -362,10 +363,10 @@ gfc_post_options (const char **pfilename)
if (gfc_current_form == FORM_FREE)
{
if (gfc_option.flag_d_lines == 0)
gfc_warning_now ("'-fd-lines-as-comments' has no effect "
"in free form");
gfc_warning_cmdline ("%<-fd-lines-as-comments%> has no effect "
"in free form");
else if (gfc_option.flag_d_lines == 1)
gfc_warning_now ("'-fd-lines-as-code' has no effect in free form");
gfc_warning_cmdline ("%<-fd-lines-as-code%> has no effect in free form");
}
/* If -pedantic, warn about the use of GNU extensions. */
@ -383,21 +384,21 @@ gfc_post_options (const char **pfilename)
if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
&& gfc_option.flag_max_stack_var_size != 0)
gfc_warning_now ("Flag -fno-automatic overwrites -fmax-stack-var-size=%d",
gfc_option.flag_max_stack_var_size);
gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
gfc_option.flag_max_stack_var_size);
else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
gfc_warning_now ("Flag -fno-automatic overwrites -frecursive");
gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%>");
else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
gfc_warning_now ("Flag -fno-automatic overwrites -frecursive implied by "
"-fopenmp");
gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
"%<-fopenmp%>");
else if (gfc_option.flag_max_stack_var_size != -2
&& gfc_option.flag_recursive)
gfc_warning_now ("Flag -frecursive overwrites -fmax-stack-var-size=%d",
gfc_option.flag_max_stack_var_size);
gfc_warning_cmdline ("Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
gfc_option.flag_max_stack_var_size);
else if (gfc_option.flag_max_stack_var_size != -2
&& gfc_option.gfc_flag_openmp)
gfc_warning_now ("Flag -fmax-stack-var-size=%d overwrites -frecursive "
"implied by -fopenmp",
gfc_warning_cmdline ("Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
"implied by %<-fopenmp%>",
gfc_option.flag_max_stack_var_size);
/* Implement -frecursive as -fmax-stack-var-size=-1. */

View File

@ -78,11 +78,11 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "gfortran.h"
#include "tree.h"
#include "gimple-expr.h"
#include "diagnostic-core.h" /* For internal_error/fatal_error. */
#include "flags.h"
#include "gfortran.h"
#include "constructor.h"
#include "trans.h"
#include "trans-stmt.h"

View File

@ -23,12 +23,12 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "gfortran.h"
#include "tree.h"
#include "stor-layout.h"
#include "realmpfr.h"
#include "diagnostic-core.h" /* For fatal_error. */
#include "double-int.h"
#include "gfortran.h"
#include "trans.h"
#include "trans-const.h"
#include "trans-types.h"

View File

@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "gfortran.h"
#include "tree.h"
#include "stringpool.h"
#include "stor-layout.h"
@ -39,7 +40,6 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h"
#include "cgraph.h"
#include "debug.h"
#include "gfortran.h"
#include "hash-set.h"
#include "constructor.h"
#include "trans.h"

View File

@ -24,12 +24,12 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "gfortran.h"
#include "tree.h"
#include "stringpool.h"
#include "diagnostic-core.h" /* For fatal_error. */
#include "langhooks.h"
#include "flags.h"
#include "gfortran.h"
#include "arith.h"
#include "constructor.h"
#include "trans.h"

View File

@ -30,10 +30,10 @@ along with GCC; see the file COPYING3. If not see
#include "tree-nested.h"
#include "stor-layout.h"
#include "ggc.h"
#include "gfortran.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "toplev.h" /* For rest_of_decl_compilation. */
#include "flags.h"
#include "gfortran.h"
#include "arith.h"
#include "intrinsic.h"
#include "trans.h"

View File

@ -26,8 +26,8 @@ along with GCC; see the file COPYING3. If not see
#include "stringpool.h"
#include "stor-layout.h"
#include "ggc.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "gfortran.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "trans.h"
#include "trans-stmt.h"
#include "trans-array.h"

View File

@ -26,8 +26,8 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-expr.h"
#include "gimplify.h" /* For create_tmp_var_raw. */
#include "stringpool.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "gfortran.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "trans.h"
#include "trans-stmt.h"
#include "trans-types.h"

View File

@ -39,9 +39,9 @@ along with GCC; see the file COPYING3. If not see
#include "langhooks.h" /* For iso-c-bindings.def. */
#include "target.h"
#include "ggc.h"
#include "gfortran.h"
#include "diagnostic-core.h" /* For fatal_error. */
#include "toplev.h" /* For rest_of_decl_compilation. */
#include "gfortran.h"
#include "trans.h"
#include "trans-types.h"
#include "trans-const.h"

View File

@ -21,13 +21,13 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "gfortran.h"
#include "tree.h"
#include "gimple-expr.h" /* For create_tmp_var_raw. */
#include "stringpool.h"
#include "tree-iterator.h"
#include "diagnostic-core.h" /* For internal_error. */
#include "flags.h"
#include "gfortran.h"
#include "trans.h"
#include "trans-stmt.h"
#include "trans-array.h"