aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2018-08-22 17:13:40 +0000
committerChih-Hung Hsieh <chh@google.com>2018-08-22 17:13:40 +0000
commit83494d2f8cc6bb743d408031188c20d6e64c2eff (patch)
tree71ce2a542f68313f9d72083a7aa04de38c491014
parentebc27c487378385058440d3eae9d1bf9ee7b40d6 (diff)
downloadllvm-83494d2f8cc6bb743d408031188c20d6e64c2eff.zip
llvm-83494d2f8cc6bb743d408031188c20d6e64c2eff.tar.gz
llvm-83494d2f8cc6bb743d408031188c20d6e64c2eff.tar.bz2
[Tooling] Allow -flto flags and filter out -Wa, flags
This change fixes the problem in https://bugs.llvm.org/show_bug.cgi?id=38332 by allowing driver::Action::BackendJobClass to run with the analyzer. Otherwise, such jobs will look up the non-existing compilation database and then run without flags. Also filter out the -Wa,* flags that could be passed to and ignored by the clang compiler. Clang-tidy gives warnings about unused -Wa,* flags. Differential Revision: http://reviews.llvm.org/D51002 llvm-svn: 340421
-rw-r--r--clang/lib/Tooling/CompilationDatabase.cpp20
-rw-r--r--clang/test/Tooling/clang-check-analyzer.cpp3
2 files changed, 17 insertions, 6 deletions
diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp
index 31a769f..246d3c0 100644
--- a/clang/lib/Tooling/CompilationDatabase.cpp
+++ b/clang/lib/Tooling/CompilationDatabase.cpp
@@ -218,6 +218,15 @@ private:
ArrayRef<std::string> Arr;
};
+// Filter of tools unused flags such as -no-integrated-as and -Wa,*.
+// They are not used for syntax checking, and could confuse targets
+// which don't support these options.
+struct FilterUnusedFlags {
+ bool operator() (StringRef S) {
+ return (S == "-no-integrated-as") || S.startswith("-Wa,");
+ }
+};
+
} // namespace
/// Strips any positional args and possible argv[0] from a command-line
@@ -275,10 +284,7 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
// up with no jobs but then this is the user's fault.
Args.push_back("placeholder.cpp");
- // Remove -no-integrated-as; it's not used for syntax checking,
- // and it confuses targets which don't support this option.
- Args.erase(std::remove_if(Args.begin(), Args.end(),
- MatchesAny(std::string("-no-integrated-as"))),
+ Args.erase(std::remove_if(Args.begin(), Args.end(), FilterUnusedFlags()),
Args.end());
const std::unique_ptr<driver::Compilation> Compilation(
@@ -291,9 +297,11 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
CompileJobAnalyzer CompileAnalyzer;
for (const auto &Cmd : Jobs) {
- // Collect only for Assemble and Compile jobs. If we do all jobs we get
- // duplicates since Link jobs point to Assemble jobs as inputs.
+ // Collect only for Assemble, Backend, and Compile jobs. If we do all jobs
+ // we get duplicates since Link jobs point to Assemble jobs as inputs.
+ // -flto* flags make the BackendJobClass, which still needs analyzer.
if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass ||
+ Cmd.getSource().getKind() == driver::Action::BackendJobClass ||
Cmd.getSource().getKind() == driver::Action::CompileJobClass) {
CompileAnalyzer.run(&Cmd.getSource());
}
diff --git a/clang/test/Tooling/clang-check-analyzer.cpp b/clang/test/Tooling/clang-check-analyzer.cpp
index ee0a6dc..72e1a20 100644
--- a/clang/test/Tooling/clang-check-analyzer.cpp
+++ b/clang/test/Tooling/clang-check-analyzer.cpp
@@ -1,4 +1,7 @@
// RUN: clang-check -analyze "%s" -- -c 2>&1 | FileCheck %s
+// RUN: clang-check -analyze "%s" -- -c -flto -Wa,--noexecstack 2>&1 | FileCheck %s
+// RUN: clang-check -analyze "%s" -- -c -no-integrated-as -flto=thin 2>&1 | FileCheck %s
+// RUN: clang-check -analyze "%s" -- -c -flto=full 2>&1 | FileCheck %s
// CHECK: Dereference of null pointer
void a(int *x) { if(x){} *x = 47; }