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
38 changes: 37 additions & 1 deletion src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,43 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
return Literal(int32_t(data->values.size()));
}
Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEncode(StringEncode* curr) {
// For now we only support JS-style strings into arrays.
if (curr->op != StringEncodeWTF16Array) {
return Flow(NONCONSTANT_FLOW);
}

Flow ref = visit(curr->ref);
if (ref.breaking()) {
return ref;
}
Flow ptr = visit(curr->ptr);
if (ptr.breaking()) {
return ptr;
}
Flow start = visit(curr->start);
if (start.breaking()) {
return start;
}

auto refData = ref.getSingleValue().getGCData();
auto ptrData = ptr.getSingleValue().getGCData();
if (!refData || !ptrData) {
trap("null ref");
}
auto startVal = start.getSingleValue().getInteger();
auto& refValues = refData->values;
auto& ptrValues = ptrData->values;
if (startVal + refValues.size() > ptrValues.size()) {
trap("oob");
}

for (Index i = 0; i < refValues.size(); i++) {
ptrValues[startVal + i] = refValues[i];
}

return Literal(int32_t(refData->values.size()));
}
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) {
NOTE_ENTER("StringEq");
Expand Down
68 changes: 68 additions & 0 deletions test/lit/exec/strings.wast
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

(module
(type $array16 (array (mut i16)))

(memory 1 1)

(import "fuzzing-support" "log" (func $log (param i32)))

;; CHECK: [fuzz-exec] calling new_wtf16_array
;; CHECK-NEXT: [fuzz-exec] note result: new_wtf16_array => string("ello")
(func $new_wtf16_array (export "new_wtf16_array") (result stringref)
Expand Down Expand Up @@ -185,6 +188,62 @@
)
)
)

;; CHECK: [fuzz-exec] calling encode
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 97]
;; CHECK-NEXT: [LoggingExternalInterface logging 98]
;; CHECK-NEXT: [LoggingExternalInterface logging 99]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
(func $encode (export "encode")
(local $array16 (ref $array16))
(local.set $array16
(array.new_default $array16
(i32.const 10)
)
)
;; Log out that we wrote 3 things.
(call $log
(string.encode_wtf16_array
(string.const "abc")
(local.get $array16)
(i32.const 4)
)
)
;; We wrote 3 things at offset 4. Log out the values at 3,4,5,6,7 (the first
;; and last should be 0, and "abc" in between).
(call $log
(array.get $array16
(local.get $array16)
(i32.const 3)
)
)
(call $log
(array.get $array16
(local.get $array16)
(i32.const 4)
)
)
(call $log
(array.get $array16
(local.get $array16)
(i32.const 5)
)
)
(call $log
(array.get $array16
(local.get $array16)
(i32.const 6)
)
)
(call $log
(array.get $array16
(local.get $array16)
(i32.const 7)
)
)
)
)
;; CHECK: [fuzz-exec] calling new_wtf16_array
;; CHECK-NEXT: [fuzz-exec] note result: new_wtf16_array => string("ello")
Expand Down Expand Up @@ -242,6 +301,14 @@

;; CHECK: [fuzz-exec] calling get_length
;; CHECK-NEXT: [fuzz-exec] note result: get_length => 7

;; CHECK: [fuzz-exec] calling encode
;; CHECK-NEXT: [LoggingExternalInterface logging 3]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [LoggingExternalInterface logging 97]
;; CHECK-NEXT: [LoggingExternalInterface logging 98]
;; CHECK-NEXT: [LoggingExternalInterface logging 99]
;; CHECK-NEXT: [LoggingExternalInterface logging 0]
;; CHECK-NEXT: [fuzz-exec] comparing compare.1
;; CHECK-NEXT: [fuzz-exec] comparing compare.10
;; CHECK-NEXT: [fuzz-exec] comparing compare.2
Expand All @@ -253,6 +320,7 @@
;; CHECK-NEXT: [fuzz-exec] comparing compare.8
;; CHECK-NEXT: [fuzz-exec] comparing compare.9
;; CHECK-NEXT: [fuzz-exec] comparing const
;; CHECK-NEXT: [fuzz-exec] comparing encode
;; CHECK-NEXT: [fuzz-exec] comparing eq.1
;; CHECK-NEXT: [fuzz-exec] comparing eq.2
;; CHECK-NEXT: [fuzz-exec] comparing eq.3
Expand Down