Skip to content

Commit b94dc38

Browse files
mdempskygopherbot
authored andcommitted
cmd/compile/internal/ir: explicit Pos for New{Bool,Int,String}
Stop depending on base.Pos for these. Change-Id: I58dea44f8141eb37b59a6e9f7db0c6baa516ad93 Reviewed-on: https://go-review.googlesource.com/c/go/+/472296 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent ce2a609 commit b94dc38

File tree

19 files changed

+115
-119
lines changed

19 files changed

+115
-119
lines changed

src/cmd/compile/internal/compare/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func eqmem(p ir.Node, q ir.Node, field *types.Sym, size int64) ir.Node {
331331
call.Args.Append(nx)
332332
call.Args.Append(ny)
333333
if needsize {
334-
call.Args.Append(ir.NewInt(size))
334+
call.Args.Append(ir.NewInt(base.Pos, size))
335335
}
336336

337337
return call

src/cmd/compile/internal/coverage/cover.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
157157
pos := cnames.InitFn.Pos()
158158
elist := make([]ir.Node, 0, 16)
159159
for i := 0; i < 16; i++ {
160-
elem := ir.NewInt(int64(hashv[i]))
160+
elem := ir.NewInt(base.Pos, int64(hashv[i]))
161161
elist = append(elist, elem)
162162
}
163163
ht := types.NewArray(types.Types[types.TUINT8], 16)
@@ -168,18 +168,18 @@ func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
168168
mdauspx := typecheck.ConvNop(mdax, types.Types[types.TUNSAFEPTR])
169169

170170
// Materialize expression for length.
171-
lenx := ir.NewInt(int64(mdlen)) // untyped
171+
lenx := ir.NewInt(base.Pos, int64(mdlen)) // untyped
172172

173173
// Generate a call to runtime.addCovMeta, e.g.
174174
//
175175
// pkgIdVar = runtime.addCovMeta(&sym, len, hash, pkgpath, pkid, cmode, cgran)
176176
//
177177
fn := typecheck.LookupRuntime("addCovMeta")
178178
pkid := coverage.HardCodedPkgID(base.Ctxt.Pkgpath)
179-
pkIdNode := ir.NewInt(int64(pkid))
180-
cmodeNode := ir.NewInt(int64(cnames.CounterMode))
181-
cgranNode := ir.NewInt(int64(cnames.CounterGran))
182-
pkPathNode := ir.NewString(base.Ctxt.Pkgpath)
179+
pkIdNode := ir.NewInt(base.Pos, int64(pkid))
180+
cmodeNode := ir.NewInt(base.Pos, int64(cnames.CounterMode))
181+
cgranNode := ir.NewInt(base.Pos, int64(cnames.CounterGran))
182+
pkPathNode := ir.NewString(base.Pos, base.Ctxt.Pkgpath)
183183
callx := typecheck.Call(pos, fn, []ir.Node{mdauspx, lenx, hashx,
184184
pkPathNode, pkIdNode, cmodeNode, cgranNode}, false)
185185
assign := callx
@@ -202,7 +202,7 @@ func addInitHookCall(initfn *ir.Func, cmode coverage.CounterMode) {
202202
pos := initfn.Pos()
203203
istest := cmode == coverage.CtrModeTestMain
204204
initf := typecheck.LookupCoverage("initHook")
205-
istestNode := ir.NewBool(istest)
205+
istestNode := ir.NewBool(base.Pos, istest)
206206
args := []ir.Node{istestNode}
207207
callx := typecheck.Call(pos, initf, args, false)
208208
initfn.Body.Append(callx)

src/cmd/compile/internal/escape/desugar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func fixRecoverCall(call *ir.CallExpr) {
2727
// FP is equal to caller's SP plus FixedFrameSize.
2828
var fp ir.Node = ir.NewCallExpr(pos, ir.OGETCALLERSP, nil, nil)
2929
if off := base.Ctxt.Arch.FixedFrameSize; off != 0 {
30-
fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(off))
30+
fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(base.Pos, off))
3131
}
3232
// TODO(mdempsky): Replace *int32 with unsafe.Pointer, without upsetting checkptr.
3333
fp = ir.NewConvExpr(pos, ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)

src/cmd/compile/internal/ir/const.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ import (
1111

1212
"cmd/compile/internal/base"
1313
"cmd/compile/internal/types"
14+
"cmd/internal/src"
1415
)
1516

16-
func NewBool(b bool) Node {
17-
return NewLiteral(constant.MakeBool(b))
17+
func NewBool(pos src.XPos, b bool) Node {
18+
return NewBasicLit(pos, constant.MakeBool(b))
1819
}
1920

20-
func NewInt(v int64) Node {
21-
return NewLiteral(constant.MakeInt64(v))
21+
func NewInt(pos src.XPos, v int64) Node {
22+
return NewBasicLit(pos, constant.MakeInt64(v))
2223
}
2324

24-
func NewString(s string) Node {
25-
return NewLiteral(constant.MakeString(s))
25+
func NewString(pos src.XPos, s string) Node {
26+
return NewBasicLit(pos, constant.MakeString(s))
2627
}
2728

2829
const (

src/cmd/compile/internal/ir/val.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ func ValidTypeForConst(t *types.Type, v constant.Value) bool {
6060
panic("unreachable")
6161
}
6262

63-
// NewLiteral returns a new untyped constant with value v.
64-
func NewLiteral(v constant.Value) Node {
65-
return NewBasicLit(base.Pos, v)
66-
}
67-
6863
func idealType(ct constant.Kind) *types.Type {
6964
switch ct {
7065
case constant.String:

src/cmd/compile/internal/pkginit/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func Task() *ir.Name {
143143
}, nil))
144144
asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
145145
asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
146-
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(0))), types.Types[types.TUNSAFEPTR]))
147-
asancall.Args.Append(typecheck.ConvNop(ir.NewInt(int64(ni)), types.Types[types.TUINTPTR]))
146+
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, 0))), types.Types[types.TUNSAFEPTR]))
147+
asancall.Args.Append(typecheck.ConvNop(ir.NewInt(base.Pos, int64(ni)), types.Types[types.TUINTPTR]))
148148

