[flang-commits] [flang] 770685e - [flang] [runtime] Fix build warnings if built with mingw

Martin Storsjö via flang-commits flang-commits at lists.llvm.org
Thu Aug 25 01:58:13 PDT 2022


Author: Martin Storsjö
Date: 2022-08-25T11:56:10+03:00
New Revision: 770685e24d3176a10093feac128fd75fac2e3f2c

URL: https://github.com/llvm/llvm-project/commit/770685e24d3176a10093feac128fd75fac2e3f2c
DIFF: https://github.com/llvm/llvm-project/commit/770685e24d3176a10093feac128fd75fac2e3f2c.diff

LOG: [flang] [runtime] Fix build warnings if built with mingw

Check whether `F_OK` et al are defined before redefining them; mingw
headers do define them, so check before providing the windows fallback
defines.

Also check `_WIN32` instead of `WIN32`; this is how it's consistently
done in the rest of llvm. (The former is a compiler builtin define,
while the latter isn't, but it's commonly set by e.g. build systems.)

Differential Revision: https://reviews.llvm.org/D132481

Added: 
    

Modified: 
    flang/runtime/file.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index b2af0fd7aac3c..5cf91b8d64c86 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -426,10 +426,12 @@ void OpenFile::CloseFd(IoErrorHandler &handler) {
 
 bool IsATerminal(int fd) { return ::isatty(fd); }
 
-#ifdef WIN32
+#if defined(_WIN32) && !defined(F_OK)
 // Access flags are normally defined in unistd.h, which unavailable under
 // Windows. Instead, define the flags as documented at
 // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess
+// On Mingw, io.h does define these same constants - so check whether they
+// already are defined before defining these.
 #define F_OK 00
 #define W_OK 02
 #define R_OK 04


        


More information about the flang-commits mailing list