From 5695c2df45b9d8d00e7c07197b200a4a54a924e6 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 2 Mar 2021 20:05:07 -0500 Subject: [PATCH] Canonicalize IR to disallow mutable GlobalRef in value position (#39893) Generally we assume parameters can be duplicated without seeing side-effects. That is not entirely true of mutable globals and multi-threading. Refs: #36450 Fixes: #39508 --- base/compiler/ssair/slot2ssa.jl | 2 +- base/compiler/ssair/verify.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/compiler/ssair/slot2ssa.jl b/base/compiler/ssair/slot2ssa.jl index cc3835897141d..66ed9e8a32e6a 100644 --- a/base/compiler/ssair/slot2ssa.jl +++ b/base/compiler/ssair/slot2ssa.jl @@ -162,7 +162,7 @@ function fixemup!(cond, rename, ir::IRCode, ci::CodeInfo, idx::Int, @nospecializ return nothing end op[] = x - elseif isa(val, GlobalRef) && !isdefined(val.mod, val.name) + elseif isa(val, GlobalRef) && !(isdefined(val.mod, val.name) && isconst(val.mod, val.name)) op[] = NewSSAValue(insert_node!(ir, idx, Any, val).id - length(ir.stmts)) end end diff --git a/base/compiler/ssair/verify.jl b/base/compiler/ssair/verify.jl index 0f29b79b417e6..6c2953c12c505 100644 --- a/base/compiler/ssair/verify.jl +++ b/base/compiler/ssair/verify.jl @@ -36,7 +36,7 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int, end end elseif isa(op, GlobalRef) - if !isdefined(op.mod, op.name) + if !isdefined(op.mod, op.name) || !isconst(op.mod, op.name) @verify_error "Unbound GlobalRef not allowed in value position" error("") end