Thanks for looking into this. I added that test case, but took a more-conservative approach to fixing the bug, by disabling the optimization that's causing this problem; please see attached patches. The optimization was a hack anyway, and these bugs suggest that it's not a hack worth keeping.