summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend
diff options
context:
space:
mode:
authorIvan Krasin <krasin@chromium.org>2015-08-13 04:04:37 +0000
committerIvan Krasin <krasin@chromium.org>2015-08-13 04:04:37 +0000
commit1193f2cbc021f040eef6f97ec72dad5fb1efb7b1 (patch)
tree921577b0f91fddfff3a6ab823d8ea049d7898919 /clang/lib/Frontend
parent1142f83ce2c28012e611903635a775a8b8944580 (diff)
downloadbcm5719-llvm-1193f2cbc021f040eef6f97ec72dad5fb1efb7b1.tar.gz
bcm5719-llvm-1193f2cbc021f040eef6f97ec72dad5fb1efb7b1.zip
Add sanitizer blacklists to the rules generated with -M/-MM/-MD/-MMD.
Summary: Clang sanitizers, such as AddressSanitizer, ThreadSanitizer, MemorySanitizer, Control Flow Integrity and others, use blacklists to specify which types / functions should not be instrumented to avoid false positives or suppress known failures. This change adds the blacklist filenames to the list of dependencies of the rules, generated with -M/-MM/-MD/-MMD. This lets CMake/Ninja recognize that certain C/C++/ObjC files need to be recompiled (if a blacklist is updated). Reviewers: pcc Subscribers: rsmith, honggyu.kim, pcc, cfe-commits Differential Revision: http://reviews.llvm.org/D11968 llvm-svn: 244867
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp8
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp4
-rw-r--r--clang/lib/Frontend/DependencyFile.cpp6
-rw-r--r--clang/lib/Frontend/HeaderIncludeGen.cpp63
4 files changed, 54 insertions, 27 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 33a330d3171..a31b33ec379 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -354,17 +354,19 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
// Handle generating header include information, if requested.
if (DepOpts.ShowHeaderIncludes)
- AttachHeaderIncludeGen(*PP);
+ AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps);
if (!DepOpts.HeaderIncludeOutputFile.empty()) {
StringRef OutputPath = DepOpts.HeaderIncludeOutputFile;
if (OutputPath == "-")
OutputPath = "";
- AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath,
+ AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps,
+ /*ShowAllHeaders=*/true, OutputPath,
/*ShowDepth=*/false);
}
if (DepOpts.PrintShowIncludes) {
- AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"",
+ AttachHeaderIncludeGen(*PP, DepOpts.ExtraDeps,
+ /*ShowAllHeaders=*/false, /*OutputPath=*/"",
/*ShowDepth=*/true, /*MSStyle=*/true);
}
}
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 8934c80fd63..ae1ccd75bda 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -705,6 +705,10 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
Args.getLastArgValue(OPT_module_dependency_dir);
if (Args.hasArg(OPT_MV))
Opts.OutputFormat = DependencyOutputFormat::NMake;
+ // Add sanitizer blacklists as extra dependencies.
+ // They won't be discovered by the regular preprocessor, so
+ // we let make / ninja to know about this implicit dependency.
+ Opts.ExtraDeps = Args.getAllArgValues(OPT_fsanitize_blacklist);
}
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp
index 72de73014ad..67a24c42629 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -182,7 +182,11 @@ public:
AddMissingHeaderDeps(Opts.AddMissingHeaderDeps),
SeenMissingHeader(false),
IncludeModuleFiles(Opts.IncludeModuleFiles),
- OutputFormat(Opts.OutputFormat) {}
+ OutputFormat(Opts.OutputFormat) {
+ for (auto ExtraDep : Opts.ExtraDeps) {
+ AddFilename(ExtraDep);
+ }
+ }
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp
index 5732e5b3fb7..9123d5321fd 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/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();
@@ -69,6 +98,14 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
}
}
+ // 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 +149,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);
}
}
OpenPOWER on IntegriCloud