From: Justin Bogner Date: Tue, 15 Jul 2014 01:24:35 +0000 (+0000) Subject: VirtualFileSystem: Correctly generate the mapping for an empty VFS X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e5a027d7977cd38db48462e754f44bebd752970;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213028 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index 1f2a856b5c..a5c83b88af 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -1101,35 +1101,34 @@ void JSONWriter::write(ArrayRef 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/unittests/libclang/LibclangTest.cpp b/unittests/libclang/LibclangTest.cpp index ef162bccc0..ee56e22936 100644 --- a/unittests/libclang/LibclangTest.cpp +++ b/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"