Skip to content

Commit 06134f6

Browse files
gbaraldiKristofferC
authored andcommitted
Utilize correct tbaa when emitting stores of unions. (#54222)
Also remove unused argument from union_store (cherry picked from commit 37f848c)
1 parent c98867b commit 06134f6

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/cgutils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,7 +3625,7 @@ static void emit_write_multibarrier(jl_codectx_t &ctx, Value *parent, Value *agg
36253625

36263626
static jl_cgval_t union_store(jl_codectx_t &ctx,
36273627
Value *ptr, Value *ptindex, jl_cgval_t rhs, jl_cgval_t cmp,
3628-
jl_value_t *jltype, MDNode *tbaa, MDNode *aliasscope, MDNode *tbaa_tindex,
3628+
jl_value_t *jltype, MDNode *tbaa, MDNode *tbaa_tindex,
36293629
AtomicOrdering Order, AtomicOrdering FailOrder,
36303630
Value *needlock, bool issetfield, bool isreplacefield, bool isswapfield, bool ismodifyfield, bool issetfieldonce,
36313631
const jl_cgval_t *modifyop, const Twine &fname)
@@ -3683,7 +3683,7 @@ static jl_cgval_t union_store(jl_codectx_t &ctx,
36833683
}
36843684
Value *tindex = compute_tindex_unboxed(ctx, rhs_union, jltype);
36853685
tindex = ctx.builder.CreateNUWSub(tindex, ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 1));
3686-
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_unionselbyte);
3686+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa_tindex);
36873687
ai.decorateInst(ctx.builder.CreateAlignedStore(tindex, ptindex, Align(1)));
36883688
// copy data
36893689
if (!rhs.isghost) {
@@ -3739,7 +3739,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
37393739
emit_bitcast(ctx, addr, getInt8PtrTy(ctx.builder.getContext())),
37403740
ConstantInt::get(ctx.types().T_size, fsz1));
37413741
setNameWithField(ctx.emission_context, ptindex, get_objname, sty, idx0, Twine(".tindex_ptr"));
3742-
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, nullptr, ctx.tbaa().tbaa_unionselbyte,
3742+
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa().tbaa_unionselbyte,
37433743
Order, FailOrder,
37443744
needlock, issetfield, isreplacefield, isswapfield, ismodifyfield, issetfieldonce,
37453745
modifyop, fname);

src/codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3870,7 +3870,7 @@ static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
38703870
ptindex = emit_bitcast(ctx, ptindex, getInt8PtrTy(ctx.builder.getContext()));
38713871
ptindex = ctx.builder.CreateInBoundsGEP(getInt8Ty(ctx.builder.getContext()), ptindex, idx0);
38723872
*ret = union_store(ctx, data, ptindex, val, cmp, ety,
3873-
ctx.tbaa().tbaa_arraybuf, nullptr, ctx.tbaa().tbaa_arrayselbyte,
3873+
ctx.tbaa().tbaa_arraybuf, ctx.tbaa().tbaa_arrayselbyte,
38743874
Order, FailOrder,
38753875
nullptr, issetmemory, isreplacememory, isswapmemory, ismodifymemory, issetmemoryonce,
38763876
modifyop, fname);

test/compiler/codegen.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,3 +873,17 @@ if Sys.ARCH === :x86_64
873873
end
874874
end
875875
end
876+
877+
#Check if we aren't emitting the store with the wrong TBAA metadata
878+
879+
foo54166(x,i,y) = x[i] = y
880+
let io = IOBuffer()
881+
code_llvm(io,foo54166, (Vector{Union{Missing,Int}}, Int, Int), dump_module=true, raw=true)
882+
str = String(take!(io))
883+
@test !occursin("jtbaa_unionselbyte", str)
884+
@test occursin("jtbaa_arrayselbyte", str)
885+
end
886+
887+
ex54166 = Union{Missing, Int64}[missing -2; missing -2];
888+
dims54166 = (1,2)
889+
@test (minimum(ex54166; dims=dims54166)[1] === missing)

0 commit comments

Comments
 (0)