]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't crash on (unsafe.Sizeof)(0)
authorMatthew Dempsky <mdempsky@google.com>
Wed, 28 Sep 2016 22:04:00 +0000 (15:04 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 28 Sep 2016 23:13:53 +0000 (23:13 +0000)
Fixes #17270.

Change-Id: I4affa57e10baf1a758bc0977265d160f220b2945
Reviewed-on: https://go-review.googlesource.com/29960
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue17270.go [new file with mode: 0644]

index 3ad869f98b57c7777ad2e83516871737b59d8144..7bf577cdc83527c5cb01dcfc045f594a45208683 100644 (file)
@@ -1185,11 +1185,12 @@ OpSwitch:
 
        // call and call like
        case OCALL:
+               n.Left = typecheck(n.Left, Erv|Etype|Ecall)
+               n.Diag |= n.Left.Diag
                l := n.Left
 
                if l.Op == ONAME {
-                       r := unsafenmagic(n)
-                       if r != nil {
+                       if r := unsafenmagic(n); r != nil {
                                if n.Isddd {
                                        yyerror("invalid use of ... with builtin %v", l)
                                }
@@ -1197,25 +1198,22 @@ OpSwitch:
                                n = typecheck1(n, top)
                                return n
                        }
-               }
 
-               n.Left = typecheck(n.Left, Erv|Etype|Ecall)
-               n.Diag |= n.Left.Diag
-               l = n.Left
-               if l.Op == ONAME && l.Etype != 0 {
-                       // TODO(marvin): Fix Node.EType type union.
-                       if n.Isddd && Op(l.Etype) != OAPPEND {
-                               yyerror("invalid use of ... with builtin %v", l)
-                       }
+                       if l.Etype != 0 {
+                               // TODO(marvin): Fix Node.EType type union.
+                               if n.Isddd && Op(l.Etype) != OAPPEND {
+                                       yyerror("invalid use of ... with builtin %v", l)
+                               }
 
-                       // builtin: OLEN, OCAP, etc.
-                       // TODO(marvin): Fix Node.EType type union.
-                       n.Op = Op(l.Etype)
+                               // builtin: OLEN, OCAP, etc.
+                               // TODO(marvin): Fix Node.EType type union.
+                               n.Op = Op(l.Etype)
 
-                       n.Left = n.Right
-                       n.Right = nil
-                       n = typecheck1(n, top)
-                       return n
+                               n.Left = n.Right
+                               n.Right = nil
+                               n = typecheck1(n, top)
+                               return n
+                       }
                }
 
                n.Left = defaultlit(n.Left, nil)
diff --git a/test/fixedbugs/issue17270.go b/test/fixedbugs/issue17270.go
new file mode 100644 (file)
index 0000000..5c009b5
--- /dev/null
@@ -0,0 +1,11 @@
+// compile
+
+// 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
+
+import "unsafe"
+
+const _ = (unsafe.Sizeof)(0)