This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] accept attribute nonstring on all narrow characters (PR 84725)
- From: Jeff Law <law at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 12 Mar 2018 17:13:59 -0600
- Subject: Re: [PATCH] accept attribute nonstring on all narrow characters (PR 84725)
- Authentication-results: sourceware.org; auth=none
- References: <bfbe80e5-f07c-c040-38ca-86097aad9384@gmail.com>
On 03/05/2018 01:54 PM, Martin Sebor wrote:
> Attribute nonstring is currently only allowed on arrays and
> pointers to plain char, but -Wstringop-truncation triggers
> even for strncpy calls whose arguments are arrays of signed
> or unsigned char (with or without a cast to char*).
>
> To help deal with -Wstringop-truncation in the Linux kernel
> it was suggested to me that it would be useful to be able
> to make use of the attribute on all three narrow char types.
> Apparently, there are enough calls to strncpy in the Linux
> kernel with arguments of the other char types that trigger
> the new warning, and the warning is considered sufficiently
> useful that making use of the attribute to suppress
> the warning rather than changing it ignore the other
> two char types is preferable.
>
> The attached patch relaxes the restriction and lets GCC
> accept attribute nonstring on all three narrow character
> types as well as their qualified forms.
>
> Tested on x86_64-linux.
>
> Martin
>
> gcc-84725.diff
>
>
> PR tree-optimization/84725 - enable attribute nonstring for all narrow character types
>
> gcc/c-family/ChangeLog:
>
> PR tree-optimization/84725
> * c-attribs.c (handle_nonstring_attribute): Allow attribute nonstring
> with all three narrow character types, including their qualified forms.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/84725
> * c-c++-common/Wstringop-truncation-4.c: New test.
> * c-c++-common/attr-nonstring-5.c: New test.
While it's not a regression, I think getting this warning to a point
where it's usable by the linux kernel is a notable win. So I'm going to
ACK it as an exception to the regression bugfixes only policy.
jeff