[libc-commits] [libc] [libc] Add NULL macro definitions to header files (PR #142764)

via libc-commits libc-commits at lists.llvm.org
Thu Jun 5 03:27:34 PDT 2025


https://github.com/saturn691 updated https://github.com/llvm/llvm-project/pull/142764

>From 65c443848986fe94b3cd4e906c43a213183fe227 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Thu, 5 Jun 2025 09:31:39 +0100
Subject: [PATCH 1/2] [libc] Add NULL macro definitions to header files

By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
---
 libc/include/CMakeLists.txt | 5 +++++
 libc/include/locale.yaml    | 3 +++
 libc/include/stdio.yaml     | 2 ++
 libc/include/stdlib.yaml    | 4 +++-
 libc/include/string.h.def   | 2 --
 libc/include/string.yaml    | 4 +++-
 libc/include/time.yaml      | 4 +++-
 libc/include/wchar.yaml     | 4 +++-
 8 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 7209e10c68b8f..55268d19529c7 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -255,6 +255,7 @@ add_header_macro(
   time.h
   DEPENDS
     .llvm_libc_common_h
+    .llvm-libc-macros.null_macro
     .llvm-libc-macros.time_macros
     .llvm-libc-types.clock_t
     .llvm-libc-types.time_t
@@ -329,6 +330,7 @@ add_header_macro(
   stdio.h
   DEPENDS
     .llvm-libc-macros.file_seek_macros
+    .llvm-libc-macros.null_macro
     .llvm-libc-macros.stdio_macros
     .llvm-libc-types.FILE
     .llvm-libc-types.cookie_io_functions_t
@@ -343,6 +345,7 @@ add_header_macro(
   ../libc/include/stdlib.yaml
   stdlib.h
   DEPENDS
+    .llvm-libc-macros.null_macro
     .llvm-libc-macros.stdlib_macros
     .llvm-libc-types.__atexithandler_t
     .llvm-libc-types.__qsortcompare_t
@@ -709,6 +712,7 @@ add_header_macro(
   wchar.h
   DEPENDS
     .llvm_libc_common_h
+    .llvm-libc-macros.null_macro
     .llvm-libc-macros.wchar_macros
     .llvm-libc-types.mbstate_t
     .llvm-libc-types.size_t
@@ -723,6 +727,7 @@ add_header_macro(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.locale_macros
+    .llvm-libc-macros.null_macro
     .llvm-libc-types.locale_t
     .llvm-libc-types.struct_lconv
 )
diff --git a/libc/include/locale.yaml b/libc/include/locale.yaml
index 6c71b70e59f0b..4566984ad83af 100644
--- a/libc/include/locale.yaml
+++ b/libc/include/locale.yaml
@@ -1,5 +1,8 @@
 header: locale.h
 header_template: locale.h.def
+macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
 types:
   - type_name: locale_t
   - type_name: struct_lconv
diff --git a/libc/include/stdio.yaml b/libc/include/stdio.yaml
index 2619984cca264..3d5164fa10ffb 100644
--- a/libc/include/stdio.yaml
+++ b/libc/include/stdio.yaml
@@ -1,6 +1,8 @@
 header: stdio.h
 header_template: stdio.h.def
 macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
   - macro_name: stdout
     macro_value: stdout
   - macro_name: stdin
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index f7155ba27a162..3b2ff13c684b1 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -4,7 +4,9 @@ standards:
   - stdc
 merge_yaml_files:
   - stdlib-malloc.yaml
-macros: []
+macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
 types:
   - type_name: __atexithandler_t
   - type_name: __qsortcompare_t
diff --git a/libc/include/string.h.def b/libc/include/string.h.def
index 1bd2687db2bea..339d005e43a4f 100644
--- a/libc/include/string.h.def
+++ b/libc/include/string.h.def
@@ -11,8 +11,6 @@
 
 #include "__llvm-libc-common.h"
 
-#include "llvm-libc-macros/null-macro.h"
-
 %%public_api()
 
 #endif // LLVM_LIBC_STRING_H
diff --git a/libc/include/string.yaml b/libc/include/string.yaml
index 9f72b8db6c1eb..736deceb453de 100644
--- a/libc/include/string.yaml
+++ b/libc/include/string.yaml
@@ -1,6 +1,8 @@
 header: string.h
 header_template: string.h.def
-macros: []
+macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
 types:
   - type_name: locale_t
   - type_name: size_t
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index 7bb25dbe85ac4..3b9d77c0aaae2 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -1,6 +1,8 @@
 header: time.h
 header_template: time.h.def
-macros: []
+macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
 types:
   - type_name: struct_timeval
   - type_name: clockid_t
diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml
index 877be48b6a10f..57f4f6660827e 100644
--- a/libc/include/wchar.yaml
+++ b/libc/include/wchar.yaml
@@ -1,6 +1,8 @@
 header: wchar.h
 header_template: wchar.h.def
-macros: []
+macros:
+  - macro_name: NULL
+    macro_header: null-macro.h
 types:
   - type_name: size_t
   - type_name: wint_t

>From ea945f9ab54c4f1122f3155d6478dee0ad95f75b Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Thu, 5 Jun 2025 11:27:10 +0100
Subject: [PATCH 2/2] fixup! [libc] Add NULL macro definitions to header files

---
 libc/test/UnitTest/LibcDeathTestExecutors.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/UnitTest/LibcDeathTestExecutors.cpp b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
index 943e2c23c5fde..3648ea7f58ef6 100644
--- a/libc/test/UnitTest/LibcDeathTestExecutors.cpp
+++ b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
@@ -15,7 +15,7 @@
 #include <assert.h>
 
 namespace {
-constexpr unsigned TIMEOUT_MS = 10000;
+constexpr unsigned TIMEOUT_MS = 100000;
 } // Anonymous namespace
 
 namespace LIBC_NAMESPACE_DECL {



More information about the libc-commits mailing list