Skip to content

Commit 976a79e

Browse files
vtjnashKristofferC
authored andcommitted
codegen: add missing initialization for PhiC nodes (#43029)
Our Phi handling assumes that it can references undefined memory, and get back legal results, but our PhiC nodes were not initialized, so the Phi node might see uninitialized results, and then cause the GC to crash. This was observed in PkgEval on the PoreMatMod.jl package to occur in recent Julia versions and master. (cherry picked from commit ec3ec02)
1 parent 5adcb4b commit 976a79e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/codegen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,8 +6634,11 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
66346634
Type *vtype = julia_type_to_llvm(ctx, jt, &isboxed);
66356635
assert(!isboxed);
66366636
assert(!type_is_ghost(vtype) && "constants should already be handled");
6637-
// CreateAlloca is OK during prologue setup
6638-
Value *lv = ctx.builder.CreateAlloca(vtype, NULL, jl_symbol_name(s));
6637+
Value *lv = new AllocaInst(vtype, 0, jl_symbol_name(s), /*InsertBefore*/ctx.pgcstack);
6638+
if (CountTrackedPointers(vtype).count) {
6639+
StoreInst *SI = new StoreInst(Constant::getNullValue(vtype), lv, false, Align(sizeof(void*)));
6640+
SI->insertAfter(ctx.pgcstack);
6641+
}
66396642
varinfo.value = mark_julia_slot(lv, jt, NULL, tbaa_stack);
66406643
alloc_def_flag(ctx, varinfo);
66416644
if (ctx.debug_enabled && varinfo.dinfo) {

0 commit comments

Comments
 (0)