Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,12 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
} 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");
}
Expand Down
23 changes: 23 additions & 0 deletions test/lit/ctor-eval/string.wast
Original file line number Diff line number Diff line change
@@ -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: )