File tree 6 files changed +9
-7
lines changed
src/cmd/compile/internal/gc
6 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -251,8 +251,6 @@ var Stksize int64 // stack size for current frame
251
251
252
252
var stkptrsize int64 // prefix of stack containing pointers
253
253
254
- var hasdefer bool // flag that curfn has defer statement
255
-
256
254
var Curfn * Node
257
255
258
256
var Widthptr int
Original file line number Diff line number Diff line change @@ -340,7 +340,6 @@ func compile(fn *Node) {
340
340
return
341
341
}
342
342
343
- hasdefer = false
344
343
walk (fn )
345
344
if nerrors != 0 {
346
345
return
Original file line number Diff line number Diff line change @@ -1092,7 +1092,7 @@ func livenessepilogue(lv *Liveness) {
1092
1092
// pointers to copy values back to the stack).
1093
1093
// TODO: if the output parameter is heap-allocated, then we
1094
1094
// don't need to keep the stack copy live?
1095
- if hasdefer {
1095
+ if lv . fn . Func . HasDefer () {
1096
1096
for i , n := range lv .vars {
1097
1097
if n .Class == PPARAMOUT {
1098
1098
if n .IsOutputParamHeapAddr () {
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ func buildssa(fn *Node) *ssa.Func {
47
47
s .pushLine (fn .Pos )
48
48
defer s .popLine ()
49
49
50
+ s .hasdefer = fn .Func .HasDefer ()
50
51
if fn .Func .Pragma & CgoUnsafeArgs != 0 {
51
52
s .cgoUnsafeArgs = true
52
53
}
@@ -218,6 +219,7 @@ type state struct {
218
219
placeholder * ssa.Value
219
220
220
221
cgoUnsafeArgs bool
222
+ hasdefer bool // whether the function contains a defer statement
221
223
}
222
224
223
225
type funcLine struct {
@@ -877,7 +879,7 @@ func (s *state) stmt(n *Node) {
877
879
// It returns a BlockRet block that ends the control flow. Its control value
878
880
// will be set to the final memory state.
879
881
func (s * state ) exit () * ssa.Block {
880
- if hasdefer {
882
+ if s . hasdefer {
881
883
s .rtcall (Deferreturn , true , nil )
882
884
}
883
885
@@ -3189,7 +3191,7 @@ func (s *state) canSSA(n *Node) bool {
3189
3191
case PEXTERN :
3190
3192
return false
3191
3193
case PPARAMOUT :
3192
- if hasdefer {
3194
+ if s . hasdefer {
3193
3195
// TODO: handle this case? Named return values must be
3194
3196
// in memory so that the deferred function can see them.
3195
3197
// Maybe do: if !strings.HasPrefix(n.String(), "~") { return false }
Original file line number Diff line number Diff line change @@ -342,6 +342,7 @@ const (
342
342
funcReflectMethod // function calls reflect.Type.Method or MethodByName
343
343
funcIsHiddenClosure
344
344
funcNoFramePointer // Must not use a frame pointer for this function
345
+ funcHasDefer // contains a defer statement
345
346
)
346
347
347
348
func (f * Func ) Dupok () bool { return f .flags & funcDupok != 0 }
@@ -350,13 +351,15 @@ func (f *Func) Needctxt() bool { return f.flags&funcNeedctxt != 0 }
350
351
func (f * Func ) ReflectMethod () bool { return f .flags & funcReflectMethod != 0 }
351
352
func (f * Func ) IsHiddenClosure () bool { return f .flags & funcIsHiddenClosure != 0 }
352
353
func (f * Func ) NoFramePointer () bool { return f .flags & funcNoFramePointer != 0 }
354
+ func (f * Func ) HasDefer () bool { return f .flags & funcHasDefer != 0 }
353
355
354
356
func (f * Func ) SetDupok (b bool ) { f .flags .set (funcDupok , b ) }
355
357
func (f * Func ) SetWrapper (b bool ) { f .flags .set (funcWrapper , b ) }
356
358
func (f * Func ) SetNeedctxt (b bool ) { f .flags .set (funcNeedctxt , b ) }
357
359
func (f * Func ) SetReflectMethod (b bool ) { f .flags .set (funcReflectMethod , b ) }
358
360
func (f * Func ) SetIsHiddenClosure (b bool ) { f .flags .set (funcIsHiddenClosure , b ) }
359
361
func (f * Func ) SetNoFramePointer (b bool ) { f .flags .set (funcNoFramePointer , b ) }
362
+ func (f * Func ) SetHasDefer (b bool ) { f .flags .set (funcHasDefer , b ) }
360
363
361
364
type Op uint8
362
365
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ func walkstmt(n *Node) *Node {
247
247
n .Right = walkstmt (n .Right )
248
248
249
249
case ODEFER :
250
- hasdefer = true
250
+ Curfn . Func . SetHasDefer ( true )
251
251
switch n .Left .Op {
252
252
case OPRINT , OPRINTN :
253
253
n .Left = walkprintfunc (n .Left , & n .Ninit )
You can’t perform that action at this time.
0 commit comments