Skip to content

Commit 771abf4

Browse files
committed
C++/C#: Sync identical files.
1 parent 3b2c3f6 commit 771abf4

File tree

4 files changed

+68
-16
lines changed

4 files changed

+68
-16
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,27 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259-
private Instruction getInstructionFromFirst(Instruction first, int index) =
260-
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
258+
/** Gets the index of `i` in its `IRBlock`. */
259+
private int getMemberIndex(Instruction i) {
260+
startsBasicBlock(i) and
261+
result = 0
262+
or
263+
exists(Instruction iPrev |
264+
adjacentInBlock(iPrev, i) and
265+
result = getMemberIndex(iPrev) + 1
266+
)
267+
}
268+
269+
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
261270

262271
/** Holds if `i` is the `index`th instruction in `block`. */
263272
cached
264273
Instruction getInstruction(TIRBlock block, int index) {
265-
result = getInstructionFromFirst(getFirstInstruction(block), index)
274+
exists(Instruction first |
275+
block = MkIRBlock(first) and
276+
index = getMemberIndex(result) and
277+
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
278+
)
266279
}
267280

268281
cached

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,27 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259-
private Instruction getInstructionFromFirst(Instruction first, int index) =
260-
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
258+
/** Gets the index of `i` in its `IRBlock`. */
259+
private int getMemberIndex(Instruction i) {
260+
startsBasicBlock(i) and
261+
result = 0
262+
or
263+
exists(Instruction iPrev |
264+
adjacentInBlock(iPrev, i) and
265+
result = getMemberIndex(iPrev) + 1
266+
)
267+
}
268+
269+
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
261270

262271
/** Holds if `i` is the `index`th instruction in `block`. */
263272
cached
264273
Instruction getInstruction(TIRBlock block, int index) {
265-
result = getInstructionFromFirst(getFirstInstruction(block), index)
274+
exists(Instruction first |
275+
block = MkIRBlock(first) and
276+
index = getMemberIndex(result) and
277+
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
278+
)
266279
}
267280

268281
cached

csharp/ql/src/experimental/ir/implementation/raw/IRBlock.qll

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,27 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259-
private Instruction getInstructionFromFirst(Instruction first, int index) =
260-
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
258+
/** Gets the index of `i` in its `IRBlock`. */
259+
private int getMemberIndex(Instruction i) {
260+
startsBasicBlock(i) and
261+
result = 0
262+
or
263+
exists(Instruction iPrev |
264+
adjacentInBlock(iPrev, i) and
265+
result = getMemberIndex(iPrev) + 1
266+
)
267+
}
268+
269+
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
261270

262271
/** Holds if `i` is the `index`th instruction in `block`. */
263272
cached
264273
Instruction getInstruction(TIRBlock block, int index) {
265-
result = getInstructionFromFirst(getFirstInstruction(block), index)
274+
exists(Instruction first |
275+
block = MkIRBlock(first) and
276+
index = getMemberIndex(result) and
277+
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
278+
)
266279
}
267280

268281
cached

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,27 @@ private module Cached {
255255
cached
256256
newtype TIRBlock = MkIRBlock(Instruction firstInstr) { startsBasicBlock(firstInstr) }
257257

258-
/** Holds if `i` is the `index`th instruction the block starting with `first`. */
259-
private Instruction getInstructionFromFirst(Instruction first, int index) =
260-
shortestDistances(startsBasicBlock/1, adjacentInBlock/2)(first, result, index)
258+
/** Gets the index of `i` in its `IRBlock`. */
259+
private int getMemberIndex(Instruction i) {
260+
startsBasicBlock(i) and
261+
result = 0
262+
or
263+
exists(Instruction iPrev |
264+
adjacentInBlock(iPrev, i) and
265+
result = getMemberIndex(iPrev) + 1
266+
)
267+
}
268+
269+
private module BlockAdjacency = QlBuiltins::EquivalenceRelation<Instruction, adjacentInBlock/2>;
261270

262271
/** Holds if `i` is the `index`th instruction in `block`. */
263272
cached
264273
Instruction getInstruction(TIRBlock block, int index) {
265-
result = getInstructionFromFirst(getFirstInstruction(block), index)
274+
exists(Instruction first |
275+
block = MkIRBlock(first) and
276+
index = getMemberIndex(result) and
277+
BlockAdjacency::getEquivalenceClass(first) = BlockAdjacency::getEquivalenceClass(result)
278+
)
266279
}
267280

268281
cached

0 commit comments

Comments
 (0)