[flang-commits] [flang] 15e997a - [flang][runtime] Fix MINVAL([CHARACTER(2)::])

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Aug 25 14:31:31 PDT 2022


Author: Peter Klausler
Date: 2022-08-25T14:31:14-07:00
New Revision: 15e997ac014b8ffe2e848b650110b55c4807900c

URL: https://github.com/llvm/llvm-project/commit/15e997ac014b8ffe2e848b650110b55c4807900c
DIFF: https://github.com/llvm/llvm-project/commit/15e997ac014b8ffe2e848b650110b55c4807900c.diff

LOG: [flang][runtime] Fix MINVAL([CHARACTER(2)::])

The result of MINVAL over an empty default character array should
(per the standard) have a 127 in every character position, not just
the first.

Differential Revision: https://reviews.llvm.org/D132677

Added: 
    

Modified: 
    flang/runtime/extrema.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/extrema.cpp b/flang/runtime/extrema.cpp
index 8290ad3c56c4e..d77ee17451d2e 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang/runtime/extrema.cpp
@@ -423,12 +423,10 @@ template <int KIND, bool IS_MAXVAL> class CharacterExtremumAccumulator {
     if (extremum_) {
       std::memcpy(p, extremum_, byteSize);
     } else {
-      // 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);
-      }
+      // Empty array; fill with character 0 for MAXVAL.
+      // For MINVAL, fill with 127 if ASCII as required
+      // by the standard, otherwise set all of the bits.
+      std::memset(p, IS_MAXVAL ? 0 : KIND == 1 ? 127 : 255, byteSize);
     }
   }
   bool Accumulate(const Type *x) {


        


More information about the flang-commits mailing list