]> granicus.if.org Git - clang/commitdiff
[clang-tidy] Fail gracefully upon empty database fields
authorSerge Guelton <sguelton@redhat.com>
Thu, 20 Jun 2019 20:25:59 +0000 (20:25 +0000)
committerSerge Guelton <sguelton@redhat.com>
Thu, 20 Jun 2019 20:25:59 +0000 (20:25 +0000)
Fix bz#42281

Differential Revision: https://reviews.llvm.org/D63613

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

lib/Tooling/InterpolatingCompilationDatabase.cpp
lib/Tooling/Tooling.cpp

index 8b1030f360786b0c300a1a56d6dae5cf23e6df36..a467d1318e2038424b2a0420d1554e9847f4259d 100644 (file)
@@ -150,7 +150,8 @@ struct TransferableCommand {
     // spelling of each argument; re-rendering is lossy for aliased flags.
     // E.g. in CL mode, /W4 maps to -Wall.
     auto OptTable = clang::driver::createDriverOptTable();
-    Cmd.CommandLine.emplace_back(OldArgs.front());
+    if (!OldArgs.empty())
+      Cmd.CommandLine.emplace_back(OldArgs.front());
     for (unsigned Pos = 1; Pos < OldArgs.size();) {
       using namespace driver::options;
 
@@ -243,7 +244,8 @@ private:
     }
 
     // Otherwise just check the clang executable file name.
-    return llvm::sys::path::stem(CmdLine.front()).endswith_lower("cl");
+    return !CmdLine.empty() &&
+           llvm::sys::path::stem(CmdLine.front()).endswith_lower("cl");
   }
 
   // Map the language from the --std flag to that of the -x flag.
index 68760ef756947209af9d847deb17b862d6e559e5..a7c64866a48fd5f801b9490ae595598b75aa70ff 100644 (file)
@@ -481,7 +481,7 @@ int ClangTool::run(ToolAction *Action) {
       if (OverlayFileSystem->setCurrentWorkingDirectory(
               CompileCommand.Directory))
         llvm::report_fatal_error("Cannot chdir into \"" +
-                                 Twine(CompileCommand.Directory) + "\n!");
+                                 Twine(CompileCommand.Directory) + "\"!");
 
       // Now fill the in-memory VFS with the relative file mappings so it will
       // have the correct relative paths. We never remove mappings but that