Skip to content

Commit 864d253

Browse files
authored
[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.
1 parent f5960c1 commit 864d253

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- include/flang/Common/windows-include.h ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Wrapper around windows.h that works around the name conflicts.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef FORTRAN_COMMON_WINDOWS_INCLUDE_H_
14+
#define FORTRAN_COMMON_WINDOWS_INCLUDE_H_
15+
16+
#ifdef _WIN32
17+
18+
#define WIN32_LEAN_AND_MEAN
19+
#define NOMINMAX
20+
21+
#include <windows.h>
22+
23+
#endif // _WIN32
24+
25+
#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_

flang/runtime/command.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
#include <limits>
1717

1818
#ifdef _WIN32
19-
#define WIN32_LEAN_AND_MEAN
20-
#define NOMINMAX
21-
#include <windows.h>
19+
#include "flang/Common/windows-include.h"
2220

2321
// On Windows GetCurrentProcessId returns a DWORD aka uint32_t
2422
#include <processthreadsapi.h>

flang/runtime/execute.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
#include <future>
1717
#include <limits>
1818
#ifdef _WIN32
19-
#define LEAN_AND_MEAN
20-
#define NOMINMAX
21-
#include <windows.h>
19+
#include "flang/Common/windows-include.h"
2220
#else
2321
#include <signal.h>
2422
#include <sys/wait.h>

flang/runtime/file.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
#include <stdlib.h>
1818
#include <sys/stat.h>
1919
#ifdef _WIN32
20-
#define NOMINMAX
20+
#include "flang/Common/windows-include.h"
2121
#include <io.h>
22-
#include <windows.h>
2322
#else
2423
#include <unistd.h>
2524
#endif

flang/runtime/lock.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#if USE_PTHREADS
2626
#include <pthread.h>
2727
#elif defined(_WIN32)
28-
// Do not define macros for "min" and "max"
29-
#define NOMINMAX
30-
#include <windows.h>
28+
#include "flang/Common/windows-include.h"
3129
#else
3230
#include <mutex>
3331
#endif

0 commit comments

Comments
 (0)