From 72691483d9278c5753f986ea47480f2aca997b77 Mon Sep 17 00:00:00 2001 From: Ian Atol Date: Mon, 11 Apr 2022 10:15:19 -0700 Subject: [PATCH] Fix 44921 by properly setting Vboxed field --- src/codegen.cpp | 17 +++++++++-------- test/compiler/codegen.jl | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 65bb19fc2f7bc..248216f475ee7 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1864,14 +1864,15 @@ static jl_cgval_t convert_julia_type_union(jl_codectx_t &ctx, const jl_cgval_t & boxv = ctx.builder.CreateSelect( ctx.builder.CreateAnd(wasboxed, isboxed), v.Vboxed, boxv); } + Value *slotv; + MDNode *tbaa; if (v.V == NULL) { // v.V might be NULL if it was all ghost objects before - return jl_cgval_t(boxv, NULL, false, typ, new_tindex, ctx.tbaa()); + slotv = NULL; + tbaa = ctx.tbaa().tbaa_const; } else { Value *isboxv = ctx.builder.CreateIsNotNull(boxv); - Value *slotv; - MDNode *tbaa; if (v.ispointer()) { slotv = v.V; tbaa = v.tbaa; @@ -1884,12 +1885,12 @@ static jl_cgval_t convert_julia_type_union(jl_codectx_t &ctx, const jl_cgval_t & slotv = ctx.builder.CreateSelect(isboxv, decay_derived(ctx, boxv), decay_derived(ctx, emit_bitcast(ctx, slotv, boxv->getType()))); - jl_cgval_t newv = jl_cgval_t(slotv, NULL, false, typ, new_tindex, ctx.tbaa()); - assert(boxv->getType() == ctx.types().T_prjlvalue); - newv.Vboxed = boxv; - newv.tbaa = tbaa; - return newv; } + jl_cgval_t newv = jl_cgval_t(slotv, NULL, false, typ, new_tindex, ctx.tbaa()); + assert(boxv->getType() == ctx.types().T_prjlvalue); + newv.Vboxed = boxv; + newv.tbaa = tbaa; + return newv; } } else { diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index d9f2bb1dbfcc0..9724091637f97 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -702,6 +702,23 @@ function f42645() end @test ((f42645()::B42645).y::A42645{Int}).x +struct A44921{T} + x::T +end +function f44921(a) + if a == :x + A44921(_f) # _f purposefully undefined + elseif a == :p + g44921(a) + end +end +function g44921(a) + if !@isdefined _f # just needs to be some non constprop-able condition + A44921(()) + end +end +@test f44921(:p) isa A44921 + # issue #43123 @noinline cmp43123(a::Some, b::Some) = something(a) === something(b) @noinline cmp43123(a, b) = a[] === b[]