.NET JIT potential error?

后端 未结 3 730
北海茫月
北海茫月 2021-01-29 17:13

The following code gives different output when running the release inside Visual Studio, and running the release outside Visual Studio. I\'m using Visual Studio 2008 and targeti

3条回答
  •  不思量自难忘°
    2021-01-29 17:55

    I copied your code into a new Console App.

    • Debug Build
      • Correct output with both debugger and no debugger
    • Switched to Release Build
      • Again, correct output both times
    • Created a new x86 configuration (I'm on running X64 Windows 2008 and was using 'Any CPU')
    • Debug Build
      • Got the correct output both F5 and CTRL+F5
    • Release Build
      • Correct output with Debugger attached
      • No debugger - Got the incorrect output

    So it is the x86 JIT incorrectly generating the code. Have deleted my original text about reordering of loops etc. A few other answers on here have confirmed that the JIT is unwinding the loop incorrectly when on x86.

    To fix the problem you can change the declaration of IntVec to a class and it works in all flavours.

    Think this needs to go on MS Connect....

    -1 to Microsoft!

提交回复
热议问题