Skip to content

Commit

Permalink
cmd/compile/internal/ir: explicit Pos for New{Bool,Int,String}
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mdempsky authored and gopherbot committed Mar 4, 2023
1 parent ce2a609 commit b94dc38
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func eqmem(p ir.Node, q ir.Node, field *types.Sym, size int64) ir.Node {
call.Args.Append(nx)
call.Args.Append(ny)
if needsize {
call.Args.Append(ir.NewInt(size))
call.Args.Append(ir.NewInt(base.Pos, size))
}

return call
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/compile/internal/coverage/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
pos := cnames.InitFn.Pos()
elist := make([]ir.Node, 0, 16)
for i := 0; i < 16; i++ {
elem := ir.NewInt(int64(hashv[i]))
elem := ir.NewInt(base.Pos, int64(hashv[i]))
elist = append(elist, elem)
}
ht := types.NewArray(types.Types[types.TUINT8], 16)
Expand All @@ -168,18 +168,18 @@ func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
mdauspx := typecheck.ConvNop(mdax, types.Types[types.TUNSAFEPTR])

// Materialize expression for length.
lenx := ir.NewInt(int64(mdlen)) // untyped
lenx := ir.NewInt(base.Pos, int64(mdlen)) // untyped

// Generate a call to runtime.addCovMeta, e.g.
//
// pkgIdVar = runtime.addCovMeta(&sym, len, hash, pkgpath, pkid, cmode, cgran)
//
fn := typecheck.LookupRuntime("addCovMeta")
pkid := coverage.HardCodedPkgID(base.Ctxt.Pkgpath)
pkIdNode := ir.NewInt(int64(pkid))
cmodeNode := ir.NewInt(int64(cnames.CounterMode))
cgranNode := ir.NewInt(int64(cnames.CounterGran))
pkPathNode := ir.NewString(base.Ctxt.Pkgpath)
pkIdNode := ir.NewInt(base.Pos, int64(pkid))
cmodeNode := ir.NewInt(base.Pos, int64(cnames.CounterMode))
cgranNode := ir.NewInt(base.Pos, int64(cnames.CounterGran))
pkPathNode := ir.NewString(base.Pos, base.Ctxt.Pkgpath)
callx := typecheck.Call(pos, fn, []ir.Node{mdauspx, lenx, hashx,
pkPathNode, pkIdNode, cmodeNode, cgranNode}, false)
assign := callx
Expand All @@ -202,7 +202,7 @@ func addInitHookCall(initfn *ir.Func, cmode coverage.CounterMode) {
pos := initfn.Pos()
istest := cmode == coverage.CtrModeTestMain
initf := typecheck.LookupCoverage("initHook")
istestNode := ir.NewBool(istest)
istestNode := ir.NewBool(base.Pos, istest)
args := []ir.Node{istestNode}
callx := typecheck.Call(pos, initf, args, false)
initfn.Body.Append(callx)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/escape/desugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func fixRecoverCall(call *ir.CallExpr) {
// FP is equal to caller's SP plus FixedFrameSize.
var fp ir.Node = ir.NewCallExpr(pos, ir.OGETCALLERSP, nil, nil)
if off := base.Ctxt.Arch.FixedFrameSize; off != 0 {
fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(off))
fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(base.Pos, off))
}
// TODO(mdempsky): Replace *int32 with unsafe.Pointer, without upsetting checkptr.
fp = ir.NewConvExpr(pos, ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
Expand Down
13 changes: 7 additions & 6 deletions src/cmd/compile/internal/ir/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import (

"cmd/compile/internal/base"
"cmd/compile/internal/types"
"cmd/internal/src"
)

func NewBool(b bool) Node {
return NewLiteral(constant.MakeBool(b))
func NewBool(pos src.XPos, b bool) Node {
return NewBasicLit(pos, constant.MakeBool(b))
}

func NewInt(v int64) Node {
return NewLiteral(constant.MakeInt64(v))
func NewInt(pos src.XPos, v int64) Node {
return NewBasicLit(pos, constant.MakeInt64(v))
}

func NewString(s string) Node {
return NewLiteral(constant.MakeString(s))
func NewString(pos src.XPos, s string) Node {
return NewBasicLit(pos, constant.MakeString(s))
}

const (
Expand Down
5 changes: 0 additions & 5 deletions src/cmd/compile/internal/ir/val.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ func ValidTypeForConst(t *types.Type, v constant.Value) bool {
panic("unreachable")
}

// NewLiteral returns a new untyped constant with value v.
func NewLiteral(v constant.Value) Node {
return NewBasicLit(base.Pos, v)
}

func idealType(ct constant.Kind) *types.Type {
switch ct {
case constant.String:
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/pkginit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func Task() *ir.Name {
}, nil))
asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(0))), types.Types[types.TUNSAFEPTR]))
asancall.Args.Append(typecheck.ConvNop(ir.NewInt(int64(ni)), types.Types[types.TUINTPTR]))
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, 0))), types.Types[types.TUNSAFEPTR]))
asancall.Args.Append(typecheck.ConvNop(ir.NewInt(base.Pos, int64(ni)), types.Types[types.TUINTPTR]))

