Skip to content

Commit

Permalink
gfortran.texi: Add description in sections on TS 29113 and further in…
Browse files Browse the repository at this point in the history
…teroperability with C.

2019-01-12  Paul Thomas  <pault@gcc.gnu.org>

	* gfortran.texi : Add description in sections on TS 29113 and
	further interoperability with C.
	* trans-array.c (gfc_conv_descriptor_attribute): New function.
	(gfc_get_dataptr_offset): Remove static function attribute.
	* trans-array.h : Add prototypes for above functions.
	* trans-decl.c : Add declarations for the library functions
	cfi_desc_to_gfc_desc and gfc_desc_to_cfi_desc.
	* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): New function.
	(gfc_conv_procedure_call): Call it for scalar and array actual
	arguments, when the formal arguments are bind_c with assumed
	shape or assumed rank.
	* trans.h : External declarations for gfor_fndecl_cfi_to_gfc
	and gfor_fndecl_gfc_to_cfi.

2019-01-12  Paul Thomas  <pault@gcc.gnu.org>

	* gfortran.dg/ISO_Fortran_binding_1.f90 : New test.
	* gfortran.dg/ISO_Fortran_binding_1.c : Auxilliary file for test.
	* gfortran.dg/ISO_Fortran_binding_2.f90 : New test.
	* gfortran.dg/ISO_Fortran_binding_2.c : Auxilliary file for test.
	* gfortran.dg/bind_c_array_params_2.f90 : Change search string
	for dump tree scan.

2019-01-12  Paul Thomas  <pault@gcc.gnu.org>

	* ISO_Fortran_binding.h : New file.
	* Makefile.am : Include ISO_Fortran_binding.c in the list of
	files to compile.
	* Makefile.in : Regenerated.
	* gfortran.map : Add _gfortran_cfi_desc_to_gfc_desc,
	_gfortran_gfc_desc_to_cfi_desc and the CFI API functions.
	* runtime/ISO_Fortran_binding.c : New file containing the new
	functions added to the map.

From-SVN: r267881
  • Loading branch information
Paul Thomas committed Jan 12, 2019
1 parent af79605 commit bbf18dc
Show file tree
Hide file tree
Showing 19 changed files with 2,161 additions and 117 deletions.
16 changes: 16 additions & 0 deletions gcc/fortran/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
2019-01-12 Paul Thomas <pault@gcc.gnu.org>

* gfortran.texi : Add description in sections on TS 29113 and
further interoperability with C.
* trans-array.c (gfc_conv_descriptor_attribute): New function.
(gfc_get_dataptr_offset): Remove static function attribute.
* trans-array.h : Add prototypes for above functions.
* trans-decl.c : Add declarations for the library functions
cfi_desc_to_gfc_desc and gfc_desc_to_cfi_desc.
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): New function.
(gfc_conv_procedure_call): Call it for scalar and array actual
arguments, when the formal arguments are bind_c with assumed
shape or assumed rank.
* trans.h : External declarations for gfor_fndecl_cfi_to_gfc
and gfor_fndecl_gfc_to_cfi.

2019-01-11 Steven G. Kargl <kargl@gcc.gnu.org>

PR fortran/35031
Expand Down
95 changes: 50 additions & 45 deletions gcc/fortran/gfortran.texi
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ extension are also run through preprocessing.
This manual specifically documents the Fortran front end, which handles
the programming language's syntax and semantics. The aspects of GCC
which relate to the optimization passes and the back-end code generation
are documented in the GCC manual; see
are documented in the GCC manual; see
@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
The two manuals together provide a complete reference for the GNU
Fortran compiler.
Expand Down Expand Up @@ -446,11 +446,11 @@ to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
@cindex Fortran 77
@cindex @command{g77}

The GNU Fortran compiler is the successor to @command{g77}, the Fortran
77 front end included in GCC prior to version 4. It is an entirely new
program that has been designed to provide Fortran 95 support and
extensibility for future Fortran language standards, as well as providing
backwards compatibility for Fortran 77 and nearly all of the GNU language
The GNU Fortran compiler is the successor to @command{g77}, the Fortran
77 front end included in GCC prior to version 4. It is an entirely new
program that has been designed to provide Fortran 95 support and
extensibility for future Fortran language standards, as well as providing
backwards compatibility for Fortran 77 and nearly all of the GNU language
extensions supported by @command{g77}.


