cmd/compile: fix constant pointer comparison failure

Previously, constant pointer-typed expressions could use either Mpint
or NilVal as their Val depending on their construction, but const.go
expects each type to have a single corresponding Val kind.

This CL changes pointer-typed expressions to exclusively use Mpint.

Fixes #21221.

Change-Id: I6ba36c9b11eb19a68306f0b296acb11a8c254c41
Reviewed-on: https://go-review.googlesource.com/105315
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2018-04-07 03:08:46 -07:00
parent c3473c4f10
commit fe77a5413e
5 changed files with 33 additions and 36 deletions

View file

@ -331,26 +331,11 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
case TARRAY:
goto bad
case TPTR32,
TPTR64,
TINTER,
TMAP,
TCHAN,
TFUNC,
TSLICE,
TUNSAFEPTR:
break
case TPTR32, TPTR64, TUNSAFEPTR:
n.SetVal(Val{new(Mpint)})
// A nil literal may be converted to uintptr
// if it is an unsafe.Pointer
case TUINTPTR:
if n.Type.Etype == TUNSAFEPTR {
i := new(Mpint)
i.SetInt64(0)
n.SetVal(Val{i})
} else {
goto bad
}
case TCHAN, TFUNC, TINTER, TMAP, TSLICE:
break
}
case CTSTR, CTBOOL: