Skip to content

Commit

Permalink
Make Memory{T} respect the max alignment of the heap (#53748)
Browse files Browse the repository at this point in the history
Fixes #53683
  • Loading branch information
gbaraldi authored May 10, 2024
1 parent 6582eaa commit 62b5159
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3948,6 +3948,8 @@ static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
bool needlock = isatomic && layout->size > MAX_ATOMIC_SIZE;
size_t elsz = layout->size;
size_t al = layout->alignment;
if (al > JL_HEAP_ALIGNMENT)
al = JL_HEAP_ALIGNMENT;
if (isatomic == (order == jl_memory_order_notatomic)) {
emit_atomic_error(ctx,
issetmemory ?
Expand Down Expand Up @@ -4276,6 +4278,8 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
bool isunion = layout->flags.arrayelem_isunion;
size_t elsz = layout->size;
size_t al = layout->alignment;
if (al > JL_HEAP_ALIGNMENT)
al = JL_HEAP_ALIGNMENT;
bool needlock = isatomic && !isboxed && elsz > MAX_ATOMIC_SIZE;
AtomicOrdering Order = (needlock || order <= jl_memory_order_notatomic)
? (isboxed ? AtomicOrdering::Unordered : AtomicOrdering::NotAtomic)
Expand Down
8 changes: 7 additions & 1 deletion test/vecelement.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using InteractiveUtils
make_value(::Type{T}, i::Integer) where {T<:Integer} = 3*i%T
make_value(::Type{T},i::Integer) where {T<:AbstractFloat} = T(3*i)

Expand Down Expand Up @@ -120,3 +120,9 @@ for T in (Float64, Float32, Int64, Int32)
@test b == result
end
end
@testset "vecelement overalignment" begin
io = IOBuffer()
code_llvm(io,getindex, (Array{NTuple{5, VecElement{Float64}}, 1}, Int64), optimize=false)
ir = String(take!(io))
@test match(r"align 64", ir) === nothing
end

0 comments on commit 62b5159

Please sign in to comment.