Skip to content

Commit

Permalink
fix(codegen): correct offset calculating
Browse files Browse the repository at this point in the history
Before it used 0 as first offset for local variables and that's baaaad, it has to be 1-based so it starts with [rbp-1] and not [rbp] :D
  • Loading branch information
MilkeeyCat committed Aug 1, 2024
1 parent 4c9ace6 commit c9e199b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/codegen/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@ impl<'a> CodeGen<'a> {
}
.clone();
//NOTE: clone bad ^
let struct_size = type_struct.size(self.arch, &self.scope);

for (name, expr) in expr.fields.into_iter() {
let offset = type_struct.offset(self.arch, &name, &self.scope);
self.expr(
expr,
Some(MoveDestination::Local(DestinationLocal {
offset: dest.local_offset() + offset,
// NOTE: local variable use 1-based offset but struct offsets are 0-based, so to plumb it correctly gotta slap that -1
offset: struct_size + dest.local_offset() - offset - 1,
})),
)?;
}
Expand All @@ -346,7 +348,7 @@ impl<'a> CodeGen<'a> {
}

fn populate_offsets(&mut self, stmts: &Vec<Stmt>) -> usize {
let mut offset: usize = 0;
let mut offset = 1;

for stmt in stmts {
if let Stmt::VarDecl(var_decl) = stmt {
Expand Down

0 comments on commit c9e199b

Please sign in to comment.