Skip to content

Commit 343b7fa

Browse files
committed
cmd/compile: don't mark argument array as noalg
It ends up making two similar types, [N]uint8 of both alg and noalg varieties. Comparsions between the two then don't come out equal when they should. In particular, the type *[N]uint8 has an Elem pointer which must point to one of the above two types; it can't point to both. Thus allocating a *[N]uint8 and dereferencing it might be a different type than a [N]uint8. The fix is easy. Making a small test for this is really hard. It requires that both a argless defer and the test be imported by a common parent package. This is why a main binary doesn't see this issue, but a test does (as Agniva noticed), because there's a wrapper package that imports both the test and the defer. Types like [N]uint8 don't really need to be marked noalg anyway, as the generated code (if any) will be shared among all vanilla memory types of the same size. Fixes #32595 Change-Id: If7b77fa6ed56cd4495601c3f90170682d853b82f Reviewed-on: https://go-review.googlesource.com/c/go/+/182357 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8382ccb commit 343b7fa

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

src/cmd/compile/internal/gc/reflect.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ func deferstruct(stksize int64) *types.Type {
330330
return f
331331
}
332332
argtype := types.NewArray(types.Types[TUINT8], stksize)
333-
argtype.SetNoalg(true)
334333
argtype.Width = stksize
335334
argtype.Align = 1
336335
// These fields must match the ones in runtime/runtime2.go:_defer and

test/fixedbugs/issue32595.dir/a.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
func A() {
8+
defer func() {}()
9+
}

test/fixedbugs/issue32595.dir/b.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package b
6+
7+
import "reflect"
8+
9+
func B() {
10+
t1 := reflect.TypeOf([0]byte{})
11+
t2 := reflect.TypeOf(new([0]byte)).Elem()
12+
if t1 != t2 {
13+
panic("[0]byte types do not match")
14+
}
15+
}

test/fixedbugs/issue32595.dir/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"a"
9+
"b"
10+
)
11+
12+
func main() {
13+
a.A()
14+
b.B()
15+
}

test/fixedbugs/issue32595.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rundir
2+
3+
// Copyright 2019 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package ignored

0 commit comments

Comments
 (0)