Skip to content

Commit ccd7c89

Browse files
ImplOfAnImplkripken
authored andcommitted
Fix for issue 5226 (#5227)
Handle a variable that is never assigned to in aggressiveVariableElimination
1 parent 10151e7 commit ccd7c89

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

tests/optimizer/test-js-optimizer-shiftsAggressive-output.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ function __ZNSt3__111__call_onceERVmPvPFvS2_E($flag, $arg, $func) {
33
$arg = $arg | 0;
44
$func = $func | 0;
55
var $2 = 0;
6+
0;
67
$2 = cheez();
78
whee1($flag + 1 | 0);
89
whee2($flag + 1 | 0);
910
whee3($flag + 1 | 0);
11+
whee4(1 + 0);
1012
}
1113

tests/optimizer/test-js-optimizer-shiftsAggressive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ function __ZNSt3__111__call_onceERVmPvPFvS2_E($flag,$arg,$func){
22
$flag=($flag)|0;
33
$arg=($arg)|0;
44
$func=($func)|0;
5-
var $1=0,$2=0,$3=0;
5+
var $1=0,$2=0,$3=0,$initializedAndNotReassigned=0;
66
$1;
77
$2 = cheez();
88
$3 = $flag + 1 | 0;
99
whee1($3);
1010
whee2($3);
1111
whee3($3);
12+
whee4(1 + $initializedAndNotReassigned);
1213
}
1314
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["__ZNSt3__111__call_onceERVmPvPFvS2_E"]

tools/js-optimizer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,6 +4847,11 @@ function aggressiveVariableEliminationInternal(func, asmData) {
48474847
}
48484848
values[name] = node;
48494849
}
4850+
// 'def' is non-null only if the variable was explicitly re-assigned after its definition.
4851+
// If it wasn't, the initial value should be used, which is supposed to always be zero.
4852+
else if (name in asmData.vars) {
4853+
values[name] = makeAsmCoercedZero(asmData.vars[name])
4854+
}
48504855
return node;
48514856
}
48524857

0 commit comments

Comments
 (0)