public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status
@ 2015-07-30 16:08 Manuel López-Ibáñez
  2015-08-03 18:48 ` Manuel López-Ibáñez
  2015-08-11 13:01 ` Marek Polacek
  0 siblings, 2 replies; 5+ messages in thread
From: Manuel López-Ibáñez @ 2015-07-30 16:08 UTC (permalink / raw)
  To: Gcc Patch List, Dodji Seketeli, Joseph S. Myers, Marek Polacek,
	Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

When I fixed PR59304, I forgot that a command-line warning can be also
an error if -Werror was enabled. This introduced a regression since
anything enabled in the command-line together with -Werror would get
initially classified as a warning when reaching the first #pragma GCC
diagnostic, and this will be the setting after a #pragma pop.

Options that appear as arguments of -W[no-]error= are not affected by
this since those are initially classified as errors/warnings even
before reaching the first #pragma, thus the pop sets them correctly
(before and after this patch). Nonetheless, the tests also check that
they work correctly.

Boot&regtested on x86_64-linux-gnu.

OK?


gcc/ChangeLog:

2015-07-29  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-07-29  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.

[-- Attachment #2: fix-pr66098.diff --]
[-- Type: text/plain, Size: 3756 bytes --]

Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revision 226312)
+++ gcc/diagnostic.c	(working copy)
@@ -694,13 +694,14 @@ diagnostic_classify_diagnostic (diagnost
       int i;
 
       /* 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;
 	}
 
       for (i = context->n_classification_history - 1; i >= 0; i --)
 	if (context->classification_history[i].option == option_index)
Index: gcc/testsuite/gcc.dg/pragma-diag-3.c
===================================================================
--- gcc/testsuite/gcc.dg/pragma-diag-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pragma-diag-3.c	(revision 0)
@@ -0,0 +1,72 @@
+/* { 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 foo() {
+  testing2();
+  testing3();
+
+  return 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-warning "switch" } */
+    {
+    case ONE:
+      r = 1;
+      break;
+    }
+  return r;
+}
Index: gcc/testsuite/gcc.dg/pragma-diag-4.c
===================================================================
--- gcc/testsuite/gcc.dg/pragma-diag-4.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pragma-diag-4.c	(revision 0)
@@ -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;
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status
  2015-07-30 16:08 PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status Manuel López-Ibáñez
@ 2015-08-03 18:48 ` Manuel López-Ibáñez
  2015-08-11 13:01 ` Marek Polacek
  1 sibling, 0 replies; 5+ messages in thread
From: Manuel López-Ibáñez @ 2015-08-03 18:48 UTC (permalink / raw)
  To: Gcc Patch List, Dodji Seketeli, Joseph S. Myers, Marek Polacek,
	Jason Merrill

PING: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02581.html

Thanks,

Manuel.

On 30 July 2015 at 17:35, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> When I fixed PR59304, I forgot that a command-line warning can be also
> an error if -Werror was enabled. This introduced a regression since
> anything enabled in the command-line together with -Werror would get
> initially classified as a warning when reaching the first #pragma GCC
> diagnostic, and this will be the setting after a #pragma pop.
>
> Options that appear as arguments of -W[no-]error= are not affected by
> this since those are initially classified as errors/warnings even
> before reaching the first #pragma, thus the pop sets them correctly
> (before and after this patch). Nonetheless, the tests also check that
> they work correctly.
>
> Boot&regtested on x86_64-linux-gnu.
>
> OK?
>
>
> gcc/ChangeLog:
>
> 2015-07-29  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-07-29  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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status
  2015-07-30 16:08 PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status Manuel López-Ibáñez
  2015-08-03 18:48 ` Manuel López-Ibáñez
@ 2015-08-11 13:01 ` Marek Polacek
  1 sibling, 0 replies; 5+ messages in thread
From: Marek Polacek @ 2015-08-11 13:01 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: Gcc Patch List, Dodji Seketeli, Joseph S. Myers, Jason Merrill

