From patchwork Tue Sep 22 20:23:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 521408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 BB8EF140783 for ; Wed, 23 Sep 2015 06:24:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=EbG2iMER; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=qZjqXmyXFIMMQ4mN4vEi/IDZ38DmDBzZuhEpe9q2I3v1NZ V2D+IfzjFCcBrlzB83oIsW6n9AYmI8KgHV5QH8cOIvsBjKbOvGWhaQ2Ywsc/balX z/J4LvynUyxCQ9tIdZ1lh4CX1VCl56nPhmccG+n2uU0eKvw74Rg8gfeR2TjwQ= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=K0nHC61HQI9V7Q+7mJVMeRwDlII=; b=EbG2iMERtI1GAOMJVtQn k68jQpLFT0/ea6J/ZLdY1Mzyr5IKi2jdvrPU5v1kN/pZmjJGcwNjzkLqW2qBL8Ae lDVustBkSxykteaA8mK88/iYu1ZW30gEZsWEhLnXZNv4lnRrYrKWO7fQLYJE9SQa vDsdx9tMwp61Y/v8c3zEmK0= Received: (qmail 15836 invoked by alias); 22 Sep 2015 20:24:16 -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 14929 invoked by uid 89); 22 Sep 2015 20:24:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f179.google.com Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 22 Sep 2015 20:24:09 +0000 Received: by wiclk2 with SMTP id lk2so41131969wic.1 for ; Tue, 22 Sep 2015 13:24:07 -0700 (PDT) X-Received: by 10.180.93.196 with SMTP id cw4mr22862600wib.54.1442953446882; Tue, 22 Sep 2015 13:24:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.186.214 with HTTP; Tue, 22 Sep 2015 13:23:27 -0700 (PDT) From: =?UTF-8?B?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= Date: Tue, 22 Sep 2015 22:23:27 +0200 Message-ID: Subject: fdiagnostics-color=never does not disable color for some diagnostics To: Gcc Patch List , "Joseph S. Myers" , Marek Polacek , Jason Merrill Actually, I was trying to reject non-warning options as argument to -Werror=. However, the new test fails because -fdiagnostics-color=never is always placed by the driver after the warning options when calling the compiler proper. This patch prunes all -fdiagnostics-color from the command-line but the last one, which is moved to the first position. Boot&tested on x86_64-linux-gnu OK? gcc/ChangeLog: 2015-09-22 Manuel López-Ibáñez PR driver/67640 * opts-common.c (prune_options): Discard all -fdiagnostics-color but the last one, which is moved to the front to be processed first. * opts.c (enable_warning_as_error): Reject options that do not control warnings. gcc/testsuite/ChangeLog: 2015-09-22 Manuel López-Ibáñez PR driver/67640 * gcc.dg/Werror-13.c: New test. Index: gcc/opts-common.c =================================================================== --- gcc/opts-common.c (revision 228011) +++ gcc/opts-common.c (working copy) @@ -823,10 +823,11 @@ prune_options (struct cl_decoded_option unsigned int new_decoded_options_count; struct cl_decoded_option *new_decoded_options = XNEWVEC (struct cl_decoded_option, old_decoded_options_count); unsigned int i; const struct cl_option *option; + unsigned int fdiagnostics_color_idx = 0; /* Remove arguments which are negated by others after them. */ new_decoded_options_count = 0; for (i = 0; i < old_decoded_options_count; i++) { @@ -842,10 +843,15 @@ prune_options (struct cl_decoded_option case OPT_SPECIAL_ignore: case OPT_SPECIAL_program_name: case OPT_SPECIAL_input_file: goto keep; + /* Do not save OPT_fdiagnostics_color_, just remember the last one. */ + case OPT_fdiagnostics_color_: + fdiagnostics_color_idx = i; + continue; + default: gcc_assert (opt_idx < cl_options_count); option = &cl_options[opt_idx]; if (option->neg_index < 0) goto keep; @@ -877,10 +883,21 @@ keep: } break; } } + if (fdiagnostics_color_idx > 1) + { + /* We put the last -fdiagnostics-color= at the first position + after argv[0] so it can take effect immediately. */ + memmove (new_decoded_options + 2, new_decoded_options + 1, + sizeof (struct cl_decoded_option) + * (new_decoded_options_count - 1)); + new_decoded_options[1] = old_decoded_options[fdiagnostics_color_idx]; + new_decoded_options_count++; + } + free (old_decoded_options); new_decoded_options = XRESIZEVEC (struct cl_decoded_option, new_decoded_options, new_decoded_options_count); *decoded_options = new_decoded_options; Index: gcc/testsuite/gcc.dg/Werror-13.c =================================================================== --- gcc/testsuite/gcc.dg/Werror-13.c (revision 0) +++ gcc/testsuite/gcc.dg/Werror-13.c (revision 0) @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror=error -Werror=p, -Werror=l, -Werror=fatal-errors" } */ +/* { dg-error "-Wp, is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Wl, is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Werror is not an option that controls warnings" "" { target *-*-* } 0 } */ +/* { dg-error "-Wfatal-errors is not an option that controls warnings" "" { target *-*-* } 0 } */ + +int i; Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 228011) +++ gcc/opts.c (working copy) @@ -2357,13 +2357,14 @@ enable_warning_as_error (const char *arg new_option = XNEWVEC (char, strlen (arg) + 2); new_option[0] = 'W'; strcpy (new_option + 1, arg); option_index = find_opt (new_option, lang_mask); if (option_index == OPT_SPECIAL_unknown) - { - error_at (loc, "-Werror=%s: no option -%s", arg, new_option); - } + error_at (loc, "-Werror=%s: no option -%s", arg, new_option); + else if (!(cl_options[option_index].flags & CL_WARNING)) + error_at (loc, "-Werror=%s: -%s is not an option that controls warnings", + arg, new_option); else { const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; control_warning_option (option_index, (int) kind, value,