runtime: implement KeepAlive using inline assembly

This commit is contained in:
Ayke van Laethem
2023-02-17 01:19:53 +01:00
committed by Ron Evans
parent 361ecf9ea4
commit c02cc339c5
3 changed files with 38 additions and 6 deletions
+10
View File
@@ -1,5 +1,7 @@
package main
import "runtime"
var xorshift32State uint32 = 1
func xorshift32(x uint32) uint32 {
@@ -17,6 +19,7 @@ func randuint32() uint32 {
func main() {
testNonPointerHeap()
testKeepAlive()
}
var scalarSlices [4][]byte
@@ -64,3 +67,10 @@ func testNonPointerHeap() {
}
println("ok")
}
func testKeepAlive() {
// There isn't much we can test, but at least we can test that
// runtime.KeepAlive compiles correctly.
var x int
runtime.KeepAlive(&x)
}