[flang-commits] [flang] [flang] GETPID runtime and lower intrinsic implementation (PR #70442)
David Truby via flang-commits
flang-commits at lists.llvm.org
Tue Oct 31 10:03:57 PDT 2023
================
@@ -14,6 +14,14 @@
#include "flang/Runtime/descriptor.h"
#include <cstdlib>
#include <limits>
+#ifdef _WIN32
+// On Windows* OS _getpid() returns int (not pid_t), declared in process.h
+#include <process.h>
+#define getpid _getpid
+typedef int pid_t;
----------------
DavidTruby wrote:
_getpid is deprecated on Windows and isn't available in some versions of the Windows CRT. Can do something like:
```c++
#include <processthreadsapi.h>
#define getpid GetCurrentProcessId
typedef int64 pid_t;
```
instead? GetCurrentProcessId is in kernel32.dll since Windows XP so will definitely be available.
I also don't really like redefining the function name as a macro, it feels a bit fragile. You could just quickly define a function here instead like
```
inline pid_t getpid() { return GetCurrentProcessId(); }
```
it's slightly more code but less likely to break.
https://github.com/llvm/llvm-project/pull/70442
More information about the flang-commits
mailing list