Fix DateTime regression on ARM
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Thu, 12 Mar 2015 01:41:28 +0000 (02:41 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 2 May 2016 22:08:05 +0000 (00:08 +0200)
commit51003c985d89ee9b9c72c93349cbdb3f317553de
tree1ba6a0848a6dcef78a818e841b900c77c8cb75c5
parentb1b82b0e31710e8d4c71ba7bff75eff86c7effe4
Fix DateTime regression on ARM

This is the same issue as in https://github.com/mono/referencesource/pull/7,
i.e. there's an overflow when casting a too large value from double->long
and the referencesource implementation relies on this being a large negative
value in order for the ArgumentOutOfRangeException to be properly thrown.

As Mono's runtime on ARM in this case returns -1, the exception isn't thrown.

The fix is to introduce an explicit overflow check, catch an eventual
OverflowException and raise the proper exception instead. This can be JIT'd
to better code than checking if the value fits into long every time.

It fixes a couple of DateTime unit tests that currently fail on ARM.
mcs/class/referencesource/mscorlib/system/datetime.cs