Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] move check_access() to late_warnings()
Date: Thu, 10 Dec 2020 00:31:38 +0100	[thread overview]
Message-ID: <20201209233138.76056-1-luc.vanoostenryck@gmail.com> (raw)

check_access() is called at each run of simplify_loads().

However, a bad access can belong to a dead branch and thus a
bad access warning can be issued for code that is not executed,
maybe specifically excluded.

So, move check_access() to late_warnings(), where all optimizations
have been done.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c                    |  6 ++++++
 memops.c                       |  3 ---
 validation/bad-check-access0.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 validation/bad-check-access0.c

diff --git a/linearize.c b/linearize.c
index 9fecb4b57e43..0250c6bb17ef 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2532,6 +2532,12 @@ static void late_warnings(struct entrypoint *ep)
 				continue;
 			if (insn->tainted)
 				check_tainted_insn(insn);
+			switch (insn->opcode) {
+			case OP_LOAD:
+				// Check for illegal offsets.
+				check_access(insn);
+				break;
+			}
 		} END_FOR_EACH_PTR(insn);
 	} END_FOR_EACH_PTR(bb);
 }
diff --git a/memops.c b/memops.c
index d96bd8a9090d..0a1106b0e464 100644
--- a/memops.c
+++ b/memops.c
@@ -147,9 +147,6 @@ static void simplify_loads(struct basic_block *bb)
 			struct pseudo_list *dominators;
 			unsigned long generation;
 
-			/* Check for illegal offsets.. */
-			check_access(insn);
-
 			if (insn->is_volatile)
 				continue;
 
diff --git a/validation/bad-check-access0.c b/validation/bad-check-access0.c
new file mode 100644
index 000000000000..3c4c023f2f89
--- /dev/null
+++ b/validation/bad-check-access0.c
@@ -0,0 +1,31 @@
+#define SIZE	2
+static int buf[SIZE];
+
+static inline int swt(int i)
+{
+	switch (i) {
+	case 0 ... (SIZE-1):
+		return buf[i];
+	default:
+		return 0;
+	}
+}
+
+static int switch_ok(void) { return swt(1); }
+static int switch_ko(void) { return swt(2); }
+
+
+static inline int cbr(int i, int p)
+{
+	if (p)
+		return buf[i];
+	else
+		return 0;
+}
+
+static int branch_ok(int x) { return cbr(1, x != x); }
+static int branch_ko(int x) { return cbr(2, x != x); }
+
+/*
+ * check-name: bad-check-access0
+ */
-- 
2.29.2


                 reply	other threads:[~2020-12-09 23:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201209233138.76056-1-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.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).