aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/decl.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-25 17:26:07 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-26 01:50:30 +0000
commitc97af0036b8cd8ab2a7ed3f68c3ba72968637e4d (patch)
tree2ef26177a3543b1dfb6388f18bd020a8b152382d /src/cmd/compile/internal/noder/decl.go
parent3663a437a781f4e7ce242aa334af2f2ce71ecef9 (diff)
downloadgo-c97af0036b8cd8ab2a7ed3f68c3ba72968637e4d.tar.gz
go-c97af0036b8cd8ab2a7ed3f68c3ba72968637e4d.zip
[dev.typeparams] cmd/compile: force untyped constants from types2 to expected kind
Currently, types2 sometimes produces constant.Values with a Kind different than the untyped constant type's Is{Integer,Float,Complex} info, which irgen expects to always match. While we mull how best to proceed in #43891, this CL adapts irgen to types2's current behavior. In particular, fixedbugs/issue11945.go now passes with -G=3. Updates #43891. Change-Id: I24823a32ff49af6045a032d3903dbb55cbec6bef Reviewed-on: https://go-review.googlesource.com/c/go/+/286652 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/decl.go')
-rw-r--r--src/cmd/compile/internal/noder/decl.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index c41b77c100..9862f452fd 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -5,6 +5,8 @@
package noder
import (
+ "go/constant"
+
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/syntax"
@@ -58,7 +60,22 @@ func (g *irgen) constDecl(out *ir.Nodes, decl *syntax.ConstDecl) {
for _, name := range decl.NameList {
name, obj := g.def(name)
- name.SetVal(obj.(*types2.Const).Val())
+
+ // For untyped numeric constants, make sure the value
+ // representation matches what the rest of the
+ // compiler (really just iexport) expects.
+ // TODO(mdempsky): Revisit after #43891 is resolved.
+ val := obj.(*types2.Const).Val()
+ switch name.Type() {
+ case types.UntypedInt, types.UntypedRune:
+ val = constant.ToInt(val)
+ case types.UntypedFloat:
+ val = constant.ToFloat(val)
+ case types.UntypedComplex:
+ val = constant.ToComplex(val)
+ }
+ name.SetVal(val)
+
out.Append(ir.NewDecl(g.pos(decl), ir.ODCLCONST, name))
}
}