Fix and test for ticket #4964 - assert in debug mode on x64

This fixes #4964 and adds a testcase which used to trigger the assert.  Note that the testcase only fails on x64 (address-model=64) in debug mode (and when the fix is not in place, obviously).
I haven't had a chance to test this on ARM, but MSDN is clear on that this applies to ARM in the same way so the fix also applies to ARM.