The following patch adds two new functions. One of them is an overload
of gfc_warning_cmdline() that takes an option. Thus now we get:

f951: Warning: Nonexistent include directory
'C:\msys\1.0.10\home\FX\ibin\i586-pc-mingw32\libgfortran/../../../trunk/libgfortran/generated'
[-Wmissing-include-dirs]

plus colors!

and of course, with -Werror=missing-include-dirs you get:

f951: Error: Nonexistent include directory
'C:\msys\1.0.10\home\FX\ibin\i586-pc-mingw32\libgfortran/../../../trunk/libgfortran/generated'
[-Werror=missing-include-dirs]
f951: some warnings being treated as errors

plus colors!

The other new function is for errors instead of warnings. Perhaps
there are more places where these functions can be used.

Surprisingly, options that are not Common and not handled explicitly
in gfc_handle_option were rejected. This is fixed by this patch since
such options are handled automatically by the common options
machinery.

Bootstrapped and regression tested on x86_64-linux-gnu.

OK?

gcc/fortran/ChangeLog:

2014-10-04  Manuel López-Ibáñez  <m...@gcc.gnu.org>

    * gfortran.h (gfc_warning_cmdline): Add overload that takes an
    option.
    (gfc_error_cmdline): Declare.
    * error.c (gfc_warning_cmdline): New overload that takes an option.
    (gfc_error_cmdline): New.
    * lang.opt (Wmissing-include-dirs): New.
    * scanner.c (add_path_to_list): Use the new functions.
    (load_file): Likewise.
    * options.c (gfc_init_options): Wmissing-include-dirs is enabled
    by default in Fortran.
    (gfc_handle_option): Accept automatically handled options.
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h      (revision 215880)
+++ gcc/fortran/gfortran.h      (working copy)
@@ -2693,17 +2693,19 @@ void gfc_buffer_error (int);
 
 const char *gfc_print_wide_char (gfc_char_t);
 
 void gfc_warning (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
 void gfc_warning_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
-void gfc_warning_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2);
+bool gfc_warning_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2);
+bool gfc_warning_cmdline (int opt, const char *gmsgid, ...) 
ATTRIBUTE_GCC_GFC(2,3);
 
 void gfc_clear_warning (void);
 void gfc_warning_check (void);
 
 void gfc_error (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
+void gfc_error_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2);
 void gfc_error_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
 void gfc_fatal_error (const char *, ...) ATTRIBUTE_NORETURN 
ATTRIBUTE_GCC_GFC(1,2);
 void gfc_internal_error (const char *, ...) ATTRIBUTE_NORETURN 
ATTRIBUTE_GCC_GFC(1,2);
 void gfc_clear_error (void);
 int gfc_error_check (void);
 int gfc_error_flag_test (void);
Index: gcc/fortran/error.c
===================================================================
--- gcc/fortran/error.c (revision 215880)
+++ gcc/fortran/error.c (working copy)
@@ -1050,25 +1109,61 @@ gfc_diagnostic_finalizer (diagnostic_con
 {
   pp_destroy_prefix (context->printer);
   pp_newline_and_flush (context->printer);
 }
 
 /* Give a warning about the command-line.  */
 
-void
+bool
+gfc_warning_cmdline (int opt, const char *gmsgid, ...)
+{
+  va_list argp;
+  diagnostic_info diagnostic;
+  bool ret;
+
+  va_start (argp, gmsgid);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION,
+                      DK_WARNING);
+  diagnostic.option_index = opt;
+  ret = report_diagnostic (&diagnostic);
+  va_end (argp);
+  return ret;
+}
+
+
+/* Give a warning about the command-line.  */
+
+bool
 gfc_warning_cmdline (const char *gmsgid, ...)
 {
   va_list argp;
   diagnostic_info diagnostic;
+  bool ret;
 
   va_start (argp, gmsgid);
   diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION,
                       DK_WARNING);
+  ret = report_diagnostic (&diagnostic);
+  va_end (argp);
+  return ret;
+}
+
+
+/* Give an error about the command-line.  */
+
+void
+gfc_error_cmdline (const char *gmsgid, ...)
+{
+  va_list argp;
+  diagnostic_info diagnostic;
+
+  va_start (argp, gmsgid);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ERROR);
   report_diagnostic (&diagnostic);
   va_end (argp);
 }
 
 /* Clear the warning flag.  */
 
 void
 gfc_clear_warning (void)
 {
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt        (revision 215880)
+++ gcc/fortran/lang.opt        (working copy)
@@ -255,10 +255,14 @@ Warn about truncated source lines
 
 Wintrinsics-std
 Fortran Warning
 Warn on intrinsics not part of the selected standard
 
+Wmissing-include-dirs
+Fortran
+; Documented in C/C++
+
 Wuse-without-only
 Fortran Warning
 Warn about USE statements that have no ONLY qualifier
 
 Wopenmp-simd
Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c       (revision 215880)
+++ gcc/fortran/scanner.c       (working copy)
@@ -322,23 +322,20 @@ add_path_to_list (gfc_directorylist **li
     q[i--] = '\0';
 
   if (stat (q, &st))
     {
       if (errno != ENOENT)
-       gfc_warning_now ("Include directory \"%s\": %s", path,
-                        xstrerror(errno));
-      else
-       {
-         /* FIXME:  Also support -Wmissing-include-dirs.  */
-         if (warn)
-           gfc_warning_now ("Nonexistent include directory \"%s\"", path);
-       }
+       gfc_warning_cmdline ("Include directory %qs: %s", path,
+                            xstrerror(errno));
+      else if (warn)
+       gfc_warning_cmdline (OPT_Wmissing_include_dirs,
+                            "Nonexistent include directory %qs", path);
       return;
     }
   else if (!S_ISDIR (st.st_mode))
     {
-      gfc_warning_now ("\"%s\" is not a directory", path);
+      gfc_warning_cmdline ("%qs is not a directory", path);
       return;
     }
 
   if (head || *list == NULL)
     {
@@ -1923,11 +1920,11 @@ load_file (const char *realfilename, con
        }
       else
        input = gfc_open_file (realfilename);
       if (input == NULL)
        {
-         gfc_error_now ("Can't open file '%s'", filename);
+         gfc_error_cmdline ("Can't open file %qs", filename);
          return false;
        }
     }
   else
     {
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c       (revision 215880)
+++ gcc/fortran/options.c       (working copy)
@@ -170,10 +170,16 @@ gfc_init_options (unsigned int decoded_o
                           | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
                           | GFC_FPE_UNDERFLOW;
   gfc_option.rtcheck = 0;
   gfc_option.coarray = GFC_FCOARRAY_NONE;
 
+  /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
+     enabled by default in Fortran.  Ideally, we should express this
+     in .opt, but that is not supported yet.  */
+  if (!global_options_set.x_cpp_warn_missing_include_dirs)
+    global_options.x_cpp_warn_missing_include_dirs = 1;;
+
   set_default_std_flags ();
 
   /* Initialize cpp-related options.  */
   gfc_cpp_init_options (decoded_options_count, decoded_options);
   gfc_diagnostics_init ();
@@ -632,10 +638,12 @@ gfc_handle_option (size_t scode, const c
     return true;
 
   switch (code)
     {
     default:
+      if (cl_options[code].flags & gfc_option_lang_mask ())
+       break;
       result = false;
       break;
 
     case OPT_Wall:
       handle_generated_option (&global_options, &global_options_set,

Reply via email to