[cfe-commits] r45839 - in /cfe/trunk: Sema/SemaDeclObjC.cpp Sema/SemaStmt.cpp test/Parser/objc-foreach-error-1.m

Fariborz Jahanian fjahanian at apple.com
Thu Jan 10 12:33:59 PST 2008


Author: fjahanian
Date: Thu Jan 10 14:33:58 2008
New Revision: 45839

URL: http://llvm.org/viewvc/llvm-project?rev=45839&view=rev
Log:
Recover from user typo not having proper @interface decl and a bad foreach decl.

Added:
    cfe/trunk/test/Parser/objc-foreach-error-1.m
Modified:
    cfe/trunk/Sema/SemaDeclObjC.cpp
    cfe/trunk/Sema/SemaStmt.cpp

Modified: cfe/trunk/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDeclObjC.cpp?rev=45839&r1=45838&r2=45839&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/Sema/SemaDeclObjC.cpp Thu Jan 10 14:33:58 2008
@@ -43,9 +43,14 @@
   PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
   PI.InvalidType = false;
   if (MDecl->isInstance()) {
-    QualType selfTy = Context.getObjCInterfaceType(MDecl->getClassInterface());
-    selfTy = Context.getPointerType(selfTy);
-    PI.TypeInfo = selfTy.getAsOpaquePtr();
+    ObjCInterfaceDecl *OID = MDecl->getClassInterface();
+    // There may be no interface context due to error in declaration of the 
+    // interface (which has been reported). Recover gracefully
+    if (OID) {
+      QualType selfTy = Context.getObjCInterfaceType(OID);
+      selfTy = Context.getPointerType(selfTy);
+      PI.TypeInfo = selfTy.getAsOpaquePtr();
+    }
   } else
     PI.TypeInfo = Context.getObjCIdType().getAsOpaquePtr();
   CurMethodDecl->setSelfDecl(ActOnParamDeclarator(PI, FnBodyScope));

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

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Thu Jan 10 14:33:58 2008
@@ -538,23 +538,25 @@
   Stmt *First  = static_cast<Stmt*>(first);
   Expr *Second = static_cast<Expr*>(second);
   Stmt *Body  = static_cast<Stmt*>(body);
-  QualType FirstType;
-  if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
-    FirstType = cast<ValueDecl>(DS->getDecl())->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();
-    BlockVarDecl *BVD = cast<BlockVarDecl>(D);
-    if (!BVD->hasLocalStorage())
-      return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
-    if (D->getNextDeclarator())
-      return Diag(D->getLocation(), diag::err_toomany_element_decls);
+  if (First) {
+    QualType FirstType;
+    if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
+      FirstType = cast<ValueDecl>(DS->getDecl())->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();
+      BlockVarDecl *BVD = cast<BlockVarDecl>(D);
+      if (!BVD->hasLocalStorage())
+        return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
+      if (D->getNextDeclarator())
+        return Diag(D->getLocation(), diag::err_toomany_element_decls);
+    }
+    else
+      FirstType = static_cast<Expr*>(first)->getType();
+    if (!isObjCObjectPointerType(FirstType))
+        Diag(ForLoc, diag::err_selector_element_type,
+             FirstType.getAsString(), First->getSourceRange());
   }
-  else
-    FirstType = static_cast<Expr*>(first)->getType();
-  if (!isObjCObjectPointerType(FirstType))
-      Diag(ForLoc, diag::err_selector_element_type,
-           FirstType.getAsString(), First->getSourceRange());
   if (Second) {
     DefaultFunctionArrayConversion(Second);
     QualType SecondType = Second->getType();

Added: cfe/trunk/test/Parser/objc-foreach-error-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-foreach-error-1.m?rev=45839&view=auto

==============================================================================
--- cfe/trunk/test/Parser/objc-foreach-error-1.m (added)
+++ cfe/trunk/test/Parser/objc-foreach-error-1.m Thu Jan 10 14:33:58 2008
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ce MyList // expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
+ at end
+
+
+ at implementation MyList
+- (unsigned int)countByEnumeratingWithState:  (struct __objcFastEnumerationState *)state objects:  (id *)items count:(unsigned int)stackcount
+{
+     return 0;
+}
+ at end
+
+
+int LOOP();
+
+ at implementation MyList (BasicTest)  // expected-error {{cannot find interface declaration for 'MyList'}}
+- (void)compilerTestAgainst {
+MyList * el;  // expected-error {{use of undeclared identifier 'MyList'}}
+     for (el in @"foo")    // expected-error {{use of undeclared identifier 'el'}} \
+			   // expected-error {{cannot find interface declaration for 'NSConstantString'}}
+	  { LOOP(); }
+}
+ at end
+





More information about the cfe-commits mailing list