RyuJIT-具有ushort和Equals覆盖的错误(64位) [英] RyuJIT - Bug with ushort and Equals override (64bit)

查看:90
本文介绍了RyuJIT-具有ushort和Equals覆盖的错误(64位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将32位托管应用程序移植到64位时,我观察到结构中的Equals()重写会产生奇怪的行为。

While porting a 32bit managed application to 64bit I've observed a strange behavior by a Equals() override within a struct.

您在< a href = https://github.com/mbeelman/StrangeEqualityComparer rel = nofollow noreferrer> github 。

要重现错误,您应该在启用 optimize标志的情况下编译库。这是发布配置上的默认设置。消耗性的TestApp必须未经任何编译即可进行编译。必须禁用首选32位才能以64位应用程序启动。

该库包含一个实现IEquatable接口的结构,该接口通过简单的代码行实现。

The library contains a struct that implements the IEquatable interface which is implemented with a simple line of code.

    public bool Equals(StructWithValue other)
    {
        return value.Equals(other.value);
    }

此代码调用ushort / UInt16类型的Equals方法。如果使用建议的配置构建解决方案,则高于32767的所有值都会失败。您在ushort值32768上调用Equal,并且'other'的值也是32768。但是对于所有高于32767的值,Equals()将返回false。

This code calls the Equals method of the ushort/UInt16 type. If you build the solution with the proposed configuration, all values above 32767 will fail. You call Equal on a ushort value of 32768 and the value of 'other' is also 32768. But Equals() will return false for all values above 32767.

更改方法以使用'=='运算符,代码将起作用。同样,如果将类型从struct更改为class,则代码将按预期运行。

If you change the method to use the '==' operator the code will work. Also if you change the type from struct to class the the code runs as expected.

    public bool Equals(StructWithValue other)
    {
        return value == othervalue;
    }

我认为这是RyuJIT编译器中的错误。如果我使用旧版JIT编译器,则代码可以正常工作。

I think this is a bug in the RyuJIT-Compiler. If I use the legacy JIT-Compiler the code works fine.

在不同Windows版本上使用Visual Studio 2015和TargetFramework 4.6.2进行了测试。

Tested with Visual Studio 2015 and TargetFramework 4.6.2 on different windows versions.

推荐答案

通过检查确认的错误。

我无法想象这里还会出现什么其他答案。如果错误是不真实的,您将得到一个答案,向您显示代码错误在哪里,但代码没有错。

I can't imagine what other answer could appear here. If the bug were unreal you would get an answer showing you where your code is wrong, but your code is not wrong.

这篇关于RyuJIT-具有ushort和Equals覆盖的错误(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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