149149
fnInit.Body.Append(asancall)
150150
typecheck.FinishFuncBody()

src/cmd/compile/internal/pkginit/initAsanGlobals.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
6969
for i, n := range InstrumentGlobalsSlice {
7070
setField := func(f string, val ir.Node, i int) {
7171
r := ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT,
72-
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(int64(i))), lname(f)), val)
72+
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, int64(i))), lname(f)), val)
7373
init.Append(typecheck.Stmt(r))
7474
}
7575
// globals[i].beg = uintptr(unsafe.Pointer(&n))
@@ -79,43 +79,43 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
7979
// Assign globals[i].size.
8080
g := n.(*ir.Name)
8181
size := g.Type().Size()
82-
c = tconv(ir.NewInt(size), types.Types[types.TUINTPTR])
82+
c = tconv(ir.NewInt(base.Pos, size), types.Types[types.TUINTPTR])
8383
setField("size", c, i)
8484
// Assign globals[i].sizeWithRedzone.
8585
rzSize := GetRedzoneSizeForGlobal(size)
8686
sizeWithRz := rzSize + size
87-
c = tconv(ir.NewInt(sizeWithRz), types.Types[types.TUINTPTR])
87+
c = tconv(ir.NewInt(base.Pos, sizeWithRz), types.Types[types.TUINTPTR])
8888
setField("sizeWithRedzone", c, i)
8989
// The C string type is terminated by a null character "\0", Go should use three-digit
9090
// octal "\000" or two-digit hexadecimal "\x00" to create null terminated string.
9191
// asanName = symbol's linkname + "\000"
9292
// globals[i].name = (*defString)(unsafe.Pointer(&asanName)).data
9393
name := g.Linksym().Name
94-
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanName, ir.NewString(name+"\000"))))
94+
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanName, ir.NewString(base.Pos, name+"\000"))))
9595
c = tconv(typecheck.NodAddr(asanName), types.Types[types.TUNSAFEPTR])
9696
c = tconv(c, types.NewPtr(defStringstruct))
9797
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
9898
setField("name", c, i)
9999

100100
// Set the name of package being compiled as a unique identifier of a module.
101101
// asanModulename = pkgName + "\000"
102-
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanModulename, ir.NewString(types.LocalPkg.Name+"\000"))))
102+
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanModulename, ir.NewString(base.Pos, types.LocalPkg.Name+"\000"))))
103103
c = tconv(typecheck.NodAddr(asanModulename), types.Types[types.TUNSAFEPTR])
104104
c = tconv(c, types.NewPtr(defStringstruct))
105105
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
106106
setField("moduleName", c, i)
107107
// Assign asanL[i].filename, asanL[i].line, asanL[i].column
108108
// and assign globals[i].location = uintptr(unsafe.Pointer(&asanL[i]))
109-
asanLi := ir.NewIndexExpr(base.Pos, asanlocation, ir.NewInt(int64(i)))
110-
filename := ir.NewString(base.Ctxt.PosTable.Pos(n.Pos()).Filename() + "\000")
109+
asanLi := ir.NewIndexExpr(base.Pos, asanlocation, ir.NewInt(base.Pos, int64(i)))
110+
filename := ir.NewString(base.Pos, base.Ctxt.PosTable.Pos(n.Pos()).Filename()+"\000")
111111
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanFilename, filename)))
112112
c = tconv(typecheck.NodAddr(asanFilename), types.Types[types.TUNSAFEPTR])
113113
c = tconv(c, types.NewPtr(defStringstruct))
114114
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
115115
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("filename")), c)))
116-
line := ir.NewInt(int64(n.Pos().Line()))
116+
line := ir.NewInt(base.Pos, int64(n.Pos().Line()))
117117
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("line")), line)))
118-
col := ir.NewInt(int64(n.Pos().Col()))
118+
col := ir.NewInt(base.Pos, int64(n.Pos().Col()))
119119
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("column")), col)))
120120
c = tconv(typecheck.NodAddr(asanLi), types.Types[types.TUNSAFEPTR])
121121
c = tconv(c, types.Types[types.TUINTPTR])

