serge-sans-paille created this revision. serge-sans-paille added a reviewer: alexfh. Herald added subscribers: cfe-commits, xazax.hun. Herald added a project: clang.
fix https://bugs.llvm.org/show_bug.cgi?id=42281 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D63613 Files: clang-tools-extra/test/clang-tidy/empty-database.cpp clang-tools-extra/test/clang-tidy/empty-database/compile_commands.json clang/lib/Tooling/InterpolatingCompilationDatabase.cpp clang/lib/Tooling/Tooling.cpp Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ clang/lib/Tooling/Tooling.cpp @@ -481,7 +481,7 @@ 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 Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp =================================================================== --- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp +++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp @@ -150,7 +150,8 @@ // 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,7 @@ } // 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: clang-tools-extra/test/clang-tidy/empty-database/compile_commands.json =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/empty-database/compile_commands.json @@ -0,0 +1,4 @@ +[{ + "directory":"", + "file":"/tmp/","arguments":[] +}] Index: clang-tools-extra/test/clang-tidy/empty-database.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/empty-database.cpp @@ -0,0 +1,3 @@ +// RUN: not clang-tidy -p %S/empty-database %s 2>&1 | FileCheck %s + +// CHECK: LLVM ERROR: Cannot chdir into ""!
Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ clang/lib/Tooling/Tooling.cpp @@ -481,7 +481,7 @@ 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 Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp =================================================================== --- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp +++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp @@ -150,7 +150,8 @@ // 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,7 @@ } // 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: clang-tools-extra/test/clang-tidy/empty-database/compile_commands.json =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/empty-database/compile_commands.json @@ -0,0 +1,4 @@ +[{ + "directory":"", + "file":"/tmp/","arguments":[] +}] Index: clang-tools-extra/test/clang-tidy/empty-database.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/empty-database.cpp @@ -0,0 +1,3 @@ +// RUN: not clang-tidy -p %S/empty-database %s 2>&1 | FileCheck %s + +// CHECK: LLVM ERROR: Cannot chdir into ""!
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits