@@ -742,63 +742,67 @@ static const ObjCIvarDecl *findBackingIvar(const ObjCPropertyDecl *Prop) {
742
742
743
743
static Stmt *createObjCPropertyGetter (ASTContext &Ctx,
744
744
const ObjCMethodDecl *MD) {
745
- // First, find the backing ivar.
745
+ // First, find the backing ivar.
746
746
const ObjCIvarDecl *IVar = nullptr ;
747
+ const ObjCPropertyDecl *Prop = nullptr ;
747
748
748
749
// Property accessor stubs sometimes do not correspond to any property decl
749
750
// in the current interface (but in a superclass). They still have a
750
751
// corresponding property impl decl in this case.
751
752
if (MD->isSynthesizedAccessorStub ()) {
752
753
const ObjCInterfaceDecl *IntD = MD->getClassInterface ();
753
754
const ObjCImplementationDecl *ImpD = IntD->getImplementation ();
754
- for (const auto *PI: ImpD->property_impls ()) {
755
- if (const ObjCPropertyDecl *P = PI->getPropertyDecl ()) {
756
- if (P->getGetterName () == MD->getSelector ())
757
- IVar = P->getPropertyIvarDecl ();
755
+ for (const auto *PI : ImpD->property_impls ()) {
756
+ if (const ObjCPropertyDecl *Candidate = PI->getPropertyDecl ()) {
757
+ if (Candidate->getGetterName () == MD->getSelector ()) {
758
+ Prop = Candidate;
759
+ IVar = Prop->getPropertyIvarDecl ();
760
+ }
758
761
}
759
762
}
760
763
}
761
764
762
765
if (!IVar) {
763
- const ObjCPropertyDecl * Prop = MD->findPropertyDecl ();
766
+ Prop = MD->findPropertyDecl ();
764
767
IVar = findBackingIvar (Prop);
765
- if (!IVar)
766
- return nullptr ;
768
+ }
767
769
768
- // Ignore weak variables, which have special behavior.
769
- if (Prop->getPropertyAttributes () & ObjCPropertyAttribute::kind_weak)
770
- return nullptr ;
770
+ if (!IVar || !Prop)
771
+ return nullptr ;
772
+
773
+ // Ignore weak variables, which have special behavior.
774
+ if (Prop->getPropertyAttributes () & ObjCPropertyAttribute::kind_weak)
775
+ return nullptr ;
771
776
772
- // Look to see if Sema has synthesized a body for us. This happens in
773
- // Objective-C++ because the return value may be a C++ class type with a
774
- // non-trivial copy constructor. We can only do this if we can find the
775
- // @synthesize for this property, though (or if we know it's been auto-
776
- // synthesized).
777
- const ObjCImplementationDecl *ImplDecl =
777
+ // Look to see if Sema has synthesized a body for us. This happens in
778
+ // Objective-C++ because the return value may be a C++ class type with a
779
+ // non-trivial copy constructor. We can only do this if we can find the
780
+ // @synthesize for this property, though (or if we know it's been auto-
781
+ // synthesized).
782
+ const ObjCImplementationDecl *ImplDecl =
778
783
IVar->getContainingInterface ()->getImplementation ();
779
- if (ImplDecl) {
780
- for (const auto *I : ImplDecl->property_impls ()) {
781
- if (I->getPropertyDecl () != Prop)
782
- continue ;
783
-
784
- if (I->getGetterCXXConstructor ()) {
785
- ASTMaker M (Ctx);
786
- return M.makeReturn (I->getGetterCXXConstructor ());
787
- }
784
+ if (ImplDecl) {
785
+ for (const auto *I : ImplDecl->property_impls ()) {
786
+ if (I->getPropertyDecl () != Prop)
787
+ continue ;
788
+
789
+ if (I->getGetterCXXConstructor ()) {
790
+ ASTMaker M (Ctx);
791
+ return M.makeReturn (I->getGetterCXXConstructor ());
788
792
}
789
793
}
790
-
791
- // Sanity check that the property is the same type as the ivar, or a
792
- // reference to it, and that it is either an object pointer or trivially
793
- // copyable.
794
- if (!Ctx.hasSameUnqualifiedType (IVar->getType (),
795
- Prop->getType ().getNonReferenceType ()))
796
- return nullptr ;
797
- if (!IVar->getType ()->isObjCLifetimeType () &&
798
- !IVar->getType ().isTriviallyCopyableType (Ctx))
799
- return nullptr ;
800
794
}
801
795
796
+ // Sanity check that the property is the same type as the ivar, or a
797
+ // reference to it, and that it is either an object pointer or trivially
798
+ // copyable.
799
+ if (!Ctx.hasSameUnqualifiedType (IVar->getType (),
800
+ Prop->getType ().getNonReferenceType ()))
801
+ return nullptr ;
802
+ if (!IVar->getType ()->isObjCLifetimeType () &&
803
+ !IVar->getType ().isTriviallyCopyableType (Ctx))
804
+ return nullptr ;
805
+
802
806
// Generate our body:
803
807
// return self->_ivar;
804
808
ASTMaker M (Ctx);
@@ -807,11 +811,8 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx,
807
811
if (!selfVar)
808
812
return nullptr ;
809
813
810
- Expr *loadedIVar =
811
- M.makeObjCIvarRef (
812
- M.makeLvalueToRvalue (
813
- M.makeDeclRefExpr (selfVar),
814
- selfVar->getType ()),
814
+ Expr *loadedIVar = M.makeObjCIvarRef (
815
+ M.makeLvalueToRvalue (M.makeDeclRefExpr (selfVar), selfVar->getType ()),
815
816
IVar);
816
817
817
818
if (!MD->getReturnType ()->isReferenceType ())
0 commit comments