src/cmd/compile/internal/reflectdata/alg.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ func hashFunc(t *types.Type) *ir.Func {
163163

164164
// for i := 0; i < nelem; i++
165165
ni := typecheck.Temp(types.Types[types.TINT])
166-
init := ir.NewAssignStmt(base.Pos, ni, ir.NewInt(0))
167-
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, ni, ir.NewInt(t.NumElem()))
168-
post := ir.NewAssignStmt(base.Pos, ni, ir.NewBinaryExpr(base.Pos, ir.OADD, ni, ir.NewInt(1)))
166+
init := ir.NewAssignStmt(base.Pos, ni, ir.NewInt(base.Pos, 0))
167+
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, ni, ir.NewInt(base.Pos, t.NumElem()))
168+
post := ir.NewAssignStmt(base.Pos, ni, ir.NewBinaryExpr(base.Pos, ir.OADD, ni, ir.NewInt(base.Pos, 1)))
169169
loop := ir.NewForStmt(base.Pos, nil, cond, post, nil)
170170
loop.PtrInit().Append(init)
171171

@@ -216,7 +216,7 @@ func hashFunc(t *types.Type) *ir.Func {
216216
na := typecheck.NodAddr(nx)
217217
call.Args.Append(na)
218218
call.Args.Append(nh)
219-
call.Args.Append(ir.NewInt(size))
219+
call.Args.Append(ir.NewInt(base.Pos, size))
220220
fn.Body.Append(ir.NewAssignStmt(base.Pos, nh, call))
221221

222222
i = next
@@ -440,8 +440,8 @@ func eqFunc(t *types.Type) *ir.Func {
440440
// Generate an unrolled for loop.
441441
// for i := 0; i < nelem/unroll*unroll; i += unroll
442442
i := typecheck.Temp(types.Types[types.TINT])
443-
init := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
444-
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(iterateTo))
443+
init := ir.NewAssignStmt(base.Pos, i, ir.NewInt(base.Pos, 0))
444+
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(base.Pos, iterateTo))
445445
loop := ir.NewForStmt(base.Pos, nil, cond, nil, nil)
446446
loop.PtrInit().Append(init)
447447

@@ -454,15 +454,15 @@ func eqFunc(t *types.Type) *ir.Func {
454454
nif := ir.NewIfStmt(base.Pos, checkIdx(i), nil, nil)
455455
nif.Else.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, neq))
456456
loop.Body.Append(nif)
457-
post := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, ir.NewInt(1)))
457+
post := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, ir.NewInt(base.Pos, 1)))
458458
loop.Body.Append(post)
459459
}
460460

461461
fn.Body.Append(loop)
462462

463463
if nelem == iterateTo {
464464
if last {
465-
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
465+
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, true)))
466466
}
467467
return
468468
}
@@ -479,12 +479,12 @@ func eqFunc(t *types.Type) *ir.Func {
479479
// }
480480
for j := iterateTo; j < nelem; j++ {
481481
// if check {} else { goto neq }
482-
nif := ir.NewIfStmt(base.Pos, checkIdx(ir.NewInt(j)), nil, nil)
482+
nif := ir.NewIfStmt(base.Pos, checkIdx(ir.NewInt(base.Pos, j)), nil, nil)
483483
nif.Else.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, neq))
484484
fn.Body.Append(nif)
485485
}
486486
if last {
487-
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(ir.NewInt(nelem))))
487+
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(ir.NewInt(base.Pos, nelem))))
488488
}
489489
}
490490

