aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-08 15:12:12 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-08 15:12:12 -0800
commit486db79e93244b743b8ce8bef83ce93ef9470e16 (patch)
treeea8dc3bb76cb10a149a4b55ff75255da1350a387
parent14bb76d546b774bf823e3a578aa69f7d1bff0f2c (diff)
fix bug with lack of recursion in simplifyBitops
-rw-r--r--tools/js-optimizer.js15
-rw-r--r--tools/test-js-optimizer-output.js3
-rw-r--r--tools/test-js-optimizer.js3
3 files changed, 16 insertions, 5 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 103fb1fe..22d0f4d1 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -418,20 +418,25 @@ function simplifyExpressionsPre(ast) {
var rerun = true;
while (rerun) {
rerun = false;
- traverseGenerated(ast, function(node, type, stack) {
+ traverseGenerated(ast, function process(node, type, stack) {
if (type == 'binary' && node[1] == '|' && (jsonCompare(node[2], ZERO) || jsonCompare(node[3], ZERO))) {
- stack.push(1); // From here on up, no need for this kind of correction, it's done at the top
-
// We might be able to remove this correction
- for (var i = stack.length-2; i >= 0; i--) {
+ for (var i = stack.length-1; i >= 0; i--) {
if (stack[i] == 1) {
// Great, we can eliminate
rerun = true;
- return jsonCompare(node[2], ZERO) ? node[3] : node[2];
+ // we will replace ourselves with the non-zero side. Recursively process that node.
+ var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other;
+ while (other = process(result, result[0], stack)) {
+ result = other;
+ }
+ return result;
} else if (stack[i] == -1) {
break; // Too bad, we can't
}
}
+ stack.push(1); // From here on up, no need for this kind of correction, it's done at the top
+ // (Add this at the end, so it is only added if we did not remove it)
} else if (type == 'binary' && node[1] in USEFUL_BINARY_OPS) {
stack.push(1);
} else if ((type == 'binary' && node[1] in SAFE_BINARY_OPS) || type == 'num' || type == 'name') {
diff --git a/tools/test-js-optimizer-output.js b/tools/test-js-optimizer-output.js
index c95a36ff..5c06475e 100644
--- a/tools/test-js-optimizer-output.js
+++ b/tools/test-js-optimizer-output.js
@@ -290,5 +290,8 @@ function asmy() {
f((HEAPU8[_buf + i6 & 16777215] & 1) + i5 | 0);
f((HEAP8[_buf + i6 & 16777215] & 1) + i5 | 0);
f((HEAPU8[_buf + i6 & 16777215] & 1) + i5 | 0);
+ if ((_sbrk($419 | 0) | 0) == -1) {
+ print("fleefl");
+ }
}
diff --git a/tools/test-js-optimizer.js b/tools/test-js-optimizer.js
index 00d6c260..982e3230 100644
--- a/tools/test-js-optimizer.js
+++ b/tools/test-js-optimizer.js
@@ -400,5 +400,8 @@ function asmy() {
f((HEAPU8[_buf + i6 & 16777215] & 255 & 1) + i5 | 0);
f((HEAP8[_buf + i6 & 16777215] & 1 & 255) + i5 | 0);
f((HEAPU8[_buf + i6 & 16777215] & 1 & 255) + i5 | 0);
+ if ((_sbrk($419 | 0) | 0 | 0) == -1) {
+ print('fleefl');
+ }
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["abc", "xyz", "xyz2", "expr", "loopy", "bits", "maths", "hoisting", "demangle", "lua", "moreLabels", "notComps", "tricky", "asmy"]