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) <TRUTH_NOT_EXPR>: Do a logical
	instead of a bitwise negation.
	<COND_EXPR>: Swap the operands if the condition is TRUTH_NOT_EXPR.
This commit is contained in:
Eric Botcazou 2022-05-16 10:44:09 +02:00
parent c6ca39c7bf
commit ad05a1d7f8
1 changed files with 17 additions and 0 deletions

View File

@ -19449,6 +19449,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;
@ -19497,6 +19505,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)