Skip to content

Commit 38b050d

Browse files
committed
Java: Fix RangeAnalysis/ModulusAnalysis.
1 parent d5afd85 commit 38b050d

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

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
@@ -689,6 +689,14 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
689689
*/
690690
abstract AstNode getAstNode();
691691

692+
/**
693+
* INTERNAL: Do not use.
694+
*
695+
* Gets a tag such that the pair `(getAstNode(), getIdTag())` uniquely
696+
* identifies this node.
697+
*/
698+
abstract string getIdTag();
699+
692700
/** Gets a textual representation of this node. */
693701
abstract string toString();
694702

@@ -710,6 +718,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
710718

711719
override AstNode getAstNode() { result = n }
712720

721+
override string getIdTag() { result = "before" }
722+
713723
override string toString() {
714724
if postOrInOrder(n) then result = "Before " + n.toString() else result = n.toString()
715725
}
@@ -722,6 +732,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
722732

723733
override AstNode getAstNode() { result = n }
724734

735+
override string getIdTag() { result = "ast" }
736+
725737
override string toString() { result = n.toString() }
726738
}
727739

@@ -733,6 +745,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
733745

734746
override AstNode getAstNode() { result = n }
735747

748+
override string getIdTag() {
749+
t.getValue() = true and result = "after-true"
750+
or
751+
t.getValue() = false and result = "after-false"
752+
}
753+
736754
override string toString() { result = "After " + n.toString() + " [" + t.toString() + "]" }
737755
}
738756

@@ -743,6 +761,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
743761

744762
override AstNode getAstNode() { result = n }
745763

764+
override string getIdTag() { result = "after" }
765+
746766
override string toString() { result = "After " + n.toString() }
747767
}
748768

@@ -756,6 +776,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
756776

757777
NormalSuccessor getSuccessorType() { additionalNode(n, tag, result) }
758778

779+
override string getIdTag() { result = "add. " + tag }
780+
759781
override string toString() { result = tag + " " + n.toString() }
760782
}
761783

@@ -768,6 +790,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
768790

769791
override AstNode getAstNode() { result = c }
770792

793+
override string getIdTag() { result = "entry" }
794+
771795
override string toString() { result = "Entry" }
772796
}
773797

@@ -782,6 +806,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
782806

783807
override AstNode getAstNode() { result = c }
784808

809+
override string getIdTag() {
810+
normal = true and result = "exit-normal"
811+
or
812+
normal = false and result = "exit-exc"
813+
}
814+
785815
override string toString() {
786816
normal = true and result = "Normal Exit"
787817
or
@@ -809,6 +839,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
809839

810840
override AstNode getAstNode() { result = c }
811841

842+
override string getIdTag() { result = "exit" }
843+
812844
override string toString() { result = "Exit" }
813845
}
814846

0 commit comments

Comments
 (0)