#include "config.h"
#include "system.h"
#include "coretypes.h"
+
+#define GCC_C_COMMON_C
+#include "options.h" /* For cpp_reason_option_codes. */
+#undef GCC_C_COMMON_C
+
#include "target.h"
#include "gfortran.h"
#include "diagnostic.h"
-
#include "toplev.h"
#include "../../libcpp/internal.h"
return gfc_cpp_option.temporary_filename;
}
+static void
+gfc_cpp_register_include_paths (void)
+{
+ int cxx_stdinc = 0;
+ cpp_get_options (cpp_in)->warn_missing_include_dirs
+ = global_options.x_cpp_warn_missing_include_dirs;
+ 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,
+ gfc_cpp_option.verbose);
+}
+
void
gfc_cpp_init_options (unsigned int decoded_options_count,
struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
return result;
}
+/* This function needs to be called before gfc_cpp_register_include_paths
+ as the latter may diagnose missing include directories. */
+static void
+gfc_cpp_init_cb (void)
+{
+ struct cpp_callbacks *cb;
+
+ cb = cpp_get_callbacks (cpp_in);
+ cb->file_change = cb_file_change;
+ cb->line_change = cb_line_change;
+ cb->ident = cb_ident;
+ cb->def_pragma = cb_def_pragma;
+ cb->diagnostic = cb_cpp_diagnostic;
+
+ if (gfc_cpp_option.dump_includes)
+ cb->include = cb_include;
+
+ if ((gfc_cpp_option.dump_macros == 'D')
+ || (gfc_cpp_option.dump_macros == 'N'))
+ {
+ cb->define = cb_define;
+ cb->undef = cb_undef;
+ }
+
+ if (gfc_cpp_option.dump_macros == 'U')
+ {
+ cb->before_define = dump_queued_macros;
+ cb->used_define = cb_used_define;
+ cb->used_undef = cb_used_undef;
+ }
+}
void
gfc_cpp_post_options (void)
way libcpp will do it, namely, with no charset conversion but with
skipping of a UTF-8 BOM if present. */
diagnostic_initialize_input_context (global_dc, nullptr, true);
+ gfc_cpp_init_cb ();
gfc_cpp_register_include_paths ();
}
void
gfc_cpp_init_0 (void)
{
- struct cpp_callbacks *cb;
-
- cb = cpp_get_callbacks (cpp_in);
- cb->file_change = cb_file_change;
- cb->line_change = cb_line_change;
- cb->ident = cb_ident;
- cb->def_pragma = cb_def_pragma;
- cb->diagnostic = cb_cpp_diagnostic;
-
- if (gfc_cpp_option.dump_includes)
- cb->include = cb_include;
-
- if ((gfc_cpp_option.dump_macros == 'D')
- || (gfc_cpp_option.dump_macros == 'N'))
- {
- cb->define = cb_define;
- cb->undef = cb_undef;
- }
-
- if (gfc_cpp_option.dump_macros == 'U')
- {
- cb->before_define = dump_queued_macros;
- cb->used_define = cb_used_define;
- cb->used_undef = cb_used_undef;
- }
-
/* Initialize the print structure. Setting print.src_line to -1 here is
a trick to guarantee that the first token of the file will cause
a linemarker to be output by maybe_print_line. */
add_path (path, INC_AFTER, cxx_aware, user_supplied);
}
-void
-gfc_cpp_register_include_paths (void)
-{
- int cxx_stdinc = 0;
- 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,
- gfc_cpp_option.verbose);
-}
-
-
static void scan_translation_unit_trad (cpp_reader *);
static void account_for_newlines (const unsigned char *, size_t);
cpp_define_queue = q;
}
+/* Return the gcc option code associated with the reason for a cpp
+ message, or 0 if none. */
+
+static int
+cb_cpp_diagnostic_cpp_option (enum cpp_warning_reason reason)
+{
+ const struct cpp_reason_option_codes_t *entry;
+
+ for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
+ if (entry->reason == reason)
+ return entry->option_code;
+ return 0;
+}
+
+
/* Callback from cpp_error for PFILE to print diagnostics from the
preprocessor. The diagnostic is of type LEVEL, with REASON set
to the reason code if LEVEL is represents a warning, at location
}
diagnostic_set_info_translated (&diagnostic, msg, ap,
richloc, dlevel);
- if (reason == CPP_W_WARNING_DIRECTIVE)
- diagnostic_override_option_index (&diagnostic, OPT_Wcpp);
+ diagnostic_override_option_index (&diagnostic,
+ cb_cpp_diagnostic_cpp_option (reason));
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
global_dc->dc_warn_system_headers = save_warn_system_headers;
void gfc_cpp_add_include_path (char *path, bool user_supplied);
void gfc_cpp_add_include_path_after (char *path, bool user_supplied);
-void gfc_cpp_register_include_paths (void);
-
#endif /* GFC_CPP_H */
void gfc_scanner_done_1 (void);
void gfc_scanner_init_1 (void);
-void gfc_add_include_path (const char *, bool, bool, bool);
+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);
FILE *gfc_open_included_file (const char *, bool, bool);
int gfc_at_end (void);
| GFC_FPE_UNDERFLOW;
gfc_option.rtcheck = 0;
- /* ??? 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. */
- SET_OPTION_IF_UNSET (&global_options, &global_options_set,
- cpp_warn_missing_include_dirs, 1);
-
set_dec_flags (0);
-
set_default_std_flags ();
/* Initialize cpp-related options. */
char *source_path;
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. */
+ SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+ cpp_warn_missing_include_dirs, 1);
+ gfc_check_include_dirs ();
+
/* Finalize DEC flags. */
post_dec_flags (flag_dec);
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);
+ gfc_add_include_path (source_path, true, true, true, false);
}
else
- gfc_add_include_path (".", true, true, true);
+ gfc_add_include_path (".", true, true, true, false);
if (canon_source_file != gfc_source_file)
free (CONST_CAST (char *, canon_source_file));
gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
strcpy (gfc_option.module_dir, arg);
- gfc_add_include_path (gfc_option.module_dir, true, false, true);
+ gfc_add_include_path (gfc_option.module_dir, true, false, true, true);
strcat (gfc_option.module_dir, "/");
}
with intrinsic modules. Do no warn because during testing
without an installed compiler, we would get lots of bogus
warnings for a missing include directory. */
- gfc_add_include_path (arg, false, false, false);
+ gfc_add_include_path (arg, false, false, false, true);
gfc_add_intrinsic_modules_path (arg);
break;
break;
case OPT_I:
- gfc_add_include_path (arg, true, false, true);
+ gfc_add_include_path (arg, true, false, true, true);
break;
case OPT_J:
}
}
+static bool
+gfc_do_check_include_dir (const char *path, bool warn)
+{
+ struct stat st;
+ if (stat (path, &st))
+ {
+ if (errno != ENOENT)
+ gfc_warning_now (0, "Include directory %qs: %s",
+ path, xstrerror(errno));
+ else if (warn && !gfc_cpp_enabled ())
+ gfc_warning_now (OPT_Wmissing_include_dirs,
+ "Nonexistent include directory %qs", path);
+ return false;
+ }
+ else if (!S_ISDIR (st.st_mode))
+ {
+ gfc_fatal_error ("%qs is not a directory", path);
+ return false;
+ }
+ return true;
+}
+
+/* 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_directorylist *prev, *q, *n;
+ prev = NULL;
+ n = *list;
+ while (n)
+ {
+ q = n; n = n->next;
+ if (gfc_do_check_include_dir (q->path, q->warn))
+ {
+ prev = q;
+ continue;
+ }
+ if (prev == NULL)
+ *list = n;
+ else
+ prev->next = n;
+ free (q->path);
+ free (q);
+ }
+}
+
+void
+gfc_check_include_dirs ()
+{
+ gfc_do_check_include_dirs (&include_dirs);
+ gfc_do_check_include_dirs (&intrinsic_modules_dirs);
+}
/* Adds path to the list pointed to by list. */
static void
add_path_to_list (gfc_directorylist **list, const char *path,
- bool use_for_modules, bool head, bool warn)
+ bool use_for_modules, bool head, bool warn, bool defer_warn)
{
gfc_directorylist *dir;
const char *p;
char *q;
- struct stat st;
size_t len;
int i;
while (i >=0 && IS_DIR_SEPARATOR (q[i]))
q[i--] = '\0';
- if (stat (q, &st))
- {
- if (errno != ENOENT)
- gfc_warning_now (0, "Include directory %qs: %s", path,
- xstrerror(errno));
- else if (warn)
- gfc_warning_now (OPT_Wmissing_include_dirs,
- "Nonexistent include directory %qs", path);
- return;
- }
- else if (!S_ISDIR (st.st_mode))
- {
- gfc_fatal_error ("%qs is not a directory", path);
- return;
- }
+ if (!defer_warn && !gfc_do_check_include_dir (q, warn))
+ return;
if (head || *list == NULL)
{
if (head)
*list = dir;
dir->use_for_modules = use_for_modules;
+ dir->warn = warn;
dir->path = XCNEWVEC (char, strlen (p) + 2);
strcpy (dir->path, p);
strcat (dir->path, "/"); /* make '/' last character */
}
+/* defer_warn is set to true while parsing the commandline. */
void
gfc_add_include_path (const char *path, bool use_for_modules, bool file_dir,
- bool warn)
+ bool warn, bool defer_warn)
{
- add_path_to_list (&include_dirs, path, use_for_modules, file_dir, warn);
+ add_path_to_list (&include_dirs, path, use_for_modules, file_dir, warn,
+ defer_warn);
/* For '#include "..."' these directories are automatically searched. */
if (!file_dir)
void
gfc_add_intrinsic_modules_path (const char *path)
{
- add_path_to_list (&intrinsic_modules_dirs, path, true, false, false);
+ add_path_to_list (&intrinsic_modules_dirs, path, true, false, false, false);
}
typedef struct gfc_directorylist
{
char *path;
- bool use_for_modules;
struct gfc_directorylist *next;
+ bool use_for_modules, warn;
}
gfc_directorylist;
--- /dev/null
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar" }
+end
+
+! { dg-warning "/fdaf/: No such file or directory" "" { target *-*-* } 0 }
+! { dg-warning "bar: No such file or directory" "" { target *-*-* } 0 }
--- /dev/null
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I 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 }
--- /dev/null
+! { dg-additional-options "-cpp -idirafter /fdaf/ -I bar -Wno-missing-include-dirs" }
+end
--- /dev/null
+! { dg-do compile }
+! { dg-options "-I foo-bar -Wno-missing-include-dirs" }
+end
+
--- /dev/null
+! { dg-do compile }
+! { dg-options "-I nothere -Wno-missing-include-dirs" }
+end
--- /dev/null
+! { dg-do compile }
+! { dg-options "-J foobar/foo -Wno-missing-include-dirs" }
+program main
+end program main
--- /dev/null
+! { dg-do compile }
+! { dg-options "-J foobar/foo" }
+program main
+end program main
+! { dg-warning "Nonexistent include directory" "" { target *-*-* } 0 }
--- /dev/null
+# 1 "../../../trunk/libgfortran/generated/_abs_c4.F90"
+# 1 "C:\\msys\\1.0.10\\home\\FX\\ibin\\i586-pc-mingw32\\libgfortran//"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "../../../trunk/libgfortran/generated/_abs_c4.F90"
+! Comment here
+
+# 1 "./config.h" 1
+
+# 37 "../../../trunk/libgfortran/generated/_abs_c4.F90" 2
+
+# 1 "./kinds.inc" 1
+# 38 "../../../trunk/libgfortran/generated/_abs_c4.F90" 2
+
+# 1 "./c99_protos.inc" 1
+# 39 "../../../trunk/libgfortran/generated/_abs_c4.F90" 2
+
+elemental function abs_c4 (parm)
+ complex (kind=4), intent (in) :: parm
+ real (kind=4) :: abs_c4
+
+ abs_c4 = abs (parm)
+end function
+
+! { dg-do compile }
+! { dg-options "-fpreprocessed -g3 -Wno-missing-include-dirs" }
! { dg-do compile }
! { dg-options "-I gfortran.log" }
-! { dg-error "is not a directory" "" { target *-*-* } 0 }
+! { dg-warning "Include directory 'gfortran.log/': Not a directory" "" { target *-*-* } 0 }
! { dg-prune-output "compilation terminated." }
end
# Add -Wall -fno-repack-arrays -fno-underscoring if we are using GCC.
if test "x$GCC" = "xyes"; then
- AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays -fno-underscoring"
+ AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays -fno-underscoring -Wno-missing-include-dirs"
## We like to use C11 and C99 routines when available. This makes
## sure that
## __STDC_VERSION__ is set such that libc includes make them available.
# Add -Wall -fno-repack-arrays -fno-underscoring if we are using GCC.
if test "x$GCC" = "xyes"; then
- AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays -fno-underscoring"
+ AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays -fno-underscoring -Wno-missing-include-dirs"
## We like to use C11 and C99 routines when available. This makes
## sure that
## __STDC_VERSION__ is set such that libc includes make them available.
# Turn on OpenMP.
lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
+# Silence warnings due to explicitly passed but nonexisting
+# -isystem <instdir>/target>/{sys-,}include (gfortran warns by default)
+lappend ALWAYS_CFLAGS "additional_flags=-Wno-missing-include-dirs"
if { $blddir != "" } {
set lang_source_re {^.*\.[fF](|90|95|03|08)$}
# Turn on OpenACC.
lappend ALWAYS_CFLAGS "additional_flags=-fopenacc"
+# Silence warnings due to explicitly passed but nonexisting
+# -isystem <instdir>/target>/{sys-,}include (gfortran warns by default)
+lappend ALWAYS_CFLAGS "additional_flags=-Wno-missing-include-dirs"
if { $blddir != "" } {
set lang_source_re {^.*\.[fF](|90|95|03|08)$}