Skip to content

Commit 0f032c5

Browse files
committed
C#: Sign analysis testcase for unsigned right shift.
1 parent 2568318 commit 0f032c5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
public class MySignAnalysis
2+
{
3+
4+
public void UnsignedRightShiftSign(int x, int y)
5+
{
6+
int z;
7+
if (x == 0)
8+
{
9+
z = x >>> y;
10+
}
11+
12+
if (y == 0)
13+
{
14+
z = x >>> y;
15+
}
16+
17+
if (x > 0 && y == 0)
18+
{
19+
z = x >>> y;
20+
}
21+
22+
if (x > 0 && y > 0)
23+
{
24+
z = x >>> y;
25+
}
26+
27+
if (x > 0 && y < 0)
28+
{
29+
z = x >>> y;
30+
}
31+
32+
if (x < 0 && y > 0)
33+
{
34+
z = x >>> y;
35+
}
36+
37+
if (x < 0 && y < 0)
38+
{
39+
z = x >>> y;
40+
}
41+
}
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| SignAnalysis.cs:9:17:9:23 | ... >>> ... | 0 |
2+
| SignAnalysis.cs:14:17:14:23 | ... >>> ... | + - 0 |
3+
| SignAnalysis.cs:19:17:19:23 | ... >>> ... | + |
4+
| SignAnalysis.cs:24:17:24:23 | ... >>> ... | + 0 |
5+
| SignAnalysis.cs:29:17:29:23 | ... >>> ... | + 0 |
6+
| SignAnalysis.cs:34:17:34:23 | ... >>> ... | + - |
7+
| SignAnalysis.cs:39:17:39:23 | ... >>> ... | + - |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import csharp
2+
import semmle.code.csharp.dataflow.internal.rangeanalysis.SignAnalysisCommon as Common
3+
4+
from ControlFlow::Nodes::ExprNode e, Expr expr
5+
where
6+
e.getExpr() = expr and
7+
expr.getFile().getStem() = "SignAnalysis" and
8+
expr instanceof UnsignedRightShiftExpr
9+
select e, strictconcat(string s | s = Common::exprSign(e).toString() | s, " ")

0 commit comments

Comments
 (0)