Hi.
As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39851#c0 we need
to call targetm.target_option.override () in order to properly report which
ISA options are enabled for a -march/-mtune. Currently, opts.c uses just
#include "common/common-target.h" we are unable to call the function direct.
One solution might be to put the hook to gcc/common/common-target.def, but
that would require huge refactoring of i386.c and i386-common.c files.
Thus I came with a small hook that lives in cl_option_handler_func.
With that I see proper results for test-case mentioned in the PR.
Thoughts?
Martin
>From 1bd4916c0c5594162d6a34c9eb4c7202931260df Mon Sep 17 00:00:00 2001
From: marxin
Date: Tue, 8 Aug 2017 13:09:12 +0200
Subject: [PATCH] Patch candidate.
---
gcc/c-family/c-common.c | 2 +-
gcc/c-family/c-pragma.c | 2 +-
gcc/gcc.c | 3 ++-
gcc/opts-common.c | 3 ++-
gcc/opts-global.c | 12
gcc/opts.c | 14 ++
gcc/opts.h | 18 +-
gcc/toplev.c| 3 ++-
8 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index feb0904bcbf..a2469471fe5 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5496,7 +5496,7 @@ parse_optimize_options (tree args, bool attr_p)
/* And apply them. */
decode_options (&global_options, &global_options_set,
decoded_options, decoded_options_count,
- input_location, global_dc);
+ input_location, global_dc, NULL);
targetm.override_options_after_change();
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 48b02b88bb5..3b49aefc6ff 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -815,7 +815,7 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
}
struct cl_option_handlers handlers;
- set_default_handlers (&handlers);
+ set_default_handlers (&handlers, NULL);
const char *arg = NULL;
if (cl_options[option_index].flags & CL_JOINED)
arg = option_string + 1 + cl_options[option_index].opt_len;
diff --git a/gcc/gcc.c b/gcc/gcc.c
index d8c5260e36b..fde68809d68 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3745,7 +3745,8 @@ driver_handle_option (struct gcc_options *opts,
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
location_t loc,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
- diagnostic_context *dc)
+ diagnostic_context *dc,
+ void (*) (void))
{
size_t opt_index = decoded->opt_index;
const char *arg = decoded->arg;
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 0cab42a021c..d7568145768 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -993,7 +993,8 @@ handle_option (struct gcc_options *opts,
{
if (!handlers->handlers[i].handler (opts, opts_set, decoded,
lang_mask, kind, loc,
- handlers, dc))
+ handlers, dc,
+ handlers->target_option_override_hook))
return false;
}
diff --git a/gcc/opts-global.c b/gcc/opts-global.c
index fc55512e554..343dbd3ac2c 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -169,7 +169,8 @@ lang_handle_option (struct gcc_options *opts,
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
+ diagnostic_context *dc,
+ void (*) (void))
{
gcc_assert (opts == &global_options);
gcc_assert (opts_set == &global_options_set);
@@ -269,10 +270,12 @@ decode_cmdline_options_to_array_default_mask (unsigned int argc,
/* Set *HANDLERS to the default set of option handlers for use in the
compilers proper (not the driver). */
void
-set_default_handlers (struct cl_option_handlers *handlers)
+set_default_handlers (struct cl_option_handlers *handlers,
+ void (*target_option_override_hook) (void))
{
handlers->unknown_option_callback = unknown_option_callback;
handlers->wrong_lang_callback = complain_wrong_lang;
+ handlers->target_option_override_hook = target_option_override_hook;
handlers->num_handlers = 3;
handlers->handlers[0].handler = lang_handle_option;
handlers->handlers[0].mask = initial_lang_mask;
@@ -290,7 +293,8 @@ void
decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
struct cl_decoded_option *decoded_options,
unsigned int decoded_options_count,
- location_t loc, diagnostic_context *dc)
+ location_t loc, diagnostic_context *dc,
+ void (*target_option_override_hook) (void))
{
struct cl_option_handlers handlers;
@@ -298,7 +302,7 @@ decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
lang_mask = initial_lang_mask;
- set_default_handlers (&handlers);
+ set_default_handlers (&handlers, target_option_override_hook);
default_options_optimization (opts, opts_set,
decoded_options, decoded_options_count,
diff --git a/gcc/opts.c b/gcc/opts.c