[flang-commits] [flang] 6ee2aa1 - [flang][NFC] Document extension: scalars are trivially contiguous

peter klausler via flang-commits flang-commits at lists.llvm.org
Tue Oct 12 16:01:46 PDT 2021


Author: peter klausler
Date: 2021-10-12T16:00:54-07:00
New Revision: 6ee2aa126cf6bccb6a4af955a663ff3512aecc63

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

LOG: [flang][NFC] Document extension: scalars are trivially contiguous

The Fortran 2018 standard defines the concept of simple contiguity
in subclause 9.5.4 as a characteristic of arrays.  So that scalars
may also be used in contexts where simply contiguous arrays are
allowed, f18 treats them as single-element arrays that are trivially
contiguous.  This patch documents this semantic extension and
also adds comments to the predicate that implements the concept.

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

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/lib/Evaluate/check-expression.cpp

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index ac293ce08d5f..d4dacb7e427f 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -175,6 +175,10 @@ end
 * OPEN(ACCESS='APPEND') is interpreted as OPEN(POSITION='APPEND')
   to ease porting from Sun Fortran.
 * Intrinsic subroutines EXIT([status]) and ABORT()
+* The definition of simple contiguity in 9.5.4 applies only to arrays;
+  we also treat scalars as being trivially contiguous, so that they
+  can be used in contexts like data targets in pointer assignments
+  with bounds remapping.
 
 ### Extensions supported when enabled by options
 

diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 2e0cc8087b8a..aaed4c33b1e1 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -626,8 +626,12 @@ class IsSimplyContiguousHelper
 
   Result operator()(const semantics::Symbol &symbol) const {
     const auto &ultimate{symbol.GetUltimate()};
-    if (ultimate.attrs().test(semantics::Attr::CONTIGUOUS) ||
-        ultimate.Rank() == 0) {
+    if (ultimate.attrs().test(semantics::Attr::CONTIGUOUS)) {
+      return true;
+    } else if (ultimate.Rank() == 0) {
+      // Extension: accept scalars as a degenerate case of
+      // simple contiguity to allow their use in contexts like
+      // data targets in pointer assignments with remapping.
       return true;
     } else if (semantics::IsPointer(ultimate)) {
       return false;


        


More information about the flang-commits mailing list