RFR: 8276836: Error in javac caused by switch expression without result expressions: Internal error: stack sim error
Guoxiong Li
gli at openjdk.java.net
Wed Dec 1 13:04:21 UTC 2021
On Mon, 29 Nov 2021 18:43:02 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> One possible alternative that might work would be to put this only into doHandleSwitchExpression
I don't think that putting the code into `doHandleSwitchExpression` can solve this issue. Because the issue is caused by the right operand of the binary operation but not the switch expression. If the switch expression is not the right operand of the binary operation, even though `!code.isAlive()` is true, it don't need to pop the stack element. You can see the comment `Complete generating code for operation, with left operand already on stack.` in the method `Gen#completeBinop`. Only when the left operand is already on the stack should we pop the stack element to resolve the mistake.
> But, I wonder if we need to fix the simulated stack at all (as it won't be completely sensible in anyway). Maybe all we need is to disable the assertion?
We can't disable the assertion when `code.isAlive()` is false, because there are many situations which can make `code.isAlive()` as false. The condition `code.state.stacksize != 0` is enough. When we simulate the stack opration to the end of the method, the stack always need to be empty which is same as the jvm(the actual stack opration). If the stack is not empty, it means the code generation step has the bug which is like this issue.
> In general, I am afraid there needs to be more testing
I will submit more tests as needed.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6350
More information about the compiler-dev
mailing list