]> granicus.if.org Git - clang/commitdiff
Add fall-back mode for clang tools.
authorManuel Klimek <klimek@google.com>
Thu, 3 Dec 2015 10:38:53 +0000 (10:38 +0000)
committerManuel Klimek <klimek@google.com>
Thu, 3 Dec 2015 10:38:53 +0000 (10:38 +0000)
Run without flags if we cannot load a compilation database. This matches
the behavior of clang itself when simply called with a source file.

Based on a patch by Russell Wallace.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254599 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/CommonOptionsParser.cpp

index e6b986709a6e380e27b96f1ba877f0a4e1f6eeec..82f5601400856af4fd09b46bbf2b8796dc526aaf 100644 (file)
@@ -116,8 +116,7 @@ CommonOptionsParser::CommonOptionsParser(
 
   cl::HideUnrelatedOptions(Category);
 
-  Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc,
-                                                                   argv));
+  Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv));
   cl::ParseCommandLineOptions(argc, argv, Overview);
   SourcePathList = SourcePaths;
   if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) &&
@@ -132,8 +131,12 @@ CommonOptionsParser::CommonOptionsParser(
       Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0],
                                                                ErrorMessage);
     }
-    if (!Compilations)
-      llvm::report_fatal_error(ErrorMessage);
+    if (!Compilations) {
+      llvm::errs() << "Error while trying to load a compilation database:\n"
+                   << ErrorMessage << "Running without flags.\n";
+      Compilations.reset(
+          new FixedCompilationDatabase(".", std::vector<std::string>()));
+    }
   }
   auto AdjustingCompilations =
       llvm::make_unique<ArgumentsAdjustingCompilations>(