[Bug fortran/101919] Inconsistent -Wstringop-overread warning with -flto

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 9 19:35:06 GMT 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |97048
                 CC|                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
      Known to fail|                            |11.2.0, 12.0
   Last reconfirmed|                            |2021-11-09

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with 11 and top of trunk.  I think there are two problems: 1)
-Wstringop-overread is a C/C++ only option that shouldn't be issued for FORTRAN
code, and 2) the code the warning triggers for in the IL does look invalid:

  <bb 3> [local count: 536870913]:
  _8 = _gfortran_string_len_trim (100, &c);
  _9 = (integer(kind=4)) _8;
  _10 = (integer(kind=8)) _9;
  if (_10 <= 111)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 5> [local count: 268435456]:
  __builtin_memmove (&c, &c[13]{lb: 1 sz: 1}, 100);   <<< warning here

If I'm reading the FORTRAN code right, c is an array of 100 characters.  The
memmove call copies 100 characters from &c[13], which would make the copy out
of bounds.

(1) is a known problem.  We don't have a way to describe language-specific
options at the LTO level.  They're either LTO options ore they're not, so we
either enable them for all languages or for none.

(2) is an optimizer problem.  It should not be emitting clearly invalid code.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97048
[Bug 97048] [meta-bug] bogus/missing -Wstringop-overread warnings


More information about the Gcc-bugs mailing list