public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13005] New: Pointer wrongly adjusted for derived class containing virtual function
@ 2003-11-11  7:51 stephenma at telus dot net
  2003-11-11 16:01 ` [Bug c++/13005] " bangerth at dealii dot org
                   ` (33 more replies)
  0 siblings, 34 replies; 35+ messages in thread
From: stephenma at telus dot net @ 2003-11-11  7:51 UTC (permalink / raw)
  To: gcc-bugs

If a base class B has no virtual functions, not even inherited ones,
but a class derived from B has at least one virtual function, then
sometimes a pointer to the derived class is wrongly adjusted.

Here is the slightly reformatted output from "g++ -v":

	Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.2/specs

	Configured with: ../src/configure -v
	--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang
	--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-debug
	--enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc
	i486-linux

	Thread model: posix
	gcc version 3.3.2 (Debian)

The following little snippet demonstrates the problem:

	class Derived;
	
	struct Base {
	  Derived* before;
	  Derived* after;
	  void insertAfter(Derived* node);
	};
	
	struct Derived: public Base {
	  virtual void foo();
	};
	
	void Base::insertAfter(Derived* node) {
	  this->before->after = node;	// Notice the double indirection.
	}

When compiled with "g++-3.3 -S z.cpp" the compiler produces the
following assembler code for Base::insertAfter():

	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	movl	(%eax), %edx
	addl	$4, %edx         <-- BOGUS INSTRUCTION
	movl	12(%ebp), %eax
	movl	%eax, 4(%edx)
	popl	%ebp
	ret

I have marked what I believe is the offending instruction.

When I delete the declaration for Derived::foo(), the "addl"
instruction magically disappears.

In this specific example, the "addl" also disappears when I compile
with "-O2", regardless of whether Derived::foo() is declared.

-- 
           Summary: Pointer wrongly adjusted for derived class containing
                    virtual function
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stephenma at telus dot net
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu


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


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

end of thread, other threads:[~2005-09-23 22:35 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-11  7:51 [Bug c++/13005] New: Pointer wrongly adjusted for derived class containing virtual function stephenma at telus dot net
2003-11-11 16:01 ` [Bug c++/13005] " bangerth at dealii dot org
2003-11-11 17:54 ` bangerth at dealii dot org
2003-11-11 17:57 ` bangerth at dealii dot org
2003-11-15  9:10 ` [Bug c++/13005] [aliasing] " pinskia at gcc dot gnu dot org
2003-11-15  9:10 ` pinskia at gcc dot gnu dot org
2003-11-16 12:04 ` geoffk at gcc dot gnu dot org
2003-12-04 18:38 ` [Bug c++/13005] [3.3/3.4 Regresssion] " pinskia at gcc dot gnu dot org
2003-12-24 15:14 ` jazzdaq at yahoo dot com
2003-12-24 21:55 ` gdr at gcc dot gnu dot org
2003-12-29 20:50 ` nathan at gcc dot gnu dot org
2003-12-31  9:48 ` stephenma at telus dot net
2003-12-31 12:15 ` nathan at gcc dot gnu dot org
2003-12-31 17:57 ` pinskia at gcc dot gnu dot org
2004-01-01  1:02 ` stephenma at telus dot net
2004-01-01  1:09 ` pinskia at gcc dot gnu dot org
2004-01-08  2:02 ` stephenma at telus dot net
2004-01-08  2:24 ` [Bug c++/13005] " pinskia at gcc dot gnu dot org
2004-01-08  8:10 ` falk dot hueffner at student dot uni-tuebingen dot de
2004-01-08 18:13 ` gdr at integrable-solutions dot net
2004-01-09  1:33 ` stephenma at telus dot net
2004-01-09  1:46 ` stephenma at telus dot net
2004-01-09  4:17 ` gdr at integrable-solutions dot net
2004-01-09  4:24 ` gdr at integrable-solutions dot net
2004-01-09  8:40 ` stephenma at telus dot net
2004-01-09  8:46 ` stephenma at telus dot net
2004-01-09 15:16 ` bangerth at dealii dot org
2004-01-10  2:13 ` gdr at integrable-solutions dot net
2004-01-10  2:16 ` gdr at integrable-solutions dot net
2004-01-10  5:45 ` stephenma at telus dot net
2004-01-10  5:48 ` stephenma at telus dot net
2004-01-10  5:53 ` stephenma at telus dot net
2004-01-10 16:02 ` gdr at integrable-solutions dot net
2004-07-27  3:13 ` [Bug c++/13005] Pointer " pinskia at gcc dot gnu dot org
2005-09-23 22:35 ` 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).