Skip to content

Commit 057a2c2

Browse files
committed
[flang] Don't fold STORAGE_SIZE() on polymorphic argument
More generally, don't return a successful result from Fortran::evaluate::DynamicType::MeasureSizeInBytes() when the type is polymorphic. Differential Revision: https://reviews.llvm.org/D142772
1 parent 5274a46 commit 057a2c2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

flang/lib/Evaluate/type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ std::optional<Expr<SubscriptInteger>> DynamicType::MeasureSizeInBytes(
157157
}
158158
break;
159159
case TypeCategory::Derived:
160-
if (derived_ && derived_->scope()) {
160+
if (!IsPolymorphic() && derived_ && derived_->scope()) {
161161
auto size{derived_->scope()->size()};
162162
auto align{aligned ? derived_->scope()->alignment().value_or(0) : 0};
163163
auto alignedSize{align > 0 ? ((size + align - 1) / align) * align : size};

flang/test/Evaluate/errors01.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
! Check errors found in folding
33
! TODO: test others emitted from flang/lib/Evaluate
44
module m
5+
type t
6+
real x
7+
end type t
58
contains
69
subroutine s1(a,b)
710
real :: a(*), b(:)
@@ -100,6 +103,14 @@ subroutine s9
100103
!CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3
101104
integer, parameter :: bad3 = spread(matrix, 4, 1)
102105
end subroutine
106+
subroutine s12(x,y)
107+
class(t), intent(in) :: x
108+
class(*), intent(in) :: y
109+
!CHERK: error: Must be a constant value
110+
integer, parameter :: bad1 = storage_size(x)
111+
!CHERK: error: Must be a constant value
112+
integer, parameter :: bad2 = storage_size(y)
113+
end subroutine
103114
subroutine warnings
104115
real, parameter :: ok1 = scale(0.0, 99999) ! 0.0
105116
real, parameter :: ok2 = scale(1.0, -99999) ! 0.0

0 commit comments

Comments
 (0)