Patchwork *ping* [patch, fortran] Handle -Wextra, -fcompare-reals is implied with -Wextra

login
register
mail settings
Submitter Thomas Koenig
Date Oct. 21, 2012, 10:38 a.m.
Message ID <5083D099.8080708@netcologne.de>
Download mbox | patch
Permalink /patch/192986/
State New
Headers show

Comments

Thomas Koenig - Oct. 21, 2012, 10:38 a.m.
Hi Janus,

> In the docu of -Wall, there is a list of which switches are included,
> but -Wc-binding-type is missing. Maybe you can add it?
>
> And how about also adding a short docu paragraph for Wextra?

I've added both items to the documentation as you suggested, and
committed as rev. 192649.  Here is the patch as I committed it.

Thanks a lot for your review!

Now we can start thinking if we want to add other flags to
-Wextra.

Regards

	Thomas

012-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

         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  <tkoenig@gcc.gnu.org>

         PR fortran/54465
         * gfortran.dg/wextra_1.f:  New test.
Andreas Schwab - Oct. 26, 2012, 11:41 p.m.
Thomas Koenig <tkoenig@netcologne.de> writes:

> Index: trans.c
> ===================================================================
> --- trans.c	(revision 192638)
> +++ trans.c	(working copy)
> @@ -814,26 +814,23 @@ gfc_allocate_allocatable (stmtblock_t * block, tre
>  }
>  
>  
> -/* 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 sta
>        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));
>  

What's this?

Andreas.
Thomas Koenig - Oct. 27, 2012, 12:10 p.m.
Am 27.10.2012 01:41, schrieb Andreas Schwab:
> Thomas Koenig <tkoenig@netcologne.de> writes:
>
>> Index: trans.c
>> ===================================================================
>> --- trans.c	(revision 192638)
>> +++ trans.c	(working copy)
>> @@ -814,26 +814,23 @@ gfc_allocate_allocatable (stmtblock_t * block, tre

> What's this?

Something that I accidentally committed, which is part of a patch
pending review (see 
http://gcc.gnu.org/ml/gcc-patches/2012-10/msg00613.html).

Reverted as of revision 192875.

	Thomas

Patch

Index: lang.opt
===================================================================
--- lang.opt	(revision 192638)
+++ lang.opt	(working copy)
@@ -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
Index: invoke.texi
===================================================================
--- invoke.texi	(revision 192638)
+++ invoke.texi	(working copy)
@@ -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
 @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 @optio
 @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 compi
 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 de
 @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}
Index: trans.c
===================================================================
--- trans.c	(revision 192638)
+++ trans.c	(working copy)
@@ -814,26 +814,23 @@  gfc_allocate_allocatable (stmtblock_t * block, tre
 }
 
 
-/* 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 sta
       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));
 
Index: options.c
===================================================================
--- options.c	(revision 192638)
+++ options.c	(working copy)
@@ -483,8 +483,15 @@  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,
       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;