Skip to content

Commit

Permalink
fix(codegen): clamp type size to word size
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkeeyCat committed Oct 13, 2024
1 parent 65b8f9f commit e7c93f7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions programs/arrays.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 0
}
6 changes: 6 additions & 0 deletions programs/arrays.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() -> u8 {
let arr: i32[4];
let arr_ptr: *i32 = arr as *i32;

return 0;
}
3 changes: 0 additions & 3 deletions programs/return.expect

This file was deleted.

3 changes: 0 additions & 3 deletions programs/return.mk

This file was deleted.

5 changes: 4 additions & 1 deletion src/codegen/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ impl CodeGen {
Expr::Cast(cast_expr) => {
if let Some(dest) = dest {
let type_ = cast_expr.expr.type_(&self.scope)?;
let og_size = self.arch.size(&type_, &self.scope);
let og_size = self
.arch
.size(&type_, &self.scope)
.clamp(0, self.arch.word_size());
let casted_size = self.arch.size(&cast_expr.type_, &self.scope);

if casted_size != og_size {
Expand Down

0 comments on commit e7c93f7

Please sign in to comment.