diff options
-rw-r--r-- | src/ir/eh-utils.cpp | 5 | ||||
-rw-r--r-- | src/ir/eh-utils.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 5 | ||||
-rw-r--r-- | test/lit/binary/stacky-eh-legacy.test | 4 | ||||
-rw-r--r-- | test/lit/binary/stacky-eh-legacy.test.wasm | bin | 47 -> 86 bytes |
5 files changed, 17 insertions, 7 deletions
diff --git a/src/ir/eh-utils.cpp b/src/ir/eh-utils.cpp index 70b5452a6..6d65de4ad 100644 --- a/src/ir/eh-utils.cpp +++ b/src/ir/eh-utils.cpp @@ -148,8 +148,9 @@ void handleBlockNestedPop(Try* try_, Function* func, Module& wasm) { } } -void handleBlockNestedPops(Function* func, Module& wasm) { - if (!wasm.features.hasExceptionHandling()) { +void handleBlockNestedPops(Function* func, Module& wasm, FeaturePolicy policy) { + if (policy == FeaturePolicy::SkipIfNoEH && + !wasm.features.hasExceptionHandling()) { return; } FindAll<Try> trys(func->body); diff --git a/src/ir/eh-utils.h b/src/ir/eh-utils.h index 79ccbc507..ee5ad661d 100644 --- a/src/ir/eh-utils.h +++ b/src/ir/eh-utils.h @@ -38,8 +38,14 @@ bool containsValidDanglingPop(Expression* catchBody); // '(local.get $new)' where the 'pop' used to be. void handleBlockNestedPop(Try* try_, Function* func, Module& wasm); -// Calls handleBlockNestedPop for each 'Try's in a given function. -void handleBlockNestedPops(Function* func, Module& wasm); +enum class FeaturePolicy { SkipIfNoEH, RunIfNoEH }; + +// Calls handleBlockNestedPop for each 'Try's in a given function. By default, +// does no work if EH is not enabled, but this can be overridden with the +// RunIfNoEH policy. +void handleBlockNestedPops(Function* func, + Module& wasm, + FeaturePolicy policy = FeaturePolicy::SkipIfNoEH); // Given a catch body, find the pop corresponding to the catch. There might be // pops nested inside a try inside this catch, and we must ignore them, like diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index fcb1fc48d..a51337cda 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1018,7 +1018,10 @@ Result<> IRBuilder::visitEnd() { func->body = maybeWrapForLabel(*expr); labelDepths.clear(); if (scope.needsPopFixup()) { - EHUtils::handleBlockNestedPops(func, wasm); + // We may be in the binary parser, where pops need to be fixed up before + // we know that EH will be enabled. + EHUtils::handleBlockNestedPops( + func, wasm, EHUtils::FeaturePolicy::RunIfNoEH); } this->func = nullptr; blockHint = 0; diff --git a/test/lit/binary/stacky-eh-legacy.test b/test/lit/binary/stacky-eh-legacy.test index c77435f0b..792c436d5 100644 --- a/test/lit/binary/stacky-eh-legacy.test +++ b/test/lit/binary/stacky-eh-legacy.test @@ -35,7 +35,7 @@ ;; The fixup will hoist the 'pop' and create another local to store it right ;; after 'catch'. -;; RUN: wasm-opt -all %s.wasm -S -o - | filecheck %s +;; RUN: wasm-opt %s.wasm -S -o - | filecheck %s ;; CHECK: (type $0 (func (param i32))) @@ -43,7 +43,7 @@ ;; CHECK: (tag $tag$0 (param i32)) -;; CHECK: (func $0 (type $1) +;; CHECK: (func $0 ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) diff --git a/test/lit/binary/stacky-eh-legacy.test.wasm b/test/lit/binary/stacky-eh-legacy.test.wasm Binary files differindex 992273cae..8da1d0238 100644 --- a/test/lit/binary/stacky-eh-legacy.test.wasm +++ b/test/lit/binary/stacky-eh-legacy.test.wasm |