[flang-commits] [flang] ede4213 - [flang][runtime] Handle READ of non-UTF-8 data into multi-byte CHARACTER

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jun 23 10:02:26 PDT 2022


Author: Peter Klausler
Date: 2022-06-23T10:02:14-07:00
New Revision: ede421316948db04cf52ba3dc7fe40b8047eca5b

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

LOG: [flang][runtime] Handle READ of non-UTF-8 data into multi-byte CHARACTER

When a READ statement reads into a CHARACTER(2 or 4) variable from a
unit whose encoding is not UTF-8, don't copy bytes directly; they must
each be zero-extended.

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

Added: 
    

Modified: 
    flang/runtime/edit-input.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index 226bf3570ab3..5be6b0760418 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -730,7 +730,17 @@ bool EditCharacterInput(
         chunk = 1;
       }
       --remaining;
-    } else {
+    } else if constexpr (sizeof *x > 1) {
+      // Read single byte with expansion into multi-byte CHARACTER
+      chunk = 1;
+      if (skipping) {
+        --skip;
+      } else {
+        *x++ = static_cast<unsigned char>(*input);
+        --length;
+      }
+      --remaining;
+    } else { // single bytes -> default CHARACTER
       if (skipping) {
         chunk = std::min<std::size_t>(skip, ready);
         skip -= chunk;


        


More information about the flang-commits mailing list