[flang-commits] [flang] fedf4dc - [flang] Do not propagate type desc when box type is not polymorphic
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Nov 22 00:41:57 PST 2022
Author: Valentin Clement
Date: 2022-11-22T09:41:50+01:00
New Revision: fedf4dcd808b0e20113e06a09d36c1c0cd56091d
URL: https://github.com/llvm/llvm-project/commit/fedf4dcd808b0e20113e06a09d36c1c0cd56091d
DIFF: https://github.com/llvm/llvm-project/commit/fedf4dcd808b0e20113e06a09d36c1c0cd56091d.diff
LOG: [flang] Do not propagate type desc when box type is not polymorphic
When the rhs is non-polymorphic the type descriptor should not
be propagated. An error in the EmboxOp verifier was raised in that case.
This patch propagate the type descriptor only if the result type of the
EmboxOp operation is polymorphic.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D138442
Added:
Modified:
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index f40953edb344e..920b4de96740b 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -504,7 +504,8 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
mlir::ValueRange emptyRange;
mlir::Value s = createShape(loc, exv);
return create<fir::EmboxOp>(loc, boxTy, itemAddr, s, /*slice=*/empty,
- /*typeparams=*/emptyRange, box.getTdesc());
+ /*typeparams=*/emptyRange,
+ isPolymorphic ? box.getTdesc() : tdesc);
},
[&](const fir::CharArrayBoxValue &box) -> mlir::Value {
mlir::Value s = createShape(loc, exv);
@@ -532,7 +533,8 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
mlir::Value empty;
mlir::ValueRange emptyRange;
return create<fir::EmboxOp>(loc, boxTy, itemAddr, empty, empty,
- emptyRange, p.getTdesc());
+ emptyRange,
+ isPolymorphic ? p.getTdesc() : tdesc);
},
[&](const auto &) -> mlir::Value {
mlir::Value empty;
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 469cefa06bf33..dadde2c5eac89 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -90,4 +90,13 @@ subroutine implicit_loop_with_polymorphic()
! CHECK: }
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %{{.*}}[%{{.*}}] : !fir.array<?xi32>, !fir.array<?xi32>, !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.slice<1>
+ subroutine polymorphic_to_nonpolymorphic(p)
+ class(p1), pointer :: p(:)
+ type(p1), allocatable, target :: t(:)
+ t = p
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPpolymorphic_to_nonpolymorphic
+! Just checking that FIR is generated without error.
+
end module
More information about the flang-commits
mailing list