Fix thinko in operator_bitwise_xor::op1_range
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 that a specific operand is false without any basis. gcc/ * range-op.cc (operator_bitwise_xor::op1_range): Fix thinko. gcc/testsuite/ * gnat.dg/opt100.adb: New test. * gnat.dg/opt100_pkg.adb, gnat.dg/opt100_pkg.ads: New helper.
This commit is contained in:
parent
2b3a3d7fe3
commit
a8404c07e7
4 changed files with 56 additions and 0 deletions
|
@ -3529,6 +3529,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;
|
||||
|
|
13
gcc/testsuite/gnat.dg/opt100.adb
Normal file
13
gcc/testsuite/gnat.dg/opt100.adb
Normal file
|
@ -0,0 +1,13 @@
|
|||
-- { 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;
|
17
gcc/testsuite/gnat.dg/opt100_pkg.adb
Normal file
17
gcc/testsuite/gnat.dg/opt100_pkg.adb
Normal file
|
@ -0,0 +1,17 @@
|
|||
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;
|
23
gcc/testsuite/gnat.dg/opt100_pkg.ads
Normal file
23
gcc/testsuite/gnat.dg/opt100_pkg.ads
Normal file
|
@ -0,0 +1,23 @@
|
|||
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;
|
Loading…
Add table
Reference in a new issue