Skip to content

Commit f720528

Browse files
authored
Merge pull request github#14149 from hvitved/csharp/extract-gen-no-trap-stack
C#: Clear TRAP stack when calling `PopulateGenerics`
2 parents 94442c1 + 718e491 commit f720528

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,41 +250,44 @@ public void ExtractRecursive()
250250
/// </summary>
251251
public void PopulateGenerics()
252252
{
253-
if (Symbol is null || !NeedsPopulation || !Context.ExtractGenerics(this))
254-
return;
253+
Context.PopulateLater(() =>
254+
{
255+
if (Symbol is null || !NeedsPopulation || !Context.ExtractGenerics(this))
256+
return;
255257

256-
var members = new List<ISymbol>();
258+
var members = new List<ISymbol>();
257259

258-
foreach (var member in Symbol.GetMembers())
259-
members.Add(member);
260-
foreach (var member in Symbol.GetTypeMembers())
261-
members.Add(member);
260+
foreach (var member in Symbol.GetMembers())
261+
members.Add(member);
262+
foreach (var member in Symbol.GetTypeMembers())
263+
members.Add(member);
262264

263-
// Mono extractor puts all BASE interface members as members of the current interface.
265+
// Mono extractor puts all BASE interface members as members of the current interface.
264266

265-
if (Symbol.TypeKind == TypeKind.Interface)
266-
{
267-
foreach (var baseInterface in Symbol.Interfaces)
267+
if (Symbol.TypeKind == TypeKind.Interface)
268268
{
269-
foreach (var member in baseInterface.GetMembers())
270-
members.Add(member);
271-
foreach (var member in baseInterface.GetTypeMembers())
272-
members.Add(member);
269+
foreach (var baseInterface in Symbol.Interfaces)
270+
{
271+
foreach (var member in baseInterface.GetMembers())
272+
members.Add(member);
273+
foreach (var member in baseInterface.GetTypeMembers())
274+
members.Add(member);
275+
}
273276
}
274-
}
275277

276-
foreach (var member in members)
277-
{
278-
Context.CreateEntity(member);
279-
}
278+
foreach (var member in members)
279+
{
280+
Context.CreateEntity(member);
281+
}
280282

281-
if (Symbol.BaseType is not null)
282-
Create(Context, Symbol.BaseType).PopulateGenerics();
283+
if (Symbol.BaseType is not null)
284+
Create(Context, Symbol.BaseType).PopulateGenerics();
283285

284-
foreach (var i in Symbol.Interfaces)
285-
{
286-
Create(Context, i).PopulateGenerics();
287-
}
286+
foreach (var i in Symbol.Interfaces)
287+
{
288+
Create(Context, i).PopulateGenerics();
289+
}
290+
}, preserveDuplicationKey: false);
288291
}
289292

