From 382c234dc959de338d4361caa974230718c5ea31 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Thu, 2 Jan 2025 16:51:52 -0300 Subject: [PATCH 1/3] Make sure we don't promise alignments that are larger than the heap alignment to LLVM --- Compiler/test/codegen.jl | 5 +++++ src/codegen.cpp | 2 ++ src/datatype.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/Compiler/test/codegen.jl b/Compiler/test/codegen.jl index 9ba268fe95be8..6b4029c0afe7b 100644 --- a/Compiler/test/codegen.jl +++ b/Compiler/test/codegen.jl @@ -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[].[1] == VecElement{Int}(1) # shouldn't crash diff --git a/src/codegen.cpp b/src/codegen.cpp index 5bf7c74deedcb..714b8e930dd51 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8916,6 +8916,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); diff --git a/src/datatype.c b/src/datatype.c index c78b00fdd2245..d313a27942b24 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -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 aligments 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); From 6389a247379b1590b630ba726aaf94b4f2644bbc Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Thu, 2 Jan 2025 16:03:59 -0500 Subject: [PATCH 2/3] typo --- src/datatype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datatype.c b/src/datatype.c index d313a27942b24..fd25cca503676 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -770,7 +770,7 @@ void jl_compute_field_offsets(jl_datatype_t *st) alignm = al; } if (alignm > MAX_ALIGN) - alignm = MAX_ALIGN; // We cannot guarantee aligments over 16 bytes because that's what our heap is aligned as + 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); From 2570e28fd93c024123546f1024bc7014f36e4912 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Fri, 3 Jan 2025 10:53:54 -0300 Subject: [PATCH 3/3] Fix broken test --- Compiler/test/codegen.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compiler/test/codegen.jl b/Compiler/test/codegen.jl index 6b4029c0afe7b..9b92f560c64fc 100644 --- a/Compiler/test/codegen.jl +++ b/Compiler/test/codegen.jl @@ -1040,4 +1040,4 @@ g56739(x) = @noinline f56739(x) struct Vec56937 x::NTuple{8, VecElement{Int}} end x56937 = Ref(Vec56937(ntuple(_->VecElement(1),8))) -@test x56937[].[1] == VecElement{Int}(1) # shouldn't crash +@test x56937[].x[1] == VecElement{Int}(1) # shouldn't crash