[clang] 39986f0 - [NFCI] [Serialization] Use demoteThisDefinitionToDeclaration instead of setCompleteDefinition(false) for CXXRecordDecl

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 00:48:30 PDT 2024


Author: Chuanqi Xu
Date: 2024-08-23T15:43:43+08:00
New Revision: 39986f0b4d797e4ad3c12607f2b4abe2322b82bb

URL: https://github.com/llvm/llvm-project/commit/39986f0b4d797e4ad3c12607f2b4abe2322b82bb
DIFF: https://github.com/llvm/llvm-project/commit/39986f0b4d797e4ad3c12607f2b4abe2322b82bb.diff

LOG: [NFCI] [Serialization] Use demoteThisDefinitionToDeclaration instead of setCompleteDefinition(false) for CXXRecordDecl

When we merge the definition for CXXRecordDecl, we would use
setCompleteDefinition(false) to mark the merged definition. But this was
not the correct/good interface. We can't know that the merged definition
was a definition then. And actually, we provided an interface for this:
demoteThisDefinitionToDeclaration.

So this patch tries to use the correct API.

This was found in the downstream developing. This is not strictly NFC
but it is intended to be NFC for every end users.

Added: 
    

Modified: 
    clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index a6da103ed9799e..4d9d024796716e 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2064,7 +2064,7 @@ void ASTDeclMerger::MergeDefinitionData(
     Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
                                                     DD.Definition));
     Reader.PendingDefinitions.erase(MergeDD.Definition);
-    MergeDD.Definition->setCompleteDefinition(false);
+    MergeDD.Definition->demoteThisDefinitionToDeclaration();
     Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
     assert(!Reader.Lookups.contains(MergeDD.Definition) &&
            "already loaded pending lookups for merged definition");
@@ -2175,6 +2175,9 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
   D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D, LambdaContext, IndexInLambdaContext);
 
+  // Mark this declaration as being a definition.
+  D->setCompleteDefinition(true);
+
   // We might already have a 
diff erent definition for this record. This can
   // happen either because we're reading an update record, or because we've
   // already done some merging. Either way, just merge into it.
@@ -2183,9 +2186,6 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
     return;
   }
 
-  // Mark this declaration as being a definition.
-  D->setCompleteDefinition(true);
-
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
   // DefinitionData pointer onto them.


        


More information about the cfe-commits mailing list