Computer Chess Club Archives


Search

Terms

Messages

Subject: MSVC .NET 2003 optimization bug [O.T]

Author: Russell Reagan

Date: 15:04:10 04/09/04


I'm posting this here because I know that some of the programmers here use MSVC
.NET 2003, and in hopes that Eugene will read this :)

Today I had a problem with a program I was writing, and I came across what I
believe is an optimization bug. I wrote this little program to reproduce the
bug. If I compile with optimizations set to "Disabled", there is no problem. If
I compile with optimzations set to anything else (Maximize Speed, Minimize Size,
Full Optimizations), the program crashes due to a loop never terminating. The
source code is at the end of this message. The line where the problem occurs is:

for (row = 11; row < 12; row--)

The problem is the comparison: row < 12

When optimizations are turned off, this is the assembly output for that
comparison:

cmp DWORD PTR _row$[ebp], 12

If optimizations are turned on, this is the assembly output:

cmp ebx, OFFSET FLAT:_a+576

I'm no assembly expert, but that looks like it is comparing the address of two
pointers to me, and has nothing to do with comparing two values.

Here is the example C source code. I compiled it under GCC with and without
optimizations and it ran fine. Another person with MSVC .NET 2003 ran this code
and he reported the same problem of crashing with optimizations turned on.

Is this really an optimization bug, or is it possible that I am doing something
wrong with the compiler settings? If this is indeed an optimization bug, how can
I find out if Microsoft is already aware of it? If they are not aware of it, how
can I report it to them?

#include <stdio.h>

unsigned int a[144];

void init ()
{
    unsigned int i;
    for (i = 0; i < 144; i++)
        a[i] = rand();
}

void dump ()
{
    unsigned int row, col;
    for (row = 11; row < 12; row--)     // <--- PROBLEM: row < 12
    {
        for (col = 0; col < 12; col++)
            printf("%u ", a[(row * 12) + col]);
        putchar('\n');
    }
}

int main ()
{
    init();
    dump();
    return 0;
}



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.