[flang-commits] [flang] 19d7cc2 - [flang] Fix assert on character literal substrings as arguments

Peter Steinfeld via flang-commits flang-commits at lists.llvm.org
Thu Aug 13 09:09:26 PDT 2020


Author: Peter Steinfeld
Date: 2020-08-13T09:09:05-07:00
New Revision: 19d7cc2e83061050923057abf72ab860bdc0a3b5

URL: https://github.com/llvm/llvm-project/commit/19d7cc2e83061050923057abf72ab860bdc0a3b5
DIFF: https://github.com/llvm/llvm-project/commit/19d7cc2e83061050923057abf72ab860bdc0a3b5.diff

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

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.

Differential Revision: https://reviews.llvm.org/D85908

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/variable.cpp b/flang/lib/Evaluate/variable.cpp
index 8c9bd18285af..cfde6ffb6fd1 100644
--- a/flang/lib/Evaluate/variable.cpp
+++ b/flang/lib/Evaluate/variable.cpp
@@ -562,10 +562,17 @@ template <typename T> const Symbol *Designator<T>::GetLastSymbol() const {
 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) {

diff  --git a/flang/test/Semantics/resolve49.f90 b/flang/test/Semantics/resolve49.f90
index 893d13d1acd5..b0bca059c041 100644
--- a/flang/test/Semantics/resolve49.f90
+++ b/flang/test/Semantics/resolve49.f90
@@ -11,6 +11,10 @@ program p1
 
 ! 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 @@ program p2
   a(n:7) = b
   a(n+3:) = b
   a(:n+2) = b
+  n = iachar(1_'ABCDEFGHIJ'(1:1))
 end
 
 ! Test pointer assignment with bounds


        


More information about the flang-commits mailing list