[cfe-commits] r167990 - /cfe/trunk/lib/AST/ASTImporter.cpp

Douglas Gregor dgregor at apple.com
Wed Nov 14 14:29:20 PST 2012


Author: dgregor
Date: Wed Nov 14 16:29:20 2012
New Revision: 167990

URL: http://llvm.org/viewvc/llvm-project?rev=167990&view=rev
Log:
Teach the AST importer to merge enumerator constants. Fixes
<rdar://problem/12676166>, and tested on the LLDB side of the world.

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=167990&r1=167989&r2=167990&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Nov 14 16:29:20 2012
@@ -122,6 +122,7 @@
     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 @@
   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 @@
     for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
       if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
         continue;
-      
+
+      if (EnumConstantDecl *FoundEnumConstant
+            = dyn_cast<EnumConstantDecl>(FoundDecls[I])) {
+        if (IsStructuralMatch(D, FoundEnumConstant))
+          return Importer.Imported(D, FoundEnumConstant);
+      }
+
       ConflictingDecls.push_back(FoundDecls[I]);
     }
     





More information about the cfe-commits mailing list