From 8d91b1da576b1643175fbac0fb4b3a95bed07bf0 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 27 Jul 2022 14:33:15 +0800 Subject: [PATCH] [NFC] [C++20] [Modules] Use Sema::isModuleUnitOfCurrentTU to simplify the code --- clang/include/clang/Sema/Sema.h | 6 +++--- clang/lib/Sema/SemaLookup.cpp | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 06ea0b4..2ada049 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2278,9 +2278,6 @@ private: bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); - // Determine whether the module M belongs to the current TU. - bool isModuleUnitOfCurrentTU(const Module *M) const; - public: /// Get the module unit whose scope we are currently within. Module *getCurrentModule() const { @@ -2301,6 +2298,9 @@ public: return DirectModuleImports.contains(M); } + // Determine whether the module M belongs to the current TU. + bool isModuleUnitOfCurrentTU(const Module *M) const; + /// Make a merged definition of an existing hidden definition \p ND /// visible at the specified location. void makeMergedDefinitionVisible(NamedDecl *ND); diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 68158ec..dd1a1e1 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1920,12 +1920,7 @@ bool LookupResult::isReachableSlow(Sema &SemaRef, NamedDecl *D) { // If D comes from a module and SemaRef doesn't own a module, it implies D // comes from another TU. In case SemaRef owns a module, we could judge if D // comes from another TU by comparing the module unit. - // - // FIXME: It would look better if we have direct method to judge whether D is - // in another TU. - if (SemaRef.getCurrentModule() && - SemaRef.getCurrentModule()->getTopLevelModule() == - DeclModule->getTopLevelModule()) + if (SemaRef.isModuleUnitOfCurrentTU(DeclModule)) return true; // [module.reach]/p3: -- 2.7.4