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]

simple example of incorrect inline (solaris2.6, 1999/06/08)


/*
 * When you compile the code below with -O2, which inlines,
 * the output code is just plain wrong.  Without O2, which avoids
 * the inlining, the code is correct.
 *
 * For convenience, I've bracket the section by startMarker() and endMarker()
 * so you can see in the inline version where the critical section of code
 * is.
 */

void startMarker();
void endMarker(void*);

class BaseMemchunk {
    struct Link {
	Link*		next;
    };

    Link*		head;
    void		*auxGet();

public:

    void* get()
    {
	startMarker();
	
	void *p = head ? head : auxGet();


	head = static_cast<Link*>(p)->next;	// this line is not performed!!

	endMarker(head+13);			// Note: the +13 addition
						// is computed *after* the
						// call to endMarker!
	return p;
    }
};

void*  func(BaseMemchunk& store)
{
    return store.get();
}

/*
 *
 * This is the code emitted by
 *	g++ -O2 -S -c bug.cpp
 *
func__FR12BaseMemchunk:
.LLFB1:
	!#PROLOGUE# 0
	save	%sp, -112, %sp
.LLCFI0:
	!#PROLOGUE# 1
	call	startMarker__Fv, 0
	mov	%i0, %l0
	ld	[%l0], %i0
	cmp	%i0, 0
	bne,a	.LL7
	ld	[%i0], %o0
	call	auxGet__12BaseMemchunk, 0
	mov	%l0, %o0
	mov	%o0, %i0
	ld	[%i0], %o0
.LL7:
	st	%o0, [%l0]
	call	endMarker__FPv, 0
	add	%o0, 52, %o0
	ret
	restore
 */


Version info:

 Reading specs from /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/specs
gcc version gcc-2.95 19990608 (prerelease)
 /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__OPTIMIZE__ -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) bug.cpp bug.ii
GNU CPP version gcc-2.95 19990608 (prerelease) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/../../../../include/g++-2
 /usr/local/include
 /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/../../../../sparc-sun-solaris2.6/include
 /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/share/egcs/latest/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/cc1plus bug.ii -quiet -dumpbase bug.cc -O2 -version -o bug.s
GNU C++ version gcc-2.95 19990608 (prerelease) (sparc-sun-solaris2.6) compiled by GNU C version gcc-2.95 19990608 (prerelease).


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