// run
+//go:build !wasm
+// +build !wasm
+
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
package main
import "fmt"
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
package main
import (
--- /dev/null
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
+package main
+
+import (
+ "fmt"
+)
+
+var sink int = 3
+
+//go:registerparams
+//go:noinline
+func F(a, b, c, d, e, f *int) {
+ G(f, e, d, c, b, a)
+ sink += *a // *a == 6 after swapping in G
+}
+
+//go:registerparams
+//go:noinline
+func G(a, b, c, d, e, f *int) {
+ var scratch [1000 * 100]int
+ scratch[*a] = *f // scratch[6] = 1
+ fmt.Println(*a, *b, *c, *d, *e, *f) // Forces it to spill b
+ sink = scratch[*b+1] // scratch[5+1] == 1
+ *f, *a = *a, *f
+ *e, *b = *b, *e
+ *d, *c = *c, *d
+}
+
+func main() {
+ a, b, c, d, e, f := 1, 2, 3, 4, 5, 6
+ F(&a, &b, &c, &d, &e, &f)
+ fmt.Println(a, b, c, d, e, f)
+ fmt.Println(sink)
+}
--- /dev/null
+6 5 4 3 2 1
+6 5 4 3 2 1
+7
--- /dev/null
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
+package main
+
+import (
+ "fmt"
+)
+
+var sink int
+
+//go:registerparams
+//go:noinline
+func F(a, b, c, d, e, f, g, h, i, j, k, l, m *int) {
+ G(m, l, k, j, i, h, g, f, e, d, c, b, a)
+ // did the pointers get properly updated?
+ sink = *a + *m
+}
+
+//go:registerparams
+//go:noinline
+func G(a, b, c, d, e, f, g, h, i, j, k, l, m *int) {
+ // Do not reference the parameters
+ var scratch [1000 * 100]int
+ I := *c - *e - *l // zero.
+ scratch[I] = *d
+ fmt.Println("Got this far!")
+ sink += scratch[0]
+}
+
+func main() {
+ a, b, c, d, e, f, g, h, i, j, k, l, m := 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
+ F(&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m)
+ fmt.Printf("Sink = %d\n", sink-7)
+}
--- /dev/null
+Got this far!
+Sink = 7
--- /dev/null
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
+package main
+
+import (
+ "fmt"
+)
+
+var sink *string
+
+var y int
+
+//go:registerparams
+//go:noinline
+func F(a, b, c *int) (x int) {
+ x = *a
+ G(&x)
+ x += *b
+ G(&x)
+ x += *c
+ G(&x)
+ return
+}
+
+//go:registerparams
+//go:noinline
+func G(x *int) {
+ y += *x
+ fmt.Println("y = ", y)
+}
+
+//go:registerparams
+//go:noinline
+func X() {
+ *sink += " !!!!!!!!!!!!!!!"
+}
+
+//go:registerparams
+//go:noinline
+func H(s, t string) (result string) { // result leaks to heap
+ result = "Aloha! " + s + " " + t
+ sink = &result
+ r := ""
+ if len(s) <= len(t) {
+ r = "OKAY! "
+ X()
+ }
+ return r + result
+}
+
+//go:registerparams
+//go:noinline
+func K(s, t string) (result string) { // result spills
+ result = "Aloha! " + s + " " + t
+ r := ""
+ if len(s) <= len(t) {
+ r = "OKAY! "
+ X()
+ }
+ return r + result
+}
+
+func main() {
+ a, b, c := 1, 4, 16
+ x := F(&a, &b, &c)
+ fmt.Printf("x = %d\n", x)
+
+ y := H("Hello", "World!")
+ fmt.Println("len(y) =", len(y))
+ fmt.Println("y =", y)
+ z := H("Hello", "Pal!")
+ fmt.Println("len(z) =", len(z))
+ fmt.Println("z =", z)
+
+ fmt.Println()
+
+ y = K("Hello", "World!")
+ fmt.Println("len(y) =", len(y))
+ fmt.Println("y =", y)
+ z = K("Hello", "Pal!")
+ fmt.Println("len(z) =", len(z))
+ fmt.Println("z =", z)
+
+}
--- /dev/null
+y = 1
+y = 6
+y = 27
+x = 21
+len(y) = 41
+y = OKAY! Aloha! Hello World! !!!!!!!!!!!!!!!
+len(z) = 17
+z = Aloha! Hello Pal!
+
+len(y) = 25
+y = OKAY! Aloha! Hello World!
+len(z) = 17
+z = Aloha! Hello Pal!
--- /dev/null
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
+package main
+
+import (
+ "fmt"
+)
+
+//go:registerparams
+//go:noinline
+func F(a, b, c *int) int {
+ return *a + *b + *c
+}
+
+//go:registerparams
+//go:noinline
+func H(s, t string) string {
+ return s + " " + t
+}
+
+func main() {
+ a, b, c := 1, 4, 16
+ x := F(&a, &b, &c)
+ fmt.Printf("x = %d\n", x)
+ y := H("Hello", "World!")
+ fmt.Println("len(y) =", len(y))
+ fmt.Println("y =", y)
+}
--- /dev/null
+x = 21
+len(y) = 12
+y = Hello World!
--- /dev/null
+// run
+
+//go:build !wasm
+// +build !wasm
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
+package main
+
+import (
+ "fmt"
+)
+
+var sink *string
+
+type toobig struct {
+ a, b, c string
+}
+
+//go:registerparams
+//go:noinline
+func H(x toobig) string {
+ return x.a + " " + x.b + " " + x.c
+}
+
+func main() {
+ s := H(toobig{"Hello", "there,", "World"})
+ gotVsWant(s, "Hello there, World")
+}
+
+func gotVsWant(got, want string) {
+ if got != want {
+ fmt.Printf("FAIL, got %s, wanted %s\n", got, want)
+ }
+}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// wasm is excluded because the compiler chatter about register abi pragma ends up
+// on stdout, and causes the expected output to not match.
+
package main
import "fmt"