mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Ruby: Ssa::WriteDefinition::getWriteAccess should return a CFG node
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
// This is an implementation of the Rubocop rule
|
||||
// https://github.com/rubocop/rubocop-performance/blob/master/lib/rubocop/cop/performance/detect.rb
|
||||
import codeql.ruby.AST
|
||||
import codeql.ruby.CFG
|
||||
import codeql.ruby.dataflow.SSA
|
||||
|
||||
/** A call that extracts the first or last element of a list. */
|
||||
@@ -41,12 +42,12 @@ class EndCall extends MethodCall {
|
||||
}
|
||||
|
||||
Expr getUniqueRead(Expr e) {
|
||||
exists(AssignExpr ae |
|
||||
e = ae.getRightOperand() and
|
||||
forex(Ssa::WriteDefinition def | def.getWriteAccess() = ae.getLeftOperand() |
|
||||
forex(CfgNode eNode | eNode.getNode() = e |
|
||||
exists(Ssa::WriteDefinition def |
|
||||
def.assigns(eNode) and
|
||||
strictcount(def.getARead()) = 1 and
|
||||
not def = any(Ssa::PhiNode phi).getAnInput() and
|
||||
def.getARead() = result.getAControlFlowNode()
|
||||
def.getARead().getNode() = result
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ newtype DefLoc =
|
||||
/** A local variable. */
|
||||
LocalVariableLoc(VariableReadAccess read, VariableWriteAccess write) {
|
||||
exists(Ssa::WriteDefinition w |
|
||||
write = w.getWriteAccess() and
|
||||
write = w.getWriteAccess().getNode() and
|
||||
read = w.getARead().getExpr() and
|
||||
not read.isSynthesized()
|
||||
)
|
||||
|
||||
@@ -24,5 +24,5 @@ from RelevantLocalVariableWriteAccess write, LocalVariable v
|
||||
where
|
||||
v = write.getVariable() and
|
||||
exists(write.getAControlFlowNode()) and
|
||||
not exists(Ssa::WriteDefinition def | def.getWriteAccess() = write)
|
||||
not exists(Ssa::WriteDefinition def | def.getWriteAccess().getNode() = write)
|
||||
select write, "This assignment to $@ is useless, since its value is never read.", v, v.getName()
|
||||
|
||||
@@ -23,5 +23,5 @@ class RelevantParameterVariable extends LocalVariable {
|
||||
}
|
||||
|
||||
from RelevantParameterVariable v
|
||||
where not exists(Ssa::WriteDefinition def | def.getWriteAccess() = v.getDefiningAccess())
|
||||
where not exists(Ssa::WriteDefinition def | def.getWriteAccess().getNode() = v.getDefiningAccess())
|
||||
select v, "The parameter '" + v.getName() + "' is never used."
|
||||
|
||||
Reference in New Issue
Block a user