Skip to content
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

runtime: Caller can return <autogenerated> as filename when called from a global variable #64520

Open
pgimalac opened this issue Dec 2, 2023 · 0 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pgimalac
Copy link

pgimalac commented Dec 2, 2023

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

$ go version
go version devel go1.22-de5b418bea Sat Dec 2 03:15:03 2023 +0000 darwin/arm64

Does this issue reproduce with the latest release?

No, the issue appeared with 88cb17e (unreleased).

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

go env Output
$ go env
GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/pierre.gimalac/Library/Caches/go-build'
GOENV='/Users/pierre.gimalac/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/pierre.gimalac/go/pkg/mod'
GONOPROXY='github.com/DataDog'
GONOSUMDB='github.com/DataDog,go.ddbuild.io'
GOOS='darwin'
GOPATH='/Users/pierre.gimalac/go'
GOPRIVATE='github.com/DataDog'
GOPROXY='binaries.ddbuild.io,proxy.golang.org,direct'
GOROOT='/tmp/dFNYRnSYTNDcoJjl/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/tmp/dFNYRnSYTNDcoJjl/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.22-de5b418bea Sat Dec 2 03:15:03 2023 +0000'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/tmp/gist/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/zp/m8h1x16s30g3f656sxsdt7rm0000gp/T/go-build2626990949=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOROOT/bin/go version: go version devel go1.22-de5b418bea Sat Dec 2 03:15:03 2023 +0000 darwin/arm64
GOROOT/bin/go tool compile -V: compile version devel go1.22-de5b418bea Sat Dec 2 03:15:03 2023 +0000
uname -v: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
ProductName:		macOS
ProductVersion:		13.5.2
BuildVersion:		22G91
lldb --version: lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)

What did you do?

When using the current dev version of Go, runtime.Caller can return <autogenerated> as caller filename, instead of the actual caller filename.

Minimal reproducible example can be found on https://github.com/pgimalac/gist/tree/go-runtime-caller-filename-autogenerated (I could not reduce it to a single file, but it's rather small as it is).

The example declares a global variable which indirectly calls runtime.Caller, which returns <autogenerated> instead of the actual filename.
A main function prints an error with the returned filename if it doesn't contain package1. It can run with go run main.go.

If this is not considered a bug, the documentation should make it clear that runtime.Caller can return something else when called from a global variable.

What did you expect to see?

runtime.Caller should return <root>/mypackage1/myfile.go.

What did you see instead?

runtime.Caller returns <autogenerated>.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 2, 2023
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 4, 2023
@mknyszek mknyszek added this to the Go1.22 milestone Dec 13, 2023
@gopherbot gopherbot modified the milestones: Go1.22, Go1.23 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants