Skip to content

Commit 1e9dcea

Browse files
committed
Java: Fix RangeAnalysis/ModulusAnalysis.
1 parent 6fbdb2c commit 1e9dcea

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
@@ -706,6 +706,14 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
706706
*/
707707
abstract AstNode getAstNode();
708708

709+
/**
710+
* INTERNAL: Do not use.
711+
*
712+
* Gets a tag such that the pair `(getAstNode(), getIdTag())` uniquely
713+
* identifies this node.
714+
*/
715+
abstract string getIdTag();
716+
709717
/** Gets a textual representation of this node. */
710718
abstract string toString();
711719

@@ -727,6 +735,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
727735

728736
override AstNode getAstNode() { result = n }
729737

738+
override string getIdTag() { result = "before" }
739+
730740
override string toString() {
731741
if postOrInOrder(n) then result = "Before " + n.toString() else result = n.toString()
732742
}
@@ -739,6 +749,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
739749

740750
override AstNode getAstNode() { result = n }
741751

752+
override string getIdTag() { result = "ast" }
753+
742754
override string toString() { result = n.toString() }
743755
}
744756

@@ -750,6 +762,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
750762

751763
override AstNode getAstNode() { result = n }
752764

765+
override string getIdTag() {
766+
t.getValue() = true and result = "after-true"
767+
or
768+
t.getValue() = false and result = "after-false"
769+
}
770+
753771
override string toString() { result = "After " + n.toString() + " [" + t.toString() + "]" }
754772
}
755773

@@ -760,6 +778,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
760778

761779
override AstNode getAstNode() { result = n }
762780

781+
override string getIdTag() { result = "after" }
782+
763783
override string toString() { result = "After " + n.toString() }
764784
}
765785

@@ -773,6 +793,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
773793

774794
NormalSuccessor getSuccessorType() { additionalNode(n, tag, result) }
775795

796+
override string getIdTag() { result = "add. " + tag }
797+
776798
override string toString() { result = tag + " " + n.toString() }
777799
}
778800

@@ -785,6 +807,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
785807

786808
override AstNode getAstNode() { result = c }
787809

810+
override string getIdTag() { result = "entry" }
811+
788812
override string toString() { result = "Entry" }
789813
}
790814

@@ -799,6 +823,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
799823

800824
override AstNode getAstNode() { result = c }
801825

826+
override string getIdTag() {
827+
normal = true and result = "exit-normal"
828+
or
829+
normal = false and result = "exit-exc"
830+
}
831+
802832
override string toString() {
803833
normal = true and result = "Normal Exit"
804834
or
@@ -826,6 +856,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
826856

827857
override AstNode getAstNode() { result = c }
828858

859+
override string getIdTag() { result = "exit" }
860+
829861
override string toString() { result = "Exit" }
830862
}
831863

0 commit comments

Comments
 (0)