Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e13a39

Browse files
committed
C++: Add getUpdatedInterval predicate to ChiInstructions, and getUsedInterval predicate to NonPhiMemoryOperands.
1 parent 1221165 commit 1e13a39

11 files changed

Lines changed: 125 additions & 16 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,13 @@ class ChiInstruction extends Instruction {
19621962
* Gets the operand that represents the new value written by the memory write.
19631963
*/
19641964
final Instruction getPartial() { result = getPartialOperand().getDef() }
1965+
1966+
/**
1967+
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`.
1968+
*/
1969+
final predicate getUpdatedInterval(int startBit, int endBit) {
1970+
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
1971+
}
19651972
}
19661973

19671974
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ class NonPhiMemoryOperand extends NonPhiOperand, MemoryOperand, NonPhiMemoryOper
328328
not Construction::isInCycle(useInstr) and
329329
strictcount(Construction::getMemoryOperandDefinition(useInstr, tag, _)) = 1
330330
}
331+
332+
/**
333+
* Holds if the operand totally overlaps with its definition and consumes the
334+
* bit range `[startBitOffset, endBitOffset)`.
335+
*/
336+
predicate getUsedInterval(int startBitOffset, int endBitOffset) {
337+
Construction::getUsedInterval(this, startBitOffset, endBitOffset)
338+
}
331339
}
332340

333341
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasedSSA.qll

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,22 +556,6 @@ private Overlap getVariableMemoryLocationOverlap(
556556
use.getEndBitOffset())
557557
}
558558

559-
predicate getDefInterval(Instruction defInstr, IntValue startBitDef, IntValue endBitDef) {
560-
exists(VariableMemoryLocation def |
561-
def = getResultMemoryLocation(defInstr) and
562-
startBitDef = def.getStartBitOffset() and
563-
endBitDef = def.getEndBitOffset()
564-
)
565-
}
566-
567-
predicate getUseInterval(Instruction useInstr, IntValue startBitUse, IntValue endBitUse) {
568-
exists(VariableMemoryLocation use |
569-
use = getOperandMemoryLocation(useInstr.getAnOperand()) and
570-
startBitUse = use.getStartBitOffset() and
571-
endBitUse = use.getEndBitOffset()
572-
)
573-
}
574-
575559
MemoryLocation getResultMemoryLocation(Instruction instr) {
576560
exists(MemoryAccessKind kind, boolean isMayAccess |
577561
kind = instr.getResultMemoryAccess() and
@@ -633,3 +617,9 @@ MemoryLocation getOperandMemoryLocation(MemoryOperand operand) {
633617
)
634618
)
635619
}
620+
621+
/** Gets the start bit offset of a `MemoryLocation`, if any. */
622+
int getStartBitOffset(VariableMemoryLocation location) { result = location.getStartBitOffset() }
623+
624+
/** Gets the end bit offset of a `MemoryLocation`, if any. */
625+
int getEndBitOffset(VariableMemoryLocation location) { result = location.getEndBitOffset() }

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ private module Cached {
149149
)
150150
}
151151

152+
/**
153+
* Holds if the partial operand of this `ChiInstruction` updates the bit range
154+
* `[startBitOffset, endBitOffset)` of the total operand.
155+
*/
156+
cached
157+
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBitOffset, int endBitOffset) {
158+
exists(Alias::MemoryLocation location, OldInstruction oldInstruction |
159+
oldInstruction = getOldInstruction(chi.getPartial()) and
160+
location = Alias::getResultMemoryLocation(oldInstruction) and
161+
startBitOffset = Alias::getStartBitOffset(location) and
162+
endBitOffset = Alias::getEndBitOffset(location)
163+
)
164+
}
165+
166+
/**
167+
* Holds if `operand` totally overlaps with its definition and consumes the bit range
168+
* `[startBitOffset, endBitOffset)`.
169+
*/
170+
cached
171+
predicate getUsedInterval(NonPhiMemoryOperand operand, int startBitOffset, int endBitOffset) {
172+
exists(Alias::MemoryLocation location, OldIR::NonPhiMemoryOperand oldOperand |
173+
oldOperand = operand.getUse().(OldInstruction).getAnOperand() and
174+
location = Alias::getOperandMemoryLocation(oldOperand) and
175+
startBitOffset = Alias::getStartBitOffset(location) and
176+
endBitOffset = Alias::getEndBitOffset(location)
177+
)
178+
}
179+
152180
/**
153181
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
154182
* through a phi instruction and therefore should be impossible.

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,13 @@ class ChiInstruction extends Instruction {
19621962
* Gets the operand that represents the new value written by the memory write.
19631963
*/
19641964
final Instruction getPartial() { result = getPartialOperand().getDef() }
1965+
1966+
/**
1967+
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`.
1968+
*/
1969+
final predicate getUpdatedInterval(int startBit, int endBit) {
1970+
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
1971+
}
19651972
}
19661973

