Skip to content

Commit 19a4b9e

Browse files
committed
move getuid/getpid to extensions.cpp and add TODO
1 parent 74242ef commit 19a4b9e

File tree

8 files changed

+54
-43
lines changed

8 files changed

+54
-43
lines changed

flang/include/flang/Optimizer/Builder/Runtime/Intrinsics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void genDateAndTime(fir::FirOpBuilder &, mlir::Location,
4747
void genEtime(fir::FirOpBuilder &builder, mlir::Location loc,
4848
mlir::Value values, mlir::Value time);
4949

50+
mlir::Value genGetUID(fir::FirOpBuilder &, mlir::Location);
51+
mlir::Value genGetGID(fir::FirOpBuilder &, mlir::Location);
52+
5053
void genRandomInit(fir::FirOpBuilder &, mlir::Location, mlir::Value repeatable,
5154
mlir::Value imageDistinct);
5255
void genRandomNumber(fir::FirOpBuilder &, mlir::Location, mlir::Value harvest);

flang/include/flang/Runtime/command.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#ifdef _WIN32
1616
// On Windows* OS GetCurrentProcessId returns DWORD aka uint32_t
1717
typedef std::uint32_t pid_t;
18-
// UID and GID don't exist on Windows, these exist to avoid errors.
19-
typedef std::uint32_t uid_t;
20-
typedef std::uint32_t gid_t;
2118
#else
2219
#include "sys/types.h" //pid_t
2320
#endif
@@ -32,15 +29,9 @@ extern "C" {
3229
// integer kind.
3330
std::int32_t RTNAME(ArgumentCount)();
3431

35-
// Calls getgid()
36-
gid_t RTNAME(GetGID)();
37-
3832
// Calls getpid()
3933
pid_t RTNAME(GetPID)();
4034

41-
// Calls getuid()
42-
uid_t RTNAME(GetUID)();
43-
4435
// 16.9.82 GET_COMMAND
4536
// Try to get the value of the whole command. All of the parameters are
4637
// optional.

flang/include/flang/Runtime/extensions.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
#include <cstddef>
2121
#include <cstdint>
2222

23+
#ifdef _WIN32
24+
// UID and GID don't exist on Windows, these exist to avoid errors.
25+
typedef std::uint32_t uid_t;
26+
typedef std::uint32_t gid_t;
27+
#else
28+
#include "sys/types.h" //pid_t
29+
#endif
30+
2331
extern "C" {
2432

2533
// CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement.
@@ -35,6 +43,12 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
3543
void FORTRAN_PROCEDURE_NAME(getarg)(
3644
std::int32_t &n, char *arg, std::int64_t length);
3745

46+
// Calls getgid()
47+
gid_t RTNAME(GetGID)();
48+
49+
// Calls getuid()
50+
uid_t RTNAME(GetUID)();
51+
3852
// GNU extension subroutine GETLOG(C).
3953
void FORTRAN_PROCEDURE_NAME(getlog)(char *name, std::int64_t length);
4054

flang/lib/Optimizer/Builder/Runtime/Command.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ mlir::Value fir::runtime::genGetCommand(fir::FirOpBuilder &builder,
4848
return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0);
4949
}
5050

51-
mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder,
52-
mlir::Location loc) {
53-
auto runtimeFunc =
54-
fir::runtime::getRuntimeFunc<mkRTKey(GetGID)>(loc, builder);
55-
56-
return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0);
57-
}
58-
5951
mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder,
6052
mlir::Location loc) {
6153
auto runtimeFunc =
@@ -64,14 +56,6 @@ mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder,
6456
return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0);
6557
}
6658

67-
mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder,
68-
mlir::Location loc) {
69-
auto runtimeFunc =
70-
fir::runtime::getRuntimeFunc<mkRTKey(GetUID)>(loc, builder);
71-
72-
return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0);
73-
}
74-
7559
mlir::Value fir::runtime::genGetCommandArgument(
7660
fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value number,
7761
mlir::Value value, mlir::Value length, mlir::Value errmsg) {

flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc,
120120
builder.create<fir::CallOp>(loc, runtimeFunc, args);
121121
}
122122

123+
mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder,
124+
mlir::Location loc) {
125+
auto runtimeFunc =
126+
fir::runtime::getRuntimeFunc<mkRTKey(GetGID)>(loc, builder);
127+
128+
return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0);
129+
}
130+
131+
mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder,
132+
mlir::Location loc) {
133+
auto runtimeFunc =
134+
fir::runtime::getRuntimeFunc<mkRTKey(GetUID)>(loc, builder);
135+
136+
return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0);
137+
}
138+
123139
void fir::runtime::genRandomInit(fir::FirOpBuilder &builder, mlir::Location loc,
124140
mlir::Value repeatable,
125141
mlir::Value imageDistinct) {

flang/lib/Semantics/check-call.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,8 @@ bool CheckPPCIntrinsic(const Symbol &generic, const Symbol &specific,
20232023
bool CheckWindowsIntrinsic(
20242024
const Symbol &intrinsic, evaluate::FoldingContext &foldingContext) {
20252025
parser::ContextualMessages &messages{foldingContext.messages()};
2026+
// TODO: there are other intrinsics that are unsupported on Windows that
2027+
// should be added here.
20262028
if (intrinsic.name() == "getuid") {
20272029
messages.Say(
20282030
"User IDs do not exist on Windows. This function will always return 1"_warn_en_US);

flang/runtime/command.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,8 @@ std::int32_t RTNAME(ArgumentCount)() {
4242
return 0;
4343
}
4444

45-
gid_t RTNAME(GetGID)() {
46-
#ifdef _WIN32
47-
// Group IDs don't exist on Windows, return 1 to avoid errors
48-
return 1;
49-
#else
50-
return getgid();
51-
#endif
52-
}
53-
5445
pid_t RTNAME(GetPID)() { return getpid(); }
5546

56-
uid_t RTNAME(GetUID)() {
57-
#ifdef _WIN32
58-
// User IDs don't exist on Windows, return 1 to avoid errors
59-
return 1;
60-
#else
61-
return getuid();
62-
#endif
63-
}
64-
6547
// Returns the length of the \p string. Assumes \p string is valid.
6648
static std::int64_t StringLength(const char *string) {
6749
std::size_t length{std::strlen(string)};

flang/runtime/extensions.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ extern "C" {
5858

5959
namespace Fortran::runtime {
6060

61+
gid_t RTNAME(GetGID)() {
62+
#ifdef _WIN32
63+
// Group IDs don't exist on Windows, return 1 to avoid errors
64+
return 1;
65+
#else
66+
return getgid();
67+
#endif
68+
}
69+
70+
uid_t RTNAME(GetUID)() {
71+
#ifdef _WIN32
72+
// User IDs don't exist on Windows, return 1 to avoid errors
73+
return 1;
74+
#else
75+
return getuid();
76+
#endif
77+
}
78+
6179
void GetUsernameEnvVar(const char *envName, char *arg, std::int64_t length) {
6280
Descriptor name{*Descriptor::Create(
6381
1, std::strlen(envName) + 1, const_cast<char *>(envName), 0)};
@@ -66,6 +84,7 @@ void GetUsernameEnvVar(const char *envName, char *arg, std::int64_t length) {
6684
RTNAME(GetEnvVariable)
6785
(name, &value, nullptr, false, nullptr, __FILE__, __LINE__);
6886
}
87+
6988
namespace io {
7089
// SUBROUTINE FLUSH(N)
7190
// FLUSH N

0 commit comments

Comments
 (0)