aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-04 23:42:48 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-04 23:42:48 +0000
commit6202119003aba91e5ff4e579cb9c26a8d1b9514f (patch)
tree081ca167e002b8b94540c111c3aea7ef54ff4b49
parent86ff308724171494395a840fd2efbe25e62f352e (diff)
Fix a crash with ill-formed code within a method in an ill-formed
category implementation, which showed up during (attempted) typo correction. Fixes <rdar://problem/7605289>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95334 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaLookup.cpp9
-rw-r--r--test/FixIt/typo-crash.m6
-rw-r--r--test/FixIt/typo.m2
3 files changed, 13 insertions, 4 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index c4b261fad4..af1b8a276e 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2027,6 +2027,9 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result,
bool InBaseClass,
VisibleDeclConsumer &Consumer,
VisibleDeclsRecord &Visited) {
+ if (!Ctx)
+ return;
+
// Make sure we don't visit the same context twice.
if (Visited.visitedContext(Ctx->getPrimaryContext()))
return;
@@ -2183,9 +2186,9 @@ static void LookupVisibleDecls(Scope *S, LookupResult &Result,
// For instance methods, look for ivars in the method's interface.
LookupResult IvarResult(Result.getSema(), Result.getLookupName(),
Result.getNameLoc(), Sema::LookupMemberName);
- ObjCInterfaceDecl *IFace = Method->getClassInterface();
- LookupVisibleDecls(IFace, IvarResult, /*QualifiedNameLookup=*/false,
- /*InBaseClass=*/false, Consumer, Visited);
+ if (ObjCInterfaceDecl *IFace = Method->getClassInterface())
+ LookupVisibleDecls(IFace, IvarResult, /*QualifiedNameLookup=*/false,
+ /*InBaseClass=*/false, Consumer, Visited);
}
// We've already performed all of the name lookup that we need
diff --git a/test/FixIt/typo-crash.m b/test/FixIt/typo-crash.m
new file mode 100644
index 0000000000..f10fe61ae7
--- /dev/null
+++ b/test/FixIt/typo-crash.m
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/7605289>
+@implementation Unknown (Blarg) // expected-error{{cannot find interface declaration for 'Unknown'}}
+- (int)method { return ivar; } // expected-error{{use of undeclared identifier 'ivar'}}
+@end
diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m
index c2069dd416..86dd383c90 100644
--- a/test/FixIt/typo.m
+++ b/test/FixIt/typo.m
@@ -86,5 +86,5 @@ void test2(Collide *a) {
- (int)send:(void*)buffer bytes:(int)bytes;
@end
-@interface IPv8 <Network_Socket> // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}}
+@interface IPv6 <Network_Socket> // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}}
@end