Skip to content

Commit

Permalink
[NFC] [Decl] Introduce Decl::isFromExplicitGlobalModule
Browse files Browse the repository at this point in the history
Introduce `Decl::isFromExplicitGlobalModule` to replace the
`D->getOwningModule() && D->getOwningModule()->isExplicitGlobalModule()`
pattern to save some typings.
  • Loading branch information
ChuanqiXu9 committed Mar 29, 2024
1 parent aa04f12 commit abfc5ef
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
5 changes: 2 additions & 3 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/AST/DeclBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions clang/unittests/AST/DeclTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand All @@ -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>(
Expand All @@ -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>(
Expand All @@ -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>(
Expand All @@ -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>(
Expand All @@ -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.

Expand All @@ -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>(
Expand All @@ -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) {
Expand Down

0 comments on commit abfc5ef

Please sign in to comment.