Bug 6631 - Miscompiled structure access
Miscompiled structure access
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.1
: P1 critical
: ---
Assigned To: Jakub Jelinek
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-05-10 18:26 UTC by Andreas Schwab
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host: ia64-suse-linux-gnu
Target: ia64-suse-linux-gnu
Build: ia64-suse-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2002-05-10 18:26:01 UTC
life_analysis misoptimizes out code to initialize the fields of a structure.

Release:
3.1 20020506 (prerelease)

Environment:
System: Linux sykes 2.4.18-SMP #1 SMP Sat Apr 13 18:56:25 UTC 2002 ia64 unknown unknown GNU/Linux
Architecture: ia64

 
host: ia64-suse-linux-gnu
build: ia64-suse-linux-gnu
target: ia64-suse-linux-gnu
configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-checking ia64-suse-linux

How-To-Repeat:
$ cat qsize.cpp
extern "C" void abort (void);

struct QSize
{
  QSize();
  QSize( int w, int h );
  int wd, ht;
  friend inline const QSize operator+( const QSize &, const QSize & );
};

inline QSize::QSize()
{ wd = ht = -1; }

inline QSize::QSize( int w, int h )
{ wd = w; ht = h; }

inline const QSize operator+( const QSize & s1, const QSize & s2 )
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }

QSize minimumSize()
{
  return QSize (100, 200);
}

QSize totalMinimumSize()
{
    QSize s = minimumSize();
    return s + QSize( 0, 0 );
}

int main()
{
  QSize s = totalMinimumSize();
  if (s.wd != 100 || s.ht != 200)
    abort ();
}
$ gcc -O -v qsize.cpp 
Reading specs from /usr/lib/gcc-lib/ia64-suse-linux/3.1/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-checking ia64-suse-linux
Thread model: posix
gcc version 3.1 20020506 (prerelease)
GNU CPP version 3.1 20020506 (prerelease) (cpplib) (IA-64) Linux
GNU C++ version 3.1 20020506 (prerelease) (ia64-suse-linux)
        compiled by GNU C version 3.1 20020506 (prerelease).
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/include/g++/ia64-suse-linux
 /usr/include/g++/backward
 /usr/local/include
 /usr/lib/gcc-lib/ia64-suse-linux/3.1/include
 /usr/ia64-suse-linux/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/ia64-suse-linux/3.1/../../../../ia64-suse-linux/bin/as -x -o /tmp/cci5U9Z1.o /tmp/ccd2tZb1.s
$ ./a.out 
Aborted
Comment 1 Andreas Schwab 2002-05-10 18:26:01 UTC
Fix:
 http://gcc.gnu.org/ml/gcc-patches/2002-10/msg00861.html
Comment 2 Jakub Jelinek 2002-05-13 00:14:15 UTC
Responsible-Changed-From-To: unassigned->jakub
Responsible-Changed-Why: Mine.
Comment 3 janis187 2002-10-08 11:39:50 UTC
From: Janis Johnson <janis187@us.ibm.com>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: optimization/6631: Miscompiled structure access
Date: Tue, 8 Oct 2002 11:39:50 -0700

 This is a regression from GCC 3.0 that was exposed by the following cp
 patch:
 
 2002-04-30  Mark Mitchell  <mark@codesourcery.com>
 
 	ABI change, returning simple classes from functions.
 	* class.c (finish_struct_bits): Only mark TREE_ADDRESSABLE if
 	TYPE_HAS_TRIVIAL_INIT_REF is false or
 	TYPE_HAS_NONTRIVIAL_DESTRUCTOR is true.
 
 The test passes with optimization on if it is altered by adding a
 destructor or a copy constructor to class QSize, or by removing "const"
 from "inline const QSize operator+".
 
 I'm not planning to investigate this further, but hope this additional
 information will be useful.
 
 Janis

Comment 4 Mark Mitchell 2002-10-14 14:20:17 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed in GCC 3.2.1.
Comment 5 Mark Mitchell 2002-10-14 21:04:34 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6631
Date: 14 Oct 2002 21:04:34 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:04:34
 
 Modified files:
 	gcc            : Makefile.in alias.c function.c ChangeLog 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/opt: const2.C 
 
 Log message:
 	PR optimization/6631
 	* Makefile.in (function.o): Depend on langhooks.h.
 	* alias.c (objects_must_conflict_p): Check honor_readonly when
 	examining TYPE_READONLY.
 	* function.c (assign_stack_temp_for_type): Likewise.
 	
 	PR optimization/6631
 	* g++.dg/opt/const2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/Makefile.in.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.830.2.15.2.2&r2=1.830.2.15.2.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/alias.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.166.2.3&r2=1.166.2.3.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.347.2.10&r2=1.347.2.10.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.86&r2=1.13152.2.657.2.87
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.24&r2=1.1672.2.166.2.25
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 

Comment 6 Mark Mitchell 2002-10-14 21:04:34 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6631
Date: 14 Oct 2002 21:04:34 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:04:34
 
 Modified files:
 	gcc            : Makefile.in alias.c function.c ChangeLog 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/opt: const2.C 
 
 Log message:
 	PR optimization/6631
 	* Makefile.in (function.o): Depend on langhooks.h.
 	* alias.c (objects_must_conflict_p): Check honor_readonly when
 	examining TYPE_READONLY.
 	* function.c (assign_stack_temp_for_type): Likewise.
 	
 	PR optimization/6631
 	* g++.dg/opt/const2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/Makefile.in.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.830.2.15.2.2&r2=1.830.2.15.2.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/alias.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.166.2.3&r2=1.166.2.3.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.347.2.10&r2=1.347.2.10.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.86&r2=1.13152.2.657.2.87
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.24&r2=1.1672.2.166.2.25
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 
Comment 7 Mark Mitchell 2002-10-14 21:19:07 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6631
Date: 14 Oct 2002 21:19:07 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:19:07
 
 Modified files:
 	gcc            : ChangeLog alias.c function.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/opt: const2.C 
 
 Log message:
 	PR optimization/6631
 	* Makefile.in (function.o): Depend on langhooks.h.
 	* alias.c (objects_must_conflict_p): Check honor_readonly when
 	examining TYPE_READONLY.
 	* function.c (assign_stack_temp_for_type): Likewise.
 	
 	PR optimization/6631
 	* g++.dg/opt/const2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15700&r2=1.15701
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/alias.c.diff?cvsroot=gcc&r1=1.179&r2=1.180
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&r1=1.386&r2=1.387
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const2.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2137&r2=1.2138
 

Comment 8 Mark Mitchell 2002-10-14 21:19:07 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6631
Date: 14 Oct 2002 21:19:07 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:19:07
 
 Modified files:
 	gcc            : ChangeLog alias.c function.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/g++.dg/opt: const2.C 
 
 Log message:
 	PR optimization/6631
 	* Makefile.in (function.o): Depend on langhooks.h.
 	* alias.c (objects_must_conflict_p): Check honor_readonly when
 	examining TYPE_READONLY.
 	* function.c (assign_stack_temp_for_type): Likewise.
 	
 	PR optimization/6631
 	* g++.dg/opt/const2.C: New test.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15700&r2=1.15701
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/alias.c.diff?cvsroot=gcc&r1=1.179&r2=1.180
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&r1=1.386&r2=1.387
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const2.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2137&r2=1.2138