[cfe-commits] r141302 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjCXX/property-reference.mm test/SemaObjCXX/property-synthesis-error.mm
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 6 11:38:18 PDT 2011
Author: fjahanian
Date: Thu Oct 6 13:38:18 2011
New Revision: 141302
URL: http://llvm.org/viewvc/llvm-project?rev=141302&view=rev
Log:
objc++: For atomic properties of c++ class objec typet, appropriate
operator= is called. Issue a warning for non-trivial case until
runtime support is provided. // rdar://6137845
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjCXX/property-reference.mm
cfe/trunk/test/SemaObjCXX/property-synthesis-error.mm
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=141302&r1=141301&r2=141302&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 6 13:38:18 2011
@@ -501,6 +501,9 @@
"writable atomic property %0 cannot pair a synthesized setter/getter "
"with a user defined setter/getter">,
InGroup<DiagGroup<"atomic-property-with-user-defined-accessor">>;
+def warn_atomic_property_nontrivial_assign_op : Warning<
+ "atomic property of type %0 synthesizing setter using non-trivial assignment"
+ "operator">, InGroup<DiagGroup<"objc-property-atomic-setter-synthesis">>;
def warn_ownin_getter_rule : Warning<
"property's synthesized getter follows Cocoa naming"
" convention for returning 'owned' objects">,
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=141302&r1=141301&r2=141302&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Oct 6 13:38:18 2011
@@ -16,6 +16,7 @@
#include "clang/Sema/Initialization.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExprObjC.h"
+#include "clang/AST/ExprCXX.h"
#include "llvm/ADT/DenseSet.h"
using namespace clang;
@@ -800,6 +801,20 @@
VK_LValue, SourceLocation());
ExprResult Res = BuildBinOp(S, lhs->getLocEnd(),
BO_Assign, lhs, rhs);
+ if (property->getPropertyAttributes() &
+ ObjCPropertyDecl::OBJC_PR_atomic) {
+ Expr *callExpr = Res.takeAs<Expr>();
+ if (const CXXOperatorCallExpr *CXXCE =
+ dyn_cast_or_null<CXXOperatorCallExpr>(callExpr)) {
+ const CallExpr *CE = cast<CallExpr>(CXXCE);
+ if (const FunctionDecl *FuncDecl = CE->getDirectCallee()) {
+ if (!FuncDecl->isTrivial())
+ Diag(PropertyLoc,
+ diag::warn_atomic_property_nontrivial_assign_op)
+ << property->getType();
+ }
+ }
+ }
PIDecl->setSetterCXXAssignment(Res.takeAs<Expr>());
}
}
Modified: cfe/trunk/test/SemaObjCXX/property-reference.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/property-reference.mm?rev=141302&r1=141301&r2=141302&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/property-reference.mm (original)
+++ cfe/trunk/test/SemaObjCXX/property-reference.mm Thu Oct 6 13:38:18 2011
@@ -29,7 +29,7 @@
@implementation TNSObject
@synthesize cppObjectNonAtomic;
- at synthesize cppObjectAtomic;
+ at synthesize cppObjectAtomic; // expected-warning{{atomic property of type 'CREF_TCPPObject' (aka 'const TCPPObject &') synthesizing setter using non-trivial assignmentoperator}}
@dynamic cppObjectDynamic;
- (const TCPPObject&) cppObjectNonAtomic
Modified: cfe/trunk/test/SemaObjCXX/property-synthesis-error.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/property-synthesis-error.mm?rev=141302&r1=141301&r2=141302&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/property-synthesis-error.mm (original)
+++ cfe/trunk/test/SemaObjCXX/property-synthesis-error.mm Thu Oct 6 13:38:18 2011
@@ -30,3 +30,32 @@
{
return 0;
}
+
+// rdar://6137845
+class TCPPObject
+{
+public:
+ TCPPObject(const TCPPObject& inObj);
+ TCPPObject();
+ ~TCPPObject();
+ TCPPObject& operator=(const TCPPObject& inObj);
+private:
+ void* fData;
+};
+
+ at interface MyDocument
+{
+ at private
+ TCPPObject _cppObject;
+ TCPPObject _ncppObject;
+}
+ at property (assign, readwrite) const TCPPObject& cppObject;
+ at property (assign, readwrite, nonatomic) const TCPPObject& ncppObject;
+ at end
+
+ at implementation MyDocument
+
+ at synthesize cppObject = _cppObject; // expected-warning {{atomic property of type 'const TCPPObject &' synthesizing setter using non-trivial assignmentoperator}}
+ at synthesize ncppObject = _ncppObject;
+
+ at end
More information about the cfe-commits
mailing list