RyuJit产生不正确的结果 [英] RyuJit producing incorrect results

查看:73
本文介绍了RyuJit产生不正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近升级到.net 4.6后,我们发现了一个RyuJit产生错误结果的错误,我们现在可以通过在app.config中添加useLegacyJit enabled ="true"来解决该问题.

After recently upgrading to .net 4.6 we discovered a bug where RyuJit produces incorrect results, we were able to work around the issue for now by adding useLegacyJit enabled="true" to the app.config.

如何调试以下代码生成的机器代码?

How can I debug the machine code generated by the following?

我在VS 2015 RTM中创建了一个新的控制台项目,将其设置为Release,Any CPU,未经检查的Prefer 32位,无论是否连接调试器,运行时都会产生相同的结果.

I created a new console project in VS 2015 RTM, set to Release, Any CPU, unchecked Prefer 32 bit, running with and without debugger attached produces the same result.

using System;
using System.Runtime.CompilerServices;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Calculate());
            Console.WriteLine(Calculate());

            Console.ReadLine();
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Value Calculate()
        {
            bool? _0 = (bool?)null;
            bool? _1 = (bool?)true;
            if (!Value.IsPresent<bool>(_1))
            {
                return default(Value);
            }

            bool? result = null;
            result = (_1.Value ? new bool?(false) : result);
            if (_0.HasValue && _0.Value)
            {
            }
            return new Value(result);
        }

        public struct Value
        {
            bool? _value;

            public Value(bool? value)
            {
                _value = value;
            }

            public static bool IsPresent<T>(bool? _)
            {
                return _.HasValue;
            }

            public override string ToString()
            {
                return _value.ToString();
            }
        }
    }
}

它应该产生: 错误的 错误

It should produce: False False

但是它产生: 真的 错误

but instead it produces: True False

该示例的关键部分是

result = true ? false : result;

应该始终返回false,但是从输出中可以看到,第一次运行该方法时返回True,第二次运行该方法时返回不同的答案.从Calculate()方法中删除更多行将使它始终返回True,但是给出的示例是我可以重现到实际生产情况的最接近示例.

Which should always return false, but as you can see from the output, it returns True the first time the method is run, and a different answer the second time the method is run. Removing some more lines from the Calculate() method will cause it to return True always, but the example given is the closest I could reproduce to our actual production scenario.

推荐答案

感谢您使用隔离的repro程序,我可以确认这确实是优化器中的RyuJIT错误,该错误由于内联而暴露.我已经修复了编译器并确定了推出细节.不要将SO变成错误跟踪器,并且要尽快解决:ryujit@microsoft.com.

Thank you for the isolated repro program and I can confirm that this is indeed a RyuJIT bug in the optimizer which got exposed due to inlining. I've made a fix to the compiler and figuring the roll out details. Not to turn SO into a bug tracker, and for a quicker turnaround: ryujit@microsoft.com.

这篇关于RyuJit产生不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