public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Synchronize <sys/cdefs.h> with FreeBSD
@ 2017-04-04  7:05 Sebastian Huber
  2017-04-04  7:05 ` [PATCH 6/8] Addition of clang nullability qualifiers Sebastian Huber
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:05 UTC (permalink / raw)
  To: newlib

This patch set synchronizes <sys/cdefs.h> with the latest FreeBSD version.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/8] Fix C++ includability of crypto headers with static array sizes
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
  2017-04-04  7:05 ` [PATCH 6/8] Addition of clang nullability qualifiers Sebastian Huber
  2017-04-04  7:05 ` [PATCH 1/8] Rename __sentinel to __null_sentinel Sebastian Huber
@ 2017-04-04  7:05 ` Sebastian Huber
  2017-04-04  7:25 ` [PATCH 7/8] don't use C99 static array indices with older GCC versions Sebastian Huber
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:05 UTC (permalink / raw)
  To: newlib; +Cc: asomers

From: asomers <asomers@FreeBSD.org>

C99 allows array function parameters to use the static keyword for their
sizes. This tells the compiler that the parameter will have at least the
specified size, and calling code will fail to compile if that guarantee is
not met. However, this syntax is not legal in C++.

This commit reverts r300824, which worked around the problem for
sys/md5.h only, and introduces a new macro: min_size(). min_size(x) can
be used in headers as a static array size, but will still compile in C++
mode.

Reviewed by:	cem, ed
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D8277

fix a typo in __STDC_VERSION__ in __min_size requirements

MFC after:	1 week
Sponsored by:	Panzura
---
 newlib/libc/include/sys/cdefs.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 0c8fced..68172ad 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -361,6 +361,20 @@
 	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
 #endif
 
+/*
+ * C99 Static array indices in function parameter declarations.  Syntax such as:
+ * void bar(int myArray[static 10]);
+ * is allowed in C99 but not in C++.  Define __min_size appropriately so
+ * headers using it can be compiled in either language.  Use like this:
+ * void bar(int myArray[__min_size(10)]);
+ */
+#if !defined(__cplusplus) && \
+    (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901))
+#define __min_size(x)	static (x)
+#else
+#define __min_size(x)	(x)
+#endif
+
 #if __GNUC_PREREQ__(2, 96)
 #define	__malloc_like	__attribute__((__malloc__))
 #define	__pure		__attribute__((__pure__))
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/8] Addition of clang nullability qualifiers.
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
@ 2017-04-04  7:05 ` Sebastian Huber
  2017-04-04  7:05 ` [PATCH 1/8] Rename __sentinel to __null_sentinel Sebastian Huber
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:05 UTC (permalink / raw)
  To: newlib; +Cc: pfg

From: pfg <pfg@FreeBSD.org>

For consistency with the qualifiers added in r310977, define a new
qualifier _Null_unspecified which is also defined in clang 3.7+.

Add two new macros:
__NULLABILITY_PRAGMA_PUSH
__NULLABILITY_PRAGMA_POP

These are for use in headers when we want avoid noisy warnings if
some pointers are left without nullability annotations.

These are added with way ahead of their first use to teach the GCC
ports headers of their existance before their first use.
---
 newlib/libc/include/sys/cdefs.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 679425a..fa1692c 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -634,6 +634,13 @@
 #if !(defined(__clang__) && __has_feature(nullability))
 #define	_Nonnull
 #define	_Nullable
+#define	_Null_unspecified
+#define	__NULLABILITY_PRAGMA_PUSH
+#define	__NULLABILITY_PRAGMA_POP
+#else
+#define	__NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push")	\
+	_Pragma("clang diagnostic ignored \"-Wnullability-completeness\"")
+#define	__NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop")
 #endif
 
 /*
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/8] Rename __sentinel to __null_sentinel
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
  2017-04-04  7:05 ` [PATCH 6/8] Addition of clang nullability qualifiers Sebastian Huber
@ 2017-04-04  7:05 ` Sebastian Huber
  2017-04-04  7:05 ` [PATCH 3/8] Fix C++ includability of crypto headers with static array sizes Sebastian Huber
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:05 UTC (permalink / raw)
  To: newlib; +Cc: pfg

From: pfg <pfg@FreeBSD.org>

GCC 5 uses a conflicting __sentinel definition in include/c++/bits/stl_algo.h

Reported by:	matteo
---
 newlib/libc/include/sys/cdefs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index f569fc4..1e3c6b0 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -464,7 +464,7 @@
 #endif
 
 #if __GNUC_PREREQ__(4, 0)
-#define	__sentinel	__attribute__((__sentinel__))
+#define	__null_sentinel	__attribute__((__sentinel__))
 #define	__exported	__attribute__((__visibility__("default")))
 /* Only default visibility is supported on PE/COFF targets. */
 #ifndef __CYGWIN__
