[clang-tools-extra] [clang-tidy] Fix llvmlibc-callee-namespace crash on implicit deallocation functions (PR #245163)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 01:09:10 PST 2026


https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/245163

Found via CTIT.

>From c360f458ae3696fc487d303802ac8ef33dbdcd21 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <zeyi2 at nekoarch.cc>
Date: Mon, 23 Nov 2026 09:04:39 +0000
Subject: [PATCH] [clang-tidy] Fix llvmlibc-callee-namespace crash on implicit
 deallocation functions

---
 .../clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp           | 5 +++--
 clang-tools-extra/docs/ReleaseNotes.md                     | 4 ++++
 .../test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp | 7 +++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
index 8f3d150ce0117a..b06adaac855282 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
@@ -63,8 +63,9 @@ void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
        "within the namespace defined by the '%1' macro")
       << FuncDecl << RequiredNamespaceRefMacroName;
 
-  diag(FuncDecl->getLocation(), "resolves to this declaration",
-       DiagnosticIDs::Note);
+  if (FuncDecl->getLocation().isValid())
+    diag(FuncDecl->getLocation(), "resolves to this declaration",
+         DiagnosticIDs::Note);
 }
 
 } // namespace clang::tidy::llvm_libc
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 2566c24544d706..6219e49ba724a4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -277,6 +277,10 @@ infrastructure are described first, followed by tool-specific sections.
   diagnostics are still emitted at the class name for implicitly declared
   destructors.
 
+- Fixed a crash in {doc}`llvmlibc-callee-namespace
+  <clang-tidy/checks/llvmlibc/callee-namespace>` when referencing implicitly
+  declared global allocation or deallocation functions without a source location.
+
 - Improved {doc}`misc-const-correctness
   <clang-tidy/checks/misc/const-correctness>` check:
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp
index c867b92d5881c6..997d2398679450 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp
@@ -84,3 +84,10 @@ void Test() {
 }
 
 } // namespace __llvm_libc
+
+void test_implicit_delete(void *p) {
+  operator delete(p);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator delete' must resolve to a function declared within the namespace defined by the 'LIBC_NAMESPACE' macro
+  operator delete[](p);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator delete[]' must resolve to a function declared within the namespace defined by the 'LIBC_NAMESPACE' macro
+}



More information about the cfe-commits mailing list