[clang-tools-extra] [clang-tidy][libc] Fix namespace check with macro (PR #68134)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 3 15:36:05 PDT 2023
https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/68134
>From baf9d8e19d2b064c05527757c6173f875b59b286 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 3 Oct 2023 10:39:02 -0700
Subject: [PATCH 1/2] [clang-tidy][libc] Fix namespace check with macro
The name of the namespace for LLVM's libc is now provided by a macro.
The ImplementationNamespaceCheck was updated to handle this, but the
CalleeNamespaceCheck was missed. This patch updates the
CalleeNamespaceCheck to handle the macro.
---
.../clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
index 98ae857b589fd64..7ad4b5fb7f043ab 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
@@ -45,9 +45,10 @@ void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
if (FuncDecl->getBuiltinID() != 0)
return;
- // If the outermost namespace of the function is __llvm_libc, we're good.
+ // If the outermost namespace of the function starts with __llvm_libc, we're
+ // good.
const auto *NS = dyn_cast<NamespaceDecl>(getOutermostNamespace(FuncDecl));
- if (NS && NS->getName() == "__llvm_libc")
+ if (NS && NS->getName().starts_with("__llvm_libc"))
return;
const DeclarationName &Name = FuncDecl->getDeclName();
@@ -55,8 +56,9 @@ void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
IgnoredFunctions.contains(Name.getAsIdentifierInfo()->getName()))
return;
- diag(UsageSiteExpr->getBeginLoc(), "%0 must resolve to a function declared "
- "within the '__llvm_libc' namespace")
+ diag(UsageSiteExpr->getBeginLoc(),
+ "%0 must resolve to a function declared "
+ "within the '__llvm_libc' namespace (use macro `LIBC_NAMESPACE`)")
<< FuncDecl;
diag(FuncDecl->getLocation(), "resolves to this declaration",
>From b3c710beda5b45dc18a5cbd74e141c1169971450 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 3 Oct 2023 15:35:32 -0700
Subject: [PATCH 2/2] update release notes
---
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 8fc28c090341802..36cc58f4ab91b21 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -321,6 +321,11 @@ Changes in existing checks
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
identify calls to static member functions with out-of-class inline definitions.
+- Improved :doc:`llvmlibc-callee-namespace
+ <clang-tidy/checks/llvmlibc/callee-namespace>` to support
+ customizable namespace. This matches the change made to implementation in
+ namespace.
+
Removed checks
^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list