From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id EF4C23858D1E; Mon, 30 Jan 2023 21:12:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF4C23858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675113140; bh=pWkE79NjZE46DXzaZjPGdaQAMJn5tRNt53n4AoiAs1Y=; h=From:To:Subject:Date:From; b=Lkp95AEeILr7rdAHfrfpCZWDj8ZnnICJAPRNkTJrQSo29TXZTW4H/aKeQmKvsUtXa rXDSbhGZ7HN5P1M6bEh7hNeTd6esvh99k0yuWaiiFtwxJjeu6/czxhphNHdb0z5pgt U5CyVI6lHbj1CdOQTXQjcPUQT1q9XLr45Fs+wQHQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9091] Correctly detect shifts out of range X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 591ec4820aa4e6d757ddc76cae1d92d445daf72c X-Git-Newrev: 9dccaeaa586a1634e1f6a0f4c51806f3c3aea63b Message-Id: <20230130211220.EF4C23858D1E@sourceware.org> Date: Mon, 30 Jan 2023 21:12:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9dccaeaa586a1634e1f6a0f4c51806f3c3aea63b commit r12-9091-g9dccaeaa586a1634e1f6a0f4c51806f3c3aea63b Author: Andrew MacLeod Date: Mon Jan 30 14:59:30 2023 -0500 Correctly detect shifts out of range get_shift_range was incorrectly communicating that it couldn't calculate a range when the shift values was always out fo range. Fix this and alwasy return [0, 0] when the shift value is always out of range. PR tree-optimization/108306 gcc/ * range-op.cc (operator_lshift::fold_range): Return [0, 0] not varying for shifts that are always out of void range. (operator_rshift::fold_range): Return [0, 0] not varying for shifts that are always out of void range. gcc/testsuite/ * gcc.dg/pr108306.c: New. Diff: --- gcc/range-op.cc | 4 ++-- gcc/testsuite/gcc.dg/pr108306.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index b5f4627fe2b..bf95f5fbaa1 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1970,7 +1970,7 @@ operator_lshift::fold_range (irange &r, tree type, if (op2.undefined_p ()) r.set_undefined (); else - r.set_varying (type); + r.set_zero (type); return true; } @@ -2240,7 +2240,7 @@ operator_rshift::fold_range (irange &r, tree type, if (op2.undefined_p ()) r.set_undefined (); else - r.set_varying (type); + r.set_zero (type); return true; } diff --git a/gcc/testsuite/gcc.dg/pr108306.c b/gcc/testsuite/gcc.dg/pr108306.c new file mode 100644 index 00000000000..1044c646de7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108306.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-strict-overflow -fsanitize=shift -Warray-bounds" } */ + +enum psi_task_count { + NR_IOWAIT, + NR_PSI_TASK_COUNTS = 4, +}; + +unsigned int tasks[NR_PSI_TASK_COUNTS]; + +static void psi_group_change(unsigned int set) +{ + unsigned int t; + unsigned int state_mask = 0; + + for (t = 0; set; set &= ~(1 << t), t++) + if (set & (1 << t)) + tasks[t]++; +} + +void psi_task_switch(int sleep) +{ + int set = 0; + + if (sleep) + set |= (1 << NR_IOWAIT); + + psi_group_change(set); +}