Major bug in 64-bit integer comparion (VC++ 7.1)

P

Peter Donov

The following console application:
---------------------
#include <stdio.h>

void main()
{
unsigned __int64 x=47;
int y=-1;
int test1=(x+y)<0;
x+=y;
//int dummy=3;dummy--;
int test2=x<0;
int test3=x<0;

printf("test1=%d, test2=%d, test3=%d\n", test1, test2,
test3);
int f=0;
}
----------------------
Produces this output:
"test1=1, test2=1, test3=0"
when compiled in "Debug" build configuration.
If you uncomment the commented line you get the
correct results for "test2" and "test3", but
"test1" is still wrong.

In "Release" it produces the correct output:
test1=0, test2=0, test3=0

I've examined the assembler code that is
generated in "Debug" mode and it seems that
there's a "cmp" instruction missing.

Is there a patch addressing this issue?
 
D

David Lowndes

Peter,

This definitely looks like a compiler bug, I'll try to report it to MS
since it reproduces with the current Whidbey compiler.

It's interesting to note that the release build probably works because
it optimises away most of the code.

Dave
 
P

Peter Donov

What's even more interesting is that nobody
found this bug by now. I guess nobody is building their
software in "Debug" mode anymore :)
Probably that's the reason for the poor quality of
software nowadays.
 
D

David Lowndes

What's even more interesting is that nobody
found this bug by now. I guess nobody is building their
software in "Debug" mode anymore :)

I can't speak for anyone else, but I always do debug builds and I try
to ensure that every line of code I write is checked through the
debugger - just to be sure that it's doing what I think it should!

As to why (or even *if*) that issue's not shown up before, I really
can't say - but let's see what MS have to say about the bug report.

Dave
 
B

Bruno van Dooren

I also develop all code in debug mode. switching to release only when going
to test for actual release, but most code developed is not 64 bit (at least
mine is not) so this is probably why nobody noticed.

kind regards,
Bruno.
 
C

Carl Daniel [VC++ MVP]

Peter said:
What's even more interesting is that nobody
found this bug by now. I guess nobody is building their
software in "Debug" mode anymore :)
Probably that's the reason for the poor quality of
software nowadays.

More likely the reason is that few programs use 64-bit integers.

-cd
 
D

David Lowndes

What's even more interesting is that nobody
More likely the reason is that few programs use 64-bit integers.

Undoubtedly, but you'd have hoped that MS's automated internal testing
would exercise this - it's tedious stuff, but not rocket science.

Dave
 
M

MerkX Zyban

What's even more interesting than that is VC++ 6.0 does not seem to have
this bug.
 
P

Peter Donov

Yes and 7.0 is also OK. I could stick with
it for now, but I'd like to use the new features
of 7.1 like partial template specialization.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top