From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Christopher Li <sparse@chrisli.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/4] volatile loads must not be simplified
Date: Wed, 4 Jan 2017 04:03:18 +0100 [thread overview]
Message-ID: <20170104030321.28019-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170104030321.28019-1-luc.vanoostenryck@gmail.com>
memops.c:simplify_loads() tries to simplify all loads,
even volatile ones.
For example, on the following code:
static int foo(volatile int *a, int v)
{
*a = v;
return *a;
}
test-linearize returns something like:
foo:
store.32 %arg2 -> 0[%arg1]
ret.32 %arg2
while the correct output is more like:
foo:
store.32 %arg2 -> 0[%arg1]
load.32 %r5 <- 0[%arg1]
ret.32 %r5
The fix is to simply ignore loads with the 'volatile' modifier.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
memops.c | 3 +++
validation/memops-volatile.c | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 validation/memops-volatile.c
diff --git a/memops.c b/memops.c
index 45bd3401..6dac1f57 100644
--- a/memops.c
+++ b/memops.c
@@ -99,6 +99,9 @@ static void simplify_loads(struct basic_block *bb)
/* Check for illegal offsets.. */
check_access(insn);
+ if (insn->type->ctype.modifiers & MOD_VOLATILE)
+ continue;
+
RECURSE_PTR_REVERSE(insn, dom) {
int dominance;
if (!dom->bb)
diff --git a/validation/memops-volatile.c b/validation/memops-volatile.c
new file mode 100644
index 00000000..0f3e12ad
--- /dev/null
+++ b/validation/memops-volatile.c
@@ -0,0 +1,21 @@
+static int foo(volatile int *a, int v)
+{
+ *a = v;
+ return *a;
+}
+
+/*
+ * check-name: memops-volatile
+ * check-command: test-linearize $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ store.32 %arg2 -> 0[%arg1]
+ load.32 %r5 <- 0[%arg1]
+ ret.32 %r5
+
+
+ * check-output-end
+ */
--
2.11.0
next prev parent reply other threads:[~2017-01-04 3:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-04 3:03 [PATCH 0/4] phisrc fixes Luc Van Oostenryck
2017-01-04 3:03 ` Luc Van Oostenryck [this message]
2017-01-04 3:03 ` [PATCH 2/4] fix superfluous phisrc Luc Van Oostenryck
2017-01-04 3:03 ` [PATCH 3/4] fix phisrc mixup Luc Van Oostenryck
2017-01-04 3:03 ` [PATCH 4/4] missing load simplification Luc Van Oostenryck
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=20170104030321.28019-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.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 NNTP newsgroup(s).