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

查看:23
本文介绍了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.

您可以在 github 上找到该副本.

You find the a repro at github.

要重现该错误,您应该使用优化"标志来编译库.这是发布配置的默认设置.使用的 TestApp 必须在没有任何优化的情况下编译.首选 32 位必须禁用才能作为 64 位应用程序启动.见github上的注释!

该库包含一个实现 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 以上的所有值都将失败.您在 32768 的 ushort 值上调用 Equal 并且other"的值也是 32768.但是 Equals() 将对 32767 以上的所有值返回 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.

推荐答案

Bug 通过检查确认.

Bug confirmed by inspection.

我无法想象这里还会出现什么其他答案.如果错误是不真实的,你会得到一个答案,告诉你你的代码哪里出错了,但你的代码没有错.

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天全站免登陆