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

            Bug ID: 94312
           Summary: missing -Wreturn-local-addr on returning local address
                    via memchr
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wreturn-local-addr diagnoses only the first function below.  It misses the
same problem in the second function.  The root cause is a missing label for
BUILT_IN_MEMCHR in is_addr_local in gimple-ssa-isolate-paths.c (it was
accidentally omitted in r273261).

$ cat x.c && gcc -O2 -S -Wall x.c
void* f (char x)
{ 
  char a[] = { x, x + 1 };
  return __builtin_strchr (a, 0);   // -Wreturn-local-addr (okay)
}

void* g (char x)
{
  char a[] = { x, x + 1 };
  return __builtin_memchr (a, 0, sizeof a);   // missing -Wreturn-local-addr
}
x.c: In function ‘f’:
x.c:4:10: warning: function returns address of local variable
[-Wreturn-local-addr]
    4 |   return __builtin_strchr (a, 0);   // -Wreturn-local-addr (okay)
      |          ^~~~~~~~~~~~~~~~~~~~~~~
x.c:3:8: note: declared here
    3 |   char a[] = { x, x + 1 };
      |        ^

Reply via email to