-
Notifications
You must be signed in to change notification settings - Fork 951
compiler question: What could be causing these false positive heap escapes? #3810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How can I reproduce this issue? That would help a lot to narrow down the issue. I suspect the issue is a phi node. Those can happen in a loop, and in that case it wouldn't be correct to optimize the heap allocation to a stack allocation (it would reuse the allocation). However, in this case there is no loop and converting to a stack allocation would be correct. |
To reproduce:
The output:
|
(BTW, I'd love to fix the max stack size allocation issue: #3331 ) |
I wonder if it's because BTW, is this still happening? I've been thinking of looking at some escape analysis tweaks. |
It doesn't like the |
I see this code in bbspi.go: var aux [1]byte
mocking := s.MockTo != nil
if len(w) != 0 {
if len(r) == 0 {
r = aux[:]
}
r[0] = s.firstTransfer(w[0], mocking)
w = w[1:]
r = r[1:]
} Here, the mocking := s.MockTo != nil
if len(w) != 0 {
result := s.firstTransfer(w[0], mocking)
if len(r) != 0 {
r[0] = result
}
w = w[1:]
r = r[1:]
} And in cy_io.go, in While the first one (in bbspi.go) could perhaps be optimized by the compiler (with some dataflow analysis), the second one is going to be very difficult: the compiler doesn't know that the |
@soypat has this question been answered now? |
Thanks everyone! Now closing. |
Question
I have a program that escapes variables which should not be escaped to heap. When I try to build an MWE I'm surprised how edge casey the escape condition seems. What could be causing this?
I've even changed the spi type on the Device to be a concrete SPIbb type and this still happens.
Line numbers may vary
Observations
If we comment out
LINE B
(in second dropdown) line both heap allocations dissapear. For some reason this line causes heap allocations of bothaux
variable and thebuf
variable in the Write32S Device's method, which is a [4]byte type.buf
ONLY escapes when passed in as the secondr
argument toTx
.Furthermore, I can't replicate these heap allocations by writing a function that performs nearly identical operations with
buf
...Code
Attempt at minimal reproducer
REMOVE
return
TO OBSERVE BEHAVIOR!SPIbb.Tx, problematic assignment
The text was updated successfully, but these errors were encountered: