Source file test/abi/too_big_to_ssa.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  package main
    11  
    12  import (
    13  	"fmt"
    14  )
    15  
    16  var sink *string
    17  
    18  type toobig struct {
    19  	// 6 words will not SSA but will fit in registers
    20  	a, b, c string
    21  }
    22  
    23  //go:registerparams
    24  //go:noinline
    25  func H(x toobig) string {
    26  	return x.a + " " + x.b + " " + x.c
    27  }
    28  
    29  //go:registerparams
    30  //go:noinline
    31  func I(a, b, c string) toobig {
    32  	return toobig{a, b, c}
    33  }
    34  
    35  func main() {
    36  	s := H(toobig{"Hello", "there,", "World"})
    37  	gotVsWant(s, "Hello there, World")
    38  	fmt.Println(s)
    39  	t := H(I("Ahoy", "there,", "Matey"))
    40  	gotVsWant(t, "Ahoy there, Matey")
    41  	fmt.Println(t)
    42  }
    43  
    44  func gotVsWant(got, want string) {
    45  	if got != want {
    46  		fmt.Printf("FAIL, got %s, wanted %s\n", got, want)
    47  	}
    48  }
    49  

View as plain text