GenASM: Set the bytesToClearFromStack variable earlier

If you set the variable after visiting the function body all children will see bytesToClearFromStack == 0.
This commit is contained in:
2023-03-23 22:52:52 +01:00
parent 5f0e84198a
commit a7e93f4f01

View File

@@ -660,17 +660,17 @@ public class GenASM implements Visitor<Void> {
asm.sub("q", "$8", "%rsp");
}
e.block.welcome(this);
// I need to clear the stack here so that the top most element is the old rbp that
// ret uses to return to the caller but code that gets generated here will never be
// reached since the block node is guaranteed to contain a return node that results
// in a ret command being executed before this code would be reached.
// As a workaround (and a dirty, dirty hack) I indicate to the return node visitor
// how many bytes need to be cleared from the stack.
// ret uses to return to the caller but code that gets generated after visiting the
// function body will never be reached since the block node is guaranteed to
// contain a return node that results in a ret command being executed before this
// code would be reached. As a workaround (and a dirty, dirty hack) I indicate
// to the return node visitor how many bytes need to be cleared from the stack.
var wasStackPadded = (registerParameters.size() + e.localVariables.length) % 2 != 0;
bytesToClearFromTheStack = 8L * (registerParameters.size() + e.localVariables.length + (wasStackPadded ? 1 : 0));
e.block.welcome(this);
return null;
}