diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-01-24 18:05:45 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-01-24 18:05:45 +0000 |
commit | 7b383e4a3888c2bebc2762a94c23ad1fbb060281 (patch) | |
tree | 693411ba74f0a0af787b47a93fc92451a6647e00 | |
parent | 5602f7e77e975d780f84079532408c0064566c3b (diff) |
objc: issue error if assigning objects in fragile-abi too.
// rdar://10731065
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148823 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 12 | ||||
-rw-r--r-- | test/SemaObjCXX/fragile-abi-object-assign.m | 13 |
3 files changed, 23 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6c2c4ef558..311d998575 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3608,6 +3608,8 @@ def warn_pointer_indirection_from_incompatible_type : Warning< 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< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2d32ea9a06..9adf22ad2d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7252,10 +7252,14 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, 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" diff --git a/test/SemaObjCXX/fragile-abi-object-assign.m b/test/SemaObjCXX/fragile-abi-object-assign.m new file mode 100644 index 0000000000..41f961d90f --- /dev/null +++ b/test/SemaObjCXX/fragile-abi-object-assign.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-fragile-abi -verify %s +// rdar://10731065 + +@interface MyView {} +@end + +@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}} +} +@end + |