[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 10:43:48 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/68134.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp (+6-4)
``````````diff
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",
``````````
</details>
https://github.com/llvm/llvm-project/pull/68134
More information about the cfe-commits
mailing list