cmd/compile: stop constructing untyped nodes when instrumenting asan

The code is using typecheck.ConvNop to convert from untyped int to
uintptr. However, that left the literal node untyped. It often does not
matter, because typecheck.EvalConst will see the OCONVNOP, and replace
the node with a new constant node.

This CL changes the code to construct the constant node directly using
typecheck.DefaultLit, so the last dependecy of typecheck.EvalConst will
go away, next CL can safely remove it from the code base.

Change-Id: Ie5a3d1ff6d3b72be7b8c43170eaa4f6cbb3206fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/484317
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2023-04-13 17:44:32 +07:00
parent 74b52d9519
commit 70451004bd
2 changed files with 3 additions and 3 deletions

View File

@ -144,7 +144,7 @@ func Task() *ir.Name {
asancall := ir.NewCallExpr(base.Pos, ir.OCALL, asanf, nil)
asancall.Args.Append(typecheck.ConvNop(typecheck.NodAddr(
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]))
asancall.Args.Append(typecheck.DefaultLit(ir.NewInt(base.Pos, int64(ni)), types.Types[types.TUINTPTR]))
fnInit.Body.Append(asancall)
typecheck.FinishFuncBody()

View File

@ -79,12 +79,12 @@ func instrumentGlobals(fn *ir.Func) *ir.Name {
// Assign globals[i].size.
g := n.(*ir.Name)
size := g.Type().Size()
c = tconv(ir.NewInt(base.Pos, size), types.Types[types.TUINTPTR])
c = typecheck.DefaultLit(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(base.Pos, sizeWithRz), types.Types[types.TUINTPTR])
c = typecheck.DefaultLit(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.