Skip to content

Commit bab6633

Browse files
gbaralditopolarity
authored and
KristofferC
committed
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> (cherry picked from commit 30542e0)
1 parent 5b3a5e4 commit bab6633

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/cgutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
27402740
else {
27412741
ptindex = emit_struct_gep(ctx, cast<StructType>(lt), staddr, byte_offset + fsz1);
27422742
}
2743-
auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, ctx.tbaa().tbaa_unionselbyte);
2743+
auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, strct.tbaa);
27442744
if (val.V && val.V != addr) {
27452745
setNameWithField(ctx.emission_context, val.V, get_objname, jt, idx, Twine());
27462746
}

test/compiler/codegen.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,12 @@ end
887887
ex54166 = Union{Missing, Int64}[missing -2; missing -2];
888888
dims54166 = (1,2)
889889
@test (minimum(ex54166; dims=dims54166)[1] === missing)
890+
891+
function foo54599()
892+
pkgid = Base.identify_package("Test")
893+
println(devnull,pkgid)
894+
println(devnull, pkgid.uuid)
895+
pkgid.uuid
896+
end
897+
898+
@test foo54599() !== nothing

0 commit comments

Comments
 (0)