[Bug c/30128] New: Strange code generated
terra at gnome dot org
gcc-bugzilla@gcc.gnu.org
Sat Dec 9 03:05:00 GMT 2006
The program...
/* ------------------------------------------- */
#define GSF_LE_SET_GUINT32(p, dat) \
((*((char *)(p) + 0) = (char) ((dat)) & 0xff), \
(*((char *)(p) + 1) = (char) ((dat) >> 8) & 0xff), \
(*((char *)(p) + 2) = (char) ((dat) >> 16) & 0xff), \
(*((char *)(p) + 3) = (char) ((dat) >> 24) & 0xff))
void bar (void *);
void
foo (unsigned i)
{
char buffer[4];
unsigned len = i + 1;
GSF_LE_SET_GUINT32 (buffer, len + 1);
bar (buffer);
}
/* ------------------------------------------- */
...generates the code below. Note, that there are two additions in the
generated code and that an extra register is used. It is as-if the least
significant byte is seen as unrelated to the three others.
foo:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
leal 2(%eax), %edx <-- one addition into edx
addl $2, %eax <-- second one to eax
shrl $8, %eax
movb %al, -3(%ebp)
shrl $8, %eax
movb %al, -2(%ebp)
shrl $8, %eax
movb %al, -1(%ebp)
leal -4(%ebp), %eax
movb %dl, -4(%ebp)
movl %eax, (%esp)
call bar
leave
ret
--
Summary: Strange code generated
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terra at gnome dot org
GCC build triplet: i586-suse-linux
GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30128
More information about the Gcc-bugs
mailing list