Commit 69a97201 by Nicola Pero Committed by Nicola Pero

In gcc/: 2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>

In gcc/:
2010-12-06  Nicola Pero  <nicola.pero@meta-innovation.com>

	* 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  <nicola.pero@meta-innovation.com>

	* objc-act.c (objc_finish_foreach_loop): Mark the
	object_expression as used.

In gcc/testsuite/:
2010-12-06  Nicola Pero  <nicola.pero@meta-innovation.com>

	* objc.dg/foreach-8.m: New.

From-SVN: r167518
parent 85b40c3a
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
* 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 <jakub@redhat.com> 2010-12-06 Jakub Jelinek <jakub@redhat.com>
PR debug/45997 PR debug/45997
...@@ -4812,8 +4812,7 @@ c_parser_for_statement (c_parser *parser) ...@@ -4812,8 +4812,7 @@ c_parser_for_statement (c_parser *parser)
is_foreach_statement = true; is_foreach_statement = true;
if (! lvalue_p (init_expression)) if (! lvalue_p (init_expression))
c_parser_error (parser, "invalid iterating variable in fast enumeration"); 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 else
{ {
...@@ -4854,7 +4853,8 @@ c_parser_for_statement (c_parser *parser) ...@@ -4854,7 +4853,8 @@ c_parser_for_statement (c_parser *parser)
else else
{ {
if (is_foreach_statement) 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 else
incr = c_process_expr_stmt (loc, c_parser_expression (parser).value); incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
} }
......
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com> 2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c (objc_finish_foreach_loop): Mark the
object_expression as used.
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c: Include c-family/c-objc.h. * objc-act.c: Include c-family/c-objc.h.
* objc-lang.c: Same change. * objc-lang.c: Same change.
* Make-lang.in (objc/objc-act.o): Depend on * Make-lang.in (objc/objc-act.o): Depend on
......
...@@ -13290,6 +13290,18 @@ objc_finish_foreach_loop (location_t location, tree object_expression, tree coll ...@@ -13290,6 +13290,18 @@ objc_finish_foreach_loop (location_t location, tree object_expression, tree coll
/* type object; */ /* type object; */
/* Done by c-parser.c. */ /* 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 */ /* id __objc_foreach_collection */
objc_foreach_collection_decl = objc_create_temporary_var (objc_object_type, "__objc_foreach_collection"); objc_foreach_collection_decl = objc_create_temporary_var (objc_object_type, "__objc_foreach_collection");
......
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/foreach-8.m: New.
2010-12-06 Jakub Jelinek <jakub@redhat.com> 2010-12-06 Jakub Jelinek <jakub@redhat.com>
PR debug/45997 PR debug/45997
......
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment