Fix thinko in operator_bitwise_xor::op1_range

Message ID 12106563.O9o76ZdvQC@fomalhaut
State New
Headers
Series Fix thinko in operator_bitwise_xor::op1_range |

Commit Message

Eric Botcazou Nov. 25, 2022, 9:21 a.m. UTC
  Hi,

there is a thinko in the op1_range method of ranger's operator_bitwise_xor 
class in a boolean context: if the result is known to be true, it may infer 
than a specific operand is false without any basis.

Tested on x86-64/Linux, OK for mainline, 12 and 11 branches?


2022-11-25  Eric Botcazou  <ebotcazou@adacore.com>

	* range-op.cc (operator_bitwise_xor::op1_range): Fix thinko.


2022-11-25  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt100.adb: New test.
	* gnat.dg/opt100_pkg.adb, gnat.dg/opt100_pkg.ads: New helper.
  

Comments

Richard Biener Nov. 25, 2022, 9:35 a.m. UTC | #1
On Fri, Nov 25, 2022 at 10:22 AM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> there is a thinko in the op1_range method of ranger's operator_bitwise_xor
> class in a boolean context: if the result is known to be true, it may infer
> than a specific operand is false without any basis.
>
> Tested on x86-64/Linux, OK for mainline, 12 and 11 branches?

OK.

Thanks,
Richard.

>
> 2022-11-25  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * range-op.cc (operator_bitwise_xor::op1_range): Fix thinko.
>
>
> 2022-11-25  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * gnat.dg/opt100.adb: New test.
>         * gnat.dg/opt100_pkg.adb, gnat.dg/opt100_pkg.ads: New helper.
>
> --
> Eric Botcazou
  

Patch

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6fa3b151596..daea084ce18 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3501,6 +3501,9 @@  operator_bitwise_xor::op1_range (irange &r, tree type,
 	    r.set_varying (type);
 	  else if (op2.zero_p ())
 	    r = range_true (type);
+	  // See get_bool_state for the rationale
+	  else if (op2.contains_p (build_zero_cst (op2.type ())))
+	    r = range_true_and_false (type);
 	  else
 	    r = range_false (type);
 	  break;