This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] use EVRP in more strlen functions


On 10/28/19 4:44 PM, Jeff Law wrote:
On 10/28/19 4:36 PM, Martin Sebor wrote:
While testing the patch for PR 92226 I posted earlier today
I ran into a few cases where I expected the strlen range
optimization to take place but it didn't.

In other instances this wouldn't be surprising because
the optimization was only introduced for multi-character stores
and with the expectation that it would be slowly extended to
other functions over time.  But these cases were among those
the optimization was meant to be in place for, so its absence
is an oversight.  The attached near-trivial patch fills this
gap.

As with all these changes, enabling the optimization also makes
it possible to detect more instances of buffer overflow.

Tested on x86_64-linux.

Martin

PS There are quite a few remaining opportunities to make use of
the strlen ranges in the pass.  Rather than enhancing the whole
pass in one go I think it will be safer to do it one small step
at a time, using little patchlets like in the attachment.

gcc-92226-2.diff

gcc/ChangeLog:

	* tree-ssa-strlen.c (get_addr_stridx): Add argument and use it.
	(handle_store): Pass argument to get_addr_stridx.

gcc/testsuite/ChangeLog:

	* gcc.dg/strlenopt-89.c: New test.
	* gcc.dg/strlenopt-90.c: New test.
	* gcc.dg/Wstringop-overflow-20.c: New test.
OK.  And patches which do similar stuff (arranging to pass down the
range info) are pre-approved.

Sounds good, thanks.

Martin

PS I have a few other things in flight so don't expect to do much
more work on this before stage 1 closes, but I should be able to
get it all done for GCC 11.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]