Use access(2) instead of stat(2) to check if a file exists.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 2 Jun 2012 16:28:09 +0000 (16:28 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 2 Jun 2012 16:28:09 +0000 (16:28 +0000)
Apart from being slightly cheaper, this fixes a real bug that hits 32 bit
linux systems. When passing a file larger than 2G to be linked (which isn't
that uncommon with large projects such as WebKit), clang's driver checks
if the file exists but the file size doesn't fit in an off_t and stat(2)
fails with EOVERFLOW. Clang then says that the file doesn't exist instead
of passing it to the linker.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157891 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/PathV2.inc

index a7007cd6974be3c8b34440816d6a84fd630b4503..a5630b9ec90ab1eb0dcd2bcac4ac6f88a3732901 100644 (file)
@@ -273,8 +273,7 @@ error_code exists(const Twine &path, bool &result) {
   SmallString<128> path_storage;
   StringRef p = path.toNullTerminatedStringRef(path_storage);
 
-  struct stat status;
-  if (::stat(p.begin(), &status) == -1) {
+  if (::access(p.begin(), F_OK) == -1) {
     if (errno != errc::no_such_file_or_directory)
       return error_code(errno, system_category());
     result = false;