andrewrk created this revision.
andrewrk added reviewers: eli.friedman, krememek, ddunbar, lattner.
andrewrk added a project: clang.
Herald added a subscriber: cfe-commits.

stdarg.h:

- va_list - macos _va_list.h was duplicately defining va_list. Fixed by this 
ifndef _VA_LIST_T
- additionally define _VA_LIST_DEFINED because glibc stdio.h was duplicately 
defining va_list

stddef.h

- ptrdiff_t - wrap in _PTRDIFF_T_DEFINED to protect against mingw defining it 
twice
- size_t - protections against collisions with mingw
- wchar_t - protections against duplicate definition with mingw

All of these came up in real world scenarios when using libclang to parse .h 
files in the Zig project.
These are the patches that Zig has on top of libclang headers, and if this 
patch is merged, then
Zig project will be tracking clang trunk.


Repository:
  rC Clang

https://reviews.llvm.org/D51265

Files:
  lib/Headers/stdarg.h
  lib/Headers/stddef.h


Index: lib/Headers/stddef.h
===================================================================
--- lib/Headers/stddef.h
+++ lib/Headers/stddef.h
@@ -48,7 +48,12 @@
 #if !__has_feature(modules)
 #define _PTRDIFF_T
 #endif
+
+#if !defined(_PTRDIFF_T_DEFINED)
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
+#define _PTRDIFF_T_DEFINED
+#endif
+
 #endif
 #undef __need_ptrdiff_t
 #endif /* defined(__need_ptrdiff_t) */
@@ -59,7 +64,23 @@
 #if !__has_feature(modules)
 #define _SIZE_T
 #endif
+
+#if !defined(_SIZE_T_DEFINED_)
+#if !defined(_SIZE_T_DEFINED)
+#if !defined(_BSD_SIZE_T_DEFINED_)
+#if !defined(_SIZE_T_DECLARED)
 typedef __SIZE_TYPE__ size_t;
+#define _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED
+#define _BSD_SIZE_T_DEFINED_
+#define _SIZE_T_DECLARED
+#endif
+#endif
+#endif
+#endif
+
+
+
 #endif
 #undef __need_size_t
 #endif /*defined(__need_size_t) */
@@ -87,7 +108,21 @@
 #define _WCHAR_T_DEFINED
 #endif
 #endif
+
+#if !defined(__INT_WCHAR_T_H)
+#if !defined(_GCC_WCHAR_T)
+#if !defined(_WCHAR_T_DECLARED)
+#if !defined(_WCHAR_T_DEFINED)
+#define __INT_WCHAR_T_H
+#define _GCC_WCHAR_T
+#define _WCHAR_T_DECLARED
+#define _WCHAR_T_DEFINED
 typedef __WCHAR_TYPE__ wchar_t;
+#endif
+#endif
+#endif
+#endif
+
 #endif
 #endif
 #undef __need_wchar_t
Index: lib/Headers/stdarg.h
===================================================================
--- lib/Headers/stdarg.h
+++ lib/Headers/stdarg.h
@@ -27,9 +27,11 @@
 #define __STDARG_H
 
 #ifndef _VA_LIST
+#ifndef _VA_LIST_T
 typedef __builtin_va_list va_list;
 #define _VA_LIST
 #endif
+#endif
 #define va_start(ap, param) __builtin_va_start(ap, param)
 #define va_end(ap)          __builtin_va_end(ap)
 #define va_arg(ap, type)    __builtin_va_arg(ap, type)
@@ -46,6 +48,7 @@
 #ifndef __GNUC_VA_LIST
 #define __GNUC_VA_LIST 1
 typedef __builtin_va_list __gnuc_va_list;
+#define _VA_LIST_DEFINED
 #endif
 
 #endif /* __STDARG_H */


Index: lib/Headers/stddef.h
===================================================================
--- lib/Headers/stddef.h
+++ lib/Headers/stddef.h
@@ -48,7 +48,12 @@
 #if !__has_feature(modules)
 #define _PTRDIFF_T
 #endif
+
+#if !defined(_PTRDIFF_T_DEFINED)
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
+#define _PTRDIFF_T_DEFINED
+#endif
+
 #endif
 #undef __need_ptrdiff_t
 #endif /* defined(__need_ptrdiff_t) */
@@ -59,7 +64,23 @@
 #if !__has_feature(modules)
 #define _SIZE_T
 #endif
+
+#if !defined(_SIZE_T_DEFINED_)
+#if !defined(_SIZE_T_DEFINED)
+#if !defined(_BSD_SIZE_T_DEFINED_)
+#if !defined(_SIZE_T_DECLARED)
 typedef __SIZE_TYPE__ size_t;
+#define _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED
+#define _BSD_SIZE_T_DEFINED_
+#define _SIZE_T_DECLARED
+#endif
+#endif
+#endif
+#endif
+
+
+
 #endif
 #undef __need_size_t
 #endif /*defined(__need_size_t) */
@@ -87,7 +108,21 @@
 #define _WCHAR_T_DEFINED
 #endif
 #endif
+
+#if !defined(__INT_WCHAR_T_H)
+#if !defined(_GCC_WCHAR_T)
+#if !defined(_WCHAR_T_DECLARED)
+#if !defined(_WCHAR_T_DEFINED)
+#define __INT_WCHAR_T_H
+#define _GCC_WCHAR_T
+#define _WCHAR_T_DECLARED
+#define _WCHAR_T_DEFINED
 typedef __WCHAR_TYPE__ wchar_t;
+#endif
+#endif
+#endif
+#endif
+
 #endif
 #endif
 #undef __need_wchar_t
Index: lib/Headers/stdarg.h
===================================================================
--- lib/Headers/stdarg.h
+++ lib/Headers/stdarg.h
@@ -27,9 +27,11 @@
 #define __STDARG_H
 
 #ifndef _VA_LIST
+#ifndef _VA_LIST_T
 typedef __builtin_va_list va_list;
 #define _VA_LIST
 #endif
+#endif
 #define va_start(ap, param) __builtin_va_start(ap, param)
 #define va_end(ap)          __builtin_va_end(ap)
 #define va_arg(ap, type)    __builtin_va_arg(ap, type)
@@ -46,6 +48,7 @@
 #ifndef __GNUC_VA_LIST
 #define __GNUC_VA_LIST 1
 typedef __builtin_va_list __gnuc_va_list;
+#define _VA_LIST_DEFINED
 #endif
 
 #endif /* __STDARG_H */
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to