Skip to content

Commit b98d637

Browse files
committed
C++: Restore and deprecate getPosInBasicBlock
This predicte was still used in a test, so it might be used in external code too.
1 parent 4cae591 commit b98d637

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
7171
}
7272

7373
/**
74-
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
74+
* Gets the (1-based) rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
7575
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
7676
*/
7777
int getRankInBasicBlock(BasicBlock bb) {
@@ -81,6 +81,15 @@ class SubBasicBlock extends ControlFlowNodeBase {
8181
)
8282
}
8383

84+
/**
85+
* DEPRECATED: use `getRankInBasicBlock` instead. Note that this predicate
86+
* returns a 0-based position, while `getRankInBasicBlock` returns a 1-based
87+
* position.
88+
*/
89+
deprecated int getPosInBasicBlock(BasicBlock bb) {
90+
result = getRankInBasicBlock(bb) - 1
91+
}
92+
8493
pragma[noinline]
8594
private int getIndexInBasicBlock(BasicBlock bb) {
8695
this = bb.getNode(result)

cpp/ql/src/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
7171
}
7272

7373
/**
74-
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
74+
* Gets the (1-based) rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
7575
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
7676
*/
7777
int getRankInBasicBlock(BasicBlock bb) {
@@ -81,6 +81,15 @@ class SubBasicBlock extends ControlFlowNodeBase {
8181
)
8282
}
8383

84+
/**
85+
* DEPRECATED: use `getRankInBasicBlock` instead. Note that this predicate
86+
* returns a 0-based position, while `getRankInBasicBlock` returns a 1-based
87+
* position.
88+
*/
89+
deprecated int getPosInBasicBlock(BasicBlock bb) {
90+
result = getRankInBasicBlock(bb) - 1
91+
}
92+
8493
pragma[noinline]
8594
private int getIndexInBasicBlock(BasicBlock bb) {
8695
this = bb.getNode(result)

0 commit comments

Comments
 (0)