-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathBasicBlock.qll
More file actions
40 lines (35 loc) · 1.04 KB
/
BasicBlock.qll
File metadata and controls
40 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Provides utilities for working with basic blocks in tests.
*/
overlay[local?]
module;
import java
import codeql.util.Boolean
private predicate entryOrExit(ControlFlowNode n) {
n instanceof ControlFlow::EntryNode or
n instanceof ControlFlow::AnnotatedExitNode or
n instanceof ControlFlow::ExitNode
}
/** Gets the first AST node in the basic block `bb`, if any. */
ControlFlowNode getFirstAstNode(BasicBlock bb) { result = getFirstAstNode(bb, false) }
/**
* Gets the first AST node in the basic block `bb`, if any. Otherwise, gets
* the first synthetic node.
*/
ControlFlowNode getFirstAstNodeOrSynth(BasicBlock bb) { result = getFirstAstNode(bb, true) }
private ControlFlowNode getFirstAstNode(BasicBlock bb, Boolean allowSynthetic) {
result =
min(ControlFlowNode n, int i, int astOrder |
bb.getNode(i) = n and
if n.injects(_)
then astOrder = 0
else
if entryOrExit(n)
then astOrder = 1
else (
allowSynthetic = true and astOrder = 2
)
|
n order by astOrder, i
)
}