Expand Down Expand Up @@ -490,10 +490,10 @@ change in future versions of GCC. See
@uref{https://gcc.gnu.org/wiki/OpenACC} for more information.

At present, the GNU Fortran compiler passes the
@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
NIST Fortran 77 Test Suite}, and produces acceptable results on the
@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
It also provides respectable performance on
It also provides respectable performance on
the @uref{http://www.polyhedron.com/fortran-compiler-comparisons/polyhedron-benchmark-suite,
Polyhedron Fortran
compiler benchmarks} and the
Expand Down Expand Up @@ -668,7 +668,7 @@ This is the default.
@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units

The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
will slow down small sequential reads and writes. If the first letter
is @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.
Expand Down Expand Up @@ -733,7 +733,7 @@ A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
@itemize @w{}
@item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
@item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
@item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
in little_endian mode, except for units 10 to 20 and 25, which are in
native format.
@item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
Expand Down Expand Up @@ -834,7 +834,7 @@ initialization are available.

@item The @code{ASSOCIATE} construct.

@item Interoperability with C including enumerations,
@item Interoperability with C including enumerations,

@item In structure constructors the components with default values may be
omitted.
Expand Down Expand Up @@ -999,7 +999,7 @@ about the current Fortran 2008 implementation status. In particular, the
following is implemented.

@itemize
@item The @option{-std=f2008} option and support for the file extensions
@item The @option{-std=f2008} option and support for the file extensions
@file{.f08} and @file{.F08}.

@item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
Expand Down Expand Up @@ -1103,8 +1103,6 @@ arrays are supported for named constants (@code{PARAMETER}).
@node Fortran 2018 status
@section Status of Fortran 2018 support

So far very little work has been done to support Fortran 2018.

@itemize
@item ERROR STOP in a PURE procedure
An @code{ERROR STOP} statement is permitted in a @code{PURE}
Expand Down Expand Up @@ -1143,8 +1141,12 @@ attribute is compatible with TS 29113.

@item Assumed types (@code{TYPE(*)}).

@item Assumed-rank (@code{DIMENSION(..)}). However, the array descriptor
of the TS is not yet supported.
@item Assumed-rank (@code{DIMENSION(..)}).

@item ISO_Fortran_binding (now in Fortran 2018 18.4) is implemented such that
conversion of the array descriptor for assumed type or assumed rank arrays is
done in the library. The include file ISO_Fortran_binding.h is can be found in
@code{~prefix/lib/gcc/$target/$version}.
@end itemize


Expand Down Expand Up @@ -1300,7 +1302,7 @@ being called from a multi-threaded program.

The GNU Fortran runtime library, (@code{libgfortran}), supports being
called concurrently from multiple threads with the following
exceptions.
exceptions.

During library initialization, the C @code{getenv} function is used,
which need not be thread-safe. Similarly, the @code{getenv}
Expand Down Expand Up @@ -1430,7 +1432,7 @@ processor dependent. GNU Fortran behaves as follows:
@cindex file, symbolic link

This section documents the behavior of GNU Fortran for file operations on
symbolic links, on systems that support them.
symbolic links, on systems that support them.

@itemize

Expand Down Expand Up @@ -1497,7 +1499,7 @@ record containing a single subrecord:
program main
use iso_fortran_env, only: int32
implicit none
integer(int32) :: i
integer(int32) :: i
real, dimension(10) :: a, b
call random_number(a)
open (10,file='test.dat',form='unformatted',access='stream')
Expand Down Expand Up @@ -1725,7 +1727,7 @@ PROGRAM test_print
END PROGRAM test_print
@end smallexample

Expanded namelist reads are permitted. This causes an error if
Expanded namelist reads are permitted. This causes an error if
@option{-std=f95} is used. In the following example, the first element
of the array will be given the value 0.00 and the two succeeding
elements will be given the values 1.00 and 2.00.
Expand Down Expand Up @@ -1988,7 +1990,7 @@ pointer in order to increment it. Consider the following example:
real pointee(10)
pointer (ipt, pointee)
ipt = loc (target)
ipt = ipt + 1
ipt = ipt + 1
@end smallexample
The last statement does not set @code{ipt} to the address of
@code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
Expand Down Expand Up @@ -2120,13 +2122,13 @@ portable.
@cindex OpenMP

