Author: Artem Dergachev Date: 2019-12-04T16:29:08-08:00 New Revision: 3c50f2544f7a8f0c41f4fc286064abce2d3629b5
URL: https://github.com/llvm/llvm-project/commit/3c50f2544f7a8f0c41f4fc286064abce2d3629b5 DIFF: https://github.com/llvm/llvm-project/commit/3c50f2544f7a8f0c41f4fc286064abce2d3629b5.diff LOG: [analyzer] Fix more ObjC accessor body farms after 2073dd2d. Fix a crash when constructing a body farm for accessors of a property that is declared and @synthesize'd in different (but related) interfaces with the explicit ivar syntax. This is a follow-up for 0b58b80e. Added: Modified: clang/lib/Analysis/BodyFarm.cpp clang/test/Analysis/properties.m Removed: ################################################################################ diff --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp index 694913b3ac93..1a7891550542 100644 --- a/clang/lib/Analysis/BodyFarm.cpp +++ b/clang/lib/Analysis/BodyFarm.cpp @@ -741,13 +741,17 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx, // First, find the backing ivar. const ObjCIvarDecl *IVar = nullptr; - // Property accessor stubs sometimes do not correspond to any property. + // Property accessor stubs sometimes do not correspond to any property decl + // in the current interface (but in a superclass). They still have a + // corresponding property impl decl in this case. if (MD->isSynthesizedAccessorStub()) { const ObjCInterfaceDecl *IntD = MD->getClassInterface(); const ObjCImplementationDecl *ImpD = IntD->getImplementation(); - for (const auto *V: ImpD->ivars()) { - if (V->getName() == MD->getSelector().getNameForSlot(0)) - IVar = V; + for (const auto *PI: ImpD->property_impls()) { + if (const ObjCPropertyDecl *P = PI->getPropertyDecl()) { + if (P->getGetterName() == MD->getSelector()) + IVar = P->getPropertyIvarDecl(); + } } } diff --git a/clang/test/Analysis/properties.m b/clang/test/Analysis/properties.m index 2f427f275182..d83b8ed14f93 100644 --- a/clang/test/Analysis/properties.m +++ b/clang/test/Analysis/properties.m @@ -1049,6 +1049,8 @@ - (NSObject *)getShadowedIvar; - (void)clearShadowedIvar; - (NSObject *)getShadowedProp; - (void)clearShadowedProp; + +@property (assign) NSObject *o2; @end @implementation Shadowed @@ -1078,7 +1080,7 @@ @implementation Shadowing @synthesize o; -(void)testPropertyShadowing { - NSObject *oo = self.o; + NSObject *oo = self.o; // no-crash clang_analyzer_eval(self.o == oo); // expected-warning{{TRUE}} clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}} [self clearShadowedIvar]; @@ -1086,4 +1088,10 @@ -(void)testPropertyShadowing { clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}} clang_analyzer_eval([self getShadowedIvar] == nil); // expected-warning{{TRUE}} } + +@synthesize o2 = ooo2; + +-(void)testPropertyShadowingWithExplicitIvar { + NSObject *oo2 = self.o2; // no-crash +} @end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits