if (!TCond) Negate = !Negate;
return getTrylockCallExpr(BOP->getLHS(), C, Negate);
}
- else if (getStaticBooleanValue(BOP->getLHS(), TCond)) {
+ TCond = false;
+ if (getStaticBooleanValue(BOP->getLHS(), TCond)) {
if (!TCond) Negate = !Negate;
return getTrylockCallExpr(BOP->getRHS(), C, Negate);
}
return 0;
}
+ if (BOP->getOpcode() == BO_LAnd) {
+ // LHS must have been evaluated in a different block.
+ return getTrylockCallExpr(BOP->getRHS(), C, Negate);
+ }
+ if (BOP->getOpcode() == BO_LOr) {
+ return getTrylockCallExpr(BOP->getRHS(), C, Negate);
+ }
return 0;
}
- // FIXME -- handle && and || as well.
return 0;
}
const CFGBlock *CurrBlock) {
Result = ExitSet;
- if (!PredBlock->getTerminatorCondition())
+ const Stmt *Cond = PredBlock->getTerminatorCondition();
+ if (!Cond)
return;
bool Negate = false;
- const Stmt *Cond = PredBlock->getTerminatorCondition();
const CFGBlockInfo *PredBlockInfo = &BlockInfo[PredBlock->getBlockID()];
const LocalVarContext &LVarCtx = PredBlockInfo->ExitContext;
if(!FunDecl || !FunDecl->hasAttrs())
return;
-
MutexIDList ExclusiveLocksToAdd;
MutexIDList SharedLocksToAdd;
public:
Mutex mu;
int x __attribute__((guarded_by(mu)));
- void MyLock() __attribute__((exclusive_lock_function(mu)));
+ void MyLock() __attribute__((exclusive_lock_function(mu)));
};
MutexWrapper sls_mw;
void sls_fun_0() {
sls_mw.mu.Lock();
- sls_mw.x = 5;
+ sls_mw.x = 5;
sls_mw.mu.Unlock();
}
#endif
}
-
-void Foo::test2() {
-/* FIXME: these tests depend on changes to the CFG.
- *
- if (mu_.TryLock() && c) {
- a = 0;
- unlock();
- }
- else return;
-
- if (c && mu_.TryLock()) {
- a = 0;
- unlock();
- }
- else return;
-
- if (!(mu_.TryLock() && c))
- return;
- a = 0;
- unlock();
-
- if (!(c && mu_.TryLock()))
- return;
- a = 0;
- unlock();
-
- if (!(mu_.TryLock() == 0) && c) {
- a = 0;
- unlock();
- }
-
- if (!mu_.TryLock() || c)
- return;
- a = 0;
- unlock();
-*/
-}
-
} // end namespace TryLockEqTest
} // end namespace AssertHeldTest
+namespace LogicalConditionalTryLock {
+
+class Foo {
+public:
+ Mutex mu;
+ int a GUARDED_BY(mu);
+ bool c;
+
+ bool newc();
+
+ void test1() {
+ if (c && mu.TryLock()) {
+ a = 0;
+ mu.Unlock();
+ }
+ }
+
+ void test2() {
+ bool b = mu.TryLock();
+ if (c && b) {
+ a = 0;
+ mu.Unlock();
+ }
+ }
+
+ void test3() {
+ if (c || !mu.TryLock())
+ return;
+ a = 0;
+ mu.Unlock();
+ }
+
+ void test4() {
+ while (c && mu.TryLock()) {
+ a = 0;
+ c = newc();
+ mu.Unlock();
+ }
+ }
+
+ void test5() {
+ while (c) {
+ if (newc() || !mu.TryLock())
+ break;
+ a = 0;
+ mu.Unlock();
+ }
+ }
+
+ void test6() {
+ mu.Lock();
+ do {
+ a = 0;
+ mu.Unlock();
+ } while (newc() && mu.TryLock());
+ }
+
+ void test7() {
+ for (bool b = mu.TryLock(); c && b;) {
+ a = 0;
+ mu.Unlock();
+ }
+ }
+
+ void test8() {
+ if (c && newc() && mu.TryLock()) {
+ a = 0;
+ mu.Unlock();
+ }
+ }
+
+ void test9() {
+ if (!(c && newc() && mu.TryLock()))
+ return;
+ a = 0;
+ mu.Unlock();
+ }
+};
+
+} // end namespace LogicalConditionalTryLock
+