Fixed Equals/GetHashCode bug for struct. (#13164)
authorJim Ma <mazong1123@gmail.com>
Wed, 23 Aug 2017 22:32:15 +0000 (10:32 +1200)
committerJan Kotas <jkotas@microsoft.com>
Wed, 23 Aug 2017 22:32:15 +0000 (15:32 -0700)
commit495ece4abd2204e1fc79f34cf3ea7fe5ecf90ad3
treec61e4ca722f697cfdd7be3611cdb144cc513b7f9
parent59da8574383d547a20dcae478b67ff458f6d71e6
Fixed Equals/GetHashCode bug for struct. (#13164)

Other than `ContainsPointers` and `IsNotTightlyPacked`, added two new conditions for checking whether a valuetype can go to fast path or not. Following are the details of these 2 conditions:

- Check whether a valuetype contains a Single/Double field. If it does, we cannot go to fast path. Floating point numbers have special `Equals` and `GetHashCode` implementation. We cannot simply compare floating point numbers via bits (e.g. +0.0 should equal to -0.0, but their underlying bits are different).

- Check whether an user-defined valuetype overrides `Equals` or `GetHashCode`. If it does, we cannot go to fast path. Because `Equals` or `GetHashCode` result may be different to bit comparison.

To find Single/Double fields and overridden `Equals`/`GetHashCode`, we start a DFS to go through the whole hierachy of the source valuetype, and cache the result to `MethodTable`.

Fix #11452
src/vm/comutilnative.cpp
src/vm/methodtable.h
src/vm/mscorlib.h