]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/54465 (Implement -Wextra for Fortran)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 21 Oct 2012 10:32:02 +0000 (10:32 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 21 Oct 2012 10:32:02 +0000 (10:32 +0000)
2012-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.

From-SVN: r192649

gcc/fortran/ChangeLog
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/options.c
gcc/fortran/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/wextra_1.f [new file with mode: 0644]

index 04304b1220fe453db5dc299cee52d540f2f57127..2ba0506944406169289b715debf5b2a360dbdb49 100644 (file)
@@ -1,3 +1,13 @@
+2012-10-21  Thomas König  <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-19  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/54224
index d5fdee3c7079426de01ef1323ff291da2a7700b7..d7c32195161ec7ff8c1ea0be3f5c8dba314664ed 100644 (file)
@@ -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}
index 8a633464c4c63a903e0aaffdb24106ae6b7bbd64..15351876c19530461a76c037c8a8e274e8fa564c 100644 (file)
@@ -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 764f5706ad0cbf19a6c4aabb0a77adf4db9229bc..08c551451e98a350f40b985dd027d228f8aba582 100644 (file)
@@ -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;
index 6365213b8f063682ef51e479d4a62ca3ac8b07b7..7c2d47250d4d6eaa2beb91b84417e14e020757c8 100644 (file)
@@ -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));
 
index a10971c255363013639f6746111af5bc17533417..7999b9770601dcaae12bcca91ac08980344ddb05 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-21  Thomas König  <tkoenig@gcc.gnu.org>
+
+       PR fortran/54465
+       * gfortran.dg/wextra_1.f:  New test.
+
 2012-10-20  Jan Hubicka  <jh@suse.cz>
 
        * gcc.dg/tree-prof/unroll-1.c: New testcase.
diff --git a/gcc/testsuite/gfortran.dg/wextra_1.f b/gcc/testsuite/gfortran.dg/wextra_1.f
new file mode 100644 (file)
index 0000000..94c8edd
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-Wextra" }
+      program main
+      integer, parameter :: x=3 ! { dg-warning "Unused parameter" }
+      real :: a
+      read (*,*) a
+      if (a .eq. 3.14) a=2.     ! { dg-warning "Equality comparison" }
+      print *,a
+      end