Skip to content

Commit 37f848c

Browse files
authored
Utilize correct tbaa when emitting stores of unions. (#54222)
Also remove unused argument from union_store
1 parent 8f6418e commit 37f848c

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
@@ -3725,7 +3725,7 @@ static void emit_write_multibarrier(jl_codectx_t &ctx, Value *parent, Value *agg
37253725

37263726
static jl_cgval_t union_store(jl_codectx_t &ctx,
37273727
Value *ptr, Value *ptindex, jl_cgval_t rhs, jl_cgval_t cmp,
3728-
jl_value_t *jltype, MDNode *tbaa, MDNode *aliasscope, MDNode *tbaa_tindex,
3728+
jl_value_t *jltype, MDNode *tbaa, MDNode *tbaa_tindex,
37293729
AtomicOrdering Order, AtomicOrdering FailOrder,
37303730
Value *needlock, bool issetfield, bool isreplacefield, bool isswapfield, bool ismodifyfield, bool issetfieldonce,
37313731
const jl_cgval_t *modifyop, const Twine &fname)
@@ -3783,7 +3783,7 @@ static jl_cgval_t union_store(jl_codectx_t &ctx,
37833783
}
37843784
Value *tindex = compute_tindex_unboxed(ctx, rhs_union, jltype);
37853785
tindex = ctx.builder.CreateNUWSub(tindex, ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 1));
3786-
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_unionselbyte);
3786+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa_tindex);
37873787
ai.decorateInst(ctx.builder.CreateAlignedStore(tindex, ptindex, Align(1)));
37883788
// copy data
37893789
if (!rhs.isghost) {
@@ -3839,7 +3839,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
38393839
emit_bitcast(ctx, addr, getInt8PtrTy(ctx.builder.getContext())),
38403840
ConstantInt::get(ctx.types().T_size, fsz1));
38413841
setNameWithField(ctx.emission_context, ptindex, get_objname, sty, idx0, Twine(".tindex_ptr"));
3842-
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, nullptr, ctx.tbaa().tbaa_unionselbyte,
3842+
return union_store(ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa().tbaa_unionselbyte,
38433843
Order, FailOrder,
38443844
needlock, issetfield, isreplacefield, isswapfield, ismodifyfield, issetfieldonce,
38453845
modifyop, fname);

src/codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3875,7 +3875,7 @@ static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
38753875
ptindex = emit_bitcast(ctx, ptindex, getInt8PtrTy(ctx.builder.getContext()));
38763876
ptindex = ctx.builder.CreateInBoundsGEP(getInt8Ty(ctx.builder.getContext()), ptindex, idx0);
38773877
*ret = union_store(ctx, data, ptindex, val, cmp, ety,
3878-
ctx.tbaa().tbaa_arraybuf, nullptr, ctx.tbaa().tbaa_arrayselbyte,
3878+
ctx.tbaa().tbaa_arraybuf, ctx.tbaa().tbaa_arrayselbyte,
38793879
Order, FailOrder,
38803880
nullptr, issetmemory, isreplacememory, isswapmemory, ismodifymemory, issetmemoryonce,
38813881
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)