[PATCH] correct handling of indices into arrays with elements larger than 1 (PR c++/96511)

Martin Sebor msebor@gmail.com
Tue Aug 11 16:19:16 GMT 2020


-Wplacement-new handles array indices and pointer offsets the same:
by adjusting them by the size of the element.  That's correct for
the latter but wrong for the former, causing false positives when
the element size is greater than one.

In addition, the warning doesn't even attempt to handle arrays of
arrays.  I'm not sure if I forgot or if I simply didn't think of
it.

The attached patch corrects these oversights by replacing most
of the -Wplacement-new code with a call to compute_objsize which
handles all this correctly (plus more), and is also better tested.
But even compute_objsize has bugs: it trips up while converting
wide_int to offset_int for some pointer offset ranges.  Since
handling the C++ IL required changes in this area the patch also
fixes that.

For review purposes, the patch affects just the middle end.
The C++ diff pretty much just removes code from the front end.

Tested on x86_64-linux plus by building the latest Glibc and
confirming no new warnings.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-96511.diff
Type: text/x-patch
Size: 44051 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200811/2ace5f23/attachment-0001.bin>


More information about the Gcc-patches mailing list