From 04edb4a23eb74fe57a7d78bf20b4a3ca9bde2d40 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 May 2026 14:10:38 +0800 Subject: [PATCH 1/2] cl: guard zero-sized interface deref --- cl/compile.go | 6 +++++- test/go/nil_pointer_interface_test.go | 9 +++++++++ test/goroot/xfail.yaml | 8 -------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cl/compile.go b/cl/compile.go index 5b6d7c9fbe..8ac8024202 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -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) }) { @@ -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) diff --git a/test/go/nil_pointer_interface_test.go b/test/go/nil_pointer_interface_test.go index b497f03ba5..f3cd73ea90 100644 --- a/test/go/nil_pointer_interface_test.go +++ b/test/go/nil_pointer_interface_test.go @@ -4,6 +4,8 @@ import "testing" type nilPointerInterfaceLarge [1 << 21]byte +type nilPointerInterfaceZero struct{} + type nilPointerInterfaceLargeStruct struct { data [1 << 21]byte } @@ -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 diff --git a/test/goroot/xfail.yaml b/test/goroot/xfail.yaml index a5a66d10b4..c583e8f9f6 100644 --- a/test/goroot/xfail.yaml +++ b/test/goroot/xfail.yaml @@ -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 @@ -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 From ed11fcadbebf88580191e8a3a7eb6f69e77e8024 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 May 2026 14:47:48 +0800 Subject: [PATCH 2/2] ci: rerun PR checks