[NFC] [C++20] [Modules] Use Sema::isModuleUnitOfCurrentTU to simplify the code
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 27 Jul 2022 06:33:15 +0000 (14:33 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 27 Jul 2022 06:33:28 +0000 (14:33 +0800)
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaLookup.cpp

index 06ea0b4..2ada049 100644 (file)
@@ -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);
index 68158ec..dd1a1e1 100644 (file)
@@ -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: