]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types: replace BOGUS_FUNARG_OFFSET with BADWIDTH
authorMatthew Dempsky <mdempsky@google.com>
Sun, 20 Aug 2023 21:27:27 +0000 (14:27 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 22 Aug 2023 20:54:55 +0000 (20:54 +0000)
We already have a magic constant to represent fields that haven't had
their offsets calculated. We don't need two.

Change-Id: Ibfa95a3a15a5cd43e1e5ec7d0971d3e61d47fb3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/521317
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/abi/abiutils.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/types/type.go

index f8e4e8ae0d062b443b302fc12265db0014a37c8d..78094d4ae941c0b3bfbed8303d483e09ea10bad0 100644 (file)
@@ -445,19 +445,18 @@ func (config *ABIConfig) ABIAnalyze(t *types.Type, setNname bool) *ABIParamResul
 }
 
 func (config *ABIConfig) updateOffset(result *ABIParamResultInfo, f *types.Field, a ABIParamAssignment, isReturn, setNname bool) {
+       if f.Offset != types.BADWIDTH {
+               base.Fatalf("field offset for %s at %s has been set to %d", f.Sym.Name, base.FmtPos(f.Pos), f.Offset)
+       }
+
        // Everything except return values in registers has either a frame home (if not in a register) or a frame spill location.
        if !isReturn || len(a.Registers) == 0 {
                // The type frame offset DOES NOT show effects of minimum frame size.
                // Getting this wrong breaks stackmaps, see liveness/plive.go:WriteFuncMap and typebits/typebits.go:Set
                off := a.FrameOffset(result)
-               fOffset := f.Offset
-               if fOffset == types.BOGUS_FUNARG_OFFSET {
-                       if setNname && f.Nname != nil {
-                               f.Nname.(*ir.Name).SetFrameOffset(off)
-                               f.Nname.(*ir.Name).SetIsOutputParamInRegisters(false)
-                       }
-               } else {
-                       base.Fatalf("field offset for %s at %s has been set to %d", f.Sym.Name, base.FmtPos(f.Pos), fOffset)
+               if setNname && f.Nname != nil {
+                       f.Nname.(*ir.Name).SetFrameOffset(off)
+                       f.Nname.(*ir.Name).SetIsOutputParamInRegisters(false)
                }
        } else {
                if setNname && f.Nname != nil {
index 89e14786b058bb504e6e08915ff5f1df66cd7f7a..9b93b599f31b813d3516e0c3252bc7988e459127 100644 (file)
@@ -306,13 +306,6 @@ func (s *state) emitOpenDeferInfo() {
        off = dvarint(x, off, -firstOffset)
 }
 
-func okOffset(offset int64) int64 {
-       if offset == types.BOGUS_FUNARG_OFFSET {
-               panic(fmt.Errorf("Bogus offset %d", offset))
-       }
-       return offset
-}
-
 // buildssa builds an SSA function for fn.
 // worker indicates which of the backend workers is doing the processing.
 func buildssa(fn *ir.Func, worker int) *ssa.Func {
index 343cc69c180319fcc41359e9fe401b2aa2ecbfe4..f03aabe4305c82eb266f0f81fa82058a0693cb91 100644 (file)
@@ -409,8 +409,7 @@ type Field struct {
        Nname Object
 
        // Offset in bytes of this field or method within its enclosing struct
-       // or interface Type.  Exception: if field is function receiver, arg or
-       // result, then this is BOGUS_FUNARG_OFFSET; types does not know the Abi.
+       // or interface Type. For parameters, this is BADWIDTH.
        Offset int64
 }
 
@@ -1686,14 +1685,6 @@ func NewInterface(methods []*Field) *Type {
        return t
 }
 
-const BOGUS_FUNARG_OFFSET = -1000000000
-
-func unzeroFieldOffsets(f []*Field) {
-       for i := range f {
-               f[i].Offset = BOGUS_FUNARG_OFFSET // This will cause an explosion if it is not corrected
-       }
-}
-
 // NewSignature returns a new function type for the given receiver,
 // parameters, and results, any of which may be nil.
 func NewSignature(recv *Field, params, results []*Field) *Type {
@@ -1711,11 +1702,6 @@ func NewSignature(recv *Field, params, results []*Field) *Type {
                return s
        }
 
-       if recv != nil {
-               recv.Offset = BOGUS_FUNARG_OFFSET
-       }
-       unzeroFieldOffsets(params)
-       unzeroFieldOffsets(results)
        ft.Receiver = funargs(recvs)
        ft.Params = funargs(params)
        ft.Results = funargs(results)