take alignment into account when calculating stack size

This commit is contained in:
Folkert 2021-08-11 22:37:00 +02:00
parent 2786e0e3d6
commit eb5439ee96
3 changed files with 36 additions and 1 deletions

View file

@ -247,7 +247,7 @@ fn jit_to_ast_help<'a>(
*(ptr.add(offset as usize) as *const i16) as i64
}
Builtin::Int64 => {
// used by non-recursive tag unions at the
// used by non-recursive unions at the
// moment, remove if that is no longer the case
*(ptr.add(offset as usize) as *const i64) as i64
}

View file

@ -636,6 +636,19 @@ impl<'a> Layout<'a> {
}
pub fn stack_size(&self, pointer_size: u32) -> u32 {
let width = self.stack_size_without_alignment(pointer_size);
let alignment = self.alignment_bytes(pointer_size);
if alignment == 0 {
width
} else if width % alignment > 0 {
width + alignment - (width % alignment)
} else {
width
}
}
fn stack_size_without_alignment(&self, pointer_size: u32) -> u32 {
use Layout::*;
match self {

View file

@ -2529,3 +2529,25 @@ fn pattern_match_unit_tag() {
i64
);
}
#[test]
fn mirror_llvm_alignment_padding() {
// see https://github.com/rtfeldman/roc/issues/1569
assert_evals_to!(
indoc!(
r#"
app "test" provides [ main ] to "./platform"
main : Str
main =
p1 = {name : "test1", test: 1 == 1 }
List.map [p1, p1 ] (\{ test } -> if test then "pass" else "fail")
|> Str.joinWith "\n"
"#
),
RocStr::from_slice(b"pass\npass"),
RocStr
);
}