Skip to content

Commit 529362e

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]>
1 parent 1771edb commit 529362e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/cmd/compile/internal/gc/gsubr.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
package gc
3232

3333
import (
34+
"cmd/compile/internal/ssa"
3435
"cmd/compile/internal/types"
3536
"cmd/internal/obj"
3637
"cmd/internal/objabi"
@@ -114,12 +115,8 @@ func (pp *Progs) Prog(as obj.As) *obj.Prog {
114115
p.As = as
115116
p.Pos = pp.pos
116117
if pp.pos.IsStmt() == src.PosIsStmt {
117-
// Clear IsStmt for later Progs at this pos provided that as generates executable code.
118-
switch as {
119-
// TODO: this is an artifact of how funcpctab combines information for instructions at a single PC.
120-
// Should try to fix it there. There is a similar workaround in *SSAGenState.Prog in gc/ssa.go.
121-
case obj.APCDATA, obj.AFUNCDATA:
122-
// is_stmt does not work for these; it DOES for ANOP
118+
// Clear IsStmt for later Progs at this pos provided that as can be marked as a stmt
119+
if ssa.LosesStmtMark(as) {
123120
return p
124121
}
125122
pp.pos = pp.pos.WithNotStmt()

src/cmd/compile/internal/gc/ssa.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,9 +4706,7 @@ type SSAGenState struct {
47064706
// Prog appends a new Prog.
47074707
func (s *SSAGenState) Prog(as obj.As) *obj.Prog {
47084708
p := s.pp.Prog(as)
4709-
switch as {
4710-
case obj.APCDATA, obj.AFUNCDATA:
4711-
// is_stmt does not work for these; it DOES for ANOP
4709+
if ssa.LosesStmtMark(as) {
47124710
return p
47134711
}
47144712
// Float a statement start to the beginning of any same-line run.

src/cmd/compile/internal/ssa/numberlines.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package ssa
66

77
import (
8+
"cmd/internal/obj"
89
"cmd/internal/src"
910
"math"
1011
)
@@ -19,6 +20,15 @@ func isPoorStatementOp(op Op) bool {
1920
return false
2021
}
2122

23+
// LosesStmtMark returns whether a prog with op as loses its statement mark on the way to DWARF.
24+
// The attributes from some opcodes are lost in translation.
25+
// TODO: this is an artifact of how funcpctab combines information for instructions at a single PC.
26+
// Should try to fix it there.
27+
func LosesStmtMark(as obj.As) bool {
28+
// is_stmt does not work for these; it DOES for ANOP even though that generates no code.
29+
return as == obj.APCDATA || as == obj.AFUNCDATA
30+
}
31+
2232
// nextGoodStatementIndex returns an index at i or later that is believed
2333
// to be a good place to start the statement for b. This decision is
2434
// based on v's Op, the possibility of a better later operation, and

0 commit comments

Comments
 (0)