8000 [clang][DependencyFile] Use atomic write for dependency file (#10902) · swiftlang/llvm-project@bfedc53 · GitHub
[go: up one dir, main page]

Skip to content

Commit bfedc53

Browse files
[clang][DependencyFile] Use atomic write for dependency file (#10902)
Previously when switch to output backend, dependency file was relying on non-atomic write + discard to remove the out of date dependency file when there are missing headers. The reliance on non-atomic write can cause race conditions that build system is trying to read the file while the file is being updated by a different compiler instance. rdar://154128578
1 parent 15629cf commit bfedc53

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

clang/lib/Frontend/DependencyFile.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,28 +383,20 @@ static void PrintFilename(raw_ostream &OS, StringRef Filename,
383383
}
384384

385385
void DependencyFileGenerator::outputDependencyFile(DiagnosticsEngine &Diags) {
386-
// The use of NoAtomicWrite and calling discard on SeenMissingHeader
387-
// preserves the previous behaviour: no temporary files are used, and when
388-
// SeenMissingHeader is true it deletes a previously-existing file.
389-
// FIXME: switch to atomic-write based on FrontendOptions::UseTemporary and
390-
// and not deleting the previous file, if possible.
391-
Expected<llvm::vfs::OutputFile> O =
392-
OutputBackend->createFile(OutputFile, llvm::vfs::OutputConfig()
393-
.setTextWithCRLF()
394-
.setNoAtomicWrite()
395-
.setNoDiscardOnSignal());
386+
if (SeenMissingHeader) {
387+
llvm::sys::fs::remove(OutputFile);
388+
return;
389+
}
390+
391+
Expected<llvm::vfs::OutputFile> O = OutputBackend->createFile(
392+
OutputFile, llvm::vfs::OutputConfig().setTextWithCRLF());
396393

397394
if (!O) {
398395
Diags.Report(diag::err_fe_error_opening)
399396
<< OutputFile << toString(O.takeError());
400397
return;
401398
}
402399

403-
if (SeenMissingHeader) {
404-
consumeError(O->discard());
405-
return;
406-
}
407-
408400
outputDependencyFile(O->getOS());
409401

410402
if (auto Err = O->keep())

0 commit comments

Comments
 (0)
0