[flang-commits] [PATCH] D144952: [flang][hlfir] Support type bound procedure in type descriptors

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Feb 28 05:12:17 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa98b031e4f38: [flang][hlfir] Support type bound procedure in type descriptors (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144952/new/

https://reviews.llvm.org/D144952

Files:
  flang/lib/Lower/ConvertConstant.cpp
  flang/test/Lower/HLFIR/type-bound-proc-tdesc.f90


Index: flang/test/Lower/HLFIR/type-bound-proc-tdesc.f90
===================================================================
--- /dev/null
+++ flang/test/Lower/HLFIR/type-bound-proc-tdesc.f90
@@ -0,0 +1,31 @@
+! Test lowering of type bound procedure in the derived type descriptors (that
+! are compiler generated constant structure constructors).
+! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
+
+module type_bound_proc_tdesc
+  type :: t
+  contains
+    procedure, nopass :: simple => simple_impl
+    procedure, nopass :: return_char => return_char_impl
+  end type
+
+interface
+  function return_char_impl()
+    character(10) :: return_char_impl
+  end function
+  subroutine simple_impl()
+  end subroutine
+end interface
+end
+  use type_bound_proc_tdesc
+  type(t) :: a
+end
+
+! CHECK-LABEL: fir.global {{.*}} @_QMtype_bound_proc_tdescE.v.t
+! CHECK:  fir.address_of(@_QPreturn_char_impl) : (!fir.ref<!fir.char<1,10>>, index) -> !fir.boxchar<1>
+! CHECK:  %[[VAL_8:.*]] = fir.extract_value %{{.*}}, [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>) -> !fir.boxproc<() -> ()>
+! CHECK:  fir.box_addr %[[VAL_8]] : (!fir.boxproc<() -> ()>) -> (() -> ())
+! ...
+! CHECK:  %[[VAL_25:.*]] = fir.address_of(@_QPsimple_impl) : () -> ()
+! CHECK:  %[[VAL_26:.*]] = fir.emboxproc %[[VAL_25]] : (() -> ()) -> !fir.boxproc<() -> ()>
+! CHECK:  fir.box_addr %[[VAL_26]] : (!fir.boxproc<() -> ()>) -> (() -> ())
Index: flang/lib/Lower/ConvertConstant.cpp
===================================================================
--- flang/lib/Lower/ConvertConstant.cpp
+++ flang/lib/Lower/ConvertConstant.cpp
@@ -374,6 +374,8 @@
         // The Ev::Expr returned is an initializer that is a pointer (e.g.,
         // null) that must be inserted into an intermediate cptr record
         // value's address field, which ought to be an intptr_t on the target.
+        if (addr.getType().isa<fir::BoxProcType>())
+          addr = builder.create<fir::BoxAddrOp>(loc, addr);
         assert((fir::isa_ref_type(addr.getType()) ||
                 addr.getType().isa<mlir::FunctionType>()) &&
                "expect reference type for address field");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144952.501101.patch
Type: text/x-patch
Size: 2146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230228/adb9f548/attachment-0001.bin>


More information about the flang-commits mailing list