On Thu, Mar 23, 2023 at 02:37:01PM -0400, Andrew MacLeod via Gcc-patches wrote:
> PS I have not managed to produce a reduced testcase yet.. If I do I will
> supply it.

Here is one:
/* PR tree-optimization/10923 */
/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */

void foo (void *) __attribute__((noreturn));
void bar (void *);

void
baz (void *p)
{
  void *c = __builtin_realloc (p, 16);
  if (c)
    foo (c);
  for (;;)
    bar (__builtin_realloc (p, 8));     /* { dg-bogus "pointer 'p' may be used 
after '__builtin_realloc'" } */
}

Better than what I've attached in the PR, because this one actually
doesn't contain a leak.  If first realloc fails, foo can still free it and
exit, if first realloc fails, bar will be called with result of second
realloc and can exit there too.  Oh, it would need global variable from
caller to pas p to it in case even the second realloc fails.

        Jakub

Reply via email to