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

Skip to content

Commit cc97cf9

Browse files
author
Robert Marsh
committed
C++: add isReachableFromFunctionEntry
1 parent 4c94144 commit cc97cf9

6 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class IRGuardCondition extends Instruction {
310310
succ.dominates(controlled) and
311311
forall(IRBlock pred
312312
| pred.getASuccessor() = succ
313-
| pred = thisblock or succ.dominates(pred)))) // removed reachability condition - is that OK?
313+
| pred = thisblock or succ.dominates(pred) or not pred.isReachableFromFunctionEntry())))
314314
}
315315
}
316316

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ class IRBlock extends TIRBlock {
8989
dominates(result.getAPredecessor()) and
9090
not strictlyDominates(result)
9191
}
92+
93+
/**
94+
* Holds if this block is reachable from the entry point of its function
95+
*/
96+
final predicate isReachableFromFunctionEntry() {
97+
this = getFunctionIR().getEntryBlock() or
98+
getAPredecessor().isReachableFromFunctionEntry()
99+
}
92100
}

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ class IRBlock extends TIRBlock {
8989
dominates(result.getAPredecessor()) and
9090
not strictlyDominates(result)
9191
}
92+
93+
/**
94+
* Holds if this block is reachable from the entry point of its function
95+
*/
96+
final predicate isReachableFromFunctionEntry() {
97+
this = getFunctionIR().getEntryBlock() or
98+
getAPredecessor().isReachableFromFunctionEntry()
99+
}
92100
}

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ class IRBlock extends TIRBlock {
8989
dominates(result.getAPredecessor()) and
9090
not strictlyDominates(result)
9191
}
92+
93+
/**
94+
* Holds if this block is reachable from the entry point of its function
95+
*/
96+
final predicate isReachableFromFunctionEntry() {
97+
this = getFunctionIR().getEntryBlock() or
98+
getAPredecessor().isReachableFromFunctionEntry()
99+
}
92100
}

cpp/ql/test/library-tests/controlflow/guards-ir/ASTGuardsControl.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@
8787
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
8888
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
8989
| test.cpp:31:7:31:13 | ... == ... | true | 31 | 32 |
90+
| test.cpp:42:13:42:20 | call to getABool | false | 53 | 53 |
9091
| test.cpp:42:13:42:20 | call to getABool | true | 43 | 45 |

cpp/ql/test/library-tests/controlflow/guards-ir/IRGuardsControl.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@
8282
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
8383
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
8484
| test.cpp:31:7:31:13 | ... == ... | true | 32 | 32 |
85+
| test.cpp:42:13:42:20 | call to getABool | false | 53 | 53 |
8586
| test.cpp:42:13:42:20 | call to getABool | true | 44 | 44 |

0 commit comments

Comments
 (0)