[patch] Fix PR c++/28112: ICE with invalid argument in attribute
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Thu Jun 22 11:18:00 GMT 2006
On 21 Jun, Mark Mitchell wrote:
> Volker Reichelt wrote:
>
>> 2006-06-21 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
>>
>> PR c++/28112
>> * attribs.c (decl_attributes): Check for invalid arguments.
>
> I think we should avoid creating an attribute with invalid arguments;
> once we figure out the attribute is erroneous, just throw it away.
OK. How about this?
The patch below doesn't add the attribute to the attribute_list if the
arguments are invalid. The patch looks much longer because of indentation
changes. It also removes a superflous pair of parentheses around the
call to cp_parser_parenthesized_expression_list and corrects a comment.
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-22 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28112
* parser.c (cp_parser_attribute_list): Skip attributes with invalid
arguments. Fix comment.
===================================================================
--- gcc/gcc/cp/parser.c 2006-06-22 03:29:02 +0200
+++ gcc/gcc/cp/parser.c 2006-06-22 03:23:12 +0200
@@ -14612,6 +14612,8 @@ cp_parser_attribute_list (cp_parser* par
if (token->type == CPP_NAME
|| token->type == CPP_KEYWORD)
{
+ tree arguments = NULL_TREE;
+
/* Consume the token. */
token = cp_lexer_consume_token (parser->lexer);
@@ -14625,18 +14627,19 @@ cp_parser_attribute_list (cp_parser* par
/* If it's an `(', then parse the attribute arguments. */
if (token->type == CPP_OPEN_PAREN)
{
- tree arguments;
-
- arguments = (cp_parser_parenthesized_expression_list
- (parser, true, /*cast_p=*/false,
- /*non_constant_p=*/NULL));
- /* Save the identifier and arguments away. */
+ arguments = cp_parser_parenthesized_expression_list
+ (parser, true, /*cast_p=*/false,
+ /*non_constant_p=*/NULL);
+ /* Save the arguments away. */
TREE_VALUE (attribute) = arguments;
}
- /* Add this attribute to the list. */
- TREE_CHAIN (attribute) = attribute_list;
- attribute_list = attribute;
+ if (arguments != error_mark_node)
+ {
+ /* Add this attribute to the list. */
+ TREE_CHAIN (attribute) = attribute_list;
+ attribute_list = attribute;
+ }
token = cp_lexer_peek_token (parser->lexer);
}
===================================================================
2006-06-22 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