* [PATCH] Fix thinko in operator_bitwise_xor::op1_range
@ 2022-11-25 9:21 Eric Botcazou
2022-11-25 9:35 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2022-11-25 9:21 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 556 bytes --]
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.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 484 bytes --]
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;
[-- Attachment #3: opt100.adb --]
[-- Type: text/x-adasrc, Size: 215 bytes --]
-- { dg-do run }
-- { dg-options "-O2 -gnatp" }
with Opt100_Pkg; use Opt100_Pkg;
procedure Opt100 is
R : constant Rec := (K => B, N => 1);
begin
if Func (R) /= 1 then
raise Program_Error;
end if;
end;
[-- Attachment #4: opt100_pkg.adb --]
[-- Type: text/x-adasrc, Size: 365 bytes --]
package body Opt100_Pkg is
function Func (R : Rec) return Integer is
begin
if R in Small_Rec then
case R.K is
when A => return 0;
when B => return 1;
when C => return 2;
when others => raise Program_Error;
end case;
else
return -1;
end if;
end;
end Opt100_Pkg;
[-- Attachment #5: opt100_pkg.ads --]
[-- Type: text/x-adasrc, Size: 505 bytes --]
with Interfaces; use Interfaces;
package Opt100_Pkg is
A : constant Unsigned_8 := 0;
B : constant Unsigned_8 := 1;
C : constant Unsigned_8 := 2;
subtype Small_Unsigned_8 is Unsigned_8 range A .. C;
type Rec is record
K : Unsigned_8;
N : Natural;
end record;
subtype Small_Rec is Rec
with Dynamic_Predicate =>
Small_Rec.K in Small_Unsigned_8 and
((Small_Rec.N in Positive) = (Small_Rec.K in B | C));
function Func (R : Rec) return Integer;
end Opt100_Pkg;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix thinko in operator_bitwise_xor::op1_range
2022-11-25 9:21 [PATCH] Fix thinko in operator_bitwise_xor::op1_range Eric Botcazou
@ 2022-11-25 9:35 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-11-25 9:35 UTC (permalink / raw)
To: Eric Botcazou; +Cc: gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-25 9:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 9:21 [PATCH] Fix thinko in operator_bitwise_xor::op1_range Eric Botcazou
2022-11-25 9:35 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).