[flang] Support lowering of intrinsic module procedure C_F_POINTER
authorPeixin Qiao <qiaopeixin@huawei.com>
Tue, 6 Sep 2022 00:15:01 +0000 (08:15 +0800)
committerPeixin Qiao <qiaopeixin@huawei.com>
Tue, 6 Sep 2022 00:15:01 +0000 (08:15 +0800)
commit109f9a291850a8e82f5026f68a382222a235c4f3
tree23fcd2ac8ebb0aee8876d4cc9c1b0f58d0d1d60d
parent7e3aa8f01a31bcf9a9cafc79594b3b8b950532f2
[flang] Support lowering of intrinsic module procedure C_F_POINTER

As Fortran 2018 18.2.3.3, the intrinsic module procedure
C_F_POINTER(CPTR, FPTR [, SHAPE]) associates a data pointer with the
target of a C pointer and specify its shape. CPTR shall be a scalar of
type C_PTR, and its value is the C address or the result of a reference
to C_LOC. FPTR is one pointer, either scalar or array. SHAPE is a
rank-one integer array, and it shall be present if and only if FPTR is
an array.

C_PTR is the derived type with only one component of integer 64, and the
integer 64 component value is the address. Build the right "source"
fir::ExtendedValue based on the address and shape, and use
associateMutableBox to associate the pointer with the target of the C
pointer.

Refactor the getting the address of C_PTR to reuse the code.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D132303
flang/include/flang/Optimizer/Builder/FIRBuilder.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/IntrinsicCall.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/test/Lower/Intrinsics/c_f_pointer.f90 [new file with mode: 0644]
flang/test/Lower/Intrinsics/c_funloc.f90
flang/test/Lower/Intrinsics/c_loc.f90