aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-07-15 01:24:35 +0000
committerJustin Bogner <mail@justinbogner.com>2014-07-15 01:24:35 +0000
commit73466400b2dcba1d67a2538684c55907221ade7a (patch)
treec444e8a873985b04a73dee0971a6c328548415bf
parent15fe7a530d352aecea65f952e6b321635b4fe2a8 (diff)
downloadllvm-73466400b2dcba1d67a2538684c55907221ade7a.zip
llvm-73466400b2dcba1d67a2538684c55907221ade7a.tar.gz
llvm-73466400b2dcba1d67a2538684c55907221ade7a.tar.bz2
VirtualFileSystem: Correctly generate the mapping for an empty VFS
In r209332 I accidentally broke generation of empty VFS maps. This fixes the issue and adds a test. llvm-svn: 213028
-rw-r--r--clang/lib/Basic/VirtualFileSystem.cpp45
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp10
2 files changed, 32 insertions, 23 deletions
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp
index 1f2a856..a5c83b8 100644
--- a/clang/lib/Basic/VirtualFileSystem.cpp
+++ b/clang/lib/Basic/VirtualFileSystem.cpp
@@ -1101,35 +1101,34 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
<< (IsCaseSensitive.getValue() ? "true" : "false") << "',\n";
OS << " 'roots': [\n";
- if (Entries.empty())
- return;
-
- const YAMLVFSEntry &Entry = Entries.front();
- startDirectory(path::parent_path(Entry.VPath));
- writeEntry(path::filename(Entry.VPath), Entry.RPath);
-
- for (const auto &Entry : Entries.slice(1)) {
- StringRef Dir = path::parent_path(Entry.VPath);
- if (Dir == DirStack.back())
- OS << ",\n";
- else {
- while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
- OS << "\n";
- endDirectory();
+ if (!Entries.empty()) {
+ const YAMLVFSEntry &Entry = Entries.front();
+ startDirectory(path::parent_path(Entry.VPath));
+ writeEntry(path::filename(Entry.VPath), Entry.RPath);
+
+ for (const auto &Entry : Entries.slice(1)) {
+ StringRef Dir = path::parent_path(Entry.VPath);
+ if (Dir == DirStack.back())
+ OS << ",\n";
+ else {
+ while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
+ OS << "\n";
+ endDirectory();
+ }
+ OS << ",\n";
+ startDirectory(Dir);
}
- OS << ",\n";
- startDirectory(Dir);
+ writeEntry(path::filename(Entry.VPath), Entry.RPath);
}
- writeEntry(path::filename(Entry.VPath), Entry.RPath);
- }
- while (!DirStack.empty()) {
+ while (!DirStack.empty()) {
+ OS << "\n";
+ endDirectory();
+ }
OS << "\n";
- endDirectory();
}
- OS << "\n"
- << " ]\n"
+ OS << " ]\n"
<< "}\n";
}
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index ef162bc..ee56e22 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -316,6 +316,16 @@ TEST(libclang, VirtualFileOverlay_TopLevel) {
T.map("/foo.h", "/real/foo.h");
}
+TEST(libclang, VirtualFileOverlay_Empty) {
+ const char *contents =
+ "{\n"
+ " 'version': 0,\n"
+ " 'roots': [\n"
+ " ]\n"
+ "}\n";
+ TestVFO T(contents);
+}
+
TEST(libclang, ModuleMapDescriptor) {
const char *Contents =
"framework module TestFrame {\n"