aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/rewriteWasm.go
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2018-05-07 16:18:19 +0200
committerCherry Zhang <cherryyz@google.com>2018-05-10 12:05:17 +0000
commitbf23a4e61ddceb26744da8f462ce6351fca66089 (patch)
treed8729a64a59e3d2b0fcbea43ff1a6239bb26e594 /src/cmd/compile/internal/ssa/rewriteWasm.go
parent10529a01fd8b0d5cc07eb3f6aa00a0272597684b (diff)
downloadgo-bf23a4e61ddceb26744da8f462ce6351fca66089.tar.gz
go-bf23a4e61ddceb26744da8f462ce6351fca66089.zip
cmd/internal/obj/wasm: avoid invalid offsets for Load/Store
Offsets for Load and Store instructions have type i32. Bad index expression offsets can cause an offset to be larger than MaxUint32, which is not allowed. One example for this is the test test/index0.go. Generate valid code by adding a guard to the responsible rewrite rule. Also emit a proper error when using such a bad index in assembly code. Change-Id: Ie90adcbf3ae3861c26680eb81790f28692913ccf Reviewed-on: https://go-review.googlesource.com/111955 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteWasm.go')
-rw-r--r--src/cmd/compile/internal/ssa/rewriteWasm.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go
index f488a93522..2255561051 100644
--- a/src/cmd/compile/internal/ssa/rewriteWasm.go
+++ b/src/cmd/compile/internal/ssa/rewriteWasm.go
@@ -5256,7 +5256,7 @@ func rewriteValueWasm_OpWasmI64Eqz_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load_0(v *Value) bool {
// match: (I64Load [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5268,7 +5268,7 @@ func rewriteValueWasm_OpWasmI64Load_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load)
@@ -5281,7 +5281,7 @@ func rewriteValueWasm_OpWasmI64Load_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load16S_0(v *Value) bool {
// match: (I64Load16S [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load16S [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5293,7 +5293,7 @@ func rewriteValueWasm_OpWasmI64Load16S_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load16S)
@@ -5306,7 +5306,7 @@ func rewriteValueWasm_OpWasmI64Load16S_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load16U_0(v *Value) bool {
// match: (I64Load16U [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load16U [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5318,7 +5318,7 @@ func rewriteValueWasm_OpWasmI64Load16U_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load16U)
@@ -5331,7 +5331,7 @@ func rewriteValueWasm_OpWasmI64Load16U_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load32S_0(v *Value) bool {
// match: (I64Load32S [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load32S [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5343,7 +5343,7 @@ func rewriteValueWasm_OpWasmI64Load32S_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load32S)
@@ -5356,7 +5356,7 @@ func rewriteValueWasm_OpWasmI64Load32S_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load32U_0(v *Value) bool {
// match: (I64Load32U [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load32U [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5368,7 +5368,7 @@ func rewriteValueWasm_OpWasmI64Load32U_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load32U)
@@ -5381,7 +5381,7 @@ func rewriteValueWasm_OpWasmI64Load32U_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load8S_0(v *Value) bool {
// match: (I64Load8S [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load8S [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5393,7 +5393,7 @@ func rewriteValueWasm_OpWasmI64Load8S_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load8S)
@@ -5406,7 +5406,7 @@ func rewriteValueWasm_OpWasmI64Load8S_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Load8U_0(v *Value) bool {
// match: (I64Load8U [off] (I64AddConst [off2] ptr) mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Load8U [off+off2] ptr mem)
for {
off := v.AuxInt
@@ -5418,7 +5418,7 @@ func rewriteValueWasm_OpWasmI64Load8U_0(v *Value) bool {
off2 := v_0.AuxInt
ptr := v_0.Args[0]
mem := v.Args[1]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Load8U)
@@ -5588,7 +5588,7 @@ func rewriteValueWasm_OpWasmI64Or_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Store_0(v *Value) bool {
// match: (I64Store [off] (I64AddConst [off2] ptr) val mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Store [off+off2] ptr val mem)
for {
off := v.AuxInt
@@ -5601,7 +5601,7 @@ func rewriteValueWasm_OpWasmI64Store_0(v *Value) bool {
ptr := v_0.Args[0]
val := v.Args[1]
mem := v.Args[2]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Store)
@@ -5615,7 +5615,7 @@ func rewriteValueWasm_OpWasmI64Store_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Store16_0(v *Value) bool {
// match: (I64Store16 [off] (I64AddConst [off2] ptr) val mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Store16 [off+off2] ptr val mem)
for {
off := v.AuxInt
@@ -5628,7 +5628,7 @@ func rewriteValueWasm_OpWasmI64Store16_0(v *Value) bool {
ptr := v_0.Args[0]
val := v.Args[1]
mem := v.Args[2]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Store16)
@@ -5642,7 +5642,7 @@ func rewriteValueWasm_OpWasmI64Store16_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Store32_0(v *Value) bool {
// match: (I64Store32 [off] (I64AddConst [off2] ptr) val mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Store32 [off+off2] ptr val mem)
for {
off := v.AuxInt
@@ -5655,7 +5655,7 @@ func rewriteValueWasm_OpWasmI64Store32_0(v *Value) bool {
ptr := v_0.Args[0]
val := v.Args[1]
mem := v.Args[2]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Store32)
@@ -5669,7 +5669,7 @@ func rewriteValueWasm_OpWasmI64Store32_0(v *Value) bool {
}
func rewriteValueWasm_OpWasmI64Store8_0(v *Value) bool {
// match: (I64Store8 [off] (I64AddConst [off2] ptr) val mem)
- // cond: off+off2 >= 0
+ // cond: isU32Bit(off+off2)
// result: (I64Store8 [off+off2] ptr val mem)
for {
off := v.AuxInt
@@ -5682,7 +5682,7 @@ func rewriteValueWasm_OpWasmI64Store8_0(v *Value) bool {
ptr := v_0.Args[0]
val := v.Args[1]
mem := v.Args[2]
- if !(off+off2 >= 0) {
+ if !(isU32Bit(off + off2)) {
break
}
v.reset(OpWasmI64Store8)