Hi,
DW_OP_not is a bitwise, not a logical NOT, so it computes the wrong result in
a DWARF conditional expression.
Tested (GCC + GDB° on x86-64/Linux, OK for the mainline?
2022-05-13 Eric Botcazou <ebotca...@adacore.com>
* dwarf2out.c (loc_list_from_tree_1) <COND_EXPR>: Swap the operands
if the condition is a TRUTH_NOT_EXPR.
--
Eric Botcazou
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 5681b01749a..affa2b5e52e 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -19497,6 +19497,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);
+ /* DW_OP_not is a bitwise, not a logical NOT, so avoid it. */
+ 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)