Commit ac1d440e authored by Matthew Dempsky's avatar Matthew Dempsky

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: default avatarRobert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0a511649
...@@ -591,7 +591,7 @@ func evconst(n *Node) { ...@@ -591,7 +591,7 @@ func evconst(n *Node) {
setconst(n, shiftOp(nl.Val(), op, nr.Val())) setconst(n, shiftOp(nl.Val(), op, nr.Val()))
} }
case OCONV: case OCONV, ORUNESTR:
if okforconst[n.Type.Etype] && nl.Op == OLITERAL { if okforconst[n.Type.Etype] && nl.Op == OLITERAL {
setconst(n, convertVal(nl.Val(), n.Type, true)) setconst(n, convertVal(nl.Val(), n.Type, true))
} }
......
...@@ -24,6 +24,10 @@ const ( ...@@ -24,6 +24,10 @@ const (
ctrue = true ctrue = true
cfalse = !ctrue cfalse = !ctrue
// Issue #34563
_ = string(int(123))
_ = string(rune(456))
) )
const ( const (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment