[flang-commits] [flang] 922c29c - [flang] Allow explicit '+' in NAMELIST input subscripts

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jan 20 17:01:14 PST 2022


Author: Peter Klausler
Date: 2022-01-20T17:01:02-08:00
New Revision: 922c29ccf143aa6c42d5887eef74d23e4ee83cb2

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

LOG: [flang] Allow explicit '+' in NAMELIST input subscripts

Array subscripts and substring limits in NAMELIST input are
allowed to bear an explicit plus sign.

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

Added: 
    

Modified: 
    flang/runtime/namelist.cpp
    flang/unittests/Runtime/Namelist.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 2804679db01e2..205212ccfb66e 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -99,7 +99,7 @@ static std::optional<SubscriptValue> GetSubscriptValue(IoStatementState &io) {
   std::optional<SubscriptValue> value;
   std::optional<char32_t> ch{io.GetCurrentChar()};
   bool negate{ch && *ch == '-'};
-  if (negate) {
+  if ((ch && *ch == '+') || negate) {
     io.HandleRelativePosition(1);
     ch = io.GetCurrentChar();
   }

diff  --git a/flang/unittests/Runtime/Namelist.cpp b/flang/unittests/Runtime/Namelist.cpp
index 4770e26048de9..f4f5a30e101eb 100644
--- a/flang/unittests/Runtime/Namelist.cpp
+++ b/flang/unittests/Runtime/Namelist.cpp
@@ -135,7 +135,7 @@ TEST(NamelistTests, Subscripts) {
   aDesc->GetDimension(1).SetBounds(-1, 1);
   const NamelistGroup::Item items[]{{"a", *aDesc}};
   const NamelistGroup group{"justa", 1, items};
-  static char t1[]{"&justa A(0,1:-1:-2)=1 2/"};
+  static char t1[]{"&justa A(0,+1:-1:-2)=1 2/"};
   StaticDescriptor<1, true> statDesc;
   Descriptor &internalDesc{statDesc.descriptor()};
   internalDesc.Establish(TypeCode{CFI_type_char},
@@ -223,7 +223,7 @@ TEST(NamelistTypes, ArraySubstring) {
           std::vector<std::string>{"abcdefgh", "ijklmnop"}, 8)};
   const NamelistGroup::Item items[]{{"a", *scDesc}};
   const NamelistGroup group{"justa", 1, items};
-  static char t1[]{"&justa A(:)(2:5)='BCDE' 'JKLM'/"};
+  static char t1[]{"&justa A(:)(2:+5)='BCDE' 'JKLM'/"};
   StaticDescriptor<1, true> statDesc;
   Descriptor &internalDesc{statDesc.descriptor()};
   internalDesc.Establish(TypeCode{CFI_type_char},


        


More information about the flang-commits mailing list