[llvm] [flang-rt] Fix for TIMEF test case hanging on Windows (PR #195651)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 06:46:35 PDT 2026


https://github.com/NimishMishra updated https://github.com/llvm/llvm-project/pull/195651

>From 6429eaf4b71a1b54eb4b7255842becf6fa77ecab Mon Sep 17 00:00:00 2001
From: NimishMishra <neelam.nimish at gmail.com>
Date: Mon, 4 May 2026 18:47:25 +0530
Subject: [PATCH 1/4] [flang-rt] Fix for hanging Windows test case

---
 flang-rt/unittests/Runtime/Time.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/flang-rt/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
index 08c672c739909..3cf35074309f1 100644
--- a/flang-rt/unittests/Runtime/Time.cpp
+++ b/flang-rt/unittests/Runtime/Time.cpp
@@ -41,8 +41,11 @@ TEST(TimeIntrinsics, Timef) {
   // Loop until we get a different value from Timef. If we don't get one
   // before we time out, then we should probably look into an implementation
   // for Timef with a better timer resolution.
-  // By default, this loop should burn for 1 second.
-  for (end = start; end == start; end = RTNAME(Timef)()) {
+  // By default, this loop should burn for 1 second or until the end of
+  // the iteration count.
+  int max_iterations{10000000};
+  for (int iter = 0, end = start; end == start && iter < max_iterations;
+      end = RTNAME(Timef)(), iter++) {
     ASSERT_GE(end, 0.0);
     ASSERT_GE(end, start);
   }

>From d30380c6eb2d1de2a2f2371e4b797bd9821af07f Mon Sep 17 00:00:00 2001
From: NimishMishra <neelam.nimish at gmail.com>
Date: Mon, 4 May 2026 18:48:26 +0530
Subject: [PATCH 2/4] Modify comment

---
 flang-rt/lib/runtime/extensions.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang-rt/lib/runtime/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp
index b653f3634187a..724c4ab6e6fd2 100644
--- a/flang-rt/lib/runtime/extensions.cpp
+++ b/flang-rt/lib/runtime/extensions.cpp
@@ -459,10 +459,8 @@ double RTNAME(Timef)() {
     return duration;
   }
 #else
-  // TODO: Windows implementation. Currently, we return a dummy
-  // non-zero value to prevent the `TIMEF` unittest from
-  // hanging
-  return 1.0;
+  // TODO: Windows implementation.
+  return 0.0;
 #endif
 }
 

>From bf134a375654808ed45fdf3165d43c97365e6990 Mon Sep 17 00:00:00 2001
From: NimishMishra <42909663+NimishMishra at users.noreply.github.com>
Date: Mon, 4 May 2026 06:40:55 -0700
Subject: [PATCH 3/4] Update Time.cpp

---
 flang-rt/unittests/Runtime/Time.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/flang-rt/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
index 3cf35074309f1..adb1a6f2c0843 100644
--- a/flang-rt/unittests/Runtime/Time.cpp
+++ b/flang-rt/unittests/Runtime/Time.cpp
@@ -41,10 +41,9 @@ TEST(TimeIntrinsics, Timef) {
   // Loop until we get a different value from Timef. If we don't get one
   // before we time out, then we should probably look into an implementation
   // for Timef with a better timer resolution.
-  // By default, this loop should burn for 1 second or until the end of
-  // the iteration count.
-  int max_iterations{10000000};
-  for (int iter = 0, end = start; end == start && iter < max_iterations;
+  constexpr int max_iterations{10000000};
+  int iter{0};
+  for (end = start; end == start && iter < max_iterations;
       end = RTNAME(Timef)(), iter++) {
     ASSERT_GE(end, 0.0);
     ASSERT_GE(end, start);

>From fb4ac2be360b8817b844f21385264e3ccdff1c5b Mon Sep 17 00:00:00 2001
From: NimishMishra <42909663+NimishMishra at users.noreply.github.com>
Date: Mon, 4 May 2026 06:46:24 -0700
Subject: [PATCH 4/4] Add GTEST_SKIP

---
 flang-rt/unittests/Runtime/Time.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/flang-rt/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
index adb1a6f2c0843..bd6f81734fb4a 100644
--- a/flang-rt/unittests/Runtime/Time.cpp
+++ b/flang-rt/unittests/Runtime/Time.cpp
@@ -32,6 +32,11 @@ TEST(TimeIntrinsics, CpuTime) {
 }
 
 TEST(TimeIntrinsics, Timef) {
+  #ifdef _WIN32
+  // TODO: remove this after TIMEF() is implemented on Windows
+  GTEST_SKIP() << "Timef() is not implemented on Windows";
+  #endif
+  
   // We can't really test that we get the "right" result for Timef, but we
   // can have a smoke test to see that we get something reasonable on the
   // platforms where we expect to support it.



More information about the llvm-commits mailing list