From a7e93f4f015d3459e794913ca3ad3f1e057b1979 Mon Sep 17 00:00:00 2001 From: nitrix Date: Thu, 23 Mar 2023 22:52:52 +0100 Subject: [PATCH] GenASM: Set the bytesToClearFromStack variable earlier If you set the variable after visiting the function body all children will see bytesToClearFromStack == 0. --- .../de/hsrm/compiler/Klang/visitors/GenASM.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java index 7848143..5fe6401 100644 --- a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java +++ b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java @@ -660,17 +660,17 @@ public class GenASM implements Visitor { 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; }