]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: explain special treatment when rewrite slice literal args
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 2 Nov 2021 03:19:24 +0000 (10:19 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 2 Nov 2021 16:19:52 +0000 (16:19 +0000)
Followup discussion in CL 360055.

Change-Id: I36212c2a497b152d01ed86d244d5f57bd34a64a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/360614
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

index 63e790a78670abeac0f9c0f96c24eccfe5913e4b..d1215afca8331e04a9519ce14a8e701df344c037 100644 (file)
@@ -333,7 +333,24 @@ func (e *escape) rewriteArgument(argp *ir.Node, init *ir.Nodes, call ir.Node, fn
                }
        }
 
-       // Peel away any slice lits.
+       // Peel away any slice literals for better escape analyze
+       // them. For example:
+       //
+       //     go F([]int{a, b})
+       //
+       // If F doesn't escape its arguments, then the slice can
+       // be allocated on the new goroutine's stack.
+       //
+       // For variadic functions, the compiler has already rewritten:
+       //
+       //     f(a, b, c)
+       //
+       // to:
+       //
+       //     f([]T{a, b, c}...)
+       //
+       // So we need to look into slice elements to handle uintptr(ptr)
+       // arguments to syscall-like functions correctly.
        if arg := *argp; arg.Op() == ir.OSLICELIT {
                list := arg.(*ir.CompLitExpr).List
                for i := range list {