VC 64-bit compiler BUG

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Probably there is bug in VC 64-bit compiler (in all versions)

Compile and run the following code with speed optimization (-O2):

#include <stdio.h>

typedef int (*fp)(const unsigned char *buf, unsigned int pos, unsigned int
num);

int f(const unsigned char *buf, unsigned int pos, unsigned int num)
{
int sum = 0;
for (; num != 0; num--)
sum += buf[(size_t)pos++];
return sum;
}

fp t = f;

int main()
{
unsigned char buffer[1] = { 0 };
unsigned int pos = 0x80000000;
return t(buffer - pos, pos, 1);
}

Bug description:
pos is unsigned int, but VC compiler uses
movsxd r9, edx
command to extend from unsigned int to size_t
 
Igor said:
Probably there is bug in VC 64-bit compiler (in all versions)

Compile and run the following code with speed optimization (-O2):

#include <stdio.h>

typedef int (*fp)(const unsigned char *buf, unsigned int pos,
unsigned int num);

int f(const unsigned char *buf, unsigned int pos, unsigned int num)
{
int sum = 0;
for (; num != 0; num--)
sum += buf[(size_t)pos++];
return sum;
}

fp t = f;

int main()
{
unsigned char buffer[1] = { 0 };
unsigned int pos = 0x80000000;
return t(buffer - pos, pos, 1);
}

Bug description:
pos is unsigned int, but VC compiler uses
movsxd r9, edx
command to extend from unsigned int to size_t

That does sound like a bug, although it's impossible to tell from a single
assembly instruction without having a 64-bit compiler to try it out on.

Please post a bug report at

http://connect.microsoft.com/feedback?SiteID=210

-cd
 
Back
Top