]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: fix escape analysis of heap-allocated results
authorMatthew Dempsky <mdempsky@google.com>
Sat, 27 Feb 2021 17:41:19 +0000 (09:41 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 27 Feb 2021 19:01:19 +0000 (19:01 +0000)
commita429926159232f2e127d46698633ffce5896ae30
treeaecc80735c3487b18eaf28a1a85d7d7fb485c664
parent998fe70b683ed64d0bc67d9e0a35f8a7bcbe161d
cmd/compile: fix escape analysis of heap-allocated results

One of escape analysis's responsibilities is to summarize whether/how
each function parameter flows to the heap so we can correctly
incorporate those flows into callers' escape analysis data flow
graphs.

As an optimization, we separately record when parameters flow to
result parameters, so that we can more precisely analyze parameter
flows based on how the results are used at the call site. However, if
a named result parameter itself needs to be heap allocated, this
optimization isn't safe and the parameter needs to be recorded as
flowing to heap rather than flowing to result.

Escape analysis used to get this correct because it conservatively
rewalked the data-flow graph multiple times. So even though it would
incorrectly record the result parameter flow, it would separately find
a flow to the heap. However, CL 196811 (specifically, case 3)
optimized the walking logic to reduce unnecessary rewalks causing us
to stop finding the extra heap flow.

This CL fixes the issue by correcting location.leakTo to be sensitive
to sink.escapes and not record result-flows when the result parameter
escapes to the heap.

Fixes #44614.

Change-Id: I48742ed35a6cab591094e2d23a439e205bd65c50
Reviewed-on: https://go-review.googlesource.com/c/go/+/297289
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/escape/escape.go
test/escape5.go