File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -21,12 +21,6 @@ func (s *stdSizes) Alignof(T types.Type) int64 {
21
21
// of alignment of the elements and fields, respectively.
22
22
switch t := T .Underlying ().(type ) {
23
23
case * types.Array :
24
- if t .Len () == 0 {
25
- // 0-sized arrays, always have 0 size.
26
- // And from the spec, should have an alignment of _at least_ 1
27
- return 1
28
- }
29
-
30
24
// spec: "For a variable x of array type: unsafe.Alignof(x)
31
25
// is the same as unsafe.Alignof(x[0]), but at least 1."
32
26
return s .Alignof (t .Elem ())
@@ -51,7 +45,11 @@ func (s *stdSizes) Alignof(T types.Type) int64 {
51
45
if t .Info ()& types .IsString != 0 {
52
46
return s .PtrSize
53
47
}
48
+ case * types.Signature :
49
+ // Even though functions in tinygo are 2 pointers, they are not 2 pointer aligned
50
+ return s .PtrSize
54
51
}
52
+
55
53
a := s .Sizeof (T ) // may be 0
56
54
// spec: "For a variable x of any type: unsafe.Alignof(x) is at least 1."
57
55
if a < 1 {
Original file line number Diff line number Diff line change @@ -347,6 +347,13 @@ func main() {
347
347
println ("errorValue.Implements(errorType) was true, expected false" )
348
348
}
349
349
350
+ println ("\n alignment / offset:" )
351
+ v2 := struct {
352
+ noCompare [0 ]func ()
353
+ data byte
354
+ }{}
355
+ println ("struct{[0]func(); byte}:" , unsafe .Offsetof (v2 .data ) == uintptr (unsafe .Pointer (& v2 .data ))- uintptr (unsafe .Pointer (& v2 )))
356
+
350
357
println ("\n struct tags" )
351
358
TestStructTag ()
352
359
Original file line number Diff line number Diff line change @@ -405,6 +405,9 @@ offset for int64 matches: true
405
405
offset for complex128 matches: true
406
406
type assertion succeeded for unreferenced type
407
407
408
+ alignment / offset:
409
+ struct{[0]func(); byte}: true
410
+
408
411
struct tags
409
412
blue gopher
410
413
You can’t perform that action at this time.
0 commit comments