Skip to content

Commit 3f73939

Browse files
committed
[flang] Handle substring in data statement constant
The case of a constant substring wasn't handled in the parser for data statement constants. Fixes #119005.
1 parent 3c3094b commit 3f73939

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,10 @@ struct DataStmtConstant {
14811481
UNION_CLASS_BOILERPLATE(DataStmtConstant);
14821482
CharBlock source;
14831483
mutable TypedExpr typedExpr;
1484-
std::variant<LiteralConstant, SignedIntLiteralConstant,
1485-
SignedRealLiteralConstant, SignedComplexLiteralConstant, NullInit,
1486-
common::Indirection<Designator>, StructureConstructor>
1484+
std::variant<common::Indirection<CharLiteralConstantSubstring>,
1485+
LiteralConstant, SignedIntLiteralConstant, SignedRealLiteralConstant,
1486+
SignedComplexLiteralConstant, NullInit, common::Indirection<Designator>,
1487+
StructureConstructor>
14871488
u;
14881489
};
14891490

flang/lib/Parser/Fortran-parsers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ TYPE_PARSER(construct<DataStmtRepeat>(intLiteralConstant) ||
930930
// So we parse literal constants, designator, null-init, and
931931
// structure-constructor, so that semantics can figure things out later
932932
// with the symbol table.
933-
TYPE_PARSER(sourced(first(construct<DataStmtConstant>(literalConstant),
933+
TYPE_PARSER(sourced(first(
934+
construct<DataStmtConstant>(indirect(charLiteralConstantSubstring)),
935+
construct<DataStmtConstant>(literalConstant),
934936
construct<DataStmtConstant>(signedRealLiteralConstant),
935937
construct<DataStmtConstant>(signedIntLiteralConstant),
936938
extension<LanguageFeature::SignedComplexLiteral>(

flang/lib/Parser/expr-parsers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TYPE_PARSER(construct<AcImpliedDoControl>(
6868
// type-param-inquiry is parsed as a structure component, except for
6969
// substring%KIND/LEN
7070
constexpr auto primary{instrumented("primary"_en_US,
71-
first(construct<Expr>(indirect(Parser<CharLiteralConstantSubstring>{})),
71+
first(construct<Expr>(indirect(charLiteralConstantSubstring)),
7272
construct<Expr>(literalConstant),
7373
construct<Expr>(construct<Expr::Parentheses>("(" >>
7474
expr / !","_tok / recovery(")"_tok, SkipPastNested<'(', ')'>{}))),

flang/lib/Parser/type-parsers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ constexpr Parser<KindParam> kindParam; // R709
6363
constexpr Parser<RealLiteralConstant> realLiteralConstant; // R714
6464
constexpr Parser<CharLength> charLength; // R723
6565
constexpr Parser<CharLiteralConstant> charLiteralConstant; // R724
66+
constexpr Parser<CharLiteralConstantSubstring> charLiteralConstantSubstring;
6667
constexpr Parser<Initialization> initialization; // R743 & R805
6768
constexpr Parser<DerivedTypeSpec> derivedTypeSpec; // R754
6869
constexpr Parser<TypeDeclarationStmt> typeDeclarationStmt; // R801

flang/test/Parser/lit-substr-data.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
!Regression test for bug #119005
3+
character*2 :: ary4
4+
!CHECK: DATA ary4/"cd"/
5+
data ary4/"abcdef"(3:4)/
6+
end
7+

0 commit comments

Comments
 (0)