mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 15:41:46 +00:00
[flang] Add runtime default initialization for polymorphic intent(out) dummy
This patch adds runtime default initialization for polymorphic dummy argument. The dynamic type might require default initialization but not the declared type. Reviewed By: jeanPerier, PeteSteinfeld Differential Revision: https://reviews.llvm.org/D141278
This commit is contained in:
parent
747211b712
commit
fdc3dd70c7
@ -625,6 +625,11 @@ mustBeDefaultInitializedAtRuntime(const Fortran::lower::pft::Variable &var) {
|
||||
return false;
|
||||
if (Fortran::semantics::IsDummy(sym) && !Fortran::semantics::IsIntentOut(sym))
|
||||
return false;
|
||||
// Polymorphic intent(out) dummy might need default initialization
|
||||
// at runtime.
|
||||
if (Fortran::semantics::IsPolymorphic(sym) &&
|
||||
Fortran::semantics::IsDummy(sym) && Fortran::semantics::IsIntentOut(sym))
|
||||
return true;
|
||||
// Local variables (including function results), and intent(out) dummies must
|
||||
// be default initialized at runtime if their type has default initialization.
|
||||
return hasDefaultInitialization(sym);
|
||||
|
@ -23,7 +23,7 @@ module polymorphic_test
|
||||
end type
|
||||
|
||||
type, extends(p1) :: p2
|
||||
real :: c
|
||||
real :: c = 10.5
|
||||
end type
|
||||
|
||||
type r1
|
||||
@ -738,6 +738,24 @@ module polymorphic_test
|
||||
! CHECK: %[[RES:.*]] = fir.call @_QMpolymorphic_testPunlimited_polymorphic_alloc_array_ret() fastmath<contract> : () -> !fir.class<!fir.heap<!fir.array<?xnone>>>
|
||||
! CHECK: fir.save_result %[[RES]] to %[[RES_TMP]] : !fir.class<!fir.heap<!fir.array<?xnone>>>, !fir.ref<!fir.class<!fir.heap<!fir.array<?xnone>>>>
|
||||
|
||||
subroutine test_unlimited_polymorphic_intentout(a)
|
||||
class(*), intent(out) :: a
|
||||
end subroutine
|
||||
|
||||
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_unlimited_polymorphic_intentout(
|
||||
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<none> {fir.bindc_name = "a"}) {
|
||||
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<none>) -> !fir.box<none>
|
||||
! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.ref<i8>, i32) -> none
|
||||
|
||||
subroutine test_polymorphic_intentout(a)
|
||||
class(p1), intent(out) :: a
|
||||
end subroutine
|
||||
|
||||
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_polymorphic_intentout(
|
||||
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) {
|
||||
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none>
|
||||
! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.ref<i8>, i32) -> none
|
||||
|
||||
end module
|
||||
|
||||
program test
|
||||
|
Loading…
Reference in New Issue
Block a user