Skip to content

Commit 1892501

Browse files
committed
Directly access @_objcImpl stored props sometimes
Accessing a stored property from a normal method should send a selector, but accessing it from an initializer or accessor should use the field offset.
1 parent 22ebf07 commit 1892501

File tree

4 files changed

+103
-29
lines changed

4 files changed

+103
-29
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,10 +3761,13 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
37613761
bool forConformance,
37623762
bool includeInlineable,
37633763
llvm::function_ref<AccessLevel()> getAccessLevel) {
3764-
// If this is an @_objcImplementation member implementation, unconditionally
3765-
// forbid access. Name lookups will instead find and use the matching
3766-
// interface decl.
3767-
if (isObjCMemberImplementation(VD, getAccessLevel))
3764+
// If this is an @_objcImplementation member implementation, and we aren't in
3765+
// a context where we would access its storage directly, forbid access. Name
3766+
// lookups will instead find and use the matching interface decl.
3767+
// FIXME: Passing `true` for `isAccessOnSelf` may cause false positives.
3768+
if (isObjCMemberImplementation(VD, getAccessLevel) &&
3769+
VD->getAccessSemanticsFromContext(useDC, /*isAccessOnSelf=*/true)
3770+
!= AccessSemantics::DirectToStorage)
37683771
return false;
37693772

37703773
if (VD->getASTContext().isAccessControlDisabled())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
448448
// (or the same file) to add vtable entries, we can re-evaluate this
449449
// restriction.
450450
if (!decl->isSynthesized() &&
451-
isa<ExtensionDecl>(decl->getDeclContext()) &&
451+
isa<ExtensionDecl>(decl->getDeclContext()->getImplementedObjCContext()) &&
452452
!(decl->getAttrs().hasAttribute<DynamicReplacementAttr>())) {
453453

454454
if (classDcl->getForeignClassKind() == ClassDecl::ForeignKind::CFType) {

test/IRGen/Inputs/objc_implementation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
@interface ImplClass: NSObject
44

5+
- (nonnull instancetype)init;
6+
57
@property (assign) int implProperty;
68

79
- (void)mainMethod:(int)param;

0 commit comments

Comments
 (0)