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
This commit is contained in:
Nicola Pero 2010-12-06 21:27:01 +00:00 committed by Nicola Pero
parent 85b40c3ac7
commit 69a9720167
6 changed files with 81 additions and 3 deletions

View File

@ -1,3 +1,9 @@
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>
PR debug/45997

View File

@ -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);
}

View File

@ -1,3 +1,8 @@
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.

View File

@ -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");

View File

@ -1,3 +1,7 @@
2010-12-06 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/foreach-8.m: New.
2010-12-06 Jakub Jelinek <jakub@redhat.com>
PR debug/45997

View File

@ -0,0 +1,51 @@
/* 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;
}