aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-08-31 23:02:17 +0200
committerAyke <[email protected]>2022-09-01 03:53:27 +0200
commitb485e8bfbd2c08a2db2d3a17a993054b7a2c4dde (patch)
treeeb402fe2ab57c318615b21b8e31801acc0dfc8b0
parent9e8739bb47d70f633962976458955cb8a5ce615c (diff)
downloadtinygo-b485e8bfbd2c08a2db2d3a17a993054b7a2c4dde.tar.gz
tinygo-b485e8bfbd2c08a2db2d3a17a993054b7a2c4dde.zip
compiler: fix unsafe.Sizeof for chan and map values
These types are simply pointers. For some reason, they were never implemented. Fixes https://github.com/tinygo-org/tinygo/issues/3083.
-rw-r--r--compiler/sizes.go2
-rw-r--r--testdata/reflect.go2
2 files changed, 3 insertions, 1 deletions
diff --git a/compiler/sizes.go b/compiler/sizes.go
index 5f28f161a..d19d634ce 100644
--- a/compiler/sizes.go
+++ b/compiler/sizes.go
@@ -152,7 +152,7 @@ func (s *stdSizes) Sizeof(T types.Type) int64 {
return align(offsets[n-1]+s.Sizeof(fields[n-1].Type()), maxAlign)
case *types.Interface:
return s.PtrSize * 2
- case *types.Pointer:
+ case *types.Pointer, *types.Chan, *types.Map:
return s.PtrSize
case *types.Signature:
// Func values in TinyGo are two words in size.
diff --git a/testdata/reflect.go b/testdata/reflect.go
index f36fcca73..4524cc1a0 100644
--- a/testdata/reflect.go
+++ b/testdata/reflect.go
@@ -175,6 +175,8 @@ func main() {
assertSize(reflect.TypeOf("").Size() == unsafe.Sizeof(""), "string")
assertSize(reflect.TypeOf(new(int)).Size() == unsafe.Sizeof(new(int)), "*int")
assertSize(reflect.TypeOf(zeroFunc).Size() == unsafe.Sizeof(zeroFunc), "func()")
+ assertSize(reflect.TypeOf(zeroChan).Size() == unsafe.Sizeof(zeroChan), "chan int")
+ assertSize(reflect.TypeOf(zeroMap).Size() == unsafe.Sizeof(zeroMap), "map[string]int")
// make sure embedding a zero-sized "not comparable" struct does not add size to a struct
assertSize(reflect.TypeOf(doNotCompare{}).Size() == unsafe.Sizeof(doNotCompare{}), "[0]func()")