aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-06-20 14:40:35 +0200
committerRon Evans <[email protected]>2022-06-24 11:10:24 +0200
commite1052f921c0d845fb6257d1347a97af4e4d8dfd9 (patch)
tree29f73031c52f24e224d5fd0425b26eb4e8aaa07b /testdata
parent6dff85c756ca571e7e6b11263a310323fb367593 (diff)
downloadtinygo-e1052f921c0d845fb6257d1347a97af4e4d8dfd9.tar.gz
tinygo-e1052f921c0d845fb6257d1347a97af4e4d8dfd9.zip
compiler: define atomic intrinsic functions directly
This changes the compiler from treating calls to sync/atomic.* functions as special calls (emitted directly at the call site) to actually defining their declarations when there is no Go SSA implementation. And rely on the inliner to inline these very small functions. This works a bit better in practice. For example, this makes it possible to use these functions in deferred function calls. This commit is a bit large because it also needs to refactor a few things to make it possible to define such intrinsic functions.
Diffstat (limited to 'testdata')
-rw-r--r--testdata/atomic.go11
-rw-r--r--testdata/atomic.txt1
2 files changed, 12 insertions, 0 deletions
diff --git a/testdata/atomic.go b/testdata/atomic.go
index f99a39bb5..2b9131c91 100644
--- a/testdata/atomic.go
+++ b/testdata/atomic.go
@@ -81,6 +81,9 @@ func main() {
// test atomic.Value load/store operations
testValue(int(3), int(-2))
testValue("", "foobar", "baz")
+
+ // Test atomic operations as deferred values.
+ testDefer()
}
func testValue(values ...interface{}) {
@@ -93,3 +96,11 @@ func testValue(values ...interface{}) {
}
}
}
+
+func testDefer() {
+ n1 := int32(5)
+ defer func() {
+ println("deferred atomic add:", n1)
+ }()
+ defer atomic.AddInt32(&n1, 3)
+}
diff --git a/testdata/atomic.txt b/testdata/atomic.txt
index d1f2ab293..a03f292ce 100644
--- a/testdata/atomic.txt
+++ b/testdata/atomic.txt
@@ -33,3 +33,4 @@ StoreUint32: 20
StoreUint64: 20
StoreUintptr: 20
StorePointer: true
+deferred atomic add: 8