aboutsummaryrefslogtreecommitdiff
path: root/lib/include/stdarg.h
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-05-09 01:52:26 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-05-09 01:52:26 -0700
commitbcb534c295d5cc6fd63caa570cc08e6b148a507c (patch)
tree0b17cb1e632d894f50f25e550d5113f232b0e877 /lib/include/stdarg.h
parentd9b00ee4ba48717ff6b306a6f9419e7b604ac04b (diff)
parent74f52954b9cb40d59d80b839b45bb859146731a7 (diff)
downloadzig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.tar.gz
zig-bcb534c295d5cc6fd63caa570cc08e6b148a507c.zip
Merge branch 'llvm18'
Upgrades the LLVM, Clang, and LLD dependencies to LLVM 18.x Related to #16270
Diffstat (limited to 'lib/include/stdarg.h')
-rw-r--r--lib/include/stdarg.h90
1 files changed, 59 insertions, 31 deletions
diff --git a/lib/include/stdarg.h b/lib/include/stdarg.h
index ba978721f1..94b066566f 100644
--- a/lib/include/stdarg.h
+++ b/lib/include/stdarg.h
@@ -7,45 +7,73 @@
*===-----------------------------------------------------------------------===
*/
-#ifndef __STDARG_H
-
-#ifndef __GNUC_VA_LIST
-#define __GNUC_VA_LIST
-typedef __builtin_va_list __gnuc_va_list;
-#endif
+/*
+ * This header is designed to be included multiple times. If any of the __need_
+ * macros are defined, then only that subset of interfaces are provided. This
+ * can be useful for POSIX headers that need to not expose all of stdarg.h, but
+ * need to use some of its interfaces. Otherwise this header provides all of
+ * the expected interfaces.
+ *
+ * When clang modules are enabled, this header is a textual header. It ignores
+ * its header guard so that multiple submodules can export its interfaces.
+ * Take module SM with submodules A and B, whose headers both include stdarg.h
+ * When SM.A builds, __STDARG_H will be defined. When SM.B builds, the
+ * definition from SM.A will leak when building without local submodule
+ * visibility. stdarg.h wouldn't include any of its implementation headers, and
+ * SM.B wouldn't import any of the stdarg modules, and SM.B's `export *`
+ * wouldn't export any stdarg interfaces as expected. However, since stdarg.h
+ * ignores its header guard when building with modules, it all works as
+ * expected.
+ *
+ * When clang modules are not enabled, the header guards can function in the
+ * normal simple fashion.
+ */
+#if !defined(__STDARG_H) || __has_feature(modules) || \
+ defined(__need___va_list) || defined(__need_va_list) || \
+ defined(__need_va_arg) || defined(__need___va_copy) || \
+ defined(__need_va_copy)
-#ifdef __need___va_list
-#undef __need___va_list
-#else
+#if !defined(__need___va_list) && !defined(__need_va_list) && \
+ !defined(__need_va_arg) && !defined(__need___va_copy) && \
+ !defined(__need_va_copy)
#define __STDARG_H
-#ifndef _VA_LIST
-typedef __builtin_va_list va_list;
-#define _VA_LIST
-#endif
-
-/* FIXME: This is using the placeholder dates Clang produces for these macros
- in C2x mode; switch to the correct values once they've been published. */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
-/* C2x does not require the second parameter for va_start. */
-#define va_start(ap, ...) __builtin_va_start(ap, 0)
-#else
-/* Versions before C2x do require the second parameter. */
-#define va_start(ap, param) __builtin_va_start(ap, param)
-#endif
-#define va_end(ap) __builtin_va_end(ap)
-#define va_arg(ap, type) __builtin_va_arg(ap, type)
-
+#define __need___va_list
+#define __need_va_list
+#define __need_va_arg
+#define __need___va_copy
/* 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.
*/
-#define __va_copy(d,s) __builtin_va_copy(d,s)
-
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L) || \
!defined(__STRICT_ANSI__)
-#define va_copy(dest, src) __builtin_va_copy(dest, src)
+#define __need_va_copy
+#endif
#endif
-#endif /* __STDARG_H */
+#ifdef __need___va_list
+#include <__stdarg___gnuc_va_list.h>
+#undef __need___va_list
+#endif /* defined(__need___va_list) */
+
+#ifdef __need_va_list
+#include <__stdarg_va_list.h>
+#undef __need_va_list
+#endif /* defined(__need_va_list) */
+
+#ifdef __need_va_arg
+#include <__stdarg_va_arg.h>
+#undef __need_va_arg
+#endif /* defined(__need_va_arg) */
+
+#ifdef __need___va_copy
+#include <__stdarg___va_copy.h>
+#undef __need___va_copy
+#endif /* defined(__need___va_copy) */
-#endif /* not __STDARG_H */
+#ifdef __need_va_copy
+#include <__stdarg_va_copy.h>
+#undef __need_va_copy
+#endif /* defined(__need_va_copy) */
+
+#endif