[flang] Changes to check for constraint C1140
authorPete Steinfeld <psteinfeld@nvidia.com>
Tue, 5 Nov 2019 18:18:33 +0000 (10:18 -0800)
committerPete Steinfeld <psteinfeld@nvidia.com>
Thu, 21 Nov 2019 19:14:51 +0000 (11:14 -0800)
commitfd76cc47c54fad4e29105fca58f00095d5d00788
treec625526df0b6fc7586237711eb2e6fd3c25d6d6d
parent96a6b8c8d0a1fab42fab89dc3eb8498274720e30
[flang] Changes to check for constraint C1140
This constraint prohibits deallocation of polymorphic entities in a DO
CONCURRENT.

Section 9.7.3.2 specifies the situations that might cause deallocation
of a polymorphic entity. The ones that are applicable to a DO CONCURRENT
are exiting from a block that declares such variables, intrinsic
assignment, and an actual DEALLOCATE statement. This section also
specifies (paragraph 8) that deallocation of a derived type causes
deallocation of all of its allocatable subobjects.

Section 10.2.1.3 specifies what happens during intrinsic assignment.
Paragraph 3 states If the variable is an allocated allocatable variable,
it is deallocated if expr is an array of different shape, any
corresponding length type parameter values of the variable and expr
differ, or the variable is polymorphic and the dynamic type or any
corresponding kind type parameter values of the variable and expr
differ." Thus, an allocatable polymorphic variable on the left hand side
of an assignment statement gets deallocated. Paragraph 13 states that
  "For a noncoarray allocatable component the following sequence of
   operations is applied.
      (1) If the component of the variable is allocated, it is deallocated."

Thus, a variable on the left-hand side of an assignment statement might have noncorray allocatable components. Such components will be deallocated.
Deallocation can be caused by exiting from a block where the entity is
declared, from an assignment, and from direct deallocation.

Original-commit: flang-compiler/f18@7d1932d344308d8266503268a7534532cebe6087
Reviewed-on: https://github.com/flang-compiler/f18/pull/814
flang/lib/semantics/check-do.cc
flang/lib/semantics/semantics.h
flang/lib/semantics/tools.cc
flang/test/semantics/CMakeLists.txt
flang/test/semantics/doconcurrent08.f90 [new file with mode: 0644]
flang/test/semantics/dosemantics05.f90