From patchwork Sat Feb 20 16:46:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 585636 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 E89B1140B97 for ; Sun, 21 Feb 2016 03:24:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dTXEarNg; 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:from :to:cc:subject:date:message-id; q=dns; s=default; b=YyDevxqRPlzt PWtVhf079ceiUS+UYbj/a/yvlXkS6mLcMRnXFnglYQ6+xcRQphBmBFQbvcOaFFwI Eekx0qMkGvsyFm7BcoNs5QJnuy8d7ys9j04PszV19GxgsvCpD0h44nMIi5bd5HLY l1TV+P45HBtmv1ZgD8H8VzIH+wxQDVs= 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 :to:cc:subject:date:message-id; s=default; bh=jeJNbzRW16ul+95nnx sGrF0smWg=; b=dTXEarNg9HOKWshgUI+GJWNGySTgz4bq/89/bzh79golcf79XZ 3rN76oddUD3DdP5F0feetLlyAYSj1t1ZwP0uLtQxqMT3vfW+nLaios8vsFG9U9Ge qsr763kOKb3SOX2w3/09YzO5pet53wSAR6ewDkIYRdowfRxH4cno7qBmk= Received: (qmail 127257 invoked by alias); 20 Feb 2016 16:24:18 -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 127205 invoked by uid 89); 20 Feb 2016 16:24:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=erroneously, xfails, 1, 19 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 20 Feb 2016 16:24:13 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id B91A414CAA3 for ; Sat, 20 Feb 2016 16:24:12 +0000 (UTC) Received: from c64.redhat.com (vpn-230-101.phx2.redhat.com [10.3.230.101]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1KGOBdp015136; Sat, 20 Feb 2016 11:24:12 -0500 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/2] RFC: Add test coverage for _Pragma (PR preprocessor 69126, 69543, 69558) Date: Sat, 20 Feb 2016 11:46:22 -0500 Message-Id: <1455986783-7920-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes We had some regressions in the ability for _Pragma to disable a warning (PR preprocessor/69126, PR preprocessor/69543, PR preprocessor/69558). This patch attempts to add more test coverage for this, for the various combinations of: - various warnings: -Wunused-variable -Wuninitialized -Wdeprecated-declarations - various combinations of location of _Pragma relative to location of the warning: - _Pragma is in a macro, warning isn't a macro - neither is in a macro - _Pragma isnt't in a macro, warning is in a macro - in different macros - both in the same macro - C vs C++ frontend. It adds some XFAILs: - pr69543-1.c for C++ (fixed in the followup patch) - pr69543-3.c for both C and C++ - pr69543-4.c for both C and C++ - pr69558.c for C++ (moving it from gcc.dg to c-c++-common, marking it as xfail for C++ for now) I've also tested the new cases on gcc 5. The only regression we currently have in trunk relative to gcc 5 is c-c++-common/pr69543-1.c lines 19, which the followup patch fixes. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu in combination with the followup patch. OK for trunk? gcc/testsuite/ChangeLog: PR preprocessor/69126 PR preprocessor/69543 PR preprocessor/69558 * c-c++-common/pr69126.c (MACRO_1, test_1): New. (f): Rename to... (test_2): ...this, and add leading comment. (MACRO_3, test_3): New. (MACRO_4A, MACRO_4B, test_4): New. (MACRO): Rename to... (MACRO_5): ...this. (g): Rename to... (test_5): ...this, updating for renaming of MACRO, and add leading comment. * c-c++-common/pr69543-1.c: New. * c-c++-common/pr69543-2.c: New. * c-c++-common/pr69543-3.c: New. * c-c++-common/pr69543-4.c: New. * c-c++-common/pr69558-1.c: New. * c-c++-common/pr69558-2.c: New. * c-c++-common/pr69558-3.c: New. * c-c++-common/pr69558-4.c: New. * gcc.dg/pr69558.c: Move to... * c-c++-common/pr69558.c: ...here. Add dg-bogus directives, with xfail for c++. --- gcc/testsuite/c-c++-common/pr69126.c | 65 +++++++++++++++++++++++++++++++--- gcc/testsuite/c-c++-common/pr69543-1.c | 21 +++++++++++ gcc/testsuite/c-c++-common/pr69543-2.c | 14 ++++++++ gcc/testsuite/c-c++-common/pr69543-3.c | 20 +++++++++++ gcc/testsuite/c-c++-common/pr69543-4.c | 25 +++++++++++++ gcc/testsuite/c-c++-common/pr69558-1.c | 21 +++++++++++ gcc/testsuite/c-c++-common/pr69558-2.c | 16 +++++++++ gcc/testsuite/c-c++-common/pr69558-3.c | 19 ++++++++++ gcc/testsuite/c-c++-common/pr69558-4.c | 23 ++++++++++++ gcc/testsuite/c-c++-common/pr69558.c | 19 ++++++++++ gcc/testsuite/gcc.dg/pr69558.c | 17 --------- 11 files changed, 239 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr69543-1.c create mode 100644 gcc/testsuite/c-c++-common/pr69543-2.c create mode 100644 gcc/testsuite/c-c++-common/pr69543-3.c create mode 100644 gcc/testsuite/c-c++-common/pr69543-4.c create mode 100644 gcc/testsuite/c-c++-common/pr69558-1.c create mode 100644 gcc/testsuite/c-c++-common/pr69558-2.c create mode 100644 gcc/testsuite/c-c++-common/pr69558-3.c create mode 100644 gcc/testsuite/c-c++-common/pr69558-4.c create mode 100644 gcc/testsuite/c-c++-common/pr69558.c delete mode 100644 gcc/testsuite/gcc.dg/pr69558.c diff --git a/gcc/testsuite/c-c++-common/pr69126.c b/gcc/testsuite/c-c++-common/pr69126.c index fb4dcfb..52c96eb 100644 --- a/gcc/testsuite/c-c++-common/pr69126.c +++ b/gcc/testsuite/c-c++-common/pr69126.c @@ -1,22 +1,79 @@ /* { dg-options "-Wunused-variable" } */ +/* Verify that ignoring -Wunused-variable works, for various placements + of the variable and the _Pragma. */ + +/* Test 1: the _Pragma is in a macro, but the affected code isn't. */ + +#pragma GCC diagnostic push + +#define MACRO_1 \ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + +int test_1() +{ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + int x; + return 0; +} +#pragma GCC diagnostic pop + + +/* Test 2: neither the _Pragma nor the affected code are in a macro. */ + +#pragma GCC diagnostic push +int test_2() +{ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + int x; + return 0; +} +#pragma GCC diagnostic pop + + +/* Test 3: the _Pragma isn't in a macro, but the affected code is. */ + +#define MACRO_3 \ + int x; + #pragma GCC diagnostic push -int f() +int test_3() { _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + MACRO_3 + return 0; +} +#pragma GCC diagnostic pop + + +/* Test 4: the _Pragma and the affected code are in different macros. */ + +#pragma GCC diagnostic push +#define MACRO_4A \ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + +#define MACRO_4B \ int x; + +int test_4() +{ + MACRO_4A; + MACRO_4B return 0; } #pragma GCC diagnostic pop + +/* Test 5: both the _Pragma and the affected code are in the same macro. */ + #pragma GCC diagnostic push -#define MACRO \ +#define MACRO_5 \ _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \ int x; -int g() +int test_5() { - MACRO; + MACRO_5; return 0; } #pragma GCC diagnostic pop diff --git a/gcc/testsuite/c-c++-common/pr69543-1.c b/gcc/testsuite/c-c++-common/pr69543-1.c new file mode 100644 index 0000000..bfb5270 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69543-1.c @@ -0,0 +1,21 @@ +/* { dg-options "-Wuninitialized" } */ + +/* Verify disabling a warning, where the _Pragma is within + a macro, but the affected code is *not* in a macro. */ + +/* TODO: XFAIL: why does g++ still emit a warning here? (works for C). */ + +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") + +void test (char yylval) +{ + char *yyvsp; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail { c++ } } } */ + YY_IGNORE_MAYBE_UNINITIALIZED_END +} diff --git a/gcc/testsuite/c-c++-common/pr69543-2.c b/gcc/testsuite/c-c++-common/pr69543-2.c new file mode 100644 index 0000000..4099fb2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69543-2.c @@ -0,0 +1,14 @@ +/* { dg-options "-Wuninitialized" } */ + +/* Verify disabling a warning, where both the _Pragma and the + affected code are *not* in a macro. */ + +void test (char yylval) +{ + char *yyvsp; + _Pragma ("GCC diagnostic push") + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") + *++yyvsp = yylval; + _Pragma ("GCC diagnostic pop") +} diff --git a/gcc/testsuite/c-c++-common/pr69543-3.c b/gcc/testsuite/c-c++-common/pr69543-3.c new file mode 100644 index 0000000..fcf750c --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69543-3.c @@ -0,0 +1,20 @@ +/* { dg-options "-Wuninitialized" } */ + +/* Verify disabling a warning, where the _Pragma is in regular code, + but the affected code is within a macro. */ + +/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning + The warning is reported at the macro definition location, rather than + the macro expansion location. */ + +#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */ + +void test (char yylval) +{ + char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */ + _Pragma ("GCC diagnostic push") + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") + WARNABLE_CODE + _Pragma ("GCC diagnostic pop") +} diff --git a/gcc/testsuite/c-c++-common/pr69543-4.c b/gcc/testsuite/c-c++-common/pr69543-4.c new file mode 100644 index 0000000..cd71e7e --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69543-4.c @@ -0,0 +1,25 @@ +/* { dg-options "-Wuninitialized" } */ + +/* Verify disabling a warning, where both the _Pragma and the + affected code are within (different) macros. */ + +/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning + The warning is reported at the macro definition location, rather than + the macro expansion location. */ + +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") + +#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */ + +void test (char yylval) +{ + char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */ + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + WARNABLE_CODE + YY_IGNORE_MAYBE_UNINITIALIZED_END +} diff --git a/gcc/testsuite/c-c++-common/pr69558-1.c b/gcc/testsuite/c-c++-common/pr69558-1.c new file mode 100644 index 0000000..57ac490 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69558-1.c @@ -0,0 +1,21 @@ +/* PR c/69558 */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* Verify disabling -Wdeprecated-declarations, where the _Pragma is in a + macro, but the affected code is *not* in a macro. */ + +#define A \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define B \ + _Pragma ("GCC diagnostic pop") + +__attribute__((deprecated)) void foo (void); + +void bar (void) +{ + A + foo (); + B +} diff --git a/gcc/testsuite/c-c++-common/pr69558-2.c b/gcc/testsuite/c-c++-common/pr69558-2.c new file mode 100644 index 0000000..83ae647 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69558-2.c @@ -0,0 +1,16 @@ +/* PR c/69558 */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* Verify disabling -Wdeprecated-declarations, where neither the _Pragma nor + the affected code are in macros. */ + +__attribute__((deprecated)) void foo (void); + +void bar (void) +{ + _Pragma ("GCC diagnostic push") + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + foo (); + _Pragma ("GCC diagnostic pop") +} diff --git a/gcc/testsuite/c-c++-common/pr69558-3.c b/gcc/testsuite/c-c++-common/pr69558-3.c new file mode 100644 index 0000000..45c38a9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69558-3.c @@ -0,0 +1,19 @@ +/* PR c/69558 */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* Verify disabling -Wdeprecated-declarations, where the _Pragma is not + in a macro, but the affected code *is*. */ + +#define C \ + foo (); + +__attribute__((deprecated)) void foo (void); + +void bar (void) +{ + _Pragma ("GCC diagnostic push") + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + C + _Pragma ("GCC diagnostic pop") +} diff --git a/gcc/testsuite/c-c++-common/pr69558-4.c b/gcc/testsuite/c-c++-common/pr69558-4.c new file mode 100644 index 0000000..02d526e --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69558-4.c @@ -0,0 +1,23 @@ +/* PR c/69558 */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* Verify disabling -Wdeprecated-declarations, where the _Pragma and the + affected code are in different macros. */ + +#define A \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define B \ + _Pragma ("GCC diagnostic pop") +#define C \ + foo (); + +__attribute__((deprecated)) void foo (void); + +void bar (void) +{ + A + C + B +} diff --git a/gcc/testsuite/c-c++-common/pr69558.c b/gcc/testsuite/c-c++-common/pr69558.c new file mode 100644 index 0000000..102d72c --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69558.c @@ -0,0 +1,19 @@ +/* PR c/69558 */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations" } */ + +/* TODO: XFAIL for g++ (works for C). */ + +#define A \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define B \ + _Pragma ("GCC diagnostic pop") +#define C(x) \ + A \ + static inline void bar (void) { x (); } /* { dg-bogus "in definition of|deprecated" "" { xfail { c++ } } } */ \ + B + +__attribute__((deprecated)) void foo (void); /* { dg-bogus "declared here" "" { xfail { c++ } } } */ + +C (foo) /* { dg-bogus "is deprecated" "" { xfail { c++ } } } */ diff --git a/gcc/testsuite/gcc.dg/pr69558.c b/gcc/testsuite/gcc.dg/pr69558.c deleted file mode 100644 index 3be8cf9..0000000 --- a/gcc/testsuite/gcc.dg/pr69558.c +++ /dev/null @@ -1,17 +0,0 @@ -/* PR c/69558 */ -/* { dg-do compile } */ -/* { dg-options "-Wdeprecated-declarations" } */ - -#define A \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -#define B \ - _Pragma ("GCC diagnostic pop") -#define C(x) \ - A \ - static inline void bar (void) { x (); } \ - B - -__attribute__((deprecated)) void foo (void); /* { dg-bogus "declared here" } */ - -C (foo) /* { dg-bogus "is deprecated" } */