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
This commit is contained in:
Shenghou Ma 2014-04-16 23:12:06 -04:00 committed by Russ Cox
parent dc370995a8
commit 32dffef098
2 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -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)
}