diff options
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 6 | ||||
-rw-r--r-- | test/lit/ctor-eval/string.wast | 23 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index eb2a4eb5d..9aa41c04d 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -889,6 +889,12 @@ public: } else if (heapType.isArray()) { // TODO: for repeated identical values, can use ArrayNew init = builder.makeArrayNewFixed(heapType, args); + } else if (heapType.isString()) { + std::string s; + for (auto c : values) { + s += char(c.getInteger()); + } + init = builder.makeStringConst(s); } else { WASM_UNREACHABLE("bad gc type"); } diff --git a/test/lit/ctor-eval/string.wast b/test/lit/ctor-eval/string.wast new file mode 100644 index 000000000..916fc2a28 --- /dev/null +++ b/test/lit/ctor-eval/string.wast @@ -0,0 +1,23 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s + +;; We should not error on precomputing this string. Nothing should change in +;; the output, as precomputing a string results in an identical string. + +(module + ;; CHECK: (type $0 (func (result anyref))) + + ;; CHECK: (global $global (ref string) (string.const "one")) + (global $global (ref string) (string.const "one")) + + (export "test" (func $test)) + + (func $test (result anyref) + (global.get $global) + ) +) +;; CHECK: (export "test" (func $test_1)) + +;; CHECK: (func $test_1 (type $0) (result anyref) +;; CHECK-NEXT: (global.get $global) +;; CHECK-NEXT: ) |