Source file test/abi/many_intstar_input.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 (
    16  	"fmt"
    17  )
    18  
    19  var sink int = 3
    20  
    21  //go:registerparams
    22  //go:noinline
    23  func F(a, b, c, d, e, f *int) {
    24  	G(f, e, d, c, b, a)
    25  	sink += *a // *a == 6 after swapping in G
    26  }
    27  
    28  //go:registerparams
    29  //go:noinline
    30  func G(a, b, c, d, e, f *int) {
    31  	var scratch [1000 * 100]int
    32  	scratch[*a] = *f                    // scratch[6] = 1
    33  	fmt.Println(*a, *b, *c, *d, *e, *f) // Forces it to spill b
    34  	sink = scratch[*b+1]                // scratch[5+1] == 1
    35  	*f, *a = *a, *f
    36  	*e, *b = *b, *e
    37  	*d, *c = *c, *d
    38  }
    39  
    40  func main() {
    41  	a, b, c, d, e, f := 1, 2, 3, 4, 5, 6
    42  	F(&a, &b, &c, &d, &e, &f)
    43  	fmt.Println(a, b, c, d, e, f)
    44  	fmt.Println(sink)
    45  }
    46  

View as plain text