public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: "hernandez, aldy" <aldyh@redhat.com>
Subject: [PATCH] tree-optimization/108306 - Correctly detect shifts out of range
Date: Mon, 23 Jan 2023 18:21:37 -0500	[thread overview]
Message-ID: <7030d247-5453-2344-2ee6-33899e52ed08@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

get_shift_range was incorrectly communicating that it couldn't calculate 
a range when the shift value was out of range.

Fix this and always return a range of [0, 0] instead of varying when the 
shift value is out of range.

Bootstraps with no regressions on x86_64-pc-linux-gnu.  OK for trunk?

Andrew

[-- Attachment #2: 0003-Correctly-detect-shifts-out-of-range.patch --]
[-- Type: text/x-patch, Size: 2239 bytes --]

From 5500762bacffd7b45a0bfa8f89333e955734820f Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 16 Jan 2023 15:02:51 -0500
Subject: [PATCH 3/3] 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.
---
 gcc/range-op.cc                 |  4 ++--
 gcc/testsuite/gcc.dg/pr108306.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr108306.c

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index ec75e07bc8a..6e5754e9130 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2166,7 +2166,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;
     }
 
@@ -2440,7 +2440,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);
+}
-- 
2.39.0


             reply	other threads:[~2023-01-23 23:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 23:21 Andrew MacLeod [this message]
2023-01-24  8:57 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7030d247-5453-2344-2ee6-33899e52ed08@redhat.com \
    --to=amacleod@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).