]> granicus.if.org Git - clang/commitdiff
Fix a crash with ill-formed code within a method in an ill-formed
authorDouglas Gregor <dgregor@apple.com>
Thu, 4 Feb 2010 23:42:48 +0000 (23:42 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 4 Feb 2010 23:42:48 +0000 (23:42 +0000)
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

lib/Sema/SemaLookup.cpp
test/FixIt/typo-crash.m [new file with mode: 0644]
test/FixIt/typo.m

index c4b261fad44890c80c0a234169ebc5a7fcc87486..af1b8a276efc4b3fd7d20ee637f3ab7a29f23513 100644 (file)
@@ -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 (file)
index 0000000..f10fe61
--- /dev/null
@@ -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
index c2069dd4169d1373ccc270b08bd9e12d31d5d51e..86dd383c904e7276aee4ce7f911a90515091ffbc 100644 (file)
@@ -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