Skip to content

Commit f650de6

Browse files
committed
Add fake support for windows
Windows doesn't have getuid or anything Win32 equivalent, and it is also not supported in gfortran. Windows however have "GetTokenInformation" call and querying for the TokenUser information class. It returns user's SID.
1 parent 0ff6e49 commit f650de6

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace fir::runtime {
2323
/// Generate call to COMMAND_ARGUMENT_COUNT intrinsic runtime routine.
2424
mlir::Value genCommandArgumentCount(fir::FirOpBuilder &, mlir::Location);
2525

26+
/// Generate a call to the GetUID runtime function which implements the
27+
/// GETUID intrinsic.
28+
mlir::Value genGetUID(fir::FirOpBuilder &, mlir::Location);
29+
2630
/// Generate a call to the GetCommand runtime function which implements the
2731
/// GET_COMMAND intrinsic.
2832
/// \p command, \p length and \p errmsg must be fir.box that can be absent (but
@@ -49,9 +53,5 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, mlir::Location,
4953
mlir::Value length, mlir::Value trimName,
5054
mlir::Value errmsg);
5155

52-
/// Generate a call to the GetUID runtime function which implements the
53-
/// GETUID intrinsic.
54-
mlir::Value genGetUID(fir::FirOpBuilder &, mlir::Location);
55-
5656
} // namespace fir::runtime
5757
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H

flang/include/flang/Runtime/command.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <cstdint>
1515

1616
#ifdef _WIN32
17+
typedef int uid_t;
1718
#else
18-
#include "sys/types.h"
19+
#include "sys/types.h" //uid_t
1920
#endif
21+
2022
namespace Fortran::runtime {
2123
class Descriptor;
2224

@@ -27,6 +29,9 @@ extern "C" {
2729
// integer kind.
2830
std::int32_t RTNAME(ArgumentCount)();
2931

32+
// Calls getuid()
33+
uid_t RTNAME(GetUID)();
34+
3035
// 16.9.82 GET_COMMAND
3136
// Try to get the value of the whole command. All of the parameters are
3237
// optional.
@@ -52,9 +57,6 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
5257
const char *sourceFile = nullptr, int line = 0);
5358
}
5459

55-
// Calls getuid()
56-
uid_t RTNAME(GetUID)();
57-
5860
} // namespace Fortran::runtime
5961

6062
#endif // FORTRAN_RUNTIME_COMMAND_H_

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,14 @@ mlir::Value IntrinsicLibrary::genFraction(mlir::Type resultType,
29072907
fir::runtime::genFraction(builder, loc, fir::getBase(args[0])));
29082908
}
29092909

2910+
// GETUID
2911+
mlir::Value IntrinsicLibrary::genGetUID(mlir::Type resultType,
2912+
llvm::ArrayRef<mlir::Value> args) {
2913+
assert(args.size() == 0 && "getuid takes no input");
2914+
return builder.createConvert(loc, resultType,
2915+
fir::runtime::genGetUID(builder, loc));
2916+
}
2917+
29102918
// GET_COMMAND
29112919
void IntrinsicLibrary::genGetCommand(llvm::ArrayRef<fir::ExtendedValue> args) {
29122920
assert(args.size() == 4);
@@ -2945,14 +2953,6 @@ void IntrinsicLibrary::genGetCommand(llvm::ArrayRef<fir::ExtendedValue> args) {
29452953
}
29462954
}
29472955

2948-
// GETUID
2949-
mlir::Value IntrinsicLibrary::genGetUID(mlir::Type resultType,
2950-
llvm::ArrayRef<mlir::Value> args) {
2951-
assert(args.size() == 0 && "getuid takes no input");
2952-
return builder.createConvert(loc, resultType,
2953-
fir::runtime::genGetUID(builder, loc));
2954-
}
2955-
29562956
// GET_COMMAND_ARGUMENT
29572957
void IntrinsicLibrary::genGetCommandArgument(
29582958
llvm::ArrayRef<fir::ExtendedValue> args) {

flang/runtime/command.cpp

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

1818
#ifdef _WIN32
19+
inline uid_t getuid() { return 0; }
1920
#else
2021
#include <unistd.h>
2122
#endif

flang/unittests/Runtime/CommandTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ TEST_F(ZeroArguments, GetCommandArgument) {
228228
TEST_F(ZeroArguments, GetCommand) { CheckCommandValue(commandOnlyArgv, 1); }
229229

230230
TEST_F(ZeroArguments, GetUID) {
231-
// uid should always greater than 0, in both linux and windows
232-
EXPECT_GT(RTNAME(GetUID)(), 0U);
231+
CheckMissingArgumentValue(-1);
232+
CheckArgumentValue(commandOnlyArgv[0], 0);
233+
CheckMissingArgumentValue(1);
233234
}
234235

235236
static const char *oneArgArgv[]{"aProgram", "anArgumentOfLength20"};

0 commit comments

Comments
 (0)