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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|out of bounds access makes  |out of bounds access
                   |a bounded loop infinite     |silently makes a bounded
                   |with inlining               |loop infinite with inlining

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Actually, I spoke too soon about the warning.  Calling f() with a value greater
than 7 suppresses the warning while keeping the loop unbounded:

$ cat x.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout x.c
struct { char a[4], b[4]; } x;

static inline void f0 (const char *s, int n)
{
  for (int i = 0; i != n; ++i)     // warning (good)...
    x.a[i] = s[i];
}

void f1 (const char *s)
{
  f0 (s, 9);                       // ...infinite loop (pr96509)
}

;; Function f1 (f1, funcdef_no=1, decl_uid=1943, cgraph_uid=2, symbol_order=2)
(executed once)

Merging blocks 3 and 4
f1 (const char * s)
{
  unsigned long ivtmp.5;
  char _6;

  <bb 2> [local count: 10631108]:

  <bb 3> [local count: 1073741824]:
  # ivtmp.5_11 = PHI <0(2), ivtmp.5_10(3)>
  _6 = MEM[base: s_2(D), index: ivtmp.5_11, offset: 0B];
  MEM[symbol: x, index: ivtmp.5_11, offset: 0B] = _6;
  ivtmp.5_10 = ivtmp.5_11 + 1;
  goto <bb 3>; [100.00%]

}

Reply via email to