This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/80331] New: unused const std::string not optimized away
- From: "hiraditya at msn dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 05 Apr 2017 16:50:56 +0000
- Subject: [Bug libstdc++/80331] New: unused const std::string not optimized away
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80331
Bug ID: 80331
Summary: unused const std::string not optimized away
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hiraditya at msn dot com
Target Milestone: ---
$ cat t.cpp
#include<string>
int sain() {
const std::string s("a");
return 0;
}
# gcc version 7.0.0 20170118 (experimental) (GCC)
$ g++ -S -o t.s t.cpp -O2 -fno-exceptions -std=c++11
$ cat t.s
.type _Z4sainv, @function
_Z4sainv:
.LFB940:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
movl $.LC0+1, %esi
subq $32, %rsp
.cfi_def_cfa_offset 48
leaq 16(%rsp), %rbx
movq %rsp, %rdi
movq %rbx, (%rsp)
call
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag.isra.16.constprop.20
movq (%rsp), %rdi
cmpq %rbx, %rdi
je .L13
call _ZdlPv
.L13:
addq $32, %rsp
.cfi_def_cfa_offset 16
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE940:
.size _Z4sainv, .-_Z4sainv
clang++, on the other hand, completely optimizes the const string.
.type _Z4sainv,@function
_Z4sainv: # @_Z4sainv
.cfi_startproc
# BB#0:
xorl %eax, %eax
retq
.Lfunc_end0:
.size _Z4sainv, .Lfunc_end0-_Z4sainv