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