From 0a79113b9e064e50f660ebe6e257bf69ba028026 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 20 May 2022 14:21:59 -0700 Subject: [PATCH] [flang] Replace crash and improve a semantics TODO message 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. Differential Revision: https://reviews.llvm.org/D126154 --- flang/lib/Semantics/runtime-type-info.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp index d24b844bd7b5..eae8c0c977a2 100644 --- a/flang/lib/Semantics/runtime-type-info.cpp +++ b/flang/lib/Semantics/runtime-type-info.cpp @@ -103,9 +103,13 @@ private: 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::StructureConstructor RuntimeTableBuilder::DescribeComponent( evaluate::Extremum>(*len)}) { if (clamped->ordering == evaluate::Ordering::Greater && clamped->left() == evaluate::Expr{0}) { - len = clamped->right(); + len = common::Clone(clamped->right()); } } AddValue(values, componentSchema_, "characterlen"s,