Source file test/abi/spills3.go

     1  // run
     2  
     3  //go:build !wasm
     4  // +build !wasm
     5  
     6  // Copyright 2021 The Go Authors. All rights reserved.
     7  // Use of this source code is governed by a BSD-style
     8  // license that can be found in the LICENSE file.
     9  
    10  // wasm is excluded because the compiler chatter about register abi pragma ends up
    11  // on stdout, and causes the expected output to not match.
    12  
    13  package main
    14  
    15  import "fmt"
    16  
    17  type i4 struct {
    18  	a, b, c, d int
    19  }
    20  
    21  //go:noinline
    22  func spills(px *i4) {
    23  }
    24  
    25  //go:registerparams
    26  //go:noinline
    27  func F(x i4) i4 {
    28  	ab := x.a + x.b
    29  	bc := x.b + x.c
    30  	cd := x.c + x.d
    31  	ad := x.a + x.d
    32  	ba := x.a - x.b
    33  	cb := x.b - x.c
    34  	dc := x.c - x.d
    35  	da := x.a - x.d
    36  	i := i4{ab*bc + da, cd*ad + cb, ba*cb + ad, dc*da + bc}
    37  	spills(&i)
    38  	return i
    39  }
    40  
    41  func main() {
    42  	x := i4{1, 2, 3, 4}
    43  	y := x
    44  	z := F(x)
    45  	if z != (i4{12, 34, 6, 8}) {
    46  		fmt.Printf("y=%v, z=%v\n", y, z)
    47  	}
    48  }
    49  

View as plain text