Skip to content

Commit

Permalink
Fix tbaa annotation on union selector bytes inside of structs (#54604)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gbaraldi authored and KristofferC committed Jun 7, 2024
1 parent 5b3a5e4 commit bab6633
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StructType>(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());
}
Expand Down
9 changes: 9 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bab6633

Please sign in to comment.