[PATCH] D80593: [flang] Fixed crash on forward referenced `len` parameter

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 16:29:04 PDT 2020


PeteSteinfeld updated this revision to Diff 268015.
PeteSteinfeld added a comment.



1. Updating D80593 <https://reviews.llvm.org/D80593>: [flang] Fixed crash on forward referenced `len` parameter #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

It turned out that the root cause of the crash was that the length of the type
of the symbol being passed to `SymbolLEN()` had a bad expression.  So I fixed
it by checking `isExplicit()` on the `ParamValue` before calling 
`GetExplicit()`.  The case where `isExplicit()` returned true and
`GetExplicit()` failed to get an expression indicates a prior error, so I just
returned `std::nullopt` from `SymbolLEN()` and avoided the call to the
constructor of `DescriptorInquiry`.

I restored the calls to variable.cpp to `CHECK(IsDescriptor(last))`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80593/new/

https://reviews.llvm.org/D80593

Files:
  flang/lib/Evaluate/variable.cpp
  flang/test/Semantics/resolve91.f90


Index: flang/test/Semantics/resolve91.f90
===================================================================
--- flang/test/Semantics/resolve91.f90
+++ flang/test/Semantics/resolve91.f90
@@ -44,3 +44,10 @@
     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
Index: flang/lib/Evaluate/variable.cpp
===================================================================
--- flang/lib/Evaluate/variable.cpp
+++ flang/lib/Evaluate/variable.cpp
@@ -257,8 +257,14 @@
 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}};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80593.268015.patch
Type: text/x-patch
Size: 1515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/3aa6068d/attachment.bin>


More information about the llvm-commits mailing list