From 749720a0362557eabbf87ef9f1494b18444c0adb Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 5 Dec 2016 15:57:45 -0800 Subject: [PATCH] cmd/compile: fix static-initialization compilation failure Fixes #13263. Change-Id: Ie1cafc62b6bfe6c5381c35d9a95563267b4cc9b0 Reviewed-on: https://go-review.googlesource.com/33970 Reviewed-by: Robert Griesemer Reviewed-by: Emmanuel Odeke Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/sinit.go | 4 +++- test/fixedbugs/issue13263.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue13263.go diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index 1192f3fac9..350c867725 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -295,7 +295,9 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool { if staticcopy(l, r, out) { return true } - *out = append(*out, nod(OAS, l, r)) + // We may have skipped past one or more OCONVNOPs, so + // use conv to ensure r is assignable to l (#13263). + *out = append(*out, nod(OAS, l, conv(r, l.Type))) return true case OLITERAL: diff --git a/test/fixedbugs/issue13263.go b/test/fixedbugs/issue13263.go new file mode 100644 index 0000000000..1933f2b5c5 --- /dev/null +++ b/test/fixedbugs/issue13263.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +var ( + x uint + y = x + z = uintptr(y) + a = uint32(y) + b = uint64(y) +) -- 2.50.0