On 05/29/2018 01:21 PM, Martin Sebor wrote:
> To make review and testing easier (thank you, Franz), attached
> is an updated patch rebased on top of today's trunk.
> 
> (Note that the patch intentionally doesn't suppress the warning
> for the submitted test case without adding the nonstring attribute.)
> 
> On 05/25/2018 02:59 PM, Martin Sebor wrote:
>> Ping:
>> https://gcc.gnu.org/ml/gcc-patches/2018-05/msg00869.html
>>
>> On 05/17/2018 08:01 PM, Martin Sebor wrote:
>>> The -Wstringop-truncation and -Wsizeof-pointer-memaccess warnings
>>> I added and enhanced, respectively, in GCC 8 are arguably overly
>>> strict for source arguments declared with the nonstring attribute.
>>>
>>> For example, -Wsizeof-pointer-memaccess triggers for the strncat
>>> call below:
>>>
>>>   __attribute__ ((nonstring)) char nonstr[8];
>>>   extern char *d;
>>>   strncat (d, nonstr, sizeof nonstr);
>>>
>>> even though it's still a fairly common (if unsafe) idiom from
>>> the early UNIX days (V7 from 1979 to be exact) where strncat
>>> was introduced.  (This use case, modulo the attribute, was
>>> reduced from coreutils.)
>>>
>>> Simialrly, -Wstringop-truncation warns for some strcat calls that
>>> are actually safe, such as in:
>>>
>>>   strcpy (nonstr, "123");
>>>   strncat (d, nonstr, 32);
>>>
>>> To help with the adoption of the warnings and the attribute and
>>> avoid unnecessary churn the attached patch relaxes both warnings
>>> to accept code like this without diagnostics.
>>>
>>> The patch doesn't add any new warnings so I'd like it considered
>>> for GCC 8 in addition to trunk.
>>>
>>> Thanks
>>> Martin
>>
> 
> 
> gcc-85602.diff
> 
> 
> PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of 
> source
> 
> gcc/c-family/ChangeLog:
> 
>       PR middle-end/85602
>       * c-warn.c (sizeof_pointer_memaccess_warning): Check for attribute
>       nonstring.
> 
> gcc/ChangeLog:
> 
>       PR middle-end/85602
>       * calls.c (maybe_warn_nonstring_arg): Handle strncat.
>       * tree-ssa-strlen.c (is_strlen_related_p): Make extern.
>       Handle integer subtraction.
>       (maybe_diag_stxncpy_trunc): Handle nonstring source arguments.
>       * tree-ssa-strlen.h (is_strlen_related_p): Declare.
> 
> gcc/testsuite/ChangeLog:
> 
>       PR middle-end/85602
>       * c-c++-common/attr-nonstring-8.c: New test.
I wonder if get_attr_nonstring_decl belongs somewhere other than
calls.[ch].  It's really got nothing to do with calls.  That might be a
followup cleanup.

I suspect some of the hunks  need updating now that MPX is gone.  In
particular you no longer need to worry about _BND calls which should
simplify things somewhat.

OK for the trunk after updating for MPX removal and re-bootstrapping &
testing.

jeff



Reply via email to