From: nicola Date: Mon, 6 Dec 2010 21:27:01 +0000 (+0000) Subject: In gcc/: X-Git-Tag: upstream/4.9.2~24344 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81976f54aa6152b4f98718f8752f825bf0b3898d;p=platform%2Fupstream%2Flinaro-gcc.git In gcc/: 2010-12-06 Nicola Pero * c-parser.c (c_parser_for_statement): Use c_fully_fold() instead of c_process_expr_stmt() for the iterating and collection expressions of an Objective-C fast enumeration loop. In gcc/objc/: 2010-12-06 Nicola Pero * objc-act.c (objc_finish_foreach_loop): Mark the object_expression as used. In gcc/testsuite/: 2010-12-06 Nicola Pero * objc.dg/foreach-8.m: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167518 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c2d40f1..b6269f7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-12-06 Nicola Pero + + * c-parser.c (c_parser_for_statement): Use c_fully_fold() instead + of c_process_expr_stmt() for the iterating and collection + expressions of an Objective-C fast enumeration loop. + 2010-12-06 Jakub Jelinek PR debug/45997 diff --git a/gcc/c-parser.c b/gcc/c-parser.c index f2d5e5b..62eb1e7 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -4812,8 +4812,7 @@ c_parser_for_statement (c_parser *parser) is_foreach_statement = true; if (! lvalue_p (init_expression)) c_parser_error (parser, "invalid iterating variable in fast enumeration"); - object_expression = c_process_expr_stmt (loc, init_expression); - + object_expression = c_fully_fold (init_expression, false, NULL); } else { @@ -4854,7 +4853,8 @@ c_parser_for_statement (c_parser *parser) else { if (is_foreach_statement) - collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value); + collection_expression = c_fully_fold (c_parser_expression (parser).value, + false, NULL); else incr = c_process_expr_stmt (loc, c_parser_expression (parser).value); } diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 99df784..f3001e5 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,5 +1,10 @@ 2010-12-06 Nicola Pero + * objc-act.c (objc_finish_foreach_loop): Mark the + object_expression as used. + +2010-12-06 Nicola Pero + * objc-act.c: Include c-family/c-objc.h. * objc-lang.c: Same change. * Make-lang.in (objc/objc-act.o): Depend on diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 49e2442..f530556 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -13290,6 +13290,18 @@ objc_finish_foreach_loop (location_t location, tree object_expression, tree coll /* type object; */ /* Done by c-parser.c. */ + /* Disable warnings that 'object' is unused. For example the code + + for (id object in collection) + i++; + + which can be used to count how many objects there are in the + collection is fine and should generate no warnings even if + 'object' is technically unused. */ + TREE_USED (object_expression) = 1; + if (DECL_P (object_expression)) + DECL_READ_P (object_expression) = 1; + /* id __objc_foreach_collection */ objc_foreach_collection_decl = objc_create_temporary_var (objc_object_type, "__objc_foreach_collection"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0aecee3..f278725 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-12-06 Nicola Pero + + * objc.dg/foreach-8.m: New. + 2010-12-06 Jakub Jelinek PR debug/45997 diff --git a/gcc/testsuite/objc.dg/foreach-8.m b/gcc/testsuite/objc.dg/foreach-8.m new file mode 100644 index 0000000..9a68e9f --- /dev/null +++ b/gcc/testsuite/objc.dg/foreach-8.m @@ -0,0 +1,51 @@ +/* Contributed by Nicola Pero , December 2010. */ +/* { dg-options "-Wall" } */ +/* { dg-do compile } */ + +/* Test that fast enumeration loops where the iterating variable is declared + but not used do not generate warnings. */ + +/* +struct __objcFastEnumerationState +{ + unsigned long state; + id *itemsPtr; + unsigned long *mutationsPtr; + unsigned long extra[5]; +}; +*/ +@interface Object +{ + Class isa; +} +- (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state + objects:(id *)stackbuf + count:(unsigned int)len; +- (id) enumerator; +- (Class) classEnumerator; +@end + +unsigned int count_objects_in_collection (id collection) +{ + unsigned int count = 0; + + /* The following line should generate no warnings even with + -Wall. */ + for (id object in collection) + count++; + + return count; +} + +unsigned int count_objects_in_collection_2 (id collection) +{ + unsigned int count = 0; + id object; + + /* The following line should generate no warnings even with + -Wall. */ + for (object in collection) + count++; + + return count; +}