Skip to content

Commit

Permalink
Fix array assign ppmm bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kroppeb committed Jan 10, 2025
1 parent 203a537 commit 42d672b
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,12 @@ private static Pair<Exprent, VarExprent> findFirstValidUsage(VarExprent match, E
for (int i = exprents.size() - 1; i >= 0; i--) {
Exprent ex = exprents.get(i);

// Skip LHS of assignment as it is invalid
if (expr instanceof AssignmentExprent asExpr && ex == asExpr.getLeft()) {
// Avoid making something like `++a = 5`. It shouldn't happen but better be safe than sorry.
if (expr instanceof AssignmentExprent asExpr &&
ex == asExpr.getLeft() &&
ex instanceof VarExprent innerEx &&
innerEx.getIndex() == match.getIndex()
) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions testData/results/pkg/TestArrayPPMM.dec
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class TestArrayPPMM {
}// 40

public void test9(int[] array, int i) {
array[i] = ++i;// 43
array[++i] = i;// 43
}// 44

public void test10(int i) {
this.getArray()[i] = ++i;// 47
this.getArray()[++i] = i;// 47
}// 48

private void accept(int i, int j) {
Expand Down Expand Up @@ -207,7 +207,7 @@ class 'pkg/TestArrayPPMM' {
1 40
2 40
3 40
4 40
5 40
6 40
7 41
}
Expand All @@ -220,7 +220,7 @@ class 'pkg/TestArrayPPMM' {
4 44
5 44
6 44
7 44
8 44
9 44
a 45
}
Expand Down
172 changes: 167 additions & 5 deletions testData/results/pkg/TestPPMM.dec
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,44 @@ public class TestPPMM {
t2(a, a);// 98
}// 99

public void ppiAssign() {
int a = 0;// 102
a++;// 103
a = 5;// 104
System.out.println();// 105
a = ++a + 5;// 106 107
System.out.println();// 108
a = 5 * ++a;// 109 110
System.out.println();// 111
t(a);// 112
}// 113

public void ppiAssignPhi(boolean b) {
int a = 0;// 117
if (b) {// 118
a++;// 119
a = 5;// 120
}

System.out.println();// 122
if (b) {// 123
a = ++a + 5;// 124 125
}

System.out.println();// 127
if (b) {// 128
a = 5 * ++a;// 129 130
}

System.out.println();// 132
t(a);// 133
}// 134

private static void t(int x) {
}// 102
}// 137

private static void t2(int x, int y) {
}// 106
}// 141
}

class 'pkg/TestPPMM' {
Expand Down Expand Up @@ -375,12 +408,114 @@ class 'pkg/TestPPMM' {
66 82
}

method 't (I)V' {
method 'ppiAssign ()V' {
0 85
1 85
2 86
3 86
4 86
5 87
6 87
7 88
8 88
9 88
a 88
b 88
c 88
d 89
e 89
f 89
11 89
12 89
13 89
14 90
15 90
16 90
17 90
18 90
19 90
1a 91
1b 91
1c 91
1d 91
1f 91
20 91
21 92
22 92
23 92
24 92
25 92
26 92
27 93
28 93
29 93
2a 93
2b 94
}

method 'ppiAssignPhi (Z)V' {
0 97
1 97
2 98
3 98
4 98
5 98
6 99
7 99
8 99
9 100
a 100
b 103
c 103
d 103
e 103
f 103
10 103
11 104
12 104
13 104
14 104
15 105
16 105
17 105
19 105
1a 105
1b 105
1c 108
1d 108
1e 108
1f 108
20 108
21 108
22 109
23 109
24 109
25 109
26 110
27 110
28 110
29 110
2b 110
2c 110
2d 113
2e 113
2f 113
30 113
31 113
32 113
33 114
34 114
35 114
36 114
37 115
}

method 't (I)V' {
0 118
}

method 't2 (II)V' {
0 88
0 121
}
}

Expand Down Expand Up @@ -454,4 +589,31 @@ Lines mapping:
98 <-> 82
99 <-> 83
102 <-> 86
106 <-> 89
103 <-> 87
104 <-> 88
105 <-> 89
106 <-> 90
107 <-> 90
108 <-> 91
109 <-> 92
110 <-> 92
111 <-> 93
112 <-> 94
113 <-> 95
117 <-> 98
118 <-> 99
119 <-> 100
120 <-> 101
122 <-> 104
123 <-> 105
124 <-> 106
125 <-> 106
127 <-> 109
128 <-> 110
129 <-> 111
130 <-> 111
132 <-> 114
133 <-> 115
134 <-> 116
137 <-> 119
141 <-> 122
35 changes: 35 additions & 0 deletions testData/src/java8/pkg/TestPPMM.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ public void doubleppi() {
t2(a, a);
}

public void ppiAssign() {
int a = 0;
++a;
a = 5;
System.out.println();
++a;
a = a + 5;
System.out.println();
++a;
a = 5 * a;
System.out.println();
t(a);
}


public void ppiAssignPhi(boolean b) {
int a = 0;
if (b) {
++a;
a = 5;
}
System.out.println();
if (b) {
++a;
a = a + 5;
}
System.out.println();
if (b) {
++a;
a = 5 * a;
}
System.out.println();
t(a);
}

private static void t(int x){
}

Expand Down

0 comments on commit 42d672b

Please sign in to comment.