[flang-commits] [flang] dbee203 - [flang] Fix emboxing when input type is directly a record type

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Jan 10 08:09:01 PST 2023


Author: Valentin Clement
Date: 2023-01-10T17:08:55+01:00
New Revision: dbee2030a5651d76b543f2b3275489c3e049df05

URL: https://github.com/llvm/llvm-project/commit/dbee2030a5651d76b543f2b3275489c3e049df05
DIFF: https://github.com/llvm/llvm-project/commit/dbee2030a5651d76b543f2b3275489c3e049df05.diff

LOG: [flang] Fix emboxing when input type is directly a record type

In some fir.embox cases as shown in the test, the type descriptor
was not correctly found and the descriptor was populated with a null in the
addendum. This patch fixes this issue.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D141383

Added: 
    

Modified: 
    flang/lib/Optimizer/Dialect/FIRType.cpp
    flang/test/Fir/polymorphic.fir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 89f757585264f..8c73fc24741f6 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -326,6 +326,7 @@ mlir::Type unwrapInnerType(mlir::Type ty) {
           return seqTy.getEleTy();
         return eleTy;
       })
+      .Case<fir::RecordType>([](auto t) { return t; })
       .Default([](mlir::Type) { return mlir::Type{}; });
 }
 

diff  --git a/flang/test/Fir/polymorphic.fir b/flang/test/Fir/polymorphic.fir
index d85fd6daa1cbd..58b19829e7ec3 100644
--- a/flang/test/Fir/polymorphic.fir
+++ b/flang/test/Fir/polymorphic.fir
@@ -124,3 +124,39 @@ fir.global linkonce @_QQcl.2E2F64756D6D792E66393000 constant : !fir.char<1,12> {
   fir.has_value %0 : !fir.char<1,12>
 }
 
+fir.global linkonce_odr @_QMmod1E.dt.t.2 constant target : !fir.type<_QM__fortran_type_infoTderivedtype{binding:!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QM__fortran_type_infoTbinding{proc:!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>,name:!fir.box<!fir.ptr<!fir.char<1,?>>>}>>>>,name:!fir.box<!fir.ptr<!fir.char<1,?>>>,sizeinbytes:i64,uninstantiated:!fir.box<!fir.ptr<!fir.type<_QM__fortran_type_infoTderivedtype>>>,kindparameter:!fir.box<!fir.ptr<!fir.array<?xi64>>>,lenparameterkind:!fir.box<!fir.ptr<!fir.array<?xi8>>>,component:!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QM__fortran_type_infoTcomponent{name:!fir.box<!fir.ptr<!fir.char<1,?>>>,genre:i8,category:i8,kind:i8,rank:i8,__padding0:!fir.array<4xi8>,offset:i64,characterlen:!fir.type<_QM__fortran_type_infoTvalue{genre:i8,__padding0:!fir.array<7xi8>,value:i64}>,derived:!fir.box<!fir.ptr<!fir.type<_QM__fortran_type_infoTderivedtype>>>,lenvalue:!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QM__fortran_type_infoTvalue{genre:i8,__padding0:!fir.array<7xi8>,value:i64}>>>>,bounds:!fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QM__fortran_type_infoTvalue{genre:i8,__padding0:!fir.array<7xi8>,value:i64}>>>>,initialization:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>>>>,procptr:!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QM__fortran_type_infoTprocptrcomponent{name:!fir.box<!fir.ptr<!fir.char<1,?>>>,offset:i64,initialization:!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>}>>>>,special:!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QM__fortran_type_infoTspecialbinding{which:i8,isargdescriptorset:i8,__padding0:!fir.array<6xi8>,proc:!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>}>>>>,specialbitset:i32,hasparent:i8,noinitializationneeded:i8,nodestructionneeded:i8,nofinalizationneeded:i8,__padding0:!fir.array<4xi8>}> {
+}
+
+fir.global @_QMmod1Ea target : !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}> {
+  %0 = fir.undefined !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>
+  %1 = fir.field_index v, !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>
+  %2 = fir.undefined !fir.array<2xi32>
+  %c17_i32 = arith.constant 17 : i32
+  %3 = fir.insert_value %2, %c17_i32, [0 : index] : (!fir.array<2xi32>, i32) -> !fir.array<2xi32>
+  %c-17_i32 = arith.constant -17 : i32
+  %4 = fir.insert_value %3, %c-17_i32, [1 : index] : (!fir.array<2xi32>, i32) -> !fir.array<2xi32>
+  %c2 = arith.constant 2 : index
+  %5 = fir.insert_value %0, %4, ["v", !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>] : (!fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>, !fir.array<2xi32>) -> !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>
+  fir.has_value %5 : !fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>
+}
+func.func @_QMmod1Psub1(%arg0: !fir.ref<!fir.class<!fir.ptr<none>>> {fir.bindc_name = "target"}) {
+  return
+}
+func.func @_QQmain() {
+  %0 = fir.alloca !fir.class<!fir.ptr<none>>
+  %1 = fir.address_of(@_QMmod1Ea) : !fir.ref<!fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>>
+  %2 = fir.embox %1 : (!fir.ref<!fir.type<_QMmod1TtK2{v:!fir.array<2xi32>}>>) -> !fir.class<!fir.ptr<none>>
+  fir.store %2 to %0 : !fir.ref<!fir.class<!fir.ptr<none>>>
+  fir.call @_QMmod1Psub1(%0) fastmath<contract> : (!fir.ref<!fir.class<!fir.ptr<none>>>) -> ()
+  return
+}
+
+// CHECK-LABEL: define void @_QQmain() {
+// CHECK: %[[CLASS_NONE:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }
+// CHECK: %[[DESC:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, i64 1
+// CHECK: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr @_QMmod1Ea, i64 ptrtoint (ptr getelementptr (%_QMmod1TtK2, ptr null, i32 1) to i64), i32 20180515, i8 0, i8 42, i8 1, i8 1, ptr @_QMmod1E.dt.t.2, [1 x i64] undef }, ptr %[[CLASS_NONE]], align 8
+// CHECK: %[[LOAD:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %[[CLASS_NONE]]
+// CHECK: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } %[[LOAD]], ptr %[[DESC]]
+// CHECK: call void @_QMmod1Psub1(ptr %[[DESC]])
+
+


        


More information about the flang-commits mailing list