]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix (*T)(nil)-to-interface conversion bug
authorAlan Donovan <adonovan@google.com>
Mon, 23 Oct 2023 22:45:06 +0000 (18:45 -0400)
committerRobert Findley <rfindley@google.com>
Tue, 24 Oct 2023 13:47:39 +0000 (13:47 +0000)
A nil *gcSizes pointer should be converted to a nil Sizes interface.

Updates #63701

Change-Id: I62e00fecf303ce0ae529f1a75c14c7ef2576a58f
Reviewed-on: https://go-review.googlesource.com/c/go/+/537255
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/gcsizes.go
src/cmd/compile/internal/types2/sizes.go
src/go/types/gcsizes.go
src/go/types/sizes.go

index fe961e30ef1e64943db38cff1634b9850df2b594..d204d9feef028975cc45036eacea939cac87c9fb 100644 (file)
@@ -160,7 +160,8 @@ func (s *gcSizes) Sizeof(T Type) int64 {
 }
 
 // gcSizesFor returns the Sizes used by gc for an architecture.
-// The result is nil if a compiler/architecture pair is not known.
+// The result is a nil *gcSizes pointer (which is not a valid types.Sizes)
+// if a compiler/architecture pair is not known.
 func gcSizesFor(compiler, arch string) *gcSizes {
        if compiler != "gc" {
                return nil
index 64da072fbf53bc38a8d16e1c0e567483c52f3258..486c05c61c7490bd495f25ced951b450d7129afd 100644 (file)
@@ -257,10 +257,12 @@ var gcArchSizes = map[string]*gcSizes{
 func SizesFor(compiler, arch string) Sizes {
        switch compiler {
        case "gc":
-               return gcSizesFor(compiler, arch)
+               if s := gcSizesFor(compiler, arch); s != nil {
+                       return Sizes(s)
+               }
        case "gccgo":
                if s, ok := gccgoArchSizes[arch]; ok {
-                       return s
+                       return Sizes(s)
                }
        }
        return nil
index 9a7c0cf43c9f16a42ff8cd101fa6f84c2a9fda13..4329cc22e82f3db527a6877a738ea398fef2a9a6 100644 (file)
@@ -162,7 +162,8 @@ func (s *gcSizes) Sizeof(T Type) int64 {
 }
 
 // gcSizesFor returns the Sizes used by gc for an architecture.
-// The result is nil if a compiler/architecture pair is not known.
+// The result is a nil *gcSizes pointer (which is not a valid types.Sizes)
+// if a compiler/architecture pair is not known.
 func gcSizesFor(compiler, arch string) *gcSizes {
        if compiler != "gc" {
                return nil
index 5e40614f39122c52c2b8cdd8a51ad18d2147556f..12a21401e24301808672f999065d5a6a284e98a0 100644 (file)
@@ -259,10 +259,12 @@ var gcArchSizes = map[string]*gcSizes{
 func SizesFor(compiler, arch string) Sizes {
        switch compiler {
        case "gc":
-               return gcSizesFor(compiler, arch)
+               if s := gcSizesFor(compiler, arch); s != nil {
+                       return Sizes(s)
+               }
        case "gccgo":
                if s, ok := gccgoArchSizes[arch]; ok {
-                       return s
+                       return Sizes(s)
                }
        }
        return nil