github.com/goproxy0/go@v0.0.0-20171111080102-49cc0c489d2c/src/cmd/compile/internal/gc/testdata/phi.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  // Test to make sure spills of cast-shortened values
     8  // don't end up spilling the pre-shortened size instead
     9  // of the post-shortened size.
    10  
    11  import (
    12  	"fmt"
    13  	"runtime"
    14  )
    15  
    16  // unfoldable true
    17  var true_ = true
    18  
    19  var data1 [26]int32
    20  var data2 [26]int64
    21  
    22  func init() {
    23  	for i := 0; i < 26; i++ {
    24  		// If we spill all 8 bytes of this datum, the 1 in the high-order 4 bytes
    25  		// will overwrite some other variable in the stack frame.
    26  		data2[i] = 0x100000000
    27  	}
    28  }
    29  
    30  func foo() int32 {
    31  	var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z int32
    32  	if true_ {
    33  		a = data1[0]
    34  		b = data1[1]
    35  		c = data1[2]
    36  		d = data1[3]
    37  		e = data1[4]
    38  		f = data1[5]
    39  		g = data1[6]
    40  		h = data1[7]
    41  		i = data1[8]
    42  		j = data1[9]
    43  		k = data1[10]
    44  		l = data1[11]
    45  		m = data1[12]
    46  		n = data1[13]
    47  		o = data1[14]
    48  		p = data1[15]
    49  		q = data1[16]
    50  		r = data1[17]
    51  		s = data1[18]
    52  		t = data1[19]
    53  		u = data1[20]
    54  		v = data1[21]
    55  		w = data1[22]
    56  		x = data1[23]
    57  		y = data1[24]
    58  		z = data1[25]
    59  	} else {
    60  		a = int32(data2[0])
    61  		b = int32(data2[1])
    62  		c = int32(data2[2])
    63  		d = int32(data2[3])
    64  		e = int32(data2[4])
    65  		f = int32(data2[5])
    66  		g = int32(data2[6])
    67  		h = int32(data2[7])
    68  		i = int32(data2[8])
    69  		j = int32(data2[9])
    70  		k = int32(data2[10])
    71  		l = int32(data2[11])
    72  		m = int32(data2[12])
    73  		n = int32(data2[13])
    74  		o = int32(data2[14])
    75  		p = int32(data2[15])
    76  		q = int32(data2[16])
    77  		r = int32(data2[17])
    78  		s = int32(data2[18])
    79  		t = int32(data2[19])
    80  		u = int32(data2[20])
    81  		v = int32(data2[21])
    82  		w = int32(data2[22])
    83  		x = int32(data2[23])
    84  		y = int32(data2[24])
    85  		z = int32(data2[25])
    86  	}
    87  	// Lots of phis of the form phi(int32,int64) of type int32 happen here.
    88  	// Some will be stack phis. For those stack phis, make sure the spill
    89  	// of the second argument uses the phi's width (4 bytes), not its width
    90  	// (8 bytes).  Otherwise, a random stack slot gets clobbered.
    91  
    92  	runtime.Gosched()
    93  	return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u + v + w + x + y + z
    94  }
    95  
    96  func main() {
    97  	want := int32(0)
    98  	got := foo()
    99  	if got != want {
   100  		fmt.Printf("want %d, got %d\n", want, got)
   101  		panic("bad")
   102  	}
   103  }