diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2024-07-15 23:20:52 +0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-07-15 17:08:26 +0000 |
| commit | 8f1ec59bdb2d095b9caf31f6f3fd3e167b14ef0a (patch) | |
| tree | afa8553a8b60f34358c2cc00a6b5ccef4cedbda9 /src/strings | |
| parent | 5d36bc18d56fa5d7ad10b675dd82892ed3100332 (diff) | |
| download | go-8f1ec59bdb2d095b9caf31f6f3fd3e167b14ef0a.tar.xz | |
strings: re-introduce noescape wrapper
CL 573955 added internal/abi:NoEscape function, and use it in strings
builder copyCheck code.
However, internal/abi is a runtime package, which can not be built with
-d=checkptr flag yet. This causes incorrect inlining decision, since
NoEscape must not be inlined when -d=checkptr is used.
Fixing this by re-introducing noescape wrapper.
Fixes #68415
Change-Id: I776cab4c9e9e4b3e58162dcce6ec025cb366bdee
Reviewed-on: https://go-review.googlesource.com/c/go/+/598295
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/strings')
| -rw-r--r-- | src/strings/builder.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/strings/builder.go b/src/strings/builder.go index e6df08c6f4..3b37888cbf 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") } |
