Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: function inlining produces incorrect results in certain conditions #30566
What version of Go are you using (
@siddharthab if you could do a bisect, that would be very helpful.
referenced this issue
Mar 4, 2019
Here's what I can understand. If you look at the assembly code, you will see that the return value from the non-inlined function call was not saved further down the stack before executing the inline function call.
In the actual code in our code base, the return value was moved to registers but then the execution immediately jumps to the inline function.
I am not familiar with the compiler code base, so can not point to the source of the bug.
This appears to be a bug in the order pass. Here's a simple repro:
This should print 1 then 2. Instead, it prints 2 then 1.
The problem is that order rewrites the code to:
Order wants to extract all the calls to their own statements so it can ensure the function calls all happen in order. But it can't extract the call from the RHS of a
As far as I can tell, my autotmp reuse code just triggers this underlying bug. There's nothing wrong with the autotmp reuse otherwise.
In particular, what happens in the OP's code is that the introduced temporaries are incorrectly reused because order processes the code in a different order than the code is emitted.
We first process
We then process
But then it issues the code out of order. We end up with
Boom, we end up with