[PATCH] restore -Warray-bounds for string literals (PR 83776)

Martin Sebor msebor@gmail.com
Fri Jan 26 04:14:00 GMT 2018


PR tree-optimization/83776 - [6/7/8 Regression] missing
-Warray-bounds indexing past the end of a string literal,
identified a not-so-recent improvement to constant propagation
as the reason for GCC no longer being able to detect out-of-
bounds accesses to string literals.  The root cause is that
the change caused accesses to strings to be transformed into
MEM_REFs that the -Warray-bounds checker isn't prepared to
handle.  A simple example is:

   int h (void)
   {
     const char *p = "1234";
     return p[16];   // missing -Warray-bounds
   }

To fix the regression the attached patch extends the array bounds
checker to handle the small subset of MEM_REF expressions that
refer to string literals but stops of short of doing more than
that.  There are outstanding gaps in the detection that the patch
intentionally doesn't handle.  They are either caused by other
regressions (PR 84047) or by other latent bugs/limitations, or
by limitations in the approach I took to try to keep the patch
simple.  I hope to address some of those in a follow-up patch
for GCC 9.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-83776.diff
Type: text/x-patch
Size: 29434 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180126/4bb25568/attachment.bin>


More information about the Gcc-patches mailing list