From: Sean Callanan Date: Tue, 19 Jul 2011 22:38:25 +0000 (+0000) Subject: This fix (thanks to Doug Gregor) corrects a bug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=673e775beba71a69dbab4fcd733a84f4cfe2ebfc;p=clang This fix (thanks to Doug Gregor) corrects a bug 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 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index f5e392f88d..e8e4c6a108 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -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(From)) { ASTNodeImporter Importer(*this); + + if (RecordDecl *ToRecord = dyn_cast(To)) { + if (!ToRecord->getDefinition()) { + Importer.ImportDefinition(cast(FromDC), ToRecord, + /*ForceImport=*/true); + return; + } + } + Importer.ImportDeclContext(FromDC, true); } }