[cfe-commits] r57207 - /cfe/trunk/lib/Sema/SemaStmt.cpp

Ted Kremenek kremenek at apple.com
Mon Oct 6 13:58:11 PDT 2008


Author: kremenek
Date: Mon Oct  6 15:58:11 2008
New Revision: 57207

URL: http://llvm.org/viewvc/llvm-project?rev=57207&view=rev
Log:
When processing Objective-C foreach statements, first check to see if the statement has a DeclStmt with a single Decl.  Afterwards, use DeclStmt::getSolitaryDecl() to access that Decl (thus avoiding an assertion being triggered).  These changes remove an unneeded use of ScopedDecl::getNextDeclarator() and DeclStmt::getDecl().

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Oct  6 15:58:11 2008
@@ -589,15 +589,17 @@
   if (First) {
     QualType FirstType;
     if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
-      FirstType = cast<ValueDecl>(DS->getDecl())->getType();
+      if (!DS->hasSolitaryDecl())
+        return Diag((*DS->decl_begin())->getLocation(),
+                    diag::err_toomany_element_decls);
+      
+      ScopedDecl *D = DS->getSolitaryDecl();
+      FirstType = cast<ValueDecl>(D)->getType();
       // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
       // identifiers for objects having storage class 'auto' or 'register'.
-      ScopedDecl *D = DS->getDecl();
       VarDecl *VD = cast<VarDecl>(D);
       if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
         return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
-      if (D->getNextDeclarator())
-        return Diag(D->getLocation(), diag::err_toomany_element_decls);
     } else {
       Expr::isLvalueResult lval = cast<Expr>(First)->isLvalue(Context);
       





More information about the cfe-commits mailing list