[Bug tree-optimization/103858] [12 Regression] strlen() implementation is optimized into a call to strlen() at -O2, causing infinite recursion

2022-01-04 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103858

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #2 from Martin Sebor  ---
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 

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;

   :
  len_3 = __builtin_strlen (str_2(D));
  _4 = len_3;

   :
:
  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);
  |^~

[Bug tree-optimization/103858] [12 Regression] strlen() implementation is optimized into a call to strlen() at -O2, causing infinite recursion

2021-12-29 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103858

Martin Liška  changed:

   What|Removed |Added

 CC||marxin at gcc dot gnu.org
 Resolution|--- |DUPLICATE
 Status|UNCONFIRMED |RESOLVED

--- Comment #1 from Martin Liška  ---
Dup.

*** This bug has been marked as a duplicate of bug 102725 ***