Skip to content

Commit

Permalink
fix #37671, bug in isa Union check
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 25, 2020
1 parent d7b391d commit 985a6b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,14 +1122,18 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
jl_value_t *type, const std::string *msg);

static void emit_isa_union(jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type,
SmallVectorImpl<std::pair<BasicBlock*,Value*>> &bbs)
SmallVectorImpl<std::pair<std::pair<BasicBlock*,BasicBlock*>,Value*>> &bbs)
{
if (jl_is_uniontype(type)) {
emit_isa_union(ctx, x, ((jl_uniontype_t*)type)->a, bbs);
emit_isa_union(ctx, x, ((jl_uniontype_t*)type)->b, bbs);
return;
}
bbs.emplace_back(ctx.builder.GetInsertBlock(), emit_isa(ctx, x, type, nullptr).first);
BasicBlock *enter = ctx.builder.GetInsertBlock();
Value *v = emit_isa(ctx, x, type, nullptr).first;
BasicBlock *exit = ctx.builder.GetInsertBlock();
std::pair<BasicBlock*,BasicBlock*> blocks(enter, exit);
bbs.emplace_back(blocks, v);
BasicBlock *isaBB = BasicBlock::Create(jl_LLVMContext, "isa", ctx.f);
ctx.builder.SetInsertPoint(isaBB);
}
Expand Down Expand Up @@ -1231,16 +1235,16 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
}
if (jl_is_uniontype(intersected_type) &&
can_optimize_isa_union((jl_uniontype_t*)intersected_type)) {
SmallVector<std::pair<BasicBlock*,Value*>,4> bbs;
SmallVector<std::pair<std::pair<BasicBlock*,BasicBlock*>,Value*>,4> bbs;
emit_isa_union(ctx, x, intersected_type, bbs);
int nbbs = bbs.size();
BasicBlock *currBB = ctx.builder.GetInsertBlock();
PHINode *res = ctx.builder.CreatePHI(T_int1, nbbs);
for (int i = 0; i < nbbs; i++) {
auto bb = bbs[i].first;
auto bb = bbs[i].first.second;
ctx.builder.SetInsertPoint(bb);
if (i + 1 < nbbs) {
ctx.builder.CreateCondBr(bbs[i].second, currBB, bbs[i + 1].first);
ctx.builder.CreateCondBr(bbs[i].second, currBB, bbs[i + 1].first.first);
res->addIncoming(ConstantInt::get(T_int1, 1), bb);
}
else {
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,9 @@ end
@test contains(llvmstr, str) || llvmstr
@test f37262(Base.inferencebarrier(true)) === nothing
end

# issue #37671
let d = Dict((:a,) => 1, (:a, :b) => 2)
@test d[(:a,)] == 1
@test d[(:a, :b)] == 2
end

0 comments on commit 985a6b8

Please sign in to comment.