Skip to content

Commit e3982cd

Browse files
authored
Fix tbaa usage when storing into heap allocated immutable structs (#58483)
1 parent 4b90899 commit e3982cd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Compiler/test/codegen.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,25 @@ f57872() = (Core.isdefinedglobal(@__MODULE__, Base.compilerbarrier(:const, :x578
10471047
@noinline f_mutateany(@nospecialize x) = x[] = 1
10481048
g_mutateany() = (y = Ref(0); f_mutateany(y); y[])
10491049
@test g_mutateany() === 1
1050+
1051+
# 58470 tbaa for unionselbyte of heap allocated mutables
1052+
mutable struct Wrapper58470
1053+
x::Union{Nothing,Int}
1054+
end
1055+
1056+
function findsomething58470(dict, inds)
1057+
default = Wrapper58470(nothing)
1058+
for i in inds
1059+
x = get(dict, i, default).x
1060+
if !isnothing(x)
1061+
return x
1062+
end
1063+
end
1064+
return nothing
1065+
end
1066+
1067+
let io = IOBuffer()
1068+
code_llvm(io, findsomething58470, Tuple{Dict{Int64, Wrapper58470}, Vector{Int}}, dump_module=true, raw=true, optimize=false)
1069+
str = String(take!(io))
1070+
@test !occursin("jtbaa_unionselbyte", str)
1071+
end

src/cgutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,7 +4141,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
41414141
size_t fsz1 = jl_field_size(sty, idx0) - 1;
41424142
Value *ptindex = emit_ptrgep(ctx, addr, fsz1);
41434143
setNameWithField(ctx.emission_context, ptindex, get_objname, sty, idx0, Twine(".tindex_ptr"));
4144-
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa().tbaa_unionselbyte,
4144+
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, strct.tbaa,
41454145
Order, FailOrder,
41464146
needlock, issetfield, isreplacefield, isswapfield, ismodifyfield, issetfieldonce,
41474147
modifyop, fname);
@@ -4409,7 +4409,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
44094409
undef_derived_strct(ctx, strct, sty, strctinfo.tbaa);
44104410
for (size_t i = nargs; i < nf; i++) {
44114411
if (!jl_field_isptr(sty, i) && jl_is_uniontype(jl_field_type(sty, i))) {
4412-
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_unionselbyte);
4412+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, strctinfo.tbaa);
44134413
ai.decorateInst(ctx.builder.CreateAlignedStore(
44144414
ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0),
44154415
emit_ptrgep(ctx, strct, jl_field_offset(sty, i) + jl_field_size(sty, i) - 1),

0 commit comments

Comments
 (0)