Skip to content

Commit 03a1dc3

Browse files
committed
cmd/compile: don't crash on (unsafe.Sizeof)(0)
Fixes golang#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>
1 parent 4d07d3e commit 03a1dc3

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/cmd/compile/internal/gc/typecheck.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,37 +1185,35 @@ OpSwitch:
11851185

11861186
// call and call like
11871187
case OCALL:
1188+
n.Left = typecheck(n.Left, Erv|Etype|Ecall)
1189+
n.Diag |= n.Left.Diag
11881190
l := n.Left
11891191

11901192
if l.Op == ONAME {
1191-
r := unsafenmagic(n)
1192-
if r != nil {
1193+
if r := unsafenmagic(n); r != nil {
11931194
if n.Isddd {
11941195
yyerror("invalid use of ... with builtin %v", l)
11951196
}
11961197
n = r
11971198
n = typecheck1(n, top)
11981199
return n
11991200
}
1200-
}
12011201

1202-
n.Left = typecheck(n.Left, Erv|Etype|Ecall)
1203-
n.Diag |= n.Left.Diag
1204-
l = n.Left
1205-
if l.Op == ONAME && l.Etype != 0 {
1206-
// TODO(marvin): Fix Node.EType type union.
1207-
if n.Isddd && Op(l.Etype) != OAPPEND {
1208-
yyerror("invalid use of ... with builtin %v", l)
1209-
}
1202+
if l.Etype != 0 {
1203+
// TODO(marvin): Fix Node.EType type union.
1204+
if n.Isddd && Op(l.Etype) != OAPPEND {
1205+
yyerror("invalid use of ... with builtin %v", l)
1206+
}
12101207

1211-
// builtin: OLEN, OCAP, etc.
1212-
// TODO(marvin): Fix Node.EType type union.
1213-
n.Op = Op(l.Etype)
1208+
// builtin: OLEN, OCAP, etc.
1209+
// TODO(marvin): Fix Node.EType type union.
1210+
n.Op = Op(l.Etype)
12141211

1215-
n.Left = n.Right
1216-
n.Right = nil
1217-
n = typecheck1(n, top)
1218-
return n
1212+
n.Left = n.Right
1213+
n.Right = nil
1214+
n = typecheck1(n, top)
1215+
return n
1216+
}
12191217
}
12201218

12211219
n.Left = defaultlit(n.Left, nil)

test/fixedbugs/issue17270.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile
2+
3+
// Copyright 2016 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
import "unsafe"
10+
11+
const _ = (unsafe.Sizeof)(0)

0 commit comments

Comments
 (0)