Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 13, 2024
1 parent 76a6156 commit e3f5ea0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
28 changes: 20 additions & 8 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AllocaInst>(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<AllocaInst>(vi.value.inline_roots);
size_t nroots = cast<ConstantInt>(ssaroots->getArraySize())->getZExtValue();
auto T_prjlvalue = ssaroots->getAllocatedType();
if (auto AT = dyn_cast<ArrayType>(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));
}
}
}
}
Expand Down Expand Up @@ -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<Instruction>(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<StoreInst>(RU)) {
if (!store_value)
store_value = dyn_cast<Instruction>(SRU->getValueOperand());
assert(isa<ConstantPointerNull>(SRU->getValueOperand()) || SRU->getValueOperand() == restTuple);
}
else if (MemSetInst *MSI = dyn_cast<MemSetInst>(RU)) {
assert(MSI->getValue() == ctx.builder.getInt8(0));
}
else if (isa<DbgInfoIntrinsic>(RU)) {
}
Expand All @@ -9628,7 +9641,6 @@ static jl_llvm_functions_t
if (use)
use->eraseFromParent();
root->eraseFromParent();
assert(!store_value || store_value == restTuple);
restTuple->eraseFromParent();
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3f5ea0

Please sign in to comment.