@@ -1726,17 +1726,24 @@ static Value *emit_array_nd_index(const jl_cgval_t &ainfo, jl_value_t *ex, ssize
1726
1726
// the accessed array, i.e. `if !(i < alen) goto error`.
1727
1727
if (nidxs > 1 ) {
1728
1728
// TODO: REMOVE DEPWARN AND RETURN FALSE AFTER 0.6.
1729
- // We need to check if this is inside the non-linearized size
1729
+ // We need to check if this index is inside its non-linearized dimension
1730
1730
BasicBlock *partidx = BasicBlock::Create (jl_LLVMContext, " partlinidx" );
1731
1731
BasicBlock *partidxwarn = BasicBlock::Create (jl_LLVMContext, " partlinidxwarn" );
1732
+ BasicBlock *trailingcheck = BasicBlock::Create (jl_LLVMContext, " trailingcheck" );
1732
1733
Value *d = emit_arraysize_for_unsafe_dim (ainfo, ex, nidxs, nd, ctx);
1733
- builder.CreateCondBr (builder.CreateICmpULT (ii, d), endBB, partidx);
1734
+ Value *alen = emit_arraylen (ainfo, ex, ctx);
1735
+ builder.CreateCondBr (builder.CreateICmpULT (ii, d), trailingcheck, partidx);
1736
+
1737
+ // If it is inside its own dimension, we still need to ensure all other
1738
+ // dimensions are non-zero
1739
+ ctx->f ->getBasicBlockList ().push_back (trailingcheck);
1740
+ builder.SetInsertPoint (trailingcheck);
1741
+ builder.CreateCondBr (builder.CreateICmpULT (ii, alen), endBB, failBB);
1734
1742
1735
1743
// We failed the normal bounds check; check to see if we're
1736
1744
// inside the linearized size (partial linear indexing):
1737
1745
ctx->f ->getBasicBlockList ().push_back (partidx);
1738
1746
builder.SetInsertPoint (partidx);
1739
- Value *alen = emit_arraylen (ainfo, ex, ctx);
1740
1747
builder.CreateCondBr (builder.CreateICmpULT (i, alen), partidxwarn, failBB);
1741
1748
1742
1749
// We passed the linearized bounds check; now throw the depwarn:
0 commit comments