Skip to content

Commit

Permalink
codegen was over-aggressively eliding the first argument to isa
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 13, 2015
1 parent 53978e7 commit d2f6ce5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,12 +2518,14 @@ static bool emit_known_call(jl_cgval_t *ret, jl_value_t *ff,
if (jl_is_type_type(ty) && !jl_has_typevars(jl_tparam0(ty))) {
jl_value_t *tp0 = jl_tparam0(ty);
if (jl_subtype(arg, tp0, 0)) {
emit_expr(args[1], ctx); // TODO remove if no side effects
*ret = mark_julia_type(ConstantInt::get(T_int1, 1), false, jl_bool_type);
JL_GC_POP();
return true;
}
if (!jl_subtype(tp0, (jl_value_t*)jl_type_type, 0)) {
if (jl_is_leaf_type(arg)) {
emit_expr(args[1], ctx); // TODO remove if no side effects
*ret = mark_julia_type(ConstantInt::get(T_int1, 0), false, jl_bool_type);
JL_GC_POP();
return true;
Expand Down
9 changes: 9 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3577,3 +3577,12 @@ gc()
g()

end

# make sure codegen doesn't remove argument to `isa`
@noinline __g_isa_test_1(a) = push!(a,1)
function __f_isa_arg_1()
a = []
isa(__g_isa_test_1(a), Any)
length(a)
end
@test __f_isa_arg_1() == 1

0 comments on commit d2f6ce5

Please sign in to comment.