summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2008-01-10 20:33:58 +0000
committerFariborz Jahanian <fjahanian@apple.com>2008-01-10 20:33:58 +0000
commit939776756f1fea394f305d82e300dfb5c390e728 (patch)
tree1deb315c284df323c2c027aa2bbc90a65447e650
parent8e60f2c9960dc42bcf347675381055980a580bb8 (diff)
downloadbcm5719-llvm-939776756f1fea394f305d82e300dfb5c390e728.tar.gz
bcm5719-llvm-939776756f1fea394f305d82e300dfb5c390e728.zip
Recover from user typo not having proper @interface decl and a bad foreach decl.
llvm-svn: 45839
-rw-r--r--clang/Sema/SemaDeclObjC.cpp11
-rw-r--r--clang/Sema/SemaStmt.cpp34
-rw-r--r--clang/test/Parser/objc-foreach-error-1.m25
3 files changed, 51 insertions, 19 deletions
diff --git a/clang/Sema/SemaDeclObjC.cpp b/clang/Sema/SemaDeclObjC.cpp
index 89b7611d865..b2e7b795566 100644
--- a/clang/Sema/SemaDeclObjC.cpp
+++ b/clang/Sema/SemaDeclObjC.cpp
@@ -43,9 +43,14 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
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));
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp
index fbe9294b203..4cad4a9f669 100644
--- a/clang/Sema/SemaStmt.cpp
+++ b/clang/Sema/SemaStmt.cpp
@@ -538,23 +538,25 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
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();
diff --git a/clang/test/Parser/objc-foreach-error-1.m b/clang/test/Parser/objc-foreach-error-1.m
new file mode 100644
index 00000000000..693f12e2ffe
--- /dev/null
+++ b/clang/test/Parser/objc-foreach-error-1.m
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ce MyList // expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
+@end
+
+
+@implementation MyList
+- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount
+{
+ return 0;
+}
+@end
+
+
+int LOOP();
+
+@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(); }
+}
+@end
+
OpenPOWER on IntegriCloud