Merge pull request #4193 from tamasvajk/feature/sign-analysis

C#: Sign analysis
This commit is contained in:
Tamás Vajk
2020-09-22 15:33:33 +02:00
committed by GitHub
33 changed files with 2670 additions and 696 deletions

View File

@@ -0,0 +1,12 @@
public class A {
int f1(int x, int y) {
if (x < 0) {
return x; // strictly negative
}
if (x < y) {
return y; // y is strictly positive because of the bound on x above
}
return 0;
}
}

View File

@@ -0,0 +1,3 @@
| A.java:4:14:4:14 | x | strictlyNegative |
| A.java:6:9:6:9 | x | positive |
| A.java:7:14:7:14 | y | strictlyPositive |

View File

@@ -0,0 +1,21 @@
import java
import semmle.code.java.dataflow.SignAnalysis
string getASignString(Expr e) {
positive(e) and
not strictlyPositive(e) and
result = "positive"
or
negative(e) and
not strictlyNegative(e) and
result = "negative"
or
strictlyPositive(e) and
result = "strictlyPositive"
or
strictlyNegative(e) and
result = "strictlyNegative"
}
from Expr e
select e, strictconcat(string s | s = getASignString(e) | s, " ")