aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/cpp.c
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2021-09-21 08:27:00 +0200
committerTobias Burnus <tobias@codesourcery.com>2021-09-21 08:28:30 +0200
commit417ea5c02cef7f000e66d1af22b066c2c1cda047 (patch)
tree1212ed64ad39e507f11d767384a56c08136a7d36 /gcc/fortran/cpp.c
parent63c6446f77b9001d26f973114450d790749f282b (diff)
downloadgcc-417ea5c02cef7f000e66d1af22b066c2c1cda047.zip
gcc-417ea5c02cef7f000e66d1af22b066c2c1cda047.tar.gz
gcc-417ea5c02cef7f000e66d1af22b066c2c1cda047.tar.bz2
Fortran: Fix -Wno-missing-include-dirs handling [PR55534]
gcc/fortran/ChangeLog: PR fortran/55534 * cpp.c: Define GCC_C_COMMON_C for #include "options.h" to make cpp_reason_option_codes available. (gfc_cpp_register_include_paths): Make static, set pfile's warn_missing_include_dirs and move before caller. (gfc_cpp_init_cb): New, cb code moved from ... (gfc_cpp_init_0): ... here. (gfc_cpp_post_options): Call gfc_cpp_init_cb. (cb_cpp_diagnostic_cpp_option): New. As implemented in c-family to match CppReason flags to -W... names. (cb_cpp_diagnostic): Use it to replace single special case. * cpp.h (gfc_cpp_register_include_paths): Remove as now static. * gfortran.h (gfc_check_include_dirs): New prototype. (gfc_add_include_path): Add new bool arg. * options.c (gfc_init_options): Don't set -Wmissing-include-dirs. (gfc_post_options): Set it here after commandline processing. Call gfc_add_include_path with defer_warn=false. (gfc_handle_option): Call it with defer_warn=true. * scanner.c (gfc_do_check_include_dir, gfc_do_check_include_dirs, gfc_check_include_dirs): New. Diagnostic moved from ... (add_path_to_list): ... here, which came before cmdline processing. Take additional bool defer_warn argument. (gfc_add_include_path): Take additional defer_warn arg. * scanner.h (struct gfc_directorylist): Reorder for alignment issues, add new 'bool warn'. libgfortran/ChangeLog: PR fortran/55534 * configure.ac (AM_FCFLAGS): Add -Wno-missing-include-dirs. * configure: Regenerate. libgomp/ChangeLog: PR fortran/55534 * testsuite/libgomp.fortran/fortran.exp: Add -Wno-missing-include-dirs to ALWAYS_CFLAGS. * testsuite/libgomp.oacc-fortran/fortran.exp: Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/include_6.f90: Change dg-error to dg-warning and update pattern. * gfortran.dg/include_14.f90: New test. * gfortran.dg/include_15.f90: New test. * gfortran.dg/include_16.f90: New test. * gfortran.dg/include_17.f90: New test. * gfortran.dg/include_18.f90: New test. * gfortran.dg/include_19.f90: New test. * gfortran.dg/include_20.f90: New test. * gfortran.dg/include_21.f90: New test.
Diffstat (limited to 'gcc/fortran/cpp.c')
-rw-r--r--gcc/fortran/cpp.c106
1 files changed, 66 insertions, 40 deletions
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index 83c4517..3ff8954 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -19,11 +19,15 @@ along with GCC; see the file COPYING3. If not see
#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"
@@ -240,6 +244,18 @@ gfc_cpp_temporary_file (void)
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)
@@ -435,6 +451,37 @@ gfc_cpp_handle_option (size_t scode, const char *arg, int value 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)
@@ -498,6 +545,7 @@ 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 ();
}
@@ -506,32 +554,6 @@ gfc_cpp_post_options (void)
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. */
@@ -723,17 +745,6 @@ gfc_cpp_add_include_path_after (char *path, bool user_supplied)
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);
@@ -1043,6 +1054,21 @@ cb_used_define (cpp_reader *pfile, location_t line ATTRIBUTE_UNUSED,
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
@@ -1089,8 +1115,8 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
}
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;