Skip to content

Commit 6411e26

Browse files
KenoKristofferC
authored andcommitted
Fix typo in codegen for isdefinedglobal (#57889)
Fixes #57872 (cherry picked from commit 400d0b1)
1 parent 5ae693e commit 6411e26

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Compiler/test/codegen.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,3 +1027,8 @@ module TurnedIntoExplicit
10271027

10281028
@test !occursin("jl_apply_generic", get_llvm(f, Tuple{UInt}))
10291029
end
1030+
1031+
# Test codegen for `isdefinedglobal` of constant (#57872)
1032+
const x57872 = "Hello"
1033+
f57872() = (Core.isdefinedglobal(@__MODULE__, Base.compilerbarrier(:const, :x57872)), x57872) # Extra globalref here to force world age bounds
1034+
@test f57872() == (true, "Hello")

src/codegen.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,30 +3824,29 @@ static bool emit_f_opfield(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
38243824

38253825
static jl_cgval_t emit_isdefinedglobal(jl_codectx_t &ctx, jl_module_t *modu, jl_sym_t *name, int allow_import, enum jl_memory_order order)
38263826
{
3827-
Value *isnull = NULL;
38283827
jl_binding_t *bnd = allow_import ? jl_get_binding(modu, name) : jl_get_module_binding(modu, name, 0);
38293828
struct restriction_kind_pair rkp = { NULL, NULL, PARTITION_KIND_GUARD, 0 };
38303829
if (allow_import && jl_get_binding_leaf_partitions_restriction_kind(bnd, &rkp, ctx.min_world, ctx.max_world)) {
3831-
if (jl_bkind_is_some_constant(rkp.kind))
3832-
return mark_julia_const(ctx, rkp.restriction);
3830+
if (jl_bkind_is_some_constant(rkp.kind) && rkp.restriction)
3831+
return mark_julia_const(ctx, jl_true);
38333832
if (rkp.kind == PARTITION_KIND_GLOBAL) {
38343833
Value *bp = julia_binding_gv(ctx, rkp.binding_if_global);
38353834
bp = julia_binding_pvalue(ctx, bp);
38363835
LoadInst *v = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, bp, Align(sizeof(void*)));
38373836
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_binding);
38383837
ai.decorateInst(v);
38393838
v->setOrdering(get_llvm_atomic_order(order));
3840-
isnull = ctx.builder.CreateICmpNE(v, Constant::getNullValue(ctx.types().T_prjlvalue));
3839+
Value *isnull = ctx.builder.CreateICmpNE(v, Constant::getNullValue(ctx.types().T_prjlvalue));
38413840
return mark_julia_type(ctx, isnull, false, jl_bool_type);
38423841
}
38433842
}
3844-
Value *v = ctx.builder.CreateCall(prepare_call(jlboundp_func), {
3843+
Value *isdef = ctx.builder.CreateCall(prepare_call(jlboundp_func), {
38453844
literal_pointer_val(ctx, (jl_value_t*)modu),
38463845
literal_pointer_val(ctx, (jl_value_t*)name),
38473846
ConstantInt::get(getInt32Ty(ctx.builder.getContext()), allow_import)
38483847
});
3849-
isnull = ctx.builder.CreateICmpNE(v, ConstantInt::get(getInt32Ty(ctx.builder.getContext()), 0));
3850-
return mark_julia_type(ctx, isnull, false, jl_bool_type);
3848+
isdef = ctx.builder.CreateTrunc(isdef, getInt1Ty(ctx.builder.getContext()));
3849+
return mark_julia_type(ctx, isdef, false, jl_bool_type);
38513850
}
38523851

38533852
static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,

0 commit comments

Comments
 (0)