From patchwork Sun Jan 13 05:05:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1024025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493958-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="aGZSqJKV"; dkim-atps=neutral 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 43cl1C43fhz9s4s for ; Sun, 13 Jan 2019 16:05:51 +1100 (AEDT) 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:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=mlhoWzMWixS58SbZ K/5JJB6SDb6xh1P/Ajp4+HHDsqm4kPIKHsXmhnS4UohN4K2xaIWhGybNWTloUBoA v99xm5pFhUF4WVzZacFv92ScwdJuIR9CFb+Y8/NqW3wRswP+7YgL94j2Kk2kP/U3 4PKcTn3kzbibXKOpu/0L09LD3tE= 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:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=6IyjIDkptOOUxoJitZ/H2W noiuE=; b=aGZSqJKVB90c4vZwZxLqYRoadlJIJmnGvxouTRPJLJe6aEoynSw1WE LENndsP4zDJsZgV1IpSywkNfJgl2oIDFwUsIXjs+E5NqE6R69NKoMYSDWGY0Qk8E Ewu37jWuyRXsO2mJI4RFNbkMPlmLgNltujqYHtuMQV5x/ivE2k3fM= 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-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 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: Sat, 12 Jan 2019 21:05:38 -0800 Message-Id: <20190113050538.19357-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes 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 } */ +}