Skip to content

Commit

Permalink
Properly rename EnterNode scope after code coverage insertion (#52720)
Browse files Browse the repository at this point in the history
Fixes #52672 and changes the emission path to move the error to the
point of corruption instead of the point of first use.
  • Loading branch information
Keno authored Jan 5, 2024
1 parent 38b8156 commit 31a9f13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,11 @@ function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int}, lab
@assert !isdefined(el, :scope)
body[i] = nothing
else
body[i] = EnterNode(el, tgt + labelchangemap[tgt])
if isdefined(el, :scope) && isa(el.scope, SSAValue)
body[i] = EnterNode(tgt + labelchangemap[tgt], SSAValue(el.scope.id + ssachangemap[el.scope.id]))
else
body[i] = EnterNode(el, tgt + labelchangemap[tgt])
end
end
end
elseif isa(el, Expr)
Expand Down
8 changes: 8 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8765,6 +8765,14 @@ static jl_llvm_functions_t
jl_aliasinfo_t scope_ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_gcframe);
if (jl_enternode_scope(stmt)) {
jl_cgval_t new_scope = emit_expr(ctx, jl_enternode_scope(stmt));
if (new_scope.typ == jl_bottom_type) {
// Probably dead code, but let's be loud about it in case it isn't, so we fail
// at the point of the miscompile, rather than later when something attempts to
// read the scope.
emit_error(ctx, "(INTERNAL ERROR): Attempted to execute EnterNode with bad scope");
find_next_stmt(-1);
continue;
}
Value *new_scope_boxed = boxed(ctx, new_scope);
scope_ptr = get_scope_field(ctx);
old_scope = scope_ai.decorateInst(
Expand Down

0 comments on commit 31a9f13

Please sign in to comment.