diff options
| author | sunnymilk <shaojunyang@google.com> | 2024-09-10 12:27:55 -0400 |
|---|---|---|
| committer | Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-11-11 21:52:00 +0000 |
| commit | fe2da30cb54aadeab243f3fc7bd3e14dd4da2892 (patch) | |
| tree | 17d7160c87cba9071034c34196c2c8271618a2ae /test | |
| parent | 73ac82f99046a8b0b0b76f767f4b2e25ef6989ca (diff) | |
| download | go-fe2da30cb54aadeab243f3fc7bd3e14dd4da2892.tar.xz | |
cmd/compile: keep variables alive in testing.B.Loop loops
For the loop body guarded by testing.B.Loop, we disable function inlining and devirtualization inside. The only legal form to be matched is `for b.Loop() {...}`.
For #61515
Change-Id: I2e226f08cb4614667cbded498a7821dffe3f72d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/612043
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Bypass: Junyang Shao <shaojunyang@google.com>
Commit-Queue: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/inline_testingbloop.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/inline_testingbloop.go b/test/inline_testingbloop.go new file mode 100644 index 0000000000..9d5138e2d8 --- /dev/null +++ b/test/inline_testingbloop.go @@ -0,0 +1,31 @@ +// errorcheck -0 -m=2 + +// 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. + +// Test no inlining of function calls in testing.B.Loop. +// See issue #61515. + +package foo + +import "testing" + +func caninline(x int) int { // ERROR "can inline caninline" + return x +} + +func cannotinline(b *testing.B) { // ERROR "b does not escape" "cannot inline cannotinline.*" + for i := 0; i < b.N; i++ { + caninline(1) // ERROR "inlining call to caninline" + } + for b.Loop() { // ERROR "skip inlining within testing.B.loop" + caninline(1) + } + for i := 0; i < b.N; i++ { + caninline(1) // ERROR "inlining call to caninline" + } + for b.Loop() { // ERROR "skip inlining within testing.B.loop" + caninline(1) + } +} |
