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

Fariborz Jahanian fjahanian at apple.com
Tue Jan 24 10:05:45 PST 2012


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">;
 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
+





More information about the cfe-commits mailing list