From: Jakub Jelinek Date: Wed, 29 May 2019 14:08:57 +0000 (+0200) Subject: re PR fortran/90329 (Incompatibility between gfortran and C lapack calls) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ffeebc4ff1100a14f439314f90651b42e30fb81a;p=gcc.git re PR fortran/90329 (Incompatibility between gfortran and C lapack calls) 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 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 679633d616d..07b485b5a50 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,17 @@ +2019-05-29 Jakub Jelinek + + 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 PR fortran/90539 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 0de375cf0bb..54987ac878b 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -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; diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index a3a9528814d..3f91f6b38fa 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -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) diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 73b836ed7d0..2e2cb5b2728 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -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{} @gol -fcoarray=@var{} -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 diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 4d2340a73fa..8b2e1ad3424 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -397,10 +397,6 @@ fblas-matmul-limit= Fortran RejectNegative Joined UInteger Var(flag_blas_matmul_limit) Init(30) -fblas-matmul-limit= 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. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 7cf1ec54289..b8e07274feb 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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. */