mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
C#: Make SuppressNullableWarningExpr a nonNullValue, and add a test.
This commit is contained in:
@@ -673,6 +673,8 @@ module Internal {
|
||||
or
|
||||
e.(Call).getTarget().getSourceDeclaration() instanceof NonNullCallable and
|
||||
not e.(QualifiableExpr).isConditional()
|
||||
or
|
||||
e instanceof SuppressNullableWarningExpr
|
||||
}
|
||||
|
||||
/** Holds if expression `e2` is a non-`null` value whenever `e1` is. */
|
||||
|
||||
@@ -7,5 +7,7 @@ class NullableRefTypes
|
||||
string? x = "source";
|
||||
string y = x!;
|
||||
y = x!!;
|
||||
x = null;
|
||||
y = x!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ suppressNullableWarnings
|
||||
| NullableRefTypes.cs:8:20:8:21 | ...! | NullableRefTypes.cs:8:20:8:20 | access to local variable x |
|
||||
| NullableRefTypes.cs:9:13:9:14 | ...! | NullableRefTypes.cs:9:13:9:13 | access to local variable x |
|
||||
| NullableRefTypes.cs:9:13:9:15 | ...! | NullableRefTypes.cs:9:13:9:14 | ...! |
|
||||
| NullableRefTypes.cs:11:13:11:14 | ...! | NullableRefTypes.cs:11:13:11:13 | access to local variable x |
|
||||
nullableDataFlow
|
||||
| NullableRefTypes.cs:7:17:7:28 | SSA def(x) | NullableRefTypes.cs:8:20:8:20 | access to local variable x |
|
||||
| NullableRefTypes.cs:7:21:7:28 | "source" | NullableRefTypes.cs:7:17:7:28 | SSA def(x) |
|
||||
@@ -9,9 +10,12 @@ nullableDataFlow
|
||||
| NullableRefTypes.cs:8:20:8:20 | access to local variable x | NullableRefTypes.cs:9:13:9:13 | access to local variable x |
|
||||
| NullableRefTypes.cs:9:13:9:13 | access to local variable x | NullableRefTypes.cs:9:13:9:14 | ...! |
|
||||
| NullableRefTypes.cs:9:13:9:14 | ...! | NullableRefTypes.cs:9:13:9:15 | ...! |
|
||||
| NullableRefTypes.cs:10:9:10:16 | SSA def(x) | NullableRefTypes.cs:11:13:11:13 | access to local variable x |
|
||||
| NullableRefTypes.cs:10:13:10:16 | null | NullableRefTypes.cs:10:9:10:16 | SSA def(x) |
|
||||
| NullableRefTypes.cs:11:13:11:13 | access to local variable x | NullableRefTypes.cs:11:13:11:14 | ...! |
|
||||
nullableControlFlow
|
||||
| NullableRefTypes.cs:5:10:5:29 | enter TestNullableRefTypes | NullableRefTypes.cs:6:5:10:5 | {...} | successor |
|
||||
| NullableRefTypes.cs:6:5:10:5 | {...} | NullableRefTypes.cs:7:9:7:29 | ... ...; | successor |
|
||||
| NullableRefTypes.cs:5:10:5:29 | enter TestNullableRefTypes | NullableRefTypes.cs:6:5:12:5 | {...} | successor |
|
||||
| NullableRefTypes.cs:6:5:12:5 | {...} | NullableRefTypes.cs:7:9:7:29 | ... ...; | successor |
|
||||
| NullableRefTypes.cs:7:9:7:29 | ... ...; | NullableRefTypes.cs:7:21:7:28 | "source" | successor |
|
||||
| NullableRefTypes.cs:7:17:7:28 | String x = ... | NullableRefTypes.cs:8:9:8:22 | ... ...; | successor |
|
||||
| NullableRefTypes.cs:7:21:7:28 | "source" | NullableRefTypes.cs:7:17:7:28 | String x = ... | successor |
|
||||
@@ -19,8 +23,25 @@ nullableControlFlow
|
||||
| NullableRefTypes.cs:8:16:8:21 | String y = ... | NullableRefTypes.cs:9:9:9:16 | ...; | successor |
|
||||
| NullableRefTypes.cs:8:20:8:20 | access to local variable x | NullableRefTypes.cs:8:20:8:21 | ...! | successor |
|
||||
| NullableRefTypes.cs:8:20:8:21 | ...! | NullableRefTypes.cs:8:16:8:21 | String y = ... | successor |
|
||||
| NullableRefTypes.cs:9:9:9:15 | ... = ... | NullableRefTypes.cs:5:10:5:29 | exit TestNullableRefTypes | successor |
|
||||
| NullableRefTypes.cs:9:9:9:15 | ... = ... | NullableRefTypes.cs:10:9:10:17 | ...; | successor |
|
||||
| NullableRefTypes.cs:9:9:9:16 | ...; | NullableRefTypes.cs:9:13:9:13 | access to local variable x | successor |
|
||||
| NullableRefTypes.cs:9:13:9:13 | access to local variable x | NullableRefTypes.cs:9:13:9:14 | ...! | successor |
|
||||
| NullableRefTypes.cs:9:13:9:14 | ...! | NullableRefTypes.cs:9:13:9:15 | ...! | successor |
|
||||
| NullableRefTypes.cs:9:13:9:15 | ...! | NullableRefTypes.cs:9:9:9:15 | ... = ... | successor |
|
||||
| NullableRefTypes.cs:10:9:10:16 | ... = ... | NullableRefTypes.cs:11:9:11:15 | ...; | successor |
|
||||
| NullableRefTypes.cs:10:9:10:17 | ...; | NullableRefTypes.cs:10:13:10:16 | null | successor |
|
||||
| NullableRefTypes.cs:10:13:10:16 | null | NullableRefTypes.cs:10:9:10:16 | ... = ... | successor |
|
||||
| NullableRefTypes.cs:11:9:11:14 | ... = ... | NullableRefTypes.cs:5:10:5:29 | exit TestNullableRefTypes | successor |
|
||||
| NullableRefTypes.cs:11:9:11:15 | ...; | NullableRefTypes.cs:11:13:11:13 | access to local variable x | successor |
|
||||
| NullableRefTypes.cs:11:13:11:13 | access to local variable x | NullableRefTypes.cs:11:13:11:14 | ...! | successor |
|
||||
| NullableRefTypes.cs:11:13:11:14 | ...! | NullableRefTypes.cs:11:9:11:14 | ... = ... | successor |
|
||||
nonNullExpressions
|
||||
| NullableRefTypes.cs:7:21:7:28 | "source" |
|
||||
| NullableRefTypes.cs:8:20:8:20 | access to local variable x |
|
||||
| NullableRefTypes.cs:8:20:8:21 | ...! |
|
||||
| NullableRefTypes.cs:9:9:9:15 | ... = ... |
|
||||
| NullableRefTypes.cs:9:13:9:13 | access to local variable x |
|
||||
| NullableRefTypes.cs:9:13:9:14 | ...! |
|
||||
| NullableRefTypes.cs:9:13:9:15 | ...! |
|
||||
| NullableRefTypes.cs:11:9:11:14 | ... = ... |
|
||||
| NullableRefTypes.cs:11:13:11:14 | ...! |
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.dataflow.Nullness
|
||||
|
||||
query predicate suppressNullableWarnings(SuppressNullableWarningExpr e, Expr op) {
|
||||
op = e.getExpr()
|
||||
@@ -15,3 +16,7 @@ query predicate nullableControlFlow(
|
||||
a.getEnclosingCallable().hasName("TestNullableRefTypes") and
|
||||
b = a.getASuccessorByType(t)
|
||||
}
|
||||
|
||||
query predicate nonNullExpressions(NonNullExpr e) {
|
||||
e.getEnclosingCallable().getName() = "TestNullableRefTypes"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user