[flang-commits] [PATCH] D132156: [flang][runtime] Fix return value for MINVAL/MAXVAL for CHARACTER(kind > 1)

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Aug 18 14:30:59 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd117fa04b62: [flang][runtime] Fix return value for MINVAL/MAXVAL for CHARACTER(kind > 1) (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132156/new/

https://reviews.llvm.org/D132156

Files:
  flang/runtime/extrema.cpp


Index: flang/runtime/extrema.cpp
===================================================================
--- flang/runtime/extrema.cpp
+++ flang/runtime/extrema.cpp
@@ -419,11 +419,16 @@
   void Reinitialize() { extremum_ = nullptr; }
   template <typename A> void GetResult(A *p, int /*zeroBasedDim*/ = -1) const {
     static_assert(std::is_same_v<A, Type>);
+    std::size_t byteSize{array_.ElementBytes()};
     if (extremum_) {
-      std::memcpy(p, extremum_, charLen_);
+      std::memcpy(p, extremum_, byteSize);
     } else {
-      // empty array: result is all zero-valued characters
-      std::memset(p, 0, charLen_);
+      // empty array
+      if constexpr (KIND == 1) { // ASCII
+        *p = IS_MAXVAL ? 0 : 127; // 127 required by standard
+      } else {
+        std::memset(p, IS_MAXVAL ? 0 : 255, byteSize);
+      }
     }
   }
   bool Accumulate(const Type *x) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132156.453790.patch
Type: text/x-patch
Size: 884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220818/6bb178da/attachment.bin>


More information about the flang-commits mailing list