Skip to content

Commit 8f1ec59

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Jorropo <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]>
1 parent 5d36bc1 commit 8f1ec59

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/strings/builder.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,26 @@ type Builder struct {
2323
buf []byte
2424
}
2525

26+
// This is just a wrapper around abi.NoEscape.
27+
//
28+
// This wrapper is necessary because internal/abi is a runtime package,
29+
// so it can not be built with -d=checkptr, causing incorrect inlining
30+
// decision when building with checkptr enabled, see issue #68415.
31+
//
32+
//go:nosplit
33+
//go:nocheckptr
34+
func noescape(p unsafe.Pointer) unsafe.Pointer {
35+
return abi.NoEscape(p)
36+
}
37+
2638
func (b *Builder) copyCheck() {
2739
if b.addr == nil {
2840
// This hack works around a failing of Go's escape analysis
2941
// that was causing b to escape and be heap allocated.
3042
// See issue 23382.
3143
// TODO: once issue 7921 is fixed, this should be reverted to
3244
// just "b.addr = b".
33-
b.addr = (*Builder)(abi.NoEscape(unsafe.Pointer(b)))
45+
b.addr = (*Builder)(noescape(unsafe.Pointer(b)))
3446
} else if b.addr != b {
3547
panic("strings: illegal use of non-zero Builder copied by value")
3648
}

test/fixedbugs/issue68415.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run -gcflags=all=-d=checkptr
2+
3+
// Copyright 2024 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import "regexp"
10+
11+
var dataFileRegexp = regexp.MustCompile(`^data\.\d+\.bin$`)
12+
13+
func main() {
14+
_ = dataFileRegexp
15+
}

0 commit comments

Comments
 (0)