[flang-commits] [flang] [flang] Relax ETIME(VALUES=) runtime checking (PR #107647)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Sep 6 15:04:19 PDT 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/107647

Don't require the "VALUES=" argument to the extension intrinsic procedure ETIME to have exactly two elements.  Other compilers that support ETIME do not, and it's easy to adapt the behavior to whatever the dynamic size turns out to be.

>From f1bf7ee5005403db2872b16c1c64bf8ffae13510 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 6 Sep 2024 15:00:43 -0700
Subject: [PATCH] [flang] Relax ETIME(VALUES=) runtime checking

Don't require the "VALUES=" argument to the extension intrinsic procedure
ETIME to have exactly two elements.  Other compilers that support ETIME
do not, and it's easy to adapt the behavior to whatever the dynamic size
turns out to be.
---
 flang/runtime/time-intrinsic.cpp | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/flang/runtime/time-intrinsic.cpp b/flang/runtime/time-intrinsic.cpp
index 7e590eabf39660..e6f6e81c7b50cc 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -490,16 +490,20 @@ void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,
     auto typeCode{values->type().GetCategoryAndKind()};
     // ETIME values argument must have decimal range == 2.
     RUNTIME_CHECK(terminator,
-        values->rank() == 1 && values->GetDimension(0).Extent() == 2 &&
-            typeCode && typeCode->first == Fortran::common::TypeCategory::Real);
+        values->rank() == 1 && typeCode &&
+            typeCode->first == Fortran::common::TypeCategory::Real);
     // Only accept KIND=4 here.
     int kind{typeCode->second};
     RUNTIME_CHECK(terminator, kind == 4);
-
-    ApplyFloatingPointKind<StoreFloatingPointAt, void>(
-        kind, terminator, *values, /* atIndex = */ 0, usrTime);
-    ApplyFloatingPointKind<StoreFloatingPointAt, void>(
-        kind, terminator, *values, /* atIndex = */ 1, sysTime);
+    auto extent{values->GetDimension(0).Extent()};
+    if (extent >= 1) {
+      ApplyFloatingPointKind<StoreFloatingPointAt, void>(
+          kind, terminator, *values, /* atIndex = */ 0, usrTime);
+    }
+    if (extent >= 2) {
+      ApplyFloatingPointKind<StoreFloatingPointAt, void>(
+          kind, terminator, *values, /* atIndex = */ 1, sysTime);
+    }
   }
 
   if (time) {



More information about the flang-commits mailing list