Skip to content

Commit b0fab14

Browse files
authored
[flang] Fix spurious error in character sequence association (#124204)
When an allocatable or pointer was being associated as a storage sequence with a dummy argument, the checks were using the actual storage size of the allocatable or pointer's descriptor, not the size of the storage that it references. Fixes #123807.
1 parent c596aae commit b0fab14

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ static void CheckCharacterActual(evaluate::Expr<evaluate::SomeType> &actual,
163163
context.foldingContext(), /*getLastComponent=*/true};
164164
if (auto actualOffset{folder.FoldDesignator(actual)}) {
165165
std::int64_t actualChars{*actualLength};
166-
if (static_cast<std::size_t>(actualOffset->offset()) >=
166+
if (IsAllocatableOrPointer(actualOffset->symbol())) {
167+
// don't use actualOffset->symbol().size()!
168+
} else if (static_cast<std::size_t>(actualOffset->offset()) >=
167169
actualOffset->symbol().size() ||
168170
!evaluate::IsContiguous(
169171
actualOffset->symbol(), foldingContext)) {
@@ -630,7 +632,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
630632
context.foldingContext(), /*getLastComponent=*/true};
631633
if (auto actualOffset{folder.FoldDesignator(actual)}) {
632634
std::optional<std::int64_t> actualElements;
633-
if (static_cast<std::size_t>(actualOffset->offset()) >=
635+
if (IsAllocatableOrPointer(actualOffset->symbol())) {
636+
// don't use actualOffset->symbol().size()!
637+
} else if (static_cast<std::size_t>(actualOffset->offset()) >=
634638
actualOffset->symbol().size() ||
635639
!evaluate::IsContiguous(
636640
actualOffset->symbol(), foldingContext)) {

flang/test/Semantics/call38.f90

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,39 @@ subroutine sub2(arg2)
544544
character(*) :: arg2(10)
545545
end subroutine sub2
546546
end subroutine
547+
548+
subroutine bug123807
549+
interface
550+
subroutine test(s)
551+
character(5), intent(inout) :: s(5)
552+
end
553+
end interface
554+
character(30) :: s30a
555+
character(30), allocatable :: s30b
556+
character(6) :: s30c(5)
557+
character(24) :: s24a
558+
character(24), allocatable :: s24b
559+
character(4) :: s24c(6)
560+
allocate(s30b)
561+
allocate(s24b)
562+
call test(s30a)
563+
call test(s30a(6:))
564+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
565+
call test(s30a(7:))
566+
call test(s30b)
567+
call test(s30b(6:))
568+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
569+
call test(s30b(7:))
570+
call test(s30c)
571+
call test(s30c(1)(6:))
572+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
573+
call test(s30c(2))
574+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
575+
call test(s30c(2)(1:))
576+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
577+
call test(s24a)
578+
!ERROR: Actual argument has fewer characters remaining in storage sequence (24) than dummy argument 's=' (25)
579+
call test(s24b)
580+
!ERROR: Actual argument array has fewer characters (24) than dummy argument 's=' array (25)
581+
call test(s24c)
582+
end

0 commit comments

Comments
 (0)