From 6202119003aba91e5ff4e579cb9c26a8d1b9514f Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 4 Feb 2010 23:42:48 +0000 Subject: [PATCH] Fix a crash with ill-formed code within a method in an ill-formed category implementation, which showed up during (attempted) typo correction. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95334 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 9 ++++++--- test/FixIt/typo-crash.m | 6 ++++++ test/FixIt/typo.m | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/FixIt/typo-crash.m 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 + +// +@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 // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}} +@interface IPv6 // expected-error{{cannot find protocol declaration for 'Network_Socket'; did you mean 'NetworkSocket'?}} @end -- 2.40.0