From 5cba5dab4f9c10efa980029eea9e5a6280922446 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Wed, 5 Jun 2024 16:00:11 -0300 Subject: [PATCH] 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 https://github.com/JuliaLang/julia/issues/54599 --------- Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com> (cherry picked from commit 30542e065b47c02d50e2b7f6f925943560324e7e) --- src/cgutils.cpp | 2 +- test/compiler/codegen.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 998a8421c79f08..9fd7a368faf397 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -2740,7 +2740,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st else { ptindex = emit_struct_gep(ctx, cast(lt), staddr, byte_offset + fsz1); } - auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, ctx.tbaa().tbaa_unionselbyte); + auto val = emit_unionload(ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst(jt, idx), union_max, strct.tbaa); if (val.V && val.V != addr) { setNameWithField(ctx.emission_context, val.V, get_objname, jt, idx, Twine()); } diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index a95ef3225c3f33..19321cf9f21a73 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -887,3 +887,12 @@ end ex54166 = Union{Missing, Int64}[missing -2; missing -2]; dims54166 = (1,2) @test (minimum(ex54166; dims=dims54166)[1] === missing) + +function foo54599() + pkgid = Base.identify_package("Test") + println(devnull,pkgid) + println(devnull, pkgid.uuid) + pkgid.uuid +end + +@test foo54599() !== nothing