diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -1414,6 +1414,11 @@ 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 --- /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: }