From 7e3d1c770e7148d56098c9e02b2cd8c6757ec8d0 Mon Sep 17 00:00:00 2001 From: tkoenig Date: Sun, 21 Oct 2012 10:32:02 +0000 Subject: 2012-10-21 Thomas Koenig PR fortran/54465 * lang.opt (Wextra): Add. * invoke.texi: Document that -Wc-binding-type, -Wconversion and -Wline-truncation are implied by -Wall. Document that -Wcompare-reals is implied by -Wextra. Document -Wextra. * options.c (set_Wextra): New function. (gfc_handle_option): Handle -Wextra. 2012-10-21 Thomas Koenig PR fortran/54465 * gfortran.dg/wextra_1.f: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192649 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 10 ++++++++++ gcc/fortran/invoke.texi | 19 +++++++++++++++---- gcc/fortran/lang.opt | 4 ++++ gcc/fortran/options.c | 16 ++++++++++++++++ gcc/fortran/trans.c | 28 ++++++++++++++++------------ 5 files changed, 61 insertions(+), 16 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 04304b1220f..2ba05069444 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2012-10-21 Thomas König + + PR fortran/54465 + * lang.opt (Wextra): Add. + * invoke.texi: Document that -Wc-binding-type, -Wconversion + and -Wline-truncation are implied by -Wall. Document that + -Wcompare-reals is implied by -Wextra. Document -Wextra. + * options.c (set_Wextra): New function. + (gfc_handle_option): Handle -Wextra. + 2012-10-19 Janus Weil PR fortran/54224 diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index d5fdee3c707..d7c32195161 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -727,7 +727,7 @@ warnings. Enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes @option{-Waliasing}, @option{-Wampersand}, -@option{-Wconversion}, @option{-Wsurprising}, +@option{-Wconversion}, @option{-Wsurprising}, @option{-Wc-binding-type}, @option{-Wintrinsics-std}, @option{-Wno-tabs}, @option{-Wintrinsic-shadow}, @option{-Wline-truncation}, @option{-Wtarget-lifetime}, @option{-Wreal-q-constant} and @option{-Wunused}. @@ -778,7 +778,8 @@ avoid such temporaries. Warn if the a variable might not be C interoperable. In particular, warn if the variable has been declared using an intrinsic type with default kind instead of using a kind parameter defined for C interoperability in the -intrinsic @code{ISO_C_Binding} module. +intrinsic @code{ISO_C_Binding} module. This option is implied by +@option{-Wall}. @item -Wcharacter-truncation @opindex @code{Wcharacter-truncation} @@ -788,7 +789,8 @@ Warn when a character assignment will truncate the assigned string. @item -Wline-truncation @opindex @code{Wline-truncation} @cindex warnings, line truncation -Warn when a source code line will be truncated. +Warn when a source code line will be truncated. This option is +implied by @option{-Wall}. @item -Wconversion @opindex @code{Wconversion} @@ -803,6 +805,14 @@ the expression after conversion. Implied by @option{-Wall}. @cindex conversion Warn about implicit conversions between different types and kinds. +@item -Wextra +@opindex @code{Wextra} +@cindex extra warnings +@cindex warnings, extra +Enables some warning options for usages of language features which +may be problematic. This currently includes @option{-Wcompare-reals} +and @option{-Wunused-parameter}. + @item -Wimplicit-interface @opindex @code{Wimplicit-interface} @cindex warnings, implicit interface @@ -884,7 +894,7 @@ encountered, which yield an UNDERFLOW during compilation. Warn if a user-defined procedure or module procedure has the same name as an intrinsic; in this case, an explicit interface or @code{EXTERNAL} or @code{INTRINSIC} declaration might be needed to get calls later resolved to -the desired intrinsic/procedure. +the desired intrinsic/procedure. This option is implied by @option{-Wall}. @item -Wunused-dummy-argument @opindex @code{Wunused-dummy-argument} @@ -939,6 +949,7 @@ allocatable variable; this includes scalars and derived types. @item -Wcompare-reals @opindex @code{Wcompare-reals} Warn when comparing real or complex types for equality or inequality. +This option is implied by @option{-Wextra}. @item -Wtarget-lifetime @opindex @code{Wtargt-lifetime} diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 8a633464c4c..15351876c19 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -230,6 +230,10 @@ Wconversion-extra Fortran Warning Warn about most implicit conversions +Wextra +Fortran Warning +Print extra (possibly unwanted) warnings + Wfunction-elimination Fortran Warning Warn about function call elimination diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 764f5706ad0..08c551451e9 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -483,6 +483,13 @@ set_Wall (int setting) warn_maybe_uninitialized = setting; } +/* Set the options for -Wextra. */ + +static void +set_Wextra (int setting) +{ + gfc_option.warn_compare_reals = setting; +} static void gfc_handle_module_path_options (const char *arg) @@ -653,6 +660,15 @@ gfc_handle_option (size_t scode, const char *arg, int value, gfc_option.warn_conversion_extra = value; break; + case OPT_Wextra: + handle_generated_option (&global_options, &global_options_set, + OPT_Wunused_parameter, NULL, value, + gfc_option_lang_mask (), kind, loc, + handlers, global_dc); + set_Wextra (value); + + break; + case OPT_Wfunction_elimination: gfc_option.warn_function_elimination = value; break; diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index 6365213b8f0..7c2d47250d4 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -814,26 +814,23 @@ gfc_allocate_allocatable (stmtblock_t * block, tree mem, tree size, tree token, } -/* Free a given variable, if it's not NULL. */ +/* Free a given variable. If it is NULL, free takes care of this + automatically. */ tree gfc_call_free (tree var) { stmtblock_t block; - tree tmp, cond, call; + tree call; if (TREE_TYPE (var) != TREE_TYPE (pvoid_type_node)) var = fold_convert (pvoid_type_node, var); gfc_start_block (&block); var = gfc_evaluate_now (var, &block); - cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, var, - build_int_cst (pvoid_type_node, 0)); call = build_call_expr_loc (input_location, builtin_decl_explicit (BUILT_IN_FREE), 1, var); - tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond, call, - build_empty_stmt (input_location)); - gfc_add_expr_to_block (&block, tmp); + gfc_add_expr_to_block (&block, call); return gfc_finish_block (&block); } @@ -861,11 +858,10 @@ gfc_call_free (tree var) } } - In this front-end version, status doesn't have to be GFC_INTEGER_4. - Moreover, if CAN_FAIL is true, then we will not emit a runtime error, - even when no status variable is passed to us (this is used for - unconditional deallocation generated by the front-end at end of - each procedure). + In this front-end version, status doesn't have to be GFC_INTEGER_4. If + CAN_FAIL is true, no status variable is passed and we are not dealing with + a coarray, we will simply call free(). This is used for unconditional + deallocation generated by the front-end at end of each procedure. If a runtime-message is possible, `expr' must point to the original expression being deallocated for its locus and variable name. @@ -890,6 +886,14 @@ gfc_deallocate_with_status (tree pointer, tree status, tree errmsg, STRIP_NOPS (pointer); } + else if (can_fail && status == NULL_TREE) + { + tmp = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_FREE), 1, + fold_convert (pvoid_type_node, pointer)); + return tmp; + } + cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, pointer, build_int_cst (TREE_TYPE (pointer), 0)); -- cgit v1.2.1