Skip to content

[clang-tidy][libc] Fix namespace check with macro #68134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ 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();
if (Name.isIdentifier() &&
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",
Expand Down