Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust ABI with unnamed function parameter #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fuhsnn
Copy link

@fuhsnn fuhsnn commented Nov 29, 2024

The current way of ignoring unnamed parameters will create ABI mismatch, since chibicc implicitly assume parameter list is just how much local objects are created at function entry:

chibicc/parse.c

Line 3266 in 2c85b56

fn->params = locals;

We need dummy object to maintain the ABI info.

It can be observed by compiling this snippet:

int fn(int,int,int,int,int should_be_r8d) {
  return should_be_r8d;
}
  mov %edi, -12(%rbp)
  lea -12(%rbp), %rax
  movsxd (%rax), %rax
  jmp .L.return.fn
  ud2
.L.return.fn:
  mov %rbp, %rsp
  pop %rbp
  ret

%edi was used instead of %r8d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant