[flang-commits] [flang] eef76f9 - [flang] Reverse a reversed type compatibility check

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon May 9 18:00:29 PDT 2022


Author: Peter Klausler
Date: 2022-05-09T17:55:10-07:00
New Revision: eef76f9821b845b684c9f54d4f3b6d67c0dc2acc

URL: https://github.com/llvm/llvm-project/commit/eef76f9821b845b684c9f54d4f3b6d67c0dc2acc
DIFF: https://github.com/llvm/llvm-project/commit/eef76f9821b845b684c9f54d4f3b6d67c0dc2acc.diff

LOG: [flang] Reverse a reversed type compatibility check

The semantic test for an intrinsic assignment to a polymorphic
derived type entity from a type that is an extension of its base
type was reversed, so it would allow assignments that it shouldn't
and disallowed some that it should; and the test case for it
incorectly assumed that the invalid semantics were correct.
Fix the code and the test, and add a new test for the invalid
case (LHS type is an extension of the RHS type).

Differential Revision: https://reviews.llvm.org/D125135

Added: 
    

Modified: 
    flang/lib/Semantics/tools.cpp
    flang/test/Semantics/selecttype03.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 0b345a66a478..87c842de8842 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -94,7 +94,7 @@ const Scope *FindPureProcedureContaining(const Scope &start) {
 static bool MightBeSameDerivedType(
     const std::optional<evaluate::DynamicType> &lhsType,
     const std::optional<evaluate::DynamicType> &rhsType) {
-  return lhsType && rhsType && rhsType->IsTkCompatibleWith(*lhsType);
+  return lhsType && rhsType && lhsType->IsTkCompatibleWith(*rhsType);
 }
 
 Tristate IsDefinedAssignment(

diff  --git a/flang/test/Semantics/selecttype03.f90 b/flang/test/Semantics/selecttype03.f90
index bfb1bd4535e5..f7070f7bb0d6 100644
--- a/flang/test/Semantics/selecttype03.f90
+++ b/flang/test/Semantics/selecttype03.f90
@@ -110,11 +110,16 @@ function foo(i)
     if (i>0) then
       foo = array1(2,U)
     else if (i<0) then
-      !ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types CLASS(t1) and CLASS(t2)
-      foo = array2(2,U)
+      foo = array2(2,U) ! ok: t2 extends t1
     end if
   end function
 
+  function foo2()
+    class(t2),DIMENSION(:),allocatable :: foo2
+    !ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types CLASS(t2) and CLASS(t1)
+    foo2 = array1(2,:)
+  end function
+
   subroutine sub_with_in_and_inout_param(y, z)
     type(t2), INTENT(IN) :: y
     class(t2), INTENT(INOUT) :: z


        


More information about the flang-commits mailing list