Skip to content

Commit 6f72234

Browse files
authored
Merge pull request #20680 from aschackmull/shared/align-ssa-interface
Shared: Align SSA interfaces in Guards and ControlFlowReachability with shared SSA
2 parents d11b445 + 72d83cc commit 6f72234

File tree

7 files changed

+77
-71
lines changed

7 files changed

+77
-71
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,20 @@ private module LogicInput_v1 implements GuardsImpl::LogicInputSig {
380380
GuardsInput::Expr getARead() { result = this.getAUse().getDef() }
381381
}
382382

383-
class SsaWriteDefinition extends SsaDefinition instanceof ExplicitDefinition {
384-
GuardsInput::Expr getDefinition() { result = super.getAssignedInstruction() }
383+
class SsaExplicitWrite extends SsaDefinition instanceof ExplicitDefinition {
384+
GuardsInput::Expr getValue() { result = super.getAssignedInstruction() }
385385
}
386386

387-
class SsaPhiNode extends SsaDefinition instanceof PhiNode {
387+
class SsaPhiDefinition extends SsaDefinition instanceof PhiNode {
388388
predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb) {
389389
super.hasInputFromBlock(inp, bb)
390390
}
391391
}
392392

393-
predicate parameterDefinition(GuardsInput::Parameter p, SsaDefinition def) {
394-
def.isParameterDefinition(p)
393+
class SsaParameterInit extends SsaDefinition {
394+
SsaParameterInit() { this.isParameterDefinition(_) }
395+
396+
GuardsInput::Parameter getParameter() { this.isParameterDefinition(result) }
395397
}
396398

397399
predicate additionalImpliesStep(

csharp/ql/lib/semmle/code/csharp/controlflow/ControlFlowReachability.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ private module ControlFlowInput implements
3333

3434
class SsaDefinition = Ssa::Definition;
3535

36-
class SsaWriteDefinition extends SsaDefinition instanceof Ssa::ExplicitDefinition {
37-
Expr getDefinition() { result = super.getADefinition().getSource() }
36+
class SsaExplicitWrite extends SsaDefinition instanceof Ssa::ExplicitDefinition {
37+
Expr getValue() { result = super.getADefinition().getSource() }
3838
}
3939

40-
class SsaPhiNode = Ssa::PhiNode;
40+
class SsaPhiDefinition = Ssa::PhiNode;
4141

42-
class SsaUncertainDefinition = Ssa::UncertainDefinition;
42+
class SsaUncertainWrite = Ssa::UncertainDefinition;
4343

4444
class GuardValue = Guards::GuardValue;
4545

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,18 @@ private module LogicInput implements GuardsImpl::LogicInputSig {
207207
Expr getARead() { super.getARead() = result }
208208
}
209209

210-
class SsaWriteDefinition extends SsaDefinition instanceof Ssa::ExplicitDefinition {
211-
Expr getDefinition() { result = super.getADefinition().getSource() }
210+
class SsaExplicitWrite extends SsaDefinition instanceof Ssa::ExplicitDefinition {
211+
Expr getValue() { result = super.getADefinition().getSource() }
212212
}
213213

214-
class SsaPhiNode extends SsaDefinition instanceof Ssa::PhiNode {
214+
class SsaPhiDefinition extends SsaDefinition instanceof Ssa::PhiNode {
215215
predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb) {
216216
super.hasInputFromBlock(inp, bb)
217217
}
218218
}
219219

220-
predicate parameterDefinition(Parameter p, SsaDefinition def) {
221-
def.(Ssa::ImplicitParameterDefinition).getParameter() = p
220+
class SsaParameterInit extends SsaDefinition instanceof Ssa::ImplicitParameterDefinition {
221+
Parameter getParameter() { result = super.getParameter() }
222222
}
223223

224224
predicate additionalNullCheck(GuardsImpl::PreGuard guard, GuardValue val, Expr e, boolean isNull) {

java/ql/lib/semmle/code/java/controlflow/ControlFlowReachability.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ private module ControlFlowInput implements InputSig<Location, ControlFlowNode, B
3131

3232
class SsaDefinition = SSA::SsaVariable;
3333

34-
class SsaWriteDefinition extends SsaDefinition instanceof SSA::SsaExplicitUpdate {
35-
Expr getDefinition() {
34+
class SsaExplicitWrite extends SsaDefinition instanceof SSA::SsaExplicitUpdate {
35+
Expr getValue() {
3636
super.getDefiningExpr().(VariableAssign).getSource() = result or
3737
super.getDefiningExpr().(AssignOp) = result
3838
}
3939
}
4040

41-
class SsaPhiNode = SSA::SsaPhiNode;
41+
class SsaPhiDefinition = SSA::SsaPhiNode;
4242

43-
class SsaUncertainDefinition extends SsaDefinition instanceof SSA::SsaUncertainImplicitUpdate {
43+
class SsaUncertainWrite extends SsaDefinition instanceof SSA::SsaUncertainImplicitUpdate {
4444
SsaDefinition getPriorDefinition() { result = super.getPriorDef() }
4545
}
4646

java/ql/lib/semmle/code/java/controlflow/Guards.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -415,21 +415,21 @@ private module LogicInput_v1 implements GuardsImpl::LogicInputSig {
415415
GuardsInput::Expr getARead() { result = this.getAUse() }
416416
}
417417

418-
class SsaWriteDefinition extends SsaDefinition instanceof BaseSsaUpdate {
419-
GuardsInput::Expr getDefinition() {
418+
class SsaExplicitWrite extends SsaDefinition instanceof BaseSsaUpdate {
419+
GuardsInput::Expr getValue() {
420420
super.getDefiningExpr().(VariableAssign).getSource() = result or
421421
super.getDefiningExpr().(AssignOp) = result
422422
}
423423
}
424424

425-
class SsaPhiNode extends SsaDefinition instanceof BaseSsaPhiNode {
425+
class SsaPhiDefinition extends SsaDefinition instanceof BaseSsaPhiNode {
426426
predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb) {
427427
super.hasInputFromBlock(inp, bb)
428428
}
429429
}
430430

431-
predicate parameterDefinition(Parameter p, SsaDefinition def) {
432-
def.(BaseSsaImplicitInit).isParameterDefinition(p)
431+
class SsaParameterInit extends SsaDefinition instanceof BaseSsaImplicitInit {
432+
Parameter getParameter() { super.isParameterDefinition(result) }
433433
}
434434

435435
predicate additionalNullCheck = LogicInputCommon::additionalNullCheck/4;
@@ -446,21 +446,21 @@ private module LogicInput_v2 implements GuardsImpl::LogicInputSig {
446446
GuardsInput::Expr getARead() { result = this.getAUse() }
447447
}
448448

449-
class SsaWriteDefinition extends SsaDefinition instanceof SSA::SsaExplicitUpdate {
450-
GuardsInput::Expr getDefinition() {
449+
class SsaExplicitWrite extends SsaDefinition instanceof SSA::SsaExplicitUpdate {
450+
GuardsInput::Expr getValue() {
451451
super.getDefiningExpr().(VariableAssign).getSource() = result or
452452
super.getDefiningExpr().(AssignOp) = result
453453
}
454454
}
455455

456-
class SsaPhiNode extends SsaDefinition instanceof SSA::SsaPhiNode {
456+
class SsaPhiDefinition extends SsaDefinition instanceof SSA::SsaPhiNode {
457457
predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb) {
458458
super.hasInputFromBlock(inp, bb)
459459
}
460460
}
461461

462-
predicate parameterDefinition(Parameter p, SsaDefinition def) {
463-
def.(SSA::SsaImplicitInit).isParameterDefinition(p)
462+
class SsaParameterInit extends SsaDefinition instanceof SSA::SsaImplicitInit {
463+
Parameter getParameter() { super.isParameterDefinition(result) }
464464
}
465465

466466
predicate additionalNullCheck = LogicInputCommon::additionalNullCheck/4;

shared/controlflow/codeql/controlflow/ControlFlowReachability.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ signature module InputSig<LocationSig Location, TypSig ControlFlowNode, TypSig B
5656
predicate isLiveAtEndOfBlock(BasicBlock b);
5757
}
5858

59-
class SsaWriteDefinition extends SsaDefinition {
60-
Expr getDefinition();
59+
class SsaExplicitWrite extends SsaDefinition {
60+
Expr getValue();
6161
}
6262

63-
class SsaPhiNode extends SsaDefinition {
63+
class SsaPhiDefinition extends SsaDefinition {
6464
/** Holds if `inp` is an input to the phi node along the edge originating in `bb`. */
6565
predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb);
6666

6767
SsaDefinition getAnInput();
6868
}
6969

70-
class SsaUncertainDefinition extends SsaDefinition {
70+
class SsaUncertainWrite extends SsaDefinition {
7171
/**
7272
* Gets the immediately preceding definition. Since this update is uncertain,
7373
* the value from the preceding definition might still be valid.
@@ -274,9 +274,9 @@ module Make<
274274
* If multiple values apply, including a singleton, then we only include the
275275
* singleton.
276276
*/
277-
private predicate ssaHasValue(SsaWriteDefinition def, GuardValue gv) {
277+
private predicate ssaHasValue(SsaExplicitWrite def, GuardValue gv) {
278278
exists(Expr e |
279-
def.getDefinition() = e and
279+
def.getValue() = e and
280280
exprHasValue(e, gv) and
281281
(any(GuardValue gv0 | exprHasValue(e, gv0)).isSingleton() implies gv.isSingleton())
282282
)
@@ -398,7 +398,7 @@ module Make<
398398
}
399399

400400
private predicate uncertainStep(SsaDefinition def1, SsaDefinition def2) {
401-
def2.(SsaUncertainDefinition).getPriorDefinition() = def1 and
401+
def2.(SsaUncertainWrite).getPriorDefinition() = def1 and
402402
Config::uncertainFlow()
403403
}
404404

@@ -459,7 +459,7 @@ module Make<
459459

460460
pragma[nomagic]
461461
private predicate phiBlock(BasicBlock bb, SourceVariable v) {
462-
exists(SsaPhiNode phi | phi.getBasicBlock() = bb and phi.getSourceVariable() = v)
462+
exists(SsaPhiDefinition phi | phi.getBasicBlock() = bb and phi.getSourceVariable() = v)
463463
}
464464

465465
/** Holds if `def1` in `bb1` may step to `def2` in `bb2`. */
@@ -468,7 +468,7 @@ module Make<
468468
not Config::barrierEdge(bb1, bb2) and
469469
not ssaValueBarrierEdge(def1, bb1, bb2) and
470470
(
471-
def2.(SsaPhiNode).hasInputFromBlock(def1, bb1) and bb2 = def2.getBasicBlock()
471+
def2.(SsaPhiDefinition).hasInputFromBlock(def1, bb1) and bb2 = def2.getBasicBlock()
472472
or
473473
exists(SourceVariable v |
474474
ssaRelevantAtEndOfBlock(def1, bb1) and
@@ -661,10 +661,10 @@ module Make<
661661
|
662662
def.getBasicBlock().dominates(loopEntry)
663663
or
664-
exists(SsaPhiNode phi |
664+
exists(SsaPhiDefinition phi |
665665
phi.definesAt(var, loopEntry, _) and
666666
phi.getAnInput+() = def and
667-
def.(SsaPhiNode).getAnInput*() = phi
667+
def.(SsaPhiDefinition).getAnInput*() = phi
668668
)
669669
)
670670
}
@@ -703,7 +703,7 @@ module Make<
703703
pathEdge(src, bb1, bb2) and
704704
relevantSplit(src, var, condgv) and
705705
lastDefInBlock(var, t, bb2) and
706-
not t instanceof SsaPhiNode and
706+
not t instanceof SsaPhiDefinition and
707707
(
708708
exists(GuardValue gv |
709709
ssaHasValue(t, gv) and
@@ -730,7 +730,7 @@ module Make<
730730
pathEdge(src, bb1, bb2) and
731731
relevantSplit(src, var, condgv) and
732732
lastDefInBlock(var, t2, bb2) and
733-
t2.(SsaPhiNode).hasInputFromBlock(t1, bb1) and
733+
t2.(SsaPhiDefinition).hasInputFromBlock(t1, bb1) and
734734
(
735735
exists(GuardValue gv |
736736
ssaControlsPathEdge(src, t1, _, gv, bb1, bb2) and

0 commit comments

Comments
 (0)