Skip to content

Commit

Permalink
fix crash when interpreting optimized top-level expressions (#29217)
Browse files Browse the repository at this point in the history
(cherry picked from commit 493068b)
  • Loading branch information
JeffBezanson authored and KristofferC committed Feb 11, 2019
1 parent 65cb309 commit a3cd674
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,25 @@ SECT_INTERP CALLBACK_ABI void *jl_interpret_call_callback(interpreter_state *s,
locals[0] = (jl_value_t*)src;
locals[1] = (jl_value_t*)stmts;
s->src = src;
s->module = args->lam->def.method->module;
size_t nargs;
int isva;
if (jl_is_module(args->lam->def.value)) {
s->module = args->lam->def.module;
nargs = 0;
isva = 0;
}
else {
s->module = args->lam->def.method->module;
nargs = args->lam->def.method->nargs;
isva = args->lam->def.method->isva;
}
s->locals = locals + 2;
s->sparam_vals = args->lam->sparam_vals;
s->continue_at = 0;
s->mi = args->lam;
size_t i;
for (i = 0; i < args->lam->def.method->nargs; i++) {
if (args->lam->def.method->isva && i == args->lam->def.method->nargs - 1)
for (i = 0; i < nargs; i++) {
if (isva && i == nargs - 1)
s->locals[i] = jl_f_tuple(NULL, &args->args[i], args->nargs - i);
else
s->locals[i] = args->args[i];
Expand Down
16 changes: 16 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6711,6 +6711,22 @@ struct T29145{A,B}
end
@test_throws TypeError T29145()

# interpreted but inferred/optimized top-level expressions with vars
let code = """
while true
try
this_is_undefined_29213
ed = 0
break
finally
break
end
end
print(42)
"""
@test read(`$(Base.julia_cmd()) --startup-file=no --compile=min -e $code`, String) == "42"
end

# issue #29175
function f29175(tuple::T) where {T<:Tuple}
prefix::Tuple{T.parameters[1:end-1]...} = tuple[1:length(T.parameters)-1]
Expand Down

0 comments on commit a3cd674

Please sign in to comment.