iana created this revision.
iana added reviewers: ributzka, vsapsai, Bigcheese.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
iana requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Make a new header to define NULL so that the OS can use it independent of 
stddef.h, i.e. in POSIX headers that are required to define NULL but not the 
rest of stddef.h.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140250

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/stddef.h


Index: clang/lib/Headers/stddef.h
===================================================================
--- clang/lib/Headers/stddef.h
+++ clang/lib/Headers/stddef.h
@@ -78,22 +78,7 @@
 #endif /* defined(__need_wchar_t) */
 
 #if defined(__need_NULL)
-#undef NULL
-#ifdef __cplusplus
-#  if !defined(__MINGW32__) && !defined(_MSC_VER)
-#    define NULL __null
-#  else
-#    define NULL 0
-#  endif
-#else
-#  define NULL ((void*)0)
-#endif
-#ifdef __cplusplus
-#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
-namespace std { typedef decltype(nullptr) nullptr_t; }
-using ::std::nullptr_t;
-#endif
-#endif
+#include <__stddef_null.h>
 #undef __need_NULL
 #endif /* defined(__need_NULL) */
 
Index: clang/lib/Headers/__stddef_null.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/__stddef_null.h
@@ -0,0 +1,32 @@
+/*===---- __stddef_null.h - Definition of NULL -----------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __STDDEF_NULL_H
+#define __STDDEF_NULL_H
+
+#undef NULL
+#ifdef __cplusplus
+#if !defined(__MINGW32__) && !defined(_MSC_VER)
+#define NULL __null
+#else
+#define NULL 0
+#endif
+#else
+#define NULL ((void *)0)
+#endif
+#ifdef __cplusplus
+#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;
+#endif
+#endif
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===================================================================
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -14,6 +14,7 @@
   stdbool.h
   stddef.h
   __stddef_max_align_t.h
+  __stddef_null.h
   stdint.h
   stdnoreturn.h
   tgmath.h


Index: clang/lib/Headers/stddef.h
===================================================================
--- clang/lib/Headers/stddef.h
+++ clang/lib/Headers/stddef.h
@@ -78,22 +78,7 @@
 #endif /* defined(__need_wchar_t) */
 
 #if defined(__need_NULL)
-#undef NULL
-#ifdef __cplusplus
-#  if !defined(__MINGW32__) && !defined(_MSC_VER)
-#    define NULL __null
-#  else
-#    define NULL 0
-#  endif
-#else
-#  define NULL ((void*)0)
-#endif
-#ifdef __cplusplus
-#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
-namespace std { typedef decltype(nullptr) nullptr_t; }
-using ::std::nullptr_t;
-#endif
-#endif
+#include <__stddef_null.h>
 #undef __need_NULL
 #endif /* defined(__need_NULL) */
 
Index: clang/lib/Headers/__stddef_null.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/__stddef_null.h
@@ -0,0 +1,32 @@
+/*===---- __stddef_null.h - Definition of NULL -----------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __STDDEF_NULL_H
+#define __STDDEF_NULL_H
+
+#undef NULL
+#ifdef __cplusplus
+#if !defined(__MINGW32__) && !defined(_MSC_VER)
+#define NULL __null
+#else
+#define NULL 0
+#endif
+#else
+#define NULL ((void *)0)
+#endif
+#ifdef __cplusplus
+#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;
+#endif
+#endif
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===================================================================
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -14,6 +14,7 @@
   stdbool.h
   stddef.h
   __stddef_max_align_t.h
+  __stddef_null.h
   stdint.h
   stdnoreturn.h
   tgmath.h
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to