@@ -5217,6 +5217,21 @@ function occurs_outside_getfield(e::ANY, sym::ANY,
52175217 if head === :(= )
52185218 return occurs_outside_getfield (e. args[2 ], sym, sv,
52195219 field_count, field_names)
5220+ elseif head === :foreigncall
5221+ args = e. args
5222+ nccallargs = args[5 ]:: Int
5223+ # Only arguments escape, GC root arguments do not escape.
5224+ for i in 1 : length (args)
5225+ a = args[i]
5226+ if i > 5 + nccallargs && symequal (a, sym)
5227+ # No need to verify indices, uninitialized members can be
5228+ # ignored in root slot.
5229+ continue
5230+ end
5231+ if occurs_outside_getfield (a, sym, sv, field_count, field_names)
5232+ return true
5233+ end
5234+ end
52205235 else
52215236 if (head === :block && isa (sym, Slot) &&
52225237 sv. src. slotflags[slot_id (sym)] & Slot_UsedUndef == 0 )
@@ -5800,8 +5815,11 @@ end
58005815function replace_getfield! (e:: Expr , tupname, vals, field_names, sv:: InferenceState )
58015816 for i = 1 : length (e. args)
58025817 a = e. args[i]
5803- if isa (a,Expr) && is_known_call (a, getfield, sv. src, sv. mod) &&
5804- symequal (a. args[2 ],tupname)
5818+ if ! isa (a, Expr)
5819+ continue
5820+ end
5821+ a = a:: Expr
5822+ if is_known_call (a, getfield, sv. src, sv. mod) && symequal (a. args[2 ], tupname)
58055823 idx = if isa (a. args[3 ], Int)
58065824 a. args[3 ]
58075825 else
@@ -5830,8 +5848,22 @@ function replace_getfield!(e::Expr, tupname, vals, field_names, sv::InferenceSta
58305848 end
58315849 end
58325850 e. args[i] = val
5833- elseif isa (a, Expr)
5834- replace_getfield! (a:: Expr , tupname, vals, field_names, sv)
5851+ else
5852+ if a. head === :foreigncall
5853+ args = a. args
5854+ nccallargs = args[5 ]:: Int
5855+ le = length (args)
5856+ next_i = 6 + nccallargs
5857+ while next_i <= le
5858+ i = next_i
5859+ next_i += 1
5860+
5861+ symequal (args[i], tupname) || continue
5862+ splice! (args, i, vals)
5863+ next_i += length (vals) - 1
5864+ end
5865+ end
5866+ replace_getfield! (a, tupname, vals, field_names, sv)
58355867 end
58365868 end
58375869end
0 commit comments