forked from OSchip/llvm-project
[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
This commit is contained in:
parent
e5caa6b5ab
commit
19d7cc2e83
|
@ -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) {
|
||||
|
|
|
@ -11,6 +11,10 @@ end
|
|||
|
||||
! 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
|
||||
|
|
Loading…
Reference in New Issue