[flang-commits] [flang] 54912dd - [flang] Catch obscure error in defined assignment

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 13:41:52 PST 2023


Author: Peter Klausler
Date: 2023-01-27T13:41:39-08:00
New Revision: 54912dd2fbbd2e212099da94bb3aaf1bbae642c3

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

LOG: [flang] Catch obscure error in defined assignment

A subroutine that implements a defined assignment cannot have
a dummy argument for its second operand (the RHS of the assignment)
with the POINTER or ALLOCATABLE attributes, since the RHS of
an assignment is always an expression.  This problem is flagged
as a fatal error in other compilers, so let's make it fatal here
as well.

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

Added: 
    

Modified: 
    flang/lib/Semantics/check-declarations.cpp
    flang/test/Semantics/resolve65.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index d9c13df031ca2..6746d47a9b02f 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1565,6 +1565,12 @@ bool CheckHelper::CheckDefinedAssignmentArg(
         msg =
             "In defined assignment subroutine '%s', second dummy"
             " argument '%s' must have INTENT(IN) or VALUE attribute"_err_en_US;
+      } else if (dataObject->attrs.test(DummyDataObject::Attr::Pointer)) {
+        msg =
+            "In defined assignment subroutine '%s', second dummy argument '%s' must not be a pointer"_err_en_US;
+      } else if (dataObject->attrs.test(DummyDataObject::Attr::Allocatable)) {
+        msg =
+            "In defined assignment subroutine '%s', second dummy argument '%s' must not be an allocatable"_err_en_US;
       }
     } else {
       DIE("pos must be 0 or 1");

diff  --git a/flang/test/Semantics/resolve65.f90 b/flang/test/Semantics/resolve65.f90
index d1fb26ddaaecd..f4a8d6b9e41f3 100644
--- a/flang/test/Semantics/resolve65.f90
+++ b/flang/test/Semantics/resolve65.f90
@@ -65,6 +65,18 @@ subroutine y()
         end
       end interface
     end
+    !ERROR: In defined assignment subroutine 's3', second dummy argument 'y' must not be a pointer
+    subroutine s3(x, y)
+      import t
+      type(t), intent(out) :: x
+      type(t), intent(in), pointer :: y
+    end
+    !ERROR: In defined assignment subroutine 's4', second dummy argument 'y' must not be an allocatable
+    subroutine s4(x, y)
+      import t
+      type(t), intent(out) :: x
+      type(t), intent(in), allocatable :: y
+    end
   end interface
 end
 


        


More information about the flang-commits mailing list