Rust: Switch test to use dedicated test module.

This commit is contained in:
Anders Schack-Mulligen
2025-02-26 12:55:54 +01:00
parent 122034fe8c
commit 8474a47c2b
3 changed files with 16 additions and 17 deletions

View File

@@ -100,12 +100,6 @@ class PhiDefinition = Impl::PhiNode;
module Consistency = Impl::Consistency;
module ExposedForTestingOnly {
predicate ssaDefReachesReadExt = Impl::ssaDefReachesReadExt/4;
predicate phiHasInputFromBlockExt = Impl::phiHasInputFromBlockExt/3;
}
/** Holds if `v` is read at index `i` in basic block `bb`. */
private predicate variableReadActual(BasicBlock bb, int i, Variable v) {
exists(VariableAccess read |

View File

@@ -535,14 +535,15 @@ phi
phiReadNode
| main.rs:104:11:105:12 | SSA phi read(s1) | main.rs:102:9:102:10 | s1 |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:492:9:492:9 | x |
phiReadNodeRead
phiReadNodeFirstRead
| main.rs:104:11:105:12 | SSA phi read(s1) | main.rs:102:9:102:10 | s1 | main.rs:105:11:105:12 | s1 |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:492:9:492:9 | x | main.rs:500:19:500:19 | x |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:492:9:492:9 | x | main.rs:502:19:502:19 | x |
phiReadInput
| main.rs:104:11:105:12 | SSA phi read(s1) | main.rs:102:9:102:10 | s1 |
| main.rs:104:11:105:12 | SSA phi read(s1) | main.rs:104:11:105:12 | SSA phi read(s1) |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:492:9:492:9 | x |
| main.rs:104:11:105:12 | SSA phi read(s1) | main.rs:105:11:105:12 | SSA read(s1) |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:494:19:494:19 | SSA read(x) |
| main.rs:493:5:497:5 | SSA phi read(x) | main.rs:496:19:496:19 | SSA read(x) |
ultimateDef
| main.rs:191:9:191:44 | phi | main.rs:191:22:191:23 | a3 |
| main.rs:191:9:191:44 | phi | main.rs:191:42:191:43 | a3 |

View File

@@ -3,7 +3,7 @@ import codeql.rust.controlflow.BasicBlocks
import codeql.rust.controlflow.ControlFlowGraph
import codeql.rust.dataflow.Ssa
import codeql.rust.dataflow.internal.SsaImpl
import ExposedForTestingOnly
import Impl::TestAdjacentRefs as RefTest
query predicate definition(Ssa::Definition def, Variable v) { def.getSourceVariable() = v }
@@ -24,18 +24,22 @@ query predicate phi(Ssa::PhiDefinition phi, Variable v, Ssa::Definition input) {
phi.getSourceVariable() = v and input = phi.getAnInput()
}
query predicate phiReadNode(PhiReadNode phi, Variable v) { phi.getSourceVariable() = v }
query predicate phiReadNode(RefTest::Ref phi, Variable v) {
phi.isPhiRead() and phi.getSourceVariable() = v
}
query predicate phiReadNodeRead(PhiReadNode phi, Variable v, CfgNode read) {
phi.getSourceVariable() = v and
exists(BasicBlock bb, int i |
ssaDefReachesReadExt(v, phi, bb, i) and
query predicate phiReadNodeFirstRead(RefTest::Ref phi, Variable v, CfgNode read) {
exists(RefTest::Ref r, BasicBlock bb, int i |
phi.isPhiRead() and
RefTest::adjacentRefRead(phi, r) and
r.accessAt(bb, i, v) and
read = bb.getNode(i)
)
}
query predicate phiReadInput(PhiReadNode phi, DefinitionExt inp) {
phiHasInputFromBlockExt(phi, inp, _)
query predicate phiReadInput(RefTest::Ref phi, RefTest::Ref inp) {
phi.isPhiRead() and
RefTest::adjacentRefPhi(inp, phi)
}
query predicate ultimateDef(Ssa::Definition def, Definition ult) {