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

            Bug ID: 87314
           Summary: pointless comparison of malloc result to a string not
                    eliminated
           Product: gcc
           Version: 9.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 fails to eliminate the impossible test in the test case below (despite the
warning).  Clang eliminates it as expected.

$ cat x.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout x.c
void f (void)
{
  char *p = __builtin_malloc (8);

  if (p == "")
    __builtin_abort ();
}
x.c: In function ‘f’:
x.c:5:9: warning: comparison with string literal results in unspecified
behavior [-Waddress]
5 |   if (p == "")
  |         ^~

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

f ()
{
  char * p;

  <bb 2> [local count: 1073741824]:
  p_3 = __builtin_malloc (8);
  if (p_3 == "")
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073312328]:
  return;

}

Reply via email to