summaryrefslogtreecommitdiff
path: root/flang/module
diff options
context:
space:
mode:
authorpeter klausler <pklausler@nvidia.com>2020-12-15 11:06:44 -0800
committerpeter klausler <pklausler@nvidia.com>2020-12-15 17:26:20 -0800
commit6aa3591e98402418e110c506cdd488ed1e3021b6 (patch)
tree8b0310ee7dd9b39fe1070227383761d348c7f098 /flang/module
parent0f903015c7746e1c91da742792dd7ee0ae7dd51e (diff)
downloadllvm-6aa3591e98402418e110c506cdd488ed1e3021b6.tar.gz
[flang] Implement STORAGE_SIZE(), SIZEOF(), C_SIZEOF()
STORAGE_SIZE() is a standard inquiry intrinsic (size in bits of an array element of the same type as the argument); SIZEOF() is a common extension that returns the size in bytes of its argument; C_SIZEOF() is a renaming of SIZEOF() in module ISO_C_BINDING. STORAGE_SIZE() and SIZEOF() are implemented via rewrites to expressions; these expressions will be constant when the necessary type parameters and bounds are also constant. Code to calculate the sizes of types (with and without alignment) was isolated into Evaluate/type.* and /characteristics.*. Code in Semantics/compute-offsets.* to calculate sizes and alignments of derived types' scopes was exposed so that it can be called at type instantiation time (earlier than before) so that these inquiry intrinsics could be called from specification expressions. Differential Revision: https://reviews.llvm.org/D93322
Diffstat (limited to 'flang/module')
-rw-r--r--flang/module/__fortran_builtins.f901
-rw-r--r--flang/module/iso_c_binding.f906
2 files changed, 4 insertions, 3 deletions
diff --git a/flang/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90
index bdff2a97954b..167bd80d6ad9 100644
--- a/flang/module/__fortran_builtins.f90
+++ b/flang/module/__fortran_builtins.f90
@@ -16,6 +16,7 @@ module __Fortran_builtins
integer, parameter, private :: int64 = selected_int_kind(18)
intrinsic :: __builtin_c_f_pointer
+ intrinsic :: sizeof ! extension
type :: __builtin_event_type
integer(kind=int64) :: __count
diff --git a/flang/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90
index 52c28e7a031d..eed264f531a4 100644
--- a/flang/module/iso_c_binding.f90
+++ b/flang/module/iso_c_binding.f90
@@ -13,7 +13,8 @@ module iso_c_binding
use __Fortran_builtins, only: &
c_f_pointer => __builtin_c_f_pointer, &
c_ptr => __builtin_c_ptr, &
- c_funptr => __builtin_c_funptr
+ c_funptr => __builtin_c_funptr, &
+ c_sizeof => sizeof
type(c_ptr), parameter :: c_null_ptr = c_ptr(0)
type(c_funptr), parameter :: c_null_funptr = c_funptr(0)
@@ -32,7 +33,7 @@ module iso_c_binding
c_long = c_int64_t, &
c_long_long = c_int64_t, &
c_signed_char = c_int8_t, &
- c_size_t = c_long_long, &
+ c_size_t = kind(c_sizeof(1)), &
c_intmax_t = c_int128_t, &
c_intptr_t = c_size_t, &
c_ptrdiff_t = c_size_t
@@ -102,6 +103,5 @@ module iso_c_binding
end function c_funloc
! TODO c_f_procpointer
- ! TODO c_sizeof
end module iso_c_binding