Skip to content

Commit 62affab

Browse files
authored
Merge pull request #655 from apple/eng/PR-58804805-58581965-20190619
Eng/pr 5880480 58581965 20190619
2 parents 7e391ca + 61212a0 commit 62affab

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
32923292
for (auto *PD : ClassExt->properties()) {
32933293
if (IsClassProperty != PD->isClassProperty())
32943294
continue;
3295+
if (PD->isDirectProperty())
3296+
continue;
32953297
PropertySet.insert(PD->getIdentifier());
32963298
Properties.push_back(PD);
32973299
}
@@ -3303,6 +3305,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
33033305
// class extension.
33043306
if (!PropertySet.insert(PD->getIdentifier()).second)
33053307
continue;
3308+
if (PD->isDirectProperty())
3309+
continue;
33063310
Properties.push_back(PD);
33073311
}
33083312

@@ -3328,8 +3332,6 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
33283332
values.addInt(ObjCTypes.IntTy, Properties.size());
33293333
auto propertiesArray = values.beginArray(ObjCTypes.PropertyTy);
33303334
for (auto PD : Properties) {
3331-
if (PD->isDirectProperty())
3332-
continue;
33333335
auto property = propertiesArray.beginStruct(ObjCTypes.PropertyTy);
33343336
property.add(GetPropertyName(PD->getIdentifier()));
33353337
property.add(GetPropertyTypeString(PD, Container));

clang/lib/Sema/SemaExprObjC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,11 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
30093009
<< Method->getDeclName();
30103010
}
30113011

3012-
if (ReceiverType->isObjCClassType() && !isImplicit) {
3012+
// Under ARC, self can't be assigned, and doing a direct call to `self`
3013+
// when it's a Class is hence safe. For other cases, we can't trust `self`
3014+
// is what we think it is, so we reject it.
3015+
if (ReceiverType->isObjCClassType() && !isImplicit &&
3016+
!(Receiver->isObjCSelfExpr() && getLangOpts().ObjCAutoRefCount)) {
30133017
Diag(Receiver->getExprLoc(),
30143018
diag::err_messaging_class_with_direct_method);
30153019
Diag(Method->getLocation(), diag::note_direct_method_declared_at)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2+
3+
__attribute__((objc_root_class))
4+
@interface A
5+
@property(direct, readonly) int i;
6+
@end
7+
8+
__attribute__((objc_root_class))
9+
@interface B
10+
@property(direct, readonly) int i;
11+
@property(readonly) int j;
12+
@end
13+
14+
// CHECK-NOT: @"__OBJC_$_PROP_LIST_A"
15+
@implementation A
16+
@synthesize i = _i;
17+
@end
18+
19+
// CHECK: @"_OBJC_$_PROP_LIST_B" = internal global { i32, i32, [1 x %struct._prop_t] } { i32 16, i32 1
20+
@implementation B
21+
@synthesize i = _i;
22+
@synthesize j = _j;
23+
@end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %clang_cc1 -fobjc-arc -fsyntax-only -verify -Wselector-type-mismatch %s
2+
3+
extern Class object_getClass(id);
4+
5+
__attribute__((objc_root_class))
6+
@interface Root
7+
- (Class)class;
8+
+ (void)directMethod __attribute__((objc_direct)); // expected-note {{direct method 'directMethod' declared here}}
9+
+ (void)anotherDirectMethod __attribute__((objc_direct));
10+
@end
11+
12+
@implementation Root
13+
- (Class)class
14+
{
15+
return object_getClass(self);
16+
}
17+
+ (void)directMethod {
18+
}
19+
+ (void)anotherDirectMethod {
20+
[self directMethod]; // this should not warn
21+
}
22+
+ (void)regularMethod {
23+
[self directMethod]; // this should not warn
24+
[self anotherDirectMethod]; // this should not warn
25+
}
26+
- (void)regularInstanceMethod {
27+
[[self class] directMethod]; // expected-error {{messaging a Class with a method that is possibly direct}}
28+
}
29+
@end
30+
31+
@interface Sub : Root
32+
@end
33+
34+
@implementation Sub
35+
+ (void)foo {
36+
[self directMethod]; // this should not warn
37+
}
38+
@end
39+
40+
__attribute__((objc_root_class))
41+
@interface Other
42+
@end
43+
44+
@implementation Other
45+
+ (void)bar {
46+
[self directMethod]; // expected-error {{no known class method for selector 'directMethod'}}
47+
}
48+
@end

clang/test/SemaObjC/method-direct.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ + (void)classRootDirect {
8989
}
9090
- (void)otherRootDirect {
9191
}
92+
+ (void)someRootDirectMethod { // expected-note {{direct method 'someRootDirectMethod' declared here}}
93+
}
9294
+ (void)otherClassRootDirect {
95+
[self someRootDirectMethod]; // expected-error {{messaging a Class with a method that is possibly direct}}
9396
}
9497
- (void)rootExtensionDirect {
9598
}

0 commit comments

Comments
 (0)