Source file src/cmd/compile/internal/escape/desugar.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package escape
     6  
     7  import (
     8  	"cmd/compile/internal/base"
     9  	"cmd/compile/internal/ir"
    10  	"cmd/compile/internal/typecheck"
    11  	"cmd/compile/internal/types"
    12  )
    13  
    14  // TODO(mdempsky): Desugaring doesn't belong during escape analysis,
    15  // but for now it's the most convenient place for some rewrites.
    16  
    17  // fixRecoverCall rewrites an ORECOVER call into ORECOVERFP,
    18  // adding an explicit frame pointer argument.
    19  // If call is not an ORECOVER call, it's left unmodified.
    20  func fixRecoverCall(call *ir.CallExpr) {
    21  	if call.Op() != ir.ORECOVER {
    22  		return
    23  	}
    24  
    25  	pos := call.Pos()
    26  
    27  	// FP is equal to caller's SP plus FixedFrameSize().
    28  	var fp ir.Node = ir.NewCallExpr(pos, ir.OGETCALLERSP, nil, nil)
    29  	if off := base.Ctxt.FixedFrameSize(); off != 0 {
    30  		fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(off))
    31  	}
    32  	// TODO(mdempsky): Replace *int32 with unsafe.Pointer, without upsetting checkptr.
    33  	fp = ir.NewConvExpr(pos, ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
    34  
    35  	call.SetOp(ir.ORECOVERFP)
    36  	call.Args = []ir.Node{typecheck.Expr(fp)}
    37  }
    38  

View as plain text