From patchwork Tue Aug 19 18:00:36 2014 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: 381419 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 07E59140095 for ; Wed, 20 Aug 2014 04:01:15 +1000 (EST) 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=vFUIkr6cgkbSBrJL7G7kJyLDYSakyU3X6EfXS3HDDyxUqu jjFKNQqYBVJqPAxIzF/lB74ekICbNaJxUq7pCLulo50mPLPDtl7p/sCY3S81fCyb 9hHMQtsCO9WB4t4CWks10fRkHFwG2vSeeYqesLyz8Lc5ulZXzqYEMtwuGkITE= 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=mHGV3wze2ibXBSaoTpxWzj0RjRo=; b=skUczwRJqtNvcvWzIlRS ozrjQcu1NJf9ivvM3wSBa2eRGmcorE3HEc4Id+3f7qhZzCxBUuXq0RE43NFZQGcJ 5K1WasclrNLEvgmSoFVqJpfQ6+4fkIHLOqw2ya8wvvUH6JmtspZldsQAdXxCzNnT jWAPHAEQTf9FpjKDrBtZbYg= Received: (qmail 7538 invoked by alias); 19 Aug 2014 18:01:01 -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 7518 invoked by uid 89); 19 Aug 2014 18:01:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f46.google.com Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 19 Aug 2014 18:01:00 +0000 Received: by mail-wg0-f46.google.com with SMTP id m15so6745361wgh.29 for ; Tue, 19 Aug 2014 11:00:57 -0700 (PDT) X-Received: by 10.180.84.66 with SMTP id w2mr8431207wiy.27.1408471257107; Tue, 19 Aug 2014 11:00:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.217.80.73 with HTTP; Tue, 19 Aug 2014 11:00:36 -0700 (PDT) From: =?ISO-8859-1?Q?Manuel_L=F3pez=2DIb=E1=F1ez?= Date: Tue, 19 Aug 2014 20:00:36 +0200 Message-ID: Subject: [PATCH/PR c/59304] #pragma diagnostic pop after warning fails for options unspecified in the command-line and disabled by default To: Gcc Patch List , Dodji Seketeli X-IsSubscribed: yes The idea is that when we see a change of classification, and the option was originally unspecified, we record the command-line status. This way, when doing pop later, we already check if the option was reclassified so we get the command-line status. This also works with -Wall, since all dependent options go through set_option and call diagnostic_classify_diagnostic. But we have to call it before changing the option status. Bootstrapped and regression tested on x86_64-linux-gnu. OK? gcc/ChangeLog: 2014-08-19 Manuel López-Ibáñez PR c/59304 * opts-common.c (set_option): Call diagnostic_classify_diagnostic before setting the option. * diagnostic.c (diagnostic_classify_diagnostic): Record command-line status. gcc/testsuite/ChangeLog: 2014-08-19 Manuel López-Ibáñez PR c/59304 * gcc.dg/pr59304.c: New test. Index: gcc/opts-common.c =================================================================== --- gcc/opts-common.c (revision 214136) +++ gcc/opts-common.c (working copy) @@ -1117,10 +1117,13 @@ set_option (struct gcc_options *opts, st void *set_flag_var = NULL; if (!flag_var) return; + if ((diagnostic_t) kind != DK_UNSPECIFIED && dc != NULL) + diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc); + if (opts_set != NULL) set_flag_var = option_flag_var (opt_index, opts_set); switch (option->var_type) { @@ -1196,14 +1199,10 @@ set_option (struct gcc_options *opts, st if (set_flag_var) *(void **) set_flag_var = v; } break; } - - if ((diagnostic_t) kind != DK_UNSPECIFIED - && dc != NULL) - diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc); } /* Return the address of the flag variable for option OPT_INDEX in options structure OPTS, or NULL if there is no flag variable. */ Index: gcc/diagnostic.c =================================================================== --- gcc/diagnostic.c (revision 214136) +++ gcc/diagnostic.c (working copy) @@ -582,10 +582,19 @@ diagnostic_classify_diagnostic (diagnost the pragmas were. */ if (where != UNKNOWN_LOCATION) { int i; + /* Record the command-line status, so we can reset it back on DK_POP. */ + if (old_kind == DK_UNSPECIFIED) + { + old_kind = context->option_enabled (option_index, + context->option_state) + ? DK_WARNING : DK_IGNORED; + context->classify_diagnostic[option_index] = old_kind; + } + for (i = context->n_classification_history - 1; i >= 0; i --) if (context->classification_history[i].option == option_index) { old_kind = context->classification_history[i].kind; break; Index: gcc/testsuite/gcc.dg/pr59304.c =================================================================== --- gcc/testsuite/gcc.dg/pr59304.c (revision 0) +++ gcc/testsuite/gcc.dg/pr59304.c (revision 0) @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +enum EE + { + ONE, TWO, THREE + }; + +int f (enum EE e) +{ + int r = 0; + +#pragma GCC diagnostic push +#pragma GCC diagnostic error "-Wswitch-enum" + + switch (e) + { + case ONE: + r = 1; + break; + case TWO: + r = 2; + break; + case THREE: + r = 3; + break; + } + +#pragma GCC diagnostic pop + + switch (e) + { + case ONE: + r = 1; + break; + case TWO: + r = 2; + break; + } + + return r; +}