19671974
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Operand.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ class NonPhiMemoryOperand extends NonPhiOperand, MemoryOperand, NonPhiMemoryOper
328328
not Construction::isInCycle(useInstr) and
329329
strictcount(Construction::getMemoryOperandDefinition(useInstr, tag, _)) = 1
330330
}
331+
332+
/**
333+
* Holds if the operand totally overlaps with its definition and consumes the
334+
* bit range `[startBitOffset, endBitOffset)`.
335+
*/
336+
predicate getUsedInterval(int startBitOffset, int endBitOffset) {
337+
Construction::getUsedInterval(this, startBitOffset, endBitOffset)
338+
}
331339
}
332340

333341
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ Instruction getMemoryOperandDefinition(
182182
none()
183183
}
184184

185+
/**
186+
* Holds if the partial operand of this `ChiInstruction` updates the bit range
187+
* `[startBitOffset, endBitOffset)` of the total operand.
188+
*/
189+
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBit, int endBit) { none() }
190+
191+
/**
192+
* Holds if the operand totally overlaps with its definition and consumes the
193+
* bit range `[startBitOffset, endBitOffset)`.
194+
*/
195+
predicate getUsedInterval(Operand operand, int startBit, int endBit) { none() }
196+
185197
/** Gets a non-phi instruction that defines an operand of `instr`. */
186198
private Instruction getNonPhiOperandDef(Instruction instr) {
187199
result = getRegisterOperandDefinition(instr, _)

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,13 @@ class ChiInstruction extends Instruction {
19621962
* Gets the operand that represents the new value written by the memory write.
19631963
*/
19641964
final Instruction getPartial() { result = getPartialOperand().getDef() }
1965+
1966+
/**
1967+
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`.
1968+
*/
1969+
final predicate getUpdatedInterval(int startBit, int endBit) {
1970+
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
1971+
}
19651972
}
19661973

19671974
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Operand.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ class NonPhiMemoryOperand extends NonPhiOperand, MemoryOperand, NonPhiMemoryOper
328328
not Construction::isInCycle(useInstr) and
329329
strictcount(Construction::getMemoryOperandDefinition(useInstr, tag, _)) = 1
330330
}
331+
332+
/**
333+
* Holds if the operand totally overlaps with its definition and consumes the
334+
* bit range `[startBitOffset, endBitOffset)`.
335+
*/
336+
predicate getUsedInterval(int startBitOffset, int endBitOffset) {
337+
Construction::getUsedInterval(this, startBitOffset, endBitOffset)
338+
}
331339
}
332340

333341
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ private module Cached {
149149
)
150150
}
151151

152+
/**
153+
* Holds if the partial operand of this `ChiInstruction` updates the bit range
154+
* `[startBitOffset, endBitOffset)` of the total operand.
155+
*/
156+
cached
157+
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBitOffset, int endBitOffset) {
158+
exists(Alias::MemoryLocation location, OldInstruction oldInstruction |
159+
oldInstruction = getOldInstruction(chi.getPartial()) and
160+
location = Alias::getResultMemoryLocation(oldInstruction) and
161+
startBitOffset = Alias::getStartBitOffset(location) and
162+
endBitOffset = Alias::getEndBitOffset(location)
163+
)
164+
}
165+
166+
/**
167+
* Holds if `operand` totally overlaps with its definition and consumes the bit range
168+
* `[startBitOffset, endBitOffset)`.
169+
*/
170+
cached
171+
predicate getUsedInterval(NonPhiMemoryOperand operand, int startBitOffset, int endBitOffset) {
172+
exists(Alias::MemoryLocation location, OldIR::NonPhiMemoryOperand oldOperand |
173+
oldOperand = operand.getUse().(OldInstruction).getAnOperand() and
174+
location = Alias::getOperandMemoryLocation(oldOperand) and
175+
startBitOffset = Alias::getStartBitOffset(location) and
176+
endBitOffset = Alias::getEndBitOffset(location)
177+
)
178+
}
179+
152180
/**
153181
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
154182
* through a phi instruction and therefore should be impossible.

0 commit comments

Comments
 (0)