[clang-tools-extra] 983b202 - [clang-tidy][NFC] Use mock header instead of #define NULL in tests (#188420)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 25 19:19:15 PDT 2026


Author: Zeyi Xu
Date: 2026-03-26T10:19:09+08:00
New Revision: 983b2023ddc366369ef1d5b8a705e87466ae7991

URL: https://github.com/llvm/llvm-project/commit/983b2023ddc366369ef1d5b8a705e87466ae7991
DIFF: https://github.com/llvm/llvm-project/commit/983b2023ddc366369ef1d5b8a705e87466ae7991.diff

LOG: [clang-tidy][NFC] Use mock header instead of #define NULL in tests (#188420)

Since stddef.h in the mock headers of clang-tidy tests now provides
`#define NULL 0L`, we can migrate manual `#define NULL` in these tests
to standard `#include`s.

Added: 
    

Modified: 
    clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp
    clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp
    clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp
    clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c
    clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp
    clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c
    clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
    clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
    clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
    clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c
    clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
    clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp
index 9990594266bfd..a4402866075ec 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp
@@ -1,8 +1,9 @@
 // RUN: %check_clang_tidy %s android-cloexec-accept %t
 
+#include <cstddef>
+
 struct sockaddr {};
 typedef int socklen_t;
-#define NULL 0
 
 extern "C" int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp
index 448d4a9f6404b..c7d8b641ff87a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s android-cloexec-accept4 %t
 
+#include <cstddef>
+
 typedef int socklen_t;
 struct sockaddr {};
 
@@ -13,7 +15,6 @@ struct sockaddr {};
       _rc = (exp);              \
     } while (_rc == -1);        \
   })
-#define NULL 0
 
 extern "C" int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp
index d1d77d35392c8..ca1a7706d8799 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s android-cloexec-memfd-create %t
 
+#include <cstddef>
+
 #define MFD_ALLOW_SEALING 1
 #define __O_CLOEXEC 3
 #define MFD_CLOEXEC __O_CLOEXEC
@@ -10,7 +12,6 @@
       _rc = (exp);              \
     } while (_rc == -1);        \
   })
-#define NULL 0
 
 extern "C" int memfd_create(const char *name, unsigned int flags);
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp
index 4bda70fa77cc5..4efe7d92c4cde 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp
@@ -10,7 +10,6 @@
       _rc = (exp);              \
     } while (_rc == -1);        \
   })
-#define NULL 0
 
 extern "C" int pipe2(int pipefd[2], int flags);
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp
index d0dfd978b7c37..e9ac55462fcd7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp
@@ -1,6 +1,7 @@
 // RUN: %check_clang_tidy %s bugprone-posix-return %t
 
-#define NULL nullptr
+#include <cstddef>
+
 #define ZERO 0
 #define NEGATIVE_ONE -1
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c
index 36b1215978603..acb4cca0f94f1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- --
-#define NULL 0
+
+#include <stddef.h>
 
 struct Node1 {
   void *Node1;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp
index d7508009e19ad..4e265b64ae524 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- --
-#define NULL 0
+#include <cstddef>
 
 namespace std {
 using intmax_t = int;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c
index 8eb874a33c101..bf84aa327fae7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c
@@ -3,7 +3,7 @@
 // RUN: clang-tidy %s -checks=-*,modernize-redundant-void-arg -- -std=c17 -Wno-strict-prototypes | count 0
 // RUN: %check_clang_tidy -std=c23-or-later -check-suffixes=C23 %s modernize-redundant-void-arg %t
 
-#define NULL 0
+#include <stddef.h>
 
 extern int i;
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
index 09dc2bb5c1775..a029cd997bdc6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-redundant-void-arg %t
 
-#define NULL 0
+#include <cstddef>
 
 int foo();
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
index b9ffeecf2bafc..7b92cbd9b7608 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -fno-delayed-template-parsing
 
 const unsigned int g_null = 0;
-#define NULL 0
+#include <cstddef>
 
 void test_assignment() {
   int *p1 = 0;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
index d9b7ec2f7d190..9097b93232dcd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy -std=c23-or-later %s modernize-use-nullptr %t
 
-#define NULL 0
+#include <stddef.h>
 
 void test_assignment() {
   int *p1 = 0;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c
index 1218b837199c0..5f659319f3546 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c
@@ -3,7 +3,7 @@
 // Note: this test expects no diagnostics, but FileCheck cannot handle that,
 // hence the use of | count 0.
 
-#define NULL 0
+#include <stddef.h>
 void f(void) {
   char *str = NULL; // ok
   (void)str;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 27a96297c4119..0092a5cc9a47b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
 // RUN:   -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL'}}"
 
-#define NULL 0
+#include <cstddef>
 
 namespace std {
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp
index 1a37c2bbf1133..b8221c1e296de 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s readability-delete-null-pointer %t -- -- -fno-delayed-template-parsing
 
-#define NULL 0
+#include <cstddef>
 
 template <typename T>
 struct Templ {

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
index e6f8eb451f67a..f9326a185b3a6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -1,11 +1,10 @@
-// RUN: %check_clang_tidy -std=c23-or-later %s readability-implicit-bool-conversion %t
-// RUN: %check_clang_tidy -std=c23-or-later -check-suffix=UPPER-CASE %s readability-implicit-bool-conversion %t -- \
+// RUN: %check_clang_tidy -std=c23-or-later %s readability-implicit-bool-conversion %t --system-headers
+// RUN: %check_clang_tidy -std=c23-or-later -check-suffix=UPPER-CASE %s readability-implicit-bool-conversion %t -- --system-headers \
 // RUN:     -config='{CheckOptions: { \
 // RUN:         readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix: true \
 // RUN:     }}'
 
-#undef NULL
-#define NULL 0L
+#include <stddef.h>
 
 void functionTakingBool(bool);
 void functionTakingInt(int);

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp
index ce3a0da796559..94b6f7f1a5d91 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s readability-isolate-declaration %t -- -- -fexceptions
 
+#include <cstddef>
+
 void f() {
   int i;
 }
@@ -190,7 +192,6 @@ void forbidden_transformations() {
     ;
 }
 
-#define NULL 0
 #define MY_NICE_TYPE int **
 #define VAR_NAME(name) name##__LINE__
 #define A_BUNCH_OF_VARIABLES int m1 = 42, m2 = 43, m3 = 44;

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp
index b360ccbadfa5f..bccb1a2285506 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
 
-#define NULL __null
+#include <cstddef>
 
 namespace std {
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
index b74d28f4873bb..77497594fa211 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
@@ -2,7 +2,7 @@
 #include <vector>
 #include <memory>
 
-#define NULL __null
+#include <cstddef>
 
 struct Bar {
   void Do();


        


More information about the cfe-commits mailing list