OpenMP (Open Multi-Processing) is an application programming
interface (API) that supports multi-platform shared memory
multiprocessing programming in C/C++ and Fortran on many
interface (API) that supports multi-platform shared memory
multiprocessing programming in C/C++ and Fortran on many
architectures, including Unix and Microsoft Windows platforms.
It consists of a set of compiler directives, library routines,
and environment variables that influence run-time behavior.

GNU Fortran strives to be compatible to the
GNU Fortran strives to be compatible to the
@uref{http://openmp.org/wp/openmp-specifications/,
OpenMP Application Program Interface v4.5}.

Expand Down Expand Up @@ -2169,7 +2171,7 @@ if the stacksize is limited.
@item
On glibc-based systems, OpenMP enabled applications cannot be statically
linked due to limitations of the underlying pthreads-implementation. It
might be possible to get a working solution if
might be possible to get a working solution if
@command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
to the command line. However, this is not supported by @command{gcc} and
thus not recommended.
Expand Down Expand Up @@ -2213,20 +2215,20 @@ change in future versions of GCC. See
@cindex @code{%REF}
@cindex @code{%LOC}

GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
and @code{%LOC} statements, for backward compatibility with g77.
It is recommended that these should be used only for code that is
accessing facilities outside of GNU Fortran, such as operating system
or windowing facilities. It is best to constrain such uses to isolated
portions of a program--portions that deal specifically and exclusively
with low-level, system-dependent facilities. Such portions might well
provide a portable interface for use by the program as a whole, but are
themselves not portable, and should be thoroughly tested each time they
GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
and @code{%LOC} statements, for backward compatibility with g77.
It is recommended that these should be used only for code that is
accessing facilities outside of GNU Fortran, such as operating system
or windowing facilities. It is best to constrain such uses to isolated
portions of a program--portions that deal specifically and exclusively
with low-level, system-dependent facilities. Such portions might well
provide a portable interface for use by the program as a whole, but are
themselves not portable, and should be thoroughly tested each time they
are rebuilt using a new compiler or version of a compiler.

@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
reference and @code{%LOC} passes its memory location. Since gfortran
already passes scalar arguments by reference, @code{%REF} is in effect
@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
reference and @code{%LOC} passes its memory location. Since gfortran
already passes scalar arguments by reference, @code{%REF} is in effect
a do-nothing. @code{%LOC} has the same effect as a Fortran pointer.

An example of passing an argument by value to a C subroutine foo.:
Expand Down Expand Up @@ -2384,7 +2386,7 @@ following shows some examples:
@example
structure /appointment/
! nested structure definition: app_time is an array of two 'time'
structure /time/ app_time (2)
structure /time/ app_time (2)
integer(1) hour, minute
end structure
character(10) memo
Expand Down Expand Up @@ -2970,7 +2972,7 @@ with the following:
@smallexample
c Variable declaration
CHARACTER(LEN=20) FMT
c
c
c Other code here...
c
WRITE(FMT,'("(I", I0, ")")') N+1
Expand All @@ -2983,7 +2985,7 @@ or with:
@smallexample
c Variable declaration
CHARACTER(LEN=20) FMT
c
c
c Other code here...
c
WRITE(FMT,*) N+1
Expand Down Expand Up @@ -3430,11 +3432,14 @@ and constraints, it adds assumed-type (@code{TYPE(*)}) and assumed-rank
assumed-shape, assumed-rank and deferred-shape arrays, including
allocatables and pointers.

