From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 0F2BE385B1BD; Fri, 25 Nov 2022 09:54:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F2BE385B1BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669370050; bh=3Pd4PGVFNlf200Tt9rFBS3r+p0+YXh7Bl8B0n19dV1A=; h=From:To:Subject:Date:From; b=xyJFoGLR6xxtgUBi6EJqpzf/h7AOTL5Rrx/Plw8gRmNEJjhHczQkQ2itPMUv/URe6 wZolhpvWyxphO21p021X1dufxmMFTmFAW4al+XTJoQ7fWU1pXX95QmeZScSE7IBzyu zmve6/h4RYlQGGyDEOCYXdN0//0ZKGQiznutTqck= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4297] Fix thinko in operator_bitwise_xor::op1_range X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 2b3a3d7fe3420b6b49810b2a7f5d120c53310335 X-Git-Newrev: a8404c07e7fca388c02c39077865f7d5fa928430 Message-Id: <20221125095410.0F2BE385B1BD@sourceware.org> Date: Fri, 25 Nov 2022 09:54:10 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a8404c07e7fca388c02c39077865f7d5fa928430 commit r13-4297-ga8404c07e7fca388c02c39077865f7d5fa928430 Author: Eric Botcazou Date: Fri Nov 25 10:49:20 2022 +0100 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. Diff: --- gcc/range-op.cc | 3 +++ gcc/testsuite/gnat.dg/opt100.adb | 13 +++++++++++++ gcc/testsuite/gnat.dg/opt100_pkg.adb | 17 +++++++++++++++++ gcc/testsuite/gnat.dg/opt100_pkg.ads | 23 +++++++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index ca1c38c9307..e53f3a70ea0 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -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; diff --git a/gcc/testsuite/gnat.dg/opt100.adb b/gcc/testsuite/gnat.dg/opt100.adb new file mode 100644 index 00000000000..83270b64339 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt100.adb @@ -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; diff --git a/gcc/testsuite/gnat.dg/opt100_pkg.adb b/gcc/testsuite/gnat.dg/opt100_pkg.adb new file mode 100644 index 00000000000..42bf8830d53 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt100_pkg.adb @@ -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; diff --git a/gcc/testsuite/gnat.dg/opt100_pkg.ads b/gcc/testsuite/gnat.dg/opt100_pkg.ads new file mode 100644 index 00000000000..a45f887d665 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt100_pkg.ads @@ -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;