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

cmd/compile: missing source information in ssa view #51988

Closed
katsusan opened this issue Mar 28, 2022 · 6 comments
Closed

cmd/compile: missing source information in ssa view #51988

katsusan opened this issue Mar 28, 2022 · 6 comments
Labels
help wanted NeedsFix
Milestone

Comments

@katsusan
Copy link

@katsusan katsusan commented Mar 28, 2022

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

$ go version
go version go1.18 linux/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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="/usr/local/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build481024948=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. try following source:
package main

func main() {
        r := min(1, 6)
        println(r)
}

func min[T int | int32 | int64](x, y T) T {
        if x < y {
                return x
        }
        return y
}
  1. run GOSSAFUNC='min[go.shape.int_0]' go tool compile z.go and open the generated ssa.html.

What did you expect to see?

The source of function min shown in sources column.

What did you see instead?

image

Possible reason

The typeschecker seems giving wrong endline info in ir.Func.

>>> info frame
Stack level 0, frame at 0xc000467a30:
 rip = 0xa6b5ef in cmd/compile/internal/ssagen.buildssa (/usr/local/go/src/cmd/compile/internal/ssagen/ssa.go:348); saved rip = 0xa6442c
 called by frame at 0xc000467af8
 source language unknown.
 Arglist at 0xc0004676b0, args: fn=0xc000445080, worker=0, ~r0=<optimized out>, ~r0=<optimized out>
 Locals at 0xc0004676b0, Previous frame's sp is 0xc000467a30
 Saved registers:
  rip at 0xc000467a28
>>> p fn.Nname.sym.Name
$26 = "min[go.shape.int_0]"
>>> p fn.Endlineno
$27 = {
  index = 0,
  lico = 0
}
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Mar 28, 2022

The typeschecker seems giving wrong endline info in ir.Func.

Thanks. Probably (*genInst).genericSubst in cmd/compile/internal/noder/stencil.go just needs newf.Endlineno = gf.Endlineno.

@cherrymui cherrymui added the NeedsFix label Apr 5, 2022
@cherrymui cherrymui added this to the Unplanned milestone Apr 5, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 8, 2022

Change https://go.dev/cl/399057 mentions this issue: cmd/compile: fix missing source information in ssa view

@hopehook
Copy link
Contributor

@hopehook hopehook commented Apr 8, 2022

The typeschecker seems giving wrong endline info in ir.Func.

Thanks. Probably (*genInst).genericSubst in cmd/compile/internal/noder/stencil.go just needs newf.Endlineno = gf.Endlineno.

I did this and the result is as follows, func min outputs twice, not sure if it is necessary to deduplicate.

  • Read sources of target function fn. output once
  • Read sources of inlined functions. output once

image

@hopehook
Copy link
Contributor

@hopehook hopehook commented Apr 14, 2022

The typeschecker seems giving wrong endline info in ir.Func.

Thanks. Probably (*genInst).genericSubst in cmd/compile/internal/noder/stencil.go just needs newf.Endlineno = gf.Endlineno.

I did this and the result is as follows, func min outputs twice, not sure if it is necessary to deduplicate.

  • Read sources of target function fn. output once
  • Read sources of inlined functions. output once

image

@mdempsky Hi, Matthew Dempsky. Could you take a look at this question.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Apr 14, 2022

@hopehook Hi, sorry, I'm not familiar with that part of the compiler. I'm not sure why the debug view is listing the sources twice. Removing the duplication seems desirable to me, if you want to investigate why.

@hopehook
Copy link
Contributor

@hopehook hopehook commented Apr 14, 2022

@mdempsky Thank you very much. I don't know the exact reason, so I don't dare to change it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix
Projects
None yet
Development

No branches or pull requests

5 participants