Skip to content

Commit e3f5ea0

Browse files
committed
bugfix
1 parent 76a6156 commit e3f5ea0

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/cgutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4201,7 +4201,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
42014201
fval = boxed(ctx, fval_info, field_promotable);
42024202
if (!init_as_value) {
42034203
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack);
4204-
ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(jl_field_align(sty, i))));
4204+
ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(roots ? sizeof(void*) : jl_field_align(sty, i))));
42054205
}
42064206
}
42074207
else if (jl_is_uniontype(jtype)) {

src/codegen.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,11 +6187,22 @@ static void emit_upsilonnode(jl_codectx_t &ctx, ssize_t phic, jl_value_t *val)
61876187
vi.pTIndex, Align(1), true);
61886188
}
61896189
else if (vi.value.V && !vi.value.constant && vi.value.typ != jl_bottom_type) {
6190-
assert(vi.value.ispointer());
6191-
Type *T = cast<AllocaInst>(vi.value.V)->getAllocatedType();
6192-
if (CountTrackedPointers(T).count) {
6190+
assert(vi.value.inline_roots || vi.value.ispointer());
6191+
if (vi.value.inline_roots) {
61936192
// memory optimization: make gc pointers re-initialized to NULL
6194-
ctx.builder.CreateStore(Constant::getNullValue(T), vi.value.V, true);
6193+
AllocaInst *ssaroots = cast<AllocaInst>(vi.value.inline_roots);
6194+
size_t nroots = cast<ConstantInt>(ssaroots->getArraySize())->getZExtValue();
6195+
auto T_prjlvalue = ssaroots->getAllocatedType();
6196+
if (auto AT = dyn_cast<ArrayType>(T_prjlvalue)) {
6197+
nroots *= AT->getNumElements();
6198+
T_prjlvalue = AT->getElementType();
6199+
}
6200+
assert(T_prjlvalue == ctx.types().T_prjlvalue);
6201+
Value *nullval = Constant::getNullValue(T_prjlvalue);
6202+
auto stack_ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack);
6203+
for (size_t i = 0; i < nroots; i++) {
6204+
stack_ai.decorateInst(ctx.builder.CreateAlignedStore(nullval, emit_ptrgep(ctx, ssaroots, i * sizeof(void*)), ssaroots->getAlign(), true));
6205+
}
61956206
}
61966207
}
61976208
}
@@ -9598,15 +9609,17 @@ static jl_llvm_functions_t
95989609

95999610
if (ctx.vaSlot > 0) {
96009611
// remove VA allocation if we never referenced it
9612+
assert(ctx.slots[ctx.vaSlot].isSA && ctx.slots[ctx.vaSlot].isArgument);
96019613
Instruction *root = cast_or_null<Instruction>(ctx.slots[ctx.vaSlot].boxroot);
96029614
if (root) {
9603-
Instruction *store_value = NULL;
96049615
bool have_real_use = false;
96059616
for (Use &U : root->uses()) {
96069617
User *RU = U.getUser();
96079618
if (StoreInst *SRU = dyn_cast<StoreInst>(RU)) {
9608-
if (!store_value)
9609-
store_value = dyn_cast<Instruction>(SRU->getValueOperand());
9619+
assert(isa<ConstantPointerNull>(SRU->getValueOperand()) || SRU->getValueOperand() == restTuple);
9620+
}
9621+
else if (MemSetInst *MSI = dyn_cast<MemSetInst>(RU)) {
9622+
assert(MSI->getValue() == ctx.builder.getInt8(0));
96109623
}
96119624
else if (isa<DbgInfoIntrinsic>(RU)) {
96129625
}
@@ -9628,7 +9641,6 @@ static jl_llvm_functions_t
96289641
if (use)
96299642
use->eraseFromParent();
96309643
root->eraseFromParent();
9631-
assert(!store_value || store_value == restTuple);
96329644
restTuple->eraseFromParent();
96339645
}
96349646
}

test/compiler/codegen.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function f37262(x)
501501
end
502502
end
503503
@testset "#37262" begin
504-
str_opaque = "store volatile { i8, ptr, ptr, ptr, ptr } zeroinitializer, ptr %phic"
504+
str_opaque = "getelementptr inbounds i8, ptr %.roots.phic, i32 16\n store volatile ptr null"
505505
llvmstr = get_llvm(f37262, (Bool,), false, false, false)
506506
@test contains(llvmstr, str_opaque)
507507
@test f37262(Base.inferencebarrier(true)) === nothing

0 commit comments

Comments
 (0)