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

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 17:26:59 PST 2024


================
@@ -620,6 +621,14 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
   if (std::error_code EC = widenPath(Path, PathUtf16))
     return EC;
 
+  if (Mode == AccessMode::Exist) {
+    if (::PathFileExistsW(PathUtf16.begin())) {
+      return std::error_code();
+    } else {
+      return errc::no_such_file_or_directory;
+    }
+  }
----------------
compnerd wrote:

```suggestion
  if (Mode == AccessMode::Exist)
    return ::PathFileExistsW(PathUtf16.begin()) ? std::error_code() : errc::no_such_file_or_directory;
```

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


More information about the llvm-commits mailing list