Commit 5e8beed1 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: remove pointer arithmetic

Change-Id: Ie4bab0b74d5a4e1aecd8501a48176b2e9a3d8c42
Reviewed-on: https://go-review.googlesource.com/c/76311
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 2f1ef6be
...@@ -286,13 +286,7 @@ func walkrange(n *Node) *Node { ...@@ -286,13 +286,7 @@ func walkrange(n *Node) *Node {
// This runs *after* the condition check, so we know // This runs *after* the condition check, so we know
// advancing the pointer is safe and won't go past the // advancing the pointer is safe and won't go past the
// end of the allocation. // end of the allocation.
tmp = nod(OADD, hp, nodintconst(t.Elem().Width)) a = nod(OAS, hp, addptr(hp, t.Elem().Width))
tmp.Type = hp.Type
tmp.SetTypecheck(1)
tmp.Right.Type = types.Types[types.Tptr]
tmp.Right.SetTypecheck(1)
a = nod(OAS, hp, tmp)
a = typecheck(a, Etop) a = typecheck(a, Etop)
n.List.Set1(a) n.List.Set1(a)
...@@ -613,3 +607,18 @@ func arrayClear(n, v1, v2, a *Node) bool { ...@@ -613,3 +607,18 @@ func arrayClear(n, v1, v2, a *Node) bool {
n = walkstmt(n) n = walkstmt(n)
return true return true
} }
// addptr returns (*T)(uintptr(p) + n).
func addptr(p *Node, n int64) *Node {
t := p.Type
p = nod(OCONVNOP, p, nil)
p.Type = types.Types[TUINTPTR]
p = nod(OADD, p, nodintconst(n))
p = nod(OCONVNOP, p, nil)
p.Type = t
return p
}
...@@ -1247,10 +1247,8 @@ var opToSSA = map[opAndType]ssa.Op{ ...@@ -1247,10 +1247,8 @@ var opToSSA = map[opAndType]ssa.Op{
opAndType{OADD, TUINT16}: ssa.OpAdd16, opAndType{OADD, TUINT16}: ssa.OpAdd16,
opAndType{OADD, TINT32}: ssa.OpAdd32, opAndType{OADD, TINT32}: ssa.OpAdd32,
opAndType{OADD, TUINT32}: ssa.OpAdd32, opAndType{OADD, TUINT32}: ssa.OpAdd32,
opAndType{OADD, TPTR32}: ssa.OpAdd32,
opAndType{OADD, TINT64}: ssa.OpAdd64, opAndType{OADD, TINT64}: ssa.OpAdd64,
opAndType{OADD, TUINT64}: ssa.OpAdd64, opAndType{OADD, TUINT64}: ssa.OpAdd64,
opAndType{OADD, TPTR64}: ssa.OpAdd64,
opAndType{OADD, TFLOAT32}: ssa.OpAdd32F, opAndType{OADD, TFLOAT32}: ssa.OpAdd32F,
opAndType{OADD, TFLOAT64}: ssa.OpAdd64F, opAndType{OADD, TFLOAT64}: ssa.OpAdd64F,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment