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

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


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Zeyi Xu (zeyi2)

<details>
<summary>Changes</summary>

Found via CTIT.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp (+3-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.md (+4) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/llvmlibc/callee-namespace.cpp (+7) 


``````````diff
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
+}

``````````

</details>


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


More information about the cfe-commits mailing list