---
doc/go1.20.html | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/doc/go1.20.html b/doc/go1.20.html
index a497f87712..6c007fe1ff 100644
--- a/doc/go1.20.html
+++ b/doc/go1.20.html
@@ -289,17 +289,6 @@ Do not send CLs removing the interior tags from such phrases.
Runtime
-
- The runtime now has experimental support for memory-safe arena allocation
- that makes it possible to eagerly free memory in bulk.
- When used appropriately, it has the potential to improve CPU performance by
- up to 15% in memory-allocation-heavy applications.
- To try it out, build your Go program with GOEXPERIMENT=arenas,
- which will make the arena package visible to your program.
- Source files that import the arena package must require the
- goexperiment.arenas build tag.
-
-
Some of the garbage collector's internal data structures were reorganized to
be both more space and CPU efficient.
@@ -1240,3 +1229,4 @@ proxyHandler := &httputil.ReverseProxy{
+
From 8409251e105486e25d9ae47568ae221eeec636c9 Mon Sep 17 00:00:00 2001
From: Russ Cox
Date: Sat, 14 Jan 2023 15:08:49 -0500
Subject: [PATCH 07/14] cmd/go: document GODEBUG=installgoroot=all
At the moment the only documentation is the release notes,
but everything mentioned in the release notes should have
proper documentation separate from them.
Change-Id: I9885962f6c6d947039b0be59b608385781479271
Reviewed-on: https://go-review.googlesource.com/c/go/+/462196
TryBot-Result: Gopher Robot
Run-TryBot: Russ Cox
Reviewed-by: Bryan Mills
---
src/cmd/go/alldocs.go | 10 ++++++++--
src/cmd/go/internal/work/build.go | 10 ++++++++--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 4c72ab6d56..84afcab7a0 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -746,9 +746,15 @@
// If module-aware mode is enabled, "go install" runs in the context of the main
// module.
//
-// When module-aware mode is disabled, other packages are installed in the
+// When module-aware mode is disabled, non-main packages are installed in the
// directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled,
-// other packages are built and cached but not installed.
+// non-main packages are built and cached but not installed.
+//
+// Before Go 1.20, the standard library was installed to
+// $GOROOT/pkg/$GOOS_$GOARCH.
+// Starting in Go 1.20, the standard library is built and cached but not installed.
+// Setting GODEBUG=installgoroot=all restores the use of
+// $GOROOT/pkg/$GOOS_$GOARCH.
//
// For more about the build flags, see 'go help build'.
// For more about specifying packages, see 'go help packages'.
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 27fa090f83..2f2860aeb5 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -590,9 +590,15 @@ variable and the presence of a go.mod file. See 'go help modules' for details.
If module-aware mode is enabled, "go install" runs in the context of the main
module.
-When module-aware mode is disabled, other packages are installed in the
+When module-aware mode is disabled, non-main packages are installed in the
directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled,
-other packages are built and cached but not installed.
+non-main packages are built and cached but not installed.
+
+Before Go 1.20, the standard library was installed to
+$GOROOT/pkg/$GOOS_$GOARCH.
+Starting in Go 1.20, the standard library is built and cached but not installed.
+Setting GODEBUG=installgoroot=all restores the use of
+$GOROOT/pkg/$GOOS_$GOARCH.
For more about the build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
From f375b305c801515b587719490b4be0db1a66e20c Mon Sep 17 00:00:00 2001
From: Filippo Valsorda
Date: Wed, 4 Jan 2023 21:51:50 +0100
Subject: [PATCH 08/14] crypto/x509: clarify that CheckSignatureFrom and
CheckSignature are low-level APIs
In particular, CheckSignatureFrom just can't check the path length
limit, because it might be enforced above the parent.
We don't need to document the supported signature algorithms for
CheckSignatureFrom, since we document at the constants in what contexts
they are allowed and not. That does leave CheckSignature ambiguous,
though, because that function doesn't have an explicit context.
Change-Id: I4c107440a93f60bc0de07df2b7efeb1a4a766da0
Reviewed-on: https://go-review.googlesource.com/c/go/+/460537
Auto-Submit: Filippo Valsorda
Reviewed-by: Cherry Mui
Reviewed-by: Roland Shoemaker
Run-TryBot: Filippo Valsorda
TryBot-Result: Gopher Robot
---
src/crypto/x509/x509.go | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go
index c72010c1e3..36229bba4f 100644
--- a/src/crypto/x509/x509.go
+++ b/src/crypto/x509/x509.go
@@ -815,8 +815,10 @@ func (c *Certificate) hasSANExtension() bool {
return oidInExtensions(oidExtensionSubjectAltName, c.Extensions)
}
-// CheckSignatureFrom verifies that the signature on c is a valid signature
-// from parent. SHA1WithRSA and ECDSAWithSHA1 signatures are not supported.
+// CheckSignatureFrom verifies that the signature on c is a valid signature from parent.
+//
+// This is a low-level API that performs very limited checks, and not a full
+// path verifier. Most users should use [Certificate.Verify] instead.
func (c *Certificate) CheckSignatureFrom(parent *Certificate) error {
// RFC 5280, 4.2.1.9:
// "If the basic constraints extension is not present in a version 3
@@ -836,13 +838,16 @@ func (c *Certificate) CheckSignatureFrom(parent *Certificate) error {
return ErrUnsupportedAlgorithm
}
- // TODO(agl): don't ignore the path length constraint.
-
return checkSignature(c.SignatureAlgorithm, c.RawTBSCertificate, c.Signature, parent.PublicKey, false)
}
// CheckSignature verifies that signature is a valid signature over signed from
// c's public key.
+//
+// This is a low-level API that performs no validity checks on the certificate.
+//
+// [MD5WithRSA] signatures are rejected, while [SHA1WithRSA] and [ECDSAWithSHA1]
+// signatures are currently accepted.
func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature []byte) error {
return checkSignature(algo, signed, signature, c.PublicKey, true)
}
From 02ed0e5e67530e6b041989d55048ce373dc60327 Mon Sep 17 00:00:00 2001
From: Filippo Valsorda
Date: Thu, 29 Dec 2022 13:08:48 +0100
Subject: [PATCH 09/14] crypto/ed25519: improve Ed25519ctx docs and add example
Change-Id: Ic215a90d1e1daa5805dbab1dc56480281e53b341
Reviewed-on: https://go-review.googlesource.com/c/go/+/459975
Auto-Submit: Filippo Valsorda
Run-TryBot: Filippo Valsorda
Reviewed-by: Cherry Mui
Reviewed-by: Roland Shoemaker
TryBot-Result: Gopher Robot
---
src/crypto/ed25519/ed25519.go | 37 ++++++++++++++++++------------
src/crypto/ed25519/ed25519_test.go | 23 +++++++++++++++++++
2 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/src/crypto/ed25519/ed25519.go b/src/crypto/ed25519/ed25519.go
index 921bbaa8ed..a45d056851 100644
--- a/src/crypto/ed25519/ed25519.go
+++ b/src/crypto/ed25519/ed25519.go
@@ -49,10 +49,10 @@ func (pub PublicKey) Equal(x crypto.PublicKey) bool {
return bytes.Equal(pub, xx)
}
-// PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer.
+// PrivateKey is the type of Ed25519 private keys. It implements [crypto.Signer].
type PrivateKey []byte
-// Public returns the PublicKey corresponding to priv.
+// Public returns the [PublicKey] corresponding to priv.
func (priv PrivateKey) Public() crypto.PublicKey {
publicKey := make([]byte, PublicKeySize)
copy(publicKey, priv[32:])
@@ -75,11 +75,15 @@ func (priv PrivateKey) Seed() []byte {
return bytes.Clone(priv[:SeedSize])
}
-// Sign signs the given message with priv. rand is ignored. If opts.HashFunc()
-// is crypto.SHA512, the pre-hashed variant Ed25519ph is used and message is
-// expected to be a SHA-512 hash, otherwise opts.HashFunc() must be
-// crypto.Hash(0) and the message must not be hashed, as Ed25519 performs two
+// Sign signs the given message with priv. rand is ignored.
+//
+// If opts.HashFunc() is [crypto.SHA512], the pre-hashed variant Ed25519ph is used
+// and message is expected to be a SHA-512 hash, otherwise opts.HashFunc() must
+// be [crypto.Hash](0) and the message must not be hashed, as Ed25519 performs two
// passes over messages to be signed.
+//
+// A value of type [Options] can be used as opts, or crypto.Hash(0) or
+// crypto.SHA512 directly to select plain Ed25519 or Ed25519ph, respectively.
func (priv PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error) {
hash := opts.HashFunc()
context := ""
@@ -108,7 +112,7 @@ func (priv PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOp
}
}
-// Options can be used with PrivateKey.Sign or VerifyWithOptions
+// Options can be used with [PrivateKey.Sign] or [VerifyWithOptions]
// to select Ed25519 variants.
type Options struct {
// Hash can be zero for regular Ed25519, or crypto.SHA512 for Ed25519ph.
@@ -119,10 +123,11 @@ type Options struct {
Context string
}
+// HashFunc returns o.Hash.
func (o *Options) HashFunc() crypto.Hash { return o.Hash }
// GenerateKey generates a public/private key pair using entropy from rand.
-// If rand is nil, crypto/rand.Reader will be used.
+// If rand is nil, [crypto/rand.Reader] will be used.
func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
if rand == nil {
rand = cryptorand.Reader
@@ -141,7 +146,7 @@ func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
}
// NewKeyFromSeed calculates a private key from a seed. It will panic if
-// len(seed) is not SeedSize. This function is provided for interoperability
+// len(seed) is not [SeedSize]. This function is provided for interoperability
// with RFC 8032. RFC 8032's private keys correspond to seeds in this
// package.
func NewKeyFromSeed(seed []byte) PrivateKey {
@@ -170,7 +175,7 @@ func newKeyFromSeed(privateKey, seed []byte) {
}
// Sign signs the message with privateKey and returns a signature. It will
-// panic if len(privateKey) is not PrivateKeySize.
+// panic if len(privateKey) is not [PrivateKeySize].
func Sign(privateKey PrivateKey, message []byte) []byte {
// Outline the function body so that the returned signature can be
// stack-allocated.
@@ -245,16 +250,18 @@ func sign(signature, privateKey, message []byte, domPrefix, context string) {
}
// Verify reports whether sig is a valid signature of message by publicKey. It
-// will panic if len(publicKey) is not PublicKeySize.
+// will panic if len(publicKey) is not [PublicKeySize].
func Verify(publicKey PublicKey, message, sig []byte) bool {
return verify(publicKey, message, sig, domPrefixPure, "")
}
// VerifyWithOptions reports whether sig is a valid signature of message by
-// publicKey. A valid signature is indicated by returning a nil error.
-// If opts.Hash is crypto.SHA512, the pre-hashed variant Ed25519ph is used
-// and message is expected to be a SHA-512 hash, otherwise opts.Hash must
-// be crypto.Hash(0) and the message must not be hashed, as Ed25519 performs two
+// publicKey. A valid signature is indicated by returning a nil error. It will
+// panic if len(publicKey) is not [PublicKeySize].
+//
+// If opts.Hash is [crypto.SHA512], the pre-hashed variant Ed25519ph is used and
+// message is expected to be a SHA-512 hash, otherwise opts.Hash must be
+// [crypto.Hash](0) and the message must not be hashed, as Ed25519 performs two
// passes over messages to be signed.
func VerifyWithOptions(publicKey PublicKey, message, sig []byte, opts *Options) error {
switch {
diff --git a/src/crypto/ed25519/ed25519_test.go b/src/crypto/ed25519/ed25519_test.go
index ae5c872e02..47c8698e2a 100644
--- a/src/crypto/ed25519/ed25519_test.go
+++ b/src/crypto/ed25519/ed25519_test.go
@@ -14,11 +14,34 @@ import (
"crypto/sha512"
"encoding/hex"
"internal/testenv"
+ "log"
"os"
"strings"
"testing"
)
+func Example_ed25519ctx() {
+ pub, priv, err := GenerateKey(nil)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ msg := []byte("The quick brown fox jumps over the lazy dog")
+
+ sig, err := priv.Sign(nil, msg, &Options{
+ Context: "Example_ed25519ctx",
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ if err := VerifyWithOptions(pub, msg, sig, &Options{
+ Context: "Example_ed25519ctx",
+ }); err != nil {
+ log.Fatal("invalid signature")
+ }
+}
+
type zeroReader struct{}
func (zeroReader) Read(buf []byte) (int, error) {
From 6cb8c43b842daffe628e8ee7a94ea3b1ba17299d Mon Sep 17 00:00:00 2001
From: Than McIntosh
Date: Fri, 13 Jan 2023 16:46:49 -0500
Subject: [PATCH 10/14] cmd/go: include coverage build flags for "go list"
This patch ensures that the go command's "list" subcommand accepts
coverage-related build options, which were incorrectly left out when
"go build -cover" was rolled out. This is needed in order to do things
like check the staleness of an installed cover-instrumented target.
Fixes #57785.
Change-Id: I140732ff1e6b83cd9c453701bb8199b333fc0f2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/462116
Reviewed-by: Bryan Mills
Reviewed-by: Russ Cox
Run-TryBot: Than McIntosh
TryBot-Result: Gopher Robot
---
src/cmd/go/internal/list/list.go | 3 +++
src/cmd/go/testdata/script/cover_list.txt | 28 +++++++++++++++++++++++
2 files changed, 31 insertions(+)
create mode 100644 src/cmd/go/testdata/script/cover_list.txt
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index 72201850b2..811d659ba3 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -336,6 +336,9 @@ For more about modules, see https://golang.org/ref/mod.
func init() {
CmdList.Run = runList // break init cycle
work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
+ if cfg.Experiment != nil && cfg.Experiment.CoverageRedesign {
+ work.AddCoverFlags(CmdList, nil)
+ }
CmdList.Flag.Var(&listJsonFields, "json", "")
}
diff --git a/src/cmd/go/testdata/script/cover_list.txt b/src/cmd/go/testdata/script/cover_list.txt
new file mode 100644
index 0000000000..c66c087793
--- /dev/null
+++ b/src/cmd/go/testdata/script/cover_list.txt
@@ -0,0 +1,28 @@
+
+# This test is intended to verify that "go list" accepts coverage related
+# build arguments (such as -cover, -covermode). See issue #57785.
+
+[short] skip
+[!GOEXPERIMENT:coverageredesign] skip
+
+env GOBIN=$WORK/bin
+
+# Install a target and then do an ordinary staleness check on it.
+go install m/example
+! stale m/example
+
+# Run a second staleness check with "-cover" as a build flag. The
+# installed target should indeed be stale, since we didn't build it
+# with -cover.
+stale -cover m/example
+
+-- go.mod --
+module m
+
+go 1.20
+-- example/main.go --
+package main
+
+func main() {
+ println("hi mom")
+}
From 8e199294361de59b637f25a7d5eebdee1b131415 Mon Sep 17 00:00:00 2001
From: fangguizhen <1297394526@qq.com>
Date: Tue, 17 Jan 2023 16:37:42 +0000
Subject: [PATCH 11/14] strings: remove redundant symbols
Change-Id: Ie3fe0274288d6cb6303acdcec1340c480e5c0b20
GitHub-Last-Rev: ce9d44619e970b1319fbccf3aace1ddf719bcec1
GitHub-Pull-Request: golang/go#57848
Reviewed-on: https://go-review.googlesource.com/c/go/+/462277
Run-TryBot: Ian Lance Taylor
Auto-Submit: Ian Lance Taylor
Run-TryBot: Keith Randall
Reviewed-by: Keith Randall
TryBot-Result: Gopher Robot
Auto-Submit: Keith Randall
Reviewed-by: Ian Lance Taylor
Reviewed-by: Keith Randall
---
src/strings/clone_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/strings/clone_test.go b/src/strings/clone_test.go
index 77479cfacf..64f2760ee3 100644
--- a/src/strings/clone_test.go
+++ b/src/strings/clone_test.go
@@ -1,6 +1,6 @@
// Copyright 2021 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.ß
+// license that can be found in the LICENSE file.
package strings_test
From d74c31f0ba8b7940350f93df044a5cb7002e02d0 Mon Sep 17 00:00:00 2001
From: Filippo Valsorda
Date: Thu, 29 Dec 2022 15:52:37 +0100
Subject: [PATCH 12/14] doc/go1.20: update cryptography release notes
Change-Id: I5d6d2bd5cbb246ea514e5adbe936fb31b92904af
Reviewed-on: https://go-review.googlesource.com/c/go/+/459978
Run-TryBot: Filippo Valsorda
Reviewed-by: Roland Shoemaker
Reviewed-by: Cherry Mui
TryBot-Result: Gopher Robot
Auto-Submit: Filippo Valsorda
---
doc/go1.20.html | 71 ++++++++++++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 28 deletions(-)
diff --git a/doc/go1.20.html b/doc/go1.20.html
index 6c007fe1ff..324d59ed6e 100644
--- a/doc/go1.20.html
+++ b/doc/go1.20.html
@@ -389,13 +389,13 @@ Do not send CLs removing the interior tags from such phrases.
Go 1.20 adds a new crypto/ecdh package
- to provide direct support for Elliptic Curve Diffie-Hellman key exchange
+ to provide explicit support for Elliptic Curve Diffie-Hellman key exchanges
over NIST curves and Curve25519.
- Programs should prefer to use crypto/ecdh
- or crypto/ecdsa
- instead of the lower-level functionality in crypto/elliptic.
+ Programs should use crypto/ecdh instead of the lower-level functionality in
+ crypto/elliptic for ECDH, and
+ third-party modules for more advanced use cases.
Wrapping multiple errors
@@ -583,6 +583,11 @@ proxyHandler := &httputil.ReverseProxy{
- crypto/ecdsa
-
+
+ When using supported curves, all operations are now implemented in constant time.
+ This led to an increase in CPU time between 5% and 30%, mostly affecting P-384 and P-521.
+
+
The new PrivateKey.ECDH method
converts an ecdsa.PrivateKey to an ecdh.PrivateKey.
@@ -609,25 +614,21 @@ proxyHandler := &httputil.ReverseProxy{
-- crypto/elliptic
- -
-
- Use of custom Curve implementations
- not provided by this package (that is, curves other than
- P224,
- P256,
- P384, and
- P521)
- is deprecated.
-
-
-
-
- crypto/rsa
-
The new field OAEPOptions.MGFHash
- allows configuring the MGF1 hash separately for OAEP encryption.
+ allows configuring the MGF1 hash separately for OAEP decryption.
+
+
+
+ crypto/rsa now uses a new, safer, constant-time backend. This causes a CPU
+ runtime increase for decryption operations between approximately 15%
+ (RSA-2048 on amd64) and 45% (RSA-4096 on arm64), and more on 32-bit architectures.
+ Encryption operations are approximately 20x slower than before (but still 5-10x faster than decryption).
+ Performance is expected to improve in future releases.
+ Programs must not modify or manually generate the fields of
+ PrecomputedValues.
@@ -643,9 +644,9 @@ proxyHandler := &httputil.ReverseProxy{
- crypto/tls
-
-
- The TLS client now shares parsed certificates across all clients actively using that certificate.
- The savings can be significant in programs that make many concurrent connections to a
+
+ Parsed certificates are now shared across all clients actively using that certificate.
+ The memory savings can be significant in programs that make many concurrent connections to a
server or collection of servers sharing any part of their certificate chains.
@@ -660,22 +661,22 @@ proxyHandler := &httputil.ReverseProxy{
- crypto/x509
-
-
- CreateCertificateRequest
+
+ ParsePKCS8PrivateKey
and
MarshalPKCS8PrivateKey
now support keys of type *crypto/ecdh.PrivateKey.
- CreateCertificate
+ ParsePKIXPublicKey
and
MarshalPKIXPublicKey
now support keys of type *crypto/ecdh.PublicKey.
- X.509 unmarshaling continues to unmarshal elliptic curve keys into
+ Parsing NIST curve keys still returns values of type
*ecdsa.PublicKey and *ecdsa.PrivateKey.
- Use their new ECDH methods to convert to the crypto/ecdh form.
+ Use their new ECDH methods to convert to the crypto/ecdh types.
The new SetFallbackRoots
- function allows a program to define a set of fallback root certificates in case the
+ function allows a program to define a set of fallback root certificates in case an
operating system verifier or standard platform root bundle is unavailable at runtime.
It will most commonly be used with a new package, golang.org/x/crypto/x509roots/fallback,
which will provide an up to date root bundle.
@@ -832,6 +833,20 @@ proxyHandler := &httputil.ReverseProxy{
+- math/big
+ -
+
+ The math/big package's wide scope and
+ input-dependent timing make it ill-suited for implementing cryptography.
+ The cryptography packages in the standard library no longer call non-trivial
+ Int methods on attacker-controlled inputs.
+ In the future, the determination of whether a bug in math/big is
+ considered a security vulnerability will depend on its wider impact on the
+ standard library.
+
+
+
+
- math/rand
-
From c0799f7015e6cae37c21294bb94f56050fda5f4e Mon Sep 17 00:00:00 2001
From: Alan Donovan
Date: Tue, 17 Jan 2023 11:30:48 -0500
Subject: [PATCH 13/14] os: document that Rename is not atomic on non-Unix
platforms
Windows provides no reliable way to rename files atomically.
The Plan 9 implementation of os.Rename performs a deletion
if the target exists.
Change-Id: Ife5f9c97b21f48c11e300cd76d8c7f715db09fd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/462395
Auto-Submit: Alan Donovan
Reviewed-by: Ian Lance Taylor
TryBot-Result: Gopher Robot
Run-TryBot: Alan Donovan
Reviewed-by: Bryan Mills
---
src/os/file.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/os/file.go b/src/os/file.go
index 6781b54da0..3d71ac068e 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -338,6 +338,7 @@ var lstat = Lstat
// Rename renames (moves) oldpath to newpath.
// If newpath already exists and is not a directory, Rename replaces it.
// OS-specific restrictions may apply when oldpath and newpath are in different directories.
+// Even within the same directory, on non-Unix platforms Rename is not an atomic operation.
// If there is an error, it will be of type *LinkError.
func Rename(oldpath, newpath string) error {
return rename(oldpath, newpath)
From 9088c691dac424540f562d6271c5ee479e9f9d80 Mon Sep 17 00:00:00 2001
From: Keith Randall
Date: Tue, 17 Jan 2023 09:35:21 -0800
Subject: [PATCH 14/14] cmd/compile: ensure temp register mask isn't empty
We need to avoid nospill registers at this point in regalloc.
Make sure that we don't restrict our register set to avoid registers
desired by other instructions, if the resulting set includes only
nospill registers.
Fixes #57846
Change-Id: I05478e4513c484755dc2e8621d73dac868e45a27
Reviewed-on: https://go-review.googlesource.com/c/go/+/461685
Reviewed-by: Keith Randall
Run-TryBot: Keith Randall
Reviewed-by: Cherry Mui
TryBot-Result: Gopher Robot
---
src/cmd/compile/internal/ssa/regalloc.go | 2 +-
test/fixedbugs/issue57846.go | 33 ++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 test/fixedbugs/issue57846.go
diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go
index 3cfe7330d1..294c522a90 100644
--- a/src/cmd/compile/internal/ssa/regalloc.go
+++ b/src/cmd/compile/internal/ssa/regalloc.go
@@ -1561,7 +1561,7 @@ func (s *regAllocState) regalloc(f *Func) {
// (Not all instructions need that distinct part, but it is conservative.)
if opcodeTable[v.Op].needIntTemp {
m := s.allocatable & s.f.Config.gpRegMask
- if m&^desired.avoid != 0 {
+ if m&^desired.avoid&^s.nospill != 0 {
m &^= desired.avoid
}
tmpReg = s.allocReg(m, &tmpVal)
diff --git a/test/fixedbugs/issue57846.go b/test/fixedbugs/issue57846.go
new file mode 100644
index 0000000000..1aea97564e
--- /dev/null
+++ b/test/fixedbugs/issue57846.go
@@ -0,0 +1,33 @@
+// compile
+
+// Copyright 2023 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
+
+func Float64D3(list [][][]float64, value float64) int {
+ valueCount := 0
+ for _, listValue := range list {
+ valueCount += Float64D2(listValue, value)
+ }
+ return valueCount
+}
+
+func Float64(list []float64, value float64) int {
+ valueCount := 0
+ for _, listValue := range list {
+ if listValue == value {
+ valueCount++
+ }
+ }
+ return valueCount
+}
+
+func Float64D2(list [][]float64, value float64) int {
+ valueCount := 0
+ for _, listValue := range list {
+ valueCount += Float64(listValue, value)
+ }
+ return valueCount
+}