gcc/libgfortran/intrinsics/f2c_specifics.F90
Tobias Schlüter 973ff4c052 re PR fortran/20178 (COMPLEX function returns incompatible with g77)
gcc/fortran/
	PR fortran/20178
	* gfortran.h (gfc_option): Add flag_f2c.
	* invoke.texi: Document '-ff2c' command line option.  Adapt
	documentation for '-fno-second-underscore' and '-fno-underscoring'.
	* lang.opt (ff2c): New entry.
	* options.c (gfc-init_options): Set default calling convention
	to -fno-f2c.  Mark -fsecond-underscore unset.
	(gfc_post_options): Set -fsecond-underscore if not explicitly set
	by user.
	(handle_options): Set gfc_option.flag_f2c according to requested
	calling	convention.
	* trans-decl.c (gfc_get_extern_function_decl): Use special f2c
	intrinsics where necessary.
	(gfc_trans_deferred_vars): Change todo error to	assertion.
	* trans-expr.c (gfc_conv_variable): Dereference access
	to hidden result argument.
	(gfc_conv_function_call): Add hidden result argument to argument
	list if f2c calling conventions requested.  Slightly restructure
	tests.  Convert result of default REAL function to requested type
	if f2c calling conventions are used.  Dereference COMPLEX result
	if f2c cc are used.
	* trans-types.c (gfc_sym_type):  Return double for default REAL
	function if f2c cc are used.
	(gfc_return_by_reference): Slightly restructure logic.  Return
	COMPLEX by reference depending on calling conventions.
	(gfc_get_function_type): Correctly make hidden result argument a
	pass-by-reference argument for COMPLEX.  Remove old code which does
	this for derived types.
libgfortran/
	PR fortran/20178
	* Makefile.am (gfor_specific_src): Add 'intrinsics/f2c_intrinsics.F90'
	to dependencies.
	* Makefile.in: Regenerate.
	* intrinsics/f2c_specific.F90: New file.
gcc/testsuite/
	PR fortran/20178
	* gfortran.dg/f2c_1.f90, gfortran.dg/f2c_2.f90,
	gfortran.dg/f2c_3.f90: New tests.

From-SVN: r99544
2005-05-11 00:06:55 +02:00

170 lines
4.1 KiB
Fortran

! Copyright 2002, 2005 Free Software Foundation, Inc.
! Contributed by Tobias Schl"uter
!
!This file is part of the GNU Fortran 95 runtime library (libgfortran).
!
!GNU libgfortran is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public
!License as published by the Free Software Foundation; either
!version 2 of the License, or (at your option) any later version.
!In addition to the permissions in the GNU General Public License, the
!Free Software Foundation gives you unlimited permission to link the
!compiled version of this file into combinations with other programs,
!and to distribute those combinations without any restriction coming
!from the use of this file. (The General Public License restrictions
!do apply in other respects; for example, they cover modification of
!the file, and distribution when not linked into a combine
!executable.)
!
!GNU libgfortran is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!GNU General Public License for more details.
!
!You should have received a copy of the GNU General Public
!License along with libgfortran; see the file COPYING. If not,
!write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
!Boston, MA 02111-1307, USA.
!
! Specifics for the intrinsics whose calling conventions change if
! -ff2c is used.
!
! There are two annoyances WRT the preprocessor:
! - we're using -traditional-cpp, so we can't use the ## operator.
! - macros expand to a single line, and Fortran lines can't be wider
! than 132 characters, therefore we use two macros to split the lines
!
! The cases we need to implement are functions returning default REAL
! or COMPLEX. The former need to return DOUBLE PRECISION instead of REAL,
! the latter become subroutines returning via a hidden first argument.
! one argument functions
#define REAL_HEAD(NAME) \
elemental function f2c_specific__/**/NAME/**/_r4 (parm) result(res);
#define REAL_BODY(NAME) \
REAL, intent (in) :: parm; \
DOUBLE PRECISION :: res; \
res = NAME (parm); \
end function
#define COMPLEX_HEAD(NAME) \
subroutine f2c_specific__/**/NAME/**/_c4 (res, parm);
#define COMPLEX_BODY(NAME) \
COMPLEX, intent (in) :: parm; \
COMPLEX, intent (out) :: res; \
res = NAME (parm); \
end subroutine
#define DCOMPLEX_HEAD(NAME) \
subroutine f2c_specific__/**/NAME/**/_c8 (res, parm);
#define DCOMPLEX_BODY(NAME) \
DOUBLE COMPLEX, intent (in) :: parm; \
DOUBLE COMPLEX, intent (out) :: res; \
res = NAME (parm); \
end subroutine
REAL_HEAD(abs)
REAL_BODY(abs)
! abs is special in that the result is real
elemental function f2c_specific__abs_c4 (parm) result (res)
COMPLEX, intent(in) :: parm
DOUBLE PRECISION :: res
res = abs(parm)
end function
REAL_HEAD(exp)
REAL_BODY(exp)
COMPLEX_HEAD(exp)
COMPLEX_BODY(exp)
DCOMPLEX_HEAD(exp)
DCOMPLEX_BODY(exp)
REAL_HEAD(log)
REAL_BODY(log)
COMPLEX_HEAD(log)
COMPLEX_BODY(log)
DCOMPLEX_HEAD(log)
DCOMPLEX_BODY(log)
REAL_HEAD(log10)
REAL_BODY(log10)
REAL_HEAD(sqrt)
REAL_BODY(sqrt)
COMPLEX_HEAD(sqrt)
COMPLEX_BODY(sqrt)
DCOMPLEX_HEAD(sqrt)
DCOMPLEX_BODY(sqrt)
REAL_HEAD(asin)
REAL_BODY(asin)
REAL_HEAD(acos)
REAL_BODY(acos)
REAL_HEAD(atan)
REAL_BODY(atan)
REAL_HEAD(sin)
REAL_BODY(sin)
COMPLEX_HEAD(sin)
COMPLEX_BODY(sin)
DCOMPLEX_HEAD(sin)
DCOMPLEX_BODY(sin)
REAL_HEAD(cos)
REAL_BODY(cos)
COMPLEX_HEAD(cos)
COMPLEX_BODY(cos)
DCOMPLEX_HEAD(cos)
DCOMPLEX_BODY(cos)
REAL_HEAD(tan)
REAL_BODY(tan)
REAL_HEAD(sinh)
REAL_BODY(sinh)
REAL_HEAD(cosh)
REAL_BODY(cosh)
REAL_HEAD(tanh)
REAL_BODY(tanh)
COMPLEX_HEAD(conjg)
COMPLEX_BODY(conjg)
DCOMPLEX_HEAD(conjg)
DCOMPLEX_BODY(conjg)
REAL_HEAD(aint)
REAL_BODY(aint)
REAL_HEAD(anint)
REAL_BODY(anint)
! two argument functions
#define REAL2_HEAD(NAME) \
elemental function f2c_specific__/**/NAME/**/_r4 (p1, p2) result(res);
#define REAL2_BODY(NAME) \
REAL, intent (in) :: p1, p2; \
DOUBLE PRECISION :: res; \
res = NAME (p1, p2); \
end function
REAL2_HEAD(sign)
REAL2_BODY(sign)
REAL2_HEAD(dim)
REAL2_BODY(dim)
REAL2_HEAD(atan2)
REAL2_BODY(atan2)
REAL2_HEAD(mod)
REAL2_BODY(mod)