r194938 - ObjectiveC ARC. More validation of toll-free bridging of

Douglas Gregor dgregor at apple.com
Mon Nov 18 16:13:32 PST 2013


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?

	- Doug

> }
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list