From 32dffef0980eb810b97f48eb9dfabb33602a0472 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 16 Apr 2014 23:12:06 -0400 Subject: [PATCH] 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 --- src/cmd/gc/const.c | 2 +- test/fixedbugs/issue7794.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue7794.go 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) +}