From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60649 invoked by alias); 13 Jan 2019 05:05:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 60624 invoked by uid 89); 13 Jan 2019 05:05:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mga17.intel.com Received: from mga17.intel.com (HELO mga17.intel.com) (192.55.52.151) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 13 Jan 2019 05:05:40 +0000 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jan 2019 21:05:39 -0800 Received: from gnu-cfl-1.sc.intel.com ([172.25.70.237]) by fmsmga007.fm.intel.com with ESMTP; 12 Jan 2019 21:05:38 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: [PATCH] C-amily: Properly strip NOP_EXPR Date: Sun, 13 Jan 2019 05:05:00 -0000 Message-Id: <20190113050538.19357-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00727.txt.bz2 gcc/c-family/ PR c/51628 * c-warn.c (warn_for_address_or_pointer_of_packed_member): Move NOP_EXPR check to ... (check_and_warn_address_of_packed_member): Here. gcc/testsuite/ PR c/51628 * c-c++-common/pr51628-33.c: New test. --- gcc/c-family/c-warn.c | 6 +++--- gcc/testsuite/c-c++-common/pr51628-33.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr51628-33.c diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index 79b2d8ad449..070934ab2b6 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -2755,6 +2755,9 @@ check_and_warn_address_of_packed_member (tree type, tree rhs) while (TREE_CODE (rhs) == COMPOUND_EXPR) rhs = TREE_OPERAND (rhs, 1); + if (TREE_CODE (rhs) == NOP_EXPR) + rhs = TREE_OPERAND (rhs, 0); + tree context = check_address_of_packed_member (type, rhs); if (context) { @@ -2844,9 +2847,6 @@ warn_for_address_or_pointer_of_packed_member (bool convert_p, tree type, /* Get the type of the pointer pointing to. */ type = TREE_TYPE (type); - if (TREE_CODE (rhs) == NOP_EXPR) - rhs = TREE_OPERAND (rhs, 0); - check_and_warn_address_of_packed_member (type, rhs); } } diff --git a/gcc/testsuite/c-c++-common/pr51628-33.c b/gcc/testsuite/c-c++-common/pr51628-33.c new file mode 100644 index 00000000000..0092f32202f --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr51628-33.c @@ -0,0 +1,19 @@ +/* PR c/51628. */ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +struct pair_t +{ + char x; + int i[4]; +} __attribute__ ((packed, aligned (4))); + +extern struct pair_t p; +extern void bar (int *); + +void +foo (struct pair_t *p) +{ + bar (p ? p->i : (int *) 0); +/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } .-1 } */ +} -- 2.20.1