[go] reflect: use &zeroVal[0] instead of nil for data field for zero-sized payloads

4 views
Skip to first unread message

Keith Randall (Gerrit)

unread,
Feb 24, 2026, 6:37:15 PM (10 hours ago) Feb 24
to Cuong Manh Le, goph...@pubsubhelper.golang.org, Keith Randall, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le

Keith Randall has uploaded the change for review

Keith Randall would like Cuong Manh Le to review this change.

Commit message

reflect: use &zeroVal[0] instead of nil for data field for zero-sized payloads

Because our wrapper functions barf if the pointer is nil, even if
we don't actually dereference the pointer.

Fixes #77779
Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a

Change diff

diff --git a/src/reflect/value.go b/src/reflect/value.go
index 6fba1e7..e4a686c 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -1288,9 +1288,10 @@
// bunch of zero-sized fields. We must return the zero-sized
// fields indirectly, as only ptr-shaped things can be direct.
// See issue 74935.
- // We use nil instead of v.ptr as it doesn't matter and
+ // We use &zeroVal[0] instead of v.ptr as it doesn't matter and
// we can avoid pinning a possibly now-unused object.
- return Value{typ, nil, fl | flagIndir}
+ // Don't use nil, see issue 77779.
+ return Value{typ, unsafe.Pointer(&zeroVal[0]), fl | flagIndir}
}

// Either flagIndir is set and v.ptr points at struct,
diff --git a/test/fixedbugs/issue77779.go b/test/fixedbugs/issue77779.go
new file mode 100644
index 0000000..1a61b2c
--- /dev/null
+++ b/test/fixedbugs/issue77779.go
@@ -0,0 +1,45 @@
+// run
+
+// Copyright 2026 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 (
+ "reflect"
+)
+
+type Renderer interface {
+ Render() error
+}
+
+type ZeroSize struct{}
+
+func (ZeroSize) Render() error { return nil }
+
+type Data struct {
+ X, Y, Z int
+}
+
+// Container is pointer-sized (8 bytes): zero-size embed + one pointer field.
+// This triggers Go 1.26 interface inlining, which produces a nil data pointer
+// for the zero-size field when extracted via reflect.Value.Interface().
+type Container struct {
+ ZeroSize
+ Data *Data
+}
+
+func main() {
+ render(Container{})
+ render(&Container{})
+}
+
+func render(iface any) {
+ if reflect.ValueOf(iface).Kind() == reflect.Ptr {
+ _ = reflect.ValueOf(iface).Elem().Field(0).Interface().(Renderer).Render()
+ return
+ }
+
+ _ = reflect.ValueOf(iface).Field(0).Interface().(Renderer).Render()
+}

Change information

Files:
  • M src/reflect/value.go
  • A test/fixedbugs/issue77779.go
Change size: M
Delta: 2 files changed, 48 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
Gerrit-Change-Number: 748660
Gerrit-PatchSet: 1
Gerrit-Owner: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Lance Taylor (Gerrit)

unread,
Feb 24, 2026, 6:39:18 PM (10 hours ago) Feb 24
to Keith Randall, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Go LUCI, Cuong Manh Le, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le and Keith Randall

Ian Lance Taylor voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
Gerrit-Change-Number: 748660
Gerrit-PatchSet: 1
Gerrit-Owner: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Comment-Date: Tue, 24 Feb 2026 23:39:14 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
Feb 24, 2026, 7:09:23 PM (10 hours ago) Feb 24
to Keith Randall, goph...@pubsubhelper.golang.org, Go LUCI, Ian Lance Taylor, golang-co...@googlegroups.com
Attention needed from Keith Randall

