]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix segfault in isgoconst.
authorShenghou Ma <minux.ma@gmail.com>
Thu, 17 Apr 2014 03:12:06 +0000 (23:12 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 17 Apr 2014 03:12:06 +0000 (23:12 -0400)
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
test/fixedbugs/issue7794.go [new file with mode: 0644]

index 28d0725d33d948f991bd42b37eaf92b7ba738ddf..f356c4f59a3edf4a961fe27e122810ad3334d054 100644 (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;
        
diff --git a/test/fixedbugs/issue7794.go b/test/fixedbugs/issue7794.go
new file mode 100644 (file)
index 0000000..1e303bd
--- /dev/null
@@ -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)
+}