From 4e26ba9022c2052fee9511a0f9d343da5645029f Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Tue, 24 May 2011 21:29:35 +0000 Subject: In gcc/: 2011-05-24 Nicola Pero In gcc/: 2011-05-24 Nicola Pero PR objc/48187 * c-parser.c (c_parser_objc_class_instance_variables): More robust parsing of syntax error in ObjC instance variable lists. In particular, avoid an infinite loop if there is a stray ']'. Updated error message. In gcc/cp/: 2011-05-24 Nicola Pero , * parser.c (cp_parser_objc_class_ivars): Deal gracefully with a syntax error in declaring an ObjC instance variable. In gcc/testsuite/: 2011-05-24 Nicola Pero PR objc/48187 * objc.dg/pr48187.m: New testcase. * obj-c++.dg/pr48187.mm: New testcase. * objc.dg/ivar-extra-semicolon.m: New testcase. From-SVN: r174142 --- gcc/ChangeLog | 8 ++++++ gcc/c-parser.c | 37 ++++++++++++++++++++------ gcc/cp/ChangeLog | 5 ++++ gcc/cp/parser.c | 3 ++- gcc/testsuite/ChangeLog | 7 +++++ gcc/testsuite/obj-c++.dg/pr48187.mm | 39 ++++++++++++++++++++++++++++ gcc/testsuite/objc.dg/ivar-extra-semicolon.m | 15 +++++++++++ gcc/testsuite/objc.dg/pr48187.m | 39 ++++++++++++++++++++++++++++ 8 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/obj-c++.dg/pr48187.mm create mode 100644 gcc/testsuite/objc.dg/ivar-extra-semicolon.m create mode 100644 gcc/testsuite/objc.dg/pr48187.m diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9a5a496..3e1b6e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2011-05-24 Nicola Pero + + PR objc/48187 + * c-parser.c (c_parser_objc_class_instance_variables): More robust + parsing of syntax error in ObjC instance variable lists. In + particular, avoid an infinite loop if there is a stray ']'. + Updated error message. + 2011-05-24 Ian Lance Taylor * godump.c (go_define): Don't accept a string immediately after diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 241bc38..cb70bed 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -6945,7 +6945,7 @@ c_parser_objc_class_instance_variables (c_parser *parser) if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, - "extra semicolon in struct or union specified"); + "extra semicolon"); c_parser_consume_token (parser); continue; } @@ -6988,13 +6988,34 @@ c_parser_objc_class_instance_variables (c_parser *parser) /* Parse some comma-separated declarations. */ decls = c_parser_struct_declaration (parser); - { - /* Comma-separated instance variables are chained together in - reverse order; add them one by one. */ - tree ivar = nreverse (decls); - for (; ivar; ivar = DECL_CHAIN (ivar)) - objc_add_instance_variable (copy_node (ivar)); - } + if (decls == NULL) + { + /* There is a syntax error. We want to skip the offending + tokens up to the next ';' (included) or '}' + (excluded). */ + + /* First, skip manually a ')' or ']'. This is because they + reduce the nesting level, so c_parser_skip_until_found() + wouldn't be able to skip past them. */ + c_token *token = c_parser_peek_token (parser); + if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) + c_parser_consume_token (parser); + + /* Then, do the standard skipping. */ + c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); + + /* We hopefully recovered. Start normal parsing again. */ + parser->error = false; + continue; + } + else + { + /* Comma-separated instance variables are chained together + in reverse order; add them one by one. */ + tree ivar = nreverse (decls); + for (; ivar; ivar = DECL_CHAIN (ivar)) + objc_add_instance_variable (copy_node (ivar)); + } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c011c83..6397194 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-05-24 Nicola Pero , + + * parser.c (cp_parser_objc_class_ivars): Deal gracefully with a + syntax error in declaring an ObjC instance variable. + 2011-05-24 Jason Merrill PR c++/48884 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2b45260..3493e44 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -22494,7 +22494,8 @@ cp_parser_objc_class_ivars (cp_parser* parser) NULL_TREE, attributes); /* Add the instance variable. */ - objc_add_instance_variable (decl); + if (decl != error_mark_node && decl != NULL_TREE) + objc_add_instance_variable (decl); /* Reset PREFIX_ATTRIBUTES. */ while (attributes && TREE_CHAIN (attributes) != first_attribute) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 95ee33e..bf257e0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-05-24 Nicola Pero + + PR objc/48187 + * objc.dg/pr48187.m: New testcase. + * obj-c++.dg/pr48187.mm: New testcase. + * objc.dg/ivar-extra-semicolon.m: New testcase. + 2011-05-24 Jason Merrill * g++.dg/template/access21.C: New. diff --git a/gcc/testsuite/obj-c++.dg/pr48187.mm b/gcc/testsuite/obj-c++.dg/pr48187.mm new file mode 100644 index 0000000..750710b --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/pr48187.mm @@ -0,0 +1,39 @@ +/* { dg-do compile } */ + +@interface A +{ + ] /* { dg-error "xpected" } */ +} +@end + +@interface B +{ + ]; /* { dg-error "xpected" } */ +} +@end + +@interface C +{ + ]; /* { dg-error "xpected" } */ + int x; +} +@end + +@interface D +{ + ( +} /* { dg-error "xpected" } */ +@end + +@interface E +{ + (; /* { dg-error "xpected" } */ +} +@end + +@interface F +{ + (; /* { dg-error "xpected" } */ + int x; +} +@end diff --git a/gcc/testsuite/objc.dg/ivar-extra-semicolon.m b/gcc/testsuite/objc.dg/ivar-extra-semicolon.m new file mode 100644 index 0000000..d3f0b54 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-extra-semicolon.m @@ -0,0 +1,15 @@ +/* Contributed by Nicola Pero , May 2011. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic" } */ + +#include + +@interface MyClass +{ + ; /* { dg-warning "extra semicolon" } */ + int a; + ; /* { dg-warning "extra semicolon" } */ + int b; + ; /* { dg-warning "extra semicolon" } */ +} +@end diff --git a/gcc/testsuite/objc.dg/pr48187.m b/gcc/testsuite/objc.dg/pr48187.m new file mode 100644 index 0000000..cd7910d --- /dev/null +++ b/gcc/testsuite/objc.dg/pr48187.m @@ -0,0 +1,39 @@ +/* { dg-do compile } */ + +@interface A +{ + ] /* { dg-error "xpected" } */ +} +@end + +@interface B +{ + ]; /* { dg-error "xpected" } */ +} +@end + +@interface C +{ + ]; /* { dg-error "xpected" } */ + int x; +} +@end + +@interface D +{ + ) /* { dg-error "xpected" } */ +} +@end + +@interface E +{ + ); /* { dg-error "xpected" } */ +} +@end + +@interface F +{ + ); /* { dg-error "xpected" } */ + int x; +} +@end -- cgit v1.1