diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-01-10 08:33:48 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-01-10 08:33:48 -0500 |
commit | be2bf5dc93ca1ec148c605a5f25b3f7a3028bf3d (patch) | |
tree | e1f6b7e553c22d4ccbf4789636816338b8440a48 /gcc/gcc-urlifier.cc | |
parent | 5daf9104ed5d4ef21b01e9564e5325adb157e5d8 (diff) | |
download | gcc-be2bf5dc93ca1ec148c605a5f25b3f7a3028bf3d.zip gcc-be2bf5dc93ca1ec148c605a5f25b3f7a3028bf3d.tar.gz gcc-be2bf5dc93ca1ec148c605a5f25b3f7a3028bf3d.tar.bz2 |
gcc-urlifier: handle option prefixes such as '-fno-'
Given e.g. this missppelled option (omitting the trailing 's'):
$ LANG=C ./xgcc -B. -fno-inline-small-function
xgcc: error: unrecognized command-line option '-fno-inline-small-function'; did you mean '-fno-inline-small-functions'?
we weren't providing a documentation URL for the suggestion.
The issue is the URLification code uses find_opt, which doesn't consider
the various '-fno-' prefixes.
This patch adds a way to find the pertinent prefix remapping and uses it
when determining URLs.
With this patch, the suggestion '-fno-inline-small-functions' now gets a
documentation link (to that of '-finline-small-functions').
gcc/ChangeLog:
* gcc-urlifier.cc (gcc_urlifier::get_url_suffix_for_option):
Handle prefix mappings before calling find_opt.
(selftest::gcc_urlifier_cc_tests): Add example of urlifying a
"-fno-"-prefixed command-line option.
* opts-common.cc (get_option_prefix_remapping): New.
* opts.h (get_option_prefix_remapping): New decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/gcc-urlifier.cc')
-rw-r--r-- | gcc/gcc-urlifier.cc | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/gcc/gcc-urlifier.cc b/gcc/gcc-urlifier.cc index 6bd176f..be6459e 100644 --- a/gcc/gcc-urlifier.cc +++ b/gcc/gcc-urlifier.cc @@ -154,11 +154,46 @@ gcc_urlifier::get_url_suffix_for_option (const char *p, size_t sz) const and skipping the leading '-'. We have a (pointer,size) pair that doesn't necessarily have a - terminator, so create a 0-terminated clone of the string. */ - gcc_assert (sz > 0); - char *tmp = xstrndup (p + 1, sz - 1); // skip the leading '-' - size_t opt = find_opt (tmp, m_lang_mask); - free (tmp); + terminator. + Additionally, we could have one of the e.g. "-Wno-" variants of + the option, which find_opt doesn't handle. + + Hence we need to create input for find_opt in a temporary buffer. */ + char *option_buffer; + + const char *new_prefix; + if (const char *old_prefix = get_option_prefix_remapping (p, sz, &new_prefix)) + { + /* We have one of the variants; generate a buffer containing a copy + that maps from the old prefix to the new prefix + e.g. given "-Wno-suffix", generate "-Wsuffix". */ + gcc_assert (old_prefix[0] == '-'); + gcc_assert (new_prefix); + gcc_assert (new_prefix[0] == '-'); + + const size_t old_prefix_len = strlen (old_prefix); + gcc_assert (old_prefix_len <= sz); + const size_t suffix_len = sz - old_prefix_len; + const size_t new_prefix_len = strlen (new_prefix); + const size_t new_sz = new_prefix_len + suffix_len + 1; + + option_buffer = (char *)xmalloc (new_sz); + memcpy (option_buffer, new_prefix, new_prefix_len); + /* Copy suffix. */ + memcpy (option_buffer + new_prefix_len, p + old_prefix_len, suffix_len); + /* Terminate. */ + option_buffer[new_prefix_len + suffix_len] = '\0'; + } + else + { + /* Otherwise we can simply create a 0-terminated clone of the string. */ + gcc_assert (sz > 0); + gcc_assert (p[0] == '-'); + option_buffer = xstrndup (p, sz); + } + + size_t opt = find_opt (option_buffer + 1, m_lang_mask); + free (option_buffer); if (opt >= N_OPTS) /* Option not recognized. */ @@ -221,6 +256,10 @@ gcc_urlifier_cc_tests () /* Check an option. */ ASSERT_STREQ (u.get_url_suffix_for_quoted_text ("-fpack-struct").get (), "gcc/Code-Gen-Options.html#index-fpack-struct"); + + /* Check a "-fno-" variant of an option. */ + ASSERT_STREQ (u.get_url_suffix_for_quoted_text ("-fno-inline").get (), + "gcc/Optimize-Options.html#index-finline"); } } // namespace selftest |