diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 8e3fb0ee34909..c9beb40a7e474 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -4201,7 +4201,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg fval = boxed(ctx, fval_info, field_promotable); if (!init_as_value) { jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack); - ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(jl_field_align(sty, i)))); + ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(roots ? sizeof(void*) : jl_field_align(sty, i)))); } } else if (jl_is_uniontype(jtype)) { diff --git a/src/codegen.cpp b/src/codegen.cpp index d86aa7ba1eb87..68f27fa23d5f0 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6187,11 +6187,22 @@ static void emit_upsilonnode(jl_codectx_t &ctx, ssize_t phic, jl_value_t *val) vi.pTIndex, Align(1), true); } else if (vi.value.V && !vi.value.constant && vi.value.typ != jl_bottom_type) { - assert(vi.value.ispointer()); - Type *T = cast(vi.value.V)->getAllocatedType(); - if (CountTrackedPointers(T).count) { + assert(vi.value.inline_roots || vi.value.ispointer()); + if (vi.value.inline_roots) { // memory optimization: make gc pointers re-initialized to NULL - ctx.builder.CreateStore(Constant::getNullValue(T), vi.value.V, true); + AllocaInst *ssaroots = cast(vi.value.inline_roots); + size_t nroots = cast(ssaroots->getArraySize())->getZExtValue(); + auto T_prjlvalue = ssaroots->getAllocatedType(); + if (auto AT = dyn_cast(T_prjlvalue)) { + nroots *= AT->getNumElements(); + T_prjlvalue = AT->getElementType(); + } + assert(T_prjlvalue == ctx.types().T_prjlvalue); + Value *nullval = Constant::getNullValue(T_prjlvalue); + auto stack_ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack); + for (size_t i = 0; i < nroots; i++) { + stack_ai.decorateInst(ctx.builder.CreateAlignedStore(nullval, emit_ptrgep(ctx, ssaroots, i * sizeof(void*)), ssaroots->getAlign(), true)); + } } } } @@ -9598,15 +9609,17 @@ static jl_llvm_functions_t if (ctx.vaSlot > 0) { // remove VA allocation if we never referenced it + assert(ctx.slots[ctx.vaSlot].isSA && ctx.slots[ctx.vaSlot].isArgument); Instruction *root = cast_or_null(ctx.slots[ctx.vaSlot].boxroot); if (root) { - Instruction *store_value = NULL; bool have_real_use = false; for (Use &U : root->uses()) { User *RU = U.getUser(); if (StoreInst *SRU = dyn_cast(RU)) { - if (!store_value) - store_value = dyn_cast(SRU->getValueOperand()); + assert(isa(SRU->getValueOperand()) || SRU->getValueOperand() == restTuple); + } + else if (MemSetInst *MSI = dyn_cast(RU)) { + assert(MSI->getValue() == ctx.builder.getInt8(0)); } else if (isa(RU)) { } @@ -9628,7 +9641,6 @@ static jl_llvm_functions_t if (use) use->eraseFromParent(); root->eraseFromParent(); - assert(!store_value || store_value == restTuple); restTuple->eraseFromParent(); } } diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index fa7532c5cc827..f152407ea5b77 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -501,7 +501,7 @@ function f37262(x) end end @testset "#37262" begin - str_opaque = "store volatile { i8, ptr, ptr, ptr, ptr } zeroinitializer, ptr %phic" + str_opaque = "getelementptr inbounds i8, ptr %.roots.phic, i32 16\n store volatile ptr null" llvmstr = get_llvm(f37262, (Bool,), false, false, false) @test contains(llvmstr, str_opaque) @test f37262(Base.inferencebarrier(true)) === nothing