[flang-commits] [flang] 864d253 - [flang] Added windows-include.h wrapper to resolve name conflicts. (#87650)
via flang-commits
flang-commits at lists.llvm.org
Thu Apr 4 14:23:43 PDT 2024
Author: Slava Zakharin
Date: 2024-04-04T14:23:40-07:00
New Revision: 864d2531df8078a5bb49d24383d7219595d23690
URL: https://github.com/llvm/llvm-project/commit/864d2531df8078a5bb49d24383d7219595d23690
DIFF: https://github.com/llvm/llvm-project/commit/864d2531df8078a5bb49d24383d7219595d23690.diff
LOG: [flang] Added windows-include.h wrapper to resolve name conflicts. (#87650)
The header file includes windows.h in a mean-and-lean way to avoid
bringing in names that may conflict with Flang code.
Added:
flang/include/flang/Common/windows-include.h
Modified:
flang/runtime/command.cpp
flang/runtime/execute.cpp
flang/runtime/file.cpp
flang/runtime/lock.h
Removed:
################################################################################
diff --git a/flang/include/flang/Common/windows-include.h b/flang/include/flang/Common/windows-include.h
new file mode 100644
index 00000000000000..75ef4974251ff9
--- /dev/null
+++ b/flang/include/flang/Common/windows-include.h
@@ -0,0 +1,25 @@
+//===-- include/flang/Common/windows-include.h ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Wrapper around windows.h that works around the name conflicts.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_COMMON_WINDOWS_INCLUDE_H_
+#define FORTRAN_COMMON_WINDOWS_INCLUDE_H_
+
+#ifdef _WIN32
+
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+
+#include <windows.h>
+
+#endif // _WIN32
+
+#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index fabfe601688bbf..b573c5dfd797b3 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -16,9 +16,7 @@
#include <limits>
#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <windows.h>
+#include "flang/Common/windows-include.h"
// On Windows GetCurrentProcessId returns a DWORD aka uint32_t
#include <processthreadsapi.h>
diff --git a/flang/runtime/execute.cpp b/flang/runtime/execute.cpp
index c84930c5c3287c..0f5bc5059e21dc 100644
--- a/flang/runtime/execute.cpp
+++ b/flang/runtime/execute.cpp
@@ -16,9 +16,7 @@
#include <future>
#include <limits>
#ifdef _WIN32
-#define LEAN_AND_MEAN
-#define NOMINMAX
-#include <windows.h>
+#include "flang/Common/windows-include.h"
#else
#include <signal.h>
#include <sys/wait.h>
diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index 67764f1f562624..acd5d33d4bb87b 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -17,9 +17,8 @@
#include <stdlib.h>
#include <sys/stat.h>
#ifdef _WIN32
-#define NOMINMAX
+#include "flang/Common/windows-include.h"
#include <io.h>
-#include <windows.h>
#else
#include <unistd.h>
#endif
diff --git a/flang/runtime/lock.h b/flang/runtime/lock.h
index 9f27a8295c468b..46ca28703a45b4 100644
--- a/flang/runtime/lock.h
+++ b/flang/runtime/lock.h
@@ -25,9 +25,7 @@
#if USE_PTHREADS
#include <pthread.h>
#elif defined(_WIN32)
-// Do not define macros for "min" and "max"
-#define NOMINMAX
-#include <windows.h>
+#include "flang/Common/windows-include.h"
#else
#include <mutex>
#endif
More information about the flang-commits
mailing list