[flang-commits] [PATCH] D132481: [flang] [runtime] Fix build warnings if built with mingw

Martin Storsjö via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Aug 23 08:51:17 PDT 2022


mstorsjo created this revision.
mstorsjo added reviewers: rovka, mmuetzel, awarzynski, Meinersbur.
Herald added projects: Flang, All.
mstorsjo requested review of this revision.
Herald added a subscriber: jdoerfert.

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.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132481

Files:
  flang/runtime/file.cpp


Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -426,10 +426,12 @@
 
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132481.454863.patch
Type: text/x-patch
Size: 671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220823/cae3f8e3/attachment-0001.bin>


More information about the flang-commits mailing list