[flang-commits] [PATCH] D142772: [flang] Don't fold STORAGE_SIZE() on polymorphic argument

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 10:00:11 PST 2023


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

More generally, don't return a successful result from
Fortran::evaluate::DynamicType::MeasureSizeInBytes() when the
type is polymorphic.


https://reviews.llvm.org/D142772

Files:
  flang/lib/Evaluate/type.cpp
  flang/test/Evaluate/errors01.f90


Index: flang/test/Evaluate/errors01.f90
===================================================================
--- flang/test/Evaluate/errors01.f90
+++ flang/test/Evaluate/errors01.f90
@@ -2,6 +2,9 @@
 ! Check errors found in folding
 ! TODO: test others emitted from flang/lib/Evaluate
 module m
+  type t
+    real x
+  end type t
  contains
   subroutine s1(a,b)
     real :: a(*), b(:)
@@ -100,6 +103,14 @@
     !CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3
     integer, parameter :: bad3 = spread(matrix, 4, 1)
   end subroutine
+  subroutine s12(x,y)
+    class(t), intent(in) :: x
+    class(*), intent(in) :: y
+    !CHERK: error: Must be a constant value
+    integer, parameter :: bad1 = storage_size(x)
+    !CHERK: error: Must be a constant value
+    integer, parameter :: bad2 = storage_size(y)
+  end subroutine
   subroutine warnings
     real, parameter :: ok1 = scale(0.0, 99999) ! 0.0
     real, parameter :: ok2 = scale(1.0, -99999) ! 0.0
Index: flang/lib/Evaluate/type.cpp
===================================================================
--- flang/lib/Evaluate/type.cpp
+++ flang/lib/Evaluate/type.cpp
@@ -157,7 +157,7 @@
     }
     break;
   case TypeCategory::Derived:
-    if (derived_ && derived_->scope()) {
+    if (!IsPolymorphic() && derived_ && derived_->scope()) {
       auto size{derived_->scope()->size()};
       auto align{aligned ? derived_->scope()->alignment().value_or(0) : 0};
       auto alignedSize{align > 0 ? ((size + align - 1) / align) * align : size};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142772.492833.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/a3a71e1f/attachment.bin>


More information about the flang-commits mailing list