public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: martin@xemacs.org
To: gcc-gnats@gcc.gnu.org
Subject: c++/8936: Declaration of never defined member function changes generated code
Date: Sat, 14 Dec 2002 02:56:00 -0000	[thread overview]
Message-ID: <20021214104635.24896.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-12-14 10:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-14  2:56 martin [this message]
2002-12-19 17:03 bangerth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021214104635.24896.qmail@sources.redhat.com \
    --to=martin@xemacs.org \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).