[llvm] Avoid calling `GetFileAttributesW` in Windows' `fs::access` when checking for existence (PR #83495)

Jeremy Day via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 15:38:10 PST 2024


z2oh wrote:

Unfortunately I haven't been able to pin down the _exact_ source of the race here, only that sometimes there is a call to `fs::access(_, AccessMode::Exist)` that unexpectedly fails with `ERROR_ACCESS_DENIED`. We have been able to reproduce this call failing in this way in isolation, where `GetFileAttributesW` fails with `ERROR_ACCESS_DENIED` called on an open handle that has been marked for deletion.

I've evaluated the veracity of this patch experimentally, but after seeing Wine's implementation of `PathFileExistsW` linked above I'm thinking it works by simply treating any failure of `GetFileAttributesW` as the evidence of the path not existing. This actually seems to be the semantics of semantics of the [`fs::exists`](https://github.com/llvm/llvm-project/blob/8f80d466d580d0fb97383eac8a2d7d9a1e3f15f4/llvm/include/llvm/Support/FileSystem.h#L461-L463) function, so I may be able to just use this instead in downstream code. Thanks for the pointers everyone! I'll report back after verifying this.

https://github.com/llvm/llvm-project/pull/83495


More information about the llvm-commits mailing list