[Bug c/14375] New: bad code gen for pointer inc with &&
gcc-bugzilla at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Mar 1 23:12:00 GMT 2004
in a for loop computing a logical and, a second pointer appears
not to increment correctly. Code demonstrating problem and fix is attached.
The bug is activated by leaving GCC3_BUGFIX set to zero. The bug
appears in gcc 3.2.3 and gcc 3.3.3.
#include <stdio.h>
#define GCC3_BUGFIX 0
void andlog(int* dest, int* src,
int count)
{
int* term;
#if (GCC3_BUGFIX)
for (term=dest+count; dest<term; dest++,src++)
*dest = (*dest) && (*src);
#else
/* GCC3X (3.2.3 and 3.3.3) do not increment src right on x86
in this sequence */
for (term=dest+count; dest<term; dest++)
*dest = (*dest) && (*src++);
#endif
}
int main()
{
int i1[] = {
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int i2[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
int i;
andlog(i1,i2,65);
for (i=0; i<65; i++)
printf("and = %d should be %d\n",i1[i],i1[i] && i2[i]);
return(0);
}
Environment:
System: Linux madhatter 2.6.3 #2 Sat Feb 21 14:38:40 EST 2004 i686 unknown unknown GNU/Linux
Architecture: i686
host: i486-slackware-linux-gnu
build: i486-slackware-linux-gnu
target: i486-slackware-linux-gnu
configured with: ../gcc-3.3.3/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i486-slackware-linux --host=i486-slackware-linux
How-To-Repeat:
compile attached program on gcc3.2.3 or gcc3.3.3 and run it. Last
4 compares are bad.
------- Additional Comments From tjb at watson dot ibm dot com 2004-03-01 23:12 -------
Fix:
recode if using GCC3.
--
Summary: bad code gen for pointer inc with &&
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tjb at watson dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-slackware-linux-gnu
GCC host triplet: i486-slackware-linux-gnu
GCC target triplet: i486-slackware-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14375
More information about the Gcc-bugs
mailing list