aboutsummaryrefslogtreecommitdiff
path: root/test/abi
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2021-02-24 12:58:01 -0500
committerDavid Chase <drchase@google.com>2021-03-04 23:07:50 +0000
commit5c5552c5bab55c7233cc0cc105876a982ec25b74 (patch)
treed6a2331e1386a7637601db69646ea4e99105266d /test/abi
parent56d52e661114be60fb1893b034ac0c5976b622af (diff)
downloadgo-5c5552c5bab55c7233cc0cc105876a982ec25b74.tar.gz
go-5c5552c5bab55c7233cc0cc105876a982ec25b74.zip
cmd/compile: add register abi tests
Change-Id: I4b2b62a8eb1c4bf47f552214127d4ed5710af196 Reviewed-on: https://go-review.googlesource.com/c/go/+/297030 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/abi')
-rw-r--r--test/abi/f_ret_z_not.go6
-rw-r--r--test/abi/many_int_input.go3
-rw-r--r--test/abi/many_intstar_input.go45
-rw-r--r--test/abi/many_intstar_input.out3
-rw-r--r--test/abi/more_intstar_input.go44
-rw-r--r--test/abi/more_intstar_input.out2
-rw-r--r--test/abi/named_return_stuff.go94
-rw-r--r--test/abi/named_return_stuff.out13
-rw-r--r--test/abi/return_stuff.go38
-rw-r--r--test/abi/return_stuff.out3
-rw-r--r--test/abi/struct_3_string_input.go40
-rw-r--r--test/abi/struct_3_string_input.out0
-rw-r--r--test/abi/uglyfib.go3
13 files changed, 294 insertions, 0 deletions
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
--- /dev/null
+++ b/test/abi/struct_3_string_input.out
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"