...
Run Format

Source file test/live1.go

Documentation: test

     1  // compile
     2  
     3  // Copyright 2014 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Test that code compiles without
     8  // "internal error: ... recorded as live on entry" errors
     9  // from the liveness code.
    10  //
    11  // This code contains methods or other construct that
    12  // trigger the generation of wrapper functions with no
    13  // clear line number (they end up using line 1), and those
    14  // would have annotations printed if we used -live=1,
    15  // like the live.go test does.
    16  // Instead, this test relies on the fact that the liveness
    17  // analysis turns any non-live parameter on entry into
    18  // a compile error. Compiling successfully means that bug
    19  // has been avoided.
    20  
    21  package main
    22  
    23  // The liveness analysis used to get confused by the tail return
    24  // instruction in the wrapper methods generated for T1.M and (*T1).M,
    25  // causing a spurious "live at entry: ~r1" for the return result.
    26  
    27  type T struct {
    28  }
    29  
    30  func (t *T) M() *int
    31  
    32  type T1 struct {
    33  	*T
    34  }
    35  
    36  // Liveness analysis used to have the VARDEFs in the wrong place,
    37  // causing a temporary to appear live on entry.
    38  
    39  func f1(pkg, typ, meth string) {
    40  	panic("value method " + pkg + "." + typ + "." + meth + " called using nil *" + typ + " pointer")
    41  }
    42  
    43  func f2() interface{} {
    44  	return new(int)
    45  }
    46  
    47  

View as plain text