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

            Bug ID: 109141
           Summary: failure to diagnose -Wuse-after-free early
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc.dg/Wuse-after-free-2.c contains

int warn_cond_loop (char *p)
{
  char *q = p;

  /*  -fno-tree-loop-distribute-patterns ensures this does not get converted
      into rawmemchr (making q and p unrelated).  Also, -fno-ivopts is required
      for some targets, to not lose track of the pointer.  */
  while (*q)
    ++q;

  free (p);         // { dg-message "call to 'free'" }
  return *q;        // { dg-warning "pointer 'q' used after 'free'" }
}

which only is diagnosed in the late access warning pass.  If you enable
-Wuse-after-free in the early passes it isn't diagnosed even though the
IL isn't very different.  This looks like an issue in handling PHIs
in pointer query?

Reply via email to