[PATCH] D44604: Make stdarg.h compatible with FreeBSD

Alexander Richardson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 17 16:57:45 PDT 2018

arichardson created this revision.
arichardson added reviewers: efriedma, dim.
Herald added subscribers: cfe-commits, krytarowski, sdardis, emaste.

On FreeBSD it is currently not possible to use the clang builtin
headers to build the base system. The build will fail with the
following error if I don't delete the std* headers from the clang
install directory:

  /sources/freebsd-mips/include/stdio.h:72:19: error:
  redefinition of typedef 'va_list' is a C11 feature
  typedef __va_list       va_list;
  note: previous definition is here
  typedef __builtin_va_list va_list;
  /sources/freebsd-mips/sys/sys/_stdarg.h:46:11: error: 'va_start' macro redefined
    #define       va_start(ap, last)      __builtin_va_start((ap), (last))
  note: previous definition is here
    #define va_start(ap, param) __builtin_va_start(ap, param)

FreeBSD includes definitions of va_list, va_copy, etc in the
<machine/stdarg.h> header and some files end up including both that
header and <stdarg.h>.

Only defining the va_* macros if they are not yet defined fixes the
macro redefiniton issue and probably also makes sense for other
operating systems. However, for the va_list typedef I can't think
of a better solution than to also check for _VA_LIST_DECLARED and
define it.

  rC Clang



Index: lib/Headers/stdarg.h
--- lib/Headers/stdarg.h
+++ lib/Headers/stdarg.h
@@ -26,22 +26,33 @@
 #ifndef __STDARG_H
 #define __STDARG_H
-#ifndef _VA_LIST
+#if !defined(_VA_LIST) && !defined(_VA_LIST_DECLARED)
 typedef __builtin_va_list va_list;
 #define _VA_LIST
+#define _VA_LIST_DECLARED /* FreeBSD */
+#ifndef va_start
 #define va_start(ap, param) __builtin_va_start(ap, param)
+#ifndef va_end
 #define va_end(ap)          __builtin_va_end(ap)
+#ifndef va_arg
 #define va_arg(ap, type)    __builtin_va_arg(ap, type)
 /* GCC always defines __va_copy, but does not define va_copy unless in c99 mode
  * or -ansi is not specified, since it was not part of C90.
+#ifndef __va_copy
 #define __va_copy(d,s) __builtin_va_copy(d,s)
 #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__)
+#ifndef va_copy
 #define va_copy(dest, src)  __builtin_va_copy(dest, src)
 #ifndef __GNUC_VA_LIST
 #define __GNUC_VA_LIST 1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44604.138836.patch
Type: text/x-patch
Size: 1079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180317/2fb8a41e/attachment-0001.bin>

More information about the cfe-commits mailing list