Commit 529362e1 authored by David Chase's avatar David Chase

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 <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 1771edb5
......@@ -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()
......
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment