Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 527eec8

Browse files
author
Fariborz Jahanian
committed
objective-c: Any use of @synthesize or @dynamic lexically after a method (or C function) implementation
will be rejected with a compilation error in ARC mode, and a compiler warning otherwise. This may cause breakage in non-arc (and arc) tests which don't expect warning/error. Feel free to fix the tests, or reverse the patch, if I am unavailable. // rdar://9818354 - WIP git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135740 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 393f249 commit 527eec8

11 files changed

+36
-22
lines changed

Diff for: include/clang/Basic/DiagnosticSemaKinds.td

+4
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ def err_continuation_class : Error<"continuation class has no primary class">;
464464
def err_property_type : Error<"property cannot have array or function type %0">;
465465
def error_missing_property_context : Error<
466466
"missing context for property implementation declaration">;
467+
def error_property_after_method_impl : Error<
468+
"property implementation declaration after method or function definition">;
469+
def warn_property_after_method_impl : Warning<
470+
"property implementation declaration after method or function definition">;
467471
def error_bad_property_decl : Error<
468472
"property implementation must have its declaration in interface %0">;
469473
def error_category_property : Error<

Diff for: lib/Sema/SemaObjCProperty.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
555555
return 0;
556556
}
557557
}
558+
if ((IC->meth_begin() != IC->meth_end()) && AtLoc.isValid()) {
559+
if (getLangOptions().ObjCAutoRefCount)
560+
Diag(AtLoc, diag::error_property_after_method_impl);
561+
else
562+
Diag(AtLoc, diag::warn_property_after_method_impl);
563+
ObjCMethodDecl *method = *(IC->meth_begin());
564+
Diag(method->getLocation(), diag::note_method_declared_at);
565+
}
558566
} else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
559567
if (Synthesize) {
560568
Diag(AtLoc, diag::error_synthesize_category_decl);

Diff for: test/ARCMT/remove-dealloc-zerouts.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ - (id) a;
3434
@end
3535

3636
@implementation Bar
37+
@synthesize a;
3738
- (void) dealloc {
3839
[self setA:0]; // This is user-defined setter overriding synthesize, don't touch it.
3940
self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized.
4041
}
41-
@synthesize a;
4242
- (void) setA:(Foo*) val { }
4343
- (id) a {return 0;}
4444
@end

Diff for: test/ARCMT/remove-dealloc-zerouts.m.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
@end
3030

3131
@implementation Bar
32+
@synthesize a;
3233
- (void) dealloc {
3334
[self setA:0]; // This is user-defined setter overriding synthesize, don't touch it.
3435
self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized.
3536
}
36-
@synthesize a;
3737
- (void) setA:(Foo*) val { }
3838
- (id) a {return 0;}
3939
@end

Diff for: test/SemaObjC/arc.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,9 @@ @implementation I34
598598
@synthesize newName;
599599

600600
@synthesize newName1;
601-
- (id) newName1 { return 0; }
601+
- (id) newName1 { return 0; } // expected-note {{method declared here}}
602602

603-
@synthesize newName2;
603+
@synthesize newName2; // expected-error {{property implementation declaration after method or function definition}}
604604
@end
605605

606606
void test35(void) {

Diff for: test/SemaObjC/atomoic-property-synnthesis-rules.m

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// XFAIL: *
23

34
/*
45
Conditions for warning:

Diff for: test/SemaObjC/conflict-nonfragile-abi2.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ @interface I
1515
// rdar://9027673
1616
// Warning on future name lookup rule is removed.
1717
@implementation I
18-
- (int) Meth { return glob; } // no warning
1918
@synthesize glob;
19+
@dynamic p;
20+
@dynamic le;
21+
@dynamic l;
22+
@dynamic ls;
23+
@dynamic r;
24+
- (int) Meth { return glob; } // no warning
2025
// rdar://8248681
2126
- (int) Meth1: (int) p {
2227
extern int le;
@@ -26,11 +31,6 @@ - (int) Meth1: (int) p {
2631
p = le + ls + r;
2732
return l;
2833
}
29-
@dynamic p;
30-
@dynamic le;
31-
@dynamic l;
32-
@dynamic ls;
33-
@dynamic r;
3434
@end
3535

3636

Diff for: test/SemaObjC/default-synthesize.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ @interface D
111111
@end
112112

113113
@implementation D
114-
- (int) Meth { return self.PROP; }
115114
@synthesize PROP=IVAR;
115+
- (int) Meth { return self.PROP; }
116116
@end
117117

Diff for: test/SemaObjC/property-ns-returns-not-retained-attr.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ @implementation I
1515
@synthesize newName;
1616

1717
@synthesize newName1;
18+
@synthesize newName2;
1819
- (id) newName1 { return 0; }
1920

20-
@synthesize newName2;
2121
@end

Diff for: test/SemaObjC/provisional-ivar-lookup.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ @implementation Foo
1515
@synthesize foo = _foo;
1616
@synthesize foo1;
1717

18-
- (void)setFoo:(int)value {
18+
- (void)setFoo:(int)value { // expected-note 3 {{method declared here}}
1919
_foo = foo; // expected-error {{use of undeclared identifier 'foo'}}
2020
}
2121

@@ -31,10 +31,10 @@ - (void)setFoo3:(int)value {
3131
_foo = foo3; // OK
3232
}
3333

34-
@synthesize foo2 = _foo2;
35-
@synthesize foo3;
34+
@synthesize foo2 = _foo2; // expected-warning {{property implementation declaration after method or function definition}}
35+
@synthesize foo3; // expected-warning {{property implementation declaration after method or function definition}}
3636

37-
@synthesize PROP=PROP;
37+
@synthesize PROP=PROP; // expected-warning {{property implementation declaration after method or function definition}}
3838
- (void)setPROP:(int)value {
3939
PROP = PROP; // OK
4040
}

Diff for: test/SemaObjC/synth-provisional-ivars.m

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ @interface I
1818
@end
1919

2020
@implementation I
21-
- (int) Meth { return PROP; } // expected-note 2{{'PROP' declared here}}
21+
- (int) Meth { return PROP; } // expected-note 2{{'PROP' declared here}} \
22+
// expected-note 5{{method declared here}}
2223

23-
@dynamic PROP1;
24+
@dynamic PROP1; // expected-warning {{property implementation declaration after method or function definition}}
2425
- (int) Meth1 { return PROP1; } // expected-error {{use of undeclared identifier 'PROP1'}}
2526

2627
- (int) Meth2 { return PROP2; } // expected-error {{use of undeclared identifier 'PROP2'}}
27-
@dynamic PROP2;
28+
@dynamic PROP2; // expected-warning {{property implementation declaration after method or function definition}}
2829

2930
- (int) Meth3 { return PROP3; } // expected-error {{use of undeclared identifier 'PROP3'}}
30-
@synthesize PROP3=IVAR;
31+
@synthesize PROP3=IVAR; // expected-warning {{property implementation declaration after method or function definition}}
3132

3233
- (int) Meth4 { return PROP4; }
33-
@synthesize PROP4=PROP4;
34+
@synthesize PROP4=PROP4; // expected-warning {{property implementation declaration after method or function definition}}
3435

3536
- (int) Meth5 { return bar; } // expected-error {{use of undeclared identifier 'bar'}}
36-
@synthesize bar = _bar;
37+
@synthesize bar = _bar; // expected-warning {{property implementation declaration after method or function definition}}
3738

3839
- (int) Meth6 { return bar1; }
3940

0 commit comments

Comments
 (0)