Skip to content

Commit

Permalink
Make sure we don't promise alignments that are larger than the heap a…
Browse files Browse the repository at this point in the history
…lignment to LLVM (#56938)

Fixes #56937

---------

Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
  • Loading branch information
gbaraldi and oscardssmith authored Jan 3, 2025
1 parent ed2cb49 commit 1e2758e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Compiler/test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,8 @@ f56739(a) where {T} = a
@test f56739(1) == 1
g56739(x) = @noinline f56739(x)
@test g56739(1) == 1

struct Vec56937 x::NTuple{8, VecElement{Int}} end

x56937 = Ref(Vec56937(ntuple(_->VecElement(1),8)))
@test x56937[].x[1] == VecElement{Int}(1) # shouldn't crash
2 changes: 2 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8927,6 +8927,8 @@ static jl_llvm_functions_t
Type *RT = Arg->getParamStructRetType();
TypeSize sz = DL.getTypeAllocSize(RT);
Align al = DL.getPrefTypeAlign(RT);
if (al > MAX_ALIGN)
al = Align(MAX_ALIGN);
param.addAttribute(Attribute::NonNull);
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
param.addDereferenceableAttr(sz);
Expand Down
2 changes: 2 additions & 0 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
if (al > alignm)
alignm = al;
}
if (alignm > MAX_ALIGN)
alignm = MAX_ALIGN; // We cannot guarantee alignments over 16 bytes because that's what our heap is aligned as
if (LLT_ALIGN(sz, alignm) > sz) {
haspadding = 1;
sz = LLT_ALIGN(sz, alignm);
Expand Down

0 comments on commit 1e2758e

Please sign in to comment.