This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11542] New: assignment to one bit of bitfield clobbers other bits


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11542

           Summary: assignment to one bit of bitfield clobbers other bits
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jfirebaugh at kde dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: powerpc-linux-gnu

Under certain optimization scenarios, g++ generates invalid code for 
assignment to bitfields. The resulting powerpc assembly typically does 
 
li      r0,1 
stw     r0,24(r31) 
 
instead of the correct masking and shifting. Thus the assignment will wipe out 
other bitfield values. This has resulted in rendering errors in khtml, the KDE 
HTML engine. 
 
john@localhost:~$ g++ -v 
Reading specs from /usr/lib/gcc-lib/powerpc-linux/3.3.1/specs 
Configured with: ../src/configure -v 
--enable-languages=c,c++,java,f77,pascal,objc,ada --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib 
--enable-nls --without-included-gettext --enable-__cxa_atexit 
--enable-clocale=gnu --enable-java-gc=boehm --enable-java-awt=xlib 
--enable-objc-gc --disable-multilib powerpc-linux 
Thread model: posix 
gcc version 3.3.1 20030626 (Debian prerelease) 
 
---begin testcase--- 
#include <cstdlib> 
 
struct RenderObject 
{ 
	virtual bool isTableCell() const { return false; } 
	virtual void setStyle(int) { isTableCell(); } 
	void setPositioned(bool b)  { m_positioned = b;  } 
	void setFloating(bool b) { m_floating = b; } 
	bool m_floating : 1; 
	bool m_positioned : 1; 
	bool m_replaced : 1; 
}; 
 
struct RenderBox : public RenderObject 
{ 
	virtual void setStyle(int pos) 
	{ 
		bool oldpos = m_positioned; 
		RenderObject::setStyle(pos); 
		switch(pos) 
		{ 
		case 2: 
			setPositioned(true); 
			break; 
		default: 
			if (oldpos) 
				setPositioned(true); 
			setPositioned(false); 
			if(!isTableCell()) 
				setFloating(true); 
		} 
	} 
}; 
 
int main(int argc, char* argv[]) 
{ 
	RenderBox b; 
	b.m_floating = false; 
	b.m_positioned = false; 
	b.m_replaced = true; 
	b.setStyle(3); 
	if(!b.m_replaced) 
		abort(); 
} 
---end testcase--- 
 
john@localhost:~$ g++ -Wall -O2 -g3 test.cpp && ./a.out 
Aborted


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]