Diff below adds C11 support to the feature test macros in
<sys/cdefs.h> and uses those to conditionally define the max_align_t
type in <stddef.h>.  All systems/compilers seem to use the same
construct.  See

  https://reviews.llvm.org/rL201729

for a bit more background.

This will make it possible to remove clang's private <stddef.h>
without losing functionality.

Since our base compiler doesn't have C11 support, the type generally
won't be available.  But it can be made available by using

  gcc -D_ISOC11_SOURCE

With clang, C11 support is enabled by default, so max_align_t is
visible.  But it can be hidden by using

  clang -std=c99

I don't expect any major fall-out in ports from this.

ok?


Index: sys/sys/cdefs.h
===================================================================
RCS file: /cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.39
diff -u -p -r1.39 cdefs.h
--- sys/sys/cdefs.h     18 Apr 2014 11:51:17 -0000      1.39
+++ sys/sys/cdefs.h     5 Jan 2017 20:07:02 -0000
@@ -375,14 +375,19 @@
 #endif
 
 /*
- * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since
- * they are non-exclusive.
+ * _ISOC99_SOURCE, _ISOC11_SOURCE and __STDC_VERSION__ override any of
+ * the other macros since they are non-exclusive.
  */
 #if defined(_ISOC99_SOURCE) || \
     (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
     (defined(__cplusplus) && __cplusplus >= 201103)
 # undef __ISO_C_VISIBLE
 # define __ISO_C_VISIBLE       1999
+#endif
+#if defined(_ISOC11_SOURCE) || \
+    (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE       2011
 #endif
 
 /*
Index: include/stddef.h
===================================================================
RCS file: /cvs/src/include/stddef.h,v
retrieving revision 1.13
diff -u -p -r1.13 stddef.h
--- include/stddef.h    9 Sep 2016 18:12:37 -0000       1.13
+++ include/stddef.h    5 Jan 2017 20:07:02 -0000
@@ -71,4 +71,11 @@ typedef      __mbstate_t     mbstate_t;
 #define        offsetof(type, member)  ((size_t)(&((type *)0)->member))
 #endif
 
+#if __ISO_C_VISIBLE >= 2011
+typedef struct {
+       long long __max_align_ll __aligned(__alignof__(long long));
+       long double __max_align_ld __aligned(__alignof__(long double));
+} max_align_t;
+#endif
+
 #endif /* _STDDEF_H_ */

Reply via email to