aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShenghou Ma <minux.ma@gmail.com>2014-04-16 23:12:06 -0400
committerRuss Cox <rsc@golang.org>2014-04-16 23:12:06 -0400
commit32dffef0980eb810b97f48eb9dfabb33602a0472 (patch)
treefa45e11ba0da9c827732b7e8a7d28fcc1394b77f
parentdc370995a87a37b43546a9ac3413d533d24e0665 (diff)
downloadgo-32dffef0980eb810b97f48eb9dfabb33602a0472.tar.gz
go-32dffef0980eb810b97f48eb9dfabb33602a0472.zip
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
-rw-r--r--src/cmd/gc/const.c2
-rw-r--r--test/fixedbugs/issue7794.go12
2 files changed, 13 insertions, 1 deletions
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)
+}