[flang-commits] [flang] [flang][runtime] NAMELIST input into storage sequence (PR #76584)
via flang-commits
flang-commits at lists.llvm.org
Fri Dec 29 11:35:03 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-runtime
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
Nearly every Fortran compiler supports the extension of NAMELIST input into a storage sequence identified by its initial scalar array element. For example,
&GROUP A(1) = 1. 2. 3. /
should be processed as if the input had been
&GROUP A(1:) = 1. 2. 3. /
Fixes llvm-test-suite/Fortran/gfortran/regression/namelist_24.f90.
---
Full diff: https://github.com/llvm/llvm-project/pull/76584.diff
2 Files Affected:
- (modified) flang/docs/Extensions.md (+4)
- (modified) flang/runtime/namelist.cpp (+31-13)
``````````diff
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 6c6588025a392d..7876a9ba80cbbe 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -654,3 +654,7 @@ end
but every Fortran compiler allows the encoding to be changed on an
open unit.
+* A `NAMELIST` input item that references a scalar element of a vector
+ or contiguous array can be used as the initial element of a storage
+ sequence. For example, "&GRP A(1)=1. 2. 3./" is treated as if had been
+ "&GRP A(1:)=1. 2. 3./".
diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 61815a7cc8a403..f2c0a0e6215708 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -229,22 +229,40 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
stride[j] = dimStride;
}
}
- if (ok) {
- if (ch && *ch == ')') {
- io.HandleRelativePosition(byteCount);
- if (desc.EstablishPointerSection(source, lower, upper, stride)) {
- return true;
- } else {
- handler.SignalError(
- "Bad subscripts for NAMELIST input group item '%s'", name);
- }
- } else {
+ if (!ok) {
+ return false;
+ } else if (ch && *ch == ')') {
+ io.HandleRelativePosition(byteCount);
+ if (!desc.EstablishPointerSection(source, lower, upper, stride)) {
handler.SignalError(
- "Bad subscripts (missing ')') for NAMELIST input group item '%s'",
- name);
+ "Bad subscripts for NAMELIST input group item '%s'", name);
+ return false;
}
+ } else {
+ handler.SignalError(
+ "Bad subscripts (missing ')') for NAMELIST input group item '%s'",
+ name);
+ return false;
}
- return false;
+ // Support the near-universal extension of NAMELIST input into a
+ // designatable storage sequence identified by its initial scalar array
+ // element. For example, treat "A(1) = 1. 2. 3." as if it had been
+ // "A(1:) = 1. 2. 3.".
+ if (desc.rank() == 0 && (source.rank() == 1 || source.IsContiguous())) {
+ if (auto stride{source.rank() == 1
+ ? source.GetDimension(0).ByteStride()
+ : static_cast<SubscriptValue>(source.ElementBytes())};
+ stride != 0) {
+ desc.raw().attribute = CFI_attribute_pointer;
+ desc.raw().rank = 1;
+ desc.GetDimension(0)
+ .SetBounds(1,
+ source.Elements() -
+ ((source.OffsetElement() - desc.OffsetElement()) / stride))
+ .SetByteStride(stride);
+ }
+ }
+ return true;
}
static bool HandleSubstring(
``````````
</details>
https://github.com/llvm/llvm-project/pull/76584
More information about the flang-commits
mailing list