]> granicus.if.org Git - clang/commitdiff
This fix (thanks to Doug Gregor) corrects a bug
authorSean Callanan <scallanan@apple.com>
Tue, 19 Jul 2011 22:38:25 +0000 (22:38 +0000)
committerSean Callanan <scallanan@apple.com>
Tue, 19 Jul 2011 22:38:25 +0000 (22:38 +0000)
in ImportDefinition when replacing a previously
forward-declared CXXRecordDecl with its full
definition.  The forward-declared type's
DefinitionData had not been intialized for the
forward-declared type, so adding fields to the
Decl caused CXXRecordDecl::addedMember() to
crash when accessing the DefinitionData.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135530 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp

index f5e392f88d0bce6a22a780684e21daf36737490b..e8e4c6a1082d051bcb90eb1d2a6735ffe05f6caf 100644 (file)
@@ -86,7 +86,7 @@ namespace {
     void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
                                   DeclarationNameInfo& To);
     void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
-    bool ImportDefinition(RecordDecl *From, RecordDecl *To);
+    bool ImportDefinition(RecordDecl *From, RecordDecl *To, bool ForceImport = false);
     TemplateParameterList *ImportTemplateParameterList(
                                                  TemplateParameterList *Params);
     TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
@@ -1781,7 +1781,7 @@ void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
     Importer.Import(*From);
 }
 
-bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To) {
+bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, bool ForceImport) {
   if (To->getDefinition())
     return false;
   
@@ -1818,7 +1818,7 @@ bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To) {
       ToCXX->setBases(Bases.data(), Bases.size());
   }
   
-  ImportDeclContext(From);
+  ImportDeclContext(From, ForceImport);
   To->completeDefinition();
   return false;
 }
@@ -4306,6 +4306,15 @@ void ASTImporter::ImportDefinition(Decl *From) {
   
   if (DeclContext *FromDC = cast<DeclContext>(From)) {
     ASTNodeImporter Importer(*this);
+      
+    if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
+      if (!ToRecord->getDefinition()) {
+        Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, 
+                                  /*ForceImport=*/true);
+        return;
+      }      
+    }
+      
     Importer.ImportDeclContext(FromDC, true);
   }
 }