VC 64-bit compiler BUG

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
 
C

Carl Daniel [VC++ MVP]

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
 

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