Implemented support for testing the ASTImporter's
authorSean Callanan <scallanan@apple.com>
Tue, 28 Apr 2015 18:24:12 +0000 (18:24 +0000)
committerSean Callanan <scallanan@apple.com>
Tue, 28 Apr 2015 18:24:12 +0000 (18:24 +0000)
ability to generate code that CodeGen likes.  Test
cases can use this functionality by calling

// RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge %t.2.ast %s

llvm-svn: 236011

clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/Frontend/ASTMerge.cpp

index 60aac07..b06fe42 100644 (file)
@@ -79,6 +79,11 @@ namespace clang {
     }
 
     void Initialize(ASTContext &Ctx) override {
+      if (Context) {
+        assert(Context == &Ctx);
+        return;
+      }
+        
       Context = &Ctx;
 
       if (llvm::TimePassesIsEnabled)
index 216ac6a..b84df94 100644 (file)
@@ -57,6 +57,7 @@ void ASTMergeAction::ExecuteAction() {
                          /*MinimalImport=*/false);
 
     TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
+    CI.getASTConsumer().Initialize(CI.getASTContext());
     for (auto *D : TU->decls()) {
       // Don't re-import __va_list_tag, __builtin_va_list.
       if (const auto *ND = dyn_cast<NamedDecl>(D))
@@ -64,7 +65,12 @@ void ASTMergeAction::ExecuteAction() {
           if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
             continue;
       
-      Importer.Import(D);
+      Decl *ToD = Importer.Import(D);
+    
+      if (ToD) {
+        DeclGroupRef DGR(ToD);
+        CI.getASTConsumer().HandleTopLevelDecl(DGR);
+      }
     }
   }