Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we don't promise alignments that are larger than the heap alignment to LLVM #56938

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Compiler/test/codegen.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
@@ -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);
Comment on lines 8917 to +8920
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change these to use dereferenceable_size and julia_alignment functions? I usually distrust all DataLayout-based values, since they based on conversions to llvm types which require accuracy in first-class aggregates in matching C, which isn't entirely accurate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll give it a shot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a super precise type to get for all arguments sadly.

param.addAttribute(Attribute::NonNull);
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
param.addDereferenceableAttr(sz);
2 changes: 2 additions & 0 deletions src/datatype.c
Original file line number Diff line number Diff line change
@@ -769,6 +769,8 @@
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

Check warning on line 773 in src/datatype.c

GitHub Actions / Check for new typos

perhaps "aligments" should be "alignments".
if (LLT_ALIGN(sz, alignm) > sz) {
haspadding = 1;
sz = LLT_ALIGN(sz, alignm);