From 28d8a67d43aff990d331852178a86e0bf0a94f30 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Fri, 21 Feb 2020 15:31:12 -0800 Subject: [PATCH] [flang] Fix parsing bug on DATA statement This DATA statement was getting a parsing error: `data x /a(i)%b/` The parser was expecting the ending '/' where the '%' was. The problem was parsing `a(i)` as a structure constructor. Instead, move the constant subobject case before structure constructor, but match it only if not followed by '('. That is because in `data x /a(1)(2)/`, `a(1)` is a valid structure constructor. Also, remove the NamedConstant alternative from DataStmtRepeat. A named constant is always parsed as a ConstantSubobject so it can never occur. Original-commit: flang-compiler/f18@04a76b272675d47ec7752420b15976c69a907dab Reviewed-on: https://github.com/flang-compiler/f18/pull/1012 --- flang/include/flang/parser/parse-tree.h | 4 +--- flang/lib/parser/Fortran-parsers.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/flang/include/flang/parser/parse-tree.h b/flang/include/flang/parser/parse-tree.h index 57093e3..f1e02e0 100644 --- a/flang/include/flang/parser/parse-tree.h +++ b/flang/include/flang/parser/parse-tree.h @@ -1412,9 +1412,7 @@ struct DataStmtConstant { // (only literal-constant -> int-literal-constant applies) struct DataStmtRepeat { UNION_CLASS_BOILERPLATE(DataStmtRepeat); - std::variant>, - Scalar>> - u; + std::variant>> u; }; // R843 data-stmt-value -> [data-stmt-repeat *] data-stmt-constant diff --git a/flang/lib/parser/Fortran-parsers.cpp b/flang/lib/parser/Fortran-parsers.cpp index f895189..d15901a7 100644 --- a/flang/lib/parser/Fortran-parsers.cpp +++ b/flang/lib/parser/Fortran-parsers.cpp @@ -818,12 +818,10 @@ constexpr auto constantSubobject{constant(indirect(designator))}; // R844 data-stmt-repeat -> scalar-int-constant | scalar-int-constant-subobject // R607 int-constant -> constant -// Factored into: -// constant -> literal-constant -> int-literal-constant and -// constant -> named-constant +// Factored into: constant -> literal-constant -> int-literal-constant +// The named-constant alternative of constant is subsumed by constant-subobject TYPE_PARSER(construct(intLiteralConstant) || - construct(scalar(integer(constantSubobject))) || - construct(scalar(integer(namedConstant)))) + construct(scalar(integer(constantSubobject)))) // R845 data-stmt-constant -> // scalar-constant | scalar-constant-subobject | @@ -833,8 +831,8 @@ TYPE_PARSER(construct(intLiteralConstant) || // references into constant subobjects. TYPE_PARSER(first(construct(scalar(Parser{})), construct(nullInit), + construct(scalar(constantSubobject)) / !"("_tok, construct(Parser{}), - construct(scalar(constantSubobject)), construct(signedRealLiteralConstant), construct(signedIntLiteralConstant), extension( -- 2.7.4