Note: Currently, GNU Fortran does not support the array descriptor
Note: Currently, GNU Fortran does not use internally the array descriptor
(dope vector) as specified in the Technical Specification, but uses
an array descriptor with different fields. The Chasm Language
Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
provide an interface to GNU Fortran's array descriptor.
an array descriptor with different fields. Assumed type and assumed rank
formal arguments are converted in the library to the specified form. The
ISO_Fortran_binding API functions (also Fortran 2018 18.4) are implemented
in libgfortran. Alternatively, the Chasm Language Interoperability Tools,
@url{http://chasm-interop.sourceforge.net/}, provide an interface to GNU
Fortran's array descriptor.

The Technical Specification adds the following new features, which
are supported by GNU Fortran:
Expand Down Expand Up @@ -5735,7 +5740,7 @@ ideas and significant help to the GNU Fortran project
The following people have contributed bug reports,
smaller or larger patches,
and much needed feedback and encouragement for the
GNU Fortran project:
GNU Fortran project:

@itemize @minus
@item Bill Clodius
Expand Down
18 changes: 17 additions & 1 deletion gcc/fortran/trans-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ gfc_conv_descriptor_rank (tree desc)
}


tree
gfc_conv_descriptor_attribute (tree desc)
{
tree tmp;
tree dtype;

dtype = gfc_conv_descriptor_dtype (desc);
tmp = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (dtype)),
GFC_DTYPE_ATTRIBUTE);
gcc_assert (tmp!= NULL_TREE
&& TREE_TYPE (tmp) == short_integer_type_node);
return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (tmp),
dtype, tmp, NULL_TREE);
}


tree
gfc_get_descriptor_dimension (tree desc)
{
Expand Down Expand Up @@ -6767,7 +6783,7 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc,


/* Calculate the overall offset, including subreferences. */
static void
void
gfc_get_dataptr_offset (stmtblock_t *block, tree parm, tree desc, tree offset,
bool subref, gfc_expr *expr)
{
Expand Down
3 changes: 3 additions & 0 deletions gcc/fortran/trans-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void gfc_conv_tmp_array_ref (gfc_se * se);
/* Translate a reference to an array temporary. */
void gfc_conv_tmp_ref (gfc_se *);

/* Calculate the overall offset, including subreferences. */
void gfc_get_dataptr_offset (stmtblock_t*, tree, tree, tree, bool, gfc_expr*);
/* Obtain the span of an array. */
tree gfc_get_array_span (tree, gfc_expr *);
/* Evaluate an array expression. */
Expand Down Expand Up @@ -167,6 +169,7 @@ tree gfc_conv_descriptor_offset_get (tree);
tree gfc_conv_descriptor_span_get (tree);
tree gfc_conv_descriptor_dtype (tree);
tree gfc_conv_descriptor_rank (tree);
tree gfc_conv_descriptor_attribute (tree);
tree gfc_get_descriptor_dimension (tree);
tree gfc_conv_descriptor_stride_get (tree, tree);
tree gfc_conv_descriptor_lbound_get (tree, tree);
Expand Down
10 changes: 10 additions & 0 deletions gcc/fortran/trans-decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ tree gfor_fndecl_fdate;
tree gfor_fndecl_ttynam;
tree gfor_fndecl_in_pack;
tree gfor_fndecl_in_unpack;
tree gfor_fndecl_cfi_to_gfc;
tree gfor_fndecl_gfc_to_cfi;
tree gfor_fndecl_associated;
tree gfor_fndecl_system_clock4;
tree gfor_fndecl_system_clock8;
Expand Down Expand Up @@ -3619,6 +3621,14 @@ gfc_build_builtin_function_decls (void)
get_identifier (PREFIX("internal_unpack")), ".wR",
void_type_node, 2, pvoid_type_node, pvoid_type_node);

gfor_fndecl_cfi_to_gfc = gfc_build_library_function_decl_with_spec (
get_identifier (PREFIX("cfi_desc_to_gfc_desc")), ".ww",
void_type_node, 2, pvoid_type_node, ppvoid_type_node);

gfor_fndecl_gfc_to_cfi = gfc_build_library_function_decl_with_spec (
get_identifier (PREFIX("gfc_desc_to_cfi_desc")), ".wR",
void_type_node, 2, ppvoid_type_node, pvoid_type_node);

gfor_fndecl_associated = gfc_build_library_function_decl_with_spec (
get_identifier (PREFIX("associated")), ".RR",
integer_type_node, 2, ppvoid_type_node, ppvoid_type_node);
Expand Down
Loading

0 comments on commit bbf18dc

Please sign in to comment.