Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 14, 2024
1 parent 5212db7 commit 68cda2e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,7 @@ static void recombine_value(jl_codectx_t &ctx, const jl_cgval_t &x, Value *dst,
{
jl_datatype_t *typ = (jl_datatype_t*)x.typ;
assert(jl_is_concrete_type(x.typ));
bool hasptr = typ->layout->first_ptr >= 0;
assert(hasptr && x.inline_roots != nullptr);
assert(typ->layout->first_ptr >= 0 && x.inline_roots != nullptr);
Align align_dst = alignment;
Align align_src(1); // TODO: compute this (and keep aligned)
Value *src = x.V;
Expand Down Expand Up @@ -4201,7 +4200,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
32 changes: 23 additions & 9 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6190,11 +6190,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 @@ -8421,7 +8432,7 @@ static jl_llvm_functions_t

// step 7. allocate local variables slots
// must be in the first basic block for the llvm mem2reg pass to work
auto allocate_local = [&ctx, &dbuilder, &debugcache, topdebugloc, va, debug_enabled, M](jl_varinfo_t &varinfo, jl_sym_t *s, int i) {
auto allocate_local = [&ctx, &dbuilder, &debugcache, topdebugloc, va, debug_enabled](jl_varinfo_t &varinfo, jl_sym_t *s, int i) {
jl_value_t *jt = varinfo.value.typ;
assert(!varinfo.boxroot); // variables shouldn't have memory locs already
if (varinfo.value.constant) {
Expand Down Expand Up @@ -9601,15 +9612,19 @@ 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);
(void)SRU;
}
else if (MemSetInst *MSI = dyn_cast<MemSetInst>(RU)) {
assert(MSI->getValue() == ctx.builder.getInt8(0));
(void)MSI;
}
else if (isa<DbgInfoIntrinsic>(RU)) {
}
Expand All @@ -9631,7 +9646,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 68cda2e

Please sign in to comment.