summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/properties.h4
-rw-r--r--src/tools/wasm-ctor-eval.cpp5
-rw-r--r--test/lit/ctor-eval/extern.wast32
3 files changed, 39 insertions, 2 deletions
diff --git a/src/ir/properties.h b/src/ir/properties.h
index 0fee67ad2..13eea6ba2 100644
--- a/src/ir/properties.h
+++ b/src/ir/properties.h
@@ -83,7 +83,9 @@ inline bool isNamedControlFlow(Expression* curr) {
// isValidInConstantExpression or find better names(#4845)
inline bool isSingleConstantExpression(const Expression* curr) {
return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() ||
- curr->is<StringConst>();
+ curr->is<StringConst>() ||
+ (curr->is<RefAs>() && (curr->cast<RefAs>()->op == ExternExternalize ||
+ curr->cast<RefAs>()->op == ExternInternalize));
}
inline bool isConstantExpression(const Expression* curr) {
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 195a5350f..5e1bf6b22 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -1064,6 +1064,11 @@ int main(int argc, const char* argv[]) {
if (canEval(wasm)) {
evalCtors(wasm, ctors, keptExports);
+ if (!WasmValidator().validate(wasm)) {
+ std::cout << wasm << '\n';
+ Fatal() << "error in validating output";
+ }
+
// Do some useful optimizations after the evalling
{
PassRunner passRunner(&wasm);
diff --git a/test/lit/ctor-eval/extern.wast b/test/lit/ctor-eval/extern.wast
index 1bd738380..462e64290 100644
--- a/test/lit/ctor-eval/extern.wast
+++ b/test/lit/ctor-eval/extern.wast
@@ -1,22 +1,37 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
-;; RUN: wasm-ctor-eval %s --ctors=test1,test2 --kept-exports=test1,test2 --quiet -all -S -o - | filecheck %s
+;; RUN: wasm-ctor-eval %s --ctors=test1,test2,test3 --kept-exports=test1,test2,test3 --quiet -all -S -o - | filecheck %s
(module
;; CHECK: (type $array (array (mut i8)))
(type $array (array (mut i8)))
+ ;; CHECK: (type $struct (struct (field externref)))
+ (type $struct (struct (field externref)))
+
;; CHECK: (type $none_=>_externref (func (result externref)))
+ ;; CHECK: (type $none_=>_anyref (func (result anyref)))
+
;; CHECK: (global $ctor-eval$global (ref $array) (array.new_fixed $array
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: (i32.const 3)
;; CHECK-NEXT: ))
+ ;; CHECK: (global $ctor-eval$global_0 (ref $struct) (struct.new $struct
+ ;; CHECK-NEXT: (extern.externalize
+ ;; CHECK-NEXT: (i31.new
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: ))
+
;; CHECK: (export "test1" (func $test1_0))
(export "test1" (func $test1))
;; CHECK: (export "test2" (func $test2_0))
(export "test2" (func $test2))
+ ;; CHECK: (export "test3" (func $test3_0))
+ (export "test3" (func $test3))
(func $test1 (result externref)
;; This will remain almost the same, even though we eval it, since the
@@ -42,6 +57,17 @@
)
)
)
+
+ (func $test3 (result anyref)
+ ;; This will add a global that contains an externalization operation.
+ (struct.new $struct
+ (extern.externalize
+ (i31.new
+ (i32.const 1)
+ )
+ )
+ )
+ )
)
;; CHECK: (func $test1_0 (type $none_=>_externref) (result externref)
@@ -57,3 +83,7 @@
;; CHECK-NEXT: (global.get $ctor-eval$global)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
+
+;; CHECK: (func $test3_0 (type $none_=>_anyref) (result anyref)
+;; CHECK-NEXT: (global.get $ctor-eval$global_0)
+;; CHECK-NEXT: )