fnInit.Body.Append(asancall)
typecheck.FinishFuncBody()
Expand Down
18 changes: 9 additions & 9 deletions src/cmd/compile/internal/pkginit/initAsanGlobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
for i, n := range InstrumentGlobalsSlice {
setField := func(f string, val ir.Node, i int) {
r := ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT,
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(int64(i))), lname(f)), val)
ir.NewIndexExpr(base.Pos, globals, ir.NewInt(base.Pos, int64(i))), lname(f)), val)
init.Append(typecheck.Stmt(r))
}
// globals[i].beg = uintptr(unsafe.Pointer(&n))
Expand All @@ -79,43 +79,43 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
// Assign globals[i].size.
g := n.(*ir.Name)
size := g.Type().Size()
c = tconv(ir.NewInt(size), types.Types[types.TUINTPTR])
c = tconv(ir.NewInt(base.Pos, size), types.Types[types.TUINTPTR])
setField("size", c, i)
// Assign globals[i].sizeWithRedzone.
rzSize := GetRedzoneSizeForGlobal(size)
sizeWithRz := rzSize + size
c = tconv(ir.NewInt(sizeWithRz), types.Types[types.TUINTPTR])
c = tconv(ir.NewInt(base.Pos, sizeWithRz), types.Types[types.TUINTPTR])
setField("sizeWithRedzone", c, i)
// The C string type is terminated by a null character "\0", Go should use three-digit
// octal "\000" or two-digit hexadecimal "\x00" to create null terminated string.
// asanName = symbol's linkname + "\000"
// globals[i].name = (*defString)(unsafe.Pointer(&asanName)).data
name := g.Linksym().Name
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanName, ir.NewString(name+"\000"))))
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanName, ir.NewString(base.Pos, name+"\000"))))
c = tconv(typecheck.NodAddr(asanName), types.Types[types.TUNSAFEPTR])
c = tconv(c, types.NewPtr(defStringstruct))
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
setField("name", c, i)

