summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/TestFS.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-02-13 17:47:16 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-02-13 17:47:16 +0000
commit18c0247852f717b3d72cbf0f8635e3108ff10613 (patch)
tree7b0ea588d3574e158815445e1e51a7fa9e66c96f /clang-tools-extra/unittests/clangd/TestFS.cpp
parent267e0f4d5fe89204534051162fa656597c5f89dd (diff)
downloadbcm5719-llvm-18c0247852f717b3d72cbf0f8635e3108ff10613.tar.gz
bcm5719-llvm-18c0247852f717b3d72cbf0f8635e3108ff10613.zip
[clangd] Fixed findDefinitions to always return absolute paths.
Relative paths could be returned in some cases, e.g. when relative path is used in compilation arguments. This led to crash when trying to convert the path to URI. llvm-svn: 325029
Diffstat (limited to 'clang-tools-extra/unittests/clangd/TestFS.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/TestFS.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang-tools-extra/unittests/clangd/TestFS.cpp b/clang-tools-extra/unittests/clangd/TestFS.cpp
index 55506e6c4e0..38cef894074 100644
--- a/clang-tools-extra/unittests/clangd/TestFS.cpp
+++ b/clang-tools-extra/unittests/clangd/TestFS.cpp
@@ -33,8 +33,10 @@ MockFSProvider::getTaggedFileSystem(PathRef File) {
return make_tagged(FS, Tag);
}
-MockCompilationDatabase::MockCompilationDatabase()
- : ExtraClangFlags({"-ffreestanding"}) {} // Avoid implicit stdc-predef.h.
+MockCompilationDatabase::MockCompilationDatabase(bool UseRelPaths)
+ : ExtraClangFlags({"-ffreestanding"}), UseRelPaths(UseRelPaths) {
+ // -ffreestanding avoids implicit stdc-predef.h.
+}
llvm::Optional<tooling::CompileCommand>
MockCompilationDatabase::getCompileCommand(PathRef File) const {
@@ -42,10 +44,10 @@ MockCompilationDatabase::getCompileCommand(PathRef File) const {
return llvm::None;
auto CommandLine = ExtraClangFlags;
+ auto FileName = llvm::sys::path::filename(File);
CommandLine.insert(CommandLine.begin(), "clang");
- CommandLine.insert(CommandLine.end(), File.str());
- return {tooling::CompileCommand(llvm::sys::path::parent_path(File),
- llvm::sys::path::filename(File),
+ CommandLine.insert(CommandLine.end(), UseRelPaths ? FileName : File);
+ return {tooling::CompileCommand(llvm::sys::path::parent_path(File), FileName,
std::move(CommandLine), "")};
}
OpenPOWER on IntegriCloud