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

  • Thread starter Thread starter Peter Donov
  • Start date Start date
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?
 
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
 
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.
 
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
 
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.
 
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
 
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
 
What's even more interesting than that is VC++ 6.0 does not seem to have
this bug.
 
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.
 
Back
Top