From: Douglas Gregor Date: Wed, 14 Nov 2012 22:29:20 +0000 (+0000) Subject: Teach the AST importer to merge enumerator constants. Fixes X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91155087e905b4004beb2865512d3c86a24f9112;p=platform%2Fupstream%2Fllvm.git Teach the AST importer to merge enumerator constants. Fixes , and tested on the LLDB side of the world. llvm-svn: 167990 --- diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 0d4f303..906cc3b 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -122,6 +122,7 @@ namespace clang { bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, bool Complain = true); bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); + bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); Decl *VisitDecl(Decl *D); Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); @@ -2143,7 +2144,18 @@ bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); } -bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, +bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, + EnumConstantDecl *ToEC) +{ + const llvm::APSInt &FromVal = FromEC->getInitVal(); + const llvm::APSInt &ToVal = ToEC->getInitVal(); + + return FromVal.isSigned() == ToVal.isSigned() && + FromVal.getBitWidth() == ToVal.getBitWidth() && + FromVal == ToVal; +} + +bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To) { StructuralEquivalenceContext Ctx(Importer.getFromContext(), Importer.getToContext(), @@ -2526,7 +2538,13 @@ Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - + + if (EnumConstantDecl *FoundEnumConstant + = dyn_cast(FoundDecls[I])) { + if (IsStructuralMatch(D, FoundEnumConstant)) + return Importer.Imported(D, FoundEnumConstant); + } + ConflictingDecls.push_back(FoundDecls[I]); }