C#: Sign analysis testcase for unsigned right shift.

This commit is contained in:
Michael Nebel
2023-01-09 13:06:19 +01:00
parent 2568318460
commit 0f032c5be9
3 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
public class MySignAnalysis
{
public void UnsignedRightShiftSign(int x, int y)
{
int z;
if (x == 0)
{
z = x >>> y;
}
if (y == 0)
{
z = x >>> y;
}
if (x > 0 && y == 0)
{
z = x >>> y;
}
if (x > 0 && y > 0)
{
z = x >>> y;
}
if (x > 0 && y < 0)
{
z = x >>> y;
}
if (x < 0 && y > 0)
{
z = x >>> y;
}
if (x < 0 && y < 0)
{
z = x >>> y;
}
}
}

View File

@@ -0,0 +1,7 @@
| SignAnalysis.cs:9:17:9:23 | ... >>> ... | 0 |
| SignAnalysis.cs:14:17:14:23 | ... >>> ... | + - 0 |
| SignAnalysis.cs:19:17:19:23 | ... >>> ... | + |
| SignAnalysis.cs:24:17:24:23 | ... >>> ... | + 0 |
| SignAnalysis.cs:29:17:29:23 | ... >>> ... | + 0 |
| SignAnalysis.cs:34:17:34:23 | ... >>> ... | + - |
| SignAnalysis.cs:39:17:39:23 | ... >>> ... | + - |

View File

@@ -0,0 +1,9 @@
import csharp
import semmle.code.csharp.dataflow.internal.rangeanalysis.SignAnalysisCommon as Common
from ControlFlow::Nodes::ExprNode e, Expr expr
where
e.getExpr() = expr and
expr.getFile().getStem() = "SignAnalysis" and
expr instanceof UnsignedRightShiftExpr
select e, strictconcat(string s | s = Common::exprSign(e).toString() | s, " ")