Skip to content

Commit f283a38

Browse files
committed
fixes
1 parent 14e4193 commit f283a38

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cpp/common/src/codingstandards/cpp/Concurrency.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ class CPPMutexFunctionCall extends MutexFunctionCall {
114114
/**
115115
* Holds if this `CPPMutexFunctionCall` is a lock.
116116
*/
117-
override predicate isLock() { getTarget().getName() = "lock" }
117+
override predicate isLock() {
118+
not isLockingOperationWithinLockingOperation(this) and
119+
getTarget().getName() = "lock"
120+
}
118121

119122
/**
120123
* Holds if this `CPPMutexFunctionCall` is a speculative lock, defined as calling
@@ -172,6 +175,7 @@ class CMutexFunctionCall extends MutexFunctionCall {
172175
* Holds if this `CMutexFunctionCall` is a lock.
173176
*/
174177
override predicate isLock() {
178+
not isLockingOperationWithinLockingOperation(this) and
175179
getTarget().getName() = ["mtx_lock", "mtx_timedlock", "mtx_trylock"]
176180
}
177181

@@ -296,6 +300,16 @@ abstract class LockingOperation extends FunctionCall {
296300
* Holds if this is an unlock operation
297301
*/
298302
abstract predicate isUnlock();
303+
304+
/**
305+
* Holds if this locking operation is really a locking operation within a
306+
* designated locking operation. This library assumes the underlying locking
307+
* operations are implemented correctly in that calling a `LockingOperation`
308+
* results in the creation of a singular lock.
309+
*/
310+
predicate isLockingOperationWithinLockingOperation(LockingOperation inner) {
311+
exists(LockingOperation outer | outer.getTarget() = inner.getEnclosingFunction())
312+
}
299313
}
300314

301315
/**
@@ -317,6 +331,7 @@ class RAIIStyleLock extends LockingOperation {
317331
* Holds if this is a lock operation
318332
*/
319333
override predicate isLock() {
334+
not isLockingOperationWithinLockingOperation(this) and
320335
this instanceof ConstructorCall and
321336
lock = getArgument(0).getAChild*() and
322337
// defer_locks don't cause a lock

cpp/common/src/codingstandards/cpp/rules/preventdeadlockbylockinginpredefinedorder/PreventDeadlockByLockingInPredefinedOrder.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ predicate getAnOrderedLockPair(
2424
lock1 = node.coveredByLock() and
2525
lock2 = node.coveredByLock() and
2626
not lock1 = lock2 and
27-
lock1.getEnclosingFunction() = lock2.getEnclosingFunction() and
27+
exists(Function f |
28+
lock1.getEnclosingFunction() = f and
29+
lock2.getEnclosingFunction() = f and
30+
node.getBasicBlock().getEnclosingFunction() = f
31+
) and
2832
exists(Location l1Loc, Location l2Loc |
2933
l1Loc = lock1.getLocation() and
3034
l2Loc = lock2.getLocation()

0 commit comments

Comments
 (0)