Skip to content

Commit 9d15944

Browse files
tlivelyradekdoulik
authored andcommitted
[StringLowering] Lower stringview_wtf16.get_codeunit to charCodeAt (WebAssembly#6353)
Previously we lowered this to `getCodePointAt`, which has different semantics around surrogate pairs.
1 parent 1b30f3c commit 9d15944

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/passes/StringLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct StringLowering : public StringGathering {
295295
Name equalsImport;
296296
Name compareImport;
297297
Name lengthImport;
298-
Name codePointAtImport;
298+
Name charCodeAtImport;
299299
Name substringImport;
300300

301301
// The name of the module to import string functions from.
@@ -334,8 +334,8 @@ struct StringLowering : public StringGathering {
334334
// string.length: string -> i32
335335
lengthImport = addImport(module, "length", nullExt, Type::i32);
336336
// string.codePointAt: string, offset -> i32
337-
codePointAtImport =
338-
addImport(module, "codePointAt", {nullExt, Type::i32}, Type::i32);
337+
charCodeAtImport =
338+
addImport(module, "charCodeAt", {nullExt, Type::i32}, Type::i32);
339339
// string.substring: string, start, end -> string
340340
substringImport =
341341
addImport(module, "substring", {nullExt, Type::i32, Type::i32}, nnExt);
@@ -425,7 +425,7 @@ struct StringLowering : public StringGathering {
425425
void visitStringWTF16Get(StringWTF16Get* curr) {
426426
Builder builder(*getModule());
427427
replaceCurrent(builder.makeCall(
428-
lowering.codePointAtImport, {curr->ref, curr->pos}, Type::i32));
428+
lowering.charCodeAtImport, {curr->ref, curr->pos}, Type::i32));
429429
}
430430

431431
void visitStringSliceWTF(StringSliceWTF* curr) {

test/lit/passes/string-gathering.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
;; LOWER: (import "wasm:js-string" "length" (func $length (type $6) (param externref) (result i32)))
6363

64-
;; LOWER: (import "wasm:js-string" "codePointAt" (func $codePointAt (type $7) (param externref i32) (result i32)))
64+
;; LOWER: (import "wasm:js-string" "charCodeAt" (func $charCodeAt (type $7) (param externref i32) (result i32)))
6565

6666
;; LOWER: (import "wasm:js-string" "substring" (func $substring (type $8) (param externref i32 i32) (result (ref extern))))
6767

@@ -182,7 +182,7 @@
182182

183183
;; LOWER: (import "wasm:js-string" "length" (func $length (type $5) (param externref) (result i32)))
184184

185-
;; LOWER: (import "wasm:js-string" "codePointAt" (func $codePointAt (type $6) (param externref i32) (result i32)))
185+
;; LOWER: (import "wasm:js-string" "charCodeAt" (func $charCodeAt (type $6) (param externref i32) (result i32)))
186186

187187
;; LOWER: (import "wasm:js-string" "substring" (func $substring (type $7) (param externref i32 i32) (result (ref extern))))
188188

test/lit/passes/string-lowering-instructions.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
;; CHECK: (import "wasm:js-string" "length" (func $length (type $23) (param externref) (result i32)))
8787

88-
;; CHECK: (import "wasm:js-string" "codePointAt" (func $codePointAt (type $24) (param externref i32) (result i32)))
88+
;; CHECK: (import "wasm:js-string" "charCodeAt" (func $charCodeAt (type $24) (param externref i32) (result i32)))
8989

9090
;; CHECK: (import "wasm:js-string" "substring" (func $substring (type $25) (param externref i32 i32) (result (ref extern))))
9191

@@ -245,7 +245,7 @@
245245
)
246246

247247
;; CHECK: (func $string.get_codeunit (type $15) (param $ref externref) (result i32)
248-
;; CHECK-NEXT: (call $codePointAt
248+
;; CHECK-NEXT: (call $charCodeAt
249249
;; CHECK-NEXT: (local.get $ref)
250250
;; CHECK-NEXT: (i32.const 2)
251251
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)