...
1[short] skip
2
3# This test may go away when the loopvar experiment goes away.
4# Accurate reporting of notable loops in the presence of inlining
5# can create warnings in sibling directories, and it's nice if those
6# can be trimmed like subdirectory paths are.
7
8env GOEXPERIMENT=loopvar
9go build -gcflags=inlines/a=-d=loopvar=2 .
10stderr ^\.[\\/]b[\\/]b\.go:12:6:.*loop.inlined.into.a[\\/]a\.go
11stderr ^\.[\\/]b[\\/]b\.go:12:9:.*loop.inlined.into.a[\\/]a\.go
12
13-- go.mod --
14module inlines
15
16go 1.21
17-- a/a.go --
18// Copyright 2023 The Go Authors. All rights reserved.
19// Use of this source code is governed by a BSD-style
20// license that can be found in the LICENSE file.
21
22package a
23
24import "inlines/b"
25
26func F() []*int {
27 var s []*int
28 for i := 0; i < 10; i++ {
29 s = append(s, &i)
30 }
31 return s
32}
33
34func Fb() []*int {
35 bf, _ := b.F()
36 return bf
37}
38-- b/b.go --
39package b
40
41var slice = []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}
42
43func F() ([]*int, []*int) {
44 return g()
45}
46
47func g() ([]*int, []*int) {
48 var s []*int
49 var t []*int
50 for i, j := range slice {
51 s = append(s, &i)
52 t = append(t, &j)
53 }
54 return s[:len(s)-1], t
55}
56-- main.go --
57package main
58
59import (
60 "fmt"
61 "inlines/a"
62 "inlines/b"
63)
64
65func sum(s []*int) int {
66 sum := 0
67 for _, pi := range s {
68 sum += *pi
69 }
70 return sum
71}
72
73func main() {
74 af := a.F()
75 bf, _ := b.F()
76 abf := a.Fb()
77
78 saf, sbf, sabf := sum(af), sum(bf), sum(abf)
79
80 fmt.Printf("af, bf, abf sums = %d, %d, %d\n", saf, sbf, sabf)
81}
View as plain text