aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2014-08-15 15:10:15 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2014-08-15 15:10:15 +0000
commit8e54f6d3bac9f2e2626e4a1496e01a243d91b9d0 (patch)
treeff48278d43446ffb9145fbbac3289b0d898cacfa /gcc/fortran
parent363785f63edd6a56427b6aa3f256ffac9a2d376d (diff)
downloadgcc-8e54f6d3bac9f2e2626e4a1496e01a243d91b9d0.zip
gcc-8e54f6d3bac9f2e2626e4a1496e01a243d91b9d0.tar.gz
gcc-8e54f6d3bac9f2e2626e4a1496e01a243d91b9d0.tar.bz2
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
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/ChangeLog25
-rw-r--r--gcc/fortran/error.c86
-rw-r--r--gcc/fortran/f95-lang.c4
-rw-r--r--gcc/fortran/gfc-diagnostic.def47
-rw-r--r--gcc/fortran/gfortran.h16
-rw-r--r--gcc/fortran/options.c29
-rw-r--r--gcc/fortran/trans-array.c2
-rw-r--r--gcc/fortran/trans-const.c2
-rw-r--r--gcc/fortran/trans-decl.c2
-rw-r--r--gcc/fortran/trans-expr.c2
-rw-r--r--gcc/fortran/trans-intrinsic.c2
-rw-r--r--gcc/fortran/trans-io.c2
-rw-r--r--gcc/fortran/trans-openmp.c2
-rw-r--r--gcc/fortran/trans-types.c2
-rw-r--r--gcc/fortran/trans.c2
15 files changed, 200 insertions, 25 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 411fe4c..2663b0a 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -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>
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 6ae44e8..e3f44f7 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -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;
+}
diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c
index 83f7eb2..da3a0d0 100644
--- a/gcc/fortran/f95-lang.c
+++ b/gcc/fortran/f95-lang.c
@@ -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"
diff --git a/gcc/fortran/gfc-diagnostic.def b/gcc/fortran/gfc-diagnostic.def
new file mode 100644
index 0000000..0f1044d
--- /dev/null
+++ b/gcc/fortran/gfc-diagnostic.def
@@ -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)
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index e84acea..d6fccee 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -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);
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index e4931f0..508a01c 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -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. */
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index c30318a..123df5d 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -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"
diff --git a/gcc/fortran/trans-const.c b/gcc/fortran/trans-const.c
index 34ab78e..9135f29 100644
--- a/gcc/fortran/trans-const.c
+++ b/gcc/fortran/trans-const.c
@@ -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"
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index bf91413..25ab419 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -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"
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1726d0f..544fc76 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -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"
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 9059878..fd3c46a 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -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"
diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index fb6f69f..cbe54ab 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -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"
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 548b5d3..c8028ab 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -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"
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index ad28c28..d455bf4 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -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"
diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index 1925506..2cc701e 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -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"