Patchwork Ping: Re: pragma diagnostic push/pop

login
register
mail settings
Submitter DJ Delorie
Date June 21, 2010, 10:21 p.m.
Message ID <201006212221.o5LMLOBY007390@greed.delorie.com>
Download mbox | patch
Permalink /patch/56357/
State New
Headers show

Comments

DJ Delorie - June 21, 2010, 10:21 p.m.
Here you go, enjoy :-)
Gerald Pfeifer - June 21, 2010, 10:30 p.m.
On Mon, 21 Jun 2010, DJ Delorie wrote:
> Here you go, enjoy :-)

Thanks, DJ!  The main suggestion I have is whether you could add an
example of how this look like?

Do I understand correctly that the first aspect (position sensitivity)
applying in general, and that for the second half something like the
following (properly replacing SOMETHINGHERE? and THESMAETHINGHERE?)
would be a suitable example?

  /* Some C code. */
  #pragma push SOMETHINGHERE?
  some; other; C(code);
  #pragma pop THESAMETHINGHERE?
  /* Yet some more C code. */

Gerald
DJ Delorie - June 21, 2010, 10:38 p.m.
The test case is probably an ideal example (minus dejagnuisms).  I assume the
usual usage will be "push; reclassify; some code; pop".

/* { dg-do compile } */
/* { dg-options "-Wuninitialized -O2" } */
/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */

main()
{
  int a;
  int b;
  int c;
  int d;

#pragma GCC diagnostic error "-Wuninitialized"
  foo(a);			/* { dg-error "uninitialized" } */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
  foo(b);
#pragma GCC diagnostic pop
  foo(c);			/* { dg-error "uninitialized" } */
#pragma GCC diagnostic pop
  foo(d);			/* { dg-warning "uninitialized" } */
}
Manuel López-Ibáñez - June 22, 2010, 7:31 a.m.
On 22 June 2010 00:21, DJ Delorie <dj@redhat.com> wrote:
>
> Here you go, enjoy :-)
>
> Index: changes.html
> ===================================================================
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.6/changes.html,v
> retrieving revision 1.18
> diff -p -U3 -r1.18 changes.html
> --- changes.html        13 Jun 2010 12:44:28 -0000      1.18
> +++ changes.html        21 Jun 2010 22:20:12 -0000
> @@ -141,6 +141,14 @@
>  <h2>Documentation improvements</h2>
>
>  <h2>Other significant improvements</h2>
> +<ul>
> +  <li>The diagnostics pragmas have been expanded to be
> +  position-sensitive - a pragma in the middle of a source file only
> +  affects diagnostics that occur after it in the source.  The compiler
> +  can be told to save and restore the diagnostic state, so that
> +  diagnostics can (for example) be temporarily suppressed around a
> +  source line.</li>
> +</ul>
>


The <a href="http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas">diagnostics
pragmas</a> have been expanded to be position-sensitive: A pragma in
the middle of a source file only affects diagnostics that occur after
it in the source. New pragmas <code>#pragma GCC diagnostic
push/pop</code> tell the compiler to save and restore the state of
diagnostics, so that, for example, diagnostics can be temporarily
suppressed around a source line.

<pre>
/* Compiled with -O2 -Wuninitialized */
main()
{
 int a;
 int b;
 int c;
 int d;

#pragma GCC diagnostic error "-Wuninitialized"
 foo(a);                       /* "error: uninitialized" */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
 foo(b);
#pragma GCC diagnostic pop
 foo(c);                       /* "error :uninitialized" }*/
#pragma GCC diagnostic pop
 foo(d);                       /* "warning: uninitialized"
(command-line setting) */
}
</pre>

I may be wrong, but I am pretty sure this example does not actually
require -O2. We should warn for this at -O0 since at least GCC 4.4

Cheers,

Manuel.

Patch

Index: changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.6/changes.html,v
retrieving revision 1.18
diff -p -U3 -r1.18 changes.html
--- changes.html        13 Jun 2010 12:44:28 -0000      1.18
+++ changes.html        21 Jun 2010 22:20:12 -0000
@@ -141,6 +141,14 @@ 
 <h2>Documentation improvements</h2>
 
 <h2>Other significant improvements</h2>
+<ul>
+  <li>The diagnostics pragmas have been expanded to be
+  position-sensitive - a pragma in the middle of a source file only
+  affects diagnostics that occur after it in the source.  The compiler
+  can be told to save and restore the diagnostic state, so that
+  diagnostics can (for example) be temporarily suppressed around a
+  source line.</li>
+</ul>
 
 </body>
 </html>