Bug 697 - 2.96 20000731 (Red Hat Linux 7.0) generates bad linked list code on -O2, working code on -O1 or -g
Summary: 2.96 20000731 (Red Hat Linux 7.0) generates bad linked list code on -O2, work...
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 2.96 (redhat)
: P1 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2000-10-26 21:06 UTC by mike
Modified: 2005-06-05 09:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
s2.i (4.42 KB, text/x-c)
2003-05-21 15:17 UTC, mike
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mike 2000-10-26 21:06:00 UTC
This dumps
rm s2; gcc -O2 ../rt/s2.c -o s2; ./s2
This does not dump:
rm s2; gcc -O1 ../rt/s2.c -o s2; ./s2

The problem appears to be that the optimizer incorrectly
re-orders a pointer load in the middle of a linked-list
routine, resulting in a damaged linked list.

Release:
gcc version 2.96 20000731 (Red Hat Linux 7.0)

How-To-Repeat:
rm s2 ; gcc -O2 -v -save-temps ../rt/s2.c -o s2 ; ./s2

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTIMIZE__ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ ../rt/s2.c s2.i
GNU CPP version 2.96 20000731 (Red Hat Linux 7.0) (cpplib)
 (i386 Linux/ELF)
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 s2.i -quiet -dumpbase s2.c -O2 -version -o s2.s
GNU C version 2.96 20000731 (Red Hat Linux 7.0) (i386-redhat-linux) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.0).
 as -V -Qy -o s2.o s2.s
GNU assembler version 2.10.90 (i386-redhat-linux) using BFD version 2.10.0.18
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o s2 /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. s2.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o

bu_ck_list_magic(re_parthead) cur=x8049ba8, cur->back=x8049ba8, cur->back->forw=x8049bb4, hd=x8049ba8, item=0
Abort (core dumped)
Comment 1 mike 2000-10-26 21:06:00 UTC
Fix:
Unknown
Comment 2 Richard Henderson 2001-01-16 07:50:21 UTC
State-Changed-From-To: open->closed
State-Changed-Why: The function rt_free_pt_list accesses the same memory as a
    struct bu_list and as a struct partition.  This violates ISO C
    type aliasing rules.
    
    As a gcc extension you may access the same memory as different
    types via a union.  Note that there is *no* portable way to do
    this in ISO C.
    
    Alternately, compile with -fno-strict-aliasing to disable the
    type-based aliasing rules entirely.
Comment 3 Richard Henderson 2001-01-16 15:50:21 UTC
From: rth@gcc.gnu.org
To: Mike@arl.army.mil, acst@arl.army.mil, gcc-gnats@gcc.gnu.org,
  nobody@gcc.gnu.org
Cc:  
Subject: Re: optimization/697
Date: 16 Jan 2001 15:50:21 -0000

 Synopsis: 2.96 20000731 (Red Hat Linux 7.0) generates bad linked list code on -O2, working code on -O1 or -g
 
 State-Changed-From-To: open->closed
 State-Changed-By: rth
 State-Changed-When: Tue Jan 16 07:50:21 2001
 State-Changed-Why:
     The function rt_free_pt_list accesses the same memory as a
     struct bu_list and as a struct partition.  This violates ISO C
     type aliasing rules.
     
     As a gcc extension you may access the same memory as different
     types via a union.  Note that there is *no* portable way to do
     this in ISO C.
     
     Alternately, compile with -fno-strict-aliasing to disable the
     type-based aliasing rules entirely.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=697&database=gcc
Comment 4 Andrew Pinski 2005-06-05 09:50:34 UTC
Reopening to ...
Comment 5 Andrew Pinski 2005-06-05 09:53:07 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***