Thread-safety analysis: bugfix for case where a trylock occurs in an

expression involving temporaries.

llvm-svn: 163237
This commit is contained in:
DeLesley Hutchins 2012-09-05 20:01:16 +00:00
parent 63b1bc70ee
commit 93b1b031c1
2 changed files with 30 additions and 0 deletions

View File

@ -1532,6 +1532,9 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond,
else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Cond)) {
return getTrylockCallExpr(CE->getSubExpr(), C, Negate);
}
else if (const ExprWithCleanups* EWC = dyn_cast<ExprWithCleanups>(Cond)) {
return getTrylockCallExpr(EWC->getSubExpr(), C, Negate);
}
else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Cond)) {
const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C);
return getTrylockCallExpr(E, C, Negate);

View File

@ -3190,3 +3190,30 @@ void Base::bar(Inner* i) {
} // end namespace LockReturnedScopeFix
namespace TrylockWithCleanups {
class MyString {
public:
MyString(const char* s);
~MyString();
};
struct Foo {
Mutex mu_;
int a GUARDED_BY(mu_);
};
Foo* GetAndLockFoo(const MyString& s)
EXCLUSIVE_TRYLOCK_FUNCTION(true, &Foo::mu_);
static void test() {
Foo* lt = GetAndLockFoo("foo");
if (!lt) return;
int a = lt->a;
lt->mu_.Unlock();
}
}