mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
take alignment into account when calculating stack size
This commit is contained in:
parent
2786e0e3d6
commit
eb5439ee96
3 changed files with 36 additions and 1 deletions
|
@ -247,7 +247,7 @@ fn jit_to_ast_help<'a>(
|
||||||
*(ptr.add(offset as usize) as *const i16) as i64
|
*(ptr.add(offset as usize) as *const i16) as i64
|
||||||
}
|
}
|
||||||
Builtin::Int64 => {
|
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
|
// moment, remove if that is no longer the case
|
||||||
*(ptr.add(offset as usize) as *const i64) as i64
|
*(ptr.add(offset as usize) as *const i64) as i64
|
||||||
}
|
}
|
||||||
|
|
|
@ -636,6 +636,19 @@ impl<'a> Layout<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stack_size(&self, pointer_size: u32) -> u32 {
|
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::*;
|
use Layout::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -2529,3 +2529,25 @@ fn pattern_match_unit_tag() {
|
||||||
i64
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue