r194938 - ObjectiveC ARC. More validation of toll-free bridging of
Douglas Gregor
dgregor at apple.com
Tue Nov 19 10:14:32 PST 2013
On Nov 18, 2013, at 4:22 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>
> On Nov 18, 2013, at 16:13, Douglas Gregor <dgregor at apple.com> wrote:
>
>>
>> On Nov 16, 2013, at 3:22 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>>
>>> Author: fjahanian
>>> Date: Sat Nov 16 17:22:37 2013
>>> New Revision: 194938
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=194938&view=rev
>>> Log:
>>> ObjectiveC ARC. More validation of toll-free bridging of
>>> CF objects with objc_bridge'ing annotaiton.
>>> // rdar://15454846
>>>
>>> Modified:
>>> cfe/trunk/lib/Sema/SemaExprObjC.cpp
>>> cfe/trunk/test/SemaObjC/objcbridge-attribute.m
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=194938&r1=194937&r2=194938&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sat Nov 16 17:22:37 2013
>>> @@ -3190,7 +3190,11 @@ static bool CheckObjCBridgeNSCast(Sema &
>>> S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge)
>>> << TDNDecl->getName() << Target->getName() << CastClass->getName();
>>> return true;
>>> - }
>>> + } else {
>>> + S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge)
>>> + << TDNDecl->getName() << Target->getName() << castType;
>>> + return true;
>>> + }
>>> }
>>> }
>>> S.Diag(castExpr->getLocStart(), diag::err_objc_cf_bridged_not_interface)
>>> @@ -3233,6 +3237,11 @@ static bool CheckObjCBridgeCFCast(Sema &
>>> << ExprClass->getName() << TDNDecl->getName();
>>> S.Diag(TDNDecl->getLocStart(), diag::note_declared_at);
>>> return true;
>>> + } else {
>>> + S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge_to_cf)
>>> + << castExpr->getType() << castType;
>>> + S.Diag(TDNDecl->getLocStart(), diag::note_declared_at);
>>> + return true;
>>> }
>>> }
>>> }
>>>
>>> Modified: cfe/trunk/test/SemaObjC/objcbridge-attribute.m
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objcbridge-attribute.m?rev=194938&r1=194937&r2=194938&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/test/SemaObjC/objcbridge-attribute.m (original)
>>> +++ cfe/trunk/test/SemaObjC/objcbridge-attribute.m Sat Nov 16 17:22:37 2013
>>> @@ -1,7 +1,7 @@
>>> // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
>>> // rdar://15454846
>>>
>>> -typedef struct __CFErrorRef * __attribute__ ((objc_bridge(NSError))) CFErrorRef; // expected-note {{declared here}}
>>> +typedef struct __CFErrorRef * __attribute__ ((objc_bridge(NSError))) CFErrorRef; // expected-note 2 {{declared here}}
>>>
>>> typedef struct __CFMyColor * __attribute__((objc_bridge(12))) CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
>>>
>>> @@ -48,10 +48,12 @@ typedef CFErrorRef1 CFErrorRef2;
>>>
>>> @class NSString;
>>>
>>> -void Test2(CFErrorRef2 cf, NSError *ns, NSString *str) {
>>> +void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c) {
>>> (void)(NSString *)cf; // expected-warning {{CFErrorRef bridges to NSError, not NSString}}
>>> (void)(NSError *)cf; // okay
>>> (void)(MyError*)cf; // okay,
>>> (void)(CFErrorRef)ns; // okay
>>> (void)(CFErrorRef)str; // expected-warning {{NSString cannot bridge to CFErrorRef}}
>>> + (void)(Class)cf; // expected-warning {{CFErrorRef bridges to NSError, not 'Class'}}
>>> + (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef’}}
>>
>> ‘Class’ behaves like ‘id’, doesn’t it? Shouldn’t these be accepted without a warning?
>
> I don't think so, actually. The only CF type that could represent a class is the base, CFTypeRef. CoreFoundation objects don't have classes (they have "type IDs").
That's a good point. Nevermind!
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131119/90a61e79/attachment.html>
More information about the cfe-commits
mailing list