Skip to content

Commit 42d672b

Browse files
committed
Fix array assign ppmm bug
1 parent 203a537 commit 42d672b

File tree

4 files changed

+212
-11
lines changed

4 files changed

+212
-11
lines changed

src/org/jetbrains/java/decompiler/modules/decompiler/SimplifyExprentsHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,12 @@ private static Pair<Exprent, VarExprent> findFirstValidUsage(VarExprent match, E
729729
for (int i = exprents.size() - 1; i >= 0; i--) {
730730
Exprent ex = exprents.get(i);
731731

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

testData/results/pkg/TestArrayPPMM.dec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public class TestArrayPPMM {
3838
}// 40
3939

4040
public void test9(int[] array, int i) {
41-
array[i] = ++i;// 43
41+
array[++i] = i;// 43
4242
}// 44
4343

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

4848
private void accept(int i, int j) {
@@ -207,7 +207,7 @@ class 'pkg/TestArrayPPMM' {
207207
1 40
208208
2 40
209209
3 40
210-
4 40
210+
5 40
211211
6 40
212212
7 41
213213
}
@@ -220,7 +220,7 @@ class 'pkg/TestArrayPPMM' {
220220
4 44
221221
5 44
222222
6 44
223-
7 44
223+
8 44
224224
9 44
225225
a 45
226226
}

testData/results/pkg/TestPPMM.dec

Lines changed: 167 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,44 @@ public class TestPPMM {
8282
t2(a, a);// 98
8383
}// 99
8484

85+
public void ppiAssign() {
86+
int a = 0;// 102
87+
a++;// 103
88+
a = 5;// 104
89+
System.out.println();// 105
90+
a = ++a + 5;// 106 107
91+
System.out.println();// 108
92+
a = 5 * ++a;// 109 110
93+
System.out.println();// 111
94+
t(a);// 112
95+
}// 113
96+
97+
public void ppiAssignPhi(boolean b) {
98+
int a = 0;// 117
99+
if (b) {// 118
100+
a++;// 119
101+
a = 5;// 120
102+
}
103+
104+
System.out.println();// 122
105+
if (b) {// 123
106+
a = ++a + 5;// 124 125
107+
}
108+
109+
System.out.println();// 127
110+
if (b) {// 128
111+
a = 5 * ++a;// 129 130
112+
}
113+
114+
System.out.println();// 132
115+
t(a);// 133
116+
}// 134
117+
85118
private static void t(int x) {
86-
}// 102
119+
}// 137
87120

88121
private static void t2(int x, int y) {
89-
}// 106
122+
}// 141
90123
}
91124

92125
class 'pkg/TestPPMM' {
@@ -375,12 +408,114 @@ class 'pkg/TestPPMM' {
375408
66 82
376409
}
377410

378-
method 't (I)V' {
411+
method 'ppiAssign ()V' {
379412
0 85
413+
1 85
414+
2 86
415+
3 86
416+
4 86
417+
5 87
418+
6 87
419+
7 88
420+
8 88
421+
9 88
422+
a 88
423+
b 88
424+
c 88
425+
d 89
426+
e 89
427+
f 89
428+
11 89
429+
12 89
430+
13 89
431+
14 90
432+
15 90
433+
16 90
434+
17 90
435+
18 90
436+
19 90
437+
1a 91
438+
1b 91
439+
1c 91
440+
1d 91
441+
1f 91
442+
20 91
443+
21 92
444+
22 92
445+
23 92
446+
24 92
447+
25 92
448+
26 92
449+
27 93
450+
28 93
451+
29 93
452+
2a 93
453+
2b 94
454+
}
455+
456+
method 'ppiAssignPhi (Z)V' {
457+
0 97
458+
1 97
459+
2 98
460+
3 98
461+
4 98
462+
5 98
463+
6 99
464+
7 99
465+
8 99
466+
9 100
467+
a 100
468+
b 103
469+
c 103
470+
d 103
471+
e 103
472+
f 103
473+
10 103
474+
11 104
475+
12 104
476+
13 104
477+
14 104
478+
15 105
479+
16 105
480+
17 105
481+
19 105
482+
1a 105
483+
1b 105
484+
1c 108
485+
1d 108
486+
1e 108
487+
1f 108
488+
20 108
489+
21 108
490+
22 109
491+
23 109
492+
24 109
493+
25 109
494+
26 110
495+
27 110
496+
28 110
497+
29 110
498+
2b 110
499+
2c 110
500+
2d 113
501+
2e 113
502+
2f 113
503+
30 113
504+
31 113
505+
32 113
506+
33 114
507+
34 114
508+
35 114
509+
36 114
510+
37 115
511+
}
512+
513+
method 't (I)V' {
514+
0 118
380515
}
381516

382517
method 't2 (II)V' {
383-
0 88
518+
0 121
384519
}
385520
}
386521

@@ -454,4 +589,31 @@ Lines mapping:
454589
98 <-> 82
455590
99 <-> 83
456591
102 <-> 86
457-
106 <-> 89
592+
103 <-> 87
593+
104 <-> 88
594+
105 <-> 89
595+
106 <-> 90
596+
107 <-> 90
597+
108 <-> 91
598+
109 <-> 92
599+
110 <-> 92
600+
111 <-> 93
601+
112 <-> 94
602+
113 <-> 95
603+
117 <-> 98
604+
118 <-> 99
605+
119 <-> 100
606+
120 <-> 101
607+
122 <-> 104
608+
123 <-> 105
609+
124 <-> 106
610+
125 <-> 106
611+
127 <-> 109
612+
128 <-> 110
613+
129 <-> 111
614+
130 <-> 111
615+
132 <-> 114
616+
133 <-> 115
617+
134 <-> 116
618+
137 <-> 119
619+
141 <-> 122

testData/src/java8/pkg/TestPPMM.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ public void doubleppi() {
9898
t2(a, a);
9999
}
100100

101+
public void ppiAssign() {
102+
int a = 0;
103+
++a;
104+
a = 5;
105+
System.out.println();
106+
++a;
107+
a = a + 5;
108+
System.out.println();
109+
++a;
110+
a = 5 * a;
111+
System.out.println();
112+
t(a);
113+
}
114+
115+
116+
public void ppiAssignPhi(boolean b) {
117+
int a = 0;
118+
if (b) {
119+
++a;
120+
a = 5;
121+
}
122+
System.out.println();
123+
if (b) {
124+
++a;
125+
a = a + 5;
126+
}
127+
System.out.println();
128+
if (b) {
129+
++a;
130+
a = 5 * a;
131+
}
132+
System.out.println();
133+
t(a);
134+
}
135+
101136
private static void t(int x){
102137
}
103138

0 commit comments

Comments
 (0)