for (GenTreeCall::Use& argUse : GenTreeCall::UseList(args))
{
- // We should not be passing gc typed args to an unmanaged call.
GenTree* arg = argUse.GetNode();
+ call->gtFlags |= arg->gtFlags & GTF_GLOB_EFFECT;
+
+ // We should not be passing gc typed args to an unmanaged call.
if (varTypeIsGC(arg->TypeGet()))
{
- assert(!"*** invalid IL: gc type passed to unmanaged call");
+ // Tolerate byrefs by retyping to native int.
+ //
+ // This is needed or we'll generate inconsistent GC info
+ // for this arg at the call site (gc info says byref,
+ // pinvoke sig says native int).
+ //
+ if (arg->TypeGet() == TYP_BYREF)
+ {
+ arg->ChangeType(TYP_I_IMPL);
+ }
+ else
+ {
+ assert(!"*** invalid IL: gc ref passed to unmanaged call");
+ }
}
-
- call->gtFlags |= arg->gtFlags & GTF_GLOB_EFFECT;
}
}