Skip to content

Commit 30542e0

Browse files
gbaralditopolarity
andauthored
Fix tbaa annotation on union selector bytes inside of structs (#54604)
We currently cause a alias analysis contradiction by saying that the unionselbytes are on the stack, even if they are on a struct. LLVM is then able to figure out that we giving it a impossible alias situation (the object doesn't alias itself) and triggers UB. https://godbolt.org/z/ssEKMzsPf We may want to do a benchmarks run on this to see if anything too critical hasn't regressed. Fixes #54599 --------- Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
1 parent a5d6b50 commit 30542e0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/cgutils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,8 @@ static MDNode *best_field_tbaa(jl_codectx_t &ctx, const jl_cgval_t &strct, jl_da
28062806
}
28072807
}
28082808
if (strct.V && jl_field_isconst(jt, idx) && isLoadFromConstGV(strct.V))
2809-
return ctx.tbaa().tbaa_const;
2809+
return ctx.tbaa().tbaa_const; //TODO: it seems odd to have a field with a tbaa that doesn't alias it's containing struct's tbaa
2810+
//Does the fact that this is marked as constant make this fine?
28102811
return tbaa;
28112812
}
28122813

@@ -2903,7 +2904,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
29032904
else {
29042905
ptindex = emit_struct_gep(ctx, cast<StructType>(lt), staddr, byte_offset + fsz1);
29052906
}
2906-
auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, ctx.tbaa().tbaa_unionselbyte);
2907+
auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, strct.tbaa);
29072908
if (val.V && val.V != addr) {
29082909
setNameWithField(ctx.emission_context, val.V, get_objname, jt, idx, Twine());
29092910
}

test/compiler/codegen.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,12 @@ BigStructAnyInt() = BigStructAnyInt((Union{Base.inferencebarrier(Float64), Int}=
938938
@test egal_any54109(Torture1_54109(), Torture1_54109())
939939
@test egal_any54109(Torture2_54109(), Torture2_54109())
940940
@test !egal_any54109(Torture1_54109(), Torture1_54109((DefaultOr54109(2.0, false) for i = 1:897)...))
941+
942+
function foo54599()
943+
pkgid = Base.identify_package("Test")
944+
println(devnull,pkgid)
945+
println(devnull, pkgid.uuid)
946+
pkgid.uuid
947+
end
948+
949+
@test foo54599() !== nothing

0 commit comments

Comments
 (0)