public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17665] New:
@ 2004-09-24 23:13 gcc-bugzilla at gcc dot gnu dot org
  2004-09-24 23:39 ` [Bug c/17665] wrong code with -O2 pinskia at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-09-24 23:13 UTC (permalink / raw)
  To: gcc-bugs



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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-06-05  8:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-24 23:13 [Bug c/17665] New: gcc-bugzilla at gcc dot gnu dot org
2004-09-24 23:39 ` [Bug c/17665] wrong code with -O2 pinskia at gcc dot gnu dot org
2004-09-25  5:41 ` davids at webmaster dot com
2004-09-25  8:48 ` jsm at polyomino dot org dot uk
2004-09-25 10:55 ` giovannibajo at libero dot it
2004-09-25 17:35 ` davids at webmaster dot com
2004-09-25 17:56 ` davids at webmaster dot com
2004-09-25 18:09 ` pinskia at gcc dot gnu dot org
2004-09-25 18:09 ` pinskia at gcc dot gnu dot org
2004-09-25 18:24 ` davids at webmaster dot com
2004-09-25 18:30 ` jsm at polyomino dot org dot uk
2004-09-26  0:28 ` davids at webmaster dot com
2005-06-05  8:56 ` pinskia at gcc dot gnu dot org
2005-06-05  8:57 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).