[cfe-commits] r148823 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjCXX/fragile-abi-object-assign.m

Douglas Gregor dgregor at apple.com
Tue Jan 24 11:11:02 PST 2012


On Jan 24, 2012, at 10:05 AM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Tue Jan 24 12:05:45 2012
> New Revision: 148823
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=148823&view=rev
> Log:
> objc: issue error if assigning objects in fragile-abi too.
> // rdar://10731065
> 
> Added:
>    cfe/trunk/test/SemaObjCXX/fragile-abi-object-assign.m
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaExpr.cpp
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=148823&r1=148822&r2=148823&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 24 12:05:45 2012
> @@ -3608,6 +3608,8 @@
> 
> def err_assignment_requires_nonfragile_object : Error<
>   "cannot assign to class object in non-fragile ABI (%0 invalid)">;
> +def err_objc_object_assignment : Error<
> +  "cannot assign to class object - use memcpy instead">;

Do we really want to suggest that users use memcpy to copy Objective-C objects? That seems… horribly error-prone, and not at all recommended because it will break under the non-fragile ABI. How about just complaining that classes cannot be assigned at all? If some clever user wants to shoot himself in the foot by using memcpy, at least we don't want to be blamed for giving him the gun...

	- Doug


> def err_direct_interface_unsupported : Error<
>   "indirection to an interface is not supported (%0 invalid)">;
> def err_typecheck_invalid_operands : Error<
> 
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=148823&r1=148822&r2=148823&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 24 12:05:45 2012
> @@ -7252,10 +7252,14 @@
>       ConvTy = Compatible;
> 
>     if (ConvTy == Compatible &&
> -        getLangOptions().ObjCNonFragileABI &&
> -        LHSType->isObjCObjectType())
> -      Diag(Loc, diag::err_assignment_requires_nonfragile_object)
> -        << LHSType;
> +        LHSType->isObjCObjectType()) {
> +      if (getLangOptions().ObjCNonFragileABI)
> +        Diag(Loc, diag::err_assignment_requires_nonfragile_object)
> +          << LHSType;
> +      else
> +        Diag(Loc, diag::err_objc_object_assignment)
> +          << LHSType;
> +    }
> 
>     // If the RHS is a unary plus or minus, check to see if they = and + are
>     // right next to each other.  If so, the user may have typo'd "x =+ 4"
> 
> Added: cfe/trunk/test/SemaObjCXX/fragile-abi-object-assign.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/fragile-abi-object-assign.m?rev=148823&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/fragile-abi-object-assign.m (added)
> +++ cfe/trunk/test/SemaObjCXX/fragile-abi-object-assign.m Tue Jan 24 12:05:45 2012
> @@ -0,0 +1,13 @@
> +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-fragile-abi -verify %s
> +// rdar://10731065
> +
> + at interface MyView {}
> + at end
> +
> + at implementation MyViewTemplate // expected-warning {{cannot find interface declaration for 'MyViewTemplate'}}
> +- (id) createRealObject {
> +  id realObj;
> +  *(MyView *) realObj = *(MyView *) self; // expected-error {{cannot assign to class object - use memcpy instead}}
> +}
> + at end
> +
> 
> 
> _______________________________________________
> 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