r311443 - [ObjC] Check written attributes only when synthesizing ambiguous property

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 09:24:33 PDT 2017


Merged in r311464. Thanks!

On Tue, Aug 22, 2017 at 3:42 AM, Alex L <arphaman at gmail.com> wrote:
> Hi Hans,
>
> Can you please merge this into LLVM 5? It fixes a rather serious Objective-C
> bug that I introduced just a couple of weeks before the branch.
>
> Cheers,
> Alex
>
>
> On 22 August 2017 at 11:38, Alex Lorenz via cfe-commits
> <cfe-commits at lists.llvm.org> wrote:
>>
>> Author: arphaman
>> Date: Tue Aug 22 03:38:07 2017
>> New Revision: 311443
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=311443&view=rev
>> Log:
>> [ObjC] Check written attributes only when synthesizing ambiguous property
>>
>> This commit fixes a bug introduced in r307903. The attribute ambiguity
>> checker
>> that was introduced in r307903 checked all property attributes, which
>> caused
>> errors for source-compatible properties, like:
>>
>> @property (nonatomic, readonly) NSObject *prop;
>> @property (nonatomic, readwrite) NSObject *prop;
>>
>> because the readwrite property would get implicit 'strong' attribute. The
>> ambiguity checker should be concerned about explicitly specified
>> attributes
>> only.
>>
>> rdar://33748089
>>
>> Modified:
>>     cfe/trunk/lib/Sema/SemaObjCProperty.cpp
>>     cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m
>>
>> Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=311443&r1=311442&r2=311443&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Aug 22 03:38:07 2017
>> @@ -872,7 +872,7 @@ SelectPropertyForSynthesisFromProtocols(
>>    }
>>
>>    QualType RHSType = S.Context.getCanonicalType(Property->getType());
>> -  unsigned OriginalAttributes = Property->getPropertyAttributes();
>> +  unsigned OriginalAttributes =
>> Property->getPropertyAttributesAsWritten();
>>    enum MismatchKind {
>>      IncompatibleType = 0,
>>      HasNoExpectedAttribute,
>> @@ -890,7 +890,7 @@ SelectPropertyForSynthesisFromProtocols(
>>    SmallVector<MismatchingProperty, 4> Mismatches;
>>    for (ObjCPropertyDecl *Prop : Properties) {
>>      // Verify the property attributes.
>> -    unsigned Attr = Prop->getPropertyAttributes();
>> +    unsigned Attr = Prop->getPropertyAttributesAsWritten();
>>      if (Attr != OriginalAttributes) {
>>        auto Diag = [&](bool OriginalHasAttribute, StringRef AttributeName)
>> {
>>          MismatchKind Kind = OriginalHasAttribute ? HasNoExpectedAttribute
>>
>> Modified: cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m?rev=311443&r1=311442&r2=311443&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m (original)
>> +++ cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m Tue Aug 22 03:38:07
>> 2017
>> @@ -225,3 +225,30 @@ __attribute__((objc_root_class))
>>  @implementation TypeVsSetter
>>  @synthesize prop; // expected-note {{property synthesized here}}
>>  @end
>> +
>> + at protocol AutoStrongProp
>> +
>> + at property (nonatomic, readonly) NSObject *prop;
>> +
>> + at end
>> +
>> + at protocol AutoStrongProp_Internal <AutoStrongProp>
>> +
>> +// This property gets the 'strong' attribute automatically.
>> + at property (nonatomic, readwrite) NSObject *prop;
>> +
>> + at end
>> +
>> + at interface SynthesizeWithImplicitStrongNoError : NSObject
>> <AutoStrongProp>
>> + at end
>> +
>> + at interface SynthesizeWithImplicitStrongNoError ()
>> <AutoStrongProp_Internal>
>> +
>> + at end
>> +
>> + at implementation SynthesizeWithImplicitStrongNoError
>> +
>> +// no error, 'strong' is implicit in the 'readwrite' property.
>> + at synthesize prop = _prop;
>> +
>> + at end
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>


More information about the cfe-commits mailing list