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

            Bug ID: 87628
           Summary: Redundant check of pointer when delete is called
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

https://godbolt.org/z/DY9ruv

void if_delete(char *p) {
    if (p) {
        delete(p);
    }
}

$ gcc-8.2 -Os -fno-exceptions

if_delete(char*):
  test rdi, rdi
  je .L1
  mov esi, 1
  jmp operator delete(void*, unsigned long)
.L1:
  ret


While clang removes the check at -Oz:

$ clang -Oz -fno-exceptions
if_delete(char*):
        jmp     operator delete(void*)

Reply via email to