[PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-12 Thread Martin Sebor
The recently introduced -Wstringop-truncation warning relies on the new nonstring attribute to allow the historical use case of calling strncpy to completely fill the destination with a copy of a string without adding a terminating nul. Glibc is currently considering making use of the attribute t

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-13 Thread Bernhard Reutner-Fischer
On 13 November 2017 01:52:41 CET, Martin Sebor wrote: s/^\(he array\)/t\1/ thanks,

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-13 Thread Jakub Jelinek
On Sun, Nov 12, 2017 at 05:52:41PM -0700, Martin Sebor wrote: > + the referenced enclosing object or pointer. Otherwise return > + null. */ > + > +tree > +get_attr_nonstring_decl (tree expr, tree *ref) > +{ > + tree dcl = expr; Usually we call vars decl, not dcl. Or what does it stand for?

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-13 Thread Martin Sebor
On 11/13/2017 12:20 PM, Jakub Jelinek wrote: On Sun, Nov 12, 2017 at 05:52:41PM -0700, Martin Sebor wrote: + the referenced enclosing object or pointer. Otherwise return + null. */ + +tree +get_attr_nonstring_decl (tree expr, tree *ref) +{ + tree dcl = expr; Usually we call vars decl, n

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-13 Thread Martin Sebor
Attached is an improved version that rather than hardcoding the built-in functions to check uses the constness of each built-in's char* argument as a trigger to do the checking. This avoids the problem of the list being incomplete either by omission or due to getting out of sync, and also makes i

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-16 Thread Jeff Law
On 11/13/2017 06:21 PM, Martin Sebor wrote: > Attached is an improved version that rather than hardcoding > the built-in functions to check uses the constness of each > built-in's char* argument as a trigger to do the checking. > > This avoids the problem of the list being incomplete either > by o

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-16 Thread Jakub Jelinek
On Thu, Nov 16, 2017 at 05:15:20PM -0700, Jeff Law wrote: > > + tree_code code = gimple_assign_rhs_code (def); > > + if (code == ADDR_EXPR > > + || code == COMPONENT_REF > > + || code == VAR_DECL) > > + dcl = gimple_assign_rhs1 (def); > Note that CO

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-19 Thread Martin Sebor
On 11/16/2017 05:15 PM, Jeff Law wrote: On 11/13/2017 06:21 PM, Martin Sebor wrote: Attached is an improved version that rather than hardcoding the built-in functions to check uses the constness of each built-in's char* argument as a trigger to do the checking. This avoids the problem of the li

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-19 Thread Martin Sebor
On 11/16/2017 05:15 PM, Jeff Law wrote: On 11/13/2017 06:21 PM, Martin Sebor wrote: Attached is an improved version that rather than hardcoding the built-in functions to check uses the constness of each built-in's char* argument as a trigger to do the checking. This avoids the problem of the li

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-19 Thread Martin Sebor
On 11/17/2017 12:47 AM, Jakub Jelinek wrote: On Thu, Nov 16, 2017 at 05:15:20PM -0700, Jeff Law wrote: + tree_code code = gimple_assign_rhs_code (def); + if (code == ADDR_EXPR + || code == COMPONENT_REF + || code == VAR_DECL) +

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-19 Thread Jeff Law
On 11/19/2017 10:06 AM, Martin Sebor wrote: >>> +/* If EXPR refers to a character array or pointer declared attribute >>> +   nonstring return a decl for that array or pointer and set *REF to >>> +   the referenced enclosing object or pointer.  Otherwise returns >>> +   null.  */ >> Generally we'd

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-19 Thread Martin Sebor
I have seen it in the early IL but this late I couldn't come up with a test case where such a loop would be necessary. The COMPONENT_REF always refers to the member array. If you can show me an example to test with I'll add the handling if possible. There are cases where it isn't, such as in

Re: [PATCH] detect nonstring arguments to string functions (PR 82945)

2017-11-20 Thread Jeff Law
On 11/19/2017 03:26 PM, Martin Sebor wrote: >>> I have seen it in the early IL but this late I couldn't come >>> up with a test case where such a loop would be necessary. >>> The COMPONENT_REF always refers to the member array.  If you >>> can show me an example to test with I'll add the handling i