From 8895a99c9ff522cf41f3a1bee365bd0c7e0c7900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=CC=88hrmann?= Date: Thu, 1 Sep 2016 08:31:37 +0200 Subject: [PATCH] cmd/compile: disallow typed non-integer constant len and cap make arguments make(T, n, m) returns a slice of type T with length n and capacity m where "The size arguments n and m must be of integer type or untyped." https://tip.golang.org/ref/spec#Making_slices_maps_and_channels The failure to reject typed non-integer size arguments in make during compile time was uncovered after https://golang.org/cl/27851 changed the generation of makeslice calls. Fixes #16940 Updates #16949 Change-Id: Ib1e3576f0e6ad199c9b16b7a50c2db81290c63b4 Reviewed-on: https://go-review.googlesource.com/28301 Reviewed-by: Joe Tsai Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/gc/typecheck.go | 10 ++++---- test/fixedbugs/issue16949.go | 30 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 test/fixedbugs/issue16949.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index d08f52e5c5..df527a5036 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3754,6 +3754,11 @@ ret: } func checkmake(t *Type, arg string, n *Node) bool { + if !n.Type.IsInteger() && n.Type.Etype != TIDEAL { + Yyerror("non-integer %s argument in make(%v) - %v", arg, t, n.Type) + return false + } + if n.Op == OLITERAL { switch n.Val().Ctype() { case CTINT, CTRUNE, CTFLT, CTCPLX: @@ -3779,11 +3784,6 @@ func checkmake(t *Type, arg string, n *Node) bool { } } - if !n.Type.IsInteger() && n.Type.Etype != TIDEAL { - Yyerror("non-integer %s argument in make(%v) - %v", arg, t, n.Type) - return false - } - // Defaultlit still necessary for non-constant: n might be 1<