summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-interpreter.h38
-rw-r--r--test/lit/exec/strings.wast68
2 files changed, 105 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 46e5c1752..31039cf28 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1919,7 +1919,43 @@ public:
}
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");
diff --git a/test/lit/exec/strings.wast b/test/lit/exec/strings.wast
index 711d2e36a..706602b1c 100644
--- a/test/lit/exec/strings.wast
+++ b/test/lit/exec/strings.wast
@@ -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)
@@ -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")
@@ -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
@@ -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