Skip to content

Commit fa09a99

Browse files
committed
Java: Fix RangeAnalysis/ModulusAnalysis.
1 parent 3c0aea1 commit fa09a99

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ module Sem implements Semantic<Location> {
220220

221221
int getBlockId1(BasicBlock bb) { idOf(bb, result) }
222222

223+
string getBlockId2(BasicBlock bb) { bb.getFirstNode().getIdTag() = result }
224+
223225
class Guard extends G::Guards_v2::Guard {
224226
Expr asExpr() { result = this }
225227
}

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SsaReadPositionSpecific.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ private predicate idOfAst(BB::ExprParent x, int y) = equivalenceRelation(id/2)(x
2323

2424
private predicate idOf(BasicBlock x, int y) { idOfAst(x.getFirstNode().getAstNode(), y) }
2525

26-
private int getId(BasicBlock bb) { idOf(bb, result) }
26+
private int getId1(BasicBlock bb) { idOf(bb, result) }
27+
28+
private string getId2(BasicBlock bb) { bb.getFirstNode().getIdTag() = result }
2729

2830
/**
2931
* Declarations to be exposed to users of SsaReadPositionCommon
@@ -39,7 +41,7 @@ module Public {
3941
rank[r](SsaReadPositionPhiInputEdge e |
4042
e.phiInput(phi, _)
4143
|
42-
e order by getId(e.getOrigBlock())
44+
e order by getId1(e.getOrigBlock()), getId2(e.getOrigBlock())
4345
)
4446
}
4547
}

shared/controlflow/codeql/controlflow/ControlFlowGraph.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,14 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
590590
/** Gets the AST node with which this control flow node is associated. */
591591
abstract AstNode getAstNode();
592592

593+
/**
594+
* INTERNAL: Do not use.
595+
*
596+
* Gets a tag such that the pair `(getAstNode(), getIdTag())` uniquely
597+
* identifies this node.
598+
*/
599+
abstract string getIdTag();
600+
593601
/** Gets a textual representation of this node. */
594602
abstract string toString();
595603

@@ -606,6 +614,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
606614

607615
override AstNode getAstNode() { result = n }
608616

617+
override string getIdTag() { result = "before" }
618+
609619
override string toString() {
610620
if postOrInOrder(n) then result = "Before " + n.toString() else result = n.toString()
611621
}
@@ -618,6 +628,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
618628

619629
override AstNode getAstNode() { result = n }
620630

631+
override string getIdTag() { result = "ast" }
632+
621633
override string toString() { result = n.toString() }
622634
}
623635

@@ -629,6 +641,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
629641

630642
override AstNode getAstNode() { result = n }
631643

644+
override string getIdTag() {
645+
t.getValue() = true and result = "after-true"
646+
or
647+
t.getValue() = false and result = "after-false"
648+
}
649+
632650
override string toString() { result = "After " + n.toString() + " [" + t.toString() + "]" }
633651
}
634652

@@ -639,6 +657,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
639657

640658
override AstNode getAstNode() { result = n }
641659

660+
override string getIdTag() { result = "after" }
661+
642662
override string toString() { result = "After " + n.toString() }
643663
}
644664

@@ -652,6 +672,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
652672

653673
NormalSuccessor getSuccessorType() { additionalNode(n, tag, result) }
654674

675+
override string getIdTag() { result = "add. " + tag }
676+
655677
override string toString() { result = tag + " " + n.toString() }
656678
}
657679

@@ -664,6 +686,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
664686

665687
override AstNode getAstNode() { result = c }
666688

689+
override string getIdTag() { result = "entry" }
690+
667691
override string toString() { result = "Entry" }
668692
}
669693

@@ -678,6 +702,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
678702

679703
override AstNode getAstNode() { result = c }
680704

705+
override string getIdTag() {
706+
normal = true and result = "exit-normal"
707+
or
708+
normal = false and result = "exit-exc"
709+
}
710+
681711
override string toString() {
682712
normal = true and result = "Normal Exit"
683713
or
@@ -705,6 +735,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
705735

706736
override AstNode getAstNode() { result = c }
707737

738+
override string getIdTag() { result = "exit" }
739+
708740
override string toString() { result = "Exit" }
709741
}
710742

0 commit comments

Comments
 (0)