@@ -4672,6 +4672,45 @@ static jl_cgval_t _emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &mem, cons
4672
4672
return _emit_memoryref (ctx, boxed (ctx, mem), data, layout, typ);
4673
4673
}
4674
4674
4675
+ static jl_cgval_t emit_memoryref_direct (jl_codectx_t &ctx, const jl_cgval_t &mem, jl_cgval_t idx, jl_value_t *typ, jl_value_t *inbounds, const jl_datatype_layout_t *layout)
4676
+ {
4677
+ bool isboxed = layout->flags .arrayelem_isboxed ;
4678
+ bool isunion = layout->flags .arrayelem_isunion ;
4679
+ bool isghost = layout->size == 0 ;
4680
+ Value *boxmem = boxed (ctx, mem);
4681
+ Value *i = emit_unbox (ctx, ctx.types ().T_size , idx, (jl_value_t *)jl_long_type);
4682
+ Value *idx0 = ctx.builder .CreateSub (i, ConstantInt::get (ctx.types ().T_size , 1 ));
4683
+ bool bc = bounds_check_enabled (ctx, inbounds);
4684
+ if (bc) {
4685
+ BasicBlock *failBB, *endBB;
4686
+ failBB = BasicBlock::Create (ctx.builder .getContext (), " oob" );
4687
+ endBB = BasicBlock::Create (ctx.builder .getContext (), " idxend" );
4688
+ Value *mlen = emit_genericmemorylen (ctx, boxmem, typ);
4689
+ Value *inbound = ctx.builder .CreateICmpULT (idx0, mlen);
4690
+ setName (ctx.emission_context , inbound, " memoryref_isinbounds" );
4691
+ ctx.builder .CreateCondBr (inbound, endBB, failBB);
4692
+ failBB->insertInto (ctx.f );
4693
+ ctx.builder .SetInsertPoint (failBB);
4694
+ ctx.builder .CreateCall (prepare_call (jlboundserror_func),
4695
+ { mark_callee_rooted (ctx, boxmem), i });
4696
+ ctx.builder .CreateUnreachable ();
4697
+ endBB->insertInto (ctx.f );
4698
+ ctx.builder .SetInsertPoint (endBB);
4699
+ }
4700
+ Value *data;
4701
+
4702
+ if ((!isboxed && isunion) || isghost) {
4703
+ data = idx0;
4704
+
4705
+ } else {
4706
+ data = emit_genericmemoryptr (ctx, boxmem, layout, 0 );
4707
+ Type *elty = isboxed ? ctx.types ().T_prjlvalue : julia_type_to_llvm (ctx, jl_tparam1 (typ));
4708
+ data = ctx.builder .CreateInBoundsGEP (elty, data, idx0);
4709
+ }
4710
+
4711
+ return _emit_memoryref (ctx, boxmem, data, layout, typ);
4712
+ }
4713
+
4675
4714
static Value *emit_memoryref_FCA (jl_codectx_t &ctx, const jl_cgval_t &ref, const jl_datatype_layout_t *layout)
4676
4715
{
4677
4716
if (!ref.inline_roots .empty ()) {
0 commit comments