summaryrefslogtreecommitdiff
path: root/gcc/opts-common.c
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2017-09-21 02:18:02 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2017-09-21 02:18:02 +0000
commit9ed32e278609dd7544366ac3639b7ecb5ad4d60f (patch)
treefa8b7dc93538e14e6db4ef2d2018a93b37b51dca /gcc/opts-common.c
parentd8a61466b974a7ed4a7cafcbb98903bc71f5021d (diff)
enable handling of -gno- command-line options as negated prefixes
This patch that adds -g to the set of negatable prefixes along with -f, -m and -W. Besides the mapping from -gno- to negated -g in option_map and adding g to the [fmW] matches for negatable options, I had to introduce gno- as an remapping prefix, for the option searching machinery to backtrack to and recognize as a remapping prefix, instead of backtracking to -g and stopping at it as if no-* was its Joined argument. Adding such remapping prefixes to preempt further backtracking can be accomplished by introducing the prefix as an Undocumented option with a Joined argument and without Driver, Target, Common, or any language-specific option. Whenever we match such a fake options prefix, we abandon further backtracking (it matches, after all), but find_opt returns the same code it would if it hadn't found any match, so that we resort to option mapping. I've arranged for such remapping prefixes to not be considered when looking for and suggesting a correct spelling for misspelled options. While testing that, I found a few -W-started options that were not marked as RejectNegative but should (-Wno-a, is not something we'd like to suggest ;-) I've also marked as such -g-started options that it makes no sense to negate, and removed the explicit -gno- ones, allowing their opposites to be negated. for gcc/ChangeLog * common.opt (Wa, Wl, Wp, g, gz=): Add RejectNegative. (gno-column-info): Remove. (gcolumn-info): Drop RejectNegative. (gno-): New prefix. (gno-record-gcc-switches): Remove. (grecord-gcc-switches): Drop RejectNegative. (gno-split-dwarf): Remove. (gsplit-dwarf): Drop RejectNegative. (gno-strict-dwarf): Remove. (gstrict-dwarf): Drop RejectNegative. * config/darwin.opt (gfull, gused): Add RejectNegative. * dwarf2out.c (gen_producer_string): Drop gno-record-gcc-switches handler. * optc-gen.awk: Add g to prefixes with negative forms. * opts-common.c (remapping_prefix_p): New. (find_opt): Check it. (generate_canonical_option): Test g prefix. (option_map): Add -gno- mapping. (add_misspelling_candidates): Check remapping_prefix_p. for gcc/ada/ChangeLog * gcc-interface/lang.opt (gant, gnatO, gnat): Add RejectNegative. for gcc/c-family/ChangeLog * c.opt (gen-decls): Add RejectNegative. From-SVN: r253047
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r--gcc/opts-common.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index d7568145768..e78ab880893 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -28,6 +28,24 @@ along with GCC; see the file COPYING3. If not see
static void prune_options (struct cl_decoded_option **, unsigned int *);
+/* An option that is undocumented, that takes a joined argument, and
+ that doesn't fit any of the classes of uses (language/common,
+ driver, target) is assumed to be a prefix used to catch
+ e.g. negated options, and stop them from being further shortened to
+ a prefix that could use the negated option as an argument. For
+ example, we want -gno-statement-frontiers to be taken as a negation
+ of -gstatement-frontiers, but without catching the gno- prefix and
+ signaling it's to be used for option remapping, it would end up
+ backtracked to g with no-statemnet-frontiers as the debug level. */
+
+static bool
+remapping_prefix_p (const struct cl_option *opt)
+{
+ return opt->flags & CL_UNDOCUMENTED
+ && opt->flags & CL_JOINED
+ && !(opt->flags & (CL_DRIVER | CL_TARGET | CL_COMMON | CL_LANG_ALL));
+}
+
/* Perform a binary search to find which option the command-line INPUT
matches. Returns its index in the option array, and
OPT_SPECIAL_unknown on failure.
@@ -98,6 +116,9 @@ find_opt (const char *input, unsigned int lang_mask)
if (opt->flags & lang_mask)
return mn;
+ if (remapping_prefix_p (opt))
+ return OPT_SPECIAL_unknown;
+
/* If we haven't remembered a prior match, remember this
one. Any prior match is necessarily better. */
if (match_wrong_lang == OPT_SPECIAL_unknown)
@@ -286,7 +307,8 @@ generate_canonical_option (size_t opt_index, const char *arg, int value,
if (value == 0
&& !option->cl_reject_negative
- && (opt_text[1] == 'W' || opt_text[1] == 'f' || opt_text[1] == 'm'))
+ && (opt_text[1] == 'W' || opt_text[1] == 'f'
+ || opt_text[1] == 'g' || opt_text[1] == 'm'))
{
char *t = XOBNEWVEC (&opts_obstack, char, option->opt_len + 5);
t[0] = '-';
@@ -349,6 +371,7 @@ static const struct option_map option_map[] =
{
{ "-Wno-", NULL, "-W", false, true },
{ "-fno-", NULL, "-f", false, true },
+ { "-gno-", NULL, "-g", false, true },
{ "-mno-", NULL, "-m", false, true },
{ "--debug=", NULL, "-g", false, false },
{ "--machine-", NULL, "-m", true, false },
@@ -394,6 +417,8 @@ add_misspelling_candidates (auto_vec<char *> *candidates,
gcc_assert (candidates);
gcc_assert (option);
gcc_assert (opt_text);
+ if (remapping_prefix_p (option))
+ return;
candidates->safe_push (xstrdup (opt_text + 1));
for (unsigned i = 0; i < ARRAY_SIZE (option_map); i++)
{