Skip to content

Commit d331cea

Browse files
gbaraldioscardssmith
authored andcommitted
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> (cherry picked from commit 1e2758e)
1 parent 5f1b80d commit d331cea

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/codegen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8508,6 +8508,8 @@ static jl_llvm_functions_t
85088508
Type *RT = Arg->getParamStructRetType();
85098509
TypeSize sz = DL.getTypeAllocSize(RT);
85108510
Align al = DL.getPrefTypeAlign(RT);
8511+
if (al > MAX_ALIGN)
8512+
al = Align(MAX_ALIGN);
85118513
param.addAttribute(Attribute::NonNull);
85128514
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
85138515
param.addDereferenceableAttr(sz);

src/datatype.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
754754
if (al > alignm)
755755
alignm = al;
756756
}
757+
if (alignm > MAX_ALIGN)
758+
alignm = MAX_ALIGN; // We cannot guarantee alignments over 16 bytes because that's what our heap is aligned as
757759
if (LLT_ALIGN(sz, alignm) > sz) {
758760
haspadding = 1;
759761
sz = LLT_ALIGN(sz, alignm);

test/compiler/codegen.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,3 +916,9 @@ end
916916

917917
# Core.getptls() special handling
918918
@test !occursin("call ptr @jlplt", get_llvm(Core.getptls, Tuple{})) #It should lower to a direct load of the ptls and not a ccall
919+
920+
921+
struct Vec56937 x::NTuple{8, VecElement{Int}} end
922+
923+
x56937 = Ref(Vec56937(ntuple(_->VecElement(1),8)))
924+
@test x56937[].x[1] == VecElement{Int}(1) # shouldn't crash

0 commit comments

Comments
 (0)