From 529362e1e2d68c1740ee71a7d5ece3f2c5190791 Mon Sep 17 00:00:00 2001 From: David Chase Date: Fri, 18 May 2018 15:11:30 -0400 Subject: [PATCH] cmd/compile: refactor and cleanup of common code/workaround There's a glitch in how attributes from procs that do not generate code are combined, and the workaround for this glitch appeared in two places. "One big pile is better than two little ones." Updates #25426. Change-Id: I252f9adc5b77591720a61fa22e6f9dda33d95350 Reviewed-on: https://go-review.googlesource.com/113717 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/gc/gsubr.go | 9 +++------ src/cmd/compile/internal/gc/ssa.go | 4 +--- src/cmd/compile/internal/ssa/numberlines.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/gc/gsubr.go b/src/cmd/compile/internal/gc/gsubr.go index 29994afb8c..55b16792f9 100644 --- a/src/cmd/compile/internal/gc/gsubr.go +++ b/src/cmd/compile/internal/gc/gsubr.go @@ -31,6 +31,7 @@ package gc import ( + "cmd/compile/internal/ssa" "cmd/compile/internal/types" "cmd/internal/obj" "cmd/internal/objabi" @@ -114,12 +115,8 @@ func (pp *Progs) Prog(as obj.As) *obj.Prog { p.As = as p.Pos = pp.pos if pp.pos.IsStmt() == src.PosIsStmt { - // Clear IsStmt for later Progs at this pos provided that as generates executable code. - switch as { - // TODO: this is an artifact of how funcpctab combines information for instructions at a single PC. - // Should try to fix it there. There is a similar workaround in *SSAGenState.Prog in gc/ssa.go. - case obj.APCDATA, obj.AFUNCDATA: - // is_stmt does not work for these; it DOES for ANOP + // Clear IsStmt for later Progs at this pos provided that as can be marked as a stmt + if ssa.LosesStmtMark(as) { return p } pp.pos = pp.pos.WithNotStmt() diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 32003843e0..7d879395a6 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -4706,9 +4706,7 @@ type SSAGenState struct { // Prog appends a new Prog. func (s *SSAGenState) Prog(as obj.As) *obj.Prog { p := s.pp.Prog(as) - switch as { - case obj.APCDATA, obj.AFUNCDATA: - // is_stmt does not work for these; it DOES for ANOP + if ssa.LosesStmtMark(as) { return p } // Float a statement start to the beginning of any same-line run. diff --git a/src/cmd/compile/internal/ssa/numberlines.go b/src/cmd/compile/internal/ssa/numberlines.go index 14eceec77f..997b05c3a2 100644 --- a/src/cmd/compile/internal/ssa/numberlines.go +++ b/src/cmd/compile/internal/ssa/numberlines.go @@ -5,6 +5,7 @@ package ssa import ( + "cmd/internal/obj" "cmd/internal/src" "math" ) @@ -19,6 +20,15 @@ func isPoorStatementOp(op Op) bool { return false } +// LosesStmtMark returns whether a prog with op as loses its statement mark on the way to DWARF. +// The attributes from some opcodes are lost in translation. +// TODO: this is an artifact of how funcpctab combines information for instructions at a single PC. +// Should try to fix it there. +func LosesStmtMark(as obj.As) bool { + // is_stmt does not work for these; it DOES for ANOP even though that generates no code. + return as == obj.APCDATA || as == obj.AFUNCDATA +} + // nextGoodStatementIndex returns an index at i or later that is believed // to be a good place to start the statement for b. This decision is // based on v's Op, the possibility of a better later operation, and -- 2.48.1