This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR fortran/42517: -fcheck=recursion does not work with -fopenmp


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]