Skip to content

Eng/pr 58804805 58581965 20190619 #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
for (auto *PD : ClassExt->properties()) {
if (IsClassProperty != PD->isClassProperty())
continue;
if (PD->isDirectProperty())
continue;
PropertySet.insert(PD->getIdentifier());
Properties.push_back(PD);
}
Expand All @@ -3303,6 +3305,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
// class extension.
if (!PropertySet.insert(PD->getIdentifier()).second)
continue;
if (PD->isDirectProperty())
continue;
Properties.push_back(PD);
}

Expand All @@ -3328,8 +3332,6 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
values.addInt(ObjCTypes.IntTy, Properties.size());
auto propertiesArray = values.beginArray(ObjCTypes.PropertyTy);
for (auto PD : Properties) {
if (PD->isDirectProperty())
continue;
auto property = propertiesArray.beginStruct(ObjCTypes.PropertyTy);
property.add(GetPropertyName(PD->getIdentifier()));
property.add(GetPropertyTypeString(PD, Container));
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,11 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
<< Method->getDeclName();
}

if (ReceiverType->isObjCClassType() && !isImplicit) {
// Under ARC, self can't be assigned, and doing a direct call to `self`
// when it's a Class is hence safe. For other cases, we can't trust `self`
// is what we think it is, so we reject it.
if (ReceiverType->isObjCClassType() && !isImplicit &&
!(Receiver->isObjCSelfExpr() && getLangOpts().ObjCAutoRefCount)) {
Diag(Receiver->getExprLoc(),
diag::err_messaging_class_with_direct_method);
Diag(Method->getLocation(), diag::note_direct_method_declared_at)
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CodeGenObjC/direct-properties.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -o - | FileCheck %s

__attribute__((objc_root_class))
@interface A
@property(direct, readonly) int i;
@end

__attribute__((objc_root_class))
@interface B
@property(direct, readonly) int i;
@property(readonly) int j;
@end

// CHECK-NOT: @"__OBJC_$_PROP_LIST_A"
@implementation A
@synthesize i = _i;
@end

// CHECK: @"_OBJC_$_PROP_LIST_B" = internal global { i32, i32, [1 x %struct._prop_t] } { i32 16, i32 1
@implementation B
@synthesize i = _i;
@synthesize j = _j;
@end
48 changes: 48 additions & 0 deletions clang/test/SemaObjC/method-direct-arc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// RUN: %clang_cc1 -fobjc-arc -fsyntax-only -verify -Wselector-type-mismatch %s

extern Class object_getClass(id);

__attribute__((objc_root_class))
@interface Root
- (Class)class;
+ (void)directMethod __attribute__((objc_direct)); // expected-note {{direct method 'directMethod' declared here}}
+ (void)anotherDirectMethod __attribute__((objc_direct));
@end

@implementation Root
- (Class)class
{
return object_getClass(self);
}
+ (void)directMethod {
}
+ (void)anotherDirectMethod {
[self directMethod]; // this should not warn
}
+ (void)regularMethod {
[self directMethod]; // this should not warn
[self anotherDirectMethod]; // this should not warn
}
- (void)regularInstanceMethod {
[[self class] directMethod]; // expected-error {{messaging a Class with a method that is possibly direct}}
}
@end

@interface Sub : Root
@end

@implementation Sub
+ (void)foo {
[self directMethod]; // this should not warn
}
@end

__attribute__((objc_root_class))
@interface Other
@end

@implementation Other
+ (void)bar {
[self directMethod]; // expected-error {{no known class method for selector 'directMethod'}}
}
@end
3 changes: 3 additions & 0 deletions clang/test/SemaObjC/method-direct.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ + (void)classRootDirect {
}
- (void)otherRootDirect {
}
+ (void)someRootDirectMethod { // expected-note {{direct method 'someRootDirectMethod' declared here}}
}
+ (void)otherClassRootDirect {
[self someRootDirectMethod]; // expected-error {{messaging a Class with a method that is possibly direct}}
}
- (void)rootExtensionDirect {
}
Expand Down