Skip to content

Commit 5118121

Browse files
authored
fix #37671, bug in isa Union check (#37762)
1 parent c4d1cd9 commit 5118121

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/cgutils.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,14 +1122,17 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
11221122
jl_value_t *type, const std::string *msg);
11231123

11241124
static void emit_isa_union(jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type,
1125-
SmallVectorImpl<std::pair<BasicBlock*,Value*>> &bbs)
1125+
SmallVectorImpl<std::pair<std::pair<BasicBlock*,BasicBlock*>,Value*>> &bbs)
11261126
{
11271127
if (jl_is_uniontype(type)) {
11281128
emit_isa_union(ctx, x, ((jl_uniontype_t*)type)->a, bbs);
11291129
emit_isa_union(ctx, x, ((jl_uniontype_t*)type)->b, bbs);
11301130
return;
11311131
}
1132-
bbs.emplace_back(ctx.builder.GetInsertBlock(), emit_isa(ctx, x, type, nullptr).first);
1132+
BasicBlock *enter = ctx.builder.GetInsertBlock();
1133+
Value *v = emit_isa(ctx, x, type, nullptr).first;
1134+
BasicBlock *exit = ctx.builder.GetInsertBlock();
1135+
bbs.emplace_back(std::make_pair(enter, exit), v);
11331136
BasicBlock *isaBB = BasicBlock::Create(jl_LLVMContext, "isa", ctx.f);
11341137
ctx.builder.SetInsertPoint(isaBB);
11351138
}
@@ -1231,16 +1234,16 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
12311234
}
12321235
if (jl_is_uniontype(intersected_type) &&
12331236
can_optimize_isa_union((jl_uniontype_t*)intersected_type)) {
1234-
SmallVector<std::pair<BasicBlock*,Value*>,4> bbs;
1237+
SmallVector<std::pair<std::pair<BasicBlock*,BasicBlock*>,Value*>,4> bbs;
12351238
emit_isa_union(ctx, x, intersected_type, bbs);
12361239
int nbbs = bbs.size();
12371240
BasicBlock *currBB = ctx.builder.GetInsertBlock();
12381241
PHINode *res = ctx.builder.CreatePHI(T_int1, nbbs);
12391242
for (int i = 0; i < nbbs; i++) {
1240-
auto bb = bbs[i].first;
1243+
auto bb = bbs[i].first.second;
12411244
ctx.builder.SetInsertPoint(bb);
12421245
if (i + 1 < nbbs) {
1243-
ctx.builder.CreateCondBr(bbs[i].second, currBB, bbs[i + 1].first);
1246+
ctx.builder.CreateCondBr(bbs[i].second, currBB, bbs[i + 1].first.first);
12441247
res->addIncoming(ConstantInt::get(T_int1, 1), bb);
12451248
}
12461249
else {

test/compiler/codegen.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,9 @@ end
473473
@test contains(llvmstr, str) || llvmstr
474474
@test f37262(Base.inferencebarrier(true)) === nothing
475475
end
476+
477+
# issue #37671
478+
let d = Dict((:a,) => 1, (:a, :b) => 2)
479+
@test d[(:a,)] == 1
480+
@test d[(:a, :b)] == 2
481+
end

0 commit comments

Comments
 (0)