[Bug tree-optimization/87314] pointless comparison of malloc result to a string not eliminated

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Sep 14 21:37:00 GMT 2018


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

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Same here (Clang doesn't eliminate the test here though):

void f (void)
{
  void *p = __builtin_malloc (sizeof (void*));

  if (p == f)   // not folded
    __builtin_abort ();
}

Here, GCC eliminates the equality test with a but not the one with b (Clang
eliminates neither):

char a[8] = "";
char b[8];

void f (void)
{
  void *p = __builtin_malloc (sizeof (void*));

  if (p == a)   // folded to false
    __builtin_abort ();
}

void g (void)
{
  void *p = __builtin_malloc (sizeof (void*));

  if (p == b)   // not folded
    __builtin_abort ();
}


More information about the Gcc-bugs mailing list