@@ -2896,7 +2896,7 @@ static Value *emit_genericmemoryowner(jl_codectx_t &ctx, Value *t)
2896
2896
2897
2897
// --- boxing ---
2898
2898
2899
- static Value *emit_allocobj (jl_codectx_t &ctx, jl_datatype_t *jt);
2899
+ static Value *emit_allocobj (jl_codectx_t &ctx, jl_datatype_t *jt, bool fully_initialized );
2900
2900
2901
2901
static void init_bits_value (jl_codectx_t &ctx, Value *newv, Value *v, MDNode *tbaa,
2902
2902
unsigned alignment = sizeof (void *)) // min alignment in julia's gc is pointer-aligned
@@ -3206,7 +3206,7 @@ static Value *box_union(jl_codectx_t &ctx, const jl_cgval_t &vinfo, const SmallB
3206
3206
jl_cgval_t vinfo_r = jl_cgval_t (vinfo, (jl_value_t *)jt, NULL );
3207
3207
box = _boxed_special (ctx, vinfo_r, t);
3208
3208
if (!box) {
3209
- box = emit_allocobj (ctx, jt);
3209
+ box = emit_allocobj (ctx, jt, true );
3210
3210
setName (ctx.emission_context , box, " unionbox" );
3211
3211
init_bits_cgval (ctx, box, vinfo_r, jl_is_mutable (jt) ? ctx.tbaa ().tbaa_mutab : ctx.tbaa ().tbaa_immut );
3212
3212
}
@@ -3333,7 +3333,7 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool is_promotab
3333
3333
if (do_promote && is_promotable) {
3334
3334
auto IP = ctx.builder .saveIP ();
3335
3335
ctx.builder .SetInsertPoint (vinfo.promotion_point );
3336
- box = emit_allocobj (ctx, (jl_datatype_t *)jt);
3336
+ box = emit_allocobj (ctx, (jl_datatype_t *)jt, true );
3337
3337
Value *decayed = decay_derived (ctx, box);
3338
3338
AllocaInst *originalAlloca = cast<AllocaInst>(vinfo.V );
3339
3339
box->takeName (originalAlloca);
@@ -3349,7 +3349,7 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool is_promotab
3349
3349
auto arg_typename = [&] JL_NOTSAFEPOINT {
3350
3350
return " box::" + std::string (jl_symbol_name (((jl_datatype_t *)(jt))->name ->name ));
3351
3351
};
3352
- box = emit_allocobj (ctx, (jl_datatype_t *)jt);
3352
+ box = emit_allocobj (ctx, (jl_datatype_t *)jt, true );
3353
3353
setName (ctx.emission_context , box, arg_typename);
3354
3354
init_bits_cgval (ctx, box, vinfo, jl_is_mutable (jt) ? ctx.tbaa ().tbaa_mutab : ctx.tbaa ().tbaa_immut );
3355
3355
}
@@ -3478,23 +3478,27 @@ static void emit_cpointercheck(jl_codectx_t &ctx, const jl_cgval_t &x, const Twi
3478
3478
// allocation for known size object
3479
3479
// returns a prjlvalue
3480
3480
static Value *emit_allocobj (jl_codectx_t &ctx, size_t static_size, Value *jt,
3481
- unsigned align= sizeof ( void *)) // Allocations are at least pointer alingned
3481
+ bool fully_initialized, unsigned align)
3482
3482
{
3483
3483
++EmittedAllocObjs;
3484
3484
Value *current_task = get_current_task (ctx);
3485
3485
Function *F = prepare_call (jl_alloc_obj_func);
3486
3486
auto call = ctx.builder .CreateCall (F, {current_task, ConstantInt::get (ctx.types ().T_size , static_size), maybe_decay_untracked (ctx, jt)});
3487
3487
call->setAttributes (F->getAttributes ());
3488
3488
if (static_size > 0 )
3489
- call->addRetAttr (Attribute::getWithDereferenceableBytes (ctx.builder .getContext (), static_size));
3490
- call->addRetAttr (Attribute::getWithAlignment (ctx.builder .getContext (), Align (align)));
3489
+ call->addRetAttr (Attribute::getWithDereferenceableBytes (call->getContext (), static_size));
3490
+ call->addRetAttr (Attribute::getWithAlignment (call->getContext (), Align (align)));
3491
+ #if JL_LLVM_VERSION >= 150000
3492
+ if (fully_initialized)
3493
+ call->addFnAttr (Attribute::get (call->getContext (), Attribute::AllocKind, uint64_t (AllocFnKind::Alloc | AllocFnKind::Uninitialized)));
3494
+ #endif
3491
3495
return call;
3492
3496
}
3493
3497
3494
- static Value *emit_allocobj (jl_codectx_t &ctx, jl_datatype_t *jt)
3498
+ static Value *emit_allocobj (jl_codectx_t &ctx, jl_datatype_t *jt, bool fully_initialized )
3495
3499
{
3496
3500
return emit_allocobj (ctx, jl_datatype_size (jt), ctx.builder .CreateIntToPtr (emit_tagfrom (ctx, jt), ctx.types ().T_pjlvalue ),
3497
- julia_alignment ((jl_value_t *)jt));
3501
+ fully_initialized, julia_alignment ((jl_value_t *)jt));
3498
3502
}
3499
3503
3500
3504
// allocation for unknown object from an untracked pointer
@@ -3716,14 +3720,20 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
3716
3720
strct = NULL ;
3717
3721
}
3718
3722
else if (init_as_value) {
3719
- if (tracked.count )
3723
+ if (tracked.count ) {
3720
3724
strct = Constant::getNullValue (lt);
3721
- else
3725
+ }
3726
+ else {
3722
3727
strct = UndefValue::get (lt);
3728
+ if (nargs < nf)
3729
+ strct = ctx.builder .CreateFreeze (strct);
3730
+ }
3723
3731
}
3724
3732
else {
3725
3733
strct = emit_static_alloca (ctx, lt);
3726
3734
setName (ctx.emission_context , strct, arg_typename);
3735
+ if (nargs < nf)
3736
+ ctx.builder .CreateStore (ctx.builder .CreateFreeze (UndefValue::get (lt)), strct);
3727
3737
if (tracked.count )
3728
3738
undef_derived_strct (ctx, strct, sty, ctx.tbaa ().tbaa_stack );
3729
3739
}
@@ -3893,7 +3903,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
3893
3903
return ret;
3894
3904
}
3895
3905
}
3896
- Value *strct = emit_allocobj (ctx, sty);
3906
+ Value *strct = emit_allocobj (ctx, sty, nargs >= nf );
3897
3907
setName (ctx.emission_context , strct, arg_typename);
3898
3908
jl_cgval_t strctinfo = mark_julia_type (ctx, strct, true , ty);
3899
3909
strct = decay_derived (ctx, strct);
@@ -3926,13 +3936,14 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
3926
3936
return strctinfo;
3927
3937
}
3928
3938
else {
3929
- // 0 fields, ghost or bitstype
3939
+ // 0 fields, ghost or primitive type
3930
3940
if (jl_datatype_nbits (sty) == 0 )
3931
3941
return ghostValue (ctx, sty);
3942
+ // n.b. this is not valid IR form to construct a primitive type (use bitcast for example)
3932
3943
bool isboxed;
3933
3944
Type *lt = julia_type_to_llvm (ctx, ty, &isboxed);
3934
3945
assert (!isboxed);
3935
- return mark_julia_type (ctx, UndefValue::get (lt), false , ty);
3946
+ return mark_julia_type (ctx, ctx. builder . CreateFreeze ( UndefValue::get (lt) ), false , ty);
3936
3947
}
3937
3948
}
3938
3949
0 commit comments