とRyuJIT C#の間違った和結果私は、コードのこの部分をしました:/最適化
private void AnswerToCe(int currentBlock, int totalBlock = 0)
{
byte[] bufferToSend;
byte[] macDst = mac;
byte[] macSrc = ConnectionManager.SInstance.GetMyMAC();
byte[] ethType;
byte[] header;
if (Function == FlashFunction.UPLOAD_APPL || Function == FlashFunction.UPLOAD_BITSTREAM)
{
ethType = BitConverter.GetBytes((ushort)EthType.ETH_TYPE_UPLOAD);
ethType = new byte[] { ethType[1], ethType[0] };
header = Header.GetBytes((ushort)binaryBlocks.Count, (ushort)(currentBlock + 1), (ushort)binaryBlocks[currentBlock].Length);
int index = 0;
bufferToSend = new byte[macDst.Length + macSrc.Length + ethType.Length + header.Length + binaryBlocks[currentBlock].Length];
Array.Copy(macDst, 0, bufferToSend, index, macDst.Length);
index += macDst.Length;
Array.Copy(macSrc, 0, bufferToSend, index, macSrc.Length);
index += macSrc.Length;
Logger.SInstance.Write(index.ToString(), "test index pre");
Array.Copy(ethType, 0, bufferToSend, index, ethType.Length);
index += ethType.Length;
Logger.SInstance.Write(index.ToString(), "test index post");
Array.Copy(header, 0, bufferToSend, index, header.Length);
index += header.Length;
Array.Copy(binaryBlocks[currentBlock], 0, bufferToSend, index, binaryBlocks[currentBlock].Length);
}
私はデバッグモードで自分のアプリケーションを構築する場合、すべてが、test index pre
版画12とtest index post
リリースでプリント14.同じokですモードはOptimize code
がチェックされていません。 Optimize code
でテストした場合、test index post
は14の代わりに18を表示します。
index += ethType.Length;
をindex += 2;
に置き換えた場合と同じ結果になります。ただindex++;index++;
が働いているようです。
空のアプリケーションでこのコードを試してみましたが、合計はOKです。
アプリケーションはマルチスレッドですが、ここには並行処理はありません。
DLLからデコンパイルされたコードは問題ありません。
これはなぜ起こるのでしょうか?
編集: アプリがx64用にコンパイルされている場合にのみ発生します。 x86は大丈夫です。
EDIT 3:ビルドENVのいくつかの情報:
のVisual Studio 15.0.0-RTW + 26228.4
枠組み4.7.02053
は、フレームワーク4.6.2と4.7でこの問題をトリガすることができます。他のフレームワークはテストされていません。
EDIT5:new, smaller example project。依存関係は必要ありません。
EDIT 6:テストプロジェクトの分解here。 (長すぎてここに掲載できません)
"アプリケーションはマルチスレッドですが、ここには並行処理はありません。"これはあなたのコードの一部であり、この関数の外部からのいくつかの変数を使用するため、言うことは難しいです。 –
https://msdn.microsoft.com/en-us/library/c151dt3s.aspx – StefanE
@PawełŁukasikブレークポイントは一度だけヒットします。インデックス変数は外部変数ではありません。 – rmbq