Skip to content

Commit 195b99c

Browse files
author
AndreiDiaconu1
committed
PR fixes
1 parent 442c9f2 commit 195b99c

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ class TranslatedForStmt extends TranslatedLoop {
651651
override ForStmt stmt;
652652

653653
override TranslatedElement getChild(int id) {
654-
initializerIndices(id) and result = this.getDeclAndInit(id)
654+
initializerIndex(id) and result = this.getDeclAndInit(id)
655655
or
656-
updateIndices(id) and result = this.getUpdate(id - initializersNo())
656+
result = this.getUpdate(updateIndex(id))
657657
or
658658
id = initializersNo() + updatesNo() and result = this.getCondition()
659659
or
@@ -674,10 +674,11 @@ class TranslatedForStmt extends TranslatedLoop {
674674

675675
private int updatesNo() { result = count(stmt.getAnUpdate()) }
676676

677-
private predicate initializerIndices(int index) { index in [0 .. initializersNo() - 1] }
677+
private predicate initializerIndex(int index) { index in [0 .. initializersNo() - 1] }
678678

679-
private predicate updateIndices(int index) {
680-
index in [initializersNo() .. initializersNo() + updatesNo() - 1]
679+
private int updateIndex(int index) {
680+
result in [0 .. updatesNo() - 1] and
681+
index = initializersNo() + result
681682
}
682683

683684
override Instruction getFirstInstruction() {
@@ -688,13 +689,11 @@ class TranslatedForStmt extends TranslatedLoop {
688689

689690
override Instruction getChildSuccessor(TranslatedElement child) {
690691
exists(int index |
691-
this.hasInitialization() and
692692
child = this.getDeclAndInit(index) and
693693
index < initializersNo() - 1 and
694694
result = this.getDeclAndInit(index + 1).getFirstInstruction()
695695
)
696696
or
697-
this.hasInitialization() and
698697
child = this.getDeclAndInit(initializersNo() - 1) and
699698
result = this.getFirstConditionInstruction()
700699
or
@@ -706,13 +705,10 @@ class TranslatedForStmt extends TranslatedLoop {
706705
)
707706
or
708707
exists(int index |
709-
this.hasUpdate() and
710708
child = this.getUpdate(index) and
711-
index < updatesNo() - 1 and
712709
result = this.getUpdate(index + 1).getFirstInstruction()
713710
)
714711
or
715-
this.hasUpdate() and
716712
child = this.getUpdate(updatesNo() - 1) and
717713
result = this.getFirstConditionInstruction()
718714
}

csharp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ stmts.cs:
11031103
# 77| r5_3(Int32) = Load : &:r5_2, ~mu0_2
11041104
# 77| r5_4(Boolean) = CompareLT : r5_1, r5_3
11051105
# 77| v5_5(Void) = ConditionalBranch : r5_4
1106-
#-----| False -> Block 1
1106+
#-----| False -> Block 7
11071107
#-----| True -> Block 6
11081108

11091109
# 79| Block 6
@@ -1114,33 +1114,37 @@ stmts.cs:
11141114
# 79| mu6_4(Int32) = Store : &:r6_0, r6_3
11151115
#-----| Goto (back edge) -> Block 5
11161116

1117-
# 83| System.Void test_stmts.doWhile()
1118-
# 83| Block 0
1119-
# 83| v0_0(Void) = EnterFunction :
1120-
# 83| mu0_1(null) = AliasedDefinition :
1121-
# 83| mu0_2(null) = UnmodeledDefinition :
1122-
# 85| r0_3(glval<Int32>) = VariableAddress[x] :
1123-
# 85| r0_4(Int32) = Constant[0] :
1124-
# 85| mu0_5(Int32) = Store : &:r0_3, r0_4
1117+
# 83| Block 7
1118+
# 83| v7_0(Void) = NoOp :
1119+
#-----| Goto (back edge) -> Block 7
1120+
1121+
# 88| System.Void test_stmts.doWhile()
1122+
# 88| Block 0
1123+
# 88| v0_0(Void) = EnterFunction :
1124+
# 88| mu0_1(null) = AliasedDefinition :
1125+
# 88| mu0_2(null) = UnmodeledDefinition :
1126+
# 90| r0_3(glval<Int32>) = VariableAddress[x] :
1127+
# 90| r0_4(Int32) = Constant[0] :
1128+
# 90| mu0_5(Int32) = Store : &:r0_3, r0_4
11251129
#-----| Goto -> Block 2
11261130

1127-
# 83| Block 1
1128-
# 83| v1_0(Void) = ReturnVoid :
1129-
# 83| v1_1(Void) = UnmodeledUse : mu*
1130-
# 83| v1_2(Void) = ExitFunction :
1131-
1132-
# 88| Block 2
1133-
# 88| r2_0(glval<Int32>) = VariableAddress[x] :
1134-
# 88| r2_1(Int32) = Load : &:r2_0, ~mu0_2
1135-
# 88| r2_2(Int32) = Constant[1] :
1136-
# 88| r2_3(Int32) = Add : r2_1, r2_2
1137-
# 88| r2_4(glval<Int32>) = VariableAddress[x] :
1138-
# 88| mu2_5(Int32) = Store : &:r2_4, r2_3
1139-
# 90| r2_6(glval<Int32>) = VariableAddress[x] :
1140-
# 90| r2_7(Int32) = Load : &:r2_6, ~mu0_2
1141-
# 90| r2_8(Int32) = Constant[10] :
1142-
# 90| r2_9(Boolean) = CompareLT : r2_7, r2_8
1143-
# 90| v2_10(Void) = ConditionalBranch : r2_9
1131+
# 88| Block 1
1132+
# 88| v1_0(Void) = ReturnVoid :
1133+
# 88| v1_1(Void) = UnmodeledUse : mu*
1134+
# 88| v1_2(Void) = ExitFunction :
1135+
1136+
# 93| Block 2
1137+
# 93| r2_0(glval<Int32>) = VariableAddress[x] :
1138+
# 93| r2_1(Int32) = Load : &:r2_0, ~mu0_2
1139+
# 93| r2_2(Int32) = Constant[1] :
1140+
# 93| r2_3(Int32) = Add : r2_1, r2_2
1141+
# 93| r2_4(glval<Int32>) = VariableAddress[x] :
1142+
# 93| mu2_5(Int32) = Store : &:r2_4, r2_3
1143+
# 95| r2_6(glval<Int32>) = VariableAddress[x] :
1144+
# 95| r2_7(Int32) = Load : &:r2_6, ~mu0_2
1145+
# 95| r2_8(Int32) = Constant[10] :
1146+
# 95| r2_9(Boolean) = CompareLT : r2_7, r2_8
1147+
# 95| v2_10(Void) = ConditionalBranch : r2_9
11441148
#-----| False -> Block 1
11451149
#-----| True (back edge) -> Block 2
11461150

csharp/ql/test/library-tests/ir/ir/stmts.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public static void forStmt()
7878
{
7979
a++;
8080
}
81+
82+
for( ; ; )
83+
{
84+
85+
}
8186
}
8287

8388
public static void doWhile()

0 commit comments

Comments
 (0)