[cfe-commits] r89400 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseStmt.cpp lib/Sema/Sema.h lib/Sema/SemaStmt.cpp test/SemaObjC/foreach.m

Fariborz Jahanian fjahanian at apple.com
Thu Nov 19 14:12:37 PST 2009


Author: fjahanian
Date: Thu Nov 19 16:12:37 2009
New Revision: 89400

URL: http://llvm.org/viewvc/llvm-project?rev=89400&view=rev
Log:
Don't issue spurious diagnostic with Obj-C fast enumeration.
(radar 7409165).

Modified:
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaObjC/foreach.m

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=89400&r1=89399&r2=89400&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Nov 19 16:12:37 2009
@@ -668,6 +668,9 @@
     return StmtEmpty();
   }
 
+  virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl) {
+  }
+
   virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr) {
     return OwningStmtResult(*this, Expr->release());
   }

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=89400&r1=89399&r2=89400&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Thu Nov 19 16:12:37 2009
@@ -944,6 +944,7 @@
     if (Tok.is(tok::semi)) {  // for (int x = 4;
       ConsumeToken();
     } else if ((ForEach = isTokIdentifier_in())) {
+      Actions.ActOnForEachDeclStmt(DG);
       // ObjC: for (id x in expr)
       ConsumeToken(); // consume 'in'
       SecondPart = ParseExpression();

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89400&r1=89399&r2=89400&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Nov 19 16:12:37 2009
@@ -1260,6 +1260,7 @@
   virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
                                          SourceLocation StartLoc,
                                          SourceLocation EndLoc);
+  virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
   virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
                                     SourceLocation DotDotDotLoc, ExprArg RHSVal,
                                     SourceLocation ColonLoc);

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=89400&r1=89399&r2=89400&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Nov 19 16:12:37 2009
@@ -59,6 +59,15 @@
   return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
 }
 
+void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) {
+  DeclGroupRef DG = dg.getAsVal<DeclGroupRef>();
+  
+  // If we have an invalid decl, just return.
+  if (DG.isNull() || !DG.isSingleDecl()) return;
+  // suppress any potential 'unused variable' warning.
+  DG.getSingleDecl()->setUsed();
+}
+
 void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
   const Expr *E = dyn_cast_or_null<Expr>(S);
   if (!E)

Modified: cfe/trunk/test/SemaObjC/foreach.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/foreach.m?rev=89400&r1=89399&r2=89400&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/foreach.m (original)
+++ cfe/trunk/test/SemaObjC/foreach.m Thu Nov 19 16:12:37 2009
@@ -1,4 +1,4 @@
-/* RUN: clang-cc -fsyntax-only -verify -std=c89 -pedantic %s
+/* RUN: clang-cc -Wall -fsyntax-only -verify -std=c89 -pedantic %s
  */
 
 @class NSArray;





More information about the cfe-commits mailing list