Skip to content

Commit 6ba1d2e

Browse files
committed
C++: Replace DefinitionExt usage with Definition.
1 parent 9375e57 commit 6ba1d2e

File tree

2 files changed

+14
-90
lines changed

2 files changed

+14
-90
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,14 +1764,14 @@ module IteratorFlow {
17641764
* Note: Unlike `def.getAnUltimateDefinition()` this predicate also
17651765
* traverses back through iterator increment and decrement operations.
17661766
*/
1767-
private Ssa::DefinitionExt getAnUltimateDefinition(Ssa::DefinitionExt def) {
1767+
private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
17681768
result = def.getAnUltimateDefinition()
17691769
or
17701770
exists(IRBlock bb, int i, IteratorCrementCall crementCall, Ssa::SourceVariable sv |
17711771
crementCall = def.getValue().asInstruction().(StoreInstruction).getSourceValue() and
17721772
sv = def.getSourceVariable() and
17731773
bb.getInstruction(i) = crementCall and
1774-
Ssa::ssaDefReachesReadExt(sv, result, bb, i)
1774+
Ssa::ssaDefReachesRead(sv, result, bb, i)
17751775
)
17761776
}
17771777

@@ -1799,13 +1799,13 @@ module IteratorFlow {
17991799
GetsIteratorCall beginCall, Instruction writeToDeref
18001800
) {
18011801
exists(
1802-
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::DefinitionExt def,
1803-
IteratorPointerDereferenceCall starCall, Ssa::DefinitionExt ultimate, Operand address
1802+
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::Definition def,
1803+
IteratorPointerDereferenceCall starCall, Ssa::Definition ultimate, Operand address
18041804
|
18051805
isIteratorWrite(writeToDeref, address) and
18061806
operandForFullyConvertedCall(address, starCall) and
18071807
bbStar.getInstruction(iStar) = starCall and
1808-
Ssa::ssaDefReachesReadExt(_, def, bbStar, iStar) and
1808+
Ssa::ssaDefReachesRead(_, def, bbStar, iStar) and
18091809
ultimate = getAnUltimateDefinition*(def) and
18101810
beginStore = ultimate.getValue().asInstruction() and
18111811
operandForFullyConvertedCall(beginStore.getSourceValueOperand(), beginCall)

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 9 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -926,30 +926,14 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
926926
*/
927927
cached
928928
module SsaCached {
929-
/**
930-
* Holds if the node at index `i` in `bb` is a last reference to SSA definition
931-
* `def`. The reference is last because it can reach another write `next`,
932-
* without passing through another read or write.
933-
*
934-
* The path from node `i` in `bb` to `next` goes via basic block `input`,
935-
* which is either a predecessor of the basic block of `next`, or `input` =
936-
* `bb` in case `next` occurs in basic block `bb`.
937-
*/
938-
cached
939-
predicate lastRefRedefExt(
940-
DefinitionExt def, SourceVariable sv, IRBlock bb, int i, IRBlock input, DefinitionExt next
941-
) {
942-
SsaImpl::lastRefRedefExt(def, sv, bb, i, input, next)
943-
}
944-
945929
cached
946-
predicate ssaDefReachesReadExt(SourceVariable v, DefinitionExt def, IRBlock bb, int i) {
947-
SsaImpl::ssaDefReachesReadExt(v, def, bb, i)
930+
predicate ssaDefReachesRead(SourceVariable v, Definition def, IRBlock bb, int i) {
931+
SsaImpl::ssaDefReachesRead(v, def, bb, i)
948932
}
949933

950934
cached
951-
predicate ssaDefReachesRead(SourceVariable v, Definition def, IRBlock bb, int i) {
952-
SsaImpl::ssaDefReachesRead(v, def, bb, i)
935+
predicate phiHasInputFromBlock(PhiNode phi, Definition inp, IRBlock bb) {
936+
SsaImpl::phiHasInputFromBlock(phi, inp, bb)
953937
}
954938

955939
predicate variableRead = SsaInput::variableRead/4;
@@ -1102,77 +1086,17 @@ predicate ssaFlow(Node nodeFrom, Node nodeTo) {
11021086

11031087
/**
11041088
* An static single assignment (SSA) phi node.
1105-
*
1106-
* This is either a normal phi node or a phi-read node.
11071089
*/
1108-
class PhiNode extends SsaImpl::DefinitionExt {
1109-
PhiNode() {
1110-
this instanceof SsaImpl::PhiNode or
1111-
this instanceof SsaImpl::PhiReadNode
1112-
}
1113-
1114-
/**
1115-
* Holds if this phi node is a phi-read node.
1116-
*
1117-
* Phi-read nodes are like normal phi nodes, but they are inserted based
1118-
* on reads instead of writes.
1119-
*/
1120-
predicate isPhiRead() { this instanceof SsaImpl::PhiReadNode }
1121-
1122-
/**
1123-
* Holds if the node at index `i` in `bb` is a last reference to SSA
1124-
* definition `def` of `sv`. The reference is last because it can reach
1125-
* this phi node, without passing through another read or write.
1126-
*
1127-
* The path from node `i` in `bb` to this phi node goes via basic block
1128-
* `input`, which is either a predecessor of the basic block of this phi
1129-
* node, or `input` = `bb` in case this phi node occurs in basic block `bb`.
1130-
*/
1131-
predicate hasInputFromBlock(DefinitionExt def, SourceVariable sv, IRBlock bb, int i, IRBlock input) {
1132-
SsaCached::lastRefRedefExt(def, sv, bb, i, input, this)
1133-
}
1134-
1090+
class PhiNode extends Definition instanceof SsaImpl::PhiNode {
11351091
/** Gets a definition that is an input to this phi node. */
1136-
final DefinitionExt getAnInput() { this.hasInputFromBlock(result, _, _, _, _) }
1092+
final Definition getAnInput() { phiHasInputFromBlock(this, result, _) }
11371093
}
11381094

11391095
/** An static single assignment (SSA) definition. */
11401096
class Definition extends SsaImpl::Definition {
1141-
/**
1142-
* INTERNAL: Do not use.
1143-
*/
1144-
Node0Impl getValue() { result = getDefImpl(this).getValue() }
1145-
1146-
/** Gets the indirection index of this definition. */
1147-
int getIndirectionIndex() { result = getDefImpl(this).getIndirectionIndex() }
1148-
1149-
/** Gets the indirection of this definition. */
1150-
int getIndirection() { result = getDefImpl(this).getIndirection() }
1151-
1152-
/**
1153-
* Holds if this definition is guaranteed to totally overwrite the buffer
1154-
* being written to.
1155-
*/
1156-
predicate isCertain() { getDefImpl(this).isCertain() }
1157-
1158-
/**
1159-
* Gets the enclosing declaration of this definition.
1160-
*
1161-
* Note that this may be a variable when this definition defines a global, or
1162-
* a static local, variable.
1163-
*/
1164-
Declaration getFunction() { result = getDefImpl(this).getBlock().getEnclosingFunction() }
1165-
1166-
/** Gets the underlying type of the variable being defined by this definition. */
1167-
Type getUnderlyingType() { result = this.getSourceVariable().getType() }
1168-
1169-
/** Gets the unspecified type of the variable being defined by this definition. */
1170-
Type getUnspecifiedType() { result = this.getUnderlyingType().getUnspecifiedType() }
1171-
}
1172-
1173-
/** An static single assignment (SSA) definition. */
1174-
class DefinitionExt extends SsaImpl::DefinitionExt {
1175-
private DefinitionExt getAPhiInputOrPriorDefinition() { result = this.(PhiNode).getAnInput() }
1097+
// TODO: Include prior definitions of uncertain writes or rename predicate
1098+
// i.e. the disjunct `SsaImpl::uncertainWriteDefinitionInput(this, result)`
1099+
private Definition getAPhiInputOrPriorDefinition() { result = this.(PhiNode).getAnInput() }
11761100

11771101
/**
11781102
* Gets a definition that ultimately defines this SSA definition and is

0 commit comments

Comments
 (0)