diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Frontend/HeaderIncludeGen.cpp | 53 |
2 files changed, 31 insertions, 30 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 453e6dc394f..a57023ad79a 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -360,18 +360,18 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { // Handle generating header include information, if requested. if (DepOpts.ShowHeaderIncludes) - AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps); + AttachHeaderIncludeGen(*PP, DepOpts); if (!DepOpts.HeaderIncludeOutputFile.empty()) { StringRef OutputPath = DepOpts.HeaderIncludeOutputFile; if (OutputPath == "-") OutputPath = ""; - AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps, + AttachHeaderIncludeGen(*PP, DepOpts, /*ShowAllHeaders=*/true, OutputPath, /*ShowDepth=*/false); } if (DepOpts.PrintShowIncludes) { - AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps, + AttachHeaderIncludeGen(*PP, DepOpts, /*ShowAllHeaders=*/true, /*OutputPath=*/"", /*ShowDepth=*/true, /*MSStyle=*/true); } @@ -765,7 +765,7 @@ bool CompilerInstance::InitializeSourceManager( /*SuggestedModule=*/nullptr, /*SkipCache=*/true); // Also add the header to /showIncludes output. if (File) - DepOpts.ExtraDeps.push_back(File->getName()); + DepOpts.ShowIncludesPretendHeader = 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 25b0c4e96b7..818365c4783 100644 --- a/clang/lib/Frontend/HeaderIncludeGen.cpp +++ b/clang/lib/Frontend/HeaderIncludeGen.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/Utils.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -19,25 +20,23 @@ namespace { class HeaderIncludesCallback : public PPCallbacks { SourceManager &SM; raw_ostream *OutputFile; - const std::vector<std::string> &ExtraHeaders; + const DependencyOutputOptions &DepOpts; unsigned CurrentIncludeDepth; bool HasProcessedPredefines; bool OwnsOutputFile; bool ShowAllHeaders; bool ShowDepth; bool MSStyle; - bool PrintedExtraHeaders; public: HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_, raw_ostream *OutputFile_, - const std::vector<std::string> &ExtraHeaders, + const DependencyOutputOptions &DepOpts, 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) {} + : SM(PP->getSourceManager()), OutputFile(OutputFile_), DepOpts(DepOpts), + CurrentIncludeDepth(0), HasProcessedPredefines(false), + OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_), + ShowDepth(ShowDepth_), MSStyle(MSStyle_) {} ~HeaderIncludesCallback() override { if (OwnsOutputFile) @@ -78,10 +77,9 @@ static void PrintHeaderInfo(raw_ostream *OutputFile, const char* Filename, } void clang::AttachHeaderIncludeGen(Preprocessor &PP, - const std::vector<std::string> &ExtraHeaders, - bool ShowAllHeaders, - StringRef OutputPath, bool ShowDepth, - bool MSStyle) { + const DependencyOutputOptions &DepOpts, + bool ShowAllHeaders, StringRef OutputPath, + bool ShowDepth, bool MSStyle) { raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs(); bool OwnsOutputFile = false; @@ -101,8 +99,15 @@ 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 : DepOpts.ExtraDeps) + PrintHeaderInfo(OutputFile, Header.c_str(), ShowDepth, 2, MSStyle); PP.addPPCallbacks(llvm::make_unique<HeaderIncludesCallback>( - &PP, ShowAllHeaders, OutputFile, ExtraHeaders, OwnsOutputFile, ShowDepth, + &PP, ShowAllHeaders, OutputFile, DepOpts, OwnsOutputFile, ShowDepth, MSStyle)); } @@ -110,17 +115,6 @@ 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); @@ -136,8 +130,13 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc, // We track when we are done with the predefines by watching for the first // place where we drop back to a nesting depth of 1. - if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) + if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) { + if (!DepOpts.ShowIncludesPretendHeader.empty()) { + PrintHeaderInfo(OutputFile, DepOpts.ShowIncludesPretendHeader.c_str(), + ShowDepth, 2, MSStyle); + } HasProcessedPredefines = true; + } return; } else @@ -150,7 +149,9 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc, (ShowAllHeaders && CurrentIncludeDepth > 2)); unsigned IncludeDepth = CurrentIncludeDepth; if (!HasProcessedPredefines) - --IncludeDepth; // Ignore indent from <built-in>. + --IncludeDepth; // Ignore indent from <built-in>. + else if (!DepOpts.ShowIncludesPretendHeader.empty()) + ++IncludeDepth; // Pretend inclusion by ShowIncludesPretendHeader. // Dump the header include information we are past the predefines buffer or // are showing all headers and this isn't the magic implicit <command line> |