-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18819 from aschackmull/ssa/refactor-phiread3
Ssa: Refactor shared SSA in preparation for eliminating phi-read definitions
- Loading branch information
Showing
10 changed files
with
448 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class A { | ||
Object source() { return null; } | ||
void sink(Object o) { } | ||
|
||
boolean isSafe(Object o) { return o == null; } | ||
|
||
void foo() { | ||
Object x = source(); | ||
if (!isSafe(x)) { | ||
x = null; | ||
} | ||
sink(x); | ||
|
||
x = source(); | ||
if (!isSafe(x)) { | ||
if (isSafe(x)) { | ||
sink(x); | ||
} else { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
sink(x); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java | ||
import semmle.code.java.controlflow.Guards | ||
import semmle.code.java.dataflow.DataFlow | ||
|
||
private predicate isSafe(Guard g, Expr checked, boolean branch) { | ||
exists(MethodCall mc | g = mc | | ||
mc.getMethod().hasName("isSafe") and | ||
checked = mc.getAnArgument() and | ||
branch = true | ||
) | ||
} | ||
|
||
module TestConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node source) { | ||
source.asExpr().(MethodCall).getMethod().hasName("source") | ||
} | ||
|
||
predicate isSink(DataFlow::Node sink) { | ||
exists(MethodCall mc | mc.getMethod().hasName("sink") and mc.getAnArgument() = sink.asExpr()) | ||
} | ||
|
||
predicate isBarrier(DataFlow::Node node) { | ||
node = DataFlow::BarrierGuard<isSafe/3>::getABarrierNode() | ||
} | ||
} | ||
|
||
module Flow = DataFlow::Global<TestConfig>; | ||
|
||
from DataFlow::Node source, DataFlow::Node sink | ||
where Flow::flow(source, sink) | ||
select source, sink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,6 @@ case String s when isSafe(s): | |
break; | ||
|
||
} | ||
|
||
String s2 = "string"; | ||
|
||
if (!isSafe(s2)) { | ||
s2 = null; | ||
} | ||
sink(s2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.