go/test/live1.go
Russ Cox 02ae91f342 cmd/gc: correct liveness for wrappers containing tail jumps
A normal RET is treated as using the return values,
but a tail jump RET does not - it is jumping to the
function that is going to fill in the return values.
If a tail jump RET is recorded as using the return values,
since nothing initializes them they will be marked as
live on entry to the function, which is clearly wrong.

Found and tested by the new code in plive.c that looks
for variables that are incorrectly live on entry.
That code is disabled for now because there are other
cases remaining to be fixed. But once it is enabled,
test/live1.go becomes a real test of this CL.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/63570045
2014-02-13 23:33:20 -05:00

30 lines
946 B
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.
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.
// This test is checking that there is no such message.
// We cannot use live.go because it runs with -live on, which will
// generate (correct) messages about the wrapper's receivers
// being live on entry, but those messages correspond to no
// source line in the file, so they are given at line 1, which we
// cannot annotate. Not using -live here avoids that problem.
type T struct {
}
func (t *T) M() *int
type T1 struct {
*T
}