]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: apply constant folding to ORUNESTR
authorMatthew Dempsky <mdempsky@google.com>
Thu, 26 Sep 2019 23:32:34 +0000 (16:32 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 26 Sep 2019 23:54:29 +0000 (23:54 +0000)
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>

src/cmd/compile/internal/gc/const.go
test/const.go

index 510b1cd15dced89cac570aeb87388db520268f46..3666ddbaa0df69b24aff7949ed2b441ca0e0a642 100644 (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))
                }
index 3f4956497ebd332df4385ce0db22687bc5e44672..f8aa1dd9ab667c6c5600386d88cafe933c823e0a 100644 (file)
@@ -24,6 +24,10 @@ const (
 
        ctrue  = true
        cfalse = !ctrue
+
+       // Issue #34563
+       _ = string(int(123))
+       _ = string(rune(456))
 )
 
 const (