r209250 - VirtualFileSystem: Fix false positives in YAMLVFSWriter::containedIn
Justin Bogner
mail at justinbogner.com
Tue May 20 15:12:58 PDT 2014
Author: bogner
Date: Tue May 20 17:12:58 2014
New Revision: 209250
URL: http://llvm.org/viewvc/llvm-project?rev=209250&view=rev
Log:
VirtualFileSystem: Fix false positives in YAMLVFSWriter::containedIn
Checking if a path starts with another path isn't sufficient for
determining if one is contained within the heirarchy of the other.
We need to ensure that the substring ends at a directory boundary.
Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp
Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=209250&r1=209249&r2=209250&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue May 20 17:12:58 2014
@@ -928,7 +928,16 @@ YAMLVFSWriter::printContents(llvm::raw_o
}
bool YAMLVFSWriter::containedIn(StringRef Parent, StringRef Path) {
- return Path.startswith(Parent);
+ using namespace llvm::sys;
+ // Compare each path component.
+ auto IParent = path::begin(Parent), EParent = path::end(Parent);
+ for (auto IChild = path::begin(Path), EChild = path::end(Path);
+ IParent != EParent && IChild != EChild; ++IParent, ++IChild) {
+ if (*IParent != *IChild)
+ return false;
+ }
+ // Have we exhausted the parent path?
+ return IParent == EParent;
}
StringRef YAMLVFSWriter::containedPart(StringRef Parent, StringRef Path) {
Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=209250&r1=209249&r2=209250&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Tue May 20 17:12:58 2014
@@ -184,6 +184,57 @@ TEST(libclang, VirtualFileOverlay) {
T.map("/path/virtual/foo.h", "/real/foo.h");
clang_VirtualFileOverlay_setCaseSensitivity(T.VFO, false);
}
+ {
+ const char *contents =
+ "{\n"
+ " 'version': 0,\n"
+ " 'roots': [\n"
+ " {\n"
+ " 'type': 'directory',\n"
+ " 'name': \"/path/foo\",\n"
+ " 'contents': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': \"bar\",\n"
+ " 'external-contents': \"/real/bar\"\n"
+ " },\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': \"bar.h\",\n"
+ " 'external-contents': \"/real/bar.h\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " 'type': 'directory',\n"
+ " 'name': \"/path/foobar\",\n"
+ " 'contents': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': \"baz.h\",\n"
+ " 'external-contents': \"/real/baz.h\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " 'type': 'directory',\n"
+ " 'name': \"/path\",\n"
+ " 'contents': [\n"
+ " {\n"
+ " 'type': 'file',\n"
+ " 'name': \"foobarbaz.h\",\n"
+ " 'external-contents': \"/real/foobarbaz.h\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+ TestVFO T(contents);
+ T.map("/path/foo/bar.h", "/real/bar.h");
+ T.map("/path/foo/bar", "/real/bar");
+ T.map("/path/foobar/baz.h", "/real/baz.h");
+ T.map("/path/foobarbaz.h", "/real/foobarbaz.h");
+ }
}
TEST(libclang, ModuleMapDescriptor) {
More information about the cfe-commits
mailing list