[cfe-commits] r159674 - in /cfe/trunk: lib/Analysis/ThreadSafety.cpp test/SemaCXX/warn-thread-safety-analysis.cpp
DeLesley Hutchins
delesley at google.com
Tue Jul 3 11:25:56 PDT 2012
Author: delesley
Date: Tue Jul 3 13:25:56 2012
New Revision: 159674
URL: http://llvm.org/viewvc/llvm-project?rev=159674&view=rev
Log:
Thread Safety Analysis: handle expressions involving temporaries,
e.g. ExprWithCleanups.
Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=159674&r1=159673&r2=159674&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Tue Jul 3 13:25:56 2012
@@ -206,15 +206,17 @@
buildMutexID(CE->getSubExpr(), CallCtx);
} else if (ParenExpr *PE = dyn_cast<ParenExpr>(Exp)) {
buildMutexID(PE->getSubExpr(), CallCtx);
+ } else if (ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Exp)) {
+ buildMutexID(EWC->getSubExpr(), CallCtx);
} else if (isa<CharacterLiteral>(Exp) ||
- isa<CXXNullPtrLiteralExpr>(Exp) ||
- isa<GNUNullExpr>(Exp) ||
- isa<CXXBoolLiteralExpr>(Exp) ||
- isa<FloatingLiteral>(Exp) ||
- isa<ImaginaryLiteral>(Exp) ||
- isa<IntegerLiteral>(Exp) ||
- isa<StringLiteral>(Exp) ||
- isa<ObjCStringLiteral>(Exp)) {
+ isa<CXXNullPtrLiteralExpr>(Exp) ||
+ isa<GNUNullExpr>(Exp) ||
+ isa<CXXBoolLiteralExpr>(Exp) ||
+ isa<FloatingLiteral>(Exp) ||
+ isa<ImaginaryLiteral>(Exp) ||
+ isa<IntegerLiteral>(Exp) ||
+ isa<StringLiteral>(Exp) ||
+ isa<ObjCStringLiteral>(Exp)) {
return; // FIXME: Ignore literals for now
} else {
// Ignore. FIXME: mark as invalid expression?
@@ -1523,6 +1525,10 @@
Decl *D = *I;
if (VarDecl *VD = dyn_cast_or_null<VarDecl>(D)) {
Expr *E = VD->getInit();
+ // handle constructors that involve temporaries
+ if (ExprWithCleanups *EWC = dyn_cast_or_null<ExprWithCleanups>(E))
+ E = EWC->getSubExpr();
+
if (CXXConstructExpr *CE = dyn_cast_or_null<CXXConstructExpr>(E)) {
NamedDecl *CtorD = dyn_cast_or_null<NamedDecl>(CE->getConstructor());
if (!CtorD || !CtorD->hasAttrs())
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=159674&r1=159673&r2=159674&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Jul 3 13:25:56 2012
@@ -57,6 +57,23 @@
void Release() UNLOCK_FUNCTION();
};
+
+template<class T>
+class SmartPtr {
+public:
+ SmartPtr(T* p) : ptr_(p) { }
+ SmartPtr(const SmartPtr<T>& p) : ptr_(p.ptr_) { }
+ ~SmartPtr();
+
+ T* get() const { return ptr_; }
+ T* operator->() const { return ptr_; }
+ T& operator*() const { return ptr_; }
+
+private:
+ T* ptr_;
+};
+
+
Mutex sls_mu;
Mutex sls_mu2 __attribute__((acquired_after(sls_mu)));
@@ -2535,3 +2552,26 @@
} // end namespace FoolishScopedLockableBug
+
+namespace TemporaryCleanupExpr {
+
+class Foo {
+ int a GUARDED_BY(getMutexPtr().get());
+
+ SmartPtr<Mutex> getMutexPtr();
+
+ void test();
+};
+
+
+void Foo::test() {
+ {
+ ReaderMutexLock lock(getMutexPtr().get());
+ int b = a;
+ } // FIXME: handle smart pointers better.
+ int b = a; // expected-warning {{reading variable 'a' requires locking 'get'}}
+}
+
+} // end namespace TemporaryCleanupExpr
+
+
More information about the cfe-commits
mailing list