BUG: Incorrect / inconsistent program behaviour when the "Remove Integer Overflow Checks" option is

  • Thread starter Thread starter Ralph Purtcher-Wydenbruck
  • Start date Start date
R

Ralph Purtcher-Wydenbruck

This is a worrying bug, and indicates a potential problem in the Framework
CLR. This bug affected a project I was working on, which behaved differently
when run from the Visual Studio IDE than when run by double clicking on the
project's EXE file. The problem can be replicated easily:

Create a new project in Visual Studio 2003 and add the following code.


Module Main
Sub Main()
Dim xmlDoc As New System.Xml.XmlDocument
xmlDoc.AppendChild(xmlDoc.CreateElement("Root"))
Dim o, n As Object
Dim count As Integer
For Each o In xmlDoc.ChildNodes
For n = 0 To 9
count += 1
Next
Next
System.Windows.Forms.MessageBox.Show("Count: " & count)
End Sub
End Module


IMPORTANT: To replicate the bug, you must

(1) Set the project compile mode to "Release"
(2) Enable the following option: Project Configuration Properties /
Optimisations / "Remove Integer Overflow Checks"

Finally, run the program from the Visual Studio IDE. The expected message,
"Count: 10", is displayed. Now run the program from it's EXE file via
Windows Explorer. A message, "Count: 1" is displayed, which is incorrect.
 
Ralph,

Interesting, that does indeed look like some kind of JIT compiler bug.

FYI, changing the loop variable n to an Integer fixes the problem. Why
did you have it declared as Object anyway?



Mattias
 
I know it fixes it, but I wanted to show the problem. Actually, changing the
code in almost any way fixes the problem.

It's a rather worrying thought that this kind arbitrary JIT compiler problem
might affect anyone's code.

So, there was no specific reason for the Object declaration, other than the
fact that I wanted to provide a simple example that did not break the
problem. (In my shipping code I used a For / Each for the inner loop, not an
object).
 
Ralph,
I know it fixes it, but I wanted to show the problem. Actually, changing the
code in almost any way fixes the problem.

OK, fine. FWIW, the bug seems to be fixed in Whidbey.

It's a rather worrying thought that this kind arbitrary JIT compiler problem
might affect anyone's code.

Well, there will always be bugs.



Mattias
 
Back
Top