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

            Bug ID: 87732
           Summary: Detect and eliminate unnecessary alloc/free pairs
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugzi...@poradnik-webmastera.com
  Target Milestone: ---

[code]
void foo()
{
    char* c = new char[4];
    delete[] c;
}
[/code]

gcc with -O3 generates this:

[asm]
foo():
        sub     rsp, 8
        mov     edi, 4
        call    operator new[](unsigned long)
        add     rsp, 8
        mov     rdi, rax
        jmp     operator delete[](void*)
[/asm]

clang 7.0.0 is able to remove unnecessary alloc/free pair:

[asm]
foo():                                # @foo()
        ret
[/asm]

Please do similar thing in gcc too.

Reply via email to