aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2017-08-18 18:40:12 +0200
committerMartin Möhrmann <moehrmann@google.com>2017-08-22 21:03:26 +0000
commit8bbae3d5c9589635225b3a614ffda33989e1f424 (patch)
tree7198ef9113fa7dae6bcdacbe336ca205afe21f0a /src
parentcbc4e5d9c4f2444c5d40ae6333b4e1f4c9cfbd41 (diff)
downloadgo-8bbae3d5c9589635225b3a614ffda33989e1f424.tar.xz
cmd/compile: make argument length mismatch in mkcall an error
mkcall is used to construct calls to builtin functions. Instead of silently ignoring any additional arguments to mkcall abort compilation with an error. This protects against accidentally supplying too many arguments to mkcall when compiler changes are made. Change appendslice and copyany to construct calls to slicestringcopy and slicecopy explicitly instead of relying on the old behavior as a feature. Change-Id: I3cfe815a57d454a129e3c08aac824f6107779a42 Reviewed-on: https://go-review.googlesource.com/57770 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/walk.go32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 83c82a6a84..971a670e9d 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -2779,9 +2779,12 @@ func vmkcall(fn *Node, t *types.Type, init *Nodes, va []*Node) *Node {
}
n := fn.Type.Params().NumFields()
+ if n != len(va) {
+ Fatalf("vmkcall %v needs %v args got %v", fn, n, len(va))
+ }
r := nod(OCALL, fn, nil)
- r.List.Set(va[:n])
+ r.List.Set(va)
if fn.Type.Results().NumFields() > 0 {
r = typecheck(r, Erv|Efnstruct)
} else {
@@ -3036,16 +3039,20 @@ func appendslice(n *Node, init *Nodes) *Node {
nptr1.SetSliceBounds(nod(OLEN, l1, nil), nil, nil)
nptr1.Etype = 1
nptr2 := l2
- var fn *Node
+
+ var ln Nodes
+ ln.Set(l)
+ var nt *Node
if l2.Type.IsString() {
- fn = syslook("slicestringcopy")
+ fn := syslook("slicestringcopy")
+ fn = substArgTypes(fn, l1.Type, l2.Type)
+ nt = mkcall1(fn, types.Types[TINT], &ln, nptr1, nptr2)
} else {
- fn = syslook("slicecopy")
+ fn := syslook("slicecopy")
+ fn = substArgTypes(fn, l1.Type, l2.Type)
+ nt = mkcall1(fn, types.Types[TINT], &ln, nptr1, nptr2, nodintconst(s.Type.Elem().Width))
}
- fn = substArgTypes(fn, l1.Type, l2.Type)
- var ln Nodes
- ln.Set(l)
- nt := mkcall1(fn, types.Types[TINT], &ln, nptr1, nptr2, nodintconst(s.Type.Elem().Width))
+
l = append(ln.Slice(), nt)
} else {
// memmove(&s[len(l1)], &l2[0], len(l2)*sizeof(T))
@@ -3186,12 +3193,13 @@ func copyany(n *Node, init *Nodes, runtimecall bool) *Node {
}
if runtimecall {
- var fn *Node
if n.Right.Type.IsString() {
- fn = syslook("slicestringcopy")
- } else {
- fn = syslook("slicecopy")
+ fn := syslook("slicestringcopy")
+ fn = substArgTypes(fn, n.Left.Type, n.Right.Type)
+ return mkcall1(fn, n.Type, init, n.Left, n.Right)
}
+
+ fn := syslook("slicecopy")
fn = substArgTypes(fn, n.Left.Type, n.Right.Type)
return mkcall1(fn, n.Type, init, n.Left, n.Right, nodintconst(n.Left.Type.Elem().Width))
}