Skip to content

Commit 0f010f0

Browse files
gbaraldiKristofferC
authored and
KristofferC
committed
Make Memory{T} respect the max alignment of the heap (#53748)
Fixes #53683 (cherry picked from commit 62b5159)
1 parent 7e5a37d commit 0f010f0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,8 @@ static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
37933793
bool needlock = isatomic && layout->size > MAX_ATOMIC_SIZE;
37943794
size_t elsz = layout->size;
37953795
size_t al = layout->alignment;
3796+
if (al > JL_HEAP_ALIGNMENT)
3797+
al = JL_HEAP_ALIGNMENT;
37963798
if (isatomic == (order == jl_memory_order_notatomic)) {
37973799
emit_atomic_error(ctx,
37983800
issetmemory ?
@@ -4120,6 +4122,8 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
41204122
bool isunion = layout->flags.arrayelem_isunion;
41214123
size_t elsz = layout->size;
41224124
size_t al = layout->alignment;
4125+
if (al > JL_HEAP_ALIGNMENT)
4126+
al = JL_HEAP_ALIGNMENT;
41234127
bool needlock = isatomic && !isboxed && elsz > MAX_ATOMIC_SIZE;
41244128
AtomicOrdering Order = (needlock || order <= jl_memory_order_notatomic)
41254129
? (isboxed ? AtomicOrdering::Unordered : AtomicOrdering::NotAtomic)

test/vecelement.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
2-
2+
using InteractiveUtils
33
make_value(::Type{T}, i::Integer) where {T<:Integer} = 3*i%T
44
make_value(::Type{T},i::Integer) where {T<:AbstractFloat} = T(3*i)
55

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

0 commit comments

Comments
 (0)