Closed SingleAccretion closed 3 months ago
@dotnet/nativeaot-llvm
If I understand this, it's a problem only if the pinned local is used by the callee (or filter)? I assume that is hard to determine, if so.
Correct. The filter case makes this tricky, as you can have code like:
static void* s_addr;
void Method() {
pinned ref int pinnedLocal = ref ...;
s_addr = Unsafe.AsPointer(ref pinnedLocal);
Throw(); // Runs a filter that reads 's_addr'.
}
It's not completely hopeless as usually Roslyn zeroes out the pin after fixed
is over, but it would require a bespoke analysis to prove the optimization safe.
Tailcalling risks losing the pin for the callee.
Some regressions, but this is a correctness fix: