[flang-commits] [PATCH] D126154: [flang] Replace crash and improve a semantics TODO message

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Sat May 21 22:19:53 PDT 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

The derived type information table construction code had a
crash whose root cause was replacing an expression with one
of its operands -- the deletion of the LHS of that assignment
led to the RHS being invalidated before it could be read.
Fix by cloning the RHS.  Also update a TODO message to the
new "_todo_en_US" message class and add a comment about how
it should be resolved.


https://reviews.llvm.org/D126154

Files:
  flang/lib/Semantics/runtime-type-info.cpp


Index: flang/lib/Semantics/runtime-type-info.cpp
===================================================================
--- flang/lib/Semantics/runtime-type-info.cpp
+++ flang/lib/Semantics/runtime-type-info.cpp
@@ -103,9 +103,13 @@
               lenParameterEnum_, FindLenParameterIndex(*parameters, *lenParam));
         }
       }
+      // TODO: Replace a specification expression requiring actual operations
+      // with a reference to a new anonymous LEN type parameter whose default
+      // value captures the expression.  This replacement must take place when
+      // the type is declared so that the new LEN type parameters appear in
+      // all instantiations and structure constructors.
       context_.Say(location_,
-          "Specification expression '%s' is neither constant nor a length "
-          "type parameter"_err_en_US,
+          "derived type specification expression '%s' that is neither constant nor a length type parameter"_todo_en_US,
           expr->AsFortran());
     }
     return PackageIntValue(deferredEnum_);
@@ -734,7 +738,7 @@
             evaluate::Extremum<evaluate::SubscriptInteger>>(*len)}) {
       if (clamped->ordering == evaluate::Ordering::Greater &&
           clamped->left() == evaluate::Expr<evaluate::SubscriptInteger>{0}) {
-        len = clamped->right();
+        len = common::Clone(clamped->right());
       }
     }
     AddValue(values, componentSchema_, "characterlen"s,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126154.431211.patch
Type: text/x-patch
Size: 1441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220522/37f5f508/attachment.bin>


More information about the flang-commits mailing list