re PR fortran/90329 (Incompatibility between gfortran and C lapack calls)
authorJakub Jelinek <jakub@redhat.com>
Wed, 29 May 2019 14:08:57 +0000 (16:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 29 May 2019 14:08:57 +0000 (16:08 +0200)
PR fortran/90329
* lang.opt (fbroken-callers): Remove.
(ftail-call-workaround, ftail-call-workaround=): New options.
* gfortran.h (struct gfc_namespace): Add implicit_interface_calls.
* interface.c (gfc_procedure_use): Set implicit_interface_calls
for calls to implicit interface procedures.
* trans-decl.c (create_function_arglist): Use flag_tail_call_workaround
instead of flag_broken_callers.  If it is not 2, also require
sym->ns->implicit_interface_calls.
* invoke.texi (fbroken-callers): Remove documentation.
(ftail-call-workaround, ftail-call-workaround=): Document.

From-SVN: r271738

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/interface.c
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/trans-decl.c

index 679633d616d173efc813c2fdea759066b6b69129..07b485b5a50d4c85a58969df230b7c482185f9b6 100644 (file)
@@ -1,3 +1,17 @@
+2019-05-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/90329
+       * lang.opt (fbroken-callers): Remove.
+       (ftail-call-workaround, ftail-call-workaround=): New options.
+       * gfortran.h (struct gfc_namespace): Add implicit_interface_calls.
+       * interface.c (gfc_procedure_use): Set implicit_interface_calls
+       for calls to implicit interface procedures.
+       * trans-decl.c (create_function_arglist): Use flag_tail_call_workaround
+       instead of flag_broken_callers.  If it is not 2, also require
+       sym->ns->implicit_interface_calls.
+       * invoke.texi (fbroken-callers): Remove documentation.
+       (ftail-call-workaround, ftail-call-workaround=): Document.
+
 2019-05-26  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/90539
index 0de375cf0bbb779ffb8f6e940e1f647efa88aae2..54987ac878b6446147cb01234c496e03b9502c46 100644 (file)
@@ -1866,6 +1866,9 @@ typedef struct gfc_namespace
 
   /* Set to 1 for !$ACC ROUTINE namespaces.  */
   unsigned oacc_routine:1;
+
+  /* Set to 1 if there are any calls to procedures with implicit interface.  */
+  unsigned implicit_interface_calls:1;
 }
 gfc_namespace;
 
index a3a9528814d60cc56f3f9c643513553b8acf2260..3f91f6b38fa22a7305f828e01bfbb2575c87e1bd 100644 (file)
@@ -3686,6 +3686,7 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
        gfc_warning (OPT_Wimplicit_procedure,
                     "Procedure %qs called at %L is not explicitly declared",
                     sym->name, where);
+      gfc_find_proc_namespace (sym->ns)->implicit_interface_calls = 1;
     }
 
   if (sym->attr.if_source == IFSRC_UNKNOWN)
index 73b836ed7d05b3704045cc62ac3c2df1c367bb3a..2e2cb5b2728c02f3c71802a7a41888be210f8d89 100644 (file)
@@ -181,7 +181,8 @@ and warnings}.
 @item Code Generation Options
 @xref{Code Gen Options,,Options for code generation conventions}.
 @gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
--fbounds-check -fbroken-callers -fcheck-array-temporaries @gol
+-fbounds-check -ftail-call-workaround -ftail-call-workaround=@var{n} @gol
+-fcheck-array-temporaries @gol
 -fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
 -fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
 -ffrontend-loop-interchange @gol
@@ -1622,8 +1623,9 @@ warnings for generated array temporaries.
 @c Note: This option is also referred in gcc's manpage
 Deprecated alias for @option{-fcheck=bounds}.
 
-@item -fbroken-callers
-@opindex @code{broken-callers}
+@item -ftail-call-workaround
+@itemx -ftail-call-workaround=@var{n}
+@opindex @code{tail-call-workaround}
 Some C interfaces to Fortran codes violate the gfortran ABI by
 omitting the hidden character length arguments as described in
 @xref{Argument passing conventions}.  This can lead to crashes
@@ -1631,7 +1633,11 @@ because pushing arguments for tail calls can overflow the stack.
 
 To provide a workaround for existing binary packages, this option
 disables tail call optimization for gfortran procedures with character
-arguments.
+arguments.  With @option{-ftail-call-workaround=2} tail call optimization
+is disabled in all gfortran procedures with character arguments,
+with @option{-ftail-call-workaround=1} or equivalent
+@option{-ftail-call-workaround} only in gfortran procedures with character
+arguments that call implicitly prototyped procedures.
 
 Using this option can lead to problems including crashes due to
 insufficient stack space.
@@ -1644,10 +1650,10 @@ source code.
 Support for this option will likely be withdrawn in a future release
 of gfortran.
 
-The negative form, @option{-fno-broken-callers}, can be used to
-disable this option.
+The negative form, @option{-fno-tail-call-workaround} or equivalent
+@option{-ftail-call-workaround=0}, can be used to disable this option.
 
-Default is currently @option{-fbroken-callers}, this will change
+Default is currently @option{-ftail-call-workaround}, this will change
 in future releases.
 
 @item -fcheck-array-temporaries
index 4d2340a73fabab5ba7d9fe1455453b5d0675a459..8b2e1ad3424b04691b3a0480f8a9200342e4df9e 100644 (file)
@@ -397,10 +397,6 @@ fblas-matmul-limit=
 Fortran RejectNegative Joined UInteger Var(flag_blas_matmul_limit) Init(30)
 -fblas-matmul-limit=<n>        Size of the smallest matrix for which matmul will use BLAS.
 
-fbroken-callers
-Fortran Var(flag_broken_callers) Init(1)
-Disallow tail call optimization when a calling routine may have omitted character lenghts.
-
 fcheck-array-temporaries
 Fortran
 Produce a warning at runtime if a array temporary has been created for a procedure argument.
@@ -766,6 +762,13 @@ fsign-zero
 Fortran Var(flag_sign_zero) Init(1)
 Apply negative sign to zero values.
 
+ftail-call-workaround
+Frotran Alias(ftail-call-workaround=,1,0)
+
+ftail-call-workaround=
+Fortran RejectNegative Joined UInteger IntegerRange(0, 2) Var(flag_tail_call_workaround) Init(1)
+Disallow tail call optimization when a calling routine may have omitted character lenghts.
+
 funderscoring
 Fortran Var(flag_underscoring) Init(1)
 Append underscores to externally visible names.
index 7cf1ec5428910425808d63c502ccac060600e9f0..b8e07274febda7828c0d4376566298fa8d025176 100644 (file)
@@ -2520,9 +2520,12 @@ create_function_arglist (gfc_symbol * sym)
          /* Marking the length DECL_HIDDEN_STRING_LENGTH will lead
             to tail calls being disabled.  Only do that if we
             potentially have broken callers.  */
-         if (flag_broken_callers && f->sym->ts.u.cl
+         if (flag_tail_call_workaround
+             && f->sym->ts.u.cl
              && f->sym->ts.u.cl->length
-             && f->sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)
+             && f->sym->ts.u.cl->length->expr_type == EXPR_CONSTANT
+             && (flag_tail_call_workaround == 2
+                 || f->sym->ns->implicit_interface_calls))
            DECL_HIDDEN_STRING_LENGTH (length) = 1;
 
          /* Remember the passed value.  */