Skip to content

Commit 88dc4ae

Browse files
neelancecherrymui
authored andcommitted
cmd/compile: fix OffPtr with negative offset on wasm
The wasm archtecture was missing a rule to handle OffPtr with a negative offset. This commit makes it so OffPtr always gets lowered to I64AddConst. Fixes #25741 Change-Id: I1d48e2954e3ff31deb8cba9a9bf0cab7c4bab71a Reviewed-on: https://go-review.googlesource.com/116595 Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]>
1 parent 6decd3d commit 88dc4ae

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/cmd/compile/internal/ssa/gen/Wasm.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
(Not x) -> (I64Eqz x)
4747

4848
// Lowering pointer arithmetic
49-
(OffPtr [0] ptr) -> ptr
50-
(OffPtr [off] ptr) && off > 0 -> (I64AddConst [off] ptr)
49+
(OffPtr [off] ptr) -> (I64AddConst [off] ptr)
5150

5251
// Lowering extension
5352
// It is unnecessary to extend loads
@@ -388,6 +387,7 @@
388387
(I64Ne x (I64Const [0])) -> (I64Eqz (I64Eqz x))
389388

390389
(I64Add x (I64Const [y])) -> (I64AddConst [y] x)
390+
(I64AddConst [0] x) -> x
391391
(I64Eqz (I64Eqz (I64Eqz x))) -> (I64Eqz x)
392392

393393
((I64Load|I64Load32U|I64Load32S|I64Load16U|I64Load16S|I64Load8U|I64Load8S) [off] (I64AddConst [off2] ptr) mem)

src/cmd/compile/internal/ssa/rewriteWasm.go

Lines changed: 19 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue25741.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
var s []int
10+
11+
func main() {
12+
i := -1
13+
s[i] = 0
14+
}

0 commit comments

Comments
 (0)