Skip to content

cmd/compile: inline message not right #54159

Closed
@578559967

Description

@578559967

What version of Go are you using (go version)?

$ go version
go version devel go1.19-be0b2a393a Wed Jun 22 02:40:04 2022 +0000 darwin/arm64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/r/Library/Caches/go-build"
GOENV="/Users/r/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/r/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/r/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="devel go1.19-be0b2a393a Wed Jun 22 02:40:04 2022 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/renzhenyu/workspace/testcode/testinline/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lr/5ttkwx8x6s9fm23m80546v180000gn/T/go-build3093233778=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import "fmt"

func run() {
	f := func() {
		fmt.Println("hello")
	}
	f()
	run()
}

func main() {
	run()
}

build this program with gcflags="-m=2",you will get these two conflict message:

go build --gcflags="-m=2" ./test3.go
# command-line-arguments
./test3.go:5:6: cannot inline run: recursive
./test3.go:6:7: can inline run.func1 with cost 76 as: func() { fmt.Println("hello") }
./test3.go:9:3: inlining call to run.func1      <------------------------------------------- message 1
./test3.go:9:3: inlining call to fmt.Println
./test3.go:6:7: cannot inline run.func1: recursive  <------------------------------------------- message 2
./test3.go:7:14: inlining call to fmt.Println
./test3.go:13:6: can inline main with cost 59 as: func() { run() }
./test3.go:9:3: "hello" escapes to heap:
./test3.go:9:3:   flow: {storage for ... argument} = &{storage for "hello"}:
./test3.go:9:3:     from "hello" (spill) at ./test3.go:9:3
./test3.go:9:3:     from ... argument (slice-literal-element) at ./test3.go:9:3
./test3.go:9:3:   flow: fmt.a = &{storage for ... argument}:
./test3.go:9:3:     from ... argument (spill) at ./test3.go:9:3
./test3.go:9:3:     from fmt.a := ... argument (assign-pair) at ./test3.go:9:3
./test3.go:9:3:   flow: {heap} = *fmt.a:
./test3.go:9:3:     from fmt.Fprintln(io.Writer(os.Stdout), fmt.a...) (call parameter) at ./test3.go:9:3
./test3.go:7:15: "hello" escapes to heap:
./test3.go:7:15:   flow: {storage for ... argument} = &{storage for "hello"}:
./test3.go:7:15:     from "hello" (spill) at ./test3.go:7:15
./test3.go:7:15:     from ... argument (slice-literal-element) at ./test3.go:7:14
./test3.go:7:15:   flow: fmt.a = &{storage for ... argument}:
./test3.go:7:15:     from ... argument (spill) at ./test3.go:7:14
./test3.go:7:15:     from fmt.a := ... argument (assign-pair) at ./test3.go:7:14
./test3.go:7:15:   flow: {heap} = *fmt.a:
./test3.go:7:15:     from fmt.Fprintln(io.Writer(os.Stdout), fmt.a...) (call parameter) at ./test3.go:7:14
./test3.go:6:7: func literal does not escape
./test3.go:7:14: ... argument does not escape
./test3.go:7:15: "hello" escapes to heap
./test3.go:9:3: ... argument does not escape
./test3.go:9:3: "hello" escapes to heap

What did you expect to see?

Expect message 2 ("cannot inline run.func1: recursive") not to be shown.

What did you see instead?

Message 2("cannot inline run.func1: recursive") is printed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions