diff options
author | Ayke van Laethem <[email protected]> | 2022-03-01 14:50:28 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2022-03-04 00:04:17 +0100 |
commit | 29c1d7c68df1834e714d8f461d6a49464712bb1a (patch) | |
tree | 62ee263e7392941fe1e6359ece2205a97229bd8f /testdata | |
parent | ecb7eebcff3f1dd26d476b99f77fedd1b92ae828 (diff) | |
download | tinygo-29c1d7c68df1834e714d8f461d6a49464712bb1a.tar.gz tinygo-29c1d7c68df1834e714d8f461d6a49464712bb1a.zip |
compiler: fix incorrect unsafe.Alignof on some 32-bit architectures
This should fix https://github.com/tinygo-org/tinygo/issues/2643
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/reflect.go | 13 | ||||
-rw-r--r-- | testdata/reflect.txt | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/testdata/reflect.go b/testdata/reflect.go index 7e21abdcb..7cc5fa7bb 100644 --- a/testdata/reflect.go +++ b/testdata/reflect.go @@ -170,6 +170,19 @@ func main() { assertSize(reflect.TypeOf(new(int)).Size() == unsafe.Sizeof(new(int)), "*int") assertSize(reflect.TypeOf(zeroFunc).Size() == unsafe.Sizeof(zeroFunc), "func()") + // Test that offset is correctly calculated. + // This doesn't just test reflect but also (indirectly) that unsafe.Alignof + // works correctly. + s := struct { + small1 byte + big1 int64 + small2 byte + big2 int64 + }{} + st := reflect.TypeOf(s) + println("offset for int64 matches:", st.Field(1).Offset-st.Field(0).Offset == uintptr(unsafe.Pointer(&s.big1))-uintptr(unsafe.Pointer(&s.small1))) + println("offset for complex128 matches:", st.Field(3).Offset-st.Field(2).Offset == uintptr(unsafe.Pointer(&s.big2))-uintptr(unsafe.Pointer(&s.small2))) + // SetBool rv := reflect.ValueOf(new(bool)).Elem() rv.SetBool(true) diff --git a/testdata/reflect.txt b/testdata/reflect.txt index 4ef44cdbf..c07fc01d8 100644 --- a/testdata/reflect.txt +++ b/testdata/reflect.txt @@ -401,6 +401,8 @@ float32 4 32 float64 8 64 complex64 8 64 complex128 16 128 +offset for int64 matches: true +offset for complex128 matches: true type assertion succeeded for unreferenced type struct tags |