[clang] abfc5ef - [NFC] [Decl] Introduce Decl::isFromExplicitGlobalModule
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 29 01:30:19 PDT 2024
Author: Chuanqi Xu
Date: 2024-03-29T16:21:02+08:00
New Revision: abfc5efb55267689f1852fd7ce3e0a38876aa259
URL: https://github.com/llvm/llvm-project/commit/abfc5efb55267689f1852fd7ce3e0a38876aa259
DIFF: https://github.com/llvm/llvm-project/commit/abfc5efb55267689f1852fd7ce3e0a38876aa259.diff
LOG: [NFC] [Decl] Introduce Decl::isFromExplicitGlobalModule
Introduce `Decl::isFromExplicitGlobalModule` to replace the
`D->getOwningModule() && D->getOwningModule()->isExplicitGlobalModule()`
pattern to save some typings.
Added:
Modified:
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp
clang/lib/Sema/SemaDecl.cpp
clang/unittests/AST/DeclTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -669,9 +669,8 @@ class alignas(8) Decl {
/// 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 04bbc49ab2f319..2cbb86b31b5e2e 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 0bd88ece2aa544..503f1f6f53a258 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 cef0f8711416b6..2530ce74eb6a37 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) {
More information about the cfe-commits
mailing list