Source file test/abi/many_intstar_input.go

     1  // run
     2  
     3  //go:build !wasm
     4  
     5  // Copyright 2021 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  // wasm is excluded because the compiler chatter about register abi pragma ends up
    10  // on stdout, and causes the expected output to not match.
    11  
    12  package main
    13  
    14  import (
    15  	"fmt"
    16  )
    17  
    18  var sink int = 3
    19  
    20  //go:registerparams
    21  //go:noinline
    22  func F(a, b, c, d, e, f *int) {
    23  	G(f, e, d, c, b, a)
    24  	sink += *a // *a == 6 after swapping in G
    25  }
    26  
    27  //go:registerparams
    28  //go:noinline
    29  func G(a, b, c, d, e, f *int) {
    30  	var scratch [1000 * 100]int
    31  	scratch[*a] = *f                    // scratch[6] = 1
    32  	fmt.Println(*a, *b, *c, *d, *e, *f) // Forces it to spill b
    33  	sink = scratch[*b+1]                // scratch[5+1] == 1
    34  	*f, *a = *a, *f
    35  	*e, *b = *b, *e
    36  	*d, *c = *c, *d
    37  }
    38  
    39  func main() {
    40  	a, b, c, d, e, f := 1, 2, 3, 4, 5, 6
    41  	F(&a, &b, &c, &d, &e, &f)
    42  	fmt.Println(a, b, c, d, e, f)
    43  	fmt.Println(sink)
    44  }
    45  

View as plain text