Skip to content

Commit 3c50f25

Browse files
committed
[analyzer] Fix more ObjC accessor body farms after 2073dd2.
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 0b58b80.
1 parent 07e4451 commit 3c50f25

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

clang/lib/Analysis/BodyFarm.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,17 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx,
741741
// First, find the backing ivar.
742742
const ObjCIvarDecl *IVar = nullptr;
743743

744-
// Property accessor stubs sometimes do not correspond to any property.
744+
// Property accessor stubs sometimes do not correspond to any property decl
745+
// in the current interface (but in a superclass). They still have a
746+
// corresponding property impl decl in this case.
745747
if (MD->isSynthesizedAccessorStub()) {
746748
const ObjCInterfaceDecl *IntD = MD->getClassInterface();
747749
const ObjCImplementationDecl *ImpD = IntD->getImplementation();
748-
for (const auto *V: ImpD->ivars()) {
749-
if (V->getName() == MD->getSelector().getNameForSlot(0))
750-
IVar = V;
750+
for (const auto *PI: ImpD->property_impls()) {
751+
if (const ObjCPropertyDecl *P = PI->getPropertyDecl()) {
752+
if (P->getGetterName() == MD->getSelector())
753+
IVar = P->getPropertyIvarDecl();
754+
}
751755
}
752756
}
753757

clang/test/Analysis/properties.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,8 @@ - (NSObject *)getShadowedIvar;
10491049
- (void)clearShadowedIvar;
10501050
- (NSObject *)getShadowedProp;
10511051
- (void)clearShadowedProp;
1052+
1053+
@property (assign) NSObject *o2;
10521054
@end
10531055

10541056
@implementation Shadowed
@@ -1078,12 +1080,18 @@ @implementation Shadowing
10781080
@synthesize o;
10791081

10801082
-(void)testPropertyShadowing {
1081-
NSObject *oo = self.o;
1083+
NSObject *oo = self.o; // no-crash
10821084
clang_analyzer_eval(self.o == oo); // expected-warning{{TRUE}}
10831085
clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}}
10841086
[self clearShadowedIvar];
10851087
clang_analyzer_eval(self.o == oo); // expected-warning{{TRUE}}
10861088
clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}}
10871089
clang_analyzer_eval([self getShadowedIvar] == nil); // expected-warning{{TRUE}}
10881090
}
1091+
1092+
@synthesize o2 = ooo2;
1093+
1094+
-(void)testPropertyShadowingWithExplicitIvar {
1095+
NSObject *oo2 = self.o2; // no-crash
1096+
}
10891097
@end

0 commit comments

Comments
 (0)