From 9d395e79a6ae87c5dead62ed37c0a46a1f0a7e9e Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 22 Nov 2022 14:47:05 +0100 Subject: [PATCH] [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 --- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 5 +++++ flang/test/Fir/polymorphic.fir | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 flang/test/Fir/polymorphic.fir diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index dd3cc38..8864a29 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -1414,6 +1414,11 @@ struct EmboxCommonConversion : public FIROpConversion { 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()) + return {rewriter.create(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 0000000..4b9e24d --- /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> {bindc_name = "u", uniq_name = "_QMpolymorphic_testFtest_allocate_unlimited_polymorphic_non_derivedEu"} + %1 = fir.zero_bits !fir.ptr + %2 = fir.embox %1 : (!fir.ptr) -> !fir.class> + fir.store %2 to %0 : !fir.ref>> + 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: } -- 2.7.4