C#: Extend pre-SSA consistency tests

This commit is contained in:
Tom Hvitved
2018-10-11 13:59:06 +02:00
parent cc14328be5
commit 98db3f89c2
2 changed files with 34 additions and 14 deletions

View File

@@ -2507,7 +2507,7 @@ module ControlFlow {
private import PreBasicBlocks
private import AssignableDefinitions
private class SimpleLocalScopeVariable extends LocalScopeVariable {
class SimpleLocalScopeVariable extends LocalScopeVariable {
SimpleLocalScopeVariable() {
not exists(AssignableDefinition def1, AssignableDefinition def2 |
def1.getTarget() = this and

View File

@@ -1,28 +1,48 @@
import csharp
import ControlFlow::Internal
predicate defReadInconsistency(AssignableRead ar, Expr e) {
exists(PreSsa::Definition ssaDef, AssignableDefinition def |
e = def.getExpr() and
PreSsa::firstReadSameVar(ssaDef, ar) and
ssaDef.getDefinition() = def and
not exists(Ssa::ExplicitDefinition edef |
predicate defReadInconsistency(AssignableRead ar, Expr e, boolean b) {
exists(AssignableDefinition def |
e = def.getExpr() |
b = true and
exists(PreSsa::Definition ssaDef |
PreSsa::firstReadSameVar(ssaDef, ar) and
ssaDef.getDefinition() = def and
not exists(Ssa::ExplicitDefinition edef |
edef.getADefinition() = def and
edef.getAFirstRead() = ar
)
)
or
b = false and
exists(Ssa::ExplicitDefinition edef |
edef.getADefinition() = def and
edef.getARead() = ar
edef.getAFirstRead() = ar and
def.getTarget() instanceof PreSsa::SimpleLocalScopeVariable and
not exists(PreSsa::Definition ssaDef |
PreSsa::firstReadSameVar(ssaDef, ar) and
ssaDef.getDefinition() = def
)
)
)
}
predicate readReadInconsistency(LocalScopeVariableRead read1, LocalScopeVariableRead read2) {
predicate readReadInconsistency(LocalScopeVariableRead read1, LocalScopeVariableRead read2, boolean b) {
b = true and
PreSsa::adjacentReadPairSameVar(read1, read2) and
not Ssa::Internal::adjacentReadPairSameVar(read1, read2)
or
b = false and
Ssa::Internal::adjacentReadPairSameVar(read1, read2) and
read1.getTarget() instanceof PreSsa::SimpleLocalScopeVariable and
not PreSsa::adjacentReadPairSameVar(read1, read2)
}
from Element e1, Element e2, string s
from Element e1, Element e2, boolean b, string s
where
defReadInconsistency(e1, e2) and
s = "def-read inconsistency"
defReadInconsistency(e1, e2, b) and
s = "def-read inconsistency (" + b + ")"
or
readReadInconsistency(e1, e2) and
s = "read-read inconsistency"
readReadInconsistency(e1, e2, b) and
s = "read-read inconsistency (" + b + ")"
select e1, e2, s