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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
As an aside, the infinite recursion could (and in the future, should) be
detected by -Winfinite-recursion.  It was mentioned as a possible future
enhancement for the warning at the time it was submitted for review
(https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584205.html).  Here's
a simpler test case where it already is detected.  Detecting the problem in the
loopy case in comment #0 requires running that subset of the detection later
(e.g., just before expansion).

$ cat pr103858.c && gcc -S -Wall -fdump-tree-einline=/dev/stdout pr103858.c
#include <stddef.h>

size_t strlen(const char* str)
{
  size_t len = __builtin_strlen (str);
  return len;
}

;; Function strlen (strlen, funcdef_no=0, decl_uid=955, cgraph_uid=1,
symbol_order=0)

__attribute__((nothrow, leaf, pure))
__attribute__((nonnull))
size_t strlen (const char * str)
{
  size_t len;
  size_t D.1990;
  size_t _4;

  <bb 2> :
  len_3 = __builtin_strlen (str_2(D));
  _4 = len_3;

  <bb 3> :
<L0>:
  return _4;

}


pr103858.c: In function ‘strlen’:
pr103858.c:3:8: warning: infinite recursion detected [-Winfinite-recursion]
    3 | size_t strlen(const char* str)
      |        ^~~~~~
pr103858.c:5:16: note: recursive call
    5 |   size_t len = __builtin_strlen (str);
      |                ^~~~~~~~~~~~~~~~~~~~~~

Reply via email to