Merge pull request #4445 from hvitved/csharp/sign-analysis-cfg

C#: Use CFG nodes instead of AST nodes in sign/modulus analysis
This commit is contained in:
Tom Hvitved
2020-10-26 09:45:38 +01:00
committed by GitHub
28 changed files with 1187 additions and 544 deletions

View File

@@ -111,18 +111,6 @@ private predicate evenlyDivisibleExpr(Expr e, int factor) {
)
}
/**
* Holds if `inp` is an input to `phi` along `edge` and this input has index `r`
* in an arbitrary 1-based numbering of the input edges to `phi`.
*/
private predicate rankedPhiInput(
SsaPhiNode phi, SsaVariable inp, SsaReadPositionPhiInputEdge edge, int r
) {
edge.phiInput(phi, inp) and
edge =
rank[r](SsaReadPositionPhiInputEdge e | e.phiInput(phi, _) | e order by getId(e.getOrigBlock()))
}
/**
* Holds if `rix` is the number of input edges to `phi`.
*/

View File

@@ -4,6 +4,7 @@ module Private {
private import semmle.code.java.dataflow.RangeUtils as RU
private import semmle.code.java.controlflow.Guards as G
private import semmle.code.java.controlflow.BasicBlocks as BB
private import SsaReadPositionCommon
class BasicBlock = BB::BasicBlock;
@@ -115,5 +116,19 @@ module Private {
private predicate idOf(BasicBlock x, int y) = equivalenceRelation(id/2)(x, y)
int getId(BasicBlock bb) { idOf(bb, result) }
private int getId(BasicBlock bb) { idOf(bb, result) }
/**
* Holds if `inp` is an input to `phi` along `edge` and this input has index `r`
* in an arbitrary 1-based numbering of the input edges to `phi`.
*/
predicate rankedPhiInput(SsaPhiNode phi, SsaVariable inp, SsaReadPositionPhiInputEdge edge, int r) {
edge.phiInput(phi, inp) and
edge =
rank[r](SsaReadPositionPhiInputEdge e |
e.phiInput(phi, _)
|
e order by getId(e.getOrigBlock())
)
}
}

View File

@@ -51,7 +51,7 @@ private predicate unknownSign(Expr e) {
or
exists(CastExpr cast, Type fromtyp |
cast = e and
fromtyp = cast.getExpr().getType() and
fromtyp = cast.getSourceType() and
not fromtyp instanceof NumericOrCharType
)
or

View File

@@ -27,7 +27,10 @@ module Private {
class LongLiteral = J::LongLiteral;
class CastExpr = J::CastExpr;
class CastExpr extends J::CastExpr {
/** Gets the source type of this cast. */
J::Type getSourceType() { result = this.getExpr().getType() }
}
class Type = J::Type;