[ASTImporter] Fix IsStructuralMatch specialization for EnumDecl to prevent re-importi...
authorShafik Yaghmour <syaghmour@apple.com>
Wed, 27 Mar 2019 17:47:36 +0000 (17:47 +0000)
committerShafik Yaghmour <syaghmour@apple.com>
Wed, 27 Mar 2019 17:47:36 +0000 (17:47 +0000)
Summary:
We may try and re-import an EnumDecl while trying to complete it in IsStructuralMatch(...) specialization for EnumDecl. This change mirrors a similar fix for the specialization for RecordDecl.

Differential Revision: https://reviews.llvm.org/D59845

llvm-svn: 357100

clang/lib/AST/ASTImporter.cpp

index dbad548..6048296 100644 (file)
@@ -1946,6 +1946,12 @@ bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
 }
 
 bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) {
+  // Eliminate a potential failure point where we attempt to re-import
+  // something we're trying to import while completin ToEnum
+  if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum))
+    if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin))
+        ToEnum = ToOriginEnum;
+
   StructuralEquivalenceContext Ctx(
       Importer.getFromContext(), Importer.getToContext(),
       Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer));