[Darwin, testsuite, committed] Fix Wnonnull on Darwin.

Iain Sandoe iain@sandoe.co.uk
Tue Oct 22 06:47:00 GMT 2019


Iain Sandoe <iain@sandoe.co.uk> wrote:

> Martin Sebor <msebor@gmail.com> wrote:
> 
>> On 10/20/2019 07:27 AM, Iain Sandoe wrote:
>>> Martin Sebor <msebor@gmail.com> wrote:
>>>> On 10/19/19 2:56 AM, Iain Sandoe wrote:
>>>>> Andreas Schwab <schwab@linux-m68k.org> wrote:
>>>>>> On Okt 19 2019, Iain Sandoe <iain@sandoe.co.uk> wrote:
>>>>>> 
>>>>>>> This test has failed always on Darwin, because Darwin does not mark
>>>>>>> entries in string.h with nonnull attributes.  Since the purpose of the test
>>>>>>> is to check that the warnings are issued for an inlined function, not that
>>>>>>> the target headers are marked up, we can provide locally marked up
>>>>>>> function declarations for Darwin.
>>>>>> 
>>>>>> If the test depends on the non-std declarations, then it should use them
>>>>>> everywhere.
>>>>> from my perspective, agreed, Martin?
>>>> 
>>>> I don't see a problem with it.  I prefer tests that don't depend
>>>> on system headers to avoid these kinds of issues
>>> We can do that anyway then, - I can just adjust the current code tor remove the
>>> special-casing, and to use __SIZE_TYPE__ instead of size_t everywhere, OK?
>> 
>> Sure.
> 
> Will try to get to it later today.

This is what I committed (will sort out backports, in due course).
tested on x86_64-linux-gnu and x86-64-darwin16.
thanks
Iain

===

[testsuite] Make the Wnonnull independent of system headers.

To avoid the result of this test depending on the implementation of
the system 'string.h', provide prototypes for the two functions used
in the test.

gcc/testsuite/ChangeLog:

2019-10-22  Iain Sandoe  <iain@sandoe.co.uk>

	* gcc.dg/Wnonnull.c: Provide prototypes for strlen and memcpy.
	Use __SIZE_TYPE__ instead of size_t.


diff --git a/gcc/testsuite/gcc.dg/Wnonnull.c b/gcc/testsuite/gcc.dg/Wnonnull.c
index a165baa99f..0ed06aabe6 100644
--- a/gcc/testsuite/gcc.dg/Wnonnull.c
+++ b/gcc/testsuite/gcc.dg/Wnonnull.c
@@ -2,16 +2,10 @@
    { dg-do compile }
    { dg-options "-O2 -Wall" } */
 
-#ifndef __APPLE__
-#include <string.h>
-#else
-/* OSX headers do not mark up the nonnull elements yet.  */
-# include <stddef.h>
-extern size_t strlen (const char *__s)
-		      __attribute ((pure)) __attribute ((nonnull (1)));
+extern __SIZE_TYPE__ strlen (const char *__s)
+			     __attribute ((pure)) __attribute ((nonnull (1)));
 extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
-		     size_t __n) __attribute ((nonnull (1, 2)));
-#endif
+		     __SIZE_TYPE__ __n) __attribute ((nonnull (1, 2)));
 
 char buf[100];
 
@@ -23,9 +17,9 @@ struct Test
 
 __attribute ((nonnull (1, 2)))
 inline char*
-my_strcpy (char *restrict dst, const char *restrict src, size_t size)
+my_strcpy (char *restrict dst, const char *restrict src, __SIZE_TYPE__ size)
 {
-  size_t len = strlen (src);        /* { dg-warning "argument 1 null where non-null expected" } */
+  __SIZE_TYPE__ len = strlen (src); /* { dg-warning "argument 1 null where non-null expected" } */
   if (len < size)
     memcpy (dst, src, len + 1);     /* { dg-warning "argument 2 null where non-null expected" } */
   else



More information about the Gcc-patches mailing list