[PATCH] D85908: [flang] Fix assert on character literal substrings as arguments

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 08:10:40 PDT 2020


PeteSteinfeld created this revision.
PeteSteinfeld added a reviewer: klausler.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld requested review of this revision.

Character literal substrings used as arguments were causing asserts.  This
happened when the code was trying to get the DynamicType of the substring.  We
were only recording the DynamicType of the Designator on which the substring
was based.  For character literal substrings, the Designator was a character
literal, and we weren't handling getting its type.

I fixed this by changing the `GetType()` method for `DynamicType` to check to
see if we were getting the type of a `Substring` and calculating the type of
the substring by getting the number of bytes in an element of the string.

I also changed the test `resolve49.f90` with some tests, one of which causes
the original crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85908

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


Index: flang/test/Semantics/resolve49.f90
===================================================================
--- flang/test/Semantics/resolve49.f90
+++ flang/test/Semantics/resolve49.f90
@@ -11,6 +11,10 @@
 
 ! Test substring
 program p2
+  type t1(n1,n2)
+    integer,kind :: n1,n2
+    integer :: c2(iachar('ABCDEFGHIJ'(n1:n1)))
+  end type
   character :: a(10)
   character :: b(5)
   integer :: n
@@ -21,6 +25,7 @@
   a(n:7) = b
   a(n+3:) = b
   a(:n+2) = b
+  n = iachar(1_'ABCDEFGHIJ'(1:1))
 end
 
 ! Test pointer assignment with bounds
Index: flang/lib/Evaluate/variable.cpp
===================================================================
--- flang/lib/Evaluate/variable.cpp
+++ flang/lib/Evaluate/variable.cpp
@@ -562,10 +562,17 @@
 template <typename T>
 std::optional<DynamicType> Designator<T>::GetType() const {
   if constexpr (IsLengthlessIntrinsicType<Result>) {
-    return {Result::GetType()};
-  } else {
-    return DynamicType::From(GetLastSymbol());
+    return Result::GetType();
+  } else if (const Symbol * symbol{GetLastSymbol()}) {
+    return DynamicType::From(*symbol);
+  } else if constexpr (Result::category == TypeCategory::Character) {
+    if (const Substring * substring{std::get_if<Substring>(&u)}) {
+      const auto *parent{substring->GetParentIf<StaticDataObject::Pointer>()};
+      CHECK(parent);
+      return DynamicType{TypeCategory::Character, (*parent)->itemBytes()};
+    }
   }
+  return std::nullopt;
 }
 
 static NamedEntity AsNamedEntity(const SymbolVector &x) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85908.285375.patch
Type: text/x-patch
Size: 1522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200813/2d56ac35/attachment.bin>


More information about the llvm-commits mailing list