summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-03-29 16:20:06 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-03-29 16:21:02 +0800
commitabfc5efb55267689f1852fd7ce3e0a38876aa259 (patch)
tree71ba73374e09fe03843418680bf36f37b546d24c
parentaa04f12fa9f086f62f81841f159085723c255245 (diff)
[NFC] [Decl] Introduce Decl::isFromExplicitGlobalModule
Introduce `Decl::isFromExplicitGlobalModule` to replace the `D->getOwningModule() && D->getOwningModule()->isExplicitGlobalModule()` pattern to save some typings.
-rw-r--r--clang/include/clang/AST/DeclBase.h5
-rw-r--r--clang/lib/AST/DeclBase.cpp8
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
-rw-r--r--clang/unittests/AST/DeclTest.cpp16
4 files changed, 17 insertions, 14 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0..858450926455 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -669,9 +669,8 @@ public:
/// Whether this declaration comes from another module unit.
bool isInAnotherModuleUnit() const;
- /// FIXME: Implement discarding declarations actually in global module
- /// fragment. See [module.global.frag]p3,4 for details.
- bool isDiscardedInGlobalModuleFragment() const { return false; }
+ /// Whether this declaration comes from explicit global module.
+ bool isFromExplicitGlobalModule() const;
/// Check if we should skip checking ODRHash for declaration \param D.
///
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 04bbc49ab2f3..2cbb86b31b5e 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1102,9 +1102,13 @@ bool Decl::isInAnotherModuleUnit() const {
return M != getASTContext().getCurrentNamedModule();
}
+bool Decl::isFromExplicitGlobalModule() const {
+ return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
+}
+
bool Decl::shouldSkipCheckingODR() const {
- return getASTContext().getLangOpts().SkipODRCheckInGMF && getOwningModule() &&
- getOwningModule()->isExplicitGlobalModule();
+ return getASTContext().getLangOpts().SkipODRCheckInGMF &&
+ isFromExplicitGlobalModule();
}
static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0bd88ece2aa5..503f1f6f53a2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9915,7 +9915,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
// FIXME: We need a better way to separate C++ standard and clang modules.
bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
!NewFD->getOwningModule() ||
- NewFD->getOwningModule()->isGlobalModule() ||
+ NewFD->isFromExplicitGlobalModule() ||
NewFD->getOwningModule()->isHeaderLikeModule();
bool isInline = D.getDeclSpec().isInlineSpecified();
bool isVirtual = D.getDeclSpec().isVirtualSpecified();
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index cef0f8711416..2530ce74eb6a 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -429,7 +429,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator new"),
Ctx));
ASSERT_TRUE(SizedOperatorNew->getOwningModule());
- EXPECT_TRUE(SizedOperatorNew->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(SizedOperatorNew->isFromExplicitGlobalModule());
// void* operator new(std::size_t, std::align_val_t);
auto *SizedAlignedOperatorNew = selectFirst<FunctionDecl>(
@@ -441,7 +441,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator new"),
Ctx));
ASSERT_TRUE(SizedAlignedOperatorNew->getOwningModule());
- EXPECT_TRUE(SizedAlignedOperatorNew->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(SizedAlignedOperatorNew->isFromExplicitGlobalModule());
// void* operator new[](std::size_t);
auto *SizedArrayOperatorNew = selectFirst<FunctionDecl>(
@@ -451,7 +451,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator new[]"),
Ctx));
ASSERT_TRUE(SizedArrayOperatorNew->getOwningModule());
- EXPECT_TRUE(SizedArrayOperatorNew->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(SizedArrayOperatorNew->isFromExplicitGlobalModule());
// void* operator new[](std::size_t, std::align_val_t);
auto *SizedAlignedArrayOperatorNew = selectFirst<FunctionDecl>(
@@ -464,7 +464,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
Ctx));
ASSERT_TRUE(SizedAlignedArrayOperatorNew->getOwningModule());
EXPECT_TRUE(
- SizedAlignedArrayOperatorNew->getOwningModule()->isGlobalModule());
+ SizedAlignedArrayOperatorNew->isFromExplicitGlobalModule());
// void operator delete(void*) noexcept;
auto *Delete = selectFirst<FunctionDecl>(
@@ -475,7 +475,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator delete"),
Ctx));
ASSERT_TRUE(Delete->getOwningModule());
- EXPECT_TRUE(Delete->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(Delete->isFromExplicitGlobalModule());
// void operator delete(void*, std::align_val_t) noexcept;
auto *AlignedDelete = selectFirst<FunctionDecl>(
@@ -487,7 +487,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator delete"),
Ctx));
ASSERT_TRUE(AlignedDelete->getOwningModule());
- EXPECT_TRUE(AlignedDelete->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(AlignedDelete->isFromExplicitGlobalModule());
// Sized deallocation is not enabled by default. So we skip it here.
@@ -500,7 +500,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator delete[]"),
Ctx));
ASSERT_TRUE(ArrayDelete->getOwningModule());
- EXPECT_TRUE(ArrayDelete->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(ArrayDelete->isFromExplicitGlobalModule());
// void operator delete[](void*, std::align_val_t) noexcept;
auto *AlignedArrayDelete = selectFirst<FunctionDecl>(
@@ -512,7 +512,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
.bind("operator delete[]"),
Ctx));
ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
- EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
+ EXPECT_TRUE(AlignedArrayDelete->isFromExplicitGlobalModule());
}
TEST(Decl, TemplateArgumentDefaulted) {