[flang] [llvm] [flang-rt] Runtime implementation of extended intrinsic function SECNDS() (PR #152021)
Peter Klausler via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 16:49:59 PDT 2025
================
@@ -303,6 +303,47 @@ void FORTRAN_PROCEDURE_NAME(qsort)(int *array, int *len, int *isize,
// PERROR(STRING)
void RTNAME(Perror)(const char *str) { perror(str); }
+// GNU extension function SECNDS(refTime)
+float FORTRAN_PROCEDURE_NAME(secnds)(float *refTime) {
+ constexpr float FAIL_SECNDS{-1.0f}; // Failure code for this function
+ // Failure code for time functions that return std::time_t
+ constexpr time_t FAIL_TIME{std::time_t{-1}};
+ if (!refTime) {
+ return FAIL_SECNDS;
+ }
+ std::time_t now{std::time(nullptr)};
+ if (now == FAIL_TIME) {
+ return FAIL_SECNDS;
+ }
+ // In float result, we can only precisely store 2^24 seconds, which
+ // comes out to about 194 days. Thus, need to pick a starting point.
+ // Given the description of this function, midnight of the current
+ // day is the best starting point.
+ static time_t startingPoint{0};
----------------
klausler wrote:
Be sure to not create a dependence on the C++ runtime library binaries from libflang_rt.runtime.
https://github.com/llvm/llvm-project/pull/152021
More information about the llvm-commits
mailing list