Skip to content

Commit 79a750d

Browse files
authored
Merge pull request #1845 from AndreiDiaconu1/ircsharp-compiler-generated
C# IR: Framework for translating compiler generated elements
2 parents e899250 + 53ebe23 commit 79a750d

32 files changed

+2429
-488
lines changed

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private import TranslatedCondition
77
private import TranslatedElement
88
private import TranslatedExpr
99
private import TranslatedStmt
10+
private import desugar.Foreach
1011
private import TranslatedFunction
1112
private import semmle.code.csharp.ir.Util
1213
private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
@@ -136,6 +137,17 @@ private module Cached {
136137
)
137138
)
138139
or
140+
// Compiler generated foreach while loop:
141+
// Same as above
142+
exists(TranslatedForeachWhile s |
143+
result = s.getFirstInstruction() and
144+
exists(TranslatedElement inBody, InstructionTag tag |
145+
result = inBody.getInstructionSuccessor(tag, kind) and
146+
exists(TranslatedElement body | body = s.getBody() | inBody = body.getAChild*()) and
147+
instruction = inBody.getInstruction(tag)
148+
)
149+
)
150+
or
139151
// Do-while loop:
140152
// The back edge should be the edge(s) from the condition to the
141153
// body. This ensures that it's the back edge that will be pruned in a `do

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/internal/InstructionTag.qll

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import csharp
22
import semmle.code.csharp.ir.Util
33

4-
//private predicate fieldIsInitialized(Field field) {
5-
// exists(field.getInitializer())
6-
//}
74
private predicate elementIsInitialized(int elementIndex) {
85
exists(ArrayInitWithMod initList | initList.isInitialized(elementIndex))
96
}
@@ -54,6 +51,7 @@ newtype TInstructionTag =
5451
BoolConversionConstantTag() or
5552
BoolConversionCompareTag() or
5653
LoadTag() or // Implicit load due to lvalue-to-rvalue conversion
54+
AddressTag() or
5755
CatchTag() or
5856
ThrowTag() or
5957
UnwindTag() or
@@ -192,16 +190,8 @@ string getInstructionTagId(TInstructionTag tag) {
192190
or
193191
tag = GeneratedBranchTag() and result = "GeneratedBranchTag"
194192
or
195-
// TODO: Reread
196-
// exists(Field field, Class cls, int index, string tagName |
197-
// field = cls.getCanonicalMember(index) and
198-
// (
199-
// tag = InitializerFieldAddressTag(field) and tagName = "InitFieldAddr" or
200-
// tag = InitializerFieldDefaultValueTag(field) and tagName = "InitFieldDefVal" or
201-
// tag = InitializerFieldDefaultValueStoreTag(field) and tagName = "InitFieldDefValStore"
202-
// ) and
203-
// result = tagName + "(" + index + ")"
204-
// ) or
193+
tag = AddressTag() and result = "AddressTag"
194+
or
205195
exists(int index, string tagName |
206196
(
207197
tag = InitializerElementIndexTag(index) and tagName = "InitElemIndex"

0 commit comments

Comments
 (0)