Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codegen for getfield of homogeneous tuples #34208

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2892,20 +2892,22 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
jl_value_t *jt = jl_tparam0(utt);
if (jl_is_vararg_type(jt))
jt = jl_unwrap_vararg(jt);
Value *vidx = emit_unbox(ctx, T_size, fld, (jl_value_t*)jl_long_type);
// This is not necessary for correctness, but allows to omit
// the extra code for getting the length of the tuple
jl_value_t *boundscheck = (nargs == 3 ? argv[3].constant : jl_true);
if (!bounds_check_enabled(ctx, boundscheck)) {
vidx = ctx.builder.CreateSub(vidx, ConstantInt::get(T_size, 1));
} else {
vidx = emit_bounds_check(ctx, obj, (jl_value_t*)obj.typ, vidx,
emit_datatype_nfields(ctx, emit_typeof_boxed(ctx, obj)),
jl_true);
if (jl_is_datatype(jt) && ((jl_datatype_t*)jt)->isinlinealloc) {
Value *vidx = emit_unbox(ctx, T_size, fld, (jl_value_t*)jl_long_type);
// This is not necessary for correctness, but allows to omit
// the extra code for getting the length of the tuple
jl_value_t *boundscheck = (nargs == 3 ? argv[3].constant : jl_true);
if (!bounds_check_enabled(ctx, boundscheck)) {
vidx = ctx.builder.CreateSub(vidx, ConstantInt::get(T_size, 1));
} else {
vidx = emit_bounds_check(ctx, obj, (jl_value_t*)obj.typ, vidx,
emit_datatype_nfields(ctx, emit_typeof_boxed(ctx, obj)),
jl_true);
}
Value *ptr = maybe_decay_tracked(data_pointer(ctx, obj));
*ret = typed_load(ctx, ptr, vidx, jt, obj.tbaa, nullptr, false);
return true;
}
Value *ptr = maybe_decay_tracked(data_pointer(ctx, obj));
*ret = typed_load(ctx, ptr, vidx, jt, obj.tbaa, nullptr, false);
return true;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7140,3 +7140,10 @@ end
struct SplatBadIterate; end
Base.iterate(s::SplatBadIterate, args...) = ()
@test_throws BoundsError (SplatBadIterate()...,)

# Issue #34206/34207
function mre34206(a)
b = ntuple(_ -> view(a, :), 1)[1]
b.offset1
end
@test mre34206([44]) == 0