From patchwork Mon Apr 27 19:09:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1277879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=IrypRjBi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499vVK3ynnz9sSv for ; Tue, 28 Apr 2020 05:09:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC7F93870909; Mon, 27 Apr 2020 19:09:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC7F93870909 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588014597; bh=tQye9ep188mTuh9IglEO6WXzF8OC9xNN7M2hxTTZb1s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IrypRjBixN9qprMHR4S548nM1M9iSDW9Yl+8R+9nAxpATc7Q/651+eQl1hCLj6zv2 +j4phJ5ycNYB9oZYyF7dEv/AJWgfbm2jFGXwx9oYJ6sloLdqWRP3LkZa6k6A0m8RwU dud3mwodkbCXsUx14IGz5QGRNjYRqDSK+8mOeN4Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id B0DDE3858D34 for ; Mon, 27 Apr 2020 19:09:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B0DDE3858D34 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-448-t0YvH3qKO9isYsoEuYe6ug-1; Mon, 27 Apr 2020 15:09:47 -0400 X-MC-Unique: t0YvH3qKO9isYsoEuYe6ug-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24263100A8E8; Mon, 27 Apr 2020 19:09:46 +0000 (UTC) Received: from t470.redhat.com (ovpn-114-112.phx2.redhat.com [10.3.114.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A66210013BD; Mon, 27 Apr 2020 19:09:45 +0000 (UTC) To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [committed] Fix warning URLs for Fortran and analyzer [PR 92830] Date: Mon, 27 Apr 2020 15:09:33 -0400 Message-Id: <20200427190933.22514-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-26.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu with all languages enabled; I also verified that it builds for the case when fortran is not enabled. Pushed to master as r10-7994-gfa29cf0c3f19b648e30b16fd2485c3c17a528a6e. 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. --- gcc/configure.ac | 2 +- gcc/opts.c | 87 ++++++++++++++++++++++++++++++++++++---- gcc/selftest-run-tests.c | 1 + gcc/selftest.h | 1 + 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/gcc/configure.ac b/gcc/configure.ac index fdee9ea587c..cd62312b813 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -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) diff --git a/gcc/opts.c b/gcc/opts.c index d4df8627bf7..c212a1a57dc 100644 --- a/gcc/opts.c +++ b/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). - - Expect an anchor of the form "index-Wfoo" e.g. - , and thus an id within - the URL of "#index-Wformat". */ - return concat (DOCUMENTATION_ROOT_URL, - "Warning-Options.html", + 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, + + /* 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. + , 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 */ diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c index d47e92862f1..f0a81d43fd6 100644 --- a/gcc/selftest-run-tests.c +++ b/gcc/selftest-run-tests.c @@ -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 (); diff --git a/gcc/selftest.h b/gcc/selftest.h index df98e0b5f12..5cffa13aedd 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -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 ();