Skip to content

inline: the wiki says compiler optimization wouldn't inline a function containing panic's #46062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hitzhangjie opened this issue May 9, 2021 · 4 comments

Comments

@hitzhangjie
Copy link
Contributor

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

$ go version
go version go1.16.3 darwin/amd64

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/zhangjie/Library/Caches/go-build"
GOENV="/Users/zhangjie/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhangjie/go/pkg/mod"
GONOPROXY="git.code.oa.com/*"
GONOSUMDB="git.code.oa.com/*"
GOOS="darwin"
GOPATH="/Users/zhangjie/go"
GOPRIVATE="git.code.oa.com/*"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0j/mvtnlhyj5j9cyqqq1b27bgg40000gn/T/go-build2792125826=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.16.3 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.16.3
uname -v: Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.15.7
BuildVersion:	19H1030
lldb --version: lldb-1200.0.44.2
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
gdb --version: GNU gdb (GDB) 10.1

What did you do?

I write a simple go code to validate inlining logic:

file: main.go

package main

import "fmt"

func main() {
	n := []float32{120.4, -46.7, 32.50, 34.65, -67.45}
	fmt.Printf("The total is %.02f\n", sum(n))
}

func sum(s []float32) float32 {
	var t float32
	for _, v := range s {
		if t < 0 {
			t = add(t, v)
		} else {
			t = sub(t, v)
		}
	}

	return t
}

func add(a, b float32) float32 {
	panic("hello")
	return 1.0
}

func sub(a, b float32) float32 {
	return a - b
}

then run `go run -gcflags='-m -m' main.go

What did you expect to see?

The wiki says the function containing panic's wouldn't be inlined. I want to see the function add not inlined.

What did you see instead?

I see the function add is inlined, the output is:

./main.go:23:6: can inline add with cost 5 as: func(float32, float32) float32 { panic("hello"); return 1 }
./main.go:28:6: can inline sub with cost 4 as: func(float32, float32) float32 { return a - b }
...

The wiki maybe not updated, if so, please update it.

@hitzhangjie hitzhangjie changed the title wiki: compiler optimization could inline a simple function containing panic inline: the wiki says compiler optimization wouldn't inline a function containing panic's May 9, 2021
@davecheney
Copy link
Contributor

You’re welcome to edit the wiki.

@seankhliao
Copy link
Member

The wiki is open for everyone to edit, no need to file issues about it

@hitzhangjie
Copy link
Contributor Author

You’re welcome to edit the wiki.

OK, thank you.

@hitzhangjie
Copy link
Contributor Author

The wiki is open for everyone to edit, no need to file issues about it

OK, thank you.

@golang golang locked and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants