2016-03-06 13:04:52 +11:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// +build !nacl
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
"unsafe"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Assert that the size of important structures do not change unexpectedly.
|
|
|
|
|
|
|
|
|
|
func TestSizeof(t *testing.T) {
|
|
|
|
|
const _64bit = unsafe.Sizeof(uintptr(0)) == 8
|
|
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
|
val interface{} // type as a value
|
|
|
|
|
_32bit uintptr // size on 32bit platforms
|
|
|
|
|
_64bit uintptr // size on 64bit platforms
|
|
|
|
|
}{
|
cmd/compile: cleanup closure.go
The main thing is we now eagerly create the ODCLFUNC node for
closures, immediately cross-link them, and assign fields (e.g., Nbody,
Dcl, Parents, Marks) directly on the ODCLFUNC (previously they were
assigned on the OCLOSURE and later moved to the ODCLFUNC).
This allows us to set Curfn to the ODCLFUNC instead of the OCLOSURE,
which makes things more consistent with normal function declarations.
(Notably, this means Cvars now hang off the ODCLFUNC instead of the
OCLOSURE.)
Assignment of xfunc symbol names also now happens before typechecking
their body, which means debugging output now provides a more helpful
name than "<S>".
In golang.org/cl/66810, we changed "x := y" statements to avoid
creating false closure variables for x, but we still create them for
struct literals like "s{f: x}". Update comment in capturevars
accordingly.
More opportunity for cleanups still, but this makes some substantial
progress, IMO.
Passes toolstash-check.
Change-Id: I65a4efc91886e3dcd1000561348af88297775cd7
Reviewed-on: https://go-review.googlesource.com/100197
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-08 06:25:04 -08:00
|
|
|
{Func{}, 124, 224},
|
2018-03-06 18:30:58 -08:00
|
|
|
{Name{}, 32, 56},
|
2018-03-07 15:11:54 -08:00
|
|
|
{Param{}, 24, 48},
|
2017-04-25 18:14:12 -07:00
|
|
|
{Node{}, 76, 128},
|
2016-03-06 13:04:52 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
want := tt._32bit
|
|
|
|
|
if _64bit {
|
|
|
|
|
want = tt._64bit
|
|
|
|
|
}
|
|
|
|
|
got := reflect.TypeOf(tt.val).Size()
|
|
|
|
|
if want != got {
|
2016-03-06 18:05:41 -08:00
|
|
|
t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
|
2016-03-06 13:04:52 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|