OSDN Git Service

In gcc/:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Dec 2010 21:27:01 +0000 (21:27 +0000)
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Dec 2010 21:27:01 +0000 (21:27 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167518 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-parser.c
gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/foreach-8.m [new file with mode: 0644]

index c2d40f1..b6269f7 100644 (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
index f2d5e5b..62eb1e7 100644 (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);
        }
index 99df784..f3001e5 100644 (file)
@@ -1,5 +1,10 @@
 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-lang.c: Same change.
        * Make-lang.in (objc/objc-act.o): Depend on
index 49e2442..f530556 100644 (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");
 
index 0aecee3..f278725 100644 (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
diff --git a/gcc/testsuite/objc.dg/foreach-8.m b/gcc/testsuite/objc.dg/foreach-8.m
new file mode 100644 (file)
index 0000000..9a68e9f
--- /dev/null
@@ -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;
+}