Skip to content

[flang] Silence bogus error message #111057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged

[flang] Silence bogus error message #111057

merged 1 commit into from
Oct 7, 2024

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Oct 3, 2024

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 #111021.

@klausler klausler requested a review from kkwli October 3, 2024 20:21
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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 #111021.


Full diff: https://github.com/llvm/llvm-project/pull/111057.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/tools.cpp (+4-1)
  • (modified) flang/test/Semantics/io14.f90 (+5-6)
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 3723b28fecef52..714417850cefa5 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -1649,7 +1649,10 @@ bool HasDefinedIo(common::DefinedIo which, const DerivedTypeSpec &derived,
       }
     }
   }
-  return false;
+  // Check for inherited defined I/O
+  const auto *parentType{derived.typeSymbol().GetParentTypeSpec()};
+  return parentType && HasDefinedIo(which, *parentType, scope);
+  ;
 }
 
 void WarnOnDeferredLengthCharacterScalar(SemanticsContext &context,
diff --git a/flang/test/Semantics/io14.f90 b/flang/test/Semantics/io14.f90
index 6dd6763bc944b9..39f91f5bd2752b 100644
--- a/flang/test/Semantics/io14.f90
+++ b/flang/test/Semantics/io14.f90
@@ -9,6 +9,8 @@ module m
     procedure :: fwrite
     generic :: write(formatted) => fwrite
   end type
+  type, extends(t) :: t2
+  end type
  contains
   subroutine fwrite(x, unit, iotype, vlist, iostat, iomsg)
     class(t), intent(in) :: x
@@ -19,19 +21,16 @@ subroutine fwrite(x, unit, iotype, vlist, iostat, iomsg)
     character(*), intent(in out) :: iomsg
     write(unit, *, iostat=iostat, iomsg=iomsg) '(', iotype, ':', vlist, ':', x%n, ')'
   end subroutine
-  subroutine subr(x, y, z)
+  subroutine subr(x, y, z, w)
     class(t), intent(in) :: x
     class(base), intent(in) :: y
     class(*), intent(in) :: z
+    class(t2), intent(in) :: w
     print *, x ! ok
+    print *, w ! ok
     !ERROR: Derived type 'base' in I/O may not be polymorphic unless using defined I/O
     print *, y
     !ERROR: I/O list item may not be unlimited polymorphic
     print *, z
   end subroutine
 end
-
-program main
-  use m
-  call subr(t(123),t(234),t(345))
-end

Copy link
Collaborator

@kkwli kkwli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Thanks for the quick fix.

// Check for inherited defined I/O
const auto *parentType{derived.typeSymbol().GetParentTypeSpec()};
return parentType && HasDefinedIo(which, *parentType, scope);
;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this statement is not necessary.

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.
@klausler klausler merged commit 49016d5 into llvm:main Oct 7, 2024
8 checks passed
@klausler klausler deleted the bug111021 branch October 7, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] incorrect diagnostic of type-bound-generic-stmt in defined I/O
3 participants