From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26029 invoked by alias); 31 Jan 2015 17:38:24 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24240 invoked by uid 48); 31 Jan 2015 17:38:20 -0000 From: "paolo.carlini at oracle dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64877] [5 Regression] strange warning message from -Waddress Date: Sat, 31 Jan 2015 17:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: paolo.carlini at oracle dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg03640.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64877 Paolo Carlini changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|strange warning message |[5 Regression] strange |from -Waddress |warning message from | |-Waddress --- Comment #6 from Paolo Carlini --- Thanks Manuel for the analysis. Indeed, now -Waddress is much more general, and those internally generated expressions are causing problems. Thus, following your suggestion, I would propose something like the below, which I'm finishing testing. Does it look Ok to you? Index: typeck.c =================================================================== --- typeck.c (revision 220306) +++ 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,