Skip to content

Commit 8c74a9a

Browse files
[ClangModuleManager] Extend the ext4 file system workaround
Extend the ext4 file system workaround so it covers `lookupByFileName`. This doesn't fix all the problems from the workaround, but it allows correct lookup of the previously added module/PCH files. rdar://119269472
1 parent 3945b43 commit 8c74a9a

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

clang/lib/Basic/FileManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
483483

484484
// If we've already bypassed just use the existing one.
485485
auto Insertion = SeenBypassFileEntries->insert(
486-
{VF.getName(), std::errc::no_such_file_or_directory});
486+
{VF.getNameAsRequested(), std::errc::no_such_file_or_directory});
487487
if (!Insertion.second)
488488
return FileEntryRef(*Insertion.first);
489489

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,16 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
19801980

19811981
// Check whether M refers to the file in the prebuilt module path.
19821982
if (M && M->getASTFile())
1983-
if (auto ModuleFile = FileMgr->getFile(ModuleFilename))
1983+
if (auto ModuleFile = FileMgr->getOptionalFileRef(ModuleFilename)) {
19841984
if (*ModuleFile == M->getASTFile())
19851985
return M;
1986+
#if !defined(__APPLE__)
1987+
// Workaround for ext4 file system. Also check bypass file if exists.
1988+
if (auto Bypass = FileMgr->getBypassFile(*ModuleFile))
1989+
if (*Bypass == M->getASTFile())
1990+
return M;
1991+
#endif
1992+
}
19861993

19871994
getDiagnostics().Report(ModuleNameLoc, diag::err_module_prebuilt)
19881995
<< ModuleName;

clang/lib/Frontend/Rewrite/FrontendActions.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,15 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener {
213213

214214
void visitModuleFile(StringRef Filename,
215215
serialization::ModuleKind Kind) override {
216-
auto File = CI.getFileManager().getFile(Filename);
216+
auto File = CI.getFileManager().getOptionalFileRef(Filename);
217217
assert(File && "missing file for loaded module?");
218218

219+
#if !defined(__APPLE__)
220+
// Workaround for ext4 file system.
221+
if (auto Bypass = CI.getFileManager().getBypassFile(*File))
222+
File = *Bypass;
223+
#endif
224+
219225
// Only rewrite each module file once.
220226
if (!Rewritten.insert(*File).second)
221227
return;

clang/lib/Serialization/ModuleManager.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ using namespace clang;
4242
using namespace serialization;
4343

4444
ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const {
45-
auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
46-
/*CacheFailure=*/false);
45+
auto Entry = FileMgr.getOptionalFileRef(Name, /*OpenFile=*/false,
46+
/*CacheFailure=*/false);
47+
#if !defined(__APPLE__)
48+
if (Entry) {
49+
// On Linux ext4 FileManager's inode caching system does not
50+
// provide us correct behaviour for ModuleCache directories.
51+
// inode can be reused after PCM delete resulting in cache misleading.
52+
if (auto BypassFile = FileMgr.getBypassFile(*Entry))
53+
Entry = *BypassFile;
54+
}
55+
#endif
56+
4757
if (Entry)
4858
return lookup(*Entry);
4959

@@ -449,7 +459,10 @@ bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
449459
// On Linux ext4 FileManager's inode caching system does not
450460
// provide us correct behaviour for ModuleCache directories.
451461
// inode can be reused after PCM delete resulting in cache misleading.
452-
File = FileMgr.getBypassFile(*File);
462+
// Only use the bypass file if bypass succeed in case the underlying file
463+
// system doesn't support bypass (thus there is no need for the workaround).
464+
if (auto Bypass = FileMgr.getBypassFile(*File))
465+
File = *Bypass;
453466
}
454467
#endif
455468

clang/test/Modules/explicit-build-relpath.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Due to module bypass workaround in https://reviews.llvm.org/D97850 for ext4 FS, relative and absolute path do not match after bypass.
2+
// REQUIRES: system-darwin
3+
14
// RUN: rm -rf %t
25
// RUN: mkdir %t
36
// RUN: cd %t

0 commit comments

Comments
 (0)