From 8e95fa8cbcf02d24e46b75a6f6a730363a48a6cf Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Tue, 28 May 2024 16:44:19 -0300 Subject: [PATCH 1/2] Fix tbaa annotation on union selector bytes inside of structs to avoid alias analysis contradictions that resulted in UB Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com> --- src/cgutils.cpp | 5 +++-- test/compiler/codegen.jl | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 6c1f7c9645a78..811dd53e4ab7f 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -2780,7 +2780,8 @@ static MDNode *best_field_tbaa(jl_codectx_t &ctx, const jl_cgval_t &strct, jl_da } } if (strct.V && jl_field_isconst(jt, idx) && isLoadFromConstGV(strct.V)) - return ctx.tbaa().tbaa_const; + return ctx.tbaa().tbaa_const; //TODO: it seems odd to have a field with a tbaa that doesn't alias it's containings struct's tbaa + //Does the fact that this is marked as constant make this fine? return tbaa; } @@ -2878,7 +2879,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 ff3cf50f45d21..81bd57355b83c 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -938,3 +938,12 @@ BigStructAnyInt() = BigStructAnyInt((Union{Base.inferencebarrier(Float64), Int}= @test egal_any54109(Torture1_54109(), Torture1_54109()) @test egal_any54109(Torture2_54109(), Torture2_54109()) @test !egal_any54109(Torture1_54109(), Torture1_54109((DefaultOr54109(2.0, false) for i = 1:897)...)) + +function foo54599() + pkgid = Base.identify_package("Test") + println(devnull,pkgid) + println(devnull, pkgid.uuid) + pkgid.uuid +end + +@test foo54599() !== nothing From b0655d88f8a151e2b80142828d09ac55a186b433 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Tue, 28 May 2024 16:48:06 -0300 Subject: [PATCH 2/2] Fix typo! --- src/cgutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 811dd53e4ab7f..6e07aa39cbe79 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -2780,8 +2780,8 @@ static MDNode *best_field_tbaa(jl_codectx_t &ctx, const jl_cgval_t &strct, jl_da } } if (strct.V && jl_field_isconst(jt, idx) && isLoadFromConstGV(strct.V)) - return ctx.tbaa().tbaa_const; //TODO: it seems odd to have a field with a tbaa that doesn't alias it's containings struct's tbaa - //Does the fact that this is marked as constant make this fine? + 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 + //Does the fact that this is marked as constant make this fine? return tbaa; }