File->ModTime = ModificationTime;
}
-/// Remove '.' path components from the given absolute path.
+/// Remove '.' and '..' path components from the given absolute path.
/// \return \c true if any changes were made.
// FIXME: Move this to llvm::sys::path.
bool FileManager::removeDotPaths(SmallVectorImpl<char> &Path) {
// Skip the root path, then look for traversal in the components.
StringRef Rel = path::relative_path(P);
- bool AnyDots = false;
for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
- if (C == ".") {
- AnyDots = true;
+ if (C == ".")
+ continue;
+ if (C == "..") {
+ if (!ComponentStack.empty())
+ ComponentStack.pop_back();
continue;
}
ComponentStack.push_back(C);
}
- if (!AnyDots)
- return false;
-
SmallString<256> Buffer = path::root_path(P);
for (StringRef C : ComponentStack)
path::append(Buffer, C);
+ bool Changed = (Path != Buffer);
Path.swap(Buffer);
- return true;
+ return Changed;
}
StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
llvm::sys::fs::make_absolute(CanonicalNameBuf);
llvm::sys::path::native(CanonicalNameBuf);
removeDotPaths(CanonicalNameBuf);
+ char *Mem = CanonicalNameStorage.Allocate<char>(CanonicalNameBuf.size());
+ memcpy(Mem, CanonicalNameBuf.data(), CanonicalNameBuf.size());
+ CanonicalName = StringRef(Mem, CanonicalNameBuf.size());
#endif
CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
--- /dev/null
+// rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -Rmodule-build -I%S/Inputs/module-map-path-hash -fmodules-cache-path=%t -fsyntax-only %s
+// xUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -Rmodule-build -I%S/Inputs//module-map-path-hash -fmodules-cache-path=%t -fsyntax-only %s 2>&1 | FileCheck -allow-empty %s
+// xUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -Rmodule-build -I%S/Inputs/./module-map-path-hash -fmodules-cache-path=%t -fsyntax-only %s 2>&1 | FileCheck -allow-empty %s
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x c++ -Rmodule-build -I%S/Inputs/../Inputs/module-map-path-hash -fmodules-cache-path=%t -fsyntax-only %s 2>&1 | FileCheck -allow-empty %s
+
+#include "a.h"
+
+// CHECK-NOT: remark: building module