Merge pull request #658 from calumgrant/cs/extractor/for-is

C#: Fix extraction bug for variable declarations in for condition
This commit is contained in:
Tom Hvitved
2018-12-17 16:16:00 +01:00
committed by GitHub
7 changed files with 38 additions and 5 deletions

View File

@@ -17,6 +17,7 @@
## Changes to code extraction
* Fix extraction of `for` statements where the condition declares new variables using `is`.
* Initializers of `stackalloc` arrays are now extracted.
## Changes to QL libraries

View File

@@ -28,7 +28,10 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
Expression.Create(cx, init, this, child--);
}
Statement.Create(cx, Stmt.Statement, this, 1 + Stmt.Incrementors.Count);
if (Stmt.Condition != null)
{
Expression.Create(cx, Stmt.Condition, this, 0);
}
child = 1;
foreach (var inc in Stmt.Incrementors)
@@ -36,10 +39,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
Expression.Create(cx, inc, this, child++);
}
if (Stmt.Condition != null)
{
Expression.Create(cx, Stmt.Condition, this, 0);
}
Statement.Create(cx, Stmt.Statement, this, 1 + Stmt.Incrementors.Count);
}
}
}

View File

@@ -290,3 +290,14 @@ class ForeachStatements
foreach (var (a, b) in list) { }
}
}
class ForLoops
{
void Test()
{
for(int x=0; x<10 && x is int y; ++x)
{
Console.WriteLine(y);
}
}
}

View File

@@ -66,3 +66,10 @@
| CSharp7.cs:284:13:284:62 | IEnumerable<(Int32,String)> list = ... | CSharp7.cs:290:32:290:35 | access to local variable list |
| CSharp7.cs:284:32:284:35 | item | CSharp7.cs:284:41:284:44 | access to parameter item |
| CSharp7.cs:284:32:284:35 | item | CSharp7.cs:284:51:284:54 | access to parameter item |
| CSharp7.cs:298:17:298:19 | Int32 x = ... | CSharp7.cs:298:22:298:22 | access to local variable x |
| CSharp7.cs:298:17:298:19 | Int32 x = ... | CSharp7.cs:298:30:298:30 | access to local variable x |
| CSharp7.cs:298:17:298:19 | Int32 x = ... | CSharp7.cs:298:44:298:44 | access to local variable x |
| CSharp7.cs:298:35:298:39 | Int32 y | CSharp7.cs:300:31:300:31 | access to local variable y |
| CSharp7.cs:298:42:298:44 | ++... | CSharp7.cs:298:22:298:22 | access to local variable x |
| CSharp7.cs:298:42:298:44 | ++... | CSharp7.cs:298:30:298:30 | access to local variable x |
| CSharp7.cs:298:42:298:44 | ++... | CSharp7.cs:298:44:298:44 | access to local variable x |

View File

@@ -2,3 +2,4 @@
| CSharp7.cs:238:18:238:31 | ... is ... | CSharp7.cs:238:23:238:28 | access to type String | String | CSharp7.cs:238:23:238:31 | String s1 | false |
| CSharp7.cs:245:18:245:28 | ... is ... | CSharp7.cs:245:23:245:25 | access to type Object | Object | CSharp7.cs:245:23:245:28 | Object v1 | true |
| CSharp7.cs:255:27:255:40 | ... is ... | CSharp7.cs:255:32:255:37 | access to type String | String | CSharp7.cs:255:32:255:40 | String s4 | false |
| CSharp7.cs:298:30:298:39 | ... is ... | CSharp7.cs:298:35:298:37 | access to type Int32 | Int32 | CSharp7.cs:298:35:298:39 | Int32 y | false |

View File

@@ -193,3 +193,14 @@
| CSharp7.cs:288:36:288:39 | access to local variable list | CSharp7.cs:290:32:290:35 | access to local variable list |
| CSharp7.cs:290:23:290:23 | Int32 a | CSharp7.cs:290:18:290:27 | (..., ...) |
| CSharp7.cs:290:26:290:26 | String b | CSharp7.cs:290:18:290:27 | (..., ...) |
| CSharp7.cs:298:17:298:19 | SSA def(x) | CSharp7.cs:298:22:298:39 | SSA phi(x) |
| CSharp7.cs:298:19:298:19 | 0 | CSharp7.cs:298:17:298:19 | SSA def(x) |
| CSharp7.cs:298:22:298:22 | access to local variable x | CSharp7.cs:298:22:298:25 | ... < ... |
| CSharp7.cs:298:22:298:22 | access to local variable x | CSharp7.cs:298:30:298:30 | access to local variable x |
| CSharp7.cs:298:22:298:25 | ... < ... | CSharp7.cs:298:22:298:39 | ... && ... |
| CSharp7.cs:298:22:298:39 | SSA phi(x) | CSharp7.cs:298:22:298:22 | access to local variable x |
| CSharp7.cs:298:30:298:30 | access to local variable x | CSharp7.cs:298:35:298:39 | SSA def(y) |
| CSharp7.cs:298:30:298:30 | access to local variable x | CSharp7.cs:298:44:298:44 | access to local variable x |
| CSharp7.cs:298:30:298:39 | ... is ... | CSharp7.cs:298:22:298:39 | ... && ... |
| CSharp7.cs:298:35:298:39 | SSA def(y) | CSharp7.cs:300:31:300:31 | access to local variable y |
| CSharp7.cs:298:42:298:44 | SSA def(x) | CSharp7.cs:298:22:298:39 | SSA phi(x) |

View File

@@ -65,3 +65,5 @@
| CSharp7.cs:288:30:288:30 | b | string |
| CSharp7.cs:290:23:290:23 | a | int |
| CSharp7.cs:290:26:290:26 | b | string |
| CSharp7.cs:298:17:298:17 | x | int |
| CSharp7.cs:298:39:298:39 | y | int |