summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-12-11 20:50:24 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-12-11 20:50:24 +0000
commit54cc3c2f231846e110dcfbc04ff52f266aa6dfb9 (patch)
tree40917c9ba0ce4b23b2f98595f012d5ab5d50a332 /clang/lib/Lex
parent72b05aa59c0268f3404af9c3e61c706d1661fd03 (diff)
downloadbcm5719-llvm-54cc3c2f231846e110dcfbc04ff52f266aa6dfb9.tar.gz
bcm5719-llvm-54cc3c2f231846e110dcfbc04ff52f266aa6dfb9.zip
[modules] When constructing paths relative to a module, strip out /./ directory
components. These sometimes get synthetically added, and we don't want -Ifoo and -I./foo to be treated fundamentally differently here. llvm-svn: 224055
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 02fd87c8226..d6b255fb014 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -131,16 +131,24 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName,
llvm::sys::path::append(Result, ModuleName + ".pcm");
} else {
// Construct the name <ModuleName>-<hash of ModuleMapPath>.pcm which should
- // be globally unique to this particular module. To avoid false-negatives
- // on case-insensitive filesystems, we use lower-case, which is safe because
- // to cause a collision the modules must have the same name, which is an
- // error if they are imported in the same translation.
- SmallString<256> AbsModuleMapPath(ModuleMapPath);
- llvm::sys::fs::make_absolute(AbsModuleMapPath);
- llvm::sys::path::native(AbsModuleMapPath);
- llvm::APInt Code(64, llvm::hash_value(AbsModuleMapPath.str().lower()));
+ // ideally be globally unique to this particular module. Name collisions
+ // in the hash are safe (because any translation unit can only import one
+ // module with each name), but result in a loss of caching.
+ //
+ // To avoid false-negatives, we form as canonical a path as we can, and map
+ // to lower-case in case we're on a case-insensitive file system.
+ auto *Dir =
+ FileMgr.getDirectory(llvm::sys::path::parent_path(ModuleMapPath));
+ if (!Dir)
+ return std::string();
+ auto DirName = FileMgr.getCanonicalName(Dir);
+ auto FileName = llvm::sys::path::filename(ModuleMapPath);
+
+ llvm::hash_code Hash =
+ llvm::hash_combine(DirName.lower(), FileName.lower());
+
SmallString<128> HashStr;
- Code.toStringUnsigned(HashStr, /*Radix*/36);
+ llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36);
llvm::sys::path::append(Result, ModuleName + "-" + HashStr.str() + ".pcm");
}
return Result.str().str();
OpenPOWER on IntegriCloud