Skip to content

Commit ec3ec02

Browse files
authored
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.
1 parent b71330d commit ec3ec02

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
@@ -6424,8 +6424,11 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
64246424
Type *vtype = julia_type_to_llvm(ctx, jt, &isboxed);
64256425
assert(!isboxed);
64266426
assert(!type_is_ghost(vtype) && "constants should already be handled");
6427-
// CreateAlloca is OK during prologue setup
6428-
Value *lv = ctx.builder.CreateAlloca(vtype, NULL, jl_symbol_name(s));
6427+
Value *lv = new AllocaInst(vtype, 0, jl_symbol_name(s), /*InsertBefore*/ctx.pgcstack);
6428+
if (CountTrackedPointers(vtype).count) {
6429+
StoreInst *SI = new StoreInst(Constant::getNullValue(vtype), lv, false, Align(sizeof(void*)));
6430+
SI->insertAfter(ctx.pgcstack);
6431+
}
64296432
varinfo.value = mark_julia_slot(lv, jt, NULL, tbaa_stack);
64306433
alloc_def_flag(ctx, varinfo);
64316434
if (ctx.debug_enabled && varinfo.dinfo) {

0 commit comments

Comments
 (0)