diff --git a/src/strings/builder.go b/src/strings/builder.go index e6df08c6f47..3b37888cbf6 100644 --- a/src/strings/builder.go +++ b/src/strings/builder.go @@ -23,6 +23,18 @@ type Builder struct { buf []byte } +// This is just a wrapper around abi.NoEscape. +// +// This wrapper is necessary because internal/abi is a runtime package, +// so it can not be built with -d=checkptr, causing incorrect inlining +// decision when building with checkptr enabled, see issue #68415. +// +//go:nosplit +//go:nocheckptr +func noescape(p unsafe.Pointer) unsafe.Pointer { + return abi.NoEscape(p) +} + func (b *Builder) copyCheck() { if b.addr == nil { // This hack works around a failing of Go's escape analysis @@ -30,7 +42,7 @@ func (b *Builder) copyCheck() { // See issue 23382. // TODO: once issue 7921 is fixed, this should be reverted to // just "b.addr = b". - b.addr = (*Builder)(abi.NoEscape(unsafe.Pointer(b))) + b.addr = (*Builder)(noescape(unsafe.Pointer(b))) } else if b.addr != b { panic("strings: illegal use of non-zero Builder copied by value") } diff --git a/test/fixedbugs/issue68415.go b/test/fixedbugs/issue68415.go new file mode 100644 index 00000000000..cf278ac6035 --- /dev/null +++ b/test/fixedbugs/issue68415.go @@ -0,0 +1,15 @@ +// run -gcflags=all=-d=checkptr + +// Copyright 2024 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 "regexp" + +var dataFileRegexp = regexp.MustCompile(`^data\.\d+\.bin$`) + +func main() { + _ = dataFileRegexp +}