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
8 env GOEXPERIMENT=loopvar
9 go build -gcflags=inlines/a=-d=loopvar=2 .
10 stderr ^\.[\\/]b[\\/]b\.go:12:6:.*loop.inlined.into.a[\\/]a\.go
11 stderr ^\.[\\/]b[\\/]b\.go:12:9:.*loop.inlined.into.a[\\/]a\.go
12
13 -- go.mod --
14 module inlines
15
16 go 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
22 package a
23
24 import "inlines/b"
25
26 func F() []*int {
27 var s []*int
28 for i := 0; i < 10; i++ {
29 s = append(s, &i)
30 }
31 return s
32 }
33
34 func Fb() []*int {
35 bf, _ := b.F()
36 return bf
37 }
38 -- b/b.go --
39 package b
40
41 var slice = []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}
42
43 func F() ([]*int, []*int) {
44 return g()
45 }
46
47 func 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 --
57 package main
58
59 import (
60 "fmt"
61 "inlines/a"
62 "inlines/b"
63 )
64
65 func sum(s []*int) int {
66 sum := 0
67 for _, pi := range s {
68 sum += *pi
69 }
70 return sum
71 }
72
73 func 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 }
82
View as plain text