Skip to content

Commit 17457e7

Browse files
gbaraldiKristofferC
authored andcommitted
Fix tbaa usage when storing into heap allocated immutable structs (#58483)
(cherry picked from commit e3982cd)
1 parent 010a829 commit 17457e7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/cgutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,7 +3764,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
37643764
emit_bitcast(ctx, addr, getInt8PtrTy(ctx.builder.getContext())),
37653765
ConstantInt::get(ctx.types().T_size, fsz1));
37663766
setNameWithField(ctx.emission_context, ptindex, get_objname, sty, idx0, Twine(".tindex_ptr"));
3767-
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa().tbaa_unionselbyte,
3767+
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, strct.tbaa,
37683768
Order, FailOrder,
37693769
needlock, issetfield, isreplacefield, isswapfield, ismodifyfield, issetfieldonce,
37703770
modifyop, fname);
@@ -4009,7 +4009,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
40094009
undef_derived_strct(ctx, strct, sty, strctinfo.tbaa);
40104010
for (size_t i = nargs; i < nf; i++) {
40114011
if (!jl_field_isptr(sty, i) && jl_is_uniontype(jl_field_type(sty, i))) {
4012-
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_unionselbyte);
4012+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, strctinfo.tbaa);
40134013
ai.decorateInst(ctx.builder.CreateAlignedStore(
40144014
ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0),
40154015
ctx.builder.CreateInBoundsGEP(getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, strct, getInt8PtrTy(ctx.builder.getContext())),

test/compiler/codegen.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,5 +936,24 @@ end
936936

937937
struct Vec56937 x::NTuple{8, VecElement{Int}} end
938938

939-
x56937 = Ref(Vec56937(ntuple(_->VecElement(1),8)))
940-
@test x56937[].x[1] == VecElement{Int}(1) # shouldn't crash
939+
# 58470 tbaa for unionselbyte of heap allocated mutables
940+
mutable struct Wrapper58470
941+
x::Union{Nothing,Int}
942+
end
943+
944+
function findsomething58470(dict, inds)
945+
default = Wrapper58470(nothing)
946+
for i in inds
947+
x = get(dict, i, default).x
948+
if !isnothing(x)
949+
return x
950+
end
951+
end
952+
return nothing
953+
end
954+
955+
let io = IOBuffer()
956+
code_llvm(io, findsomething58470, Tuple{Dict{Int64, Wrapper58470}, Vector{Int}}, dump_module=true, raw=true, optimize=false)
957+
str = String(take!(io))
958+
@test !occursin("jtbaa_unionselbyte", str)
959+
end

0 commit comments

Comments
 (0)