On Fri, Mar 07, 2025 at 09:41:15PM -0800, Kees Cook wrote:
> On Tue, Feb 18, 2025 at 11:51:41AM -0800, Kees Cook wrote:
> > On Fri, Feb 14, 2025 at 11:21:07AM +0100, Jakub Jelinek wrote:
> > > On Thu, Feb 13, 2025 at 02:10:25PM +0100, Jakub Jelinek wrote:
> > > > Kees, are you submitting this under assignment to FSF (maybe the Google 
> > > > one
> > > > if it has one) or DCO?  See https://gcc.gnu.org/contribute.html#legal
> > > > for details.  If DCO, can you add your Signed-off-by: tag for it?
> > > > 
> > > > So far lightly tested, ok for trunk if it passes bootstrap/regtest?
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux successfully.
> > 
> > Thank you for getting this done! I really appreciate having this
> > available. I'll give it a spin. :)
> 
> Sorry this took me so long. I finally tested this and while it does
> allow setting nonstring on multi-dim char arrays, it looks like the
> initializer check is still broken:
> 
> $ cat multi.c
> const char table_sigs[][4] __attribute__((nonstring)) = {
>         "BERT", "BGRT", "CPEP", "ECDT"
> };
> $ gcc -o multi.o -c multi.c -O2 -Wall -Wunterminated-string-initialization
> multi.c:2:9: warning: initializer-string for array of 'char' truncates NUL 
> terminator but destination lacks 'nonstring' attribute (5 chars into 4 
> available) [-Wunterminated-string-initialization]
>     2 |         "BERT", "BGRT", "CPEP", "ECDT"
>       |         ^~~~~~
> multi.c:2:17: warning: initializer-string for array of 'char' truncates NUL 
> terminator but destination lacks 'nonstring' attribute (5 chars into 4 
> available) [-Wunterminated-string-initialization]
>     2 |         "BERT", "BGRT", "CPEP", "ECDT"
>       |                 ^~~~~~
> ...
> 
> It looks like get_attr_nonstring_decl() still isn't correctly finding
> the attribute. (It looks like multi-dimensional static initializers
> tests that drop the NUL are missing in commit ab714e60870d.)
> 
> And to answer your earlier question about Linux's use, while we have
> the __nonstring macro for applying the attribute, I intend to add
> __nonstring_array that is version-checked against GCC 15.

Hi! Thanks again for continuing to poke at this. Even with commit
1301e18f69ce ("gimple-ssa-warn-access: Adjust maybe_warn_nonstring_arg
for nonstring multidimensional arrays [PR117178]"), this is still not
working. Does the above test pass for you? I still get warnings with
the latest ToT GCC.

Can you add a test like the above? Perhaps this, which should emit no
warning:


diff --git a/gcc/testsuite/c-c++-common/attr-nonstring-11.c 
b/gcc/testsuite/c-c++-common/attr-nonstring-11.c
index 745e99382fe3..5e722df0d641 100644
--- a/gcc/testsuite/c-c++-common/attr-nonstring-11.c
+++ b/gcc/testsuite/c-c++-common/attr-nonstring-11.c
@@ -417,6 +417,7 @@ void test_strlen (struct MemArrays *p, char *s NONSTRING, 
size_t n)
   }
 }
 
+const char drop_nul[][4] __attribute__ ((nonstring)) = { "ABCD", "1234" };
 
 void test_strnlen (struct MemArrays *p, size_t n)
 {

-- 
Kees Cook

Reply via email to