On Thu, Jul 30, 2015 at 05:35:39PM +0200, Manuel López-Ibáñez wrote:
> When I fixed PR59304, I forgot that a command-line warning can be also
> an error if -Werror was enabled. This introduced a regression since
> anything enabled in the command-line together with -Werror would get
> initially classified as a warning when reaching the first #pragma GCC
> diagnostic, and this will be the setting after a #pragma pop.
> 
> Options that appear as arguments of -W[no-]error= are not affected by
> this since those are initially classified as errors/warnings even
> before reaching the first #pragma, thus the pop sets them correctly
> (before and after this patch). Nonetheless, the tests also check that
> they work correctly.

Sorry for the delay (vacation/Cauldron).

> Index: gcc/diagnostic.c
> ===================================================================
> --- gcc/diagnostic.c	(revision 226312)
> +++ gcc/diagnostic.c	(working copy)
> @@ -694,13 +694,14 @@ diagnostic_classify_diagnostic (diagnost
>        int i;
>  
>        /* 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);

Missing space before the colon.

> Index: gcc/testsuite/gcc.dg/pragma-diag-3.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/pragma-diag-3.c	(revision 0)
> +++ gcc/testsuite/gcc.dg/pragma-diag-3.c	(revision 0)
> @@ -0,0 +1,72 @@
> +/* { 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 foo() {
> +  testing2();
> +  testing3();
> +
> +  return 0;
> +}
> +
> +

I think you can drop the foo function.

Otherwise LGTM.

	Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status
  2015-08-10 14:38 Manuel López-Ibáñez
@ 2015-08-11 19:53 ` Jeff Law
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Law @ 2015-08-11 19:53 UTC (permalink / raw)
  To: Manuel López-Ibáñez, Gcc Patch List,
	Dodji Seketeli, Joseph S. Myers, Marek Polacek, Jason Merrill

On 08/10/2015 08:37 AM, Manuel López-Ibáñez wrote:
> PING^2: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02581.html
>
> On 3 August 2015 at 20:47, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
>> PING: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02581.html
>>
>> Thanks,
>>
>> Manuel.
>>
>> On 30 July 2015 at 17:35, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
>>> When I fixed PR59304, I forgot that a command-line warning can be also
>>> an error if -Werror was enabled. This introduced a regression since
>>> anything enabled in the command-line together with -Werror would get
>>> initially classified as a warning when reaching the first #pragma GCC
>>> diagnostic, and this will be the setting after a #pragma pop.
>>>
>>> Options that appear as arguments of -W[no-]error= are not affected by
>>> this since those are initially classified as errors/warnings even
>>> before reaching the first #pragma, thus the pop sets them correctly
>>> (before and after this patch). Nonetheless, the tests also check that
>>> they work correctly.
>>>
>>> Boot&regtested on x86_64-linux-gnu.
>>>
>>> OK?
>>>
>>>
>>> gcc/ChangeLog:
>>>
>>> 2015-07-29  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-07-29  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.
OK
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status
@ 2015-08-10 14:38 Manuel López-Ibáñez
  2015-08-11 19:53 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2015-08-10 14:38 UTC (permalink / raw)
  To: Gcc Patch List, Dodji Seketeli, Joseph S. Myers, Marek Polacek,
	Jason Merrill

PING^2: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02581.html

On 3 August 2015 at 20:47, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> PING: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02581.html
>
> Thanks,
>
> Manuel.
>
> On 30 July 2015 at 17:35, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
>> When I fixed PR59304, I forgot that a command-line warning can be also
>> an error if -Werror was enabled. This introduced a regression since
>> anything enabled in the command-line together with -Werror would get
>> initially classified as a warning when reaching the first #pragma GCC
>> diagnostic, and this will be the setting after a #pragma pop.
>>
>> Options that appear as arguments of -W[no-]error= are not affected by
>> this since those are initially classified as errors/warnings even
>> before reaching the first #pragma, thus the pop sets them correctly
>> (before and after this patch). Nonetheless, the tests also check that
>> they work correctly.
>>
>> Boot&regtested on x86_64-linux-gnu.
>>
>> OK?
>>
>>
>> gcc/ChangeLog:
>>
>> 2015-07-29  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-07-29  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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-11 19:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-30 16:08 PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status Manuel López-Ibáñez
2015-08-03 18:48 ` Manuel López-Ibáñez
2015-08-11 13:01 ` Marek Polacek
2015-08-10 14:38 Manuel López-Ibáñez
2015-08-11 19:53 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).