Skip to content

[libc] Add NULL macro definitions to header files #142764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025

Conversation

saturn691
Copy link
Contributor

@saturn691 saturn691 commented Jun 4, 2025

By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>, <string.h>, <time.h>, and <wchar.h> require NULL to be defined.

@llvmbot llvmbot added the libc label Jun 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2025

@llvm/pr-subscribers-libc

Author: William (saturn691)

Changes

By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>, <string.h>, <time.h>, and <wchar.h> require NULL to be defined.


Full diff: https://github.com/llvm/llvm-project/pull/142764.diff

6 Files Affected:

  • (modified) libc/include/CMakeLists.txt (+5)
  • (modified) libc/include/locale.h.def (+1-1)
  • (modified) libc/include/stdio.h.def (+1)
  • (modified) libc/include/stdlib.h.def (+1)
  • (modified) libc/include/time.h.def (+1)
  • (modified) libc/include/wchar.h.def (+1)
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.h.def b/libc/include/locale.h.def
index 930373eade4d5..83b7e5738dd1b 100644
--- a/libc/include/locale.h.def
+++ b/libc/include/locale.h.def
@@ -10,8 +10,8 @@
 #define LLVM_LIBC_LOCALE_H
 
 #include "__llvm-libc-common.h"
-
 #include "llvm-libc-macros/locale-macros.h"
+#include "llvm-libc-macros/null-macro.h"
 
 %%public_api()
 
diff --git a/libc/include/stdio.h.def b/libc/include/stdio.h.def
index 78d800c83b514..9ed8189eb74bb 100644
--- a/libc/include/stdio.h.def
+++ b/libc/include/stdio.h.def
@@ -11,6 +11,7 @@
 
 #include "__llvm-libc-common.h"
 #include "llvm-libc-macros/file-seek-macros.h"
+#include "llvm-libc-macros/null-macro.h"
 #include "llvm-libc-macros/stdio-macros.h"
 
 #include <stdarg.h>
diff --git a/libc/include/stdlib.h.def b/libc/include/stdlib.h.def
index d523f7a53024a..6d86c6962bf0c 100644
--- a/libc/include/stdlib.h.def
+++ b/libc/include/stdlib.h.def
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_STDLIB_H
 
 #include "__llvm-libc-common.h"
+#include "llvm-libc-macros/null-macro.h"
 #include "llvm-libc-macros/stdlib-macros.h"
 
 %%public_api()
diff --git a/libc/include/time.h.def b/libc/include/time.h.def
index 2355e8822fad7..1658d48e0fa0f 100644
--- a/libc/include/time.h.def
+++ b/libc/include/time.h.def
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_TIME_H
 
 #include "__llvm-libc-common.h"
+#include "llvm-libc-macros/null-macro.h"
 #include "llvm-libc-macros/time-macros.h"
 
 %%public_api()
diff --git a/libc/include/wchar.h.def b/libc/include/wchar.h.def
index 4c25de700d606..becfccd4c899d 100644
--- a/libc/include/wchar.h.def
+++ b/libc/include/wchar.h.def
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_WCHAR_H
 
 #include "__llvm-libc-common.h"
+#include "llvm-libc-macros/null-macro.h"
 #include "llvm-libc-macros/wchar-macros.h"
 
 %%public_api()

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

saturn691 added 2 commits June 5, 2025 11:20
By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
@saturn691
Copy link
Contributor Author

Hi Tue, I don't have commit access yet, please commit this on behalf of me, thanks!

@michaelrj-google michaelrj-google merged commit 117e78f into llvm:main Jun 11, 2025
13 checks passed
@saturn691 saturn691 deleted the null-fixes branch June 11, 2025 17:38
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
By the C standard, <locale.h>, <stddef.h> <stdio.h>, <stdlib.h>,
<string.h>, <time.h>, and <wchar.h> require NULL to be defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants