Skip to content

Commit 31a9f13

Browse files
authored
Properly rename EnterNode scope after code coverage insertion (#52720)
Fixes #52672 and changes the emission path to move the error to the point of corruption instead of the point of first use.
1 parent 38b8156 commit 31a9f13

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/compiler/optimize.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,11 @@ function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int}, lab
13791379
@assert !isdefined(el, :scope)
13801380
body[i] = nothing
13811381
else
1382-
body[i] = EnterNode(el, tgt + labelchangemap[tgt])
1382+
if isdefined(el, :scope) && isa(el.scope, SSAValue)
1383+
body[i] = EnterNode(tgt + labelchangemap[tgt], SSAValue(el.scope.id + ssachangemap[el.scope.id]))
1384+
else
1385+
body[i] = EnterNode(el, tgt + labelchangemap[tgt])
1386+
end
13831387
end
13841388
end
13851389
elseif isa(el, Expr)

src/codegen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8765,6 +8765,14 @@ static jl_llvm_functions_t
87658765
jl_aliasinfo_t scope_ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_gcframe);
87668766
if (jl_enternode_scope(stmt)) {
87678767
jl_cgval_t new_scope = emit_expr(ctx, jl_enternode_scope(stmt));
8768+
if (new_scope.typ == jl_bottom_type) {
8769+
// Probably dead code, but let's be loud about it in case it isn't, so we fail
8770+
// at the point of the miscompile, rather than later when something attempts to
8771+
// read the scope.
8772+
emit_error(ctx, "(INTERNAL ERROR): Attempted to execute EnterNode with bad scope");
8773+
find_next_stmt(-1);
8774+
continue;
8775+
}
87688776
Value *new_scope_boxed = boxed(ctx, new_scope);
87698777
scope_ptr = get_scope_field(ctx);
87708778
old_scope = scope_ai.decorateInst(

0 commit comments

Comments
 (0)