290293
public void ExtractRecursive(TextWriter trapFile, IEntity parent)

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ internal void AddFreshLabel(Entity entity)
153153
/// Enqueue the given action to be performed later.
154154
/// </summary>
155155
/// <param name="toRun">The action to run.</param>
156-
public void PopulateLater(Action a)
156+
public void PopulateLater(Action a, bool preserveDuplicationKey = true)
157157
{
158-
var key = GetCurrentTagStackKey();
158+
var key = preserveDuplicationKey ? GetCurrentTagStackKey() : null;
159159
if (key is not null)
160160
{
161161
// If we are currently executing with a duplication guard, then the same

csharp/ql/test/library-tests/csharp7/TupleExpr.expected

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
| CSharp7.cs:87:18:87:34 | (..., ...) | CSharp7.cs:87:18:87:34 | (String,String) | 1 | CSharp7.cs:87:30:87:33 | "X2" |
4141
| CSharp7.cs:88:9:88:24 | (..., ...) | CSharp7.cs:87:18:87:34 | (String,String) | 0 | CSharp7.cs:88:14:88:15 | String t2 |
4242
| CSharp7.cs:88:9:88:24 | (..., ...) | CSharp7.cs:87:18:87:34 | (String,String) | 1 | CSharp7.cs:88:22:88:23 | String t3 |
43-
| CSharp7.cs:95:18:95:38 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 0 | CSharp7.cs:95:19:95:19 | 1 |
44-
| CSharp7.cs:95:18:95:38 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 1 | CSharp7.cs:95:22:95:37 | "TupleExprNode1" |
43+
| CSharp7.cs:95:18:95:38 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 0 | CSharp7.cs:95:19:95:19 | 1 |
44+
| CSharp7.cs:95:18:95:38 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 1 | CSharp7.cs:95:22:95:37 | "TupleExprNode1" |
4545
| CSharp7.cs:96:18:96:43 | (..., ...) | CSharp7.cs:96:18:96:43 | (Int32,(String,Int32)) | 0 | CSharp7.cs:96:19:96:19 | 1 |
4646
| CSharp7.cs:96:18:96:43 | (..., ...) | CSharp7.cs:96:18:96:43 | (Int32,(String,Int32)) | 1 | CSharp7.cs:96:22:96:42 | (..., ...) |
4747
| CSharp7.cs:96:22:96:42 | (..., ...) | file://:0:0:0:0 | (String,Int32) | 0 | CSharp7.cs:96:23:96:38 | "TupleExprNode2" |
@@ -82,11 +82,11 @@
8282
| CSharp7.cs:223:9:223:18 | (..., ...) | CSharp7.cs:213:5:213:17 | (Int32,Double) | 1 | CSharp7.cs:223:17:223:17 | _ |
8383
| CSharp7.cs:224:9:224:18 | (..., ...) | CSharp7.cs:213:5:213:17 | (Int32,Double) | 0 | CSharp7.cs:224:10:224:10 | _ |
8484
| CSharp7.cs:224:9:224:18 | (..., ...) | CSharp7.cs:213:5:213:17 | (Int32,Double) | 1 | CSharp7.cs:224:17:224:17 | Double y |
85-
| CSharp7.cs:283:40:283:61 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 0 | CSharp7.cs:283:41:283:48 | access to property Key |
86-
| CSharp7.cs:283:40:283:61 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 1 | CSharp7.cs:283:51:283:60 | access to property Value |
87-
| CSharp7.cs:285:18:285:34 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 0 | CSharp7.cs:285:23:285:23 | Int32 a |
88-
| CSharp7.cs:285:18:285:34 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 1 | CSharp7.cs:285:33:285:33 | String b |
89-
| CSharp7.cs:287:18:287:31 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 0 | CSharp7.cs:287:23:287:23 | Int32 a |
90-
| CSharp7.cs:287:18:287:31 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 1 | CSharp7.cs:287:30:287:30 | String b |
91-
| CSharp7.cs:289:18:289:27 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 0 | CSharp7.cs:289:23:289:23 | Int32 a |
92-
| CSharp7.cs:289:18:289:27 | (..., ...) | file://:0:0:0:0 | (Int32,String) | 1 | CSharp7.cs:289:26:289:26 | String b |
85+
| CSharp7.cs:283:40:283:61 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 0 | CSharp7.cs:283:41:283:48 | access to property Key |
86+
| CSharp7.cs:283:40:283:61 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 1 | CSharp7.cs:283:51:283:60 | access to property Value |
87+
| CSharp7.cs:285:18:285:34 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 0 | CSharp7.cs:285:23:285:23 | Int32 a |
88+
| CSharp7.cs:285:18:285:34 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 1 | CSharp7.cs:285:33:285:33 | String b |
89+
| CSharp7.cs:287:18:287:31 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 0 | CSharp7.cs:287:23:287:23 | Int32 a |
90+
| CSharp7.cs:287:18:287:31 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 1 | CSharp7.cs:287:30:287:30 | String b |
91+
| CSharp7.cs:289:18:289:27 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 0 | CSharp7.cs:289:23:289:23 | Int32 a |
92+
| CSharp7.cs:289:18:289:27 | (..., ...) | CSharp7.cs:95:18:95:38 | (Int32,String) | 1 | CSharp7.cs:289:26:289:26 | String b |
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
| (Int32,(String,Int32)) | (int, (string, int)) | ValueTuple<int, (string, int)> | 2 | 0 | CSharp7.cs:96:19:96:19 | Item1 |
2-
| (Int32,(String,Int32)) | (int, (string, int)) | ValueTuple<int, (string, int)> | 2 | 1 | CSharp7.cs:96:22:96:42 | Item2 |
2+
| (Int32,(String,Int32)) | (int, (string, int)) | ValueTuple<int, (string, int)> | 2 | 1 | CSharp7.cs:102:22:102:46 | Item2 |
33
| (Int32,Double) | (int, double) | ValueTuple<int, double> | 2 | 0 | CSharp7.cs:213:6:213:8 | Item1 |
44
| (Int32,Double) | (int, double) | ValueTuple<int, double> | 2 | 1 | CSharp7.cs:213:11:213:16 | Item2 |
55
| (Int32,Int32) | (int, int) | ValueTuple<int, int> | 2 | 0 | CSharp7.cs:62:10:62:10 | Item1 |
66
| (Int32,Int32) | (int, int) | ValueTuple<int, int> | 2 | 1 | CSharp7.cs:62:17:62:17 | Item2 |
7+
| (Int32,String) | (int, string) | ValueTuple<int, string> | 2 | 0 | CSharp7.cs:95:19:95:19 | Item1 |
8+
| (Int32,String) | (int, string) | ValueTuple<int, string> | 2 | 1 | CSharp7.cs:95:22:95:37 | Item2 |
79
| (String,Int32) | (string, int) | ValueTuple<string, int> | 2 | 0 | CSharp7.cs:82:17:82:17 | Item1 |
10+
| (String,Int32) | (string, int) | ValueTuple<string, int> | 2 | 0 | CSharp7.cs:101:19:101:38 | Item1 |
811
| (String,Int32) | (string, int) | ValueTuple<string, int> | 2 | 1 | CSharp7.cs:82:23:82:23 | Item2 |
912
| (String,String) | (string, string) | ValueTuple<string, string> | 2 | 0 | CSharp7.cs:87:19:87:27 | Item1 |
1013
| (String,String) | (string, string) | ValueTuple<string, string> | 2 | 1 | CSharp7.cs:87:30:87:33 | Item2 |

0 commit comments

Comments
 (0)