// Set the name of package being compiled as a unique identifier of a module.
// asanModulename = pkgName + "\000"
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanModulename, ir.NewString(types.LocalPkg.Name+"\000"))))
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanModulename, ir.NewString(base.Pos, types.LocalPkg.Name+"\000"))))
c = tconv(typecheck.NodAddr(asanModulename), types.Types[types.TUNSAFEPTR])
c = tconv(c, types.NewPtr(defStringstruct))
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
setField("moduleName", c, i)
// Assign asanL[i].filename, asanL[i].line, asanL[i].column
// and assign globals[i].location = uintptr(unsafe.Pointer(&asanL[i]))
asanLi := ir.NewIndexExpr(base.Pos, asanlocation, ir.NewInt(int64(i)))
filename := ir.NewString(base.Ctxt.PosTable.Pos(n.Pos()).Filename() + "\000")
asanLi := ir.NewIndexExpr(base.Pos, asanlocation, ir.NewInt(base.Pos, int64(i)))
filename := ir.NewString(base.Pos, base.Ctxt.PosTable.Pos(n.Pos()).Filename()+"\000")
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, asanFilename, filename)))
c = tconv(typecheck.NodAddr(asanFilename), types.Types[types.TUNSAFEPTR])
c = tconv(c, types.NewPtr(defStringstruct))
c = ir.NewSelectorExpr(base.Pos, ir.ODOT, c, lname("data"))
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("filename")), c)))
line := ir.NewInt(int64(n.Pos().Line()))
line := ir.NewInt(base.Pos, int64(n.Pos().Line()))
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("line")), line)))
col := ir.NewInt(int64(n.Pos().Col()))
col := ir.NewInt(base.Pos, int64(n.Pos().Col()))
init.Append(typecheck.Stmt(ir.NewAssignStmt(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, asanLi, lname("column")), col)))
c = tconv(typecheck.NodAddr(asanLi), types.Types[types.TUNSAFEPTR])
c = tconv(c, types.Types[types.TUINTPTR])
Expand Down
24 changes: 12 additions & 12 deletions src/cmd/compile/internal/reflectdata/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func hashFunc(t *types.Type) *ir.Func {

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

Expand Down Expand Up @@ -216,7 +216,7 @@ func hashFunc(t *types.Type) *ir.Func {
na := typecheck.NodAddr(nx)
call.Args.Append(na)
call.Args.Append(nh)
call.Args.Append(ir.NewInt(size))
call.Args.Append(ir.NewInt(base.Pos, size))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nh, call))

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

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

fn.Body.Append(loop)

if nelem == iterateTo {
if last {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, true)))
}
return
}
Expand All @@ -479,12 +479,12 @@ func eqFunc(t *types.Type) *ir.Func {
// }
for j := iterateTo; j < nelem; j++ {
// if check {} else { goto neq }
nif := ir.NewIfStmt(base.Pos, checkIdx(ir.NewInt(j)), nil, nil)
nif := ir.NewIfStmt(base.Pos, checkIdx(ir.NewInt(base.Pos, j)), nil, nil)
nif.Else.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, neq))
fn.Body.Append(nif)
}
if last {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(ir.NewInt(nelem))))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(ir.NewInt(base.Pos, nelem))))
}
}

Expand Down Expand Up @@ -518,7 +518,7 @@ func eqFunc(t *types.Type) *ir.Func {
case types.TSTRUCT:
flatConds := compare.EqStruct(t, np, nq)
if len(flatConds) == 0 {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, true)))
} else {
for _, c := range flatConds[:len(flatConds)-1] {
// if cond {} else { goto neq }
Expand All @@ -540,7 +540,7 @@ func eqFunc(t *types.Type) *ir.Func {
// r = false
// return (or goto ret)
fn.Body.Append(ir.NewLabelStmt(base.Pos, neq))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(false)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(base.Pos, false)))
if compare.EqCanPanic(t) || anyCall(fn) {
// Epilogue is large, so share it with the equal case.
fn.Body.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, ret))
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/typecheck/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func tcMake(n *ir.CallExpr) ir.Node {
return n
}
} else {
l = ir.NewInt(0)
l = ir.NewInt(base.Pos, 0)
}
nn = ir.NewMakeExpr(n.Pos(), ir.OMAKEMAP, l, nil)
nn.SetEsc(n.Esc())
Expand All @@ -699,7 +699,7 @@ func tcMake(n *ir.CallExpr) ir.Node {
return n
}
} else {
l = ir.NewInt(0)
l = ir.NewInt(base.Pos, 0)
}
nn = ir.NewMakeExpr(n.Pos(), ir.OMAKECHAN, l, nil)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/typecheck/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node {
var l []ir.Node
i := 0
for _, r := range ir.StringVal(n.X) {
l = append(l, ir.NewKeyExpr(base.Pos, ir.NewInt(int64(i)), ir.NewInt(int64(r))))
l = append(l, ir.NewKeyExpr(base.Pos, ir.NewInt(base.Pos, int64(i)), ir.NewInt(base.Pos, int64(r))))
i++
}

Expand Down
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/walk/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func appendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {

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

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

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

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

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

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

clrname := "memclrNoHeapPointers"
hasPointers := elemtype.HasPointers()
Expand Down
Loading

0 comments on commit b94dc38

Please sign in to comment.