[cfe-commits] r143258 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/arc-objc-lifetime.m test/SemaObjC/arc-unavailable-for-weakref.m test/SemaObjCXX/arc-unavailable-for-weakref.mm

Ted Kremenek kremenek at apple.com
Mon Oct 31 10:20:49 PDT 2011


Minor nit:

Instead of "would have no effect" how about "has no effect"?

Sent from my iPad

On Oct 28, 2011, at 5:06 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:

> Author: fjahanian
> Date: Fri Oct 28 19:06:10 2011
> New Revision: 143258
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=143258&view=rev
> Log:
> objc-arc: desugar certain type and improve on diagnostic for
> ownership qualifier cast which won't work.
> // rdar://10244607
> 
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaExprObjC.cpp
>    cfe/trunk/test/SemaObjC/arc-objc-lifetime.m
>    cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
>    cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=143258&r1=143257&r2=143258&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 28 19:06:10 2011
> @@ -3043,8 +3043,7 @@
>   "an Objective-C pointer|an indirect pointer to an Objective-C pointer}1"
>   " to %3 is disallowed with ARC">;
> def err_arc_nolifetime_behavior : Error<
> -  "casting expression of type %1 to type %0 with qualified lifetime"
> -  "will not change object lifetime">;
> +  "explicit ownership qualifier on cast result would have no effect">;
> def err_arc_objc_object_in_struct : Error<
>   "ARC forbids Objective-C objects in structs or unions">;
> def err_arc_objc_property_default_assign_on_object : Error<
> 
> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=143258&r1=143257&r2=143258&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Oct 28 19:06:10 2011
> @@ -1937,17 +1937,27 @@
>   if (exprACTC == castACTC) {
>     // check for viablity and report error if casting an rvalue to a
>     // life-time qualifier.
> -    if ((castACTC == ACTC_retainable) && 
> -        isa<AttributedType>(castType) &&
> -        (castType.getObjCLifetime() !=  Qualifiers::OCL_None) &&
> +    if ((castACTC == ACTC_retainable) &&
>         (CCK == CCK_CStyleCast || CCK == CCK_OtherCast) &&
> -        castType != castExprType) {
> -      SourceLocation loc =
> -        (castRange.isValid() ? castRange.getBegin() 
> -                             : castExpr->getExprLoc());
> -      Diag(loc, diag::err_arc_nolifetime_behavior)
> -        << effCastType << castExprType 
> -        << castRange << castExpr->getSourceRange();
> +        (castType != castExprType)) {
> +      const Type *DT = castType.getTypePtr();
> +      QualType QDT = castType;
> +      // We desugar some types but not others. We ignore those
> +      // that cannot happen in a cast; i.e. auto, and those which
> +      // should not be de-sugared; i.e typedef.
> +      if (const ParenType *PT = dyn_cast<ParenType>(DT))
> +        QDT = PT->desugar();
> +      else if (const TypeOfType *TP = dyn_cast<TypeOfType>(DT))
> +        QDT = TP->desugar();
> +      else if (const AttributedType *AT = dyn_cast<AttributedType>(DT))
> +        QDT = AT->desugar();
> +      if (QDT != castType &&
> +          QDT.getObjCLifetime() !=  Qualifiers::OCL_None) {
> +        SourceLocation loc =
> +          (castRange.isValid() ? castRange.getBegin() 
> +                              : castExpr->getExprLoc());
> +        Diag(loc, diag::err_arc_nolifetime_behavior);
> +      }
>     }
>     return ACR_okay;
>   }
> 
> Modified: cfe/trunk/test/SemaObjC/arc-objc-lifetime.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-objc-lifetime.m?rev=143258&r1=143257&r2=143258&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/arc-objc-lifetime.m (original)
> +++ cfe/trunk/test/SemaObjC/arc-objc-lifetime.m Fri Oct 28 19:06:10 2011
> @@ -17,12 +17,14 @@
> - (CFStringRef)myString
> {
>     CFStringRef myString =
> -      (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{casting expression of type 'NSString *' to type 'NSString *__strong' with qualified lifetimewill not change object lifetime}}
> +      (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> 
>     myString =
> -      (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{casting expression of type 'NSString *' to type '__autoreleasing PNSString' (aka 'NSString *__autoreleasing') with qualified lifetimewill not change object}}
> +      (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result would have no effect}}
>     myString =
>       (__bridge CFStringRef) (AUTORELEASEPNSString) CFBridgingRelease(); // OK
> +    myString =
> +      (__bridge CFStringRef) (typeof(__strong NSString *)) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result would have no effect}}
>     return myString;
> }
> 
> 
> Modified: cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m?rev=143258&r1=143257&r2=143258&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m (original)
> +++ cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m Fri Oct 28 19:06:10 2011
> @@ -16,7 +16,7 @@
> 
>   ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \
>                            // expected-error {{class is incompatible with __weak references}} \
> -                           // expected-error {{casting expression of type 'id' to type 'sub *__weak' with qualified lifetimewill not change object lifetime}}
> +                           // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> // rdar://9732636
> @@ -32,7 +32,7 @@
> 
>   __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
>   return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \
> -                             // expected-error {{casting expression of type 'NOWEAK *' to type '__weak id' with qualified lifetimewill not change object lifetime}}
> +                             // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> @protocol P @end
> @@ -45,6 +45,6 @@
> 
>   __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
>   return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}} \
> -                                // expected-error {{casting expression of type 'NOWEAK<P,P1> *' to type '__weak id<P>' with qualified lifetimewill not change object lifetime}}
> +                                // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> 
> Modified: cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm?rev=143258&r1=143257&r2=143258&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm (original)
> +++ cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm Fri Oct 28 19:06:10 2011
> @@ -16,7 +16,7 @@
> 
>   ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \
>                            // expected-error {{class is incompatible with __weak references}} \
> -                           // expected-error {{casting expression of type 'id' to type 'sub *__weak' with qualified lifetimewill not change object lifetime}}
> +                           // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> // rdar://9732636
> @@ -32,7 +32,7 @@
> 
>   __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
>   return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \
> -                             // expected-error {{casting expression of type 'NOWEAK *' to type '__weak id' with qualified lifetimewill not change object lifetime}}
> +                             // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> @protocol P @end
> @@ -45,6 +45,6 @@
> 
>   __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
>   return (__weak id<P, P1>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P,P1>'}} \
> -                                    // expected-error {{casting expression of type 'NOWEAK<P,P1> *' to type '__weak id<P,P1>' with qualified lifetimewill not change object lifetime}}
> +                                    // expected-error {{explicit ownership qualifier on cast result would have no effect}}
> }
> 
> 
> 
> _______________________________________________
> 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