Skip to content

Commit 5379506

Browse files
committed
Java: Use firstUse and adjacentUseUse predicates.
1 parent cf2136f commit 5379506

File tree

1 file changed

+11
-52
lines changed
  • java/ql/lib/semmle/code/java/dataflow/internal

1 file changed

+11
-52
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -508,34 +508,15 @@ private module Cached {
508508
Impl::uncertainWriteDefinitionInput(redef, def)
509509
}
510510

511-
pragma[nomagic]
512-
private predicate defReaches(Definition def, DataFlowIntegration::Node node) {
513-
exists(DataFlowIntegration::SsaDefinitionExtNode nodeFrom |
514-
nodeFrom.getDefinitionExt() = def and
515-
DataFlowIntegrationImpl::localFlowStep(_, nodeFrom, node, false)
516-
)
517-
or
518-
exists(DataFlowIntegration::Node mid |
519-
defReaches(def, mid) and
520-
DataFlowIntegrationImpl::localFlowStep(_, mid, node, _)
521-
|
522-
// flow into phi input node
523-
mid instanceof DataFlowIntegration::SsaInputNode
524-
or
525-
// flow into definition
526-
mid instanceof DataFlowIntegration::SsaDefinitionExtNode
527-
)
528-
}
529-
530511
/**
531512
* Holds if the value defined at `def` can reach `use` without passing through
532513
* any other uses, but possibly through phi nodes and uncertain implicit updates.
533514
*/
534515
cached
535516
predicate firstUse(Definition def, VarRead use) {
536-
exists(DataFlowIntegration::ExprNode nodeTo |
537-
nodeTo.getExpr() = use and
538-
defReaches(def, nodeTo)
517+
exists(BasicBlock bb, int i |
518+
Impl::firstUse(def, bb, i, _) and
519+
use.getControlFlowNode() = bb.getNode(i)
539520
)
540521
}
541522

@@ -594,40 +575,17 @@ private module Cached {
594575

595576
cached
596577
module SsaPublic {
597-
pragma[nomagic]
598-
private predicate useReaches(VarRead use, DataFlowIntegration::Node node, boolean sameVar) {
599-
exists(DataFlowIntegration::ExprNode nodeFrom |
600-
nodeFrom.getExpr() = use and
601-
DataFlowIntegration::localFlowStep(_, nodeFrom, node, true) and
602-
sameVar = true
603-
)
604-
or
605-
exists(DataFlowIntegration::Node mid, boolean sameVarMid |
606-
useReaches(use, mid, sameVarMid) and
607-
DataFlowIntegration::localFlowStep(_, mid, node, _)
608-
|
609-
exists(Impl::DefinitionExt def |
610-
// flow into definition
611-
def = mid.(DataFlowIntegration::SsaDefinitionExtNode).getDefinitionExt()
612-
or
613-
// flow into phi input node
614-
def = mid.(DataFlowIntegration::SsaInputNode).getDefinitionExt()
615-
|
616-
if def instanceof Impl::PhiReadNode then sameVar = sameVarMid else sameVar = false
617-
)
618-
)
619-
}
620-
621578
/**
622579
* Holds if `use1` and `use2` form an adjacent use-use-pair of the same SSA
623580
* variable, that is, the value read in `use1` can reach `use2` without passing
624581
* through any other use or any SSA definition of the variable.
625582
*/
626583
cached
627584
predicate adjacentUseUseSameVar(VarRead use1, VarRead use2) {
628-
exists(DataFlowIntegration::ExprNode nodeTo |
629-
nodeTo.getExpr() = use2 and
630-
useReaches(use1, nodeTo, true)
585+
exists(BasicBlock bb1, int i1, BasicBlock bb2, int i2 |
586+
use1.getControlFlowNode() = bb1.getNode(i1) and
587+
use2.getControlFlowNode() = bb2.getNode(i2) and
588+
Impl::adjacentUseUse(bb1, i1, bb2, i2, _, true)
631589
)
632590
}
633591

@@ -639,9 +597,10 @@ private module Cached {
639597
*/
640598
cached
641599
predicate adjacentUseUse(VarRead use1, VarRead use2) {
642-
exists(DataFlowIntegration::ExprNode nodeTo |
643-
nodeTo.getExpr() = use2 and
644-
useReaches(use1, nodeTo, _)
600+
exists(BasicBlock bb1, int i1, BasicBlock bb2, int i2 |
601+
use1.getControlFlowNode() = bb1.getNode(i1) and
602+
use2.getControlFlowNode() = bb2.getNode(i2) and
603+
Impl::adjacentUseUse(bb1, i1, bb2, i2, _, _)
645604
)
646605
}
647606
}

0 commit comments

Comments
 (0)