From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30468 invoked by alias); 14 Dec 2002 10:56:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 30429 invoked by uid 71); 14 Dec 2002 10:56:01 -0000 Resent-Date: 14 Dec 2002 10:56:01 -0000 Resent-Message-ID: <20021214105601.30428.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, martin@xemacs.org Received: (qmail 24897 invoked by uid 61); 14 Dec 2002 10:46:35 -0000 Message-Id: <20021214104635.24896.qmail@sources.redhat.com> Date: Sat, 14 Dec 2002 02:56:00 -0000 From: martin@xemacs.org Reply-To: martin@xemacs.org To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/8936: Declaration of never defined member function changes generated code X-SW-Source: 2002-12/txt/msg00790.txt.bz2 List-Id: >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: