diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 3624f63d3e..77585d9b77 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -30,16 +30,17 @@ import { Array } from "./array"; } static fromCodePoint(code: i32): String { - assert(code <= 0x10FFFF); - var hasSur = code > 0xFFFF; + var hasSur = code > 0xFFFF; var out = changetype(__new(2 << i32(hasSur), idof())); if (!hasSur) { store(changetype(out), code); } else { + // Checks valid code point range + assert(code <= 0x10FFFF); code -= 0x10000; let hi = (code & 0x03FF) | 0xDC00; - let lo = (code >>> 10) | 0xD800; - store(changetype(out), lo | (hi << 16)); + let lo = code >>> 10 | 0xD800; + store(changetype(out), lo | hi << 16); } return out; } diff --git a/tests/compiler/std-wasi/process.optimized.wat b/tests/compiler/std-wasi/process.optimized.wat index 97ea52e086..a2f6527925 100644 --- a/tests/compiler/std-wasi/process.optimized.wat +++ b/tests/compiler/std-wasi/process.optimized.wat @@ -4792,7 +4792,7 @@ if i32.const 0 i32.const 4816 - i32.const 748 + i32.const 749 i32.const 7 call $~lib/wasi/index/abort unreachable diff --git a/tests/compiler/std-wasi/process.untouched.wat b/tests/compiler/std-wasi/process.untouched.wat index 061e79a721..decdaf0529 100644 --- a/tests/compiler/std-wasi/process.untouched.wat +++ b/tests/compiler/std-wasi/process.untouched.wat @@ -7791,7 +7791,7 @@ if i32.const 0 i32.const 3792 - i32.const 748 + i32.const 749 i32.const 7 call $~lib/wasi/index/abort unreachable diff --git a/tests/compiler/std/string-casemapping.optimized.wat b/tests/compiler/std/string-casemapping.optimized.wat index 607b5b49c5..8aa51a1d63 100644 --- a/tests/compiler/std/string-casemapping.optimized.wat +++ b/tests/compiler/std/string-casemapping.optimized.wat @@ -5967,22 +5967,11 @@ global.get $~lib/memory/__stack_pointer i32.const 0 i32.store - local.get $0 - i32.const 1114111 - i32.gt_u - if - i32.const 0 - i32.const 15344 - i32.const 33 - i32.const 5 - call $~lib/builtins/abort - unreachable - end global.get $~lib/memory/__stack_pointer i32.const 2 local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.tee $2 i32.shl i32.const 1 @@ -5991,6 +5980,17 @@ i32.store local.get $2 if + local.get $0 + i32.const 1114111 + i32.gt_u + if + i32.const 0 + i32.const 15344 + i32.const 39 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $1 local.get $0 i32.const 65536 diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index 58d43bed23..cfb7e7640d 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -8589,20 +8589,8 @@ i32.const 0 i32.store local.get $0 - i32.const 1114111 - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 14576 - i32.const 33 - i32.const 5 - call $~lib/builtins/abort - unreachable - end - local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.set $1 global.get $~lib/memory/__stack_pointer i32.const 2 @@ -8619,6 +8607,18 @@ local.get $0 i32.store16 else + local.get $0 + i32.const 1114111 + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 14576 + i32.const 39 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $0 i32.const 65536 i32.sub diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index bc55b7e596..7c76a4beb0 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3883,7 +3883,7 @@ if i32.const 0 i32.const 1712 - i32.const 748 + i32.const 749 i32.const 7 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 947c9da3aa..65f2c9be39 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -5958,7 +5958,7 @@ if i32.const 0 i32.const 688 - i32.const 748 + i32.const 749 i32.const 7 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index a4342fca7c..22257a02ee 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -2770,7 +2770,7 @@ if i32.const 1264 i32.const 1328 - i32.const 56 + i32.const 57 i32.const 31 call $~lib/builtins/abort unreachable @@ -20364,22 +20364,11 @@ global.get $~lib/memory/__stack_pointer i32.const 0 i32.store - local.get $0 - i32.const 1114111 - i32.gt_u - if - i32.const 0 - i32.const 1328 - i32.const 33 - i32.const 5 - call $~lib/builtins/abort - unreachable - end global.get $~lib/memory/__stack_pointer i32.const 2 local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.tee $2 i32.shl i32.const 1 @@ -20388,6 +20377,17 @@ i32.store local.get $2 if + local.get $0 + i32.const 1114111 + i32.gt_u + if + i32.const 0 + i32.const 1328 + i32.const 39 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $1 local.get $0 i32.const 65536 @@ -20988,7 +20988,7 @@ if i32.const 13648 i32.const 1328 - i32.const 332 + i32.const 333 i32.const 7 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 2b5ed767dd..5d8b16e859 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -3089,7 +3089,7 @@ if i32.const 240 i32.const 304 - i32.const 56 + i32.const 57 i32.const 31 call $~lib/builtins/abort unreachable @@ -25393,20 +25393,8 @@ i32.const 0 i32.store local.get $0 - i32.const 1114111 - i32.le_u - i32.eqz - if - i32.const 0 - i32.const 304 - i32.const 33 - i32.const 5 - call $~lib/builtins/abort - unreachable - end - local.get $0 i32.const 65535 - i32.gt_s + i32.gt_u local.set $1 global.get $~lib/memory/__stack_pointer i32.const 2 @@ -25423,6 +25411,18 @@ local.get $0 i32.store16 else + local.get $0 + i32.const 1114111 + i32.le_u + i32.eqz + if + i32.const 0 + i32.const 304 + i32.const 39 + i32.const 7 + call $~lib/builtins/abort + unreachable + end local.get $0 i32.const 65536 i32.sub @@ -26084,7 +26084,7 @@ if i32.const 12624 i32.const 304 - i32.const 332 + i32.const 333 i32.const 7 call $~lib/builtins/abort unreachable