Description
When using -index-store-path
, we occasionally see compiler crashes on Windows like:
<unknown>:0: error: failed writing record 'Windows.Media.AppRecording.h-178ZCD4YPC99X': could not access record 'C:\<snip>\build\debug\index\store\v5\records\9X\Windows.Media.AppRecording.h-178ZCD4YPC99X': permission denied
Some investigation has led me to the llvm::sys::fs::access
function, which can sometimes erroneously fail when called with AccessMode::Exist
. Despite the path existing, the call to GetFileAttributesW
fails with ERROR_ACCESS_DENIED
. This seems to be some kind of race, but I've been unable to reproduce the problem in isolation.
I've had some success in fixing the issue with something like:
if (Mode == AccessMode::Exist) {
if (::PathFileExistsW(PathUtf16.begin())) {
return std::error_code();
} else {
return errc::no_such_file_or_directory;
}
}
which I believe matches the expected semantics of the function. With this patch, I've been unable to reproduce the index writing failure, but I'm still not sure what the root cause of the access denied failure is, which I feel should be well understood before submitting a patch.
I'm aware this particular function is not specific to the Apple's LLVM fork, but as the compiler crash is surfaced in Apple specific code (the diagnostic is reported here), I figured I'd check here first. If it's agreed that the issue is in fact in llvm::sys::fs::access
as I suspect, I will file upstream.