[flang-commits] [PATCH] D142752: [flang] Catch obscure error in defined assignment

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 09:30:42 PST 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D142752

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


Index: flang/test/Semantics/resolve65.f90
===================================================================
--- flang/test/Semantics/resolve65.f90
+++ flang/test/Semantics/resolve65.f90
@@ -65,6 +65,18 @@
         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
 
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -1565,6 +1565,12 @@
         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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142752.492807.patch
Type: text/x-patch
Size: 1605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/dd6a3930/attachment-0001.bin>


More information about the flang-commits mailing list