[patch] Fix PR c++/28112: ICE with invalid argument in attribute

Volker Reichelt reichelt@igpm.rwth-aachen.de
Wed Jun 21 11:28:00 GMT 2006


The following invalid code snippet crashes the C++ frontend since GCC 3.4.0:

  struct A {} __attribute__((aligned(;)));

bug.cc:1: error: expected primary-expression before ';' token
bug.cc:1: error: expected `)' before ';' token
bug.cc:1: error: expected `)' before ';' token
bug.cc:1: internal compiler error: tree check: expected tree_list, have
error_mark in handle_aligned_attribute, at c-common.c:4698
Please submit a full bug report, [etc.]

This happens more or less with all attributes that take an argument list.
The patch fixes the problem by checking for invalid argument lists in
decl_attributes before calling the attribute handlers.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?

Regards,
Volker

:ADDPATCH C++:


2006-06-21  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28112
	* attribs.c (decl_attributes): Check for invalid arguments.

===================================================================
--- gcc/gcc/attribs.c	(revision 114800)
+++ gcc/gcc/attribs.c	(working copy)
@@ -176,6 +176,8 @@ decl_attributes (tree *node, tree attributes,
 		   IDENTIFIER_POINTER (name));
 	  continue;
 	}
+      else if (args == error_mark_node)
+	continue;
       else if (list_length (args) < spec->min_length
 	       || (spec->max_length >= 0
 		   && list_length (args) > spec->max_length))
===================================================================

2006-06-21  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28112
	* g++.dg/ext/attrib23.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/ext/attrib23.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/ext/attrib23.C	2006-06-20 18:23:35 +0200
@@ -0,0 +1,11 @@
+// PR c++/28112
+// { dg-do compile }
+
+int i       __attribute__((init_priority(;)));  // { dg-error "before" }
+int j       __attribute__((vector_size(;)));    // { dg-error "before" }
+int k       __attribute__((visibility(;)));     // { dg-error "before" }
+struct A {} __attribute__((aligned(;)));        // { dg-error "before" }
+struct B {} __attribute__((mode(;)));           // { dg-error "before" }
+void foo()  __attribute__((alias(;)));          // { dg-error "before" }
+void bar()  __attribute__((nonnull(;)));        // { dg-error "before" }
+void baz()  __attribute__((section(;)));        // { dg-error "before" }
===================================================================




More information about the Gcc-patches mailing list