]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: add register abi tests
authorDavid Chase <drchase@google.com>
Wed, 24 Feb 2021 17:58:01 +0000 (12:58 -0500)
committerDavid Chase <drchase@google.com>
Thu, 4 Mar 2021 23:07:50 +0000 (23:07 +0000)
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>
13 files changed:
test/abi/f_ret_z_not.go
test/abi/many_int_input.go
test/abi/many_intstar_input.go [new file with mode: 0644]
test/abi/many_intstar_input.out [new file with mode: 0644]
test/abi/more_intstar_input.go [new file with mode: 0644]
test/abi/more_intstar_input.out [new file with mode: 0644]
test/abi/named_return_stuff.go [new file with mode: 0644]
test/abi/named_return_stuff.out [new file with mode: 0644]
test/abi/return_stuff.go [new file with mode: 0644]
test/abi/return_stuff.out [new file with mode: 0644]
test/abi/struct_3_string_input.go [new file with mode: 0644]
test/abi/struct_3_string_input.out [new file with mode: 0644]
test/abi/uglyfib.go

index d890223ff79e4b812c368d92904f75170047b45d..63d6c7918fbb6d2e1c1b37ef259160478007b836 100644 (file)
@@ -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"
index 6c3332f8426d527c2a47e01172212d357714e8cb..8fda937932c7e045e2fe414f7bcf4900fe0a8945 100644 (file)
@@ -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 (file)
index 0000000..b209c80
--- /dev/null
@@ -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 (file)
index 0000000..0a37ccb
--- /dev/null
@@ -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 (file)
index 0000000..f0a48fb
--- /dev/null
@@ -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 (file)
index 0000000..2ab84bf
--- /dev/null
@@ -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 (file)
index 0000000..faa0221
--- /dev/null
@@ -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 (file)
index 0000000..02f12e8
--- /dev/null
@@ -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 (file)
index 0000000..130d8be
--- /dev/null
@@ -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 (file)
index 0000000..5f519d7
--- /dev/null
@@ -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 (file)
index 0000000..54a8b38
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
index bde3548bee2c9385432f1f3c6c5cfef0d3c6e7b3..b8e8739f30c34def236b676b8343dd85812677ef 100644 (file)
@@ -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"