The compiler is lifting the local ```bytesRead``` into a field on the async state machine, even though its value need not be preserved across any await.
Commit migrated from https://github.com/dotnet/coreclr/commit/
6f399b187eb286b2b682fe9efaad531495770638
Contract.Requires(destination.CanWrite);
byte[] buffer = new byte[bufferSize];
- int bytesRead;
- while ((bytesRead = await ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
+ while (true)
{
+ int bytesRead = await ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
+ if (bytesRead == 0) break;
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
}
}