[Bug bootstrap/90918] New: -Wreturn-local-addr in __splitstack_find in libgcc/generic-morestack.c

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 18 18:02:00 GMT 2019


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

            Bug ID: 90918
           Summary: -Wreturn-local-addr in __splitstack_find in
                    libgcc/generic-morestack.c
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While testing an enhancement to the -Wreturn-local-addr warning I get the
following instance of it for the code in libgcc below:

/ssd/test/src/71924/libgcc/generic-morestack.c: In function
‘__splitstack_find’:
cc1: warning: function may return address of local variable
[-Wreturn-local-addr]
/ssd/test/src/71924/libgcc/generic-morestack.c:853:25: note: declared here
  853 |   struct stack_segment *segment;
      |                         ^~~~~~~


The warning looks justified:

void *
__splitstack_find (void *segment_arg, void *sp, size_t *len,
                   void **next_segment, void **next_sp,
                   void **initial_sp)
{
  struct stack_segment *segment;   <<< local
  void *ret;
  char *nsp;
  ...
  else
    {
      *initial_sp = __morestack_initial_sp.sp;
      segment = __morestack_current_segment;
      sp = (void *) &segment;      <<< assign address of a local to sp
      ...
  }
  ...
#ifdef __LIBGCC_STACK_GROWS_DOWNWARD__
  *len = (char *) (segment + 1) + segment->size - (char *) sp;
  ret = (void *) sp;               <<< assign sp to ret
#else
  *len = (char *) sp - (char *) (segment + 1);
  ret = (void *) (segment + 1);
#endif

  return ret;                      <<< return &segment
}


More information about the Gcc-bugs mailing list