From 922c29ccf143aa6c42d5887eef74d23e4ee83cb2 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 12 Jan 2022 15:10:20 -0800 Subject: [PATCH] [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 --- flang/runtime/namelist.cpp | 2 +- flang/unittests/Runtime/Namelist.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp index 2804679db01e..205212ccfb66 100644 --- a/flang/runtime/namelist.cpp +++ b/flang/runtime/namelist.cpp @@ -99,7 +99,7 @@ static std::optional GetSubscriptValue(IoStatementState &io) { std::optional value; std::optional 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 4770e26048de..f4f5a30e101e 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{"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},