Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Tidy up SubBasicBlocks.qll #1827

Merged
merged 7 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C++: Use the word "rank" to denote a rank
Previously, the word "position" was used ambiguously in this library.
  • Loading branch information
jbj committed Aug 26, 2019
commit 2b94bb9edabcba35d3563b99e39c85dad90a6316
21 changes: 10 additions & 11 deletions cpp/ql/src/semmle/code/cpp/controlflow/SubBasicBlocks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
* predecessors.
*/
predicate firstInBB() {
exists(BasicBlock bb | this.getPosInBasicBlock(bb) = 0)
exists(BasicBlock bb | this.getRankInBasicBlock(bb) = 1)
}

/**
Expand All @@ -66,19 +66,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
*/
predicate lastInBB() {
exists(BasicBlock bb |
this.getPosInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb) - 1
this.getRankInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb)
)
}

/**
* Gets the position of this `SubBasicBlock` in its containing basic block
* `bb`, where `bb` is equal to `getBasicBlock()`.
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
*/
int getPosInBasicBlock(BasicBlock bb) {
exists(int thisIndexInBB, int rnk |
int getRankInBasicBlock(BasicBlock bb) {
exists(int thisIndexInBB |
thisIndexInBB = this.getIndexInBasicBlock(bb) and
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
result = rnk - 1
thisIndexInBB = rank[result](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb))
)
}

Expand All @@ -93,7 +92,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
result = this.getBasicBlock().getASuccessor()
or
exists(BasicBlock bb |
result.getPosInBasicBlock(bb) = this.getPosInBasicBlock(bb) + 1
result.getRankInBasicBlock(bb) = this.getRankInBasicBlock(bb) + 1
)
}

Expand Down Expand Up @@ -168,9 +167,9 @@ class SubBasicBlock extends ControlFlowNodeBase {
)
or
exists(SubBasicBlock succ, int succPos, int thisRank, int succRank |
thisRank = this.getPosInBasicBlock(bb) and
thisRank = this.getRankInBasicBlock(bb) and
succRank = thisRank + 1 and
succRank = succ.getPosInBasicBlock(bb) and
succRank = succ.getRankInBasicBlock(bb) and
bb.getNode(succPos) = succ and
result = succPos - thisPos
)
Expand Down
21 changes: 10 additions & 11 deletions cpp/ql/src/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
* predecessors.
*/
predicate firstInBB() {
exists(BasicBlock bb | this.getPosInBasicBlock(bb) = 0)
exists(BasicBlock bb | this.getRankInBasicBlock(bb) = 1)
}

/**
Expand All @@ -66,19 +66,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
*/
predicate lastInBB() {
exists(BasicBlock bb |
this.getPosInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb) - 1
this.getRankInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb)
)
}

/**
* Gets the position of this `SubBasicBlock` in its containing basic block
* `bb`, where `bb` is equal to `getBasicBlock()`.
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
*/
int getPosInBasicBlock(BasicBlock bb) {
exists(int thisIndexInBB, int rnk |
int getRankInBasicBlock(BasicBlock bb) {
exists(int thisIndexInBB |
thisIndexInBB = this.getIndexInBasicBlock(bb) and
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
result = rnk - 1
thisIndexInBB = rank[result](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb))
)
}

Expand All @@ -93,7 +92,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
result = this.getBasicBlock().getASuccessor()
or
exists(BasicBlock bb |
result.getPosInBasicBlock(bb) = this.getPosInBasicBlock(bb) + 1
result.getRankInBasicBlock(bb) = this.getRankInBasicBlock(bb) + 1
)
}

Expand Down Expand Up @@ -168,9 +167,9 @@ class SubBasicBlock extends ControlFlowNodeBase {
)
or
exists(SubBasicBlock succ, int succPos, int thisRank, int succRank |
thisRank = this.getPosInBasicBlock(bb) and
thisRank = this.getRankInBasicBlock(bb) and
succRank = thisRank + 1 and
succRank = succ.getPosInBasicBlock(bb) and
succRank = succ.getRankInBasicBlock(bb) and
bb.getNode(succPos) = succ and
result = succPos - thisPos
)
Expand Down