Merge branch 'bug/fix-tco' into 'master'

push all args onto stack before moving them into the local var to ensure that...

See merge request mkais001/klang!22
This commit is contained in:
Dennis Kaiser
2020-03-10 12:19:34 +01:00

View File

@@ -695,16 +695,20 @@ public class GenASM implements Visitor<Void> {
public Void visit(FunctionCall e) {
if (e.isTailRecursive) {
// Visit the arguments and move them into the location of the corresponding local var
// Visit the arguments and move them into the stack
for(int i = 0; i < e.arguments.length; i++) {
e.arguments[i].welcome(this);
int offset = this.env.get(this.currentFunctionParams[i].name);
if (e.arguments[i].type.equals(Type.getFloatType())) {
this.ex.write(" movq %xmm0, %rax\n");
}
this.ex.write(" movq %rax, " + offset + "(%rbp)\n");
this.ex.write(" pushq %rax\n");
}
// push args into local var locations, last arg is ontop of the stack
for (int i = e.arguments.length - 1; i >= 0; i--) {
this.ex.write(" popq " + this.env.get(this.currentFunctionParams[i].name) + "(%rbp)\n");
}
this.ex.write(" jmp .L" + this.currentFunctionStartLabel + "\n");