From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
Christopher Li <sparse@chrisli.org>
Subject: [PATCH 3/3] fix discarded label statement
Date: Thu, 10 Nov 2016 15:45:20 +0100 [thread overview]
Message-ID: <20161110144520.24965-4-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20161110144520.24965-1-luc.vanoostenryck@gmail.com>
When code contains an unused label, it's not needed to create a new
basic block for the code that follow it but that doesn't mean that
the following code is unreachable.
There is currently a bug related to this when processing a label statement
for a label that is never used: not only the label is ignored (and this
no new basic block is created) but the whol statement is ignored.
In other words the statement directly following an unused label is
simply ignored.
The patch fix this by simply moving the code handling the statement out
of the conditional part processing used labels.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 2 +-
validation/discarded-label-statement.c | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 validation/discarded-label-statement.c
diff --git a/linearize.c b/linearize.c
index c6ada1e8..4dc3d04d 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2026,8 +2026,8 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
if (label->used) {
add_label(ep, label);
- linearize_statement(ep, stmt->label_statement);
}
+ linearize_statement(ep, stmt->label_statement);
break;
}
diff --git a/validation/discarded-label-statement.c b/validation/discarded-label-statement.c
new file mode 100644
index 00000000..b4e58ac6
--- /dev/null
+++ b/validation/discarded-label-statement.c
@@ -0,0 +1,24 @@
+/*
+ * Verify that the statement following an unused label
+ * is not discarded with the label.
+ */
+
+static int bad(int a, int b)
+{
+ int r = 0;
+
+start:
+ r += a;
+ r += b;
+
+ return r;
+}
+
+/*
+ * check-name: discarded-label-statement
+ * check-command: test-linearize $file
+ *
+ * check-output-ignore
+ * check-output-contains: add
+ * check-output-contains: %arg1
+ */
--
2.10.1
next prev parent reply other threads:[~2016-11-10 14:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 14:45 [PATCH 0/3] fix discarded label statement Luc Van Oostenryck
2016-11-10 14:45 ` [PATCH 1/3] testsuite: add tag to ignore the output/error Luc Van Oostenryck
2016-11-17 17:15 ` Christopher Li
2016-11-10 14:45 ` [PATCH 2/3] testsuite: check patterns presence or absence in output Luc Van Oostenryck
2016-11-10 14:45 ` Luc Van Oostenryck [this message]
2016-11-17 17:19 ` [PATCH 3/3] fix discarded label statement Christopher Li
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=20161110144520.24965-4-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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).