Add Java test file for sign analysis

This commit is contained in:
Tamas Vajk
2020-09-03 15:17:06 +02:00
parent 4a3118b13e
commit 441fbe3215
3 changed files with 34 additions and 0 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 | negative strictlyNegative |
| A.java:6:9:6:9 | x | positive |
| A.java:7:14:7:14 | y | positive strictlyPositive |

View File

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