public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Martin Sebor <msebor@gmail.com>,
	Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] add support for strnlen (PR 81384)
Date: Tue, 12 Jun 2018 21:11:00 -0000	[thread overview]
Message-ID: <5bbc3729-6c5e-3aa4-556a-f56ee4636e63@redhat.com> (raw)
In-Reply-To: <d72c0492-28aa-0d90-ee82-53520583bb73@gmail.com>

On 06/05/2018 03:43 PM, Martin Sebor wrote:
> The attached patch adds basic support for handling strnlen
> as a built-in function.  It touches the strlen pass where
> it folds constant results of the function, and builtins.c
> to add simple support for expanding strnlen calls with known
> results.  It also changes calls.c to detect excessive bounds
> to the function and unsafe calls with arguments declared
> attribute nonstring.
> 
> A side-effect of the strlen change I should call out is that
> strlen() calls to all zero-length arrays that aren't considered
> flexible array members (i.e., internal members or non-members)
> are folded into zero.  No warning is issued for such invalid
> uses of zero-length arrays but based on the responses to my
> question Re: aliasing between internal zero-length-arrays and
> other members(*) it sounds like one would be appropriate.
> I will see about adding one in a separate patch.
> 
> Martin
> 
> [*] https://gcc.gnu.org/ml/gcc/2018-06/msg00046.html
> 
> gcc-81384.diff
> 
> 
> PR tree-optimization/81384 - built-in form of strnlen missing
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/81384
> 	* builtin-types.def (BT_FN_SIZE_CONST_STRING_SIZE): New.
> 	* builtins.c (expand_builtin_strnlen): New function.
> 	(expand_builtin): Call it.
> 	(fold_builtin_n): Avoid setting TREE_NO_WARNING.
> 	* builtins.def (BUILT_IN_STRNLEN): New.
> 	* calls.c (maybe_warn_nonstring_arg): Handle BUILT_IN_STRNLEN.
> 	Warn for bounds in excess of maximum object size.
> 	* tree-ssa-strlen.c (maybe_set_strlen_range): Return tree representing
> 	single-value ranges.  Handle strnlen.
> 	(handle_builtin_strlen): Handle strnlen.
> 	(strlen_check_and_optimize_stmt): Same.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/81384
> 	* gcc.c-torture/execute/builtins/lib/strnlen.c: New test.
> 	* gcc.c-torture/execute/builtins/strnlen-lib.c: New test.
> 	* gcc.c-torture/execute/builtins/strnlen.c: New test.
> 	* gcc.dg/attr-nonstring-2.c: New test.
> 	* gcc.dg/attr-nonstring-3.c: New test.
> 	* gcc.dg/attr-nonstring-4.c: New test.
> 	* gcc.dg/strlenopt-44.c: New test.
> 	* gcc.dg/strlenopt.h (strnlen):  Declare.
> 
> diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
> index 5365bef..1f15350 100644
> --- a/gcc/builtin-types.def
> +++ b/gcc/builtin-types.def
> @@ -322,6 +322,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_STRING_CONST_STRING_INT,
>  		     BT_STRING, BT_CONST_STRING, BT_INT)
>  DEF_FUNCTION_TYPE_2 (BT_FN_STRING_CONST_STRING_SIZE,
>  		     BT_STRING, BT_CONST_STRING, BT_SIZE)
> +DEF_FUNCTION_TYPE_2 (BT_FN_SIZE_CONST_STRING_SIZE,
> +		     BT_SIZE, BT_CONST_STRING, BT_SIZE)
>  DEF_FUNCTION_TYPE_2 (BT_FN_INT_CONST_STRING_FILEPTR,
>  		     BT_INT, BT_CONST_STRING, BT_FILEPTR)
>  DEF_FUNCTION_TYPE_2 (BT_FN_INT_INT_FILEPTR,
I believe Jakub already suggested these change and you ack'd that.

You have some hunks which will need updating now that the CHKP/MPX bits
are gone.

So OK after the cleanups noted above and a fresh bootstrap & regression
test cycle.

jeff

  parent reply	other threads:[~2018-06-12 21:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 21:43 Martin Sebor
2018-06-05 22:20 ` Jakub Jelinek
2018-06-06 15:14   ` Martin Sebor
2018-06-06 15:49     ` Jakub Jelinek
2018-06-06  0:39 ` Eric Gallager
2018-06-06 14:44   ` Martin Sebor
2018-06-12 15:10 ` PING " Martin Sebor
2018-06-12 21:11 ` Jeff Law [this message]
2018-06-18 16:35   ` Martin Sebor
2018-07-09 14:36     ` Aldy Hernandez
2018-07-09 19:51       ` Jeff Law
2018-07-09 20:51         ` Martin Sebor
2018-07-09 21:26       ` Martin Sebor
2018-07-10  7:13         ` Richard Biener
2018-07-10 14:10           ` Martin Sebor
2018-07-10 14:25             ` Richard Biener
2018-07-10 14:34               ` Jeff Law
2018-07-10 14:57                 ` Martin Sebor
2018-06-19 19:33 David Edelsohn
2018-06-19 20:10 ` Martin Sebor
2018-06-19 20:25   ` Martin Sebor
2018-06-20  5:24   ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5bbc3729-6c5e-3aa4-556a-f56ee4636e63@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).