Skip to content

Commit abfc5ef

Browse files
committed
[NFC] [Decl] Introduce Decl::isFromExplicitGlobalModule
Introduce `Decl::isFromExplicitGlobalModule` to replace the `D->getOwningModule() && D->getOwningModule()->isExplicitGlobalModule()` pattern to save some typings.
1 parent aa04f12 commit abfc5ef

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,8 @@ class alignas(8) Decl {
669669
/// Whether this declaration comes from another module unit.
670670
bool isInAnotherModuleUnit() const;
671671

672-
/// FIXME: Implement discarding declarations actually in global module
673-
/// fragment. See [module.global.frag]p3,4 for details.
674-
bool isDiscardedInGlobalModuleFragment() const { return false; }
672+
/// Whether this declaration comes from explicit global module.
673+
bool isFromExplicitGlobalModule() const;
675674

676675
/// Check if we should skip checking ODRHash for declaration \param D.
677676
///

clang/lib/AST/DeclBase.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,13 @@ bool Decl::isInAnotherModuleUnit() const {
11021102
return M != getASTContext().getCurrentNamedModule();
11031103
}
11041104

1105+
bool Decl::isFromExplicitGlobalModule() const {
1106+
return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
1107+
}
1108+
11051109
bool Decl::shouldSkipCheckingODR() const {
1106-
return getASTContext().getLangOpts().SkipODRCheckInGMF && getOwningModule() &&
1107-
getOwningModule()->isExplicitGlobalModule();
1110+
return getASTContext().getLangOpts().SkipODRCheckInGMF &&
1111+
isFromExplicitGlobalModule();
11081112
}
11091113

11101114
static Decl::Kind getKind(const Decl *D) { return D->getKind(); }

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9915,7 +9915,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
99159915
// FIXME: We need a better way to separate C++ standard and clang modules.
99169916
bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
99179917
!NewFD->getOwningModule() ||
9918-
NewFD->getOwningModule()->isGlobalModule() ||
9918+
NewFD->isFromExplicitGlobalModule() ||
99199919
NewFD->getOwningModule()->isHeaderLikeModule();
99209920
bool isInline = D.getDeclSpec().isInlineSpecified();
99219921
bool isVirtual = D.getDeclSpec().isVirtualSpecified();

clang/unittests/AST/DeclTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
429429
.bind("operator new"),
430430
Ctx));
431431
ASSERT_TRUE(SizedOperatorNew->getOwningModule());
432-
EXPECT_TRUE(SizedOperatorNew->getOwningModule()->isGlobalModule());
432+
EXPECT_TRUE(SizedOperatorNew->isFromExplicitGlobalModule());
433433

434434
// void* operator new(std::size_t, std::align_val_t);
435435
auto *SizedAlignedOperatorNew = selectFirst<FunctionDecl>(
@@ -441,7 +441,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
441441
.bind("operator new"),
442442
Ctx));
443443
ASSERT_TRUE(SizedAlignedOperatorNew->getOwningModule());
444-
EXPECT_TRUE(SizedAlignedOperatorNew->getOwningModule()->isGlobalModule());
444+
EXPECT_TRUE(SizedAlignedOperatorNew->isFromExplicitGlobalModule());
445445

446446
// void* operator new[](std::size_t);
447447
auto *SizedArrayOperatorNew = selectFirst<FunctionDecl>(
@@ -451,7 +451,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
451451
.bind("operator new[]"),
452452
Ctx));
453453
ASSERT_TRUE(SizedArrayOperatorNew->getOwningModule());
454-
EXPECT_TRUE(SizedArrayOperatorNew->getOwningModule()->isGlobalModule());
454+
EXPECT_TRUE(SizedArrayOperatorNew->isFromExplicitGlobalModule());
455455

456456
// void* operator new[](std::size_t, std::align_val_t);
457457
auto *SizedAlignedArrayOperatorNew = selectFirst<FunctionDecl>(
@@ -464,7 +464,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
464464
Ctx));
465465
ASSERT_TRUE(SizedAlignedArrayOperatorNew->getOwningModule());
466466
EXPECT_TRUE(
467-
SizedAlignedArrayOperatorNew->getOwningModule()->isGlobalModule());
467+
SizedAlignedArrayOperatorNew->isFromExplicitGlobalModule());
468468

469469
// void operator delete(void*) noexcept;
470470
auto *Delete = selectFirst<FunctionDecl>(
@@ -475,7 +475,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
475475
.bind("operator delete"),
476476
Ctx));
477477
ASSERT_TRUE(Delete->getOwningModule());
478-
EXPECT_TRUE(Delete->getOwningModule()->isGlobalModule());
478+
EXPECT_TRUE(Delete->isFromExplicitGlobalModule());
479479

480480
// void operator delete(void*, std::align_val_t) noexcept;
481481
auto *AlignedDelete = selectFirst<FunctionDecl>(
@@ -487,7 +487,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
487487
.bind("operator delete"),
488488
Ctx));
489489
ASSERT_TRUE(AlignedDelete->getOwningModule());
490-
EXPECT_TRUE(AlignedDelete->getOwningModule()->isGlobalModule());
490+
EXPECT_TRUE(AlignedDelete->isFromExplicitGlobalModule());
491491

492492
// Sized deallocation is not enabled by default. So we skip it here.
493493

@@ -500,7 +500,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
500500
.bind("operator delete[]"),
501501
Ctx));
502502
ASSERT_TRUE(ArrayDelete->getOwningModule());
503-
EXPECT_TRUE(ArrayDelete->getOwningModule()->isGlobalModule());
503+
EXPECT_TRUE(ArrayDelete->isFromExplicitGlobalModule());
504504

505505
// void operator delete[](void*, std::align_val_t) noexcept;
506506
auto *AlignedArrayDelete = selectFirst<FunctionDecl>(
@@ -512,7 +512,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
512512
.bind("operator delete[]"),
513513
Ctx));
514514
ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
515-
EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
515+
EXPECT_TRUE(AlignedArrayDelete->isFromExplicitGlobalModule());
516516
}
517517

518518
TEST(Decl, TemplateArgumentDefaulted) {

0 commit comments

Comments
 (0)