Java/C++: Share ssaUpdateStep.

This commit is contained in:
Anders Schack-Mulligen
2023-11-09 15:56:17 +01:00
parent daffae020b
commit b8e7e1d15e
6 changed files with 31 additions and 49 deletions

View File

@@ -30,7 +30,7 @@ module ModulusAnalysis<
*/
pragma[nomagic]
private predicate valueFlowStepSsa(Sem::SsaVariable v, SsaReadPosition pos, Sem::Expr e, int delta) {
U::semSsaUpdateStep(v, e, D::fromInt(delta)) and pos.hasReadOfVar(v)
ssaUpdateStep(v, e, D::fromInt(delta)) and pos.hasReadOfVar(v)
or
exists(Sem::Guard guard, boolean testIsTrue |
hasReadOfVarInlineLate(pos, v) and

View File

@@ -304,8 +304,6 @@ signature module LangSig<Semantic Sem, DeltaSig D> {
}
signature module UtilSig<Semantic Sem, DeltaSig DeltaParam> {
predicate semSsaUpdateStep(Sem::SsaExplicitUpdate v, Sem::Expr e, DeltaParam::Delta delta);
predicate semValueFlowStep(Sem::Expr e2, Sem::Expr e1, DeltaParam::Delta delta);
/**
@@ -671,7 +669,7 @@ module RangeStage<
Sem::SsaVariable v, SsaReadPosition pos, Sem::Expr e, D::Delta delta, boolean upper,
SemReason reason
) {
semSsaUpdateStep(v, e, delta) and
ssaUpdateStep(v, e, delta) and
pos.hasReadOfVar(v) and
(upper = true or upper = false) and
reason = TSemNoReason()

View File

@@ -57,6 +57,33 @@ module MakeUtils<Semantic Lang, DeltaSig D> {
)
}
/**
* Holds if `v` is an `SsaExplicitUpdate` that equals `e + delta`.
*/
predicate ssaUpdateStep(SsaExplicitUpdate v, Expr e, D::Delta delta) {
exists(Expr defExpr | defExpr = v.getDefiningExpr() |
defExpr.(CopyValueExpr).getOperand() = e and delta = D::fromFloat(0)
or
defExpr.(PostIncExpr).getOperand() = e and delta = D::fromFloat(1)
or
defExpr.(PreIncExpr).getOperand() = e and delta = D::fromFloat(1)
or
defExpr.(PostDecExpr).getOperand() = e and delta = D::fromFloat(-1)
or
defExpr.(PreDecExpr).getOperand() = e and delta = D::fromFloat(-1)
or
e = defExpr and
not (
defExpr instanceof CopyValueExpr or
defExpr instanceof PostIncExpr or
defExpr instanceof PreIncExpr or
defExpr instanceof PostDecExpr or
defExpr instanceof PreDecExpr
) and
delta = D::fromFloat(0)
)
}
private newtype TSsaReadPosition =
TSsaReadPositionBlock(BasicBlock bb) {
exists(SsaVariable v | v.getAUse().getBasicBlock() = bb)