diff --git a/test/abi/f_ret_z_not.go b/test/abi/f_ret_z_not.go index d890223ff7..63d6c7918f 100644 --- a/test/abi/f_ret_z_not.go +++ b/test/abi/f_ret_z_not.go @@ -1,9 +1,15 @@ // 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" diff --git a/test/abi/many_int_input.go b/test/abi/many_int_input.go index 6c3332f842..8fda937932 100644 --- a/test/abi/many_int_input.go +++ b/test/abi/many_int_input.go @@ -7,6 +7,9 @@ // 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 ( diff --git a/test/abi/many_intstar_input.go b/test/abi/many_intstar_input.go new file mode 100644 index 0000000000..b209c801ba --- /dev/null +++ b/test/abi/many_intstar_input.go @@ -0,0 +1,45 @@ +// 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) +} diff --git a/test/abi/many_intstar_input.out b/test/abi/many_intstar_input.out new file mode 100644 index 0000000000..0a37ccbec7 --- /dev/null +++ b/test/abi/many_intstar_input.out @@ -0,0 +1,3 @@ +6 5 4 3 2 1 +6 5 4 3 2 1 +7 diff --git a/test/abi/more_intstar_input.go b/test/abi/more_intstar_input.go new file mode 100644 index 0000000000..f0a48fbdc2 --- /dev/null +++ b/test/abi/more_intstar_input.go @@ -0,0 +1,44 @@ +// 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) +} diff --git a/test/abi/more_intstar_input.out b/test/abi/more_intstar_input.out new file mode 100644 index 0000000000..2ab84bfa8c --- /dev/null +++ b/test/abi/more_intstar_input.out @@ -0,0 +1,2 @@ +Got this far! +Sink = 7 diff --git a/test/abi/named_return_stuff.go b/test/abi/named_return_stuff.go new file mode 100644 index 0000000000..faa0221a3c --- /dev/null +++ b/test/abi/named_return_stuff.go @@ -0,0 +1,94 @@ +// 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) + +} diff --git a/test/abi/named_return_stuff.out b/test/abi/named_return_stuff.out new file mode 100644 index 0000000000..02f12e806d --- /dev/null +++ b/test/abi/named_return_stuff.out @@ -0,0 +1,13 @@ +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! diff --git a/test/abi/return_stuff.go b/test/abi/return_stuff.go new file mode 100644 index 0000000000..130d8be5c5 --- /dev/null +++ b/test/abi/return_stuff.go @@ -0,0 +1,38 @@ +// 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) +} diff --git a/test/abi/return_stuff.out b/test/abi/return_stuff.out new file mode 100644 index 0000000000..5f519d7b99 --- /dev/null +++ b/test/abi/return_stuff.out @@ -0,0 +1,3 @@ +x = 21 +len(y) = 12 +y = Hello World! diff --git a/test/abi/struct_3_string_input.go b/test/abi/struct_3_string_input.go new file mode 100644 index 0000000000..54a8b38af9 --- /dev/null +++ b/test/abi/struct_3_string_input.go @@ -0,0 +1,40 @@ +// 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) + } +} diff --git a/test/abi/struct_3_string_input.out b/test/abi/struct_3_string_input.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/abi/uglyfib.go b/test/abi/uglyfib.go index bde3548bee..b8e8739f30 100644 --- a/test/abi/uglyfib.go +++ b/test/abi/uglyfib.go @@ -7,6 +7,9 @@ // 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"