compiler: use correct init order for multi-value initialization

Use the correct initialization order for

var a = c
var b, c = x.(bool)

The global c is initialized by the preinit of b, but were missing a
dependency of c on b, so a would be initialized to the zero value of c
rather than the correct value.

Simply adding the dependency of c on b didn't work because the preinit
of b refers to c, so that appeared circular.  So this patch changes
the init order to skip dependencies that only appear on the left hand
side of assignments in preinit blocks.

Doing that didn't work because the write barrier pass can transform "a
= b" into code like "gcWriteBarrier(&a, b)" that is not obviously a
simple assigment.  So this patch moves the collection of dependencies
to just after lowering, before the write barriers are inserted.

Making those changes permit relaxing the requirement that we don't
warn about self-dependency in preinit blocks, so now we correctly warn

var a, b any = b.(bool)

The test case is

Fixes golang/go#53619

Change-Id: I095b5a330ab657fc3c7b366e85c881c2a80e5a1a
Reviewed-by: Cherry Mui <>
Reviewed-by: Ian Lance Taylor <>
4 files changed
tree: cd84aee70e7c5bf07a74dc8391526d3ab32c71cf
  1. go/
  2. libgo/
  3. .gitignore
  5. codereview.cfg

A Go frontend

Ian Lance Taylor Last update 15 June 2014

This is a compiler frontend for the Go programming language. The frontend was originally developed at Google, and was released in November 2009. It was originally written by Ian Lance Taylor.

It was originally written for GCC. As of this writing it only supports GCC, but the GCC support has been separated from the rest of the frontend, so supporting another compiler is feasible.

The go subdirectory holds the frontend source code. This is mirrored to the gcc/go subdirectory in the GCC repository.

The libgo subdirectory holds the library source code. This is a copy of the main Go library with various changes appropriate for this compiler. The main Go library is hosted at, in the src directory. The libgo subdirectory is mirrored to the libgo subdirectory in the gcc repository.

Legal Matters

To contribute patches to the files in this directory, please see Contributing to the gccgo frontend.

The master copy of these files is hosted in Gerrit (there is a mirror at Github). Changes to these files require signing a Google contributor license agreement. If you are the copyright holder, you will need to agree to the Google Individual Contributor License Agreement. This agreement can be completed online.

If your organization is the copyright holder, the organization will need to agree to the Google Software Grant and Corporate Contributor License Agreement.

If the copyright holder for your code has already completed the agreement in connection with another Google open source project, it does not need to be completed again.

The authors of these files may be found in the AUTHORS and CONTRIBUTORS files.