Skip to content

Commit ba4d77f

Browse files
authored
Fix ref if mixed (#2331)
1 parent 47b65b2 commit ba4d77f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/jlrt.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,18 @@ function val_from_byref_if_mixed(B::LLVM.IRBuilder, gutils::GradientUtils, @nosp
366366
end
367367
end
368368

369-
function ref_if_mixed(val::VT) where {VT}
370-
if active_reg_inner(Core.Typeof(val), (), nothing, Val(true)) == ActiveState
371-
return Ref(val)
369+
@generated function ref_if_mixed(val::VT) where VT
370+
areg = active_reg_inner(VT, (), nothing, Val(true))
371+
if areg == ActiveState || areg == MixedState
372+
quote
373+
Base.@_inline_meta
374+
Ref(val)
375+
end
372376
else
373-
return val
377+
quote
378+
Base.@_inline_meta
379+
val
380+
end
374381
end
375382
end
376383

@@ -380,15 +387,13 @@ function byref_from_val_if_mixed(B::LLVM.IRBuilder, @nospecialize(val::LLVM.Valu
380387
if !legal
381388
legal, TT, _ = abs_typeof(val, true)
382389
act = active_reg_inner(TT, (), world)
383-
if act == AnyState
390+
if legal && act == AnyState
384391
return val
385392
end
386-
if !legal
387-
return emit_apply_generic!(B, [unsafe_to_llvm(B, ref_if_mixed), val])
388-
end
393+
return emit_apply_generic!(B, LLVM.Value[unsafe_to_llvm(B, ref_if_mixed), val])
389394
end
390395
act = active_reg_inner(TT, (), world)
391-
396+
392397
if act == ActiveState || act == MixedState
393398
obj = emit_allocobj!(B, Base.RefValue{TT})
394399
lty = convert(LLVMType, TT)

0 commit comments

Comments
 (0)