2017-08-02 30 views
9

と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。 (長すぎてここに掲載できません)

+0

"アプリケーションはマルチスレッドですが、ここには並行処理はありません。"これはあなたのコードの一部であり、この関数の外部からのいくつかの変数を使用するため、言うことは難しいです。 –

+0

https://msdn.microsoft.com/en-us/library/c151dt3s.aspx – StefanE

+0

@PawełŁukasikブレークポイントは一度だけヒットします。インデックス変数は外部変数ではありません。 – rmbq

答えて

0

RyuJITにはすでに報告されていたバグです。詳細はhereです。すぐに修正プログラムで修正される予定です。