Patchwork Fix thinko in handle_error_attribute (PR middle-end/56167)

login
register
mail settings
Submitter Jakub Jelinek
Date Feb. 4, 2013, 4:25 p.m.
Message ID <20130204162511.GC4385@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/217987/
State New
Headers show

Comments

Jakub Jelinek - Feb. 4, 2013, 4:25 p.m.
Hi!

Without this fix, we were letting in invalid error/warning attributes,
on function decls in addition to valid ones with STRING_CST argument also
attributes with various bogus arguments, and for e.g. VAR_DECLs which
shouldn't have any error/warning attributes those with STRING_CST arguments.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2013-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/56167
	* c-common.c (handle_error_attribute): Fix condition.

	* gcc.dg/pr56167.c: New test.


	Jakub
Joseph S. Myers - Feb. 5, 2013, 1:40 a.m.
On Mon, 4 Feb 2013, Jakub Jelinek wrote:

> Hi!
> 
> Without this fix, we were letting in invalid error/warning attributes,
> on function decls in addition to valid ones with STRING_CST argument also
> attributes with various bogus arguments, and for e.g. VAR_DECLs which
> shouldn't have any error/warning attributes those with STRING_CST arguments.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

Patch

--- gcc/c-family/c-common.c.jj	2013-01-30 19:01:11.000000000 +0100
+++ gcc/c-family/c-common.c	2013-02-01 08:46:07.741550116 +0100
@@ -6678,7 +6678,7 @@  handle_error_attribute (tree *node, tree
 			int ARG_UNUSED (flags), bool *no_add_attrs)
 {
   if (TREE_CODE (*node) == FUNCTION_DECL
-      || TREE_CODE (TREE_VALUE (args)) == STRING_CST)
+      && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
     /* Do nothing else, just set the attribute.  We'll get at
        it later with lookup_attribute.  */
     ;
--- gcc/testsuite/gcc.dg/pr56167.c.jj	2013-02-01 08:50:11.268198682 +0100
+++ gcc/testsuite/gcc.dg/pr56167.c	2013-02-01 08:49:43.000000000 +0100
@@ -0,0 +1,15 @@ 
+/* PR middle-end/56167 */
+/* { dg-do compile } */
+
+extern void foo (void) __attribute__ ((error (0)));	/* { dg-warning "attribute ignored" } */
+extern void bar (void) __attribute__ ((warning (0)));	/* { dg-warning "attribute ignored" } */
+int var __attribute__ ((error ("foo")));		/* { dg-warning "attribute ignored" } */
+
+int
+main ()
+{
+  foo ();
+  bar ();
+  var++;
+  return 0;
+}