Skip to content

Ssa: Deprecate the unused getALastRead predicate. #18729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,4 @@ module InputSigCommon {
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { this.getLastInstruction() instanceof ExitFunctionInstruction }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module PreSsa {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock {
private class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { scopeLast(_, this.getLastElement(), _) }
}

Expand Down
4 changes: 2 additions & 2 deletions csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ module Ssa {
* - The read of `this.Field` on line 11 is a last read of the phi node
* between lines 9 and 10.
*/
final AssignableRead getALastRead() { result = this.getALastReadAtNode(_) }
deprecated final AssignableRead getALastRead() { result = this.getALastReadAtNode(_) }

/**
* Gets a last read of the source variable underlying this SSA definition at
Expand Down Expand Up @@ -375,7 +375,7 @@ module Ssa {
* - The read of `this.Field` on line 11 is a last read of the phi node
* between lines 9 and 10.
*/
final AssignableRead getALastReadAtNode(ControlFlow::Node cfn) {
deprecated final AssignableRead getALastReadAtNode(ControlFlow::Node cfn) {
SsaImpl::lastReadSameVar(this, cfn) and
result.getAControlFlowNode() = cfn
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ module BaseSsa {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }

class SourceVariable = PreSsa::SimpleLocalScopeVariable;

predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
Expand Down
24 changes: 12 additions & 12 deletions csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }

class SourceVariable = Ssa::SourceVariable;

/**
Expand Down Expand Up @@ -784,7 +782,9 @@ private predicate adjacentDefReachesUncertainRead(

/** Same as `lastRefRedef`, but skips uncertain reads. */
pragma[nomagic]
private predicate lastRefSkipUncertainReads(Definition def, SsaInput::BasicBlock bb, int i) {
deprecated private predicate lastRefSkipUncertainReads(
Definition def, SsaInput::BasicBlock bb, int i
) {
Impl::lastRef(def, bb, i) and
not SsaInput::variableRead(bb, i, def.getSourceVariable(), false)
or
Expand All @@ -794,6 +794,15 @@ private predicate lastRefSkipUncertainReads(Definition def, SsaInput::BasicBlock
)
}

pragma[nomagic]
deprecated predicate lastReadSameVar(Definition def, ControlFlow::Node cfn) {
exists(ControlFlow::BasicBlock bb, int i |
lastRefSkipUncertainReads(def, bb, i) and
variableReadActual(bb, i, _) and
cfn = bb.getNode(i)
)
}

cached
private module Cached {
cached
Expand Down Expand Up @@ -957,15 +966,6 @@ private module Cached {
)
}

cached
predicate lastReadSameVar(Definition def, ControlFlow::Node cfn) {
exists(ControlFlow::BasicBlock bb, int i |
lastRefSkipUncertainReads(def, bb, i) and
variableReadActual(bb, i, _) and
cfn = bb.getNode(i)
)
}

cached
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to replace this with pragma[nomagic]; I highly doubt anyone actually calls this.

Definition uncertainWriteDefinitionInput(UncertainWriteDefinition def) {
Impl::uncertainWriteDefinitionInput(def, result)
Expand Down
259 changes: 0 additions & 259 deletions csharp/ql/test/library-tests/dataflow/ssa/SsaDefLastRead.expected

This file was deleted.

5 changes: 0 additions & 5 deletions csharp/ql/test/library-tests/dataflow/ssa/SsaDefLastRead.ql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ module VariableCaptureConfig implements InputSig<js::DbLocation> {
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }

predicate entryBlock(BasicBlock bb) { bb instanceof js::EntryBasicBlock }

predicate exitBlock(BasicBlock bb) { bb.getLastNode() instanceof js::ControlFlowExitNode }
}

module VariableCaptureOutput = Flow<js::DbLocation, VariableCaptureConfig>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ module SsaConfig implements InputSig<js::DbLocation> {

class BasicBlock = js::BasicBlock;

class ExitBasicBlock extends BasicBlock {
ExitBasicBlock() { this.isExitBlock() }
}

class SourceVariable extends LocalVariableOrThis {
SourceVariable() { not this.isCaptured() }
}
Expand Down
2 changes: 1 addition & 1 deletion ruby/ql/lib/codeql/ruby/dataflow/SSA.qll
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module Ssa {
* end
* ```
*/
final VariableReadAccessCfgNode getALastRead() { SsaImpl::lastRead(this, result) }
deprecated final VariableReadAccessCfgNode getALastRead() { SsaImpl::lastRead(this, result) }

/**
* Holds if `read1` and `read2` are adjacent reads of this SSA definition.
Expand Down
34 changes: 17 additions & 17 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

class ExitBasicBlock extends BasicBlock, BasicBlocks::ExitBasicBlock { }

class SourceVariable = LocalVariable;

/**
Expand Down Expand Up @@ -292,7 +290,9 @@

/** Same as `lastRefRedef`, but skips uncertain reads. */
pragma[nomagic]
private predicate lastRefSkipUncertainReadsExt(DefinitionExt def, SsaInput::BasicBlock bb, int i) {
deprecated private predicate lastRefSkipUncertainReadsExt(

Check warning

Code scanning / CodeQL

Missing QLDoc for parameter Warning

The QLDoc has no documentation for bb, or def, or i, but the QLDoc mentions lastRefRedef
DefinitionExt def, SsaInput::BasicBlock bb, int i
) {
Impl::lastRef(def, bb, i) and
not SsaInput::variableRead(bb, i, def.getSourceVariable(), false)
or
Expand All @@ -302,6 +302,20 @@
)
}

/**
* Holds if the read of `def` at `read` may be a last read. That is, `read`
* can either reach another definition of the underlying source variable or
* the end of the CFG scope, without passing through another non-pseudo read.
*/
pragma[nomagic]
deprecated predicate lastRead(Definition def, VariableReadAccessCfgNode read) {
exists(Cfg::BasicBlock bb, int i |
lastRefSkipUncertainReadsExt(def, bb, i) and
variableReadActual(bb, i, _) and
read = bb.getNode(i)
)
}

cached
private module Cached {
/**
Expand Down Expand Up @@ -401,20 +415,6 @@
)
}

/**
* Holds if the read of `def` at `read` may be a last read. That is, `read`
* can either reach another definition of the underlying source variable or
* the end of the CFG scope, without passing through another non-pseudo read.
*/
cached
predicate lastRead(Definition def, VariableReadAccessCfgNode read) {
exists(Cfg::BasicBlock bb, int i |
lastRefSkipUncertainReadsExt(def, bb, i) and
variableReadActual(bb, i, _) and
read = bb.getNode(i)
)
}

cached
Definition uncertainWriteDefinitionInput(UncertainWriteDefinition def) {
Impl::uncertainWriteDefinitionInput(def, result)
Expand Down
Loading
Loading