[PATCH] D34687: [Tooling] CompilationDatabase should be able to strip position arguments when `-fsyntax-only` is used
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 27 07:41:25 PDT 2017
arphaman created this revision.
Right now, Clang fails to create a fixed compilation database when the compilation arguments use `-fsyntax-only` instead of `-c`. The reported error is: "warning: no compile jobs found". This happens because we don't look at the compilation job when stripping the positional arguments.
Repository:
rL LLVM
https://reviews.llvm.org/D34687
Files:
lib/Tooling/CompilationDatabase.cpp
unittests/Tooling/CompilationDatabaseTest.cpp
Index: unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- unittests/Tooling/CompilationDatabaseTest.cpp
+++ unittests/Tooling/CompilationDatabaseTest.cpp
@@ -586,6 +586,27 @@
EXPECT_EQ(2, Argc);
}
+TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) {
+ // Adjust the given command line arguments to ensure that any positional
+ // arguments in them are stripped.
+ const char *Argv[] = {"--", "somefile.cpp", "-fsyntax-only", "-DDEF3"};
+ int Argc = llvm::array_lengthof(Argv);
+ std::string ErrorMessage;
+ std::unique_ptr<CompilationDatabase> Database =
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMessage);
+ ASSERT_TRUE((bool)Database);
+ ASSERT_TRUE(ErrorMessage.empty());
+ std::vector<CompileCommand> Result = Database->getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ ASSERT_EQ(".", Result[0].Directory);
+ std::vector<std::string> Expected;
+ Expected.push_back("clang-tool");
+ Expected.push_back("-fsyntax-only");
+ Expected.push_back("-DDEF3");
+ Expected.push_back("source");
+ ASSERT_EQ(Expected, Result[0].CommandLine);
+}
+
TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"};
int Argc = sizeof(Argv) / sizeof(char*);
Index: lib/Tooling/CompilationDatabase.cpp
===================================================================
--- lib/Tooling/CompilationDatabase.cpp
+++ lib/Tooling/CompilationDatabase.cpp
@@ -255,10 +255,12 @@
CompileJobAnalyzer CompileAnalyzer;
for (const auto &Cmd : Jobs) {
- // Collect only for Assemble jobs. If we do all jobs we get duplicates
- // since Link jobs point to Assemble jobs as inputs.
- if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
+ // Collect only for Assemble and Compile jobs. If we do all jobs we get
+ // duplicates since Link jobs point to Assemble jobs as inputs.
+ if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass ||
+ Cmd.getSource().getKind() == driver::Action::CompileJobClass) {
CompileAnalyzer.run(&Cmd.getSource());
+ }
}
if (CompileAnalyzer.Inputs.empty()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34687.104161.patch
Type: text/x-patch
Size: 2243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170627/1a5c7324/attachment.bin>
More information about the cfe-commits
mailing list