1
0
mirror of https://github.com/golang/go synced 2024-11-05 19:46:11 -07:00
go/test/live1.go
Russ Cox 7a7c0ffb47 cmd/gc: correct liveness for fat variables
The VARDEF placement must be before the initialization
but after any final use. If you have something like s = ... using s ...
the rhs must be evaluated, then the VARDEF, then the lhs
assigned.

There is a large comment in pgen.c on gvardef explaining
this in more detail.

This CL also includes Ian's suggestions from earlier CLs,
namely commenting the use of mode in link.h and fixing
the precedence of the ~r check in dcl.c.

This CL enables the check that if liveness analysis decides
a variable is live on entry to the function, that variable must
be a function parameter (not a result, and not a local variable).
If this check fails, it indicates a bug in the liveness analysis or
in the generated code being analyzed.

The race detector generates invalid code for append(x, y...).
The code declares a temporary t and then uses cap(t) before
initializing t. The new liveness check catches this bug and
stops the compiler from writing out the buggy code.
Consequently, this CL disables the race detector tests in
run.bash until the race detector bug can be fixed
(golang.org/issue/7334).

Except for the race detector bug, the liveness analysis check
does not detect any problems (this CL and the previous CLs
fixed all the detected problems).

The net test still fails with GOGC=0 but the rest of the tests
now pass or time out (because GOGC=0 is so slow).

TBR=iant
CC=golang-codereviews
https://golang.org/cl/64170043
2014-02-15 10:58:55 -05:00

47 lines
1.3 KiB
Go

// compile
// Copyright 2014 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.
// Test that code compiles without
// "internal error: ... recorded as live on entry" errors
// from the liveness code.
//
// This code contains methods or other construct that
// trigger the generation of wrapper functions with no
// clear line number (they end up using line 1), and those
// would have annotations printed if we used -live=1,
// like the live.go test does.
// Instead, this test relies on the fact that the liveness
// analysis turns any non-live parameter on entry into
// a compile error. Compiling successfully means that bug
// has been avoided.
package main
// The liveness analysis used to get confused by the tail return
// instruction in the wrapper methods generated for T1.M and (*T1).M,
// causing a spurious "live at entry: ~r1" for the return result.
type T struct {
}
func (t *T) M() *int
type T1 struct {
*T
}
// Liveness analysis used to have the VARDEFs in the wrong place,
// causing a temporary to appear live on entry.
func f1(pkg, typ, meth string) {
panic("value method " + pkg + "." + typ + "." + meth + " called using nil *" + typ + " pointer")
}
func f2() interface{} {
return new(int)
}