1
0
mirror of https://github.com/golang/go synced 2024-11-11 17:51:49 -07:00

cmd/compile: apply constant folding to ORUNESTR

ORUNESTR represents the special case of integer->string conversion. If
the integer is a constant, then the string is a constant too, so
evconst needs to perform constant folding here.

Passes toolstash-check.

Fixes #34563.

Change-Id: Ieab3d76794d8ce570106b6b707a4bcd725d156e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/197677
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2019-09-26 16:32:34 -07:00
parent 0a5116493c
commit ac1d440ea6
2 changed files with 5 additions and 1 deletions

View File

@ -591,7 +591,7 @@ func evconst(n *Node) {
setconst(n, shiftOp(nl.Val(), op, nr.Val()))
}
case OCONV:
case OCONV, ORUNESTR:
if okforconst[n.Type.Etype] && nl.Op == OLITERAL {
setconst(n, convertVal(nl.Val(), n.Type, true))
}

View File

@ -24,6 +24,10 @@ const (
ctrue = true
cfalse = !ctrue
// Issue #34563
_ = string(int(123))
_ = string(rune(456))
)
const (