Source file test/abi/double_nested_struct.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 *string
    20  
    21  type stringPair struct {
    22  	a, b string
    23  }
    24  
    25  type stringPairPair struct {
    26  	x, y stringPair
    27  }
    28  
    29  // The goal of this test is to be sure that the call arg/result expander works correctly
    30  // for a corner case of passing a 2-nested struct that fits in registers to/from calls.
    31  
    32  //go:registerparams
    33  //go:noinline
    34  func H(spp stringPairPair) string {
    35  	return spp.x.a + " " + spp.x.b + " " + spp.y.a + " " + spp.y.b
    36  }
    37  
    38  //go:registerparams
    39  //go:noinline
    40  func G(a, b, c, d string) stringPairPair {
    41  	return stringPairPair{stringPair{a, b}, stringPair{c, d}}
    42  }
    43  
    44  func main() {
    45  	spp := G("this", "is", "a", "test")
    46  	s := H(spp)
    47  	gotVsWant(s, "this is a test")
    48  }
    49  
    50  func gotVsWant(got, want string) {
    51  	if got != want {
    52  		fmt.Printf("FAIL, got %s, wanted %s\n", got, want)
    53  	}
    54  }
    55  

View as plain text