From ac1d440ea6576dcfb851374dca69cf480f593517 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 26 Sep 2019 16:32:34 -0700 Subject: [PATCH] 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 Reviewed-by: Robert Griesemer TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/const.go | 2 +- test/const.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 510b1cd15d..3666ddbaa0 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -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)) } diff --git a/test/const.go b/test/const.go index 3f4956497e..f8aa1dd9ab 100644 --- a/test/const.go +++ b/test/const.go @@ -24,6 +24,10 @@ const ( ctrue = true cfalse = !ctrue + + // Issue #34563 + _ = string(int(123)) + _ = string(rune(456)) ) const (