mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #8859 from tausbn/python-fix-bad-essa-joins
Python: Fix a bunch of bad joins
This commit is contained in:
@@ -498,13 +498,13 @@ private EssaVariable potential_input(EssaNodeRefinement ref) {
|
||||
|
||||
/** An assignment to a variable `v = val` */
|
||||
class AssignmentDefinition extends EssaNodeDefinition {
|
||||
ControlFlowNode value;
|
||||
|
||||
AssignmentDefinition() {
|
||||
SsaSource::assignment_definition(this.getSourceVariable(), this.getDefiningNode(), _)
|
||||
SsaSource::assignment_definition(this.getSourceVariable(), this.getDefiningNode(), value)
|
||||
}
|
||||
|
||||
ControlFlowNode getValue() {
|
||||
SsaSource::assignment_definition(this.getSourceVariable(), this.getDefiningNode(), result)
|
||||
}
|
||||
ControlFlowNode getValue() { result = value }
|
||||
|
||||
override string getRepresentation() { result = this.getValue().getNode().toString() }
|
||||
|
||||
|
||||
@@ -496,8 +496,8 @@ private module SsaComputeImpl {
|
||||
predicate firstUse(EssaDefinition def, ControlFlowNode use) {
|
||||
exists(SsaSourceVariable v, BasicBlock b1, int i1, BasicBlock b2, int i2 |
|
||||
adjacentVarRefs(v, b1, i1, b2, i2) and
|
||||
definesAt(def, v, b1, i1) and
|
||||
variableSourceUse(v, use, b2, i2)
|
||||
definesAt(def, pragma[only_bind_into](v), b1, i1) and
|
||||
variableSourceUse(pragma[only_bind_into](v), use, b2, i2)
|
||||
)
|
||||
or
|
||||
exists(
|
||||
|
||||
@@ -10,36 +10,30 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import semmle.python.dataflow.new.DataFlow
|
||||
import semmle.python.ApiGraphs
|
||||
|
||||
predicate squareOp(BinaryExpr e) {
|
||||
e.getOp() instanceof Pow and e.getRight().(IntegerLiteral).getN() = "2"
|
||||
}
|
||||
|
||||
predicate squareMul(BinaryExpr e) {
|
||||
e.getOp() instanceof Mult and e.getRight().(Name).getId() = e.getLeft().(Name).getId()
|
||||
}
|
||||
|
||||
predicate squareRef(Name e) {
|
||||
e.isUse() and
|
||||
exists(SsaVariable v, Expr s | v.getVariable() = e.getVariable() |
|
||||
s = v.getDefinition().getNode().getParentNode().(AssignStmt).getValue() and
|
||||
square(s)
|
||||
DataFlow::ExprNode squareOp() {
|
||||
exists(BinaryExpr e | e = result.asExpr() |
|
||||
e.getOp() instanceof Pow and e.getRight().(IntegerLiteral).getN() = "2"
|
||||
)
|
||||
}
|
||||
|
||||
predicate square(Expr e) {
|
||||
squareOp(e)
|
||||
or
|
||||
squareMul(e)
|
||||
or
|
||||
squareRef(e)
|
||||
DataFlow::ExprNode squareMul() {
|
||||
exists(BinaryExpr e | e = result.asExpr() |
|
||||
e.getOp() instanceof Mult and e.getRight().(Name).getId() = e.getLeft().(Name).getId()
|
||||
)
|
||||
}
|
||||
|
||||
from Call c, BinaryExpr s
|
||||
DataFlow::ExprNode square() { result in [squareOp(), squareMul()] }
|
||||
|
||||
from DataFlow::CallCfgNode c, BinaryExpr s, DataFlow::ExprNode left, DataFlow::ExprNode right
|
||||
where
|
||||
c.getFunc().toString() = "sqrt" and
|
||||
c.getArg(0) = s and
|
||||
c = API::moduleImport("math").getMember("sqrt").getACall() and
|
||||
c.getArg(0).asExpr() = s and
|
||||
s.getOp() instanceof Add and
|
||||
square(s.getLeft()) and
|
||||
square(s.getRight())
|
||||
left.asExpr() = s.getLeft() and
|
||||
right.asExpr() = s.getRight() and
|
||||
left.getALocalSource() = square() and
|
||||
right.getALocalSource() = square()
|
||||
select c, "Pythagorean calculation with sub-optimal numerics"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
| pythagorean_test.py:6:12:6:28 | sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
| pythagorean_test.py:9:12:9:26 | sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
| pythagorean_test.py:14:12:14:24 | sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
| pythagorean_test.py:6:12:6:28 | ControlFlowNode for sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
| pythagorean_test.py:9:12:9:26 | ControlFlowNode for sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
| pythagorean_test.py:14:12:14:24 | ControlFlowNode for sqrt() | Pythagorean calculation with sub-optimal numerics |
|
||||
|
||||
Reference in New Issue
Block a user