re PR other/30824 (-Werror -Wfatal-errors should stop after the first warning)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 20 Feb 2007 10:18:58 +0000 (10:18 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 20 Feb 2007 10:18:58 +0000 (10:18 +0000)
2007-02-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
            DJ Delorie <dj@redhat.com>

PR other/30824
* diagnostic.c (diagnostic_count_diagnostic): Move -Werror
logic to...
(diagnostic_report_diagnostic): ... here, and turn them into
real errors. If warnings are inhibited, no need to do
anything.

testsuite/
* gcc.dg/Wfatal.c: New.
* gcc.dg/Wfatal-2.c: New.
* gcc.dg/Werror-1.c: Adjust expectations.
* gcc.dg/Werror-5.c: Likewise.
* gcc.dg/Werror-7.c: Likewise.
* gcc.dg/Werror-10.c: Likewise.
* gcc.dg/Werror-11.c: Likewise.

Co-Authored-By: DJ Delorie <dj@redhat.com>
From-SVN: r122159

gcc/ChangeLog
gcc/diagnostic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Werror-1.c
gcc/testsuite/gcc.dg/Werror-10.c
gcc/testsuite/gcc.dg/Werror-11.c
gcc/testsuite/gcc.dg/Werror-5.c
gcc/testsuite/gcc.dg/Werror-7.c
gcc/testsuite/gcc.dg/Wfatal-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wfatal.c [new file with mode: 0644]

index d57787877550ec4fb051c14d31f826e106d9426f..ebceb404f1a7cf48b5d0049a1a919d59e14d3871 100644 (file)
@@ -1,3 +1,11 @@
+2007-02-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+            DJ Delorie <dj@redhat.com>
+
+       PR other/30824
+       * diagnostic.c (diagnostic_count_diagnostic): Move -Werror logic to...
+       (diagnostic_report_diagnostic): ... here, and turn them into real
+       errors. If warnings are inhibited, no need to do anything.
+
 2007-02-20  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (expm1xf2): Reorder insn sequence for
index 3691477e07b5bc68de9f8469d2e2270f5241ac4a..2199c7d24dbf98f7f34ef66af276fd55e35813e4 100644 (file)
@@ -202,27 +202,9 @@ diagnostic_count_diagnostic (diagnostic_context *context,
       break;
 
     case DK_WARNING:
-      if (!diagnostic_report_warnings_p ())
-        return false;
-
-      /* -Werror can reclassify warnings as errors, but
-        classify_diagnostic can reclassify it back to a warning.  The
-        second part of this test detects that case.  */
-      if (!context->warning_as_error_requested
-         || (context->classify_diagnostic[diagnostic->option_index]
-             == DK_WARNING))
-        {
-          ++diagnostic_kind_count (context, DK_WARNING);
-          break;
-        }
-      else if (context->issue_warnings_are_errors_message)
-        {
-         pp_verbatim (context->printer,
-                       "%s: warnings being treated as errors\n", progname);
-          context->issue_warnings_are_errors_message = false;
-        }
+      ++diagnostic_kind_count (context, DK_WARNING);
+      break;
 
-      /* And fall through.  */
     case DK_ERROR:
       ++diagnostic_kind_count (context, DK_ERROR);
       break;
@@ -362,6 +344,14 @@ void
 diagnostic_report_diagnostic (diagnostic_context *context,
                              diagnostic_info *diagnostic)
 {
+  bool maybe_print_warnings_as_errors_message = false;
+
+  /* Give preference to being able to inhibit warnings, before they
+     get reclassified to something else.  */
+  if (diagnostic->kind == DK_WARNING 
+      && !diagnostic_report_warnings_p ())
+    return;
+  
   if (context->lock > 0)
     {
       /* If we're reporting an ICE in the middle of some other error,
@@ -373,6 +363,17 @@ diagnostic_report_diagnostic (diagnostic_context *context,
        error_recursion (context);
     }
 
+  /* If the user requested that warnings be treated as errors, so be
+     it.  Note that we do this before the next block so that
+     individual warnings can be overridden back to warnings with
+     -Wno-error=*.  */
+  if (context->warning_as_error_requested
+      && diagnostic->kind == DK_WARNING)
+    {
+      diagnostic->kind = DK_ERROR;
+      maybe_print_warnings_as_errors_message = true;
+    }
+  
   if (diagnostic->option_index)
     {
       /* This tests if the user provided the appropriate -Wfoo or
@@ -382,13 +383,26 @@ diagnostic_report_diagnostic (diagnostic_context *context,
       /* This tests if the user provided the appropriate -Werror=foo
         option.  */
       if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
-       diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
+       {
+         diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
+         maybe_print_warnings_as_errors_message = false;
+       }
       /* This allows for future extensions, like temporarily disabling
         warnings for ranges of source code.  */
       if (diagnostic->kind == DK_IGNORED)
        return;
     }
 
+  /* If we changed the kind due to -Werror, and didn't override it, we
+     need to print this message.  */
+  if (context->issue_warnings_are_errors_message
+      && maybe_print_warnings_as_errors_message)
+    {
+      pp_verbatim (context->printer,
+                  "%s: warnings being treated as errors\n", progname);
+      context->issue_warnings_are_errors_message = false;
+    }
+
   context->lock++;
 
   if (diagnostic_count_diagnostic (context, diagnostic))
index 8e85108942fe811573b9e0c643e1b29d93ffd06a..b5f91c5e7ddce705174b19fe3435c8316c703768 100644 (file)
@@ -1,3 +1,15 @@
+2007-02-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+            DJ Delorie <dj@redhat.com>
+
+       PR other/30824
+       * gcc.dg/Wfatal.c: New.
+       * gcc.dg/Wfatal-2.c: New.
+       * gcc.dg/Werror-1.c: Adjust expectations.
+       * gcc.dg/Werror-5.c: Likewise.
+       * gcc.dg/Werror-7.c: Likewise.
+       * gcc.dg/Werror-10.c: Likewise.
+       * gcc.dg/Werror-11.c: Likewise.
+
 2007-02-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/30522
index 7984740ca88d5108dfc268fa2dae1a1dde4387d9..33fc1d3583c2c44046cf57432044f8fc84457940 100644 (file)
@@ -9,7 +9,7 @@
 
 #pragma GCC diagnostic error "-Waddress"
 
-void __attribute__((dj)) bar() { }     /* { dg-warning "warning: .* attribute directive ignored" } */
+void __attribute__((dj)) bar() { }     /* { dg-error "error: .* attribute directive ignored" } */
 
 int i;
 
index eeadf512b5ba50553674cf878cc22ab7ef8df7c8..f564654513210bc557f6251ea920f10048d65115 100644 (file)
@@ -6,7 +6,7 @@
 
 #pragma GCC diagnostic error "-Waddress"
 
-void __attribute__((dj)) bar() { }     /* { dg-warning "warning: .* attribute directive ignored" } */
+void __attribute__((dj)) bar() { }     /* { dg-error "error: .* attribute directive ignored" } */
 
 int i;
 
index 493ded044a828085ee1774b20674ec57ff75f63d..0dea5faf6a88aa22c99809c9d66a5c0ba4b24f6d 100644 (file)
@@ -6,7 +6,7 @@
 
 #pragma GCC diagnostic warning "-Waddress"
 
-void __attribute__((dj)) bar() { }     /* { dg-warning "warning: .* attribute directive ignored" } */
+void __attribute__((dj)) bar() { }     /* { dg-error "error: .* attribute directive ignored" } */
 
 int i;
 
index 40d3cd1f7ad3afa0db4ce852467eb73f550df82a..8a21593fbd87d0a7b407cd1beb6dc8e97e7b7c87 100644 (file)
@@ -4,13 +4,13 @@
 
 /* Make sure -Werror turns warnings in to errors.  */
 
-void __attribute__((dj)) bar() { }     /* { dg-warning "warning: .* attribute directive ignored" } */
+void __attribute__((dj)) bar() { }     /* { dg-error "error: .* attribute directive ignored" } */
 
 int i;
 
 void
 foo ()
 {
-  if (&i)      /* { dg-warning "warning: .* will always evaluate as 'true'" } */
+  if (&i)      /* { dg-error "error: .* will always evaluate as 'true'" } */
     grill ();
 }
index 9829ce9e4f744745163a69fb6283fd89f29a6581..6a69fae4ded0e8c9b6142b2a4b41bb11a819d9e6 100644 (file)
@@ -4,7 +4,7 @@
 
 /* Make sure -Wno-error= overrides -Werror.  */
 
-void __attribute__((dj)) bar() { }     /* { dg-warning "warning: .* attribute directive ignored" } */
+void __attribute__((dj)) bar() { }     /* { dg-error "error: .* attribute directive ignored" } */
 
 int i;
 
diff --git a/gcc/testsuite/gcc.dg/Wfatal-2.c b/gcc/testsuite/gcc.dg/Wfatal-2.c
new file mode 100644 (file)
index 0000000..cbb7c8e
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-Woverflow -Wdiv-by-zero -Werror -Wfatal-errors" } */
+#include <limits.h>
+
+int i = INT_MAX + 1; /* { dg-error "integer overflow in expression" } */
+int k = 1 / 0; 
+int j = INT_MIN - 1;
+/* { dg-warning "being treated as errors" "" { target *-*-* } 0 } */
+/* { dg-warning "terminated due to -Wfatal-errors" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.dg/Wfatal.c b/gcc/testsuite/gcc.dg/Wfatal.c
new file mode 100644 (file)
index 0000000..bb3efc8
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Woverflow -Werror=div-by-zero -Wfatal-errors" } */
+#include <limits.h>
+
+int i = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */
+int k = 1 / 0; /* { dg-error "division by zero" } */
+int j = INT_MIN - 1;
+/* { dg-warning "terminated due to -Wfatal-errors" "" { target *-*-* } 0 } */
+
+
+