This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/17665] New:
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Sep 2004 23:13:12 -0000
- Subject: [Bug c/17665] New:
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The wrong code is generated for -O2 on a dereference of a pointer to a 'void
*'.
Environment:
System: Linux youknow.youwant.to 2.4.20-28.7smp #1 SMP Thu Dec 18 11:18:31 EST 2003 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --enable-languages=c++,java --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --program-suffix=342
How-To-Repeat:
#include <stdio.h>
#include <stdlib.h>
// Optimization issue with g++ 2.96 and 3.4.2 and probably others.
// With -O2, I get "3 1 0" and "3 1 2"
// With -O1, I get "3 1 2" and "3 1 2"
void *GetBlocks(void)
{
void *block1=malloc(64);
void *block2=malloc(64);
void *block3=malloc(64);
*(void **) block1=block2;
*(void **) block2=block3;
*(void **) block3=NULL;
return block1;
}
int CountList(void *a)
{
int ret=0;
while(a!=NULL)
{
ret++;
a=*(void **) a;
}
return ret;
}
void RemoveOneA(void *head)
{
int l1, l2, l3;
void *newhead;
l1=CountList(head);
newhead=*(void **) head;
*(char **) head=NULL;
l2=CountList(head);
l3=CountList(newhead);
printf("%d %d %d\n", l1, l2, l3);
}
void RemoveOneB(void *head)
{
int l1, l2, l3;
void *newhead;
l1=CountList(head);
newhead=*(char **) head;
*(char **) head=0;
l2=CountList(head);
l3=CountList(newhead);
printf("%d %d %d\n", l1, l2, l3);
}
int main(void)
{
RemoveOneA(GetBlocks());
RemoveOneB(GetBlocks());
}
------- Additional Comments From davids at webmaster dot com 2004-09-24 23:13 -------
Fix:
The same code should be generated. Or see the other 'RemoveOne'
implementation.
David Schwartz
<davids@webmaster.com>
--
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: davids at webmaster dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17665