File tree Expand file tree Collapse file tree
src/semmle/code/cpp/controlflow
test/library-tests/c++_exceptions Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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`. */
Original file line number Diff line number Diff line change 1- | exceptions.cpp:25:13:30:9 | ExprStmt |
1+ | exceptions.cpp:25:13:25:19 | ExprStmt |
22| exceptions.cpp:26:13:26:13 | ExprStmt |
You can’t perform that action at this time.
0 commit comments