From c450ace12c657e3953d79975c04f51605395cd50 Mon Sep 17 00:00:00 2001 From: David Chase Date: Mon, 29 Jul 2019 16:23:31 -0400 Subject: [PATCH] cmd/compile: remove statement marks from secondary calls Calls are code-generated in an alternate path that inherits its positions from values, not from *SSAGenState. The default position on *SSAGenState was marked as not-a-statement, but this was not applied to the value itself, leading to spurious "is statement" marks in the output (convention: after code generation in the compiler, everything is either definitely a statement or definitely not a statement, nothing is in the undetermined state). This CL causes a 35 statement regression in ssa/stmtlines_test. This is down from the earlier 150 because of all the other CLs preceding this one that deal with the root causes of the missing lines (repeated lines on nested calls hid missing lines). This also removes some line repeats from ssa/debug_test. Change-Id: Ie9a507bd5447e906b35bbd098e3295211df2ae01 Reviewed-on: https://go-review.googlesource.com/c/go/+/188018 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- src/cmd/compile/internal/gc/ssa.go | 10 ++++- .../internal/ssa/testdata/hist.dlv-opt.nexts | 8 ---- .../internal/ssa/testdata/hist.gdb-dbg.nexts | 2 +- .../internal/ssa/testdata/hist.gdb-opt.nexts | 44 ++++--------------- 4 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index ed1cccc6b0a..a263fa7e996 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -5238,8 +5238,11 @@ func (s *SSAGenState) DebugFriendlySetPosFrom(v *ssa.Value) { // in the generated code. if p.IsStmt() != src.PosIsStmt { p = p.WithNotStmt() + // Calls use the pos attached to v, but copy the statement mark from SSAGenState } s.SetPos(p) + } else { + s.SetPos(s.pp.pos.WithNotStmt()) } } } @@ -5878,10 +5881,15 @@ func (s *SSAGenState) AddrScratch(a *obj.Addr) { // Call returns a new CALL instruction for the SSA value v. // It uses PrepareCall to prepare the call. func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog { + pPosIsStmt := s.pp.pos.IsStmt() // The statement-ness fo the call comes from ssaGenState s.PrepareCall(v) p := s.Prog(obj.ACALL) - p.Pos = v.Pos + if pPosIsStmt == src.PosIsStmt { + p.Pos = v.Pos.WithIsStmt() + } else { + p.Pos = v.Pos.WithNotStmt() + } if sym, ok := v.Aux.(*obj.LSym); ok { p.To.Type = obj.TYPE_MEM p.To.Name = obj.NAME_EXTERN diff --git a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts index 1e4d35051b6..2be83ce9369 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts @@ -70,32 +70,24 @@ 87: if a == 0 { //gdb-opt=(a,n,t) 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) 86: for i, a := range hist { diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts index 4fde3bcc66b..72df60c76f4 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-dbg.nexts @@ -9,7 +9,7 @@ l.end.y = 4 61: sink = dx + dy //gdb-opt=(dx,dy) 63: hist := make([]int, 7) //gdb-opt=(dx/O,dy/O) // TODO sink is missing if this code is in 'test' instead of 'main' 64: var reader io.Reader = strings.NewReader(cannedInput) //gdb-dbg=(hist/A) // TODO cannedInput/A is missing if this code is in 'test' instead of 'main' -hist = []int = {0, 0, 0, 0, 0, 0, 0} +hist = {array = , len = 7, cap = 7} 65: if len(os.Args) > 1 { 73: scanner := bufio.NewScanner(reader) 74: for scanner.Scan() { //gdb-opt=(scanner/A) diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts index 65c5d0a2cee..d3a34acf691 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts @@ -24,92 +24,74 @@ scanner = (bufio.Scanner *) 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 0, 0, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 1, 0, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 2, 0, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 0, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 1, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 2, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 3, 0, 0, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 4 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 3, 0, 1, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 4 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) err = {tab = 0x0, data = 0x0} -hist = []int = {0, 3, 3, 0, 2, 0, 0} +hist = {array = 0xc00005ae50, len = 7, cap = 7} i = 5 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ -74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (bufio.Scanner *) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0 @@ -122,9 +104,7 @@ n = 0 t = 0 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 3 @@ -132,9 +112,7 @@ n = 3 t = 3 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0 @@ -147,9 +125,7 @@ n = 6 t = 9 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 1 @@ -157,9 +133,7 @@ n = 8 t = 17 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 90: t += i * a -92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0