forked from OSchip/llvm-project
Thread-safety analysis: bugfix for case where a trylock occurs in an
expression involving temporaries. llvm-svn: 163237
This commit is contained in:
parent
63b1bc70ee
commit
93b1b031c1
|
@ -1532,6 +1532,9 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond,
|
||||||
else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Cond)) {
|
else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Cond)) {
|
||||||
return getTrylockCallExpr(CE->getSubExpr(), C, Negate);
|
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)) {
|
else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Cond)) {
|
||||||
const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C);
|
const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C);
|
||||||
return getTrylockCallExpr(E, C, Negate);
|
return getTrylockCallExpr(E, C, Negate);
|
||||||
|
|
|
@ -3190,3 +3190,30 @@ void Base::bar(Inner* i) {
|
||||||
|
|
||||||
} // end namespace LockReturnedScopeFix
|
} // 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue