[flang-commits] [flang] 1746c8e - [flang] Fixed crash on forward referenced `len` parameter
Pete Steinfeld via flang-commits
flang-commits at lists.llvm.org
Thu Jun 4 13:12:35 PDT 2020
Author: Pete Steinfeld
Date: 2020-06-04T13:12:11-07:00
New Revision: 1746c8ed2660c83895c79de94453f44f8e729a94
URL: https://github.com/llvm/llvm-project/commit/1746c8ed2660c83895c79de94453f44f8e729a94
DIFF: https://github.com/llvm/llvm-project/commit/1746c8ed2660c83895c79de94453f44f8e729a94.diff
LOG: [flang] Fixed crash on forward referenced `len` parameter
Summary:
Using a forward reference to define a `len` parameter causes a crash.
The underlying cause was that a previously declared type had an
erroneous expression for its `LEN` param value. When this expression
was referenced to evaluate a subsequent expression, bad things happened.
I fixed this by putting in code to detect this case.
Reviewers: tskeith, klausler, DavidTruby
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D80593
Added:
Modified:
flang/lib/Evaluate/variable.cpp
flang/test/Semantics/resolve91.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/variable.cpp b/flang/lib/Evaluate/variable.cpp
index c7b261d27e9a..3a6cf560384c 100644
--- a/flang/lib/Evaluate/variable.cpp
+++ b/flang/lib/Evaluate/variable.cpp
@@ -257,8 +257,14 @@ DescriptorInquiry::DescriptorInquiry(NamedEntity &&base, Field field, int dim)
static std::optional<Expr<SubscriptInteger>> SymbolLEN(const Symbol &sym) {
if (auto dyType{DynamicType::From(sym)}) {
if (const semantics::ParamValue * len{dyType->charLength()}) {
- if (auto intExpr{len->GetExplicit()}) {
- return ConvertToType<SubscriptInteger>(*std::move(intExpr));
+ if (len->isExplicit()) {
+ if (auto intExpr{len->GetExplicit()}) {
+ return ConvertToType<SubscriptInteger>(*std::move(intExpr));
+ } else {
+ // There was an error constructing this symbol's type. It should
+ // have a length expression, but we couldn't retrieve it
+ return std::nullopt;
+ }
} else {
return Expr<SubscriptInteger>{
DescriptorInquiry{NamedEntity{sym}, DescriptorInquiry::Field::Len}};
diff --git a/flang/test/Semantics/resolve91.f90 b/flang/test/Semantics/resolve91.f90
index f55ca865cf3c..0a375b873aa4 100644
--- a/flang/test/Semantics/resolve91.f90
+++ b/flang/test/Semantics/resolve91.f90
@@ -44,3 +44,10 @@ module m4
real, dimension(:), pointer :: realArray => localArray
end type
end module m4
+
+module m5
+ !ERROR: Actual argument for 'string=' has bad type 'REAL(4)'
+ character(len=len(a)) :: b
+ !ERROR: The type of 'a' has already been implicitly declared
+ character(len=len(b)) :: a
+end module m5
More information about the flang-commits
mailing list