cmd/gc: initialize t->width in dgcsym() if required

Update #5291.

R=golang-dev, daniel.morsing, iant, r
CC=golang-dev
https://golang.org/cl/8663052
This commit is contained in:
Jan Ziak 2013-04-25 18:47:12 +02:00
parent db1c218d4f
commit 13cbf41a7f
4 changed files with 68 additions and 0 deletions

View file

@ -1046,6 +1046,9 @@ dgcsym1(Sym *s, int ot, Type *t, vlong *off, int stack_size)
if(t->align > 0 && (*off % t->align) != 0)
fatal("dgcsym1: invalid initial alignment, %T", t);
if(t->width == BADWIDTH)
dowidth(t);
switch(t->etype) {
case TINT8:
@ -1141,6 +1144,8 @@ dgcsym1(Sym *s, int ot, Type *t, vlong *off, int stack_size)
case TARRAY:
if(t->bound < -1)
fatal("dgcsym1: invalid bound, %T", t);
if(t->type->width == BADWIDTH)
dowidth(t->type);
if(isslice(t)) {
// NOTE: Any changes here need to be made to reflect.SliceOf as well.
// struct { byte* array; uint32 len; uint32 cap; }
@ -1214,6 +1219,9 @@ dgcsym(Type *t)
return s;
s->flags |= SymGcgen;
if(t->width == BADWIDTH)
dowidth(t);
ot = 0;
off = 0;
ot = duintptr(s, ot, t->width);

View file

@ -0,0 +1,34 @@
// Copyright 2013 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 pkg1
import (
"runtime"
)
type T2 *[]string
type Data struct {
T1 *[]T2
}
func CrashCall() (err error) {
var d Data
for count := 0; count < 10; count++ {
runtime.GC()
len := 2 // crash when >=2
x := make([]T2, len)
d = Data{T1: &x}
for j := 0; j < len; j++ {
y := make([]string, 1)
(*d.T1)[j] = &y
}
}
return nil
}

View file

@ -0,0 +1,17 @@
// Copyright 2013 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
import (
"./pkg1"
)
type message struct { // Presence of this creates a crash
data pkg1.Data
}
func main() {
pkg1.CrashCall()
}

View file

@ -0,0 +1,9 @@
// rundir
// Copyright 2013 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.
// Issue 5291: GC crash
package ignored