@@ -473,7 +473,7 @@
 #define	__hidden
 #endif
 #else
-#define	__sentinel
+#define	__null_sentinel
 #define	__exported
 #define	__hidden
 #endif
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/8] don't use C99 static array indices with older GCC versions
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (2 preceding siblings ...)
  2017-04-04  7:05 ` [PATCH 3/8] Fix C++ includability of crypto headers with static array sizes Sebastian Huber
@ 2017-04-04  7:25 ` Sebastian Huber
  2017-04-04  7:25 ` [PATCH 2/8] Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling for C++. It clashes with the one in libc++'s <atomic> header Sebastian Huber
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:25 UTC (permalink / raw)
  To: newlib; +Cc: avg

From: avg <avg@FreeBSD.org>

For example, the FreeBSD GCC (4.2.1) has a spotty support for that
feature.  If the static keyword is used with an unnamed array parameter
in a function declaration, then the compilation fails with:
error: static or type qualifiers in abstract declarator

The feature does work if the parameter is named.
So, the restriction introduced in this commit can be removed when all
affected function prototypes have the workaround.

MFC after:	1 week
Sponsored by:	Panzura
---
 newlib/libc/include/sys/cdefs.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index fa1692c..280aefd 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -369,6 +369,7 @@
  * void bar(int myArray[__min_size(10)]);
  */
 #if !defined(__cplusplus) && \
+    (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \
     (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901))
 #define __min_size(x)	static (x)
 #else
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/8] Remove unused __gnu_inline() attribute.
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (5 preceding siblings ...)
  2017-04-04  7:25 ` [PATCH 4/8] Addition of clang nullability qualifiers Sebastian Huber
@ 2017-04-04  7:25 ` Sebastian Huber
  2017-04-04  7:25 ` [PATCH 8/8] Renumber copyright clause 4 Sebastian Huber
  2017-04-04  9:45 ` Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:25 UTC (permalink / raw)
  To: newlib; +Cc: pfg

From: pfg <pfg@FreeBSD.org>

This was meant to be used by a future FORTIFY_SOURCE implementation.
Probably for good, FORTIFY_SOURCE and this particular GCCism were never
well supported by clang or other compilers. Furthermore, the technology
has long since been replaced by either static checkers, sanitizers, or
even just the strong stack protector that was enabled by default.

Drop __gnu_inline to avoid cluttering the headers.

MFC after:	5 days
---
 newlib/libc/include/sys/cdefs.h | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index ad23232..679425a 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -537,22 +537,6 @@
 	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
 #endif
 
-/*
- * FORTIFY_SOURCE, and perhaps other compiler-specific features, require
- * the use of non-standard inlining.  In general we should try to avoid
- * using these but GCC-compatible compilers tend to support the extensions
- * well enough to use them in limited cases.
- */ 
-#if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
-#if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__)
-#define	__gnu_inline	__attribute__((__gnu_inline__, __artificial__))
-#else
-#define	__gnu_inline	__attribute__((__gnu_inline__))
-#endif /* artificial */
-#else
-#define	__gnu_inline
-#endif
-
 /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
 #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
     defined(__GNUC__) && !defined(__INTEL_COMPILER)
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/8] Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling for C++. It clashes with the one in libc++'s <atomic> header.
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (3 preceding siblings ...)
  2017-04-04  7:25 ` [PATCH 7/8] don't use C99 static array indices with older GCC versions Sebastian Huber
@ 2017-04-04  7:25 ` Sebastian Huber
  2017-04-04  7:25 ` [PATCH 4/8] Addition of clang nullability qualifiers Sebastian Huber
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:25 UTC (permalink / raw)
  To: newlib; +Cc: dim

From: dim <dim@FreeBSD.org>

(Previously, the _Atomic() macro was defined in <stdatomic.h>, which is
only for use with C11, but for various reasons it was moved to its
current location in r251804.)

Discussed with:	bdrewery, ed
MFC after:	2 weeks
---
 newlib/libc/include/sys/cdefs.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 1e3c6b0..0c8fced 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -295,7 +295,8 @@
 #define	_Alignof(x)		__alignof(x)
 #endif
 
