Skip to content

Commit bb0b511

Browse files
committed
cmd/compile: use right line number for conversion expression
Use the position of the actual conversion operation instead of base.Pos. Fixes #47880 Change-Id: I56adc134e09cb7fd625adc0a847c1a6b3e254b1a Reviewed-on: https://go-review.googlesource.com/c/go/+/345095 Trust: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 7637345 commit bb0b511

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/cmd/compile/internal/walk/convert.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"cmd/compile/internal/ssagen"
1515
"cmd/compile/internal/typecheck"
1616
"cmd/compile/internal/types"
17+
"cmd/internal/src"
1718
"cmd/internal/sys"
1819
)
1920

@@ -58,7 +59,7 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
5859
} else {
5960
typeWord = reflectdata.ITabAddr(fromType, toType)
6061
}
61-
l := ir.NewBinaryExpr(base.Pos, ir.OEFACE, typeWord, dataWord(n.X, init, n.Esc() != ir.EscNone))
62+
l := ir.NewBinaryExpr(base.Pos, ir.OEFACE, typeWord, dataWord(n.Pos(), n.X, init, n.Esc() != ir.EscNone))
6263
l.SetType(toType)
6364
l.SetTypecheck(n.Typecheck())
6465
return l
@@ -75,7 +76,7 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
7576
itab := ir.NewUnaryExpr(base.Pos, ir.OITAB, c)
7677
itab.SetType(types.Types[types.TUINTPTR].PtrTo())
7778
itab.SetTypecheck(1)
78-
data := ir.NewUnaryExpr(base.Pos, ir.OIDATA, c)
79+
data := ir.NewUnaryExpr(n.Pos(), ir.OIDATA, c)
7980
data.SetType(types.Types[types.TUINT8].PtrTo()) // Type is generic pointer - we're just passing it through.
8081
data.SetTypecheck(1)
8182

@@ -112,7 +113,7 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
112113
// Returns the data word (the second word) used to represent n in an interface.
113114
// n must not be of interface type.
114115
// esc describes whether the result escapes.
115-
func dataWord(n ir.Node, init *ir.Nodes, escapes bool) ir.Node {
116+
func dataWord(pos src.XPos, n ir.Node, init *ir.Nodes, escapes bool) ir.Node {
116117
fromType := n.Type()
117118

118119
// If it's a pointer, it is its own representation.
@@ -184,16 +185,16 @@ func dataWord(n ir.Node, init *ir.Nodes, escapes bool) ir.Node {
184185
fromType.IsPtrShaped() && argType.IsPtrShaped():
185186
// can directly convert (e.g. named type to underlying type, or one pointer to another)
186187
// TODO: never happens because pointers are directIface?
187-
arg = ir.NewConvExpr(n.Pos(), ir.OCONVNOP, argType, n)
188+
arg = ir.NewConvExpr(pos, ir.OCONVNOP, argType, n)
188189
case fromType.IsInteger() && argType.IsInteger():
189190
// can directly convert (e.g. int32 to uint32)
190-
arg = ir.NewConvExpr(n.Pos(), ir.OCONV, argType, n)
191+
arg = ir.NewConvExpr(pos, ir.OCONV, argType, n)
191192
default:
192193
// unsafe cast through memory
193194
arg = copyExpr(n, fromType, init)
194195
var addr ir.Node = typecheck.NodAddr(arg)
195-
addr = ir.NewConvExpr(n.Pos(), ir.OCONVNOP, argType.PtrTo(), addr)
196-
arg = ir.NewStarExpr(n.Pos(), addr)
196+
addr = ir.NewConvExpr(pos, ir.OCONVNOP, argType.PtrTo(), addr)
197+
arg = ir.NewStarExpr(pos, addr)
197198
arg.SetType(argType)
198199
}
199200
args = []ir.Node{arg}
@@ -206,7 +207,7 @@ func dataWord(n ir.Node, init *ir.Nodes, escapes bool) ir.Node {
206207
// walkConvIData walks an OCONVIDATA node.
207208
func walkConvIData(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
208209
n.X = walkExpr(n.X, init)
209-
return dataWord(n.X, init, n.Esc() != ir.EscNone)
210+
return dataWord(n.Pos(), n.X, init, n.Esc() != ir.EscNone)
210211
}
211212

212213
// walkBytesRunesToString walks an OBYTES2STR or ORUNES2STR node.

0 commit comments

Comments
 (0)