From: Shenghou Ma Date: Thu, 17 Apr 2014 03:12:06 +0000 (-0400) Subject: cmd/gc: fix segfault in isgoconst. X-Git-Tag: go1.3beta1~30 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=32dffef0980eb810b97f48eb9dfabb33602a0472;p=gostls13.git cmd/gc: fix segfault in isgoconst. Variables declared with 'var' have no sym->def. Fixes #7794. LGTM=rsc R=golang-codereviews, bradfitz, rsc CC=golang-codereviews https://golang.org/cl/88360043 --- diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index 28d0725d33..f356c4f59a 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -1594,7 +1594,7 @@ isgoconst(Node *n) case ONAME: l = n->sym->def; - if(l->op == OLITERAL && n->val.ctype != CTNIL) + if(l && l->op == OLITERAL && n->val.ctype != CTNIL) return 1; break; diff --git a/test/fixedbugs/issue7794.go b/test/fixedbugs/issue7794.go new file mode 100644 index 0000000000..1e303bd4f2 --- /dev/null +++ b/test/fixedbugs/issue7794.go @@ -0,0 +1,12 @@ +// compile + +// Copyright 2014 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 main + +func main() { + var a [10]int + const ca = len(a) +}