}
}
if (auto dyType{DynamicType::From(ultimate)}) {
- if (auto len{dyType->GetCharLength()}) {
+ auto len{dyType->GetCharLength()};
+ if (!len && ultimate.attrs().test(semantics::Attr::PARAMETER)) {
+ // Its initializer determines the length of an implied-length named
+ // constant.
+ if (const auto *object{
+ ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
+ if (object->init()) {
+ if (auto dyType2{DynamicType::From(*object->init())}) {
+ len = dyType2->GetCharLength();
+ }
+ }
+ }
+ }
+ if (len) {
if (auto constLen{ToInt64(*len)}) {
return Expr<SubscriptInteger>{std::max<std::int64_t>(*constLen, 0)};
} else if (ultimate.owner().IsDerivedType() ||
logical, parameter :: test_05b = len(ca(:)(2:4)) == 3
logical, parameter :: test_06a = ca(1)(1:2)//ca(2)(2:3)//ca(3)(3:4) == "abfgkl"
logical, parameter :: test_06b = len(ca(1)(1:2)//ca(2)(2:3)//ca(3)(3:4)) == 6
+ logical, parameter :: test_07a = ca(1)(:2) == "ab"
+ logical, parameter :: test_07b = ca(1)(3:) == "cd"
+ logical, parameter :: test_07c = ca(1)(:-1) == ""
+ logical, parameter :: test_07d = ca(1)(5:) == ""
+ logical, parameter :: test_07e = ca(1)(:) == "abcd"
end module
subroutine assumed_length_param(n)
character(*), parameter :: c(1)=(/"abcd"/)
integer :: n
- ! CHECK: %[[c4:.*]] = arith.constant 4 : index
- ! CHECK: %[[len:.*]] = fir.convert %[[c4]] : (index) -> i64
- ! CHECK: fir.store %[[len]] to %[[tmp:.*]] : !fir.ref<i64>
+ ! CHECK: %[[c4:.*]] = arith.constant 4 : i64
+ ! CHECK: fir.store %[[c4]] to %[[tmp:.*]] : !fir.ref<i64>
! CHECK: fir.call @_QPtake_int(%[[tmp]]) {{.*}}: (!fir.ref<i64>) -> ()
call take_int(len(c(n), kind=8))
end