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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Purtcher-Wydenbruck

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

    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.XmlD ocument
    xmlDoc.AppendCh ild(xmlDoc.Crea teElement("Root "))
    Dim o, n As Object
    Dim count As Integer
    For Each o In xmlDoc.ChildNod es
    For n = 0 To 9
    count += 1
    Next
    Next
    System.Windows. Forms.MessageBo x.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.


  • Mattias Sjögren

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

    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

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    • Ralph Purtcher-Wydenbruck

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

      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).


      "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
      news:et3CkNiqDH A.1680@TK2MSFTN GP10.phx.gbl...[color=blue]
      > 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
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/
      > Please reply only to the newsgroup.[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: BUG: Incorrect / inconsistent program behaviour when the &quot;Remove Integer Overflow Checks&quot; option is enabled

        Ralph,
        [color=blue]
        >I know it fixes it, but I wanted to show the problem. Actually, changing the
        >code in almost any way fixes the problem.[/color]

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

        [color=blue]
        >It's a rather worrying thought that this kind arbitrary JIT compiler problem
        >might affect anyone's code.[/color]

        Well, there will always be bugs.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org

        Please reply only to the newsgroup.

        Comment

        Working...