diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-03-13 02:44:13 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-03-13 02:44:13 +0000 |
commit | 4b5aedef16fc5faa78a2683d6a8fccfe9cefd84c (patch) | |
tree | 43691e2903e02e003449bd085676e08b85b175f6 /clang | |
parent | 28286cdfc7818a97304349d7f491322bfc2dc8da (diff) | |
download | bcm5719-llvm-4b5aedef16fc5faa78a2683d6a8fccfe9cefd84c.tar.gz bcm5719-llvm-4b5aedef16fc5faa78a2683d6a8fccfe9cefd84c.zip |
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.
llvm-svn: 263352
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Frontend/CompilerInstance.h | 1 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Frontend/HeaderIncludeGen.cpp | 44 | ||||
-rw-r--r-- | clang/test/Driver/cl-pch-showincludes.cpp | 3 |
4 files changed, 34 insertions, 29 deletions
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index fe36eeee2e6..99c43aa40d0 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -752,6 +752,7 @@ public: FileManager &FileMgr, SourceManager &SourceMgr, HeaderSearch *HS, + DependencyOutputOptions &DepOpts, const FrontendOptions &Opts); /// } diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index c02eb761041..7e7588af58a 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -715,16 +715,14 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){ 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::InitializeSourceManager(const FrontendInputFile &Input, /*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; diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp index 0bc1169ba0a..bb053c6e806 100644 --- a/clang/lib/Frontend/HeaderIncludeGen.cpp +++ b/clang/lib/Frontend/HeaderIncludeGen.cpp @@ -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(Preprocessor &PP, } } - // 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); diff --git a/clang/test/Driver/cl-pch-showincludes.cpp b/clang/test/Driver/cl-pch-showincludes.cpp index 1fe25c08ece..db4fb7b7322 100644 --- a/clang/test/Driver/cl-pch-showincludes.cpp +++ b/clang/test/Driver/cl-pch-showincludes.cpp @@ -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}} |