Fix warning URLs for Fortran and analyzer [PR 92830]
PR 92830 reports that we always use "gcc/Warning-Options.html" when we emit escaped documentation URLs when printing "[-Wname-of-option]" for a warning. This page is wrong for most Fortran warnings, and for analyzer warnings. I considered various schemes involving adding extra tags to the .opt format to capture where options are documented, but for now this patch fixes the issue by introducing some special-casing logic. It only fixes the URLs for warning options, not for other command-line options, but those are the only options for which get_option_url is currently called. gcc/ChangeLog: PR 92830 * configure.ac (DOCUMENTATION_ROOT_URL): Drop trailing "gcc/" from default value, so that it can by supplied by get_option_html_page. * configure: Regenerate. * opts.c: Include "selftest.h". (get_option_html_page): New function. (get_option_url): Use it. Reformat to place comments next to the expressions they refer to. (selftest::test_get_option_html_page): New. (selftest::opts_c_tests): New. * selftest-run-tests.c (selftest::run_tests): Call selftest::opts_c_tests. * selftest.h (selftest::opts_c_tests): New decl.
This commit is contained in:
parent
76458c912b
commit
fa29cf0c3f
5 changed files with 82 additions and 9 deletions
2
gcc/configure
vendored
2
gcc/configure
vendored
|
@ -7851,7 +7851,7 @@ if test "${with_documentation_root_url+set}" = set; then :
|
|||
;;
|
||||
esac
|
||||
else
|
||||
DOCUMENTATION_ROOT_URL="https://gcc.gnu.org/onlinedocs/gcc/"
|
||||
DOCUMENTATION_ROOT_URL="https://gcc.gnu.org/onlinedocs/"
|
||||
|
||||
fi
|
||||
|
||||
|
|
|
@ -982,7 +982,7 @@ AC_ARG_WITH(documentation-root-url,
|
|||
*) DOCUMENTATION_ROOT_URL="$withval"
|
||||
;;
|
||||
esac],
|
||||
DOCUMENTATION_ROOT_URL="https://gcc.gnu.org/onlinedocs/gcc/"
|
||||
DOCUMENTATION_ROOT_URL="https://gcc.gnu.org/onlinedocs/"
|
||||
)
|
||||
AC_SUBST(DOCUMENTATION_ROOT_URL)
|
||||
|
||||
|
|
85
gcc/opts.c
85
gcc/opts.c
|
@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
|
|||
#include "spellcheck.h"
|
||||
#include "opt-suggestions.h"
|
||||
#include "diagnostic-color.h"
|
||||
#include "selftest.h"
|
||||
|
||||
static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
|
||||
|
||||
|
@ -3128,6 +3129,42 @@ option_name (diagnostic_context *context, int option_index,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the page within the documentation for this option. */
|
||||
|
||||
static const char *
|
||||
get_option_html_page (int option_index)
|
||||
{
|
||||
const cl_option *cl_opt = &cl_options[option_index];
|
||||
|
||||
/* Analyzer options are on their own page. */
|
||||
if (strstr(cl_opt->opt_text, "analyzer-"))
|
||||
return "gcc/Static-Analyzer-Options.html";
|
||||
|
||||
#ifdef CL_Fortran
|
||||
if (cl_opt->flags & CL_Fortran)
|
||||
{
|
||||
switch (option_index)
|
||||
{
|
||||
default:
|
||||
/* Most Fortran warnings are documented on this page. */
|
||||
return "gfortran/Error-and-Warning-Options.html";
|
||||
|
||||
case OPT_Wdate_time:
|
||||
case OPT_Wconversion:
|
||||
case OPT_Wconversion_extra:
|
||||
case OPT_Wmissing_include_dirs:
|
||||
case OPT_Wopenmp_simd:
|
||||
/* These warnings are marked in fortran/lang.opt as
|
||||
"Documented in C" and thus use the common
|
||||
Warning-Options page below. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return "gcc/Warning-Options.html";
|
||||
}
|
||||
|
||||
/* Return malloced memory for a URL describing the option OPTION_INDEX
|
||||
which enabled a diagnostic (context CONTEXT). */
|
||||
|
||||
|
@ -3135,16 +3172,50 @@ char *
|
|||
get_option_url (diagnostic_context *, int option_index)
|
||||
{
|
||||
if (option_index)
|
||||
/* DOCUMENTATION_ROOT_URL should be supplied via -D by the Makefile
|
||||
(see --with-documentation-root-url).
|
||||
return concat (/* DOCUMENTATION_ROOT_URL should be supplied via -D by
|
||||
the Makefile (see --with-documentation-root-url), and
|
||||
should have a trailing slash. */
|
||||
DOCUMENTATION_ROOT_URL,
|
||||
|
||||
Expect an anchor of the form "index-Wfoo" e.g.
|
||||
<a name="index-Wformat"></a>, and thus an id within
|
||||
the URL of "#index-Wformat". */
|
||||
return concat (DOCUMENTATION_ROOT_URL,
|
||||
"Warning-Options.html",
|
||||
/* get_option_html_page will return something like
|
||||
"gcc/Warning-Options.html". */
|
||||
get_option_html_page (option_index),
|
||||
|
||||
/* Expect an anchor of the form "index-Wfoo" e.g.
|
||||
<a name="index-Wformat"></a>, and thus an id within
|
||||
the URL of "#index-Wformat". */
|
||||
"#index", cl_options[option_index].opt_text,
|
||||
NULL);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if CHECKING_P
|
||||
|
||||
namespace selftest {
|
||||
|
||||
/* Verify that get_option_html_page works as expected. */
|
||||
|
||||
static void
|
||||
test_get_option_html_page ()
|
||||
{
|
||||
ASSERT_STREQ (get_option_html_page (OPT_Wcpp), "gcc/Warning-Options.html");
|
||||
ASSERT_STREQ (get_option_html_page (OPT_Wanalyzer_double_free),
|
||||
"gcc/Static-Analyzer-Options.html");
|
||||
#ifdef CL_Fortran
|
||||
ASSERT_STREQ (get_option_html_page (OPT_Wline_truncation),
|
||||
"gfortran/Error-and-Warning-Options.html");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Run all of the selftests within this file. */
|
||||
|
||||
void
|
||||
opts_c_tests ()
|
||||
{
|
||||
test_get_option_html_page ();
|
||||
}
|
||||
|
||||
} // namespace selftest
|
||||
|
||||
#endif /* #if CHECKING_P */
|
||||
|
|
|
@ -73,6 +73,7 @@ selftest::run_tests ()
|
|||
typed_splay_tree_c_tests ();
|
||||
unique_ptr_tests_cc_tests ();
|
||||
opt_proposer_c_tests ();
|
||||
opts_c_tests ();
|
||||
json_cc_tests ();
|
||||
cgraph_c_tests ();
|
||||
optinfo_emit_json_cc_tests ();
|
||||
|
|
|
@ -243,6 +243,7 @@ extern void input_c_tests ();
|
|||
extern void json_cc_tests ();
|
||||
extern void opt_problem_cc_tests ();
|
||||
extern void optinfo_emit_json_cc_tests ();
|
||||
extern void opts_c_tests ();
|
||||
extern void ordered_hash_map_tests_cc_tests ();
|
||||
extern void predict_c_tests ();
|
||||
extern void pretty_print_c_tests ();
|
||||
|
|
Loading…
Add table
Reference in a new issue