Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-ctor-eval: Properly eval strings #6276

Merged
merged 1 commit into from
Feb 5, 2024
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
11 changes: 3 additions & 8 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,9 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
// GC data (structs and arrays) must be handled with the special global-
// creating logic later down. But MVP types as well as i31s (even
// externalized i31s) can be handled by the general makeConstantExpression
// logic (which knows how to handle externalization, for i31s).
if (!value.isData()) {
// logic (which knows how to handle externalization, for i31s; and it also
// can handle string constants).
if (!value.isData() || value.type.getHeapType().isString()) {
return builder.makeConstantExpression(original);
}

Expand Down Expand Up @@ -889,12 +890,6 @@ 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
7 changes: 3 additions & 4 deletions test/lit/ctor-eval/string.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
;; 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))
Expand All @@ -16,8 +13,10 @@
(global.get $global)
)
)
;; CHECK: (type $0 (func (result anyref)))

;; CHECK: (export "test" (func $test_1))

;; CHECK: (func $test_1 (type $0) (result anyref)
;; CHECK-NEXT: (global.get $global)
;; CHECK-NEXT: (string.const "one")
;; CHECK-NEXT: )
Loading