Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (p *context) isLargeNonPointerValue(t llssa.Type) bool {
return sizes.Sizeof(raw) > maxDirectDerefSize
}

func (p *context) isZeroSizedValue(t llssa.Type) bool {
return p.prog.SizeOf(t) == 0
}

func dbgGoSSADump(f interface {
WriteTo(io.Writer) (int64, error)
}) {
Expand Down Expand Up @@ -988,7 +992,7 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
t := p.type_(v.Type(), llssa.InGo)
if unop, ok := v.X.(*ssa.UnOp); ok && unop.Op == token.MUL {
if vt := p.type_(unop.Type(), llssa.InGo); vt.RawType() != nil {
if p.isLargeNonPointerValue(vt) {
if p.isLargeNonPointerValue(vt) || p.isZeroSizedValue(vt) {
if ptr := p.compileValue(b, unop.X); ptr.Type != nil {
p.assertNilDerefBase(b, unop.X)
ret = b.MakeInterfaceFromPtr(t, ptr)
Expand Down
9 changes: 9 additions & 0 deletions test/go/nil_pointer_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "testing"

type nilPointerInterfaceLarge [1 << 21]byte

type nilPointerInterfaceZero struct{}

type nilPointerInterfaceLargeStruct struct {
data [1 << 21]byte
}
Expand Down Expand Up @@ -32,6 +34,13 @@ func TestNilPointerLargeArrayToInterfacePanics(t *testing.T) {
})
}

func TestNilPointerZeroSizedValueToInterfacePanics(t *testing.T) {
expectNilPointerInterfacePanic(t, func() {
var p *nilPointerInterfaceZero
nilPointerInterfaceSink = *p
})
}

func TestNilPointerLargeStructToInterfacePanics(t *testing.T) {
expectNilPointerInterfacePanic(t, func() {
var p *nilPointerInterfaceLargeStruct
Expand Down
8 changes: 0 additions & 8 deletions test/goroot/xfail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3614,10 +3614,6 @@ xfails:
directive: run
case: fixedbugs/issue15175.go
reason: current main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: fixedbugs/issue19246.go
reason: current main goroot run failure on darwin/arm64
- platform: darwin/arm64
directive: run
case: fixedbugs/issue23017.go
Expand Down Expand Up @@ -3812,10 +3808,6 @@ xfails:
directive: run
case: fixedbugs/issue15175.go
reason: current main goroot run failure on linux/amd64
- platform: linux/amd64
directive: run
case: fixedbugs/issue19246.go
reason: current main goroot run failure on linux/amd64
- platform: linux/amd64
directive: run
case: fixedbugs/issue23017.go
Expand Down
Loading