[flang-commits] [PATCH] D139049: [flang] Enforce restrictions on intrinsic assignment
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Dec 2 15:23:51 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc83d1c655c1: [flang] Enforce restrictions on intrinsic assignment (authored by klausler).
Changed prior to commit:
https://reviews.llvm.org/D139049?vs=479080&id=479760#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139049/new/
https://reviews.llvm.org/D139049
Files:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/assign11.f90
flang/test/Semantics/call28.f90
Index: flang/test/Semantics/call28.f90
===================================================================
--- flang/test/Semantics/call28.f90
+++ flang/test/Semantics/call28.f90
@@ -11,6 +11,7 @@
end subroutine
pure subroutine s2(x)
class(t), intent(in out) :: x
+ !ERROR: Left-hand side of assignment may not be polymorphic unless assignment is to an entire allocatable
!ERROR: Left-hand side of assignment is not definable
!BECAUSE: 'x' is polymorphic in a pure subprogram
x = t()
Index: flang/test/Semantics/assign11.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/assign11.f90
@@ -0,0 +1,12 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! 10.2.1.2p1(1)
+program test
+ class(*), allocatable :: pa
+ class(*), pointer :: pp
+ class(*), allocatable :: pac[:]
+ pa = 1 ! ok
+ !ERROR: Left-hand side of assignment may not be polymorphic unless assignment is to an entire allocatable
+ pp = 1
+ !ERROR: Left-hand side of assignment may not be polymorphic if it is a coarray
+ pac = 1
+end
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -2633,6 +2633,18 @@
if (!procRef) {
analyzer.CheckForNullPointer(
"in a non-pointer intrinsic assignment statement");
+ const Expr<SomeType> &lhs{analyzer.GetExpr(0)};
+ if (auto dyType{lhs.GetType()};
+ dyType && dyType->IsPolymorphic()) { // 10.2.1.2p1(1)
+ const Symbol *lastWhole0{UnwrapWholeSymbolOrComponentDataRef(lhs)};
+ const Symbol *lastWhole{
+ lastWhole0 ? &lastWhole0->GetUltimate() : nullptr};
+ if (!lastWhole || !IsAllocatable(*lastWhole)) {
+ Say("Left-hand side of assignment may not be polymorphic unless assignment is to an entire allocatable"_err_en_US);
+ } else if (evaluate::IsCoarray(*lastWhole)) {
+ Say("Left-hand side of assignment may not be polymorphic if it is a coarray"_err_en_US);
+ }
+ }
}
assignment.emplace(analyzer.MoveExpr(0), analyzer.MoveExpr(1));
if (procRef) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139049.479760.patch
Type: text/x-patch
Size: 2253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221202/adfa74a5/attachment-0001.bin>
More information about the flang-commits
mailing list