[Bug middle-end/79349] New: unused std::string is not optimized away in presense of a call

hiraditya at msn dot com gcc-bugzilla@gcc.gnu.org
Thu Feb 2 22:52:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79349

            Bug ID: 79349
           Summary: unused std::string is not optimized away in presense
                    of a call
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

g++ version (GCC) 7.0.0 20170118 (experimental)

$ cat t.cpp

#include<string>
void foo();

int main() {
  std::string s("abc");
  foo ();
  return 0;
}

$ install/bin/g++ -O3 t.cpp -S -o t.s
$ cat t.s

main:
.LFB995:
        .cfi_startproc
        .cfi_personality 0x3,__gxx_personality_v0
        .cfi_lsda 0x3,.LLSDA995
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        subq    $32, %rsp
        .cfi_def_cfa_offset 48
        leaq    16(%rsp), %rax
        movb    $99, 18(%rsp)
        movq    $3, 8(%rsp)
        movb    $0, 19(%rsp)
        movq    %rax, (%rsp)
        movl    $25185, %eax
        movw    %ax, 16(%rsp)
.LEHB0:
        call    _Z3foov
.LEHE0:
        movq    (%rsp), %rdi
        leaq    16(%rsp), %rax
        cmpq    %rax, %rdi
        je      .L6
        call    _ZdlPv
.L6:
        addq    $32, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 16
        xorl    %eax, %eax
        popq    %rbx
        .cfi_def_cfa_offset 8
        ret
.L5:
        .cfi_restore_state
        movq    (%rsp), %rdi
        leaq    16(%rsp), %rdx
        movq    %rax, %rbx
        cmpq    %rdx, %rdi
        je      .L4
        call    _ZdlPv
.L4:
        movq    %rbx, %rdi
.LEHB1:
        call    _Unwind_Resume
.LEHE1:
        .cfi_endproc
.LFE995:
        .globl  __gxx_personality_v0
        .section        .gcc_except_table,"a",@progbits


While clang++ optimizes it away: clang version 5.0.0 (llvm-project SHA:
28b7c19c2379e17b26571260933467b9f98b449c)


$ ./bin/clang++ -O3 t.cpp -S -o t.s -stdlib=libc++
$ cat t.s

main:                                   # @main
        .cfi_startproc
# BB#0:                                 # %entry
        pushq   %rax
.Lcfi0:
        .cfi_def_cfa_offset 16
        callq   _Z3foov
        xorl    %eax, %eax
        popq    %rcx
        retq
.Lfunc_end0:
        .size   main, .Lfunc_end0-main
        .cfi_endproc


        .ident  "clang version 5.0.0 "
        .section        ".note.GNU-stack","",@progbits


More information about the Gcc-bugs mailing list