aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/doc/invoke.texi6
-rw-r--r--gcc/fortran/cpp.c9
-rw-r--r--gcc/fortran/cpp.h2
-rw-r--r--gcc/fortran/f95-lang.c4
-rw-r--r--gcc/fortran/gfortran.h4
-rw-r--r--gcc/fortran/options.c19
-rw-r--r--gcc/fortran/scanner.c27
-rw-r--r--gcc/testsuite/gfortran.dg/include_14.f907
-rw-r--r--gcc/testsuite/gfortran.dg/include_15.f907
-rw-r--r--gcc/testsuite/gfortran.dg/include_16.f902
-rw-r--r--gcc/testsuite/gfortran.dg/include_17.f904
-rw-r--r--gcc/testsuite/gfortran.dg/include_18.f904
-rw-r--r--gcc/testsuite/gfortran.dg/include_19.f902
13 files changed, 61 insertions, 36 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4acb941..ba98eab 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6459,10 +6459,12 @@ int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @};
This warning is enabled by @option{-Wall}.
-@item -Wmissing-include-dirs @r{(C, C++, Objective-C and Objective-C++ only)}
+@item -Wmissing-include-dirs @r{(C, C++, Objective-C, Objective-C++ and Fortran only)}
@opindex Wmissing-include-dirs
@opindex Wno-missing-include-dirs
-Warn if a user-supplied include directory does not exist.
+Warn if a user-supplied include directory does not exist. This opions is disabled
+by default for C, C++, Objective-C and Objective-C++. For Fortran, it is partially
+enabled by default by warning for -I and -J, only.
@item -Wno-missing-profile
@opindex Wmissing-profile
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index 3ff8954..e86386c 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -245,11 +245,12 @@ gfc_cpp_temporary_file (void)
}
static void
-gfc_cpp_register_include_paths (void)
+gfc_cpp_register_include_paths (bool verbose_missing_dir_warn)
{
int cxx_stdinc = 0;
cpp_get_options (cpp_in)->warn_missing_include_dirs
- = global_options.x_cpp_warn_missing_include_dirs;
+ = (global_options.x_cpp_warn_missing_include_dirs
+ && verbose_missing_dir_warn);
register_include_chains (cpp_in, gfc_cpp_option.sysroot,
gfc_cpp_option.prefix, gfc_cpp_option.multilib,
gfc_cpp_option.standard_include_paths, cxx_stdinc,
@@ -484,7 +485,7 @@ gfc_cpp_init_cb (void)
}
void
-gfc_cpp_post_options (void)
+gfc_cpp_post_options (bool verbose_missing_dir_warn)
{
/* Any preprocessing-related option without '-cpp' is considered
an error. */
@@ -547,7 +548,7 @@ gfc_cpp_post_options (void)
diagnostic_initialize_input_context (global_dc, nullptr, true);
gfc_cpp_init_cb ();
- gfc_cpp_register_include_paths ();
+ gfc_cpp_register_include_paths (verbose_missing_dir_warn);
}
diff --git a/gcc/fortran/cpp.h b/gcc/fortran/cpp.h
index 5cb7e5a..44644a2 100644
--- a/gcc/fortran/cpp.h
+++ b/gcc/fortran/cpp.h
@@ -41,7 +41,7 @@ void gfc_cpp_init_options (unsigned int decoded_options_count,
int gfc_cpp_handle_option(size_t scode, const char *arg, int value);
-void gfc_cpp_post_options (void);
+void gfc_cpp_post_options (bool);
bool gfc_cpp_preprocess (const char *source_file);
diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c
index 026228d..58dcaf0 100644
--- a/gcc/fortran/f95-lang.c
+++ b/gcc/fortran/f95-lang.c
@@ -259,8 +259,8 @@ gfc_init (void)
gfc_init_1 ();
- if (!gfc_new_file ())
- fatal_error (input_location, "cannot open input file: %s", gfc_source_file);
+ /* Calls exit in case of a fail. */
+ gfc_new_file ();
if (flag_preprocess_only)
return false;
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 3c7a843..7ef835b 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3032,7 +3032,7 @@ void gfc_scanner_init_1 (void);
void gfc_add_include_path (const char *, bool, bool, bool, bool);
void gfc_add_intrinsic_modules_path (const char *);
void gfc_release_include_path (void);
-void gfc_check_include_dirs (void);
+void gfc_check_include_dirs (bool);
FILE *gfc_open_included_file (const char *, bool, bool);
int gfc_at_end (void);
@@ -3064,7 +3064,7 @@ gfc_char_t gfc_peek_char (void);
char gfc_peek_ascii_char (void);
void gfc_error_recovery (void);
void gfc_gobble_whitespace (void);
-bool gfc_new_file (void);
+void gfc_new_file (void);
const char * gfc_read_orig_filename (const char *, const char **);
extern gfc_source_form gfc_current_form;
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index d789397..016b704 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -251,14 +251,20 @@ gfc_post_options (const char **pfilename)
{
const char *filename = *pfilename, *canon_source_file = NULL;
char *source_path;
+ bool verbose_missing_dir_warn;
int i;
/* This needs to be after the commandline has been processed.
In Fortran, the options is by default enabled, in C/C++
- by default disabled. */
+ by default disabled.
+ If not enabled explicitly by the user, only warn for -I
+ and -J, otherwise warn for all include paths. */
+ verbose_missing_dir_warn
+ = (global_options_set.x_cpp_warn_missing_include_dirs
+ && global_options.x_cpp_warn_missing_include_dirs);
SET_OPTION_IF_UNSET (&global_options, &global_options_set,
cpp_warn_missing_include_dirs, 1);
- gfc_check_include_dirs ();
+ gfc_check_include_dirs (verbose_missing_dir_warn);
/* Finalize DEC flags. */
post_dec_flags (flag_dec);
@@ -339,10 +345,13 @@ gfc_post_options (const char **pfilename)
source_path = (char *) alloca (i + 1);
memcpy (source_path, canon_source_file, i);
source_path[i] = 0;
- gfc_add_include_path (source_path, true, true, true, false);
+ /* Only warn if the directory is different from the input file as
+ if that one is not found, already an error is shown. */
+ bool warn = gfc_option.flag_preprocessed && gfc_source_file != filename;
+ gfc_add_include_path (source_path, true, true, warn, false);
}
else
- gfc_add_include_path (".", true, true, true, false);
+ gfc_add_include_path (".", true, true, false, false);
if (canon_source_file != gfc_source_file)
free (CONST_CAST (char *, canon_source_file));
@@ -490,7 +499,7 @@ gfc_post_options (const char **pfilename)
gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
MAX_SUBRECORD_LENGTH);
- gfc_cpp_post_options ();
+ gfc_cpp_post_options (verbose_missing_dir_warn);
if (gfc_option.allow_std & GFC_STD_F2008)
lang_hooks.name = "GNU Fortran2008";
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 6fe74bd..52124bd 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -307,9 +307,9 @@ gfc_do_check_include_dir (const char *path, bool warn)
if (errno != ENOENT)
gfc_warning_now (0, "Include directory %qs: %s",
path, xstrerror(errno));
- else if (warn && !gfc_cpp_enabled ())
+ else if (warn)
gfc_warning_now (OPT_Wmissing_include_dirs,
- "Nonexistent include directory %qs", path);
+ "Nonexistent include directory %qs", path);
return false;
}
else if (!S_ISDIR (st.st_mode))
@@ -323,7 +323,7 @@ gfc_do_check_include_dir (const char *path, bool warn)
/* In order that -W(no-)missing-include-dirs works, the diagnostic can only be
run after processing the commandline. */
static void
-gfc_do_check_include_dirs (gfc_directorylist **list)
+gfc_do_check_include_dirs (gfc_directorylist **list, bool do_warn)
{
gfc_directorylist *prev, *q, *n;
prev = NULL;
@@ -331,7 +331,7 @@ gfc_do_check_include_dirs (gfc_directorylist **list)
while (n)
{
q = n; n = n->next;
- if (gfc_do_check_include_dir (q->path, q->warn))
+ if (gfc_do_check_include_dir (q->path, q->warn && do_warn))
{
prev = q;
continue;
@@ -346,10 +346,16 @@ gfc_do_check_include_dirs (gfc_directorylist **list)
}
void
-gfc_check_include_dirs ()
+gfc_check_include_dirs (bool verbose_missing_dir_warn)
{
- gfc_do_check_include_dirs (&include_dirs);
- gfc_do_check_include_dirs (&intrinsic_modules_dirs);
+ /* This is a bit convoluted: If gfc_cpp_enabled () and
+ verbose_missing_dir_warn, the warning is shown by libcpp. Otherwise,
+ it is shown here, still conditional on OPT_Wmissing_include_dirs. */
+ bool warn = !gfc_cpp_enabled () || !verbose_missing_dir_warn;
+ gfc_do_check_include_dirs (&include_dirs, warn);
+ gfc_do_check_include_dirs (&intrinsic_modules_dirs, verbose_missing_dir_warn);
+ if (gfc_option.module_dir && gfc_cpp_enabled ())
+ gfc_do_check_include_dirs (&include_dirs, true);
}
/* Adds path to the list pointed to by list. */
@@ -2771,7 +2777,7 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
it tries to determine the source form from the filename, defaulting
to free form. */
-bool
+void
gfc_new_file (void)
{
bool result;
@@ -2789,6 +2795,9 @@ gfc_new_file (void)
else
result = load_file (gfc_source_file, NULL, true);
+ if (!result)
+ exit (FATAL_EXIT_CODE);
+
gfc_current_locus.lb = line_head;
gfc_current_locus.nextc = (line_head == NULL) ? NULL : line_head->line;
@@ -2799,8 +2808,6 @@ gfc_new_file (void)
exit (SUCCESS_EXIT_CODE);
#endif
-
- return result;
}
static char *
diff --git a/gcc/testsuite/gfortran.dg/include_14.f90 b/gcc/testsuite/gfortran.dg/include_14.f90
index b306b2c..8110e49 100644
--- a/gcc/testsuite/gfortran.dg/include_14.f90
+++ b/gcc/testsuite/gfortran.dg/include_14.f90
@@ -1,5 +1,6 @@
-! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar" }
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -J foo/bar" }
end
+! default: warn for -I and -J but ignore other options.
+! { dg-warning "Nonexistent include directory 'bar/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'foo/bar/'" "" { target *-*-* } 0 }
-! { dg-warning "/fdaf/: No such file or directory" "" { target *-*-* } 0 }
-! { dg-warning "bar: No such file or directory" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gfortran.dg/include_15.f90 b/gcc/testsuite/gfortran.dg/include_15.f90
index 4944282..068dcef 100644
--- a/gcc/testsuite/gfortran.dg/include_15.f90
+++ b/gcc/testsuite/gfortran.dg/include_15.f90
@@ -1,5 +1,6 @@
-! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -Wmissing-include-dirs" }
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -J foo/bar -Wmissing-include-dirs" }
end
-! { dg-warning "/fdaf/: No such file or directory" "" { target *-*-* } 0 }
-! { dg-warning "bar: No such file or directory" "" { target *-*-* } 0 }
+! { dg-warning " /fdaf/: No such file or directory" "" { target *-*-* } 0 }
+! { dg-warning " bar: No such file or directory" "" { target *-*-* } 0 }
+! { dg-warning " foo/bar: No such file or directory" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gfortran.dg/include_16.f90 b/gcc/testsuite/gfortran.dg/include_16.f90
index 45794f2..65e4c7e 100644
--- a/gcc/testsuite/gfortran.dg/include_16.f90
+++ b/gcc/testsuite/gfortran.dg/include_16.f90
@@ -1,2 +1,2 @@
-! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -Wno-missing-include-dirs" }
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -J foo/bar -Wno-missing-include-dirs" }
end
diff --git a/gcc/testsuite/gfortran.dg/include_17.f90 b/gcc/testsuite/gfortran.dg/include_17.f90
index 0ed5c86d..0667759 100644
--- a/gcc/testsuite/gfortran.dg/include_17.f90
+++ b/gcc/testsuite/gfortran.dg/include_17.f90
@@ -1,4 +1,6 @@
! { dg-do compile }
-! { dg-options "-I foo-bar -Wno-missing-include-dirs" }
+! { dg-options "-I foo-bar -J foo/bar" }
end
+! { dg-warning "Nonexistent include directory 'foo-bar/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'foo/bar/'" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gfortran.dg/include_18.f90 b/gcc/testsuite/gfortran.dg/include_18.f90
index ca69df3..b74a585 100644
--- a/gcc/testsuite/gfortran.dg/include_18.f90
+++ b/gcc/testsuite/gfortran.dg/include_18.f90
@@ -1,3 +1,5 @@
! { dg-do compile }
-! { dg-options "-I nothere -Wno-missing-include-dirs" }
+! { dg-options "-I nothere -J neither/here -Wmissing-include-dirs" }
end
+! { dg-warning "Nonexistent include directory 'nothere/'" "" { target *-*-* } 0 }
+! { dg-warning "Nonexistent include directory 'neither/here/'" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gfortran.dg/include_19.f90 b/gcc/testsuite/gfortran.dg/include_19.f90
index 2a06817..7404929 100644
--- a/gcc/testsuite/gfortran.dg/include_19.f90
+++ b/gcc/testsuite/gfortran.dg/include_19.f90
@@ -1,4 +1,4 @@
! { dg-do compile }
-! { dg-options "-J foobar/foo -Wno-missing-include-dirs" }
+! { dg-options "-I nothere -J foobar/foo -Wno-missing-include-dirs" }
program main
end program main