mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C++: Sync the two copies of SubBasicBlocks.qll
These files are now added to `identical-files.json` so they will remain in sync.
This commit is contained in:
@@ -36,6 +36,10 @@
|
||||
"java/ql/src/semmle/code/java/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
|
||||
"java/ql/src/semmle/code/java/dataflow/internal/tainttracking2/TaintTrackingImpl.qll"
|
||||
],
|
||||
"C++ SubBasicBlocks": [
|
||||
"cpp/ql/src/semmle/code/cpp/controlflow/SubBasicBlocks.qll",
|
||||
"cpp/ql/src/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll"
|
||||
],
|
||||
"IR Instruction": [
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll",
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll",
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
// NOTE: There are two copies of this file, and they must be kept identical:
|
||||
// - semmle/code/cpp/controlflow/SubBasicBlocks.qll
|
||||
// - semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll
|
||||
//
|
||||
// NOTE: Maintain this file in synchrony with
|
||||
// semmlecode-cpp-queries/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll
|
||||
//
|
||||
// The second one is a private copy of the `SubBasicBlocks` library for
|
||||
// internal use by the data flow library. Having an extra copy prevents
|
||||
// non-monotonic recursion errors in queries that use both the data flow
|
||||
// library and the `SubBasicBlocks` library.
|
||||
|
||||
/**
|
||||
* Provides the `SubBasicBlock` class, used for partitioning basic blocks in
|
||||
@@ -71,14 +75,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
|
||||
* `bb`, where `bb` is equal to `getBasicBlock()`.
|
||||
*/
|
||||
int getPosInBasicBlock(BasicBlock bb) {
|
||||
exists(int nodePos, int rnk |
|
||||
bb = this.(ControlFlowNode).getBasicBlock() and
|
||||
this = bb.getNode(nodePos) and
|
||||
nodePos = rank[rnk](int i | exists(SubBasicBlock n | n = bb.getNode(i))) and
|
||||
exists(int thisIndexInBB, int rnk |
|
||||
thisIndexInBB = this.getIndexInBasicBlock(bb) and
|
||||
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
|
||||
result = rnk - 1
|
||||
)
|
||||
}
|
||||
|
||||
pragma[noinline]
|
||||
private int getIndexInBasicBlock(BasicBlock bb) {
|
||||
this = bb.getNode(result)
|
||||
}
|
||||
|
||||
/** Gets a successor in the control-flow graph of `SubBasicBlock`s. */
|
||||
SubBasicBlock getASuccessor() {
|
||||
this.lastInBB() and
|
||||
@@ -94,16 +102,22 @@ class SubBasicBlock extends ControlFlowNodeBase {
|
||||
* start from 0, and the node at position 0 always exists and compares equal
|
||||
* to `this`.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
ControlFlowNode getNode(int pos) {
|
||||
exists(BasicBlock bb | bb = this.getBasicBlock() |
|
||||
exists(int thisPos | this = bb.getNode(thisPos) |
|
||||
result = bb.getNode(thisPos + pos) and
|
||||
pos >= 0 and
|
||||
pos < this.getNumberOfNodes()
|
||||
exists(BasicBlock bb |
|
||||
exists(int outerPos |
|
||||
result = bb.getNode(outerPos) and
|
||||
pos = outerPosToInnerPos(bb, outerPos)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private int outerPosToInnerPos(BasicBlock bb, int posInBB) {
|
||||
posInBB = result + this.getIndexInBasicBlock(bb) and
|
||||
result = [ 0 .. this.getNumberOfNodes() - 1 ]
|
||||
}
|
||||
|
||||
/** Gets a control-flow node in this `SubBasicBlock`. */
|
||||
ControlFlowNode getANode() {
|
||||
result = this.getNode(_)
|
||||
@@ -143,14 +157,20 @@ class SubBasicBlock extends ControlFlowNodeBase {
|
||||
* Gets the number of control-flow nodes in this `SubBasicBlock`. There is
|
||||
* always at least one.
|
||||
*/
|
||||
pragma[noopt]
|
||||
int getNumberOfNodes() {
|
||||
exists(BasicBlock bb | bb = this.getBasicBlock() |
|
||||
exists(int thisPos | this = bb.getNode(thisPos) |
|
||||
this.lastInBB() and
|
||||
result = bb.length() - thisPos
|
||||
exists(int bbLength |
|
||||
this.lastInBB() and
|
||||
bbLength = bb.length() and
|
||||
result = bbLength - thisPos
|
||||
)
|
||||
or
|
||||
exists(SubBasicBlock succ, int succPos |
|
||||
succ.getPosInBasicBlock(bb) = this.getPosInBasicBlock(bb) + 1 and
|
||||
exists(SubBasicBlock succ, int succPos, int thisRank, int succRank |
|
||||
thisRank = this.getPosInBasicBlock(bb) and
|
||||
succRank = thisRank + 1 and
|
||||
succRank = succ.getPosInBasicBlock(bb) and
|
||||
bb.getNode(succPos) = succ and
|
||||
result = succPos - thisPos
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// NOTE: There are two copies of this file, and they must be kept identical:
|
||||
// - semmle/code/cpp/controlflow/SubBasicBlocks.qll
|
||||
// - semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll
|
||||
//
|
||||
// NOTE: Maintain this file in synchrony with
|
||||
// semmlecode-cpp-queries/semmle/code/cpp/controlflow/SubBasicBlocks.qll
|
||||
//
|
||||
// This is a private copy of the `SubBasicBlocks` library for internal use by
|
||||
// the data flow library. Having an extra copy can prevent non-monotonic
|
||||
// recursion errors in queries that use both the data flow library and the
|
||||
// `SubBasicBlocks` library.
|
||||
// The second one is a private copy of the `SubBasicBlocks` library for
|
||||
// internal use by the data flow library. Having an extra copy prevents
|
||||
// non-monotonic recursion errors in queries that use both the data flow
|
||||
// library and the `SubBasicBlocks` library.
|
||||
|
||||
/**
|
||||
* Provides the `SubBasicBlock` class, used for partitioning basic blocks in
|
||||
|
||||
Reference in New Issue
Block a user