/// AttachDependencyGraphGen - Create a dependency graph generator, and attach
/// it to the given preprocessor.
- void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile,
- StringRef SysRoot);
+void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile,
+ StringRef SysRoot);
/// AttachHeaderIncludeGen - Create a header include list generator, and attach
/// it to the given preprocessor.
///
-/// \param ExtraHeaders - If not empty, will write the header filenames, just
-/// like they were included during a regular preprocessing. Useful for
-/// implicit include dependencies, like sanitizer blacklists.
+/// \param DepOpts - Options controlling the output.
/// \param ShowAllHeaders - If true, show all header information instead of just
/// headers following the predefines buffer. This is useful for making sure
/// includes mentioned on the command line are also reported, but differs from
/// \param ShowDepth - Whether to indent to show the nesting of the includes.
/// \param MSStyle - Whether to print in cl.exe /showIncludes style.
void AttachHeaderIncludeGen(Preprocessor &PP,
- const std::vector<std::string> &ExtraHeaders,
+ const DependencyOutputOptions &DepOpts,
bool ShowAllHeaders = false,
StringRef OutputPath = "",
bool ShowDepth = true, bool MSStyle = false);
// 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);
}
/*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;
//
//===----------------------------------------------------------------------===//
+#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/Utils.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/FrontendDiagnostic.h"
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)
}
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;
}
}
+ // 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));
}
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);
// 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
(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>
// RUN: %clang_cl -Werror /showIncludes /I%S/Inputs /Ycheader2.h /FIheader2.h /Fp%t.pch /c /Fo%t -- %s \
// RUN: | FileCheck --strict-whitespace -check-prefix=CHECK-YC %s
// CHECK-YC: Note: including file: {{[^ ]*header2.h}}
-// FIXME: header1.h should be indented one more:
-// CHECK-YC: Note: including file: {{[^ ]*header1.h}}
+// CHECK-YC: Note: including file: {{[^ ]*header1.h}}
// CHECK-YC: Note: including file: {{[^ ]*header3.h}}
// When using the pch, only the direct include is printed.
// /FI flags before the /Yc arg should be printed, /FI flags after it shouldn't.
// RUN: %clang_cl -Werror /showIncludes /I%S/Inputs /Ycheader2.h /FIheader0.h /FIheader2.h /FIheader4.h /Fp%t.pch /c /Fo%t -- %s \
// RUN: | FileCheck --strict-whitespace -check-prefix=CHECK-YCFI %s
-// FIXME: The order of the first two lines here must be reversed:
-// CHECK-YCFI: Note: including file: {{[^ ]*header2.h}}
// CHECK-YCFI: Note: including file: {{[^ ]*header0.h}}
-// FIXME: header1.h should be indented one more:
-// CHECK-YCFI: Note: including file: {{[^ ]*header1.h}}
+// CHECK-YCFI: Note: including file: {{[^ ]*header2.h}}
+// CHECK-YCFI: Note: including file: {{[^ ]*header1.h}}
// CHECK-YCFI: Note: including file: {{[^ ]*header4.h}}
// CHECK-YCFI: Note: including file: {{[^ ]*header3.h}}