Commit e1a7db7f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: minor cleanup

Follow-up to review comments on CL 41797.

Mask the input to set2 and set3, so that at the very least,
we won't corrupt the rest of the flags in case of a bad input.
It also seems more semantically appropriate.

Do minor cleanup in addrescapes. I started on larger cleanup,
but it wasn't clear that it was an improvement.

Add warning comments and sanity checks to Initorder and Class constants,
to attempt to prevent them from overflowing their allotted flag bits.

Passes toolstash-check.

Change-Id: I57b9661ba36f56406aa7a1d8da9b7c70338f9119
Reviewed-on: https://go-review.googlesource.com/41817
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 6910e108
......@@ -28,20 +28,22 @@ func (f bitset32) get2(shift uint8) uint8 {
return uint8(f>>shift) & 3
}
// set2 sets two bits in f using the bottom two bits of b.
func (f *bitset32) set2(shift uint8, b uint8) {
// Clear old bits.
*(*uint32)(f) &^= 3 << shift
// Set new bits.
*(*uint32)(f) |= uint32(b) << shift
*(*uint32)(f) |= uint32(b&3) << shift
}
func (f bitset32) get3(shift uint8) uint8 {
return uint8(f>>shift) & 7
}
// set3 sets three bits in f using the bottom three bits of b.
func (f *bitset32) set3(shift uint8, b uint8) {
// Clear old bits.
*(*uint32)(f) &^= 7 << shift
// Set new bits.
*(*uint32)(f) |= uint32(b) << shift
*(*uint32)(f) |= uint32(b&7) << shift
}
......@@ -24,10 +24,11 @@ func Sysfunc(name string) *obj.LSym {
// to be taken.
func addrescapes(n *Node) {
switch n.Op {
// probably a type error already.
// dump("addrescapes", n);
default:
break
// Unexpected Op, probably due to a previous type error. Ignore.
case OIND, ODOTPTR:
// Nothing to do.
case ONAME:
if n == nodfp {
......@@ -73,9 +74,6 @@ func addrescapes(n *Node) {
Curfn = oldfn
lineno = ln
case OIND, ODOTPTR:
break
// ODOTPTR has already been introduced,
// so these are the non-pointer ODOT and OINDEX.
// In &x[0], if x is a slice, then x does not
......
......@@ -31,17 +31,25 @@ func isRuntimePkg(p *types.Pkg) bool {
type Class uint8
const (
Pxxx Class = iota
PEXTERN // global variable
PAUTO // local variables
PAUTOHEAP // local variable or parameter moved to heap
PPARAM // input arguments
PPARAMOUT // output results
PFUNC // global function
Pxxx Class = iota // no class; used during ssa conversion to indicate pseudo-variables
PEXTERN // global variable
PAUTO // local variables
PAUTOHEAP // local variable or parameter moved to heap
PPARAM // input arguments
PPARAMOUT // output results
PFUNC // global function
PDISCARD // discard during parse of duplicate import
// Careful: Class is stored in three bits in Node.flags.
// Adding a new Class will overflow that.
)
func init() {
if PDISCARD != 7 {
panic("PDISCARD changed; does all Class values still fit in three bits?")
}
}
// note this is the runtime representation
// of the compilers arrays.
//
......
......@@ -9,11 +9,12 @@ import (
"fmt"
)
// static initialization
// Static initialization ordering state.
// These values are stored in two bits in Node.flags.
const (
InitNotStarted = 0
InitDone = 1
InitPending = 2
InitNotStarted = iota
InitDone
InitPending
)
type InitEntry struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment