]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent ICE from misuse of [...]T arrays
authorMatthew Dempsky <mdempsky@google.com>
Fri, 21 Oct 2016 20:44:29 +0000 (13:44 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 21 Oct 2016 22:41:56 +0000 (22:41 +0000)
Fixes #16428.

Change-Id: I78d37472e228402bb3c06d7ebd441952386fa38a
Reviewed-on: https://go-review.googlesource.com/31731
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue16428.go [new file with mode: 0644]

index 182bf0727aa611cef17daa875fd115752882d928..2f30967e6650292c84bb315f590fd9e3b44d644e 100644 (file)
@@ -344,12 +344,15 @@ OpSwitch:
                if n.Left == nil {
                        t = typSlice(r.Type)
                } else if n.Left.Op == ODDD {
-                       t = typDDDArray(r.Type)
-                       if top&Ecomplit == 0 && n.Diag == 0 {
-                               t.Broke = true
-                               n.Diag = 1
-                               yyerror("use of [...] array outside of array literal")
+                       if top&Ecomplit == 0 {
+                               if n.Diag == 0 {
+                                       n.Diag = 1
+                                       yyerror("use of [...] array outside of array literal")
+                               }
+                               n.Type = nil
+                               return n
                        }
+                       t = typDDDArray(r.Type)
                } else {
                        n.Left = indexlit(typecheck(n.Left, Erv))
                        l := n.Left
diff --git a/test/fixedbugs/issue16428.go b/test/fixedbugs/issue16428.go
new file mode 100644 (file)
index 0000000..5696d18
--- /dev/null
@@ -0,0 +1,12 @@
+// errorcheck
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+var (
+       b = [...]byte("abc") // ERROR "outside of array literal"
+       s = len(b)
+)