public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8936: Declaration of never defined member function changes generated code
@ 2002-12-19 17:03 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2002-12-19 17:03 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, martin, nobody

Synopsis: Declaration of never defined member function changes generated code

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Thu Dec 19 17:03:48 2002
State-Changed-Why:
    I can confirm this, and it happens with all versions of
    gcc up to the present mainline after the BIB merge.
    
    The effect can be traced back to the case with no 
    optimizations switched on. There, in foo we have at
    the beginning
    	subl	$24, %esp
    where we have at the beginning of bar:
    	subl	$72, %esp
    Otherwise the code is identical (apart from the obvious
    changes in addressing local variables relative to ebp).
    
    Why so much stack space is allocated remains a mystery to
    me, but since the difference in stack allocation is the
    only thing that remains constant the more optimizations
    we switch on, this would indeed be interesting to
    investigate.
    
    The existence of a copy constructor (that is indeed not
    used here) changes something in data structures that
    should not even be used here. I thought a moment about
    exception handling, but declaring the copy constructor
    with throw() does not change anything.
    
    I don't think I can be of further help, but this would be
    something well worth fixing!
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8936


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

* c++/8936: Declaration of never defined member function changes generated code
@ 2002-12-14  2:56 martin
  0 siblings, 0 replies; 2+ messages in thread
From: martin @ 2002-12-14  2:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8936
>Category:       c++
>Synopsis:       Declaration of never defined member function changes generated code
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 14 02:56:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Martin Buchholz
>Release:        unknown-1.0
>Organization:
>Environment:
g++ 3.2.1
Linux x86
>Description:
This is related to my message "Failure to apply trivial peephole optimizations".

Declaring (not defining) a member function should not cause generated
code to be different (unless the generated code contains a call to the undefined function, which would lead to a link error).

Yet for this source file:

    enum E { E1, E2 };

    struct S
    {
      enum E e;
      S (enum E ee) : e (ee) {}
      S (const S&other);
      operator E () { return e; }
    };

    struct T
    {
      enum E e;
      T (enum E ee) : e (ee) {}
      //T (const T&other);
      operator E () { return e; }
    };

    bool foo () { return E(T(E1)) == E(T(E2)); }
    bool bar () { return E(S(E1)) == E(S(E2)); }

the code generated for foo and bar are different.  S and T differ only
in that S has a declared, undefined, unused copy constructor.

Here is the generated x86 asm:


_Z3foov:
.LFB1:
	pushl	%ebp
.LCFI0:
	xorl	%eax, %eax
	movl	%esp, %ebp
.LCFI1:
	popl	%ebp
	ret
.LFE1:
.Lfe1:
	.size	_Z3foov,.Lfe1-_Z3foov
	.align 2
	.p2align 4,,15
.globl _Z3barv
	.type	_Z3barv,@function
_Z3barv:
.LFB2:
	pushl	%ebp
.LCFI2:
	xorl	%eax, %eax
	movl	%esp, %ebp
.LCFI3:
	subl	$40, %esp
.LCFI4:
	movl	%ebp, %esp
	popl	%ebp
	ret


Details: g++ 3.2.1, Linux x86, g++ -O3
My other message points out how trivially the asm for bar can be
converted to the superior asm for foo.  But why should gcc ever even
consider generating different code?  The copy constructor
is clearly not being called.


>How-To-Repeat:
g++ -O3 -S
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-12-20  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-19 17:03 c++/8936: Declaration of never defined member function changes generated code bangerth
  -- strict thread matches above, loose matches on Subject: below --
2002-12-14  2:56 martin

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).