[clang] [C++20] [Modules] Implementing Eliding Unreachable Decls of GMF in ASTWriter (PR #76930)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 01:43:23 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 7a3b0cbb143d02b70b2bfae5cd40e9867c124748 b9a03912276d25ff819a755bef4ee72d64ce1480 -- clang/test/CXX/module/module.glob.frag/cxx20-10-4-ex2.cppm clang/test/Modules/abi-tag.cppm clang/include/clang/AST/DeclBase.h clang/include/clang/Serialization/ASTWriter.h clang/lib/Sema/SemaModule.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp clang/test/CXX/module/module.import/p2.cpp clang/test/CodeGenCXX/module-intializer-pmf.cpp clang/test/CodeGenCXX/module-intializer.cpp clang/test/Modules/concept.cppm clang/test/Modules/explicitly-specialized-template.cpp clang/test/Modules/inconsistent-deduction-guide-linkage.cppm clang/test/Modules/named-modules-adl-2.cppm clang/test/Modules/named-modules-adl.cppm clang/test/Modules/polluted-operator.cppm clang/test/Modules/pr58716.cppm clang/test/Modules/pr60775.cppm clang/test/Modules/pr62589.cppm clang/test/Modules/preferred_name.cppm clang/test/Modules/redundant-template-default-arg3.cpp clang/test/Modules/template-function-specialization.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 4823cbd5dd..b981a8e5bd 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3992,9 +3992,9 @@ ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC,
         if (IsDeclModuleDiscardable(D))
           MarkDeclReachable(D);
     } else if (llvm::all_of(Result.getLookupResult(), [this](NamedDecl *D) {
-            return IsDeclModuleDiscardable(D);
-          }))
-        continue;
+                 return IsDeclModuleDiscardable(D);
+               }))
+      continue;
 
     // We also skip empty results. If any of the results could be external and
     // the currently available results are empty, then all of the results are
@@ -5744,13 +5744,12 @@ bool ASTWriter::IsSpecialDeclNotDiscardable(Decl *D) {
   //
   // This may imply that the ODR checking process is context sensitive.
   // That said, the same type in different module units can be considered to be
-  // different if some module units discard the unused `__gnu_cxx::__cxx11` namespace
-  // while other module units don't. This is incorrect.
+  // different if some module units discard the unused `__gnu_cxx::__cxx11`
+  // namespace while other module units don't. This is incorrect.
   //
-  // This is a workaround to make things happen but we indeed to fix the ODR checking
-  // process indeed.
-  if (auto *ND = dyn_cast<NamedDecl>(D);
-      ND && ND->getAttr<AbiTagAttr>()) {
+  // This is a workaround to make things happen but we indeed to fix the ODR
+  // checking process indeed.
+  if (auto *ND = dyn_cast<NamedDecl>(D); ND && ND->getAttr<AbiTagAttr>()) {
     MarkDeclReachable(D);
     return true;
   }
@@ -5779,7 +5778,8 @@ bool ASTWriter::IsDeclModuleDiscardable(const Decl *ConstD) {
     DC = DC->getParent()->getNonTransparentContext();
 
   assert(DC && "Why is the decl not covered by file context?");
-  if (!DC->isFileContext() && !cast<Decl>(DC)->isDiscardedInGlobalModuleFragment()) {
+  if (!DC->isFileContext() &&
+      !cast<Decl>(DC)->isDiscardedInGlobalModuleFragment()) {
     MarkDeclReachable(D);
     return false;
   }
@@ -5835,7 +5835,8 @@ DeclID ASTWriter::GetDeclRef(const Decl *D) {
   if (D->isFromASTFile())
     return D->getGlobalID();
 
-  assert(!D->isDiscardedInGlobalModuleFragment() && "We shouldn't write discarded decl.\n");
+  assert(!D->isDiscardedInGlobalModuleFragment() &&
+         "We shouldn't write discarded decl.\n");
 
   assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer");
   DeclID &ID = DeclIDs[D];

``````````

</details>


https://github.com/llvm/llvm-project/pull/76930


More information about the cfe-commits mailing list