From patchwork Tue Jul 16 11:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1132610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505142-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wVb5aQmi"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45nyXZ6yhGz9s7T for ; Tue, 16 Jul 2019 21:17:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=bgFbGHhhbKVsKfzCiE4/iKGI7NUYSJ0EVlNs/D/R7B/5ao58podnL VoGqKcoQHZ8cunMD9sCBfZuh9n8dsEWSF/KZkXp8gCxaGpiGJm19HzEarMTiIUix 7G6Ms1nlQ4EOYUfz9B86ZxsGQK8Q4rPZR1tmUdw+w6Z/RfeRrVp9+U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=tWpD9AknY63dweA7hZFw2sDtR2c=; b=wVb5aQmioUk6+Jx82WH+ bYiVo4WUfQ70PmIWS+AJtHlPlYJJiJhillYkrhO3t2Li0CbHfOHlbIm3q31Ci2I/ XkOoX/TS5EjJ5LMWOrHEM5yFd09nCvAfGWK9HGZOPi5QyN+EEVmNIBrJWqlY97cf n6HgX9y2U/1UXQDT769InnA= Received: (qmail 92226 invoked by alias); 16 Jul 2019 11:16:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 92213 invoked by uid 89); 16 Jul 2019 11:16:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=ideal X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jul 2019 11:16:52 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 08BE5ADE0 for ; Tue, 16 Jul 2019 11:16:50 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Make a warning for -Werror=wrong-language (PR driver/91172). To: gcc-patches@gcc.gnu.org Message-ID: <18dabe94-1a98-8a14-997a-24e512190a02@suse.cz> Date: Tue, 16 Jul 2019 13:16:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi. I noticed in the PR that -Werror=argument argument is not verified that the option is supported by a language we compile for. That's changed in the patch. However, it's not ideal as I need to mark the -Werror as the problematic option and one can't print a proper list of valid languages for which the rejected option can be used. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: 2019-07-16 Martin Liska PR driver/91172 * opts-common.c (decode_cmdline_option): Decode argument of -Werror and check it for a wrong language. * opts-global.c (complain_wrong_lang): Remove such case. gcc/testsuite/ChangeLog: 2019-07-16 Martin Liska PR driver/91172 * gcc.dg/pr91172.c: New test. --- gcc/opts-common.c | 20 +++++++++++++++++++- gcc/opts-global.c | 6 +++++- gcc/testsuite/gcc.dg/pr91172.c | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr91172.c diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 660dfe63858..76285bdcf93 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -537,7 +537,8 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, extra_args = 0; - opt_index = find_opt (argv[0] + 1, lang_mask); + const char *opt_value = argv[0] + 1; + opt_index = find_opt (opt_value, lang_mask); i = 0; while (opt_index == OPT_SPECIAL_unknown && i < ARRAY_SIZE (option_map)) @@ -745,6 +746,23 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, /* Check if this is a switch for a different front end. */ if (!option_ok_for_language (option, lang_mask)) errors |= CL_ERR_WRONG_LANG; + else if (strcmp (option->opt_text, "-Werror=") == 0 + && strchr (opt_value, ',') == NULL) + { + /* Verify that -Werror argument is a valid warning + for a languages. */ + char *werror_arg = xstrdup (opt_value + 6); + werror_arg[0] = 'W'; + + size_t warning_index = find_opt (werror_arg, lang_mask); + if (warning_index != OPT_SPECIAL_unknown) + { + const struct cl_option *warning_option + = &cl_options[warning_index]; + if (!option_ok_for_language (warning_option, lang_mask)) + errors |= CL_ERR_WRONG_LANG; + } + } /* Convert the argument to lowercase if appropriate. */ if (arg && option->cl_tolower) diff --git a/gcc/opts-global.c b/gcc/opts-global.c index bf4db775928..f62d6a3cddb 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -103,10 +103,14 @@ complain_wrong_lang (const struct cl_decoded_option *decoded, text, bad_lang); else if (lang_mask == CL_DRIVER) gcc_unreachable (); - else + else if (ok_langs[0] != '\0') /* Eventually this should become a hard error IMO. */ warning (0, "command-line option %qs is valid for %s but not for %s", text, ok_langs, bad_lang); + else + /* Happens for -Werror=warning_name. */ + warning (0, "command-line error argument %qs is not valid for %s", + text, bad_lang); free (ok_langs); free (bad_lang); diff --git a/gcc/testsuite/gcc.dg/pr91172.c b/gcc/testsuite/gcc.dg/pr91172.c new file mode 100644 index 00000000000..bf62d94d8a2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr91172.c @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror=target-lifetime" } */ +/* { dg-warning "command-line error argument '-Werror=target-lifetime' is not valid for C" "" { target *-*-* } 0 } */