[flang-commits] [flang] 9d395e7 - [flang] Set initial size and type code for unlimited polymorphic descriptor
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Nov 22 05:48:48 PST 2022
Author: Valentin Clement
Date: 2022-11-22T14:48:34+01:00
New Revision: 9d395e79a6ae87c5dead62ed37c0a46a1f0a7e9e
URL: https://github.com/llvm/llvm-project/commit/9d395e79a6ae87c5dead62ed37c0a46a1f0a7e9e
DIFF: https://github.com/llvm/llvm-project/commit/9d395e79a6ae87c5dead62ed37c0a46a1f0a7e9e.diff
LOG: [flang] Set initial size and type code for unlimited polymorphic descriptor
Initialization of unlimited polymorphic descriptor was raising an error.
This patch sets a default size and type code for unlimited polymoprhic descriptor
that will be updated once allocated/assigned.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D138479
Added:
flang/test/Fir/polymorphic.fir
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index dd3cc38159d69..8864a297c4723 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1414,6 +1414,11 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
mlir::Value size = genTypeStrideInBytes(loc, i64Ty, rewriter, ptrTy);
return {size, this->genConstantOffset(loc, rewriter, CFI_type_cptr)};
}
+ // Unlimited polymorphic or assumed type. Use 0 and CFI_type_other since the
+ // information is not none at this point.
+ if (boxEleTy.isa<mlir::NoneType>())
+ return {rewriter.create<mlir::LLVM::ConstantOp>(loc, i64Ty, 0),
+ this->genConstantOffset(loc, rewriter, CFI_type_other)};
fir::emitFatalError(loc, "unhandled type in fir.box code generation");
}
diff --git a/flang/test/Fir/polymorphic.fir b/flang/test/Fir/polymorphic.fir
new file mode 100644
index 0000000000000..4b9e24dac6242
--- /dev/null
+++ b/flang/test/Fir/polymorphic.fir
@@ -0,0 +1,20 @@
+// RUN: tco %s | FileCheck %s
+
+// Test code gen for unlimited polymorphic type descriptor.
+
+func.func @_QMpolymorphic_testPtest_allocate_unlimited_polymorphic_non_derived() {
+ %0 = fir.alloca !fir.class<!fir.ptr<none>> {bindc_name = "u", uniq_name = "_QMpolymorphic_testFtest_allocate_unlimited_polymorphic_non_derivedEu"}
+ %1 = fir.zero_bits !fir.ptr<none>
+ %2 = fir.embox %1 : (!fir.ptr<none>) -> !fir.class<!fir.ptr<none>>
+ fir.store %2 to %0 : !fir.ref<!fir.class<!fir.ptr<none>>>
+ return
+}
+
+// CHECK-LABEL: define void @_QMpolymorphic_testPtest_allocate_unlimited_polymorphic_non_derived() {
+// CHECK: %[[MEM:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }
+// CHECK: %[[DESC:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1
+// CHECK: store { ptr, i64, i32, i8, i8, i8, i8 } { ptr null, i64 0, i32 20180515, i8 0, i8 -1, i8 1, i8 0 }, ptr %[[MEM]]
+// CHECK: %[[LOADED:.*]] = load { ptr, i64, i32, i8, i8, i8, i8 }, ptr %[[MEM]], align 8
+// CHECK: store { ptr, i64, i32, i8, i8, i8, i8 } %[[LOADED]], ptr %[[DESC]]
+// CHECK: ret void
+// CHECK: }
More information about the flang-commits
mailing list