RyuJIT C#错误的总和结果与/ optimize

时间:2017-08-02 12:53:18

标签: c# sum ryujit

我是这段代码:

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.在发布模式下相同,Optimize code未选中。如果我用Optimize code检查test index post打印18而不是14 如果我将index += ethType.Length;替换为index += 2;,结果相同。似乎只有index++;index++;正在发挥作用 我在一个空的应用程序中尝试了这个代码,总结还可以 应用程序是多线程的,但这里没有并发性 来自DLL的反编译代码似乎没问题 任何想法为什么会发生这种情况?

编辑: 仅在为x64编译应用程序时才会发生。 x86还可以。
编辑3:构建环境的一些信息:
visual studio 15.0.0-RTW + 26228.4
框架4.7.02053
可以在框架4.6.2和4.7上触发此问题。其他框架未经过测试 编辑5:new, smaller example project。不需要依赖。
编辑6:反汇编测试项目here。 (太长了,不能在这里发布)

1 个答案:

答案 0 :(得分:0)

这是RyuJIT中已经报道的错误,更多细节here。将很快修复在修补程序中。