diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 56aa4480fbe6..34c702076593 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -1249,10 +1249,20 @@ ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl, return 0; } +static IdentifierInfo * getDefaultSynthIvarName(ObjCPropertyDecl *Prop, + ASTContext &Ctx) { + llvm::SmallString<128> ivarName; + { + llvm::raw_svector_ostream os(ivarName); + os << '_' << Prop->getIdentifier()->getName(); + } + return &Ctx.Idents.get(ivarName.str()); +} + /// DefaultSynthesizeProperties - This routine default synthesizes all /// properties which must be synthesized in class's @implementation. -void Sema::DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, - ObjCInterfaceDecl *IDecl) { +void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, + ObjCInterfaceDecl *IDecl) { llvm::DenseMap PropMap; CollectClassPropertyImplementations(IDecl, PropMap); @@ -1289,7 +1299,8 @@ void Sema::DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, // to help users. ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(), true, - Prop->getIdentifier(), Prop->getIdentifier(), + /* property = */ Prop->getIdentifier(), + /* ivar = */ getDefaultSynthIvarName(Prop, Context), SourceLocation()); } } diff --git a/clang/test/Index/complete-synthesized.m b/clang/test/Index/complete-synthesized.m index 4d2d80b84598..e6e49fb778d1 100644 --- a/clang/test/Index/complete-synthesized.m +++ b/clang/test/Index/complete-synthesized.m @@ -27,7 +27,7 @@ @dynamic prop3; - (short)method2 { - return prop4; + return _prop4; } - (short)method3 { @@ -43,4 +43,4 @@ // CHECK: ObjCIvarDecl:{ResultType float}{TypedText _prop2} (35) // CHECK-NOT: prop2 // CHECK-NOT: prop3 -// CHECK: ObjCIvarDecl:{ResultType double}{TypedText prop4} (37) +// CHECK: ObjCIvarDecl:{ResultType double}{TypedText _prop4} (37) diff --git a/clang/test/SemaObjC/default-synthesize-1.m b/clang/test/SemaObjC/default-synthesize-1.m index 3a27a1d9c7c8..9774de6e3bb2 100644 --- a/clang/test/SemaObjC/default-synthesize-1.m +++ b/clang/test/SemaObjC/default-synthesize-1.m @@ -25,12 +25,12 @@ //@synthesize howMany, what; - (int) howMany { - return howMany; + return _howMany; } // - (void) setHowMany: (int) value - (NSString*) what { - return what; + return _what; } // - (void) setWhat: (NSString*) value @end @@ -46,14 +46,14 @@ // - (int) howMany - (void) setHowMany: (int) value { - howMany = value; + _howMany = value; } // - (NSString*) what - (void) setWhat: (NSString*) value { - if (what != value) { - [what release]; - what = [value retain]; + if (_what != value) { + [_what release]; + _what = [value retain]; } } @end diff --git a/clang/test/SemaObjC/default-synthesize-2.m b/clang/test/SemaObjC/default-synthesize-2.m index d402348c2581..92a147d14c9f 100644 --- a/clang/test/SemaObjC/default-synthesize-2.m +++ b/clang/test/SemaObjC/default-synthesize-2.m @@ -16,7 +16,7 @@ // @synthesize name, rank, serialNumber; // default synthesis allows direct access to property ivars. - (id)init { - name = rank = serialNumber = 0; + _name = _rank = _serialNumber = 0; return self; } @@ -41,7 +41,7 @@ // Test3 @interface Test3 { - id _uid; + id uid; } @property (readwrite, assign) id uid; @end @@ -50,8 +50,8 @@ // Oops, forgot to write @synthesize! will be default synthesized - (void) myMethod { self.uid = 0; // Use of the “setter” - _uid = 0; // Use of the wrong instance variable - uid = 0; // Use of the property instance variable + uid = 0; // Use of the wrong instance variable + _uid = 0; // Use of the property instance variable } @end @@ -65,7 +65,7 @@ // default synthesize property named 'var' @implementation Test4 - (id) myMethod { - return self->var; // compiles because 'var' is synthesized by default + return self->_var; // compiles because 'var' is synthesized by default } @end @@ -80,7 +80,7 @@ @implementation Test5 - (id) myMethod { Test5 *foo = 0; - return foo->var; // OK + return foo->_var; // OK } @end @@ -100,19 +100,17 @@ @synthesize var = _var; @end -int* object; +int* _object; -@interface Test7 { -id _object; -} +@interface Test7 @property (readwrite, assign) id object; @end -// With default synthesis, 'object' is be the synthesized ivar not the global +// With default synthesis, '_object' is be the synthesized ivar not the global // 'int*' object. So no error. @implementation Test7 - (id) myMethod { - return object; + return _object; } @end diff --git a/clang/test/SemaObjC/direct-synthesized-ivar-access.m b/clang/test/SemaObjC/direct-synthesized-ivar-access.m index d9be872b4556..b1a470ab2e5c 100644 --- a/clang/test/SemaObjC/direct-synthesized-ivar-access.m +++ b/clang/test/SemaObjC/direct-synthesized-ivar-access.m @@ -10,6 +10,6 @@ @end @implementation I -- (int) Meth { return IVAR; } +- (int) Meth { return _IVAR; } - (int) OK { return self.IVAR; } @end diff --git a/clang/test/SemaObjC/synth-provisional-ivars.m b/clang/test/SemaObjC/synth-provisional-ivars.m index 8a743220416e..752a577a011d 100644 --- a/clang/test/SemaObjC/synth-provisional-ivars.m +++ b/clang/test/SemaObjC/synth-provisional-ivars.m @@ -18,7 +18,7 @@ int bar; @end @implementation I -- (int) Meth { return PROP; } +- (int) Meth { return _PROP; } @dynamic PROP1; - (int) Meth1 { return PROP1; } // expected-error {{use of undeclared identifier 'PROP1'}} @@ -30,12 +30,12 @@ int bar; @synthesize PROP3=IVAR; - (int) Meth4 { return PROP4; } -@synthesize PROP4=PROP4; +@synthesize PROP4=PROP4; // expected-note 4 {{'PROP4' declared here}} - (int) Meth5 { return bar; } @synthesize bar = _bar; -- (int) Meth6 { return bar1; } +- (int) Meth6 { return _bar1; } @end diff --git a/clang/test/SemaObjC/synthesized-ivar.m b/clang/test/SemaObjC/synthesized-ivar.m index 4786d808fa2f..12e7df1f5347 100644 --- a/clang/test/SemaObjC/synthesized-ivar.m +++ b/clang/test/SemaObjC/synthesized-ivar.m @@ -31,8 +31,8 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri @implementation I1 - (int) Meth { - PROP_INMAIN = 1; - PROP_INCLASSEXT = 2; + _PROP_INMAIN = 1; + _PROP_INCLASSEXT = 2; protected_ivar = 1; // OK return private_ivar; // OK } @@ -45,8 +45,8 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri @implementation DER - (int) Meth { protected_ivar = 1; // OK - PROP_INMAIN = 1; // expected-error {{instance variable 'PROP_INMAIN' is private}} - PROP_INCLASSEXT = 2; // expected-error {{instance variable 'PROP_INCLASSEXT' is private}} + _PROP_INMAIN = 1; // expected-error {{instance variable '_PROP_INMAIN' is private}} + _PROP_INCLASSEXT = 2; // expected-error {{instance variable '_PROP_INCLASSEXT' is private}} return private_ivar; // expected-error {{instance variable 'private_ivar' is private}} } @end