Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3dfa31

Browse files
committed
CPP: Make Handlers always begin a BasicBlock.
1 parent 092db18 commit a3dfa31

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

cpp/ql/src/semmle/code/cpp/controlflow/BasicBlocks.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,15 @@ class BasicBlock extends ControlFlowNodeBase {
240240

241241
/**
242242
* Holds if control flow may reach this basic block from a function entry
243-
* point or a `catch` clause of a reachable `try` statement.
243+
* point or any handler of a reachable `try` statement.
244244
*/
245245
predicate isReachable() {
246246
exists(Function f | f.getBlock() = this)
247247
or
248248
exists(TryStmt t, BasicBlock tryblock |
249-
(
250-
this = t.getACatchClause() or
251-
this.(Handler).getTryStmt() = t
252-
) and
249+
// a `Handler` preceeds the `CatchBlock`, and is always the beginning
250+
// of a new `BasicBlock` (see `primitive_basic_block_entry_node`).
251+
this.(Handler).getTryStmt() = t and
253252
tryblock.isReachable() and
254253
tryblock.contains(t)
255254
) or

cpp/ql/src/semmle/code/cpp/controlflow/internal/PrimitiveBasicBlocks.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ private cached module Cached {
4444
// that the node have at least one successor.
4545
or
4646
(not successors_extended(_, node) and successors_extended(node, _))
47+
48+
// An exception handler is always the start of a new basic block. We
49+
// don't generate edges for [possible] exceptions, but in practice control
50+
// flow could reach the handler from anywhere inside the try block that
51+
// could throw an exception of a corresponding type. A `Handler` usually
52+
// needs to be considered reachable (see also `BasicBlock.isReachable`).
53+
or
54+
node instanceof Handler
4755
}
4856

4957
/** Holds if `n2` follows `n1` in a `PrimitiveBasicBlock`. */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| exceptions.cpp:25:13:30:9 | ExprStmt |
1+
| exceptions.cpp:25:13:25:19 | ExprStmt |
22
| exceptions.cpp:26:13:26:13 | ExprStmt |

0 commit comments

Comments
 (0)