[flang-commits] [flang] [flang] Add GETCWD runtime and lowering intrinsics implementation (PR #92746)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon May 20 08:13:53 PDT 2024
================
@@ -239,4 +241,22 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
return StatOk;
}
+std::int32_t RTNAME(GetCwd)(
+ const Descriptor &cwd, const char *sourceFile, int line) {
+ Terminator terminator{sourceFile, line};
+
+ RUNTIME_CHECK(terminator, IsValidCharDescriptor(&cwd));
+
+ char *buf = getcwd(nullptr, 0);
----------------
tblah wrote:
POSIX does not require that `getcwd(nullptr, 0)` allocates memory with `malloc`. It would be standards compliant to just return nullptr here.
My glibc man page says that it does implement the memory allocation as an extension to the POSIX standard. If this extension is present on all implementations where people are using flang in practice (MacOS, *BSD, Windows, AIX(?)) then this is okay, otherwise we cannot rely on this behavior.
See https://pubs.opengroup.org/onlinepubs/009695399/functions/getcwd.html
https://github.com/llvm/llvm-project/pull/92746
More information about the flang-commits
mailing list