public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46188] New: -fipa-cp removes destructor call
@ 2010-10-26 17:05 jens.maurer at gmx dot net
  2010-10-26 19:08 ` [Bug c++/46188] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: jens.maurer at gmx dot net @ 2010-10-26 17:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46188

           Summary: -fipa-cp removes destructor call
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jens.maurer@gmx.net


Created attachment 22164
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22164
source file to reproduce the bug

In the attached source code, the destructor calls for B::char_array when
destroying "c2" at the end of function "f" are removed by the optimizer when
compiling with -fipa-cp .

I have removed .cfi notes in the assembly quoted below, for conciseness.

bad compile:

$ g++  -S playground.cxx -fverbose-asm -O2

yields (note that no operator delete[] is called on B::char_array):

    159 .LEHB0:
    160         call    g(C const&, C&) #
    161 .LEHE0:
    162         movq    24(%rsp), %rdi  # c2.b_array.data, D.2822
    163         testq   %rdi, %rdi      # D.2822
    164         je      .L15    #,
    165         call    operator delete[](void*)        #
    166 .L15:
    167         movq    16(%rsp), %rdi  # c2.s.adr, D.2837
    168         testq   %rdi, %rdi      # D.2837
    169         je      .L14    #,
    170         call    operator delete[](void*)        #
    171 .L14:
    172         addq    $48, %rsp       #,
    175         popq    %rbx    #
    177         ret


good compile:

$ g++  -S playground.cxx -fverbose-asm -O2 -fno-ipa-cp

    165         call    g(C const&, C&) #
    166 .LEHE0:
    167         movq    8(%rsp), %rbx   # c2.b_array.data, p
    168         testq   %rbx, %rbx      # p
    169         je      .L15    #,
    170         movq    16(%rsp), %r12  # c2.b_array.size, D.2808
    171         testq   %r12, %r12      # D.2808
    172         je      .L16    #,
    173         xorl    %ebp, %ebp      # i
    174         jmp     .L20    #
    175         .p2align 4,,10
    176         .p2align 3
    177 .L25:
    178         addq    $24, %rbx       #, p
    179 .L20:
    180         movq    (%rbx), %rdi    # p->char_array.data, D.2820
    181         testq   %rdi, %rdi      # D.2820
    182         je      .L18    #,
    183         call    operator delete[](void*)        #
    184 .L18:
    185         addq    $1, %rbp        #, i
    186         cmpq    %rbp, %r12      # i, D.2808
    187         ja      .L25    #,
    188         movq    8(%rsp), %rbx   # c2.b_array.data, p
    189 .L16:
    190         testq   %rbx, %rbx      # p
    191         je      .L15    #,
    192         movq    %rbx, %rdi      # p,
    193         call    operator delete[](void*)        #
    194 .L15:
    195         movq    (%rsp), %rdi    # c2.s.adr, D.2824
    196         testq   %rdi, %rdi      # D.2824
    197         je      .L14    #,
    198         call    operator delete[](void*)        #
    199 .L14:
    200         addq    $32, %rsp       #,
    203         popq    %rbx    #
    205         popq    %rbp    #
    207         popq    %r12    #
    209         ret


Removing any one of the seemingly unrelated lines marked ##1, ##2, ##3 will
produce correct compiler output.  Also, messing with the Array::destruct
function (e.g. use "data + i" instead of "p", use the constants for start/end
directly instead of passing via parameters) will remove the problem.


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

end of thread, other threads:[~2011-04-19  9:03 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 17:05 [Bug c++/46188] New: -fipa-cp removes destructor call jens.maurer at gmx dot net
2010-10-26 19:08 ` [Bug c++/46188] " pinskia at gcc dot gnu.org
2010-10-26 21:09 ` jens.maurer at gmx dot net
2010-10-27  6:14 ` jens.maurer at gmx dot net
2010-10-27  7:55 ` jens.maurer at gmx dot net
2010-10-27 10:31 ` zsojka at seznam dot cz
2010-10-27 13:17 ` jens.maurer at gmx dot net
2010-10-27 13:18 ` jens.maurer at gmx dot net
2010-10-27 15:44 ` zsojka at seznam dot cz
2010-11-10 19:11 ` [Bug c++/46188] [4.5 regression] " jason at gcc dot gnu.org
2010-11-10 23:01 ` rguenth at gcc dot gnu.org
2010-11-12 14:18 ` rguenth at gcc dot gnu.org
2010-12-16 13:06 ` [Bug tree-optimization/46188] " rguenth at gcc dot gnu.org
2011-02-05 15:19 ` mikpe at it dot uu.se
2011-04-18 14:52 ` rguenth at gcc dot gnu.org
2011-04-18 15:33 ` rguenth at gcc dot gnu.org
2011-04-19  9:00 ` rguenth at gcc dot gnu.org
2011-04-19  9:03 ` rguenth at gcc dot gnu.org

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