]> granicus.if.org Git - clang/commitdiff
[modules] Support use of -E on modules built from the command line.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 15 Sep 2018 01:21:18 +0000 (01:21 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 15 Sep 2018 01:21:18 +0000 (01:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342306 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/FrontendAction.cpp
lib/Frontend/FrontendActions.cpp
lib/Frontend/Rewrite/FrontendActions.cpp
test/Modules/no-module-map.cpp

index 10f1d1ef611d1f7d863879ad5c3bffe68c20e5c1..d24700535e270e83cefef7546a8bdd76ba798f18 100644 (file)
@@ -587,12 +587,12 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
       assert(ASTModule && "module file does not define its own module");
       Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind);
     } else {
-      auto &SM = CI.getSourceManager();
-      FileID ID = SM.getMainFileID();
-      if (auto *File = SM.getFileEntryForID(ID))
+      auto &OldSM = AST->getSourceManager();
+      FileID ID = OldSM.getMainFileID();
+      if (auto *File = OldSM.getFileEntryForID(ID))
         Input = FrontendInputFile(File->getName(), Kind);
       else
-        Input = FrontendInputFile(SM.getBuffer(ID), Kind);
+        Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
     }
     setCurrentInput(Input, std::move(AST));
   }
index d0d83076f1d19be1bc2b2428b6ce8580d1759ed2..08d91e6a5a12a8446c3b7f5ee7d080ac1d08df50 100644 (file)
@@ -825,7 +825,7 @@ void PrintPreprocessedAction::ExecuteAction() {
   }
 
   std::unique_ptr<raw_ostream> OS =
-      CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
+      CI.createDefaultOutputFile(BinaryMode, getCurrentFileOrBufferName());
   if (!OS) return;
 
   // If we're preprocessing a module map, start by dumping the contents of the
@@ -837,8 +837,6 @@ void PrintPreprocessedAction::ExecuteAction() {
       OS->write_escaped(Input.getFile());
       (*OS) << "\"\n";
     }
-    // FIXME: Include additional information here so that we don't need the
-    // original source files to exist on disk.
     getCurrentModule()->print(*OS);
     (*OS) << "#pragma clang module contents\n";
   }
index fa17b3e7cb3f59c8dbb9f2f11a844dbc10378d50..bcf6d215c998433dc5d285b203c7c0441b765cf6 100644 (file)
@@ -181,7 +181,7 @@ RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
 void RewriteMacrosAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   std::unique_ptr<raw_ostream> OS =
-      CI.createDefaultOutputFile(true, getCurrentFile());
+      CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
   if (!OS) return;
 
   RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@@ -190,7 +190,7 @@ void RewriteMacrosAction::ExecuteAction() {
 void RewriteTestAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   std::unique_ptr<raw_ostream> OS =
-      CI.createDefaultOutputFile(false, getCurrentFile());
+      CI.createDefaultOutputFile(false, getCurrentFileOrBufferName());
   if (!OS) return;
 
   DoRewriteTest(CI.getPreprocessor(), OS.get());
@@ -265,7 +265,8 @@ public:
 
 bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
   if (!OutputStream) {
-    OutputStream = CI.createDefaultOutputFile(true, getCurrentFile());
+    OutputStream =
+        CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
     if (!OutputStream)
       return false;
   }
index 08a864bc84b026173a8a9293ae8ef3155bf5203a..46ca38af7eed37249da5216708ecc33ae61dc8ab 100644 (file)
@@ -4,6 +4,11 @@
 // RUN: %clang_cc1 -fmodules-ts -fmodule-file=%t.pcm %s -I%S/Inputs/no-module-map -verify -DB
 // RUN: %clang_cc1 -fmodules-ts -fmodule-file=%t.pcm %s -I%S/Inputs/no-module-map -verify -DA -DB
 
+// RUN: %clang_cc1 -E %t.pcm -o - | FileCheck %s
+// RUN: %clang_cc1 -frewrite-imports -E %t.pcm -o - | FileCheck %s
+// CHECK: # {{.*}}a.h
+// CHECK: # {{.*}}b.h
+
 #ifdef B
 // expected-no-diagnostics
 #endif