From patchwork Tue Feb 3 10:45:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 435774 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 8CE73140188 for ; Tue, 3 Feb 2015 21:47:06 +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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=TdLcslew25qzkOTdUhSV9ckavKNL06k6L2iLCjcR3Lr jNlLcLg4tv6xK6niNjQaFjRl+/uLcQhlfRCu5cD7kLHzYqOLeq+oTsdW9XSTr+0x N4JyMOtqsSDqNtqXNyPsPIZSGwmULj+XSVv7P/uCcxoQ6fVoKd4Ttm2QFZ5yFmOY = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=MMohbY7GC3P6kshkDO+4hMpbrgo=; b=atNaAMTh73Epckf56 XJCbrrFGkwsQ0NlLpj08WPGl74ZBsNEqN1NrUW5Xuy5EyKYML4dY91JXFc0lltFt JJjSt9saNVQKxllQM2aMwGjFc0m5l4eKhSVYDLOJvKa23XmvqMwIuERyeNOI4MYV UX6QR4+Kna7bBb2hjzmcM3OUo0= Received: (qmail 12676 invoked by alias); 3 Feb 2015 10:45:49 -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 12652 invoked by uid 89); 3 Feb 2015 10:45:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 03 Feb 2015 10:45:47 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t13Ajift020360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Feb 2015 10:45:45 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t13AjibU003084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 3 Feb 2015 10:45:44 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t13AjiG7020902; Tue, 3 Feb 2015 10:45:44 GMT Received: from [192.168.1.4] (/79.53.237.212) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Feb 2015 02:45:43 -0800 Message-ID: <54D0A6D5.9090406@oracle.com> Date: Tue, 03 Feb 2015 11:45:41 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch/RFC] PR 64877 X-IsSubscribed: yes Hi, Manuel did most of the work on this [5 Regression], caused by my fix for c++/43906, which extended a lot the functionality of -Waddress: a spurious warning is emitted with -Waddress for an expression internally generated in cp_build_binary_op. Manuel suggested that when safe we could completely avoid generating the relevant recursive calls to cp_build_binary_op. Alternately, for these internally generated expressions we could probably use tf_none instead of passing down complain. Note: I'm not 100% sure the ptrmemfunc_vbit_in_delta bits are correct, for sure avoid the spurious warning for those targets too. Thanks, Paolo. /////////////////////////// Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 220366) +++ cp/typeck.c (working copy) @@ -4552,35 +4552,44 @@ cp_build_binary_op (location_t location, The reason for the `!op0.pfn' bit is that a NULL pointer-to-member is any member with a zero PFN and - LSB of the DELTA field is 0. */ + LSB of the DELTA field is 0. Note: avoid generating the + '|| (!op0.pfn && ...)' if !op0.pfn is known to be false. */ - e1 = cp_build_binary_op (location, BIT_AND_EXPR, - delta0, - integer_one_node, - complain); - e1 = cp_build_binary_op (location, - EQ_EXPR, e1, integer_zero_node, - complain); - e2 = cp_build_binary_op (location, BIT_AND_EXPR, - delta1, - integer_one_node, - complain); - e2 = cp_build_binary_op (location, - EQ_EXPR, e2, integer_zero_node, - complain); - e1 = cp_build_binary_op (location, - TRUTH_ANDIF_EXPR, e2, e1, - complain); - e2 = cp_build_binary_op (location, EQ_EXPR, - pfn0, - build_zero_cst (TREE_TYPE (pfn0)), - complain); - e2 = cp_build_binary_op (location, - TRUTH_ANDIF_EXPR, e2, e1, complain); - e1 = cp_build_binary_op (location, - EQ_EXPR, delta0, delta1, complain); - e1 = cp_build_binary_op (location, - TRUTH_ORIF_EXPR, e1, e2, complain); + if (TREE_CODE (pfn0) != ADDR_EXPR + || !decl_with_nonnull_addr_p (TREE_OPERAND (pfn0, 0))) + { + e1 = cp_build_binary_op (location, BIT_AND_EXPR, + delta0, + integer_one_node, + complain); + e1 = cp_build_binary_op (location, + EQ_EXPR, e1, integer_zero_node, + complain); + e2 = cp_build_binary_op (location, BIT_AND_EXPR, + delta1, + integer_one_node, + complain); + e2 = cp_build_binary_op (location, + EQ_EXPR, e2, integer_zero_node, + complain); + e1 = cp_build_binary_op (location, + TRUTH_ANDIF_EXPR, e2, e1, + complain); + e2 = cp_build_binary_op (location, EQ_EXPR, + pfn0, + build_zero_cst (TREE_TYPE (pfn0)), + complain); + e2 = cp_build_binary_op (location, + TRUTH_ANDIF_EXPR, e2, e1, complain); + e1 = cp_build_binary_op (location, + EQ_EXPR, delta0, delta1, complain); + e1 = cp_build_binary_op (location, + TRUTH_ORIF_EXPR, e1, e2, complain); + + } + else + e1 = cp_build_binary_op (location, + EQ_EXPR, delta0, delta1, complain); } else { @@ -4591,17 +4600,22 @@ cp_build_binary_op (location_t location, The reason for the `!op0.pfn' bit is that a NULL pointer-to-member is any member with a zero PFN; the - DELTA field is unspecified. */ + DELTA field is unspecified. Note: avoid generating the + '!op0.pfn ||' if !op0.pfn is known to be false. */ e1 = cp_build_binary_op (location, EQ_EXPR, delta0, delta1, complain); - e2 = cp_build_binary_op (location, - EQ_EXPR, - pfn0, - build_zero_cst (TREE_TYPE (pfn0)), - complain); - e1 = cp_build_binary_op (location, - TRUTH_ORIF_EXPR, e1, e2, complain); + if (TREE_CODE (pfn0) != ADDR_EXPR + || !decl_with_nonnull_addr_p (TREE_OPERAND (pfn0, 0))) + { + e2 = cp_build_binary_op (location, + EQ_EXPR, + pfn0, + build_zero_cst (TREE_TYPE (pfn0)), + complain); + e1 = cp_build_binary_op (location, + TRUTH_ORIF_EXPR, e1, e2, complain); + } } e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1); e = cp_build_binary_op (location, Index: testsuite/g++.dg/warn/Waddress-2.C =================================================================== --- testsuite/g++.dg/warn/Waddress-2.C (revision 0) +++ testsuite/g++.dg/warn/Waddress-2.C (working copy) @@ -0,0 +1,24 @@ +// PR c++/64877 +// { dg-options "-Waddress" } + +template +struct S +{ + void m() { + } + + S() + { + if (&S::Unwrap != &Derived::Unwrap) + m(); + } + + void Unwrap() { + } +}; + +struct T : public S +{ +}; + +T t;