Skip to content

Commit 49016d5

Browse files
authored
[flang] Silence bogus error message (llvm#111057)
Fortran doesn't permit the use of a polymorphic I/O list item for intrinsic data transfers, so the compiler emits an error message for polymorphic items whose types can't possibly be handled by a defined I/O subroutine. This check didn't allow for the possibility that the defined I/O subroutine might apply to the parent component of an extended type. Fixes llvm#111021.
1 parent ce5edfd commit 49016d5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

flang/lib/Semantics/tools.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,9 @@ bool HasDefinedIo(common::DefinedIo which, const DerivedTypeSpec &derived,
16491649
}
16501650
}
16511651
}
1652-
return false;
1652+
// Check for inherited defined I/O
1653+
const auto *parentType{derived.typeSymbol().GetParentTypeSpec()};
1654+
return parentType && HasDefinedIo(which, *parentType, scope);
16531655
}
16541656

16551657
void WarnOnDeferredLengthCharacterScalar(SemanticsContext &context,

flang/test/Semantics/io14.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module m
99
procedure :: fwrite
1010
generic :: write(formatted) => fwrite
1111
end type
12+
type, extends(t) :: t2
13+
end type
1214
contains
1315
subroutine fwrite(x, unit, iotype, vlist, iostat, iomsg)
1416
class(t), intent(in) :: x
@@ -19,19 +21,16 @@ subroutine fwrite(x, unit, iotype, vlist, iostat, iomsg)
1921
character(*), intent(in out) :: iomsg
2022
write(unit, *, iostat=iostat, iomsg=iomsg) '(', iotype, ':', vlist, ':', x%n, ')'
2123
end subroutine
22-
subroutine subr(x, y, z)
24+
subroutine subr(x, y, z, w)
2325
class(t), intent(in) :: x
2426
class(base), intent(in) :: y
2527
class(*), intent(in) :: z
28+
class(t2), intent(in) :: w
2629
print *, x ! ok
30+
print *, w ! ok
2731
!ERROR: Derived type 'base' in I/O may not be polymorphic unless using defined I/O
2832
print *, y
2933
!ERROR: I/O list item may not be unlimited polymorphic
3034
print *, z
3135
end subroutine
3236
end
33-
34-
program main
35-
use m
36-
call subr(t(123),t(234),t(345))
37-
end

0 commit comments

Comments
 (0)