aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/cpp.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-09-21 14:32:26 -0700
committerIan Lance Taylor <iant@golang.org>2021-09-21 14:32:26 -0700
commita5b5cabc91c38710adbe5c8a2b53882abe994441 (patch)
tree66b099a6ebc2076ef353afa90d9703824d023812 /gcc/fortran/cpp.c
parenta0791d0ed4f147ef347e83f4aedc7ad03f1a2008 (diff)
parent09e18d113b3c3dae896ac1a8ad1e0087adbb153b (diff)
downloadgcc-a5b5cabc91c38710adbe5c8a2b53882abe994441.zip
gcc-a5b5cabc91c38710adbe5c8a2b53882abe994441.tar.gz
gcc-a5b5cabc91c38710adbe5c8a2b53882abe994441.tar.bz2
Merge from trunk revision 09e18d113b3c3dae896ac1a8ad1e0087adbb153b.
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;