Skip to content

Commit 1e2758e

Browse files
Make sure we don't promise alignments that are larger than the heap alignment to LLVM (#56938)
Fixes #56937 --------- Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
1 parent ed2cb49 commit 1e2758e

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Compiler/test/codegen.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,8 @@ f56739(a) where {T} = a
10361036
@test f56739(1) == 1
10371037
g56739(x) = @noinline f56739(x)
10381038
@test g56739(1) == 1
1039+
1040+
struct Vec56937 x::NTuple{8, VecElement{Int}} end
1041+
1042+
x56937 = Ref(Vec56937(ntuple(_->VecElement(1),8)))
1043+
@test x56937[].x[1] == VecElement{Int}(1) # shouldn't crash

src/codegen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8927,6 +8927,8 @@ static jl_llvm_functions_t
89278927
Type *RT = Arg->getParamStructRetType();
89288928
TypeSize sz = DL.getTypeAllocSize(RT);
89298929
Align al = DL.getPrefTypeAlign(RT);
8930+
if (al > MAX_ALIGN)
8931+
al = Align(MAX_ALIGN);
89308932
param.addAttribute(Attribute::NonNull);
89318933
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
89328934
param.addDereferenceableAttr(sz);

src/datatype.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
769769
if (al > alignm)
770770
alignm = al;
771771
}
772+
if (alignm > MAX_ALIGN)
773+
alignm = MAX_ALIGN; // We cannot guarantee alignments over 16 bytes because that's what our heap is aligned as
772774
if (LLT_ALIGN(sz, alignm) > sz) {
773775
haspadding = 1;
774776
sz = LLT_ALIGN(sz, alignm);

0 commit comments

Comments
 (0)