aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2015-08-11 13:34:00 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2015-08-11 13:34:00 +0000
commitb32bc1ac16670eef2a0e61ae7bad47f8cfd278ed (patch)
treea12c2f52d788ca60fdf10a283f4349676f1fe125
parent8299dd5cbb6fbb756f0ad2f4dbff31c549e00837 (diff)
downloadgcc-b32bc1ac16670eef2a0e61ae7bad47f8cfd278ed.zip
gcc-b32bc1ac16670eef2a0e61ae7bad47f8cfd278ed.tar.gz
gcc-b32bc1ac16670eef2a0e61ae7bad47f8cfd278ed.tar.bz2
re PR c/66098 (#pragma diagnostic 'ignored' not fully undone by pop for strict-overflow)
gcc/ChangeLog: 2015-08-11 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c/66098 PR c/66711 * diagnostic.c (diagnostic_classify_diagnostic): Take -Werror into account when deciding what was the command-line status. gcc/testsuite/ChangeLog: 2015-08-11 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c/66098 PR c/66711 * gcc.dg/pragma-diag-3.c: New test. * gcc.dg/pragma-diag-4.c: New test. From-SVN: r226780
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/diagnostic.c7
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/pragma-diag-3.c64
-rw-r--r--gcc/testsuite/gcc.dg/pragma-diag-4.c48
5 files changed, 130 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cb2d6a0..099d2c1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-08-11 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c/66098
+ PR c/66711
+ * diagnostic.c (diagnostic_classify_diagnostic): Take -Werror into
+ account when deciding what was the command-line status.
+
2015-08-11 Nathan Sidwell <nathan@acm.org>
* tree-vrp.c (simplify_abs_using_ranges): Simplify.
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index fb9d1fbf..01a8e35 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -696,9 +696,10 @@ diagnostic_classify_diagnostic (diagnostic_context *context,
/* Record the command-line status, so we can reset it back on DK_POP. */
if (old_kind == DK_UNSPECIFIED)
{
- old_kind = context->option_enabled (option_index,
- context->option_state)
- ? DK_WARNING : DK_IGNORED;
+ old_kind = !context->option_enabled (option_index,
+ context->option_state)
+ ? DK_IGNORED : (context->warning_as_error_requested
+ ? DK_ERROR : DK_WARNING);
context->classify_diagnostic[option_index] = old_kind;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8d4903f..7a35aad 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2015-08-11 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c/66098
+ PR c/66711
+ * gcc.dg/pragma-diag-3.c: New test.
+ * gcc.dg/pragma-diag-4.c: New test.
+
2015-08-11 Nathan Sidwell <nathan@acm.org>
* c-c++-common/dfp/operator-comma.c: Call init function.
diff --git a/gcc/testsuite/gcc.dg/pragma-diag-3.c b/gcc/testsuite/gcc.dg/pragma-diag-3.c
new file mode 100644
index 0000000..2ee439d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pragma-diag-3.c
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-options "-Wswitch-enum -Wsign-compare -fstrict-overflow -Wstrict-overflow -Werror -Wno-error=switch-enum" } */
+/* PR c/66098 - #pragma diagnostic 'ignored' not fully undone by pop for strict-overflow
+ PR c/66711 - GCC does not correctly restore diagnostic state after pragma GCC diagnostic pop with -Werror
+*/
+/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */
+
+void testing2() {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstrict-overflow"
+ int j = 4;
+ j + 4 < j;
+#pragma GCC diagnostic pop
+}
+
+void testing3() {
+ int k = 4;
+ k + 4 < k; /* { dg-error "overflow" } */
+}
+
+int bar()
+{
+ unsigned x = 0;
+ int y = 1;
+
+ /* generates an error - ok */
+ x += x < y ? 1 : 0; /* { dg-error "comparison" } */
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-compare"
+ /* generates no diagnostic - ok */
+ x += x < y ? 1 : 0;
+#pragma GCC diagnostic pop
+
+ x += x < y ? 1 : 0; /* { dg-error "comparison" } */
+
+ return x;
+}
+
+enum EE { ONE, TWO };
+
+int f (enum EE e)
+{
+ int r = 0;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch-enum"
+
+ switch (e)
+ {
+ case ONE:
+ r = 1;
+ break;
+ }
+#pragma GCC diagnostic pop
+
+ switch (e) /* { dg-warning "switch" } */
+ {
+ case ONE:
+ r = 1;
+ break;
+ }
+ return r;
+}
diff --git a/gcc/testsuite/gcc.dg/pragma-diag-4.c b/gcc/testsuite/gcc.dg/pragma-diag-4.c
new file mode 100644
index 0000000..fc8d4b1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pragma-diag-4.c
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-Wsign-compare -Werror=sign-compare -Werror=switch-enum" } */
+/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */
+
+int bar()
+{
+ unsigned x = 0;
+ int y = 1;
+
+ /* generates an error - ok */
+ x += x < y ? 1 : 0; /* { dg-error "comparison" } */
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-compare"
+ /* generates no diagnostic - ok */
+ x += x < y ? 1 : 0;
+#pragma GCC diagnostic pop
+
+ x += x < y ? 1 : 0; /* { dg-error "comparison" } */
+
+ return x;
+}
+
+enum EE { ONE, TWO };
+
+int f (enum EE e)
+{
+ int r = 0;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch-enum"
+
+ switch (e)
+ {
+ case ONE:
+ r = 1;
+ break;
+ }
+#pragma GCC diagnostic pop
+
+ switch (e) /* { dg-error "switch" } */
+ {
+ case ONE:
+ r = 1;
+ break;
+ }
+ return r;
+}