diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 47ed6d0d1db0d..858450926455c 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 04bbc49ab2f31..2cbb86b31b5e2 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 0bd88ece2aa54..503f1f6f53a25 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 cef0f8711416b..2530ce74eb6a3 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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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) {