r263352 - clang-cl: Add /Yc argument to /showIncludes output.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 12 18:44:14 PST 2016


Author: nico
Date: Sat Mar 12 20:44:13 2016
New Revision: 263352

URL: http://llvm.org/viewvc/llvm-project?rev=263352&view=rev
Log:
clang-cl: Add /Yc argument to /showIncludes output.

To make this work, delay printing of ExtraDeps in HeaderIncludesCallback a bit,
so that it happens after CompilerInstance::InitializeSourceManager() has run.

General /FI arguments are still missing from /showIncludes output, this still
needs to be fixed.

Modified:
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp
    cfe/trunk/test/Driver/cl-pch-showincludes.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=263352&r1=263351&r2=263352&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Sat Mar 12 20:44:13 2016
@@ -752,6 +752,7 @@ public:
                                       FileManager &FileMgr,
                                       SourceManager &SourceMgr,
                                       HeaderSearch *HS,
+                                      DependencyOutputOptions &DepOpts,
                                       const FrontendOptions &Opts);
 
   /// }

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=263352&r1=263351&r2=263352&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sat Mar 12 20:44:13 2016
@@ -715,16 +715,14 @@ bool CompilerInstance::InitializeSourceM
   return InitializeSourceManager(
       Input, getDiagnostics(), getFileManager(), getSourceManager(),
       hasPreprocessor() ? &getPreprocessor().getHeaderSearchInfo() : nullptr,
-      getFrontendOpts());
+      getDependencyOutputOpts(), getFrontendOpts());
 }
 
 // static
-bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
-                                               DiagnosticsEngine &Diags,
-                                               FileManager &FileMgr,
-                                               SourceManager &SourceMgr,
-                                               HeaderSearch *HS,
-                                               const FrontendOptions &Opts) {
+bool CompilerInstance::InitializeSourceManager(
+    const FrontendInputFile &Input, DiagnosticsEngine &Diags,
+    FileManager &FileMgr, SourceManager &SourceMgr, HeaderSearch *HS,
+    DependencyOutputOptions &DepOpts, const FrontendOptions &Opts) {
   SrcMgr::CharacteristicKind
     Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
 
@@ -765,6 +763,9 @@ bool CompilerInstance::InitializeSourceM
                             /*RelativePath=*/nullptr,
                             /*RequestingModule=*/nullptr,
                             /*SuggestedModule=*/nullptr, /*SkipCache=*/true);
+      // Also add the header to /showIncludes output.
+      if (File)
+        DepOpts.ExtraDeps.push_back(File->getName());
     }
     if (!File) {
       Diags.Report(diag::err_fe_error_reading) << InputFile;

Modified: cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp?rev=263352&r1=263351&r2=263352&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp (original)
+++ cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp Sat Mar 12 20:44:13 2016
@@ -19,21 +19,25 @@ namespace {
 class HeaderIncludesCallback : public PPCallbacks {
   SourceManager &SM;
   raw_ostream *OutputFile;
+  const std::vector<std::string> &ExtraHeaders;
   unsigned CurrentIncludeDepth;
   bool HasProcessedPredefines;
   bool OwnsOutputFile;
   bool ShowAllHeaders;
   bool ShowDepth;
   bool MSStyle;
+  bool PrintedExtraHeaders;
 
 public:
   HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_,
-                         raw_ostream *OutputFile_, bool OwnsOutputFile_,
-                         bool ShowDepth_, bool MSStyle_)
-    : SM(PP->getSourceManager()), OutputFile(OutputFile_),
-      CurrentIncludeDepth(0), HasProcessedPredefines(false),
-      OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),
-      ShowDepth(ShowDepth_), MSStyle(MSStyle_) {}
+                         raw_ostream *OutputFile_,
+                         const std::vector<std::string> &ExtraHeaders,
+                         bool OwnsOutputFile_, bool ShowDepth_, bool MSStyle_)
+      : SM(PP->getSourceManager()), OutputFile(OutputFile_),
+        ExtraHeaders(ExtraHeaders), CurrentIncludeDepth(0),
+        HasProcessedPredefines(false), OwnsOutputFile(OwnsOutputFile_),
+        ShowAllHeaders(ShowAllHeaders_), ShowDepth(ShowDepth_),
+        MSStyle(MSStyle_), PrintedExtraHeaders(false) {}
 
   ~HeaderIncludesCallback() override {
     if (OwnsOutputFile)
@@ -97,26 +101,26 @@ void clang::AttachHeaderIncludeGen(Prepr
     }
   }
 
-  // Print header info for extra headers, pretending they were discovered
-  // by the regular preprocessor. The primary use case is to support
-  // proper generation of Make / Ninja file dependencies for implicit includes,
-  // such as sanitizer blacklists. It's only important for cl.exe
-  // compatibility, the GNU way to generate rules is -M / -MM / -MD / -MMD.
-  for (auto Header : ExtraHeaders) {
-    PrintHeaderInfo(OutputFile, Header.c_str(), ShowDepth, 2, MSStyle);
-  }
-  PP.addPPCallbacks(llvm::make_unique<HeaderIncludesCallback>(&PP,
-                                                              ShowAllHeaders,
-                                                              OutputFile,
-                                                              OwnsOutputFile,
-                                                              ShowDepth,
-                                                              MSStyle));
+  PP.addPPCallbacks(llvm::make_unique<HeaderIncludesCallback>(
+      &PP, ShowAllHeaders, OutputFile, ExtraHeaders, OwnsOutputFile, ShowDepth,
+      MSStyle));
 }
 
 void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
                                          FileChangeReason Reason,
                                        SrcMgr::CharacteristicKind NewFileType,
                                        FileID PrevFID) {
+  if (!PrintedExtraHeaders) {
+    // Print header info for extra headers, pretending they were discovered by
+    // the regular preprocessor. The primary use case is to support proper
+    // generation of Make / Ninja file dependencies for implicit includes, such
+    // as sanitizer blacklists. It's only important for cl.exe compatibility,
+    // the GNU way to generate rules is -M / -MM / -MD / -MMD.
+    for (auto Header : ExtraHeaders)
+      PrintHeaderInfo(OutputFile, Header.c_str(), ShowDepth, 2, MSStyle);
+    PrintedExtraHeaders = true;
+  }
+
   // Unless we are exiting a #include, make sure to skip ahead to the line the
   // #include directive was at.
   PresumedLoc UserLoc = SM.getPresumedLoc(Loc);

Modified: cfe/trunk/test/Driver/cl-pch-showincludes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-pch-showincludes.cpp?rev=263352&r1=263351&r2=263352&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-pch-showincludes.cpp (original)
+++ cfe/trunk/test/Driver/cl-pch-showincludes.cpp Sat Mar 12 20:44:13 2016
@@ -9,8 +9,7 @@
 // input itself) and header3.h (included directly, above) should be printed.
 // RUN: %clang_cl -Werror /showIncludes /I%S/Inputs /Ycheader2.h /FIheader2.h /Fp%t.pch /c -- %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-YC %s
-// FIXME: clang-cl doesn't print "header2.h" yet, next line shouldn't say -NOT
-// CHECK-YC-NOT: Note: including file: {{.*header2.h}}
+// CHECK-YC: Note: including file: {{.*header2.h}}
 // CHECK-YC: Note: including file: {{.*header1.h}}
 // CHECK-YC: Note: including file: {{.*header3.h}}
 




More information about the cfe-commits mailing list