Skip to content

Commit c397abb

Browse files
authored
Fix incorrect flow state after throwing (#1262)
1 parent e68fbb4 commit c397abb

27 files changed

+2441
-2334
lines changed

src/compiler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,15 +2820,13 @@ export class Compiler extends DiagnosticEmitter {
28202820
private compileThrowStatement(
28212821
statement: ThrowStatement
28222822
): ExpressionRef {
2823+
// TODO: requires exception-handling spec.
28232824
var flow = this.currentFlow;
28242825

28252826
// Remember that this branch throws
28262827
flow.set(FlowFlags.THROWS | FlowFlags.TERMINATES);
28272828

28282829
var stmts = new Array<ExpressionRef>();
2829-
this.finishAutoreleases(flow, stmts);
2830-
2831-
// TODO: requires exception-handling spec.
28322830
var value = statement.value;
28332831
var message: Expression | null = null;
28342832
if (value.kind == NodeKind.NEW) {
@@ -2838,6 +2836,11 @@ export class Compiler extends DiagnosticEmitter {
28382836
stmts.push(
28392837
this.makeAbort(message, statement)
28402838
);
2839+
// generates dead code (after unreachable) but still updates state
2840+
var dropped = new Array<ExpressionRef>();
2841+
this.performAutoreleases(flow, dropped);
2842+
this.finishAutoreleases(flow, dropped);
2843+
flow.freeScopedLocals();
28412844

28422845
return this.module.flatten(stmts);
28432846
}

tests/compiler/assert-nonnull.untouched.wat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@
139139
local.get $2
140140
i32.eqz
141141
if
142-
local.get $2
143-
call $~lib/rt/stub/__release
144142
i32.const 208
145143
i32.const 160
146144
i32.const 108

tests/compiler/class.untouched.wat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@
483483
i32.shr_u
484484
i32.gt_u
485485
if
486-
local.get $0
487-
call $~lib/rt/stub/__release
488486
i32.const 32
489487
i32.const 80
490488
i32.const 57

tests/compiler/infer-array.untouched.wat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,6 @@
17261726
local.get $2
17271727
i32.eqz
17281728
if
1729-
local.get $2
1730-
call $~lib/rt/stub/__release
17311729
i32.const 640
17321730
i32.const 128
17331731
i32.const 108

tests/compiler/resolve-elementaccess.untouched.wat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@
409409
i32.shr_u
410410
i32.gt_u
411411
if
412-
local.get $0
413-
call $~lib/rt/stub/__release
414412
i32.const 32
415413
i32.const 80
416414
i32.const 18

tests/compiler/retain-release-sanity.untouched.wat

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,6 @@
17921792
i32.shr_u
17931793
i32.gt_u
17941794
if
1795-
local.get $0
1796-
call $~lib/rt/pure/__release
17971795
i32.const 32
17981796
i32.const 80
17991797
i32.const 57
@@ -3452,8 +3450,6 @@
34523450
i32.shr_u
34533451
i32.gt_u
34543452
if
3455-
local.get $0
3456-
call $~lib/rt/pure/__release
34573453
i32.const 32
34583454
i32.const 80
34593455
i32.const 57
@@ -3534,8 +3530,6 @@
35343530
i32.shr_u
35353531
i32.gt_u
35363532
if
3537-
local.get $0
3538-
call $~lib/rt/pure/__release
35393533
i32.const 32
35403534
i32.const 80
35413535
i32.const 57

tests/compiler/retain-release.untouched.wat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,6 @@
718718
global.get $retain-release/REF
719719
call $~lib/rt/stub/__retain
720720
local.set $2
721-
local.get $2
722-
call $~lib/rt/stub/__release
723721
i32.const 32
724722
i32.const 64
725723
i32.const 367

tests/compiler/std/array-access.untouched.wat

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
local.get $2
6363
i32.eqz
6464
if
65-
local.get $2
66-
call $~lib/rt/stub/__release
6765
i32.const 144
6866
i32.const 96
6967
i32.const 108
@@ -159,8 +157,6 @@
159157
local.get $2
160158
i32.eqz
161159
if
162-
local.get $2
163-
call $~lib/rt/stub/__release
164160
i32.const 144
165161
i32.const 96
166162
i32.const 108
@@ -453,8 +449,6 @@
453449
local.get $2
454450
i32.eqz
455451
if
456-
local.get $2
457-
call $~lib/rt/stub/__release
458452
i32.const 144
459453
i32.const 96
460454
i32.const 108

tests/compiler/std/array.optimized.wat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,8 +1532,6 @@
15321532
i32.const 268435452
15331533
i32.gt_u
15341534
if
1535-
local.get $3
1536-
call $~lib/rt/pure/__release
15371535
i32.const 1040
15381536
i32.const 1088
15391537
i32.const 57
@@ -2816,8 +2814,6 @@
28162814
local.tee $0
28172815
i32.eqz
28182816
if
2819-
local.get $0
2820-
call $~lib/rt/pure/__release
28212817
i32.const 4928
28222818
i32.const 1088
28232819
i32.const 108

tests/compiler/std/array.untouched.wat

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,6 @@
20112011
i32.shr_u
20122012
i32.gt_u
20132013
if
2014-
local.get $0
2015-
call $~lib/rt/pure/__release
20162014
i32.const 32
20172015
i32.const 80
20182016
i32.const 57
@@ -2140,8 +2138,6 @@
21402138
i32.shr_u
21412139
i32.gt_u
21422140
if
2143-
local.get $0
2144-
call $~lib/rt/pure/__release
21452141
i32.const 32
21462142
i32.const 336
21472143
i32.const 18
@@ -4454,8 +4450,6 @@
44544450
i32.shr_u
44554451
i32.gt_u
44564452
if
4457-
local.get $1
4458-
call $~lib/rt/pure/__release
44594453
i32.const 32
44604454
i32.const 80
44614455
i32.const 229
@@ -5496,8 +5490,6 @@
54965490
local.get $2
54975491
i32.eqz
54985492
if
5499-
local.get $2
5500-
call $~lib/rt/pure/__release
55015493
i32.const 3920
55025494
i32.const 80
55035495
i32.const 108
@@ -9744,8 +9736,6 @@
97449736
i32.shr_u
97459737
i32.gt_u
97469738
if
9747-
local.get $0
9748-
call $~lib/rt/pure/__release
97499739
i32.const 32
97509740
i32.const 80
97519741
i32.const 57
@@ -9838,8 +9828,6 @@
98389828
i32.const 0
98399829
i32.lt_s
98409830
if
9841-
local.get $2
9842-
call $~lib/rt/pure/__release
98439831
i32.const 496
98449832
i32.const 80
98459833
i32.const 120
@@ -10144,8 +10132,6 @@
1014410132
local.get $2
1014510133
i32.eqz
1014610134
if
10147-
local.get $2
10148-
call $~lib/rt/pure/__release
1014910135
i32.const 3920
1015010136
i32.const 80
1015110137
i32.const 108
@@ -10280,8 +10266,6 @@
1028010266
i32.shr_u
1028110267
i32.gt_u
1028210268
if
10283-
local.get $0
10284-
call $~lib/rt/pure/__release
1028510269
i32.const 32
1028610270
i32.const 80
1028710271
i32.const 57
@@ -10389,8 +10373,6 @@
1038910373
i32.const 0
1039010374
i32.lt_s
1039110375
if
10392-
local.get $2
10393-
call $~lib/rt/pure/__release
1039410376
i32.const 496
1039510377
i32.const 80
1039610378
i32.const 120
@@ -10688,8 +10670,6 @@
1068810670
local.get $2
1068910671
i32.eqz
1069010672
if
10691-
local.get $2
10692-
call $~lib/rt/pure/__release
1069310673
i32.const 3920
1069410674
i32.const 80
1069510675
i32.const 108
@@ -11584,8 +11564,6 @@
1158411564
i32.shr_u
1158511565
i32.gt_u
1158611566
if
11587-
local.get $0
11588-
call $~lib/rt/pure/__release
1158911567
i32.const 32
1159011568
i32.const 80
1159111569
i32.const 57
@@ -11864,8 +11842,6 @@
1186411842
i32.const 0
1186511843
i32.lt_s
1186611844
if
11867-
local.get $2
11868-
call $~lib/rt/pure/__release
1186911845
i32.const 496
1187011846
i32.const 80
1187111847
i32.const 120
@@ -12141,8 +12117,6 @@
1214112117
local.get $2
1214212118
i32.eqz
1214312119
if
12144-
local.get $2
12145-
call $~lib/rt/pure/__release
1214612120
i32.const 3920
1214712121
i32.const 80
1214812122
i32.const 108

0 commit comments

Comments
 (0)