From: peter klausler Date: Thu, 28 Feb 2019 21:31:34 +0000 (-0800) Subject: [flang] Character length conversion on structure constructor component assignments X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69352908e026e80f215253138b37ae5172b035a8;p=platform%2Fupstream%2Fllvm.git [flang] Character length conversion on structure constructor component assignments Original-commit: flang-compiler/f18@051c1dd923a3b321d1a19768414caf93732a3426 Reviewed-on: https://github.com/flang-compiler/f18/pull/311 Tree-same-pre-rewrite: false --- diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 4725162..21bc222 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -298,7 +298,7 @@ std::ostream &StructureConstructor::AsFortran(std::ostream &o) const { std::ostream &DerivedTypeSpecAsFortran( std::ostream &o, const semantics::DerivedTypeSpec &spec) { - o << "TYPE("s << spec.typeSymbol().name().ToString(); + o << spec.typeSymbol().name().ToString(); if (!spec.parameters().empty()) { char ch{'('}; for (const auto &[name, value] : spec.parameters()) { diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index ee91d7d..b9241fe 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -702,6 +702,24 @@ Expr> FoldOperation( return Expr{std::move(x)}; } +template +Expr> FoldOperation( + FoldingContext &context, SetLength &&x) { + using Result = Type; + if (auto folded{FoldOperands(context, x.left(), x.right())}) { + auto oldLength{static_cast(folded->first.size())}; + auto newLength{folded->second.ToInt64()}; + if (newLength < oldLength) { + folded->first.erase(newLength); + } else { + folded->first.append(newLength - oldLength, ' '); + } + CHECK(static_cast(folded->first.size()) == newLength); + return Expr{Constant{std::move(folded->first)}}; + } + return Expr{std::move(x)}; +} + template Expr FoldOperation( FoldingContext &context, Relational &&relation) { diff --git a/flang/lib/evaluate/type.cc b/flang/lib/evaluate/type.cc index 252aad8..7516114 100644 --- a/flang/lib/evaluate/type.cc +++ b/flang/lib/evaluate/type.cc @@ -207,7 +207,7 @@ bool SomeKind::operator==( std::string SomeDerived::AsFortran() const { std::stringstream out; - DerivedTypeSpecAsFortran(out, spec()); + DerivedTypeSpecAsFortran(out << "TYPE(", spec()) << ')'; return out.str(); } } diff --git a/flang/test/semantics/CMakeLists.txt b/flang/test/semantics/CMakeLists.txt index 2df6257..74eda1e 100644 --- a/flang/test/semantics/CMakeLists.txt +++ b/flang/test/semantics/CMakeLists.txt @@ -117,6 +117,7 @@ set(MODFILE_TESTS modfile19.f90 modfile20.f90 modfile21.f90 + modfile22.f90 ) set(LABEL_TESTS