Skip to content

Commit

Permalink
Fix a regression in the test for #13432 (#55004)
Browse files Browse the repository at this point in the history
The test for #13432 is supposed to test a particular codegen path
involving Bottom. It turns out that this code path is regressed on
master, but hidden by the fact that in modern julia, the optimizer can
fold this code path early. Fix the bug and add a variant of the test
that shows the issue on julia master. Note that this is both an
assertion failure and incorrect codegen. This PR addresses both.
  • Loading branch information
Keno authored Jul 5, 2024
1 parent a5f0016 commit 5468a3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ static bool can_optimize_isa_union(jl_uniontype_t *type)
// a simple case of emit_isa that is obvious not to include a safe-point
static Value *emit_exactly_isa(jl_codectx_t &ctx, const jl_cgval_t &arg, jl_datatype_t *dt, bool could_be_null=false)
{
assert(jl_is_concrete_type((jl_value_t*)dt));
assert(jl_is_concrete_type((jl_value_t*)dt) || is_uniquerep_Type((jl_value_t*)dt));
if (arg.TIndex) {
unsigned tindex = get_box_tindex(dt, arg.typ);
if (tindex > 0) {
Expand All @@ -1621,7 +1621,12 @@ static Value *emit_exactly_isa(jl_codectx_t &ctx, const jl_cgval_t &arg, jl_data
BasicBlock *postBB = BasicBlock::Create(ctx.builder.getContext(), "post_isa", ctx.f);
ctx.builder.CreateCondBr(isboxed, isaBB, postBB);
ctx.builder.SetInsertPoint(isaBB);
Value *istype_boxed = ctx.builder.CreateICmpEQ(emit_typeof(ctx, arg.Vboxed, false, true), emit_tagfrom(ctx, dt));
Value *istype_boxed = NULL;
if (is_uniquerep_Type((jl_value_t*)dt)) {
istype_boxed = ctx.builder.CreateICmpEQ(decay_derived(ctx, arg.Vboxed), decay_derived(ctx, literal_pointer_val(ctx, jl_tparam0(dt))));
} else {
istype_boxed = ctx.builder.CreateICmpEQ(emit_typeof(ctx, arg.Vboxed, false, true), emit_tagfrom(ctx, dt));
}
ctx.builder.CreateBr(postBB);
isaBB = ctx.builder.GetInsertBlock(); // could have changed
ctx.builder.SetInsertPoint(postBB);
Expand Down
8 changes: 8 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,14 @@ end
end
@test f13432b(true) == true
@test f13432b(false) == false
@noinline function f13432c(x)
offset = x ? Base.Bottom : 1
# Barrier for inference, so the optimizer cannot optimize this,
# but codegen can still see this is a constant
return ===(offset, Base.inferencebarrier(Base.Bottom))
end
@test f13432c(true) == true
@test f13432c(false) == false

#13433, read!(::IO, a::Vector{UInt8}) should return a
mutable struct IO13433 <: IO end
Expand Down

0 comments on commit 5468a3e

Please sign in to comment.