aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Frontend/HeaderIncludeGen.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:49:41 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:49:41 +0000
commit45b533945f0851ec234ca846e1af5ee1e4df0b6e (patch)
tree0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /lib/Frontend/HeaderIncludeGen.cpp
parent7e86edd64bfae4e324224452e4ea879b3371a4bd (diff)
downloadsrc-45b533945f0851ec234ca846e1af5ee1e4df0b6e.tar.gz
src-45b533945f0851ec234ca846e1af5ee1e4df0b6e.zip
Vendor import of clang trunk r256633:vendor/clang/clang-trunk-r256633
Notes
Notes: svn path=/vendor/clang/dist/; revision=292920 svn path=/vendor/clang/clang-trunk-r256633/; revision=292923; tag=vendor/clang/clang-trunk-r256633
Diffstat (limited to 'lib/Frontend/HeaderIncludeGen.cpp')
-rw-r--r--lib/Frontend/HeaderIncludeGen.cpp64
1 files changed, 40 insertions, 24 deletions
diff --git a/lib/Frontend/HeaderIncludeGen.cpp b/lib/Frontend/HeaderIncludeGen.cpp
index 5732e5b3fb73..0bc1169ba0a9 100644
--- a/lib/Frontend/HeaderIncludeGen.cpp
+++ b/lib/Frontend/HeaderIncludeGen.cpp
@@ -46,7 +46,36 @@ public:
};
}
-void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
+static void PrintHeaderInfo(raw_ostream *OutputFile, const char* Filename,
+ bool ShowDepth, unsigned CurrentIncludeDepth,
+ bool MSStyle) {
+ // Write to a temporary string to avoid unnecessary flushing on errs().
+ SmallString<512> Pathname(Filename);
+ if (!MSStyle)
+ Lexer::Stringify(Pathname);
+
+ SmallString<256> Msg;
+ if (MSStyle)
+ Msg += "Note: including file:";
+
+ if (ShowDepth) {
+ // The main source file is at depth 1, so skip one dot.
+ for (unsigned i = 1; i != CurrentIncludeDepth; ++i)
+ Msg += MSStyle ? ' ' : '.';
+
+ if (!MSStyle)
+ Msg += ' ';
+ }
+ Msg += Pathname;
+ Msg += '\n';
+
+ OutputFile->write(Msg.data(), Msg.size());
+ OutputFile->flush();
+}
+
+void clang::AttachHeaderIncludeGen(Preprocessor &PP,
+ const std::vector<std::string> &ExtraHeaders,
+ bool ShowAllHeaders,
StringRef OutputPath, bool ShowDepth,
bool MSStyle) {
raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs();
@@ -63,12 +92,19 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
delete OS;
} else {
OS->SetUnbuffered();
- OS->SetUseAtomicWrites(true);
OutputFile = OS;
OwnsOutputFile = true;
}
}
+ // 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,
@@ -112,27 +148,7 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
// Dump the header include information we are past the predefines buffer or
// are showing all headers.
if (ShowHeader && Reason == PPCallbacks::EnterFile) {
- // Write to a temporary string to avoid unnecessary flushing on errs().
- SmallString<512> Filename(UserLoc.getFilename());
- if (!MSStyle)
- Lexer::Stringify(Filename);
-
- SmallString<256> Msg;
- if (MSStyle)
- Msg += "Note: including file:";
-
- if (ShowDepth) {
- // The main source file is at depth 1, so skip one dot.
- for (unsigned i = 1; i != CurrentIncludeDepth; ++i)
- Msg += MSStyle ? ' ' : '.';
-
- if (!MSStyle)
- Msg += ' ';
- }
- Msg += Filename;
- Msg += '\n';
-
- OutputFile->write(Msg.data(), Msg.size());
- OutputFile->flush();
+ PrintHeaderInfo(OutputFile, UserLoc.getFilename(),
+ ShowDepth, CurrentIncludeDepth, MSStyle);
}
}