diff options
author | Janus Weil <janus@gcc.gnu.org> | 2018-07-18 20:31:59 +0200 |
---|---|---|
committer | Janus Weil <janus@gcc.gnu.org> | 2018-07-18 20:31:59 +0200 |
commit | 6457b1f096d216ca742f8e1f2a93462ecb24b38d (patch) | |
tree | e42854bbf767584ce4c287893b494c6154cdea1c /gcc/fortran/frontend-passes.c | |
parent | c56e97274f164e704e7f13dfe53531ced3cb24ca (diff) | |
download | gcc-6457b1f096d216ca742f8e1f2a93462ecb24b38d.zip gcc-6457b1f096d216ca742f8e1f2a93462ecb24b38d.tar.gz gcc-6457b1f096d216ca742f8e1f2a93462ecb24b38d.tar.bz2 |
re PR fortran/85599 (warn about short-circuiting of logical expressions for non-pure functions)
2018-07-18 Janus Weil <janus@gcc.gnu.org>
Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85599
* dump-parse-tree.c (show_attr): Add handling of implicit_pure.
* frontend-passes.c (do_warn_function_elimination): Do not warn for
pure functions.
* gfortran.h: Add prototypes for gfc_pure_function and
gfc_implicit_pure_function.
* gfortran.texi: Add chapter on evaluation of logical expressions.
* invoke.texi: Mention that -Wfunction-elimination is implied
by -Wextra.
* lang.opt: Make -Wextra imply -Wfunction-elimination.
* resolve.c (pure_function): Rename to gfc_pure_function.
(gfc_implicit_pure_function): New function.
(check_pure_function): Use it here.
(impure_function_callback): New function.
(resolve_operator): Call it via gfc_expr_walker.
2018-07-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/85599
* gfortran.dg/function_optimize_5.f90: Add option
'-faggressive-function-elimination' and update dg-warning clauses.
* gfortran.dg/short_circuiting.f90: New test.
Co-Authored-By: Thomas Koenig <tkoenig@gcc.gnu.org>
From-SVN: r262860
Diffstat (limited to 'gcc/fortran/frontend-passes.c')
-rw-r--r-- | gcc/fortran/frontend-passes.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 6d3a12a..f9dcddc 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -840,17 +840,22 @@ create_var (gfc_expr * e, const char *vname) static void do_warn_function_elimination (gfc_expr *e) { - if (e->expr_type != EXPR_FUNCTION) - return; - if (e->value.function.esym) - gfc_warning (OPT_Wfunction_elimination, - "Removing call to function %qs at %L", - e->value.function.esym->name, &(e->where)); - else if (e->value.function.isym) - gfc_warning (OPT_Wfunction_elimination, - "Removing call to function %qs at %L", - e->value.function.isym->name, &(e->where)); + const char *name; + if (e->expr_type == EXPR_FUNCTION + && !gfc_pure_function (e, &name) && !gfc_implicit_pure_function (e)) + { + if (name) + gfc_warning (OPT_Wfunction_elimination, + "Removing call to impure function %qs at %L", name, + &(e->where)); + else + gfc_warning (OPT_Wfunction_elimination, + "Removing call to impure function at %L", + &(e->where)); + } } + + /* Callback function for the code walker for doing common function elimination. This builds up the list of functions in the expression and goes through them to detect duplicates, which it then replaces |