Bug 12926 - [3.3 regression] Wrong value after assignment in initialize list using bit-fields
Summary: [3.3 regression] Wrong value after assignment in initialize list using bit-fi...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.2
: P2 critical
Target Milestone: 3.3.3
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-11-06 15:21 UTC by Bjoern Seebeck
Modified: 2003-11-13 10:00 UTC (History)
1 user (show)

See Also:
Host: sparc-sun-solaris2.7
Target: sparc-sun-solaris2.7
Build: sparc-sun-solaris2.7
Known to work:
Known to fail:
Last reconfirmed: 2003-11-10 15:03:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bjoern Seebeck 2003-11-06 15:21:40 UTC
In the example below GCC seems to have problems with assignment 
of types in the initialize list, which were declared using Bit Fields:

#include <iostream>

using namespace std;

struct A 
{
  enum Type {P, U, S};

  A( const size_t size, const Type type ): mSize(size), mType(type)
  {
    cout << "type = " << type << endl;
    cout << "mType = " << mType << endl;
  }
  const size_t mSize :CHAR_BIT*sizeof(size_t) - 3 ;	
  Type mType       : 2;
}; 

int main()
{
  A testa(2,A::S); 
  return testa.mType;
}

The output is:

type = 2
mType = 0


Note that the output after compiling with -O1 is correct:
type = 2
mType = 2
, with -O2 or -O3 it is wrong.

Release:
gcc version 3.3.2

Environment:
sparc-sun-solaris2.7


Verbose message g++:
g++ a.C -v -oa -O3 -m64
Reading specs from /sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --prefix=/sw/gcc3 --with-local-
prefix=/sw/local --enable-libgcj --with-ld=/usr/ccs/bin/ld --with-
as=/usr/ccs/bin/as
Thread model: posix
gcc version 3.3.2
 /sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/cc1plus -quiet -v -
D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=2 -Dsparc -D__sparc__ -
D__sparc -D__arch64__ -Acpu=sparc64 -Amachine=sparcv9 -D__sparcv9 a.C -
D__GNUG__=3 -mptr64 -mstack-bias -mno-v8plus -mcpu=v9 -quiet -dumpbase a.C -
m64 -auxbase a -O3 -version -o /var/tmp//ccnuC6vI.s
GNU C++ version 3.3.2 (sparc-sun-solaris2.7)
        compiled by GNU C version 3.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/sw/gcc3/sparc-sun-solaris2.7/include"
#include "..." search starts here:
#include <...> search starts here:
 /sw/gcc3/include/c++/3.3.2
 /sw/gcc3/include/c++/3.3.2/sparc-sun-solaris2.7
 /sw/gcc3/include/c++/3.3.2/backward
 /sw/local/include
 /sw/gcc3/include
 /sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/include
 /usr/include
End of search list.
 /usr/ccs/bin/as -V -Qy -s -xarch=v9 -
o /var/tmp//ccu1ZhGI.o /var/tmp//ccnuC6vI.s
/usr/ccs/bin/as: Sun WorkShop 6 99/08/18
 /sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/collect2 -V -Y 
P,/usr/lib/sparcv9 -Qy -oa /sw/gcc3/lib/gcc-lib/sparc-sun-
solaris2.7/3.3.2/sparcv9/crt1.o /sw/gcc3/lib/gcc-lib/sparc-sun-
solaris2.7/3.3.2/sparcv9/crti.o /usr/ccs/lib/sparcv9/values-
Xa.o /sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/sparcv9/crtbegin.o -
L/sw/gcc3/lib/gcc-lib/sparc-sun-solaris2.7/3.3.2/sparcv9 -L/sw/gcc3/lib/gcc-
lib/sparc-sun-solaris2.7/3.3.2 -L/sw/gcc3/lib/gcc-lib/sparc-sun-
solaris2.7/3.3.2/../../../../sparc-sun-solaris2.7/lib -L/usr/ccs/bin/sparcv9 -
L/usr/ccs/bin -L/usr/ccs/lib/sparcv9 -L/usr/ccs/lib -L/sw/gcc3/lib/gcc-
lib/sparc-sun-solaris2.7/3.3.2/../../../sparcv9 -L/sw/gcc3/lib/gcc-lib/sparc-
sun-solaris2.7/3.3.2/../../.. -L/lib/sparcv9 -
L/usr/lib/sparcv9 /var/tmp//ccu1ZhGI.o -lstdc++ -lm -lgcc_s_sparcv9 -lgcc -lc -
lgcc_s_sparcv9 -lgcc -lc /sw/gcc3/lib/gcc-lib/sparc-sun-
solaris2.7/3.3.2/sparcv9/crtend.o /sw/gcc3/lib/gcc-lib/sparc-sun-
solaris2.7/3.3.2/sparcv9/crtn.o
ld: Software Generation Utilities - Solaris Link Editors: 5.8-1.279
Comment 1 Eric Botcazou 2003-11-10 15:03:02 UTC
Confirmed on 3.3 branch at least, a regression from GCC 3.2.3.
Comment 2 Eric Botcazou 2003-11-10 15:03:52 UTC
I'll investigate.
Comment 3 Eric Botcazou 2003-11-11 12:53:05 UTC
The bug doesn't occur on mainline because of a recent patch, but I think the
problem is latent there anyway.
Comment 4 CVS Commits 2003-11-13 09:48:42 UTC
Subject: Bug 12926

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-11-13 09:48:37

Modified files:
	gcc            : ChangeLog expr.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: const3.C 

Log message:
	PR optimization/12926
	* expr.c (expand_assignment) [COMPONENT_REF]: Don't put
	the UNCHANGING_RTX_P flag on memory references to read-only
	components that are not addressable.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1732&r2=2.1733
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.598&r2=1.599
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3188&r2=1.3189
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 CVS Commits 2003-11-13 09:56:55 UTC
Subject: Bug 12926

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	ebotcazou@gcc.gnu.org	2003-11-13 09:56:51

Modified files:
	gcc            : ChangeLog expr.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: const3.C 

Log message:
	PR optimization/12926
	* expr.c (expand_assignment) [COMPONENT_REF]: Don't put
	the UNCHANGING_RTX_P flag on memory references to read-only
	components that are not addressable.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.804&r2=1.16114.2.805
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.498.2.21&r2=1.498.2.22
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.316&r2=1.2261.2.317
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/const3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 6 Eric Botcazou 2003-11-13 10:00:12 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00845.html