Skip to content

Commit 63bcfd5

Browse files
committed
[libc] Update libc namespace clang-tidy checks
Namespace macro that should be used to declare a new namespace is updated from LIBC_NAMESPACE to LIBC_NAMESPACE_DECL which by default has hidden visibility (#97109). This commit updates the clang-tidy checks to match the new policy.
1 parent cb4cd3a commit 63bcfd5

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
5151
// __llvm_libc, we're good.
5252
const auto *NS = dyn_cast<NamespaceDecl>(getOutermostNamespace(FuncDecl));
5353
if (NS && Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) &&
54-
NS->getName().starts_with(RequiredNamespaceStart))
54+
NS->getName().starts_with(RequiredNamespaceRefStart))
5555
return;
5656

5757
const DeclarationName &Name = FuncDecl->getDeclName();
@@ -62,7 +62,7 @@ void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
6262
diag(UsageSiteExpr->getBeginLoc(),
6363
"%0 must resolve to a function declared "
6464
"within the namespace defined by the '%1' macro")
65-
<< FuncDecl << RequiredNamespaceMacroName;
65+
<< FuncDecl << RequiredNamespaceRefMacroName;
6666

6767
diag(FuncDecl->getLocation(), "resolves to this declaration",
6868
clang::DiagnosticIDs::Note);

clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ void ImplementationInNamespaceCheck::check(
3333
if (NS == nullptr || NS->isAnonymousNamespace()) {
3434
diag(MatchedDecl->getLocation(),
3535
"declaration must be enclosed within the '%0' namespace")
36-
<< RequiredNamespaceMacroName;
36+
<< RequiredNamespaceDeclMacroName;
3737
return;
3838
}
3939
if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
4040
diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
41-
<< RequiredNamespaceMacroName;
41+
<< RequiredNamespaceDeclMacroName;
4242
return;
4343
}
44-
if (NS->getName().starts_with(RequiredNamespaceStart) == false) {
44+
if (NS->getName().starts_with(RequiredNamespaceDeclStart) == false) {
4545
diag(NS->getLocation(), "the '%0' macro should start with '%1'")
46-
<< RequiredNamespaceMacroName << RequiredNamespaceStart;
46+
<< RequiredNamespaceDeclMacroName << RequiredNamespaceDeclStart;
4747
return;
4848
}
4949
}

clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
namespace clang::tidy::llvm_libc {
1212

13-
const static llvm::StringRef RequiredNamespaceStart = "__llvm_libc";
14-
const static llvm::StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
13+
const static llvm::StringRef RequiredNamespaceRefStart = "__llvm_libc";
14+
const static llvm::StringRef RequiredNamespaceRefMacroName = "LIBC_NAMESPACE";
15+
const static llvm::StringRef RequiredNamespaceDeclStart =
16+
"[[gnu::visibility(\"hidden\")]] __llvm_libc";
17+
const static llvm::StringRef RequiredNamespaceDeclMacroName =
18+
"LIBC_NAMESPACE_DECL";
1519

1620
} // namespace clang::tidy::llvm_libc

clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
#define MACRO_A "defining macros outside namespace is valid"
44

55
class ClassB;
6-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
6+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
77
struct StructC {};
8-
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
8+
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
99
char *VarD = MACRO_A;
10-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
10+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
1111
typedef int typeE;
12-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
12+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
1313
void funcF() {}
14-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
14+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
1515

1616
namespace outer_most {
17-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro
17+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE_DECL' macro
1818
class A {};
1919
}
2020

2121
// Wrapped in anonymous namespace.
2222
namespace {
23-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace
23+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace
2424
class A {};
2525
}
2626

2727
namespace namespaceG {
28-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro
28+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE_DECL' macro
2929
namespace __llvm_libc {
3030
namespace namespaceH {
3131
class ClassB;
@@ -38,19 +38,19 @@ void funcF() {}
3838
} // namespace namespaceG
3939

4040
// Wrapped in macro namespace but with an incorrect name
41-
#define LIBC_NAMESPACE custom_namespace
42-
namespace LIBC_NAMESPACE {
43-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'LIBC_NAMESPACE' macro should start with '__llvm_libc'
41+
#define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] custom_namespace
42+
namespace LIBC_NAMESPACE_DECL {
43+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'LIBC_NAMESPACE_DECL' macro should start with '__llvm_libc'
4444
namespace namespaceH {
4545
class ClassB;
4646
} // namespace namespaceH
47-
} // namespace LIBC_NAMESPACE
47+
} // namespace LIBC_NAMESPACE_DECL
4848

4949

50-
// Wrapped in macro namespace with a valid name, LIBC_NAMESPACE starts with '__llvm_libc'
51-
#undef LIBC_NAMESPACE
52-
#define LIBC_NAMESPACE __llvm_libc_xyz
53-
namespace LIBC_NAMESPACE {
50+
// Wrapped in macro namespace with a valid name, LIBC_NAMESPACE_DECL starts with '__llvm_libc'
51+
#undef LIBC_NAMESPACE_DECL
52+
#define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] __llvm_libc_xyz
53+
namespace LIBC_NAMESPACE_DECL {
5454
namespace namespaceI {
5555
class ClassB;
5656
} // namespace namespaceI
@@ -59,4 +59,4 @@ char *VarD = MACRO_A;
5959
typedef int typeE;
6060
void funcF() {}
6161
extern "C" void extern_funcJ() {}
62-
} // namespace LIBC_NAMESPACE
62+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)