[Bug middle-end/96900] [12/13/14/15 Regression] bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 10 03:13:27 GMT 2025


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |false-positive

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the location is messed up starting in GCC 12.

GCC 11 gave:
<source>: In function 'int g()':
<source>:13:27: warning: offset '1' outside bounds of constant string
[-Warray-bounds]
   13 |   return __builtin_strlen (p - sizeof s.a);    // bogus -Warray-bounds
      |          ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~

GCC 12 gives:
<source>: In function 'int g()':
<source>:10:5: warning: offset '1' outside bounds of constant string
[-Warray-bounds]
   10 | int g (void)
      |     ^


Looks like c_strlen could use a loc argument but that is a huge huge change.


More information about the Gcc-bugs mailing list