This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/46188] New: -fipa-cp removes destructor call
- From: "jens.maurer at gmx dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 26 Oct 2010 17:05:26 +0000
- Subject: [Bug c++/46188] New: -fipa-cp removes destructor call
- Auto-submitted: auto-generated
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.