c++/8936: Declaration of never defined member function changes generated code
martin@xemacs.org
martin@xemacs.org
Sat Dec 14 02:56:00 GMT 2002
>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:
More information about the Gcc-prs
mailing list