From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id E75B83857C50; Mon, 16 May 2022 09:05:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E75B83857C50 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-503] Do not use DW_OP_not for TRUTH_NOT_EXPR in conditional expressions X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: b90e43dbbb2ba00ef2f8b2468fb09b43a12ae13d X-Git-Newrev: cc7cd8d57cabf2598a1c5f64dd77487c31b4d149 Message-Id: <20220516090503.E75B83857C50@sourceware.org> Date: Mon, 16 May 2022 09:05:03 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2022 09:05:04 -0000 https://gcc.gnu.org/g:cc7cd8d57cabf2598a1c5f64dd77487c31b4d149 commit r13-503-gcc7cd8d57cabf2598a1c5f64dd77487c31b4d149 Author: Eric Botcazou Date: Mon May 16 10:44:09 2022 +0200 Do not use DW_OP_not for TRUTH_NOT_EXPR in conditional expressions DW_OP_not is a bitwise, not a logical NOT, so it computes the wrong result in a DWARF conditional expression. gcc/ * dwarf2out.cc (loc_list_from_tree_1) : Do a logical instead of a bitwise negation. : Swap the operands if the condition is TRUTH_NOT_EXPR. Diff: --- gcc/dwarf2out.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 4ef644c5fae..fccf59e8ec3 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -19448,6 +19448,14 @@ loc_list_from_tree_1 (tree loc, int want_address, break; case TRUTH_NOT_EXPR: + list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context); + if (list_ret == 0) + return 0; + + add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_lit0, 0, 0)); + add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_eq, 0, 0)); + break; + case BIT_NOT_EXPR: op = DW_OP_not; goto do_unop; @@ -19496,6 +19504,15 @@ loc_list_from_tree_1 (tree loc, int want_address, list_ret = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0), 0, context); + /* Likewise, swap the operands for a logically negated condition. */ + else if (TREE_CODE (TREE_OPERAND (loc, 0)) == TRUTH_NOT_EXPR) + { + lhs = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0, context); + rhs = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context); + list_ret + = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0), + 0, context); + } else list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context); if (list_ret == 0 || lhs == 0 || rhs == 0)