This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: PATCH: PR fortran/42517: -fcheck=recursion does not work with -fopenmp
- From: Tobias Burnus <burnus at net-b dot de>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: "H.J. Lu" <hjl dot tools at gmail dot com>, "H.J. Lu" <hongjiu dot lu at intel dot com>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 05 Jan 2010 10:50:54 +0100
- Subject: Re: PATCH: PR fortran/42517: -fcheck=recursion does not work with -fopenmp
- References: <20100104223504.GA17039@lucon.org> <4B42E8A2.8010306@net-b.de>
On 01/05/2010 08:22 AM, Tobias Burnus wrote:
> H.J. Lu wrote:
>> One gfc_option.flag_openmp check is missing, which leads to libgomp.fortran/recursion1.f90
>> Fortran runtime error: Recursive call to nonrecursive procedure 'sub'
>> OK for trunk?
>> @@ -4322,7 +4322,7 @@ gfc_generate_function_code (gfc_namespace * ns)
>> if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION) && !is_recursive
>> - && !gfc_option.flag_recursive)
>> + && !gfc_option.flag_recursive && !gfc_option.flag_openmp)
Actually, I think the following patch makes more sense: It sets
gfc_option.flag_recursive when -fopenmp is given, which is in line with
the manual (man gfortran: "The option -fopenmp implies -frecursive.").
Currently, -fopenmp and -frecursive both set
"gfc_option.flag_max_stack_var_size = -1", which implies that all local
variables use the stack (and no static memory); but
gfc_option.flag_recursive is also used in resolve.c. Currently, the
following program is allowed with -frecursive but rejected with -fopenmp:
subroutine rec(a)
logical a
if (a) call rec(.false.)
end
call rec(.true.)
end
Thus, HJ, please hold off with committing your patch.
I am currently regtesting+testing the patch below and plan to apply it
as obvious, unless someone protests - or the (reg)testing fails.
Tobias
PS: Thanks to Dominique for pointing out the inconsistency that -fopenmp
does not imply gfc_option.flag_recursive.
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c (revision 155642)
+++ gcc/fortran/options.c (working copy)
@@ -353,6 +353,12 @@ gfc_post_options (const char **pfilename
"implied by -fopenmp",
gfc_option.flag_max_stack_var_size);
+ /* Implement -frecursive as -fmax-stack-var-size=-1. */
+ if (gfc_option.flag_recursive)
+ gfc_option.flag_max_stack_var_size = -1;
+ else if (gfc_option.flag_openmp)
+ gfc_option.flag_recursive = 1;
+
/* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.flag_openmp)
gfc_option.flag_max_stack_var_size = -1;
@@ -361,10 +367,6 @@ gfc_post_options (const char **pfilename
if (gfc_option.flag_max_stack_var_size == -2)
gfc_option.flag_max_stack_var_size = 32768;
- /* Implement -frecursive as -fmax-stack-var-size=-1. */
- if (gfc_option.flag_recursive)
- gfc_option.flag_max_stack_var_size = -1;
-
/* Implement -fno-automatic as -fmax-stack-var-size=0. */
if (!gfc_option.flag_automatic)
gfc_option.flag_max_stack_var_size = 0;