-#if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
+#if !defined(__cplusplus) && !__has_extension(c_atomic) && \
+    !__has_extension(cxx_atomic)
 /*
  * No native support for _Atomic(). Place object in structure to prevent
  * most forms of direct non-atomic access.
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/8] Renumber copyright clause 4
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (6 preceding siblings ...)
  2017-04-04  7:25 ` [PATCH 5/8] Remove unused __gnu_inline() attribute Sebastian Huber
@ 2017-04-04  7:25 ` Sebastian Huber
  2017-04-04  9:45 ` Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:25 UTC (permalink / raw)
  To: newlib; +Cc: imp

From: imp <imp@FreeBSD.org>

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
---
 newlib/libc/include/sys/cdefs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 280aefd..2e63a07 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -17,7 +17,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/8] Addition of clang nullability qualifiers.
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (4 preceding siblings ...)
  2017-04-04  7:25 ` [PATCH 2/8] Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling for C++. It clashes with the one in libc++'s <atomic> header Sebastian Huber
@ 2017-04-04  7:25 ` Sebastian Huber
  2017-04-04  7:25 ` [PATCH 5/8] Remove unused __gnu_inline() attribute Sebastian Huber
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  7:25 UTC (permalink / raw)
  To: newlib; +Cc: pfg

From: pfg <pfg@FreeBSD.org>

Add two new qualifiers for use by the static checkers:

_Nonnull
The _Nonnull nullability qualifier indicates that null is not a meaningful
value for a value of the _Nonnull pointer type.

_Nullable
The _Nullable nullability qualifier indicates that a value of the
_Nullable pointer type can be null.

These were introduced in Clang 3.7. For more information, see:
http://clang.llvm.org/docs/AttributeReference.html#nonnull

We add these now without using them so that the GCC ports have time to
pick up the header change.

Hinted by:	Android Bionic libc [1]
Also seen in:	Apple's Libc-1158.20.4

[1]
https://github.com/android/platform_bionic/commit/baa2a973bd776a51bb05a8590ab05d86eea7b321
---
 newlib/libc/include/sys/cdefs.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
index 68172ad..ad23232 100644
--- a/newlib/libc/include/sys/cdefs.h
+++ b/newlib/libc/include/sys/cdefs.h
@@ -645,6 +645,14 @@
 #endif
 
 /*
+ * Nullability qualifiers: currently only supported by Clang.
+ */
+#if !(defined(__clang__) && __has_feature(nullability))
+#define	_Nonnull
+#define	_Nullable
+#endif
+
+/*
  * Type Safety Checking
  *
  * Clang provides additional attributes to enable checking type safety
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Synchronize <sys/cdefs.h> with FreeBSD
  2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
                   ` (7 preceding siblings ...)
  2017-04-04  7:25 ` [PATCH 8/8] Renumber copyright clause 4 Sebastian Huber
@ 2017-04-04  9:45 ` Corinna Vinschen
  8 siblings, 0 replies; 11+ messages in thread
From: Corinna Vinschen @ 2017-04-04  9:45 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

On Apr  4 09:04, Sebastian Huber wrote:
> This patch set synchronizes <sys/cdefs.h> with the latest FreeBSD version.

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/8] Renumber copyright clause 4
  2017-04-04  8:35 [PATCH 1/8] Add new FOREACH_FROM variants of the queue(3) FOREACH macros which can optionally start the traversal from a previously found element by passing the element in as "var". Passing a NULL "var" retains the same semantics as the regular FOREACH macros Sebastian Huber
@ 2017-04-04  8:35 ` Sebastian Huber
  0 siblings, 0 replies; 11+ messages in thread
From: Sebastian Huber @ 2017-04-04  8:35 UTC (permalink / raw)
  To: newlib

From: imp <imp@FreeBSD.org>

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
---
 newlib/libc/include/sys/queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/include/sys/queue.h b/newlib/libc/include/sys/queue.h
index 6cae4c1..491bdde 100644
--- a/newlib/libc/include/sys/queue.h
+++ b/newlib/libc/include/sys/queue.h
@@ -10,7 +10,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-04-04  9:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-04  7:05 Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber
2017-04-04  7:05 ` [PATCH 6/8] Addition of clang nullability qualifiers Sebastian Huber
2017-04-04  7:05 ` [PATCH 1/8] Rename __sentinel to __null_sentinel Sebastian Huber
2017-04-04  7:05 ` [PATCH 3/8] Fix C++ includability of crypto headers with static array sizes Sebastian Huber
2017-04-04  7:25 ` [PATCH 7/8] don't use C99 static array indices with older GCC versions Sebastian Huber
2017-04-04  7:25 ` [PATCH 2/8] Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling for C++. It clashes with the one in libc++'s <atomic> header Sebastian Huber
2017-04-04  7:25 ` [PATCH 4/8] Addition of clang nullability qualifiers Sebastian Huber
2017-04-04  7:25 ` [PATCH 5/8] Remove unused __gnu_inline() attribute Sebastian Huber
2017-04-04  7:25 ` [PATCH 8/8] Renumber copyright clause 4 Sebastian Huber
2017-04-04  9:45 ` Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen
2017-04-04  8:35 [PATCH 1/8] Add new FOREACH_FROM variants of the queue(3) FOREACH macros which can optionally start the traversal from a previously found element by passing the element in as "var". Passing a NULL "var" retains the same semantics as the regular FOREACH macros Sebastian Huber
2017-04-04  8:35 ` [PATCH 8/8] Renumber copyright clause 4 Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).