Skip to content

Commit 58fb05a

Browse files
committed
cmd/compile: explain special treatment when rewrite slice literal args
Followup discussion in CL 360055. Change-Id: I36212c2a497b152d01ed86d244d5f57bd34a64a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/360614 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent f2ff1c6 commit 58fb05a

File tree

1 file changed

+18
-1
lines changed
  • src/cmd/compile/internal/escape

1 file changed

+18
-1
lines changed

src/cmd/compile/internal/escape/call.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,24 @@ func (e *escape) rewriteArgument(argp *ir.Node, init *ir.Nodes, call ir.Node, fn
333333
}
334334
}
335335

336-
// Peel away any slice lits.
336+
// Peel away any slice literals for better escape analyze
337+
// them. For example:
338+
//
339+
// go F([]int{a, b})
340+
//
341+
// If F doesn't escape its arguments, then the slice can
342+
// be allocated on the new goroutine's stack.
343+
//
344+
// For variadic functions, the compiler has already rewritten:
345+
//
346+
// f(a, b, c)
347+
//
348+
// to:
349+
//
350+
// f([]T{a, b, c}...)
351+
//
352+
// So we need to look into slice elements to handle uintptr(ptr)
353+
// arguments to syscall-like functions correctly.
337354
if arg := *argp; arg.Op() == ir.OSLICELIT {
338355
list := arg.(*ir.CompLitExpr).List
339356
for i := range list {

0 commit comments

Comments
 (0)