2017-08-02 19 views
9

optimize:RyuJIT C# yanlış toplamı sonucu/I kod parçası ettik

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); 
    } 

Ben hata ayıklama modu her şeyde başvurum ok oluşturursanız, Release aynı test index pre baskılar 12 ve test index post baskılar 14. modu Optimize code işaretlenmemiş olarak. Optimize code ile test edersem test index post işaretlerini yerine 14 basar 14
index += 2; ile değiştirirseniz aynı sonuç. sadece index++;index++; çalışıyor görünüyor.
Bu kodu boş bir uygulamada denedim ve toplamlar tamam.
Uygulama çok iş parçacıklı ancak burada herhangi bir tutarlılık yok.
Decompiled kodu DLL'den görünüyor.
Bunun neden olduğuyla ilgili bir fikrin var mı?

DÜZENLEME: Sadece uygulama x64 için derlendiğinde olur. x86 tamam.
DÜZENLEME 3: inşa env'nin bazı bilgiler:
görsel stüdyo 15.0.0-RTW + 26228,4
çerçeve 4.7.02053
çerçevesi 4.6.2 ve 4.7 bu sorunu tetikleyebilir. diğer çerçeveler test edilmemiştir.
DÜZENLEME 5: new, smaller example project. bağımlılık gerektirmez.
DÜZENLEME 6: test projesinin sökülmesi here. (buraya göndermek için çok uzun süre)

+0

"Uygulama çok iş parçacıklı ancak burada hiçbir tutarlılık yok." Bu, sadece kodunuzun bir parçası olduğu ve bu işlevin dışından bazı değişkenleri kullandığı için söylenmesi zor. –

+0

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

+0

@ PawełŁukasik kesme noktaları yalnızca bir kez çarptı. dizin değişkeni harici değil. – rmbq

cevap

0

RyuJIT'de daha önce bildirilen bir hata oldu, daha fazla ayrıntı here. Yakında bir düzeltmede giderilecektir.