Cuong Manh Le voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
    Gerrit-Change-Number: 748660
    Gerrit-PatchSet: 1
    Gerrit-Owner: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Wed, 25 Feb 2026 00:09:14 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Cherry Mui (Gerrit)

    unread,
    Feb 24, 2026, 11:13:25 PM (6 hours ago) Feb 24
    to Keith Randall, goph...@pubsubhelper.golang.org, Cuong Manh Le, Go LUCI, Ian Lance Taylor, golang-co...@googlegroups.com
    Attention needed from Keith Randall

    Cherry Mui voted Code-Review+2

    Code-Review+2
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
    Gerrit-Change-Number: 748660
    Gerrit-PatchSet: 1
    Gerrit-Owner: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Wed, 25 Feb 2026 04:13:22 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Keith Randall (Gerrit)

    unread,
    Feb 24, 2026, 11:51:11 PM (5 hours ago) Feb 24
    to Keith Randall, goph...@pubsubhelper.golang.org, Cherry Mui, Cuong Manh Le, Go LUCI, Ian Lance Taylor, golang-co...@googlegroups.com
    Attention needed from Keith Randall

    Keith Randall voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Gerrit-Change-Number: 748660
      Gerrit-PatchSet: 1
      Gerrit-Owner: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Comment-Date: Wed, 25 Feb 2026 04:51:06 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Feb 24, 2026, 11:51:22 PM (5 hours ago) Feb 24
      to Keith Randall, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Keith Randall, Cherry Mui, Cuong Manh Le, Go LUCI, Ian Lance Taylor, golang-co...@googlegroups.com

      Keith Randall submitted the change

      Change information

      Commit message:
      reflect: use &zeroVal[0] instead of nil for data field for zero-sized payloads

      Because our wrapper functions barf if the pointer is nil, even if
      we don't actually dereference the pointer.

      Fixes #77779
      Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Reviewed-by: Ian Lance Taylor <ia...@golang.org>
      Reviewed-by: Cuong Manh Le <cuong.m...@gmail.com>
      Reviewed-by: Cherry Mui <cher...@google.com>
      Reviewed-by: Keith Randall <k...@google.com>
      Files:
      • M src/reflect/value.go
      • A test/fixedbugs/issue77779.go
      Change size: M
      Delta: 2 files changed, 48 insertions(+), 2 deletions(-)
      Branch: refs/heads/master
      Submit Requirements:
      • requirement satisfiedCode-Review: +2 by Cherry Mui, +2 by Cuong Manh Le, +2 by Ian Lance Taylor, +1 by Keith Randall
      • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Gerrit-Change-Number: 748660
      Gerrit-PatchSet: 2
      open
      diffy
      satisfied_requirement

      Keith Randall (Gerrit)

      unread,
      Feb 24, 2026, 11:52:30 PM (5 hours ago) Feb 24
      to goph...@pubsubhelper.golang.org, Keith Randall, golang-co...@googlegroups.com

      Keith Randall has uploaded the change for review

      Commit message

      [release-branch.go1.26] reflect: use &zeroVal[0] instead of nil for data field for zero-sized payloads


      Because our wrapper functions barf if the pointer is nil, even if
      we don't actually dereference the pointer.

      Fixes #77780


      Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Reviewed-on: https://go-review.googlesource.com/c/go/+/748660
      Reviewed-by: Ian Lance Taylor <ia...@golang.org>
      LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
      Reviewed-by: Cuong Manh Le <cuong.m...@gmail.com>
      Reviewed-by: Cherry Mui <cher...@google.com>
      Reviewed-by: Keith Randall <k...@google.com>
      (cherry picked from commit 60dc96479a85db0e245a5c14d964628169abedf4)

      Change diff

      diff --git a/src/reflect/value.go b/src/reflect/value.go
      index 8c8acba..f192eb5 100644

      Change information

      Files:
      • M src/reflect/value.go
      • A test/fixedbugs/issue77779.go
      Change size: M
      Delta: 2 files changed, 48 insertions(+), 2 deletions(-)
      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newchange
      Gerrit-Project: go
      Gerrit-Branch: release-branch.go1.26
      Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Gerrit-Change-Number: 748720
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Feb 24, 2026, 11:53:03 PM (5 hours ago) Feb 24
      to Keith Randall, goph...@pubsubhelper.golang.org, Cuong Manh Le, Ian Lance Taylor, Cherry Mui, golang-co...@googlegroups.com
      Attention needed from Cherry Mui, Cuong Manh Le and Ian Lance Taylor

      Keith Randall voted Commit-Queue+1

      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      • Cuong Manh Le
      • Ian Lance Taylor
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: release-branch.go1.26
      Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Gerrit-Change-Number: 748720
      Gerrit-PatchSet: 1
      Gerrit-Owner: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Comment-Date: Wed, 25 Feb 2026 04:52:57 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Feb 24, 2026, 11:53:30 PM (5 hours ago) Feb 24
      to Keith Randall, goph...@pubsubhelper.golang.org, Go LUCI, Cuong Manh Le, Ian Lance Taylor, Cherry Mui, golang-co...@googlegroups.com
      Attention needed from Cherry Mui, Cuong Manh Le, Ian Lance Taylor and Keith Randall

      Keith Randall voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      • Cuong Manh Le
      • Ian Lance Taylor
      • Keith Randall
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: release-branch.go1.26
      Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
      Gerrit-Change-Number: 748720
      Gerrit-PatchSet: 1
      Gerrit-Owner: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Cherry Mui <cher...@google.com>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Comment-Date: Wed, 25 Feb 2026 04:53:27 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      12:20 AM (5 hours ago) 12:20 AM
      to Keith Randall, goph...@pubsubhelper.golang.org, Keith Randall, Go LUCI, Ian Lance Taylor, Cherry Mui, golang-co...@googlegroups.com
      Attention needed from Cherry Mui, Ian Lance Taylor and Keith Randall

      Cuong Manh Le voted Code-Review+2

      Code-Review+2
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      • Ian Lance Taylor
      • Keith Randall
        Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: release-branch.go1.26
        Gerrit-Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
        Gerrit-Change-Number: 748720
        Gerrit-PatchSet: 1
        Gerrit-Owner: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Comment-Date: Wed, 25 Feb 2026 05:19:59 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages