[flang-commits] [flang] c55bf52 - [flang] Make sure allocatable components are initialzed for temp derived-type
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Sep 2 11:43:48 PDT 2022
Author: Valentin Clement
Date: 2022-09-02T20:43:38+02:00
New Revision: c55bf526356bab67fcd65eafb2ca253c20e0715e
URL: https://github.com/llvm/llvm-project/commit/c55bf526356bab67fcd65eafb2ca253c20e0715e
DIFF: https://github.com/llvm/llvm-project/commit/c55bf526356bab67fcd65eafb2ca253c20e0715e.diff
LOG: [flang] Make sure allocatable components are initialzed for temp derived-type
Runtime functions expect clean unallocated state for descriptor. This
patch adds a call to the runtime function to initialize the temporary
derived-type created.
Reviewed By: vdonaldson
Differential Revision: https://reviews.llvm.org/D133189
Added:
flang/test/Lower/derived-type-temp.f90
Modified:
flang/lib/Lower/ConvertExpr.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index e10a0007a5246..7b3d258bb0b8e 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -34,6 +34,7 @@
#include "flang/Optimizer/Builder/Complex.h"
#include "flang/Optimizer/Builder/Factory.h"
#include "flang/Optimizer/Builder/Runtime/Character.h"
+#include "flang/Optimizer/Builder/Runtime/Derived.h"
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
#include "flang/Optimizer/Builder/Runtime/Ragged.h"
#include "flang/Optimizer/Builder/Todo.h"
@@ -1056,6 +1057,8 @@ class ScalarExprLowering {
auto recTy = ty.cast<fir::RecordType>();
auto fieldTy = fir::FieldType::get(ty.getContext());
mlir::Value res = builder.createTemporary(loc, recTy);
+ mlir::Value box = builder.createBox(loc, fir::ExtendedValue{res});
+ fir::runtime::genDerivedTypeInitialize(builder, loc, box);
for (const auto &value : ctor.values()) {
const Fortran::semantics::Symbol &sym = *value.first;
diff --git a/flang/test/Lower/derived-type-temp.f90 b/flang/test/Lower/derived-type-temp.f90
new file mode 100644
index 0000000000000..8e8d5f35c2877
--- /dev/null
+++ b/flang/test/Lower/derived-type-temp.f90
@@ -0,0 +1,19 @@
+! Test lowering of derived type temporary creation and init
+! RUN: bbc -emit-fir %s -o - | FileCheck %s
+
+program derived_temp_init
+ type t1
+ integer, allocatable :: i
+ end type
+ type t2
+ type(t1) :: c
+ end type
+ type(t1) :: x
+ type(t2) :: y
+ y = t2(x)
+end
+
+! CHECK: %[[temp:.*]] = fir.alloca !fir.type<_QFTt1{i:!fir.box<!fir.heap<i32>>}> {bindc_name = "x", uniq_name = "_QFEx"}
+! CHECK: %[[box:.*]] = fir.embox %[[temp]] : (!fir.ref<!fir.type<_QFTt1{i:!fir.box<!fir.heap<i32>>}>>) -> !fir.box<!fir.type<_QFTt1{i:!fir.box<!fir.heap<i32>>}>>
+! CHECK: %[[box_none:.*]] = fir.convert %[[box]] : (!fir.box<!fir.type<_QFTt1{i:!fir.box<!fir.heap<i32>>}>>) -> !fir.box<none>
+! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[box_none]], %{{.*}}, %{{.*}}) : (!fir.box<none>, !fir.ref<i8>, i32) -> none
More information about the flang-commits
mailing list