Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98db3f8

Browse files
committed
C#: Extend pre-SSA consistency tests
1 parent cc14328 commit 98db3f8

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

csharp/ql/src/semmle/code/csharp/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,7 @@ module ControlFlow {
25072507
private import PreBasicBlocks
25082508
private import AssignableDefinitions
25092509

2510-
private class SimpleLocalScopeVariable extends LocalScopeVariable {
2510+
class SimpleLocalScopeVariable extends LocalScopeVariable {
25112511
SimpleLocalScopeVariable() {
25122512
not exists(AssignableDefinition def1, AssignableDefinition def2 |
25132513
def1.getTarget() = this and
Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
11
import csharp
22
import ControlFlow::Internal
33

4-
predicate defReadInconsistency(AssignableRead ar, Expr e) {
5-
exists(PreSsa::Definition ssaDef, AssignableDefinition def |
6-
e = def.getExpr() and
7-
PreSsa::firstReadSameVar(ssaDef, ar) and
8-
ssaDef.getDefinition() = def and
9-
not exists(Ssa::ExplicitDefinition edef |
4+
predicate defReadInconsistency(AssignableRead ar, Expr e, boolean b) {
5+
exists(AssignableDefinition def |
6+
e = def.getExpr() |
7+
b = true and
8+
exists(PreSsa::Definition ssaDef |
9+
PreSsa::firstReadSameVar(ssaDef, ar) and
10+
ssaDef.getDefinition() = def and
11+
not exists(Ssa::ExplicitDefinition edef |
12+
edef.getADefinition() = def and
13+
edef.getAFirstRead() = ar
14+
)
15+
)
16+
or
17+
b = false and
18+
exists(Ssa::ExplicitDefinition edef |
1019
edef.getADefinition() = def and
11-
edef.getARead() = ar
20+
edef.getAFirstRead() = ar and
21+
def.getTarget() instanceof PreSsa::SimpleLocalScopeVariable and
22+
not exists(PreSsa::Definition ssaDef |
23+
PreSsa::firstReadSameVar(ssaDef, ar) and
24+
ssaDef.getDefinition() = def
25+
)
1226
)
1327
)
1428
}
1529

16-
predicate readReadInconsistency(LocalScopeVariableRead read1, LocalScopeVariableRead read2) {
30+
predicate readReadInconsistency(LocalScopeVariableRead read1, LocalScopeVariableRead read2, boolean b) {
31+
b = true and
1732
PreSsa::adjacentReadPairSameVar(read1, read2) and
1833
not Ssa::Internal::adjacentReadPairSameVar(read1, read2)
34+
or
35+
b = false and
36+
Ssa::Internal::adjacentReadPairSameVar(read1, read2) and
37+
read1.getTarget() instanceof PreSsa::SimpleLocalScopeVariable and
38+
not PreSsa::adjacentReadPairSameVar(read1, read2)
1939
}
2040

21-
from Element e1, Element e2, string s
41+
from Element e1, Element e2, boolean b, string s
2242
where
23-
defReadInconsistency(e1, e2) and
24-
s = "def-read inconsistency"
43+
defReadInconsistency(e1, e2, b) and
44+
s = "def-read inconsistency (" + b + ")"
2545
or
26-
readReadInconsistency(e1, e2) and
27-
s = "read-read inconsistency"
46+
readReadInconsistency(e1, e2, b) and
47+
s = "read-read inconsistency (" + b + ")"
2848
select e1, e2, s

0 commit comments

Comments
 (0)