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

            Bug ID: 79697
           Summary: unused realloc(0, n) not eliminated
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC eliminates calls to allocation functions like malloc and calloc whose
return value is unused but fails to eliminate equivalent calls to realloc:

$ cat t.c && gcc -O2 -S -Wall -Wextra -Wpedantic -Wunused-result
-fdump-tree-optimized=/dev/stdout t.c
void f (void)
{
  __builtin_malloc (123);
}

void g (void)
{
  __builtin_realloc (0, 123);
}

;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f ()
{
  <bb 2> [100.00%]:
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1798, cgraph_uid=1, symbol_order=1)

g ()
{
  <bb 2> [100.00%]:
  __builtin_realloc (0B, 123); [tail call]
  return;

}

Reply via email to