summaryrefslogtreecommitdiff
path: root/test/abi
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2021-01-04 13:32:10 -0500
committerDavid Chase <drchase@google.com>2021-01-13 15:50:04 +0000
commit861707a8c84f0b1ddbcaea0e9f439398ee2175fb (patch)
treec4a6e6c249d20865ea801cccc8bedd583aea3a21 /test/abi
parentc1370e918fd88a13f77a133f8e431197cd3a1fc6 (diff)
downloadgo-git-861707a8c84f0b1ddbcaea0e9f439398ee2175fb.tar.gz
[dev.regabi] cmd/compile: added limited //go:registerparams pragma for new ABI dev
This only works for functions; if you try it with a method, it will fail. It does work for both local package and imports. For now, it tells you when it thinks it sees either a declaration or a call of such a function (this will normally be silent since no existing code uses this pragma). Note: it appears to be really darn hard to figure out if this pragma was set for a method, and the method's call site. Better ir.Node wranglers than I might be able to make headway, but it seemed unnecessary for this experiment. Change-Id: I601c2ddd124457bf6d62f714d7ac871705743c0a Reviewed-on: https://go-review.googlesource.com/c/go/+/279521 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
Diffstat (limited to 'test/abi')
-rw-r--r--test/abi/regabipragma.dir/main.go36
-rw-r--r--test/abi/regabipragma.dir/tmp/foo.go19
-rw-r--r--test/abi/regabipragma.go9
-rw-r--r--test/abi/regabipragma.out6
4 files changed, 70 insertions, 0 deletions
diff --git a/test/abi/regabipragma.dir/main.go b/test/abi/regabipragma.dir/main.go
new file mode 100644
index 0000000000..d663337a10
--- /dev/null
+++ b/test/abi/regabipragma.dir/main.go
@@ -0,0 +1,36 @@
+// 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.
+
+package main
+
+import (
+ "fmt"
+ "regabipragma.dir/tmp"
+)
+
+type S string
+
+//go:noinline
+func (s S) ff(t string) string {
+ return string(s) + " " + t
+}
+
+//go:noinline
+//go:registerparams
+func f(s,t string) string { // ERROR "Declared function f has register params"
+ return s + " " + t
+}
+
+func check(s string) {
+ if s != "Hello world!" {
+ fmt.Printf("FAIL, wanted 'Hello world!' but got '%s'\n", s)
+ }
+}
+
+func main() {
+ check(f("Hello", "world!")) // ERROR "Called function ...f has register params"
+ check(tmp.F("Hello", "world!")) // ERROR "Called function regabipragma.dir/tmp.F has register params"
+ check(S("Hello").ff("world!"))
+ check(tmp.S("Hello").FF("world!"))
+}
diff --git a/test/abi/regabipragma.dir/tmp/foo.go b/test/abi/regabipragma.dir/tmp/foo.go
new file mode 100644
index 0000000000..cff989bbcd
--- /dev/null
+++ b/test/abi/regabipragma.dir/tmp/foo.go
@@ -0,0 +1,19 @@
+// 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.
+
+package tmp
+
+
+type S string
+
+//go:noinline
+func (s S) FF(t string) string {
+ return string(s) + " " + t
+}
+
+//go:noinline
+//go:registerparams
+func F(s,t string) string {
+ return s + " " + t
+}
diff --git a/test/abi/regabipragma.go b/test/abi/regabipragma.go
new file mode 100644
index 0000000000..93cdb6abbb
--- /dev/null
+++ b/test/abi/regabipragma.go
@@ -0,0 +1,9 @@
+// runindir
+
+// 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.
+
+// TODO May delete or adapt this test once regabi is the default
+
+package ignore
diff --git a/test/abi/regabipragma.out b/test/abi/regabipragma.out
new file mode 100644
index 0000000000..7803613351
--- /dev/null
+++ b/test/abi/regabipragma.out
@@ -0,0 +1,6 @@
+# regabipragma.dir/tmp
+tmp/foo.go:17:6: Declared function F has register params
+# regabipragma.dir
+./main.go:21:6: Declared function f has register params
+./main.go:32:9: Called function "".f has register params
+./main.go:33:13: Called function regabipragma.dir/tmp.F has register params