From patchwork Thu Jul 30 15:35:39 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: 502194 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 A80051409B7 for ; Fri, 31 Jul 2015 01:36:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=M2H6JyUh; 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=FEWVE3kGERL8SBTWlkrTp7F/UuA7OXGOvb9fPjWsgpUZbW Z3TcmfA3RvZAxjhyfSPDp6e4XqkYrgwfX/6RyMVrTNZX7L4tg0sRb1REEdj8K7yB xAKHubw5xKmGUpECIDRWJ//YIFbFmU+5XetnBxT4w2X6jrPHFU/W/DfXtRFss= 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=EO+eZWpYAlKzmP/QqqIqbmISZ9g=; b=M2H6JyUhlsKKw/QfVP09 cP6muBfFqDekdKpYkO2fai2W7wQ6wR7PfxJVsDopfUy8AMAlJdjv9LI5oScmWH2d b79q5LfN8G35U557WsENMz31yUxvwG6H4Gr9LZAot5GQUk2Zxgiet8W+jArusS9Z 7UMhCFnbi4nHe8tew+Jc77E= Received: (qmail 71008 invoked by alias); 30 Jul 2015 15:36:26 -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 70999 invoked by uid 89); 30 Jul 2015 15:36:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_20, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f177.google.com Received: from mail-wi0-f177.google.com (HELO mail-wi0-f177.google.com) (209.85.212.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 30 Jul 2015 15:36:22 +0000 Received: by wicmv11 with SMTP id mv11so26029763wic.0 for ; Thu, 30 Jul 2015 08:36:19 -0700 (PDT) X-Received: by 10.180.89.104 with SMTP id bn8mr7513740wib.6.1438270579661; Thu, 30 Jul 2015 08:36:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.188.139 with HTTP; Thu, 30 Jul 2015 08:35:39 -0700 (PDT) From: =?UTF-8?B?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= Date: Thu, 30 Jul 2015 17:35:39 +0200 Message-ID: Subject: PR c/c++/diagnostics/66098 Take -Werror into account when deciding what was the command-line status To: Gcc Patch List , Dodji Seketeli , "Joseph S. Myers" , Marek Polacek , Jason Merrill When I fixed PR59304, I forgot that a command-line warning can be also an error if -Werror was enabled. This introduced a regression since anything enabled in the command-line together with -Werror would get initially classified as a warning when reaching the first #pragma GCC diagnostic, and this will be the setting after a #pragma pop. Options that appear as arguments of -W[no-]error= are not affected by this since those are initially classified as errors/warnings even before reaching the first #pragma, thus the pop sets them correctly (before and after this patch). Nonetheless, the tests also check that they work correctly. Boot®tested on x86_64-linux-gnu. OK? gcc/ChangeLog: 2015-07-29 Manuel López-Ibáñez PR c/66098 PR c/66711 * diagnostic.c (diagnostic_classify_diagnostic): Take -Werror into account when deciding what was the command-line status. gcc/testsuite/ChangeLog: 2015-07-29 Manuel López-Ibáñez PR c/66098 PR c/66711 * gcc.dg/pragma-diag-3.c: New test. * gcc.dg/pragma-diag-4.c: New test. Index: gcc/diagnostic.c =================================================================== --- gcc/diagnostic.c (revision 226312) +++ gcc/diagnostic.c (working copy) @@ -694,13 +694,14 @@ diagnostic_classify_diagnostic (diagnost 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; + old_kind = !context->option_enabled (option_index, + context->option_state) + ? DK_IGNORED : (context->warning_as_error_requested + ? DK_ERROR: DK_WARNING); 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) Index: gcc/testsuite/gcc.dg/pragma-diag-3.c =================================================================== --- gcc/testsuite/gcc.dg/pragma-diag-3.c (revision 0) +++ gcc/testsuite/gcc.dg/pragma-diag-3.c (revision 0) @@ -0,0 +1,72 @@ +/* { dg-do compile } */ +/* { dg-options "-Wswitch-enum -Wsign-compare -fstrict-overflow -Wstrict-overflow -Werror -Wno-error=switch-enum" } */ +/* PR c/66098 - #pragma diagnostic 'ignored' not fully undone by pop for strict-overflow + PR c/66711 - GCC does not correctly restore diagnostic state after pragma GCC diagnostic pop with -Werror +*/ +/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */ + +void testing2() { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-overflow" + int j = 4; + j + 4 < j; +#pragma GCC diagnostic pop +} + +void testing3() { + int k = 4; + k + 4 < k; /* { dg-error "overflow" } */ +} + +int foo() { + testing2(); + testing3(); + + return 0; +} + + +int bar() +{ + unsigned x = 0; + int y = 1; + + /* generates an error - ok */ + x += x < y ? 1 : 0; /* { dg-error "comparison" } */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" + /* generates no diagnostic - ok */ + x += x < y ? 1 : 0; +#pragma GCC diagnostic pop + + x += x < y ? 1 : 0; /* { dg-error "comparison" } */ + + return x; +} + +enum EE { ONE, TWO }; + +int f (enum EE e) +{ + int r = 0; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-enum" + + switch (e) + { + case ONE: + r = 1; + break; + } +#pragma GCC diagnostic pop + + switch (e) /* { dg-warning "switch" } */ + { + case ONE: + r = 1; + break; + } + return r; +} Index: gcc/testsuite/gcc.dg/pragma-diag-4.c =================================================================== --- gcc/testsuite/gcc.dg/pragma-diag-4.c (revision 0) +++ gcc/testsuite/gcc.dg/pragma-diag-4.c (revision 0) @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-Wsign-compare -Werror=sign-compare -Werror=switch-enum" } */ +/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */ + +int bar() +{ + unsigned x = 0; + int y = 1; + + /* generates an error - ok */ + x += x < y ? 1 : 0; /* { dg-error "comparison" } */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" + /* generates no diagnostic - ok */ + x += x < y ? 1 : 0; +#pragma GCC diagnostic pop + + x += x < y ? 1 : 0; /* { dg-error "comparison" } */ + + return x; +} + +enum EE { ONE, TWO }; + +int f (enum EE e) +{ + int r = 0; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-enum" + + switch (e) + { + case ONE: + r = 1; + break; + } +#pragma GCC diagnostic pop + + switch (e) /* { dg-error "switch" } */ + { + case ONE: + r = 1; + break; + } + return r; +}