@@ -518,7 +518,7 @@ func eqFunc(t *types.Type) *ir.Func {
518518
case types.TSTRUCT:
519519
flatConds := compare.EqStruct(t, np, nq)
520520
if len(flatConds) == 0 {
521-
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
521+
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, true)))
522522
} else {
523523
for _, c := range flatConds[:len(flatConds)-1] {
524524
// if cond {} else { goto neq }
@@ -540,7 +540,7 @@ func eqFunc(t *types.Type) *ir.Func {
540540
// r = false
541541
// return (or goto ret)
542542
fn.Body.Append(ir.NewLabelStmt(base.Pos, neq))
543-
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(false)))
543+
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, false)))
544544
if compare.EqCanPanic(t) || anyCall(fn) {
545545
// Epilogue is large, so share it with the equal case.
546546
fn.Body.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, ret))

src/cmd/compile/internal/typecheck/func.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ func tcMake(n *ir.CallExpr) ir.Node {
678678
return n
679679
}
680680
} else {
681-
l = ir.NewInt(0)
681+
l = ir.NewInt(base.Pos, 0)
682682
}
683683
nn = ir.NewMakeExpr(n.Pos(), ir.OMAKEMAP, l, nil)
684684
nn.SetEsc(n.Esc())
@@ -699,7 +699,7 @@ func tcMake(n *ir.CallExpr) ir.Node {
699699
return n
700700
}
701701
} else {
702-
l = ir.NewInt(0)
702+
l = ir.NewInt(base.Pos, 0)
703703
}
704704
nn = ir.NewMakeExpr(n.Pos(), ir.OMAKECHAN, l, nil)
705705
}

src/cmd/compile/internal/typecheck/typecheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node {
16051605
var l []ir.Node
16061606
i := 0
16071607
for _, r := range ir.StringVal(n.X) {
1608-
l = append(l, ir.NewKeyExpr(base.Pos, ir.NewInt(int64(i)), ir.NewInt(int64(r))))
1608+
l = append(l, ir.NewKeyExpr(base.Pos, ir.NewInt(base.Pos, int64(i)), ir.NewInt(base.Pos, int64(r))))
16091609
i++
16101610
}
16111611

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func appendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
559559

560560
fn := typecheck.LookupRuntime("slicecopy")
561561
fn = typecheck.SubstArgTypes(fn, ptr1.Type().Elem(), ptr2.Type().Elem())
562-
ncopy = mkcall1(fn, types.Types[types.TINT], &nodes, ptr1, len1, ptr2, len2, ir.NewInt(elemtype.Size()))
562+
ncopy = mkcall1(fn, types.Types[types.TINT], &nodes, ptr1, len1, ptr2, len2, ir.NewInt(base.Pos, elemtype.Size()))
563563
} else {
564564
// memmove(&s[idx], &l2[0], len(l2)*sizeof(T))
565565
ix := ir.NewIndexExpr(base.Pos, s, idx)
@@ -569,7 +569,7 @@ func appendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
569569
sptr := ir.NewUnaryExpr(base.Pos, ir.OSPTR, l2)
570570

571571
nwid := cheapExpr(typecheck.Conv(ir.NewUnaryExpr(base.Pos, ir.OLEN, l2), types.Types[types.TUINTPTR]), &nodes)
572-
nwid = ir.NewBinaryExpr(base.Pos, ir.OMUL, nwid, ir.NewInt(elemtype.Size()))
572+
nwid = ir.NewBinaryExpr(base.Pos, ir.OMUL, nwid, ir.NewInt(base.Pos, elemtype.Size()))
573573

574574
// instantiate func memmove(to *any, frm *any, length uintptr)
575575
fn := typecheck.LookupRuntime("memmove")
@@ -667,7 +667,7 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
667667
var nodes []ir.Node
668668

669669
// if l2 >= 0 (likely happens), do nothing
670-
nifneg := ir.NewIfStmt(base.Pos, ir.NewBinaryExpr(base.Pos, ir.OGE, l2, ir.NewInt(0)), nil, nil)
670+
nifneg := ir.NewIfStmt(base.Pos, ir.NewBinaryExpr(base.Pos, ir.OGE, l2, ir.NewInt(base.Pos, 0)), nil, nil)
671671
nifneg.Likely = true
672672

673673
// else panicmakeslicelen()
@@ -718,7 +718,7 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
718718
hp := typecheck.ConvNop(typecheck.NodAddr(ix), types.Types[types.TUNSAFEPTR])
719719

720720
// hn := l2 * sizeof(elem(s))
721-
hn := typecheck.Conv(ir.NewBinaryExpr(base.Pos, ir.OMUL, l2, ir.NewInt(elemtype.Size())), types.Types[types.TUINTPTR])
721+
hn := typecheck.Conv(ir.NewBinaryExpr(base.Pos, ir.OMUL, l2, ir.NewInt(base.Pos, elemtype.Size())), types.Types[types.TUINTPTR])
722722

723723
clrname := "memclrNoHeapPointers"
724724
hasPointers := elemtype.HasPointers()

0 